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.
60 protected void initialize( TestParameters tParam
, PrintWriter log
) {
61 SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
63 log
.println( "creating a textdocument" );
64 xTextDoc
= SOF
.createTextDoc( null );
65 } catch ( com
.sun
.star
.uno
.Exception e
) {
66 e
.printStackTrace( log
);
67 throw new StatusException( "Couldn't create document", e
);
72 * Disposes text document.
75 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
76 log
.println( " disposing xTextDoc " );
77 util
.DesktopTools
.closeDoc(xTextDoc
);
81 * Creating a Testenvironment for the interfaces to be tested. At first
82 * method creates and initializes the table, then if text document has no
83 * tables, previously created table is inserted to text document. Finally,
84 * custom cell range is gotten from the table created.
85 * Object relations created :
87 * <li> <code>'CellProperties.TextSection'</code> for
88 * {@link ifc.text._CellProperties} : range of complete paragraphs
93 protected synchronized TestEnvironment createTestEnvironment
94 (TestParameters tParam
, PrintWriter log
) {
96 XTextTable the_table
= null;
97 XInterface oObj
= null;
98 the_table
= SOfficeFactory
.createTextTable( xTextDoc
);
99 the_table
.initialize(5, 5);
101 if( SOfficeFactory
.getTableCollection( xTextDoc
).getCount() == 0 ) {
103 SOfficeFactory
.insertTextContent(xTextDoc
, the_table
);
104 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
105 e
.printStackTrace( log
);
106 throw new StatusException("Couldn't create TextTable : "
107 + e
.getMessage(), e
);
111 XCellRange the_Range
= UnoRuntime
.queryInterface(XCellRange
.class, the_table
);
112 oObj
= the_Range
.getCellRangeByPosition(0, 0, 3, 4);
113 } catch (com
.sun
.star
.uno
.Exception e
) {
114 e
.printStackTrace( log
);
115 throw new StatusException("Couldn't get CellRange : "
116 + e
.getMessage(), e
);
119 log
.println("Creating instance...");
120 TestEnvironment tEnv
= new TestEnvironment( oObj
);
121 log
.println("ImplName: " + util
.utils
.getImplName(oObj
));
123 XMultiServiceFactory oDocMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
125 XInterface oTS
= (XInterface
)
126 oDocMSF
.createInstance("com.sun.star.text.TextSection");
127 log
.println(" adding TextSection object");
128 tEnv
.addObjRelation("CellProperties.TextSection", oTS
);
129 } catch (com
.sun
.star
.uno
.Exception e
) {
130 log
.println("Could not get instance of TextSection");
131 e
.printStackTrace(log
);
134 Object
[][] NewData
= new Object
[5][];
135 NewData
[0] = new Double
[]
136 {new Double(2.5),new Double(5),new Double(2.5),new Double(5)};
137 NewData
[1] = new Double
[]
138 {new Double(4),new Double(9),new Double(2.5),new Double(5)};
139 NewData
[2] = new Double
[]
140 {new Double(2.5),new Double(5),new Double(2.5),new Double(5)};
141 NewData
[3] = new Double
[]
142 {new Double(2.5),new Double(5),new Double(2.5),new Double(5)};
143 NewData
[4] = new Double
[]
144 {new Double(4),new Double(9),new Double(2.5),new Double(5)};
145 tEnv
.addObjRelation("NewData",NewData
);
147 // com::sun::star::chart::XChartDataArray
148 tEnv
.addObjRelation("CRDESC",
149 "Column and RowDescriptions can't be changed for this Object");
154 } // finish class SwXCellRange