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