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
.awt
.Rectangle
;
30 import com
.sun
.star
.container
.XIndexAccess
;
31 import com
.sun
.star
.container
.XNameAccess
;
32 import com
.sun
.star
.lang
.XComponent
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.sheet
.XCellRangeAddressable
;
35 import com
.sun
.star
.sheet
.XSpreadsheet
;
36 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
37 import com
.sun
.star
.sheet
.XSpreadsheets
;
38 import com
.sun
.star
.table
.CellRangeAddress
;
39 import com
.sun
.star
.table
.XCell
;
40 import com
.sun
.star
.table
.XCellRange
;
41 import com
.sun
.star
.table
.XTableChart
;
42 import com
.sun
.star
.table
.XTableCharts
;
43 import com
.sun
.star
.table
.XTableChartsSupplier
;
44 import com
.sun
.star
.uno
.AnyConverter
;
45 import com
.sun
.star
.uno
.Type
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
49 * Test for object which is represented by service
50 * <code>com.sun.star.table.TableChart</code>. <p>
51 * Object implements the following interfaces :
53 * <li> <code>com::sun::star::container::XNamed</code></li>
54 * <li> <code>com::sun::star::table::XTableChart</code></li>
55 * <li> <code>com::sun::star::document::XEmbeddedObjectSupplier</code></li>
57 * @see com.sun.star.table.TableChart
58 * @see com.sun.star.container.XNamed
59 * @see com.sun.star.table.XTableChart
60 * @see com.sun.star.document.XEmbeddedObjectSupplier
61 * @see ifc.container._XNamed
62 * @see ifc.table._XTableChart
63 * @see ifc.document._XEmbeddedObjectSupplier
65 public class ScChartObj
extends TestCase
{
66 private XSpreadsheetDocument xSheetDoc
= null;
69 * Creates Spreadsheet document.
71 protected void initialize( TestParameters tParam
, PrintWriter log
) {
72 // get a soffice factory object
73 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
76 log
.println( "creating a sheetdocument" );
77 xSheetDoc
= SOF
.createCalcDoc(null);
78 } catch (com
.sun
.star
.uno
.Exception e
) {
79 // Some exception occurs.FAILED
80 e
.printStackTrace( log
);
81 throw new StatusException( "Couldn't create document", e
);
86 * Disposes Spreadsheet document.
88 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
89 log
.println( " disposing xSheetDoc " );
90 XComponent oComp
= UnoRuntime
.queryInterface(XComponent
.class, xSheetDoc
);
91 util
.DesktopTools
.closeDoc(oComp
);
95 * Creating a Testenvironment for the interfaces to be tested.
96 * Retrieves a collection of spreadsheets from a document
97 * and takes one of them. Inserts some values into the cells of the some cell
98 * range address. Adds the chart that using the data from the cells of this
99 * cell range address. New chart is the instance of
100 * the service <code>com.sun.star.table.TableChart</code>.
101 * Object relations created :
103 * <li> <code>'setName'</code> for
104 * {@link ifc.container._XNamed}(the method <code>setName</code> must
105 * not be tested)</li>
107 * @see com.sun.star.container.XNamed
109 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
111 XSpreadsheet oSheet
=null;
114 log
.println("Getting spreadsheet") ;
115 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
116 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
117 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
118 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
119 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
120 log
.println("Couldn't get Sheet ");
121 e
.printStackTrace(log
);
122 throw new StatusException("Couldn't get sheet", e
);
123 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
124 log
.println("Couldn't get Sheet ");
125 e
.printStackTrace(log
);
126 throw new StatusException("Couldn't get sheet", e
);
127 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
128 log
.println("Couldn't get Sheet ");
129 e
.printStackTrace(log
);
130 throw new StatusException("Couldn't get sheet", e
);
133 log
.println("Creating the Header") ;
135 insertIntoCell(1,0,"JAN",oSheet
,"");
136 insertIntoCell(2,0,"FEB",oSheet
,"");
137 insertIntoCell(3,0,"MAR",oSheet
,"");
138 insertIntoCell(4,0,"APR",oSheet
,"");
139 insertIntoCell(5,0,"MAI",oSheet
,"");
140 insertIntoCell(6,0,"JUN",oSheet
,"");
141 insertIntoCell(7,0,"JUL",oSheet
,"");
142 insertIntoCell(8,0,"AUG",oSheet
,"");
143 insertIntoCell(9,0,"SEP",oSheet
,"");
144 insertIntoCell(10,0,"OCT",oSheet
,"");
145 insertIntoCell(11,0,"NOV",oSheet
,"");
146 insertIntoCell(12,0,"DEC",oSheet
,"");
147 insertIntoCell(13,0,"SUM",oSheet
,"");
149 log
.println("Fill the lines");
151 insertIntoCell(0,1,"Smith",oSheet
,"");
152 insertIntoCell(1,1,"42",oSheet
,"V");
153 insertIntoCell(2,1,"58.9",oSheet
,"V");
154 insertIntoCell(3,1,"-66.5",oSheet
,"V");
155 insertIntoCell(4,1,"43.4",oSheet
,"V");
156 insertIntoCell(5,1,"44.5",oSheet
,"V");
157 insertIntoCell(6,1,"45.3",oSheet
,"V");
158 insertIntoCell(7,1,"-67.3",oSheet
,"V");
159 insertIntoCell(8,1,"30.5",oSheet
,"V");
160 insertIntoCell(9,1,"23.2",oSheet
,"V");
161 insertIntoCell(10,1,"-97.3",oSheet
,"V");
162 insertIntoCell(11,1,"22.4",oSheet
,"V");
163 insertIntoCell(12,1,"23.5",oSheet
,"V");
164 insertIntoCell(13,1,"=SUM(B2:M2)",oSheet
,"");
166 insertIntoCell(0,2,"Jones",oSheet
,"");
167 insertIntoCell(1,2,"21",oSheet
,"V");
168 insertIntoCell(2,2,"40.9",oSheet
,"V");
169 insertIntoCell(3,2,"-57.5",oSheet
,"V");
170 insertIntoCell(4,2,"-23.4",oSheet
,"V");
171 insertIntoCell(5,2,"34.5",oSheet
,"V");
172 insertIntoCell(6,2,"59.3",oSheet
,"V");
173 insertIntoCell(7,2,"27.3",oSheet
,"V");
174 insertIntoCell(8,2,"-38.5",oSheet
,"V");
175 insertIntoCell(9,2,"43.2",oSheet
,"V");
176 insertIntoCell(10,2,"57.3",oSheet
,"V");
177 insertIntoCell(11,2,"25.4",oSheet
,"V");
178 insertIntoCell(12,2,"28.5",oSheet
,"V");
179 insertIntoCell(13,2,"=SUM(B3:M3)",oSheet
,"");
181 insertIntoCell(0,3,"Brown",oSheet
,"");
182 insertIntoCell(1,3,"31.45",oSheet
,"V");
183 insertIntoCell(2,3,"-20.9",oSheet
,"V");
184 insertIntoCell(3,3,"-117.5",oSheet
,"V");
185 insertIntoCell(4,3,"23.4",oSheet
,"V");
186 insertIntoCell(5,3,"-114.5",oSheet
,"V");
187 insertIntoCell(6,3,"115.3",oSheet
,"V");
188 insertIntoCell(7,3,"-171.3",oSheet
,"V");
189 insertIntoCell(8,3,"89.5",oSheet
,"V");
190 insertIntoCell(9,3,"41.2",oSheet
,"V");
191 insertIntoCell(10,3,"71.3",oSheet
,"V");
192 insertIntoCell(11,3,"25.4",oSheet
,"V");
193 insertIntoCell(12,3,"38.5",oSheet
,"V");
194 insertIntoCell(13,3,"=SUM(A4:L4)",oSheet
,"");
198 Rectangle oRect
= new Rectangle(500, 3000, 25000, 11000);
200 XCellRange oRange
= UnoRuntime
.queryInterface(XCellRange
.class, oSheet
);
201 XCellRange myRange
= oRange
.getCellRangeByName("A1:N4");
202 XCellRangeAddressable oRangeAddr
= UnoRuntime
.queryInterface(XCellRangeAddressable
.class, myRange
);
203 CellRangeAddress myAddr
= oRangeAddr
.getRangeAddress();
205 CellRangeAddress
[] oAddr
= new CellRangeAddress
[1];
207 XTableChartsSupplier oSupp
= UnoRuntime
.queryInterface(XTableChartsSupplier
.class, oSheet
);
209 log
.println("Insert Chart");
211 XTableCharts oCharts
= oSupp
.getCharts();
212 oCharts
.addNewByName("ScChartObj", oRect
, oAddr
, true, true);
214 // get the TableChart
215 XTableChart oChart
= null;
217 XNameAccess names
= (XNameAccess
) AnyConverter
.toObject(
218 new Type(XNameAccess
.class),UnoRuntime
.queryInterface(
219 XNameAccess
.class, oCharts
));
221 oChart
= (XTableChart
) AnyConverter
.toObject(
222 new Type(XTableChart
.class),names
.getByName("ScChartObj"));
224 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
225 log
.println("Couldn't get TableChart");
226 e
.printStackTrace(log
);
227 throw new StatusException("Couldn't get TableChart", e
);
228 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
229 log
.println("Couldn't get TableChart");
230 e
.printStackTrace(log
);
231 throw new StatusException("Couldn't get TableChart", e
);
232 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
233 log
.println("Couldn't get TableChart");
234 e
.printStackTrace(log
);
235 throw new StatusException("Couldn't get TableChart", e
);
238 log
.println("creating a new environment for object");
239 TestEnvironment tEnv
= new TestEnvironment(oChart
);
241 //adding ObjRelation 'setName' for 'XNamed'
242 tEnv
.addObjRelation("setName", new Boolean(true));
248 * Inserts a value or a formula in the cell of the spreasheet.
249 * @param CellX is the column index of the cell
250 * @param CellY is the row index of the cell
251 * @param theValue string representation of the value
252 * @param TT1 specify the spreadsheet, the interface
253 * <code>com.sun.star.sheet.XSpreadsheet</code>
254 * @param flag if it's equal to <code>'V'</code> then the method inserts
255 * a double-value in the cell else it inserts a formula in the cell
257 public static void insertIntoCell(
258 int CellX
, int CellY
, String theValue
, XSpreadsheet TT1
, String flag
)
263 oCell
= TT1
.getCellByPosition(CellX
, CellY
);
264 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ex
) {
265 System
.out
.println("Could not get Cell");
268 if (flag
.equals("V")) {
269 oCell
.setValue(new Float(theValue
).floatValue());
271 oCell
.setFormula(theValue
);
273 } // end of insertIntoCell