Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextTables.java
blob60c1d85d340676ad490f5ac4f29029718a3704ac
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod._sw;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.lang.XMultiServiceFactory;
30 import com.sun.star.text.XTextDocument;
31 import com.sun.star.text.XTextTable;
32 import com.sun.star.text.XTextTablesSupplier;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
36 /**
38 * initial description
39 * @see com.sun.star.container.XElementAccess
40 * @see com.sun.star.container.XIndexAccess
41 * @see com.sun.star.container.XNameAccess
44 public class SwXTextTables extends TestCase {
45 XTextDocument xTextDoc;
47 @Override
48 protected void initialize( TestParameters tParam, PrintWriter log ) {
49 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
51 try {
52 log.println( "creating a textdocument" );
53 xTextDoc = SOF.createTextDoc( null );
54 } catch ( com.sun.star.uno.Exception e ) {
55 // Some exception occurs.FAILED
56 e.printStackTrace( log );
57 throw new StatusException( "Couldn't create document", e );
61 @Override
62 protected void cleanup( TestParameters tParam, PrintWriter log ) {
63 log.println( " disposing xTextDoc " );
64 util.DesktopTools.closeDoc(xTextDoc);
68 /**
69 * creating a Testenvironment for the interfaces to be tested
71 * @param tParam class which contains additional test parameters
72 * @param log class to log the test state and result
74 * @return Status class
76 * @see TestParameters
77 * @see PrintWriter
79 @Override
80 public synchronized TestEnvironment createTestEnvironment
81 (TestParameters tParam, PrintWriter log) {
83 XInterface oObj = null;
84 int nRow = 4;
85 int nCol = 5;
88 // creation of testobject here
89 // first we write what we are intend to do to log file
90 log.println( "creating a test environment" );
92 // get a soffice factory object
93 SOfficeFactory.getFactory( tParam.getMSF() );
95 // create testobject here
96 TestEnvironment tEnv = null;
97 XTextTable oTable = null;
98 try {
99 oTable = SOfficeFactory.createTextTable( xTextDoc );
100 SOfficeFactory.insertTextContent(xTextDoc, oTable );
102 catch( Exception uE ) {
103 uE.printStackTrace( log );
104 throw new StatusException("Couldn't create TextTable : "
105 + uE.getMessage(), uE);
108 // Number two
109 XTextTable oTable2 = null;
110 try {
111 oTable2 = SOfficeFactory.createTextTable( xTextDoc );
112 SOfficeFactory.insertTextContent(xTextDoc, oTable2 );
114 catch( Exception uE ) {
115 uE.printStackTrace( log );
116 throw new StatusException("Couldn't create TextTable two: "
117 + uE.getMessage(), uE);
120 XMultiServiceFactory msf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
121 XTextTablesSupplier oTTSupp = UnoRuntime.queryInterface(XTextTablesSupplier.class, msf);
122 oObj = oTTSupp.getTextTables();
124 if ( oTable != null ) {
125 log.println("Creating instance...");
126 tEnv = new TestEnvironment(oObj);
129 log.println( "adding TextDocument as mod relation to environment" );
130 tEnv.addObjRelation( "TEXTDOC", xTextDoc );
131 tEnv.addObjRelation( "ROW", Integer.valueOf( nRow ) );
132 tEnv.addObjRelation( "COL", Integer.valueOf( nCol ) );
133 try {
134 tEnv.addObjRelation( "INST", SOfficeFactory.createTextTable( xTextDoc ));
136 catch( Exception uE ) {
137 uE.printStackTrace( log );
138 throw new StatusException("Couldn't create TextTable : "
139 + uE.getMessage(), uE);
142 return tEnv;
143 } // finish method getTestEnvironment
145 } // finish class SwXTextTables