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.table.XCellRange;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.text.XTextTable;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
40 
41 /**
42  * Test for object which is represented by service
43  * <code>com.sun.star.table.CellRange</code>. <p>
44  * Object implements the following interfaces :
45  * <ul>
46  *  <li> <code>com::sun::star::text::CellProperties</code></li>
47  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
48  * </ul> <p>
49  * This object test <b> is NOT </b> designed to be run in several
50  * threads concurently.
51  * @see com.sun.star.table.CellRange
52  * @see com.sun.star.text.CellProperties
53  * @see com.sun.star.beans.XPropertySet
54  * @see ifc.text._CellProperties
55  * @see ifc.beans._XPropertySet
56  */
57 public class SwXCellRange extends TestCase {
58     SOfficeFactory SOF;
59     XTextDocument xTextDoc;
60 
61     /**
62     * Creates text document.
63     */
initialize( TestParameters tParam, PrintWriter log )64     protected void initialize( TestParameters tParam, PrintWriter log ) {
65         SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
66         try {
67             log.println( "creating a textdocument" );
68             xTextDoc = SOF.createTextDoc( null );
69         } catch ( com.sun.star.uno.Exception e ) {
70             e.printStackTrace( log );
71             throw new StatusException( "Couldn't create document", e );
72         }
73     }
74 
75     /**
76     * Disposes text document.
77     */
cleanup( TestParameters tParam, PrintWriter log )78     protected void cleanup( TestParameters tParam, PrintWriter log ) {
79         log.println( "    disposing xTextDoc " );
80         util.DesktopTools.closeDoc(xTextDoc);
81     }
82 
83     /**
84     * Creating a Testenvironment for the interfaces to be tested. At first
85     * method creates and initializes the table, then if text document has no
86     * tables, previously created table is inserted to text document. Finally,
87     * custom cell range is gotten from the table created.
88     *     Object relations created :
89     * <ul>
90     *  <li> <code>'CellProperties.TextSection'</code> for
91     *    {@link ifc.text._CellProperties} : range of complete paragraphs
92     *  within a text</li>
93     * </ul>
94     */
createTestEnvironment(TestParameters tParam, PrintWriter log)95     protected synchronized TestEnvironment createTestEnvironment
96             (TestParameters tParam, PrintWriter log) {
97 
98         XTextTable the_table = null;
99         XInterface oObj = null;
100         try {
101             the_table = SOF.createTextTable( xTextDoc );
102             the_table.initialize(5, 5);
103         } catch ( com.sun.star.uno.Exception e ) {
104             e.printStackTrace( log );
105             throw new StatusException("Couldn't create testobj: "
106                 +e.getMessage(),e);
107         }
108 
109         if( SOF.getTableCollection( xTextDoc ).getCount() == 0 ) {
110             try {
111                 SOF.insertTextContent(xTextDoc, the_table );
112             } catch( com.sun.star.uno.Exception e ) {
113                 e.printStackTrace( log );
114                 throw new StatusException("Couldn't create TextTable : "
115                         + e.getMessage(), e);
116             }
117         }
118         try {
119             XCellRange the_Range = (XCellRange)
120                     UnoRuntime.queryInterface(XCellRange.class, the_table);
121             oObj = the_Range.getCellRangeByPosition(0, 0, 3, 4);
122         } catch (com.sun.star.uno.Exception e) {
123             e.printStackTrace( log );
124             throw new StatusException("Couldn't get CellRange : "
125                     + e.getMessage(), e);
126         }
127 
128         log.println("Creating instance...");
129         TestEnvironment tEnv = new TestEnvironment( oObj );
130         log.println("ImplName: " + util.utils.getImplName(oObj));
131 
132         XMultiServiceFactory oDocMSF = (XMultiServiceFactory)
133             UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
134         try {
135             XInterface oTS = (XInterface)
136                 oDocMSF.createInstance("com.sun.star.text.TextSection");
137             log.println("  adding TextSection object");
138             tEnv.addObjRelation("CellProperties.TextSection", oTS);
139         } catch (com.sun.star.uno.Exception e) {
140             log.println("Could not get instance of TextSection");
141             e.printStackTrace(log);
142         }
143 
144         Object[][] NewData = new Object[5][];
145         NewData[0] = new Double[]
146             {new Double(2.5),new Double(5),new Double(2.5),new Double(5)};
147         NewData[1] = new Double[]
148             {new Double(4),new Double(9),new Double(2.5),new Double(5)};
149         NewData[2] = new Double[]
150             {new Double(2.5),new Double(5),new Double(2.5),new Double(5)};
151         NewData[3] = new Double[]
152             {new Double(2.5),new Double(5),new Double(2.5),new Double(5)};
153         NewData[4] = new Double[]
154             {new Double(4),new Double(9),new Double(2.5),new Double(5)};
155         tEnv.addObjRelation("NewData",NewData);
156 
157         // com::sun::star::chart::XChartDataArray
158         tEnv.addObjRelation("CRDESC",
159                  "Column and RowDescriptions can't be changed for this Object");
160 
161 
162         return tEnv;
163     }
164 }    // finish class SwXCellRange
165 
166