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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.lang
.XMultiServiceFactory
;
30 import com
.sun
.star
.table
.XCellRange
;
31 import com
.sun
.star
.text
.XTextDocument
;
32 import com
.sun
.star
.text
.XTextTable
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.uno
.XInterface
;
37 * Test for object which is represented by service
38 * <code>com.sun.star.table.CellRange</code>. <p>
39 * Object implements the following interfaces :
41 * <li> <code>com::sun::star::text::CellProperties</code></li>
42 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
44 * This object test <b> is NOT </b> designed to be run in several
45 * threads concurently.
46 * @see com.sun.star.table.CellRange
47 * @see com.sun.star.text.CellProperties
48 * @see com.sun.star.beans.XPropertySet
49 * @see ifc.text._CellProperties
50 * @see ifc.beans._XPropertySet
52 public class SwXCellRange
extends TestCase
{
54 XTextDocument xTextDoc
;
57 * Creates text document.
59 protected void initialize( TestParameters tParam
, PrintWriter log
) {
60 SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
62 log
.println( "creating a textdocument" );
63 xTextDoc
= SOF
.createTextDoc( null );
64 } catch ( com
.sun
.star
.uno
.Exception e
) {
65 e
.printStackTrace( log
);
66 throw new StatusException( "Couldn't create document", e
);
71 * Disposes text document.
73 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
74 log
.println( " disposing xTextDoc " );
75 util
.DesktopTools
.closeDoc(xTextDoc
);
79 * Creating a Testenvironment for the interfaces to be tested. At first
80 * method creates and initializes the table, then if text document has no
81 * tables, previously created table is inserted to text document. Finally,
82 * custom cell range is gotten from the table created.
83 * Object relations created :
85 * <li> <code>'CellProperties.TextSection'</code> for
86 * {@link ifc.text._CellProperties} : range of complete paragraphs
90 protected synchronized TestEnvironment createTestEnvironment
91 (TestParameters tParam
, PrintWriter log
) {
93 XTextTable the_table
= null;
94 XInterface oObj
= null;
96 the_table
= SOfficeFactory
.createTextTable( xTextDoc
);
97 the_table
.initialize(5, 5);
98 } catch ( com
.sun
.star
.uno
.Exception e
) {
99 e
.printStackTrace( log
);
100 throw new StatusException("Couldn't create testobj: "
104 if( SOfficeFactory
.getTableCollection( xTextDoc
).getCount() == 0 ) {
106 SOfficeFactory
.insertTextContent(xTextDoc
, the_table
);
107 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
108 e
.printStackTrace( log
);
109 throw new StatusException("Couldn't create TextTable : "
110 + e
.getMessage(), e
);
114 XCellRange the_Range
= UnoRuntime
.queryInterface(XCellRange
.class, the_table
);
115 oObj
= the_Range
.getCellRangeByPosition(0, 0, 3, 4);
116 } catch (com
.sun
.star
.uno
.Exception e
) {
117 e
.printStackTrace( log
);
118 throw new StatusException("Couldn't get CellRange : "
119 + e
.getMessage(), e
);
122 log
.println("Creating instance...");
123 TestEnvironment tEnv
= new TestEnvironment( oObj
);
124 log
.println("ImplName: " + util
.utils
.getImplName(oObj
));
126 XMultiServiceFactory oDocMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
128 XInterface oTS
= (XInterface
)
129 oDocMSF
.createInstance("com.sun.star.text.TextSection");
130 log
.println(" adding TextSection object");
131 tEnv
.addObjRelation("CellProperties.TextSection", oTS
);
132 } catch (com
.sun
.star
.uno
.Exception e
) {
133 log
.println("Could not get instance of TextSection");
134 e
.printStackTrace(log
);
137 Object
[][] NewData
= new Object
[5][];
138 NewData
[0] = new Double
[]
139 {new Double(2.5),new Double(5),new Double(2.5),new Double(5)};
140 NewData
[1] = new Double
[]
141 {new Double(4),new Double(9),new Double(2.5),new Double(5)};
142 NewData
[2] = new Double
[]
143 {new Double(2.5),new Double(5),new Double(2.5),new Double(5)};
144 NewData
[3] = new Double
[]
145 {new Double(2.5),new Double(5),new Double(2.5),new Double(5)};
146 NewData
[4] = new Double
[]
147 {new Double(4),new Double(9),new Double(2.5),new Double(5)};
148 tEnv
.addObjRelation("NewData",NewData
);
150 // com::sun::star::chart::XChartDataArray
151 tEnv
.addObjRelation("CRDESC",
152 "Column and RowDescriptions can't be changed for this Object");
157 } // finish class SwXCellRange