1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._sw;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.SOfficeFactory;
33 
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.text.XTextDocument;
36 import com.sun.star.text.XTextTable;
37 import com.sun.star.text.XTextTablesSupplier;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
40 
41 /**
42  *
43  * initial description
44  * @see com.sun.star.container.XElementAccess
45  * @see com.sun.star.container.XIndexAccess
46  * @see com.sun.star.container.XNameAccess
47  *
48  */
49 public class SwXTextTables extends TestCase {
50     XTextDocument xTextDoc;
51 
initialize( TestParameters tParam, PrintWriter log )52     protected void initialize( TestParameters tParam, PrintWriter log ) {
53         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
54 
55         try {
56             log.println( "creating a textdocument" );
57             xTextDoc = SOF.createTextDoc( null );
58         } catch ( com.sun.star.uno.Exception e ) {
59             // Some exception occures.FAILED
60             e.printStackTrace( log );
61             throw new StatusException( "Couldn't create document", e );
62         }
63     }
64 
cleanup( TestParameters tParam, PrintWriter log )65     protected void cleanup( TestParameters tParam, PrintWriter log ) {
66         log.println( "    disposing xTextDoc " );
67         util.DesktopTools.closeDoc(xTextDoc);
68     }
69 
70 
71     /**
72      *    creating a Testenvironment for the interfaces to be tested
73      *
74      *  @param tParam    class which contains additional test parameters
75      *  @param log        class to log the test state and result
76      *
77      *  @return    Status class
78      *
79      *  @see TestParameters
80      *    @see PrintWriter
81      */
createTestEnvironment(TestParameters tParam, PrintWriter log)82     public synchronized TestEnvironment createTestEnvironment
83             (TestParameters tParam, PrintWriter log) {
84 
85         XInterface oObj = null;
86         int nRow = 4;
87         int nCol = 5;
88 
89 
90         // creation of testobject here
91         // first we write what we are intend to do to log file
92         log.println( "creating a test environment" );
93 
94         // get a soffice factory object
95         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
96 
97         // create testobject here
98         TestEnvironment tEnv = null;
99         XTextTable oTable = null;
100         try {
101             oTable = SOF.createTextTable( xTextDoc );
102             SOF.insertTextContent(xTextDoc, oTable );
103         }
104         catch( Exception uE ) {
105             uE.printStackTrace( log );
106             throw new StatusException("Couldn't create TextTable : "
107                     + uE.getMessage(), uE);
108         }
109 
110         // Number two
111         XTextTable oTable2 = null;
112         try {
113             oTable2 = SOF.createTextTable( xTextDoc );
114             SOF.insertTextContent(xTextDoc, oTable2 );
115         }
116         catch( Exception uE ) {
117             uE.printStackTrace( log );
118             throw new StatusException("Couldn't create TextTable two: "
119                     + uE.getMessage(), uE);
120         }
121 
122         XMultiServiceFactory msf = (XMultiServiceFactory)
123             UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
124         XTextTablesSupplier oTTSupp = (XTextTablesSupplier)
125             UnoRuntime.queryInterface(XTextTablesSupplier.class, msf);
126         oObj = oTTSupp.getTextTables();
127 
128         if ( oTable != null ) {
129             log.println("Creating instance...");
130             tEnv = new TestEnvironment(oObj);
131         }
132 
133         log.println( "adding TextDocument as mod relation to environment" );
134         tEnv.addObjRelation( "TEXTDOC", xTextDoc );
135         tEnv.addObjRelation( "ROW", new Integer( nRow ) );
136         tEnv.addObjRelation( "COL", new Integer( nCol ) );
137         try {
138             tEnv.addObjRelation( "INST", SOF.createTextTable( xTextDoc ));
139         }
140         catch( Exception uE ) {
141             uE.printStackTrace( log );
142             throw new StatusException("Couldn't create TextTable : "
143                     + uE.getMessage(), uE);
144         }
145 
146         return tEnv;
147     } // finish method getTestEnvironment
148 
149 }    // finish class SwXTextTables
150 
151