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
.chart
.XChartDataArray
;
31 import com
.sun
.star
.chart
.XChartDocument
;
32 import com
.sun
.star
.chart
.XDiagram
;
33 import com
.sun
.star
.container
.XIndexAccess
;
34 import com
.sun
.star
.container
.XNameAccess
;
35 import com
.sun
.star
.document
.XEmbeddedObjectSupplier
;
36 import com
.sun
.star
.lang
.XMultiServiceFactory
;
37 import com
.sun
.star
.sheet
.XCellRangeAddressable
;
38 import com
.sun
.star
.sheet
.XSpreadsheet
;
39 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
40 import com
.sun
.star
.sheet
.XSpreadsheets
;
41 import com
.sun
.star
.table
.CellRangeAddress
;
42 import com
.sun
.star
.table
.XCell
;
43 import com
.sun
.star
.table
.XCellRange
;
44 import com
.sun
.star
.table
.XTableChart
;
45 import com
.sun
.star
.table
.XTableCharts
;
46 import com
.sun
.star
.table
.XTableChartsSupplier
;
47 import com
.sun
.star
.uno
.AnyConverter
;
48 import com
.sun
.star
.uno
.Type
;
49 import com
.sun
.star
.uno
.UnoRuntime
;
50 import com
.sun
.star
.uno
.XInterface
;
53 * Test for object which is represented by the following services:
55 * <li> <code>com.sun.star.chart.Dim3DDiagram</code> </li>
56 * <li> <code>com.sun.star.chart.StockDiagram</code> </li>
57 * <li> <code>com.sun.star.chart.LineDiagram</code> </li>
58 * <li> <code>com.sun.star.chart.BarDiagram</code> </li>
59 * <li> <code>com.sun.star.chart.StackableDiagram</code> </li>
62 * Object implements the following interfaces :
64 * <li> <code>com::sun::star::chart::XDiagram</code></li>
65 * <li> <code>com::sun::star::chart::ChartAxisXSupplier</code></li>
66 * <li> <code>com::sun::star::chart::Dim3DDiagram</code></li>
67 * <li> <code>com::sun::star::chart::StockDiagram</code></li>
68 * <li> <code>com::sun::star::chart::ChartAxisZSupplier</code></li>
69 * <li> <code>com::sun::star::chart::XTwoAxisXSupplier</code></li>
70 * <li> <code>com::sun::star::chart::LineDiagram</code></li>
71 * <li> <code>com::sun::star::chart::BarDiagram</code></li>
72 * <li> <code>com::sun::star::chart::XAxisYSupplier</code></li>
73 * <li> <code>com::sun::star::chart::Diagram</code></li>
74 * <li> <code>com::sun::star::chart::X3DDisplay</code></li>
75 * <li> <code>com::sun::star::chart::ChartTwoAxisYSupplier</code></li>
76 * <li> <code>com::sun::star::chart::StackableDiagram</code></li>
77 * <li> <code>com::sun::star::chart::ChartAxisYSupplier</code></li>
78 * <li> <code>com::sun::star::chart::XAxisXSupplier</code></li>
79 * <li> <code>com::sun::star::chart::ChartTwoAxisXSupplier</code></li>
80 * <li> <code>com::sun::star::drawing::XShape</code></li>
81 * <li> <code>com::sun::star::chart::XTwoAxisYSupplier</code></li>
82 * <li> <code>com::sun::star::chart::ChartStatistics</code></li>
83 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
84 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
85 * <li> <code>com::sun::star::chart::XAxisZSupplier</code></li>
86 * <li> <code>com::sun::star::chart::XStatisticDisplay</code></li>
88 * @see com.sun.star.chart.XDiagram
89 * @see com.sun.star.chart.ChartAxisXSupplier
90 * @see com.sun.star.chart.Dim3DDiagram
91 * @see com.sun.star.chart.StockDiagram
92 * @see com.sun.star.chart.ChartAxisZSupplier
93 * @see com.sun.star.chart.XTwoAxisXSupplier
94 * @see com.sun.star.chart.LineDiagram
95 * @see com.sun.star.chart.BarDiagram
96 * @see com.sun.star.chart.XAxisYSupplier
97 * @see com.sun.star.chart.Diagram
98 * @see com.sun.star.chart.X3DDisplay
99 * @see com.sun.star.chart.ChartTwoAxisYSupplier
100 * @see com.sun.star.chart.StackableDiagram
101 * @see com.sun.star.chart.ChartAxisYSupplier
102 * @see com.sun.star.chart.XAxisXSupplier
103 * @see com.sun.star.chart.ChartTwoAxisXSupplier
104 * @see com.sun.star.drawing.XShape
105 * @see com.sun.star.chart.XTwoAxisYSupplier
106 * @see com.sun.star.chart.ChartStatistics
107 * @see com.sun.star.beans.XPropertySet
108 * @see com.sun.star.drawing.XShapeDescriptor
109 * @see com.sun.star.chart.XAxisZSupplier
110 * @see com.sun.star.chart.XStatisticDisplay
111 * @see ifc.chart._XDiagram
112 * @see ifc.chart._ChartAxisXSupplier
113 * @see ifc.chart._Dim3DDiagram
114 * @see ifc.chart._StockDiagram
115 * @see ifc.chart._ChartAxisZSupplier
116 * @see ifc.chart._XTwoAxisXSupplier
117 * @see ifc.chart._LineDiagram
118 * @see ifc.chart._BarDiagram
119 * @see ifc.chart._XAxisYSupplier
120 * @see ifc.chart._Diagram
121 * @see ifc.chart._X3DDisplay
122 * @see ifc.chart._ChartTwoAxisYSupplier
123 * @see ifc.chart._StackableDiagram
124 * @see ifc.chart._ChartAxisYSupplier
125 * @see ifc.chart._XAxisXSupplier
126 * @see ifc.chart._ChartTwoAxisXSupplier
127 * @see ifc.drawing._XShape
128 * @see ifc.chart._XTwoAxisYSupplier
129 * @see ifc.chart._ChartStatistics
130 * @see ifc.beans._XPropertySet
131 * @see ifc.drawing._XShapeDescriptor
132 * @see ifc.chart._XAxisZSupplier
133 * @see ifc.chart._XStatisticDisplay
135 public class ChXDiagram
extends TestCase
{
136 XSpreadsheetDocument xSheetDoc
= null;
139 * Creates Spreadsheet document.
141 protected void initialize( TestParameters tParam
, PrintWriter log
) {
142 // get a soffice factory object
143 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
146 log
.println( "creating a sheetdocument" );
147 xSheetDoc
= SOF
.createCalcDoc(null);
148 } catch (com
.sun
.star
.uno
.Exception e
) {
149 // Some exception occurs.FAILED
150 e
.printStackTrace( log
);
151 throw new StatusException( "Couldn't create document", e
);
156 * Disposes Spreadsheet document.
158 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
159 log
.println( " closing xSheetDoc " );
160 util
.DesktopTools
.closeDoc(xSheetDoc
);
164 * Creating a Testenvironment for the interfaces to be tested.
165 * Retrieves a collection of spreadsheets from a document
166 * and takes one of them. Inserts some values into the cells of the some cell
167 * range address. Adds and retrieves the chart that using the data from
168 * the cells of this cell range address. Obtains the chart document which is
169 * embedded into the retrieved chart using the interface
170 * <code>XEmbeddedObjectSupplier</code>. Retrieves the diagram from
171 * the obtained chart document. The retrieved diagram is the instance of
172 * the service <code>com.sun.star.chart.Diagram</code>.
173 * Obtains the data source of the chart from the chart document.
174 * Creates a stock-diagram, a bar-diagram, a XY-diagram and line-diagram
175 * that are the instances of the following services:
177 * <li> <code>com.sun.star.chart.StockDiagram</code> </li>
178 * <li> <code>com.sun.star.chart.BarDiagram</code> </li>
179 * <li> <code>com.sun.star.chart.LineDiagram</code> </li>
180 * <li> <code>com.sun.star.chart.StackableDiagram</code> </li>
182 * Object relations created :
184 * <li> <code>'CHARTDOC'</code> for
185 * {@link ifc.chart._Dim3DDiagram}, {@link ifc.chart._StockDiagram},
186 * {@link ifc.chart._ChartAxisZSupplier}, {@link ifc.chart._LineDiagram},
187 * {@link ifc.chart._BarDiagram}, {@link ifc.chart._Diagram},
188 * {@link ifc.chart._ChartTwoAxisYSupplier},
189 * {@link ifc.chart._StackableDiagram}, {@link ifc.chart._Diagram},
190 * {@link ifc.chart._ChartAxisYSupplier},
191 * {@link ifc.chart._ChartTwoAxisXSupplier},
192 * {@link ifc.chart._ChartStatistics} (the obtained chart document)</li>
193 * <li> <code>'ROWAMOUNT', 'COLAMOUNT'</code> for
194 * {@link ifc.chart._XDiagram}(the number of chart columns and
195 * the number of chart rows) </li>
196 * <li> <code>'STOCK'</code> for
197 * {@link ifc.chart._StockDiagram}(the created stock-diagram) </li>
198 * <li> <code>'BAR'</code> for
199 * {@link ifc.chart._BarDiagram}, {@link ifc.chart._ChartAxisZSupplier},
200 * {@link ifc.chart._ChartTwoAxisXSupplier},
201 * {@link ifc.chart._ChartTwoAxisYSupplier}(the created bar-diagram)</li>
202 * <li> <code>'LINE'</code> for
203 * {@link ifc.chart._LineDiagram}(the created XY-diagram) </li>
204 * <li> <code>'STACK'</code> for
205 * {@link ifc.chart._StackableDiagram}(the created Line-diagram) </li>
207 * @see com.sun.star.document.XEmbeddedObjectSupplier
208 * @see com.sun.star.chart.Diagram
209 * @see com.sun.star.chart.StockDiagram
211 protected synchronized TestEnvironment createTestEnvironment
212 (TestParameters Param
, PrintWriter log
) {
214 XSpreadsheet oSheet
=null;
215 XChartDocument xChartDoc
=null;
216 XDiagram oObj
= null;
218 System
.out
.println("Getting spreadsheet") ;
219 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
220 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
222 oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
223 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
224 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
225 e
.printStackTrace(log
);
226 throw new StatusException("Couldn't get sheet", e
);
227 } catch(com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
228 e
.printStackTrace(log
);
229 throw new StatusException("Couldn't get sheet", e
);
230 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
231 e
.printStackTrace(log
);
232 throw new StatusException("Couldn't get sheet", e
);
235 log
.println("Creating the Header") ;
237 insertIntoCell(1,0,"JAN",oSheet
,"");
238 insertIntoCell(2,0,"FEB",oSheet
,"");
239 insertIntoCell(3,0,"MAR",oSheet
,"");
240 insertIntoCell(4,0,"APR",oSheet
,"");
241 insertIntoCell(5,0,"MAI",oSheet
,"");
242 insertIntoCell(6,0,"JUN",oSheet
,"");
243 insertIntoCell(7,0,"JUL",oSheet
,"");
244 insertIntoCell(8,0,"AUG",oSheet
,"");
245 insertIntoCell(9,0,"SEP",oSheet
,"");
246 insertIntoCell(10,0,"OCT",oSheet
,"");
247 insertIntoCell(11,0,"NOV",oSheet
,"");
248 insertIntoCell(12,0,"DEC",oSheet
,"");
249 insertIntoCell(13,0,"SUM",oSheet
,"");
251 log
.println("Fill the lines");
253 insertIntoCell(0,1,"Smith",oSheet
,"");
254 insertIntoCell(1,1,"42",oSheet
,"V");
255 insertIntoCell(2,1,"58.9",oSheet
,"V");
256 insertIntoCell(3,1,"-66.5",oSheet
,"V");
257 insertIntoCell(4,1,"43.4",oSheet
,"V");
258 insertIntoCell(5,1,"44.5",oSheet
,"V");
259 insertIntoCell(6,1,"45.3",oSheet
,"V");
260 insertIntoCell(7,1,"-67.3",oSheet
,"V");
261 insertIntoCell(8,1,"30.5",oSheet
,"V");
262 insertIntoCell(9,1,"23.2",oSheet
,"V");
263 insertIntoCell(10,1,"-97.3",oSheet
,"V");
264 insertIntoCell(11,1,"22.4",oSheet
,"V");
265 insertIntoCell(12,1,"23.5",oSheet
,"V");
266 insertIntoCell(13,1,"=SUM(B2:M2)",oSheet
,"");
268 insertIntoCell(0,2,"Jones",oSheet
,"");
269 insertIntoCell(1,2,"21",oSheet
,"V");
270 insertIntoCell(2,2,"40.9",oSheet
,"V");
271 insertIntoCell(3,2,"-57.5",oSheet
,"V");
272 insertIntoCell(4,2,"-23.4",oSheet
,"V");
273 insertIntoCell(5,2,"34.5",oSheet
,"V");
274 insertIntoCell(6,2,"59.3",oSheet
,"V");
275 insertIntoCell(7,2,"27.3",oSheet
,"V");
276 insertIntoCell(8,2,"-38.5",oSheet
,"V");
277 insertIntoCell(9,2,"43.2",oSheet
,"V");
278 insertIntoCell(10,2,"57.3",oSheet
,"V");
279 insertIntoCell(11,2,"25.4",oSheet
,"V");
280 insertIntoCell(12,2,"28.5",oSheet
,"V");
281 insertIntoCell(13,2,"=SUM(B3:M3)",oSheet
,"");
283 insertIntoCell(0,3,"Brown",oSheet
,"");
284 insertIntoCell(1,3,"31.45",oSheet
,"V");
285 insertIntoCell(2,3,"-20.9",oSheet
,"V");
286 insertIntoCell(3,3,"-117.5",oSheet
,"V");
287 insertIntoCell(4,3,"23.4",oSheet
,"V");
288 insertIntoCell(5,3,"-114.5",oSheet
,"V");
289 insertIntoCell(6,3,"115.3",oSheet
,"V");
290 insertIntoCell(7,3,"-171.3",oSheet
,"V");
291 insertIntoCell(8,3,"89.5",oSheet
,"V");
292 insertIntoCell(9,3,"41.2",oSheet
,"V");
293 insertIntoCell(10,3,"71.3",oSheet
,"V");
294 insertIntoCell(11,3,"25.4",oSheet
,"V");
295 insertIntoCell(12,3,"38.5",oSheet
,"V");
296 insertIntoCell(13,3,"=SUM(A4:L4)",oSheet
,"");
299 Rectangle oRect
= new Rectangle(500, 3000, 25000, 11000);
301 XCellRange oRange
= UnoRuntime
.queryInterface(XCellRange
.class, oSheet
);
302 XCellRange myRange
= oRange
.getCellRangeByName("A1:N4");
303 XCellRangeAddressable oRangeAddr
= UnoRuntime
.queryInterface(XCellRangeAddressable
.class, myRange
);
304 CellRangeAddress myAddr
= oRangeAddr
.getRangeAddress();
306 CellRangeAddress
[] oAddr
= new CellRangeAddress
[1];
308 XTableChartsSupplier oSupp
= UnoRuntime
.queryInterface(XTableChartsSupplier
.class, oSheet
);
310 log
.println("Insert Chart");
311 XTableCharts oCharts
= oSupp
.getCharts();
314 if (!oCharts
.hasByName("ChXDiagram")) {
315 oCharts
.addNewByName("ChXDiagram", oRect
, oAddr
, true, true);
318 // get the TableChart
319 XTableChart oChart
= null;
321 oChart
= (XTableChart
) AnyConverter
.toObject(
322 new Type(XTableChart
.class),UnoRuntime
.queryInterface(
323 XNameAccess
.class, oCharts
).getByName("ChXDiagram"));
324 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
325 e
.printStackTrace(log
);
326 throw new StatusException("Couldn't get TableChart", e
);
327 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
328 e
.printStackTrace(log
);
329 throw new StatusException("Couldn't get TableChart", e
);
330 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
331 e
.printStackTrace(log
);
332 throw new StatusException("Couldn't get TableChart", e
);
335 XEmbeddedObjectSupplier oEOS
= UnoRuntime
.queryInterface(XEmbeddedObjectSupplier
.class, oChart
);
336 XInterface oInt
= oEOS
.getEmbeddedObject();
337 xChartDoc
= UnoRuntime
.queryInterface(XChartDocument
.class,oInt
);
338 oObj
= xChartDoc
.getDiagram();
340 log
.println( "creating a new environment for chartdocument object" );
341 TestEnvironment tEnv
= new TestEnvironment( oObj
);
343 log
.println( "adding ChartDocument as mod relation to environment" );
344 tEnv
.addObjRelation("CHARTDOC", xChartDoc
);
346 XChartDataArray da
= UnoRuntime
.queryInterface(XChartDataArray
.class, xChartDoc
.getData());
347 int cols
= da
.getColumnDescriptions().length
;
348 int rows
= da
.getRowDescriptions().length
;
350 tEnv
.addObjRelation("ROWAMOUNT", new Integer(rows
));
351 tEnv
.addObjRelation("COLAMOUNT", new Integer(cols
));
353 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)Param
.getMSF());
354 Object stock
= SOF
.createDiagram(xChartDoc
,"StockDiagram");
355 tEnv
.addObjRelation("STOCK",stock
);
357 Object bar
= SOF
.createDiagram(xChartDoc
,"BarDiagram");
358 tEnv
.addObjRelation("BAR",bar
);
360 Object line
= SOF
.createDiagram(xChartDoc
,"XYDiagram");
361 tEnv
.addObjRelation("LINE",line
);
363 Object stack
= SOF
.createDiagram(xChartDoc
,"LineDiagram");
364 tEnv
.addObjRelation("STACK",stack
);
367 } // finish method getTestEnvironment
370 * Inserts a value or a formula in the cell of the spreasheet.
371 * @param CellX is the column index of the cell
372 * @param CellY is the row index of the cell
373 * @param theValue string representation of the value
374 * @param TT1 specify the spreadsheet, the interface
375 * <code>com.sun.star.sheet.XSpreadsheet</code>
376 * @param flag if it's equal to <code>'V'</code> then the method inserts
377 * a double-value in the cell else it inserts a formula in the cell
379 public static void insertIntoCell(
380 int CellX
, int CellY
, String theValue
, XSpreadsheet TT1
, String flag
) {
385 oCell
= TT1
.getCellByPosition(CellX
, CellY
);
386 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ex
) {
387 System
.out
.println("Could not get Cell");
389 if (flag
.equals("V")) {oCell
.setValue((new Float(theValue
)).floatValue());}
390 else {oCell
.setFormula(theValue
);}
392 } // end of insertIntoCell
395 } // finish class ChXDiagram