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.uno.XInterface;
38 
39 /**
40  *
41  * initial description
42  * @see com.sun.star.beans.XPropertySet
43  * @see com.sun.star.text.XTextTableCursor
44  *
45  */
46 public class SwXTextTableCursor extends TestCase {
47     XTextDocument xTextDoc;
48 
initialize( TestParameters tParam, PrintWriter log )49     protected void initialize( TestParameters tParam, PrintWriter log ) {
50         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
51 
52         try {
53             log.println( "creating a textdocument" );
54             xTextDoc = SOF.createTextDoc( null );
55         } catch ( com.sun.star.uno.Exception e ) {
56             // Some exception occures.FAILED
57             e.printStackTrace( log );
58             throw new StatusException( "Couldn't create document", e );
59         }
60     }
61 
cleanup( TestParameters tParam, PrintWriter log )62     protected void cleanup( TestParameters tParam, PrintWriter log ) {
63         log.println( "    disposing xTextDoc " );
64         util.DesktopTools.closeDoc(xTextDoc);
65     }
66 
67 
68     /**
69      *    creating a Testenvironment for the interfaces to be tested
70      *
71      *  @param tParam    class which contains additional test parameters
72      *  @param log        class to log the test state and result
73      *
74      *  @return    Status class
75      *
76      *  @see TestParameters
77      *    @see PrintWriter
78      */
createTestEnvironment( TestParameters tParam, PrintWriter log )79     public synchronized TestEnvironment createTestEnvironment( TestParameters tParam,
80                                                   PrintWriter log )
81                                                     throws StatusException {
82 
83         XInterface oObj = null;
84 
85         // creation of testobject here
86         // first we write what we are intend to do to log file
87         log.println( "creating a test environment" );
88 
89         // get a soffice factory object
90         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
91 
92         // create testobject here
93 
94         XTextTable oTable = null;
95         try {
96             oTable = SOF.createTextTable( xTextDoc );
97             SOF.insertTextContent(xTextDoc, oTable );
98         }
99         catch( com.sun.star.uno.Exception uE ) {
100             uE.printStackTrace( log );
101             throw new StatusException("Couldn't create TextTable : "
102                     + uE.getMessage(), uE);
103         }
104 
105         oObj = oTable.createCursorByCellName("A1");
106 
107         log.println( "creating a new environment for TextTableCursor object" );
108         TestEnvironment tEnv = new TestEnvironment( oObj );
109 
110         log.println( "adding TextDocument as mod relation to environment" );
111         tEnv.addObjRelation("TEXTDOC", xTextDoc);
112 
113         tEnv.addObjRelation("STYLENAME1", "Table");
114         tEnv.addObjRelation("STYLENAME2", "Text");
115 
116         return tEnv;
117     } // finish method getTestEnvironment
118 
119 }    // finish class SwXTextTableCursor
120 
121