merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sch / ChXDiagram.java
blobedd12aafc8957d9337ce74e60b0d7bae50e7592a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChXDiagram.java,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sch;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
41 import com.sun.star.awt.Rectangle;
42 import com.sun.star.chart.XChartDataArray;
43 import com.sun.star.chart.XChartDocument;
44 import com.sun.star.chart.XDiagram;
45 import com.sun.star.container.XIndexAccess;
46 import com.sun.star.container.XNameAccess;
47 import com.sun.star.document.XEmbeddedObjectSupplier;
48 import com.sun.star.lang.XMultiServiceFactory;
49 import com.sun.star.sheet.XCellRangeAddressable;
50 import com.sun.star.sheet.XSpreadsheet;
51 import com.sun.star.sheet.XSpreadsheetDocument;
52 import com.sun.star.sheet.XSpreadsheets;
53 import com.sun.star.table.CellRangeAddress;
54 import com.sun.star.table.XCell;
55 import com.sun.star.table.XCellRange;
56 import com.sun.star.table.XTableChart;
57 import com.sun.star.table.XTableCharts;
58 import com.sun.star.table.XTableChartsSupplier;
59 import com.sun.star.uno.AnyConverter;
60 import com.sun.star.uno.Type;
61 import com.sun.star.uno.UnoRuntime;
62 import com.sun.star.uno.XInterface;
64 /**
65 * Test for object which is represented by the following services:
66 * <ul>
67 * <li> <code>com.sun.star.chart.Dim3DDiagram</code> </li>
68 * <li> <code>com.sun.star.chart.StockDiagram</code> </li>
69 * <li> <code>com.sun.star.chart.LineDiagram</code> </li>
70 * <li> <code>com.sun.star.chart.BarDiagram</code> </li>
71 * <li> <code>com.sun.star.chart.StackableDiagram</code> </li>
72 * </ul>
73 * <p>
74 * Object implements the following interfaces :
75 * <ul>
76 * <li> <code>com::sun::star::chart::XDiagram</code></li>
77 * <li> <code>com::sun::star::chart::ChartAxisXSupplier</code></li>
78 * <li> <code>com::sun::star::chart::Dim3DDiagram</code></li>
79 * <li> <code>com::sun::star::chart::StockDiagram</code></li>
80 * <li> <code>com::sun::star::chart::ChartAxisZSupplier</code></li>
81 * <li> <code>com::sun::star::chart::XTwoAxisXSupplier</code></li>
82 * <li> <code>com::sun::star::chart::LineDiagram</code></li>
83 * <li> <code>com::sun::star::chart::BarDiagram</code></li>
84 * <li> <code>com::sun::star::chart::XAxisYSupplier</code></li>
85 * <li> <code>com::sun::star::chart::Diagram</code></li>
86 * <li> <code>com::sun::star::chart::X3DDisplay</code></li>
87 * <li> <code>com::sun::star::chart::ChartTwoAxisYSupplier</code></li>
88 * <li> <code>com::sun::star::chart::StackableDiagram</code></li>
89 * <li> <code>com::sun::star::chart::ChartAxisYSupplier</code></li>
90 * <li> <code>com::sun::star::chart::XAxisXSupplier</code></li>
91 * <li> <code>com::sun::star::chart::ChartTwoAxisXSupplier</code></li>
92 * <li> <code>com::sun::star::drawing::XShape</code></li>
93 * <li> <code>com::sun::star::chart::XTwoAxisYSupplier</code></li>
94 * <li> <code>com::sun::star::chart::ChartStatistics</code></li>
95 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
96 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
97 * <li> <code>com::sun::star::chart::XAxisZSupplier</code></li>
98 * <li> <code>com::sun::star::chart::XStatisticDisplay</code></li>
99 * </ul>
100 * @see com.sun.star.chart.XDiagram
101 * @see com.sun.star.chart.ChartAxisXSupplier
102 * @see com.sun.star.chart.Dim3DDiagram
103 * @see com.sun.star.chart.StockDiagram
104 * @see com.sun.star.chart.ChartAxisZSupplier
105 * @see com.sun.star.chart.XTwoAxisXSupplier
106 * @see com.sun.star.chart.LineDiagram
107 * @see com.sun.star.chart.BarDiagram
108 * @see com.sun.star.chart.XAxisYSupplier
109 * @see com.sun.star.chart.Diagram
110 * @see com.sun.star.chart.X3DDisplay
111 * @see com.sun.star.chart.ChartTwoAxisYSupplier
112 * @see com.sun.star.chart.StackableDiagram
113 * @see com.sun.star.chart.ChartAxisYSupplier
114 * @see com.sun.star.chart.XAxisXSupplier
115 * @see com.sun.star.chart.ChartTwoAxisXSupplier
116 * @see com.sun.star.drawing.XShape
117 * @see com.sun.star.chart.XTwoAxisYSupplier
118 * @see com.sun.star.chart.ChartStatistics
119 * @see com.sun.star.beans.XPropertySet
120 * @see com.sun.star.drawing.XShapeDescriptor
121 * @see com.sun.star.chart.XAxisZSupplier
122 * @see com.sun.star.chart.XStatisticDisplay
123 * @see ifc.chart._XDiagram
124 * @see ifc.chart._ChartAxisXSupplier
125 * @see ifc.chart._Dim3DDiagram
126 * @see ifc.chart._StockDiagram
127 * @see ifc.chart._ChartAxisZSupplier
128 * @see ifc.chart._XTwoAxisXSupplier
129 * @see ifc.chart._LineDiagram
130 * @see ifc.chart._BarDiagram
131 * @see ifc.chart._XAxisYSupplier
132 * @see ifc.chart._Diagram
133 * @see ifc.chart._X3DDisplay
134 * @see ifc.chart._ChartTwoAxisYSupplier
135 * @see ifc.chart._StackableDiagram
136 * @see ifc.chart._ChartAxisYSupplier
137 * @see ifc.chart._XAxisXSupplier
138 * @see ifc.chart._ChartTwoAxisXSupplier
139 * @see ifc.drawing._XShape
140 * @see ifc.chart._XTwoAxisYSupplier
141 * @see ifc.chart._ChartStatistics
142 * @see ifc.beans._XPropertySet
143 * @see ifc.drawing._XShapeDescriptor
144 * @see ifc.chart._XAxisZSupplier
145 * @see ifc.chart._XStatisticDisplay
147 public class ChXDiagram extends TestCase {
148 XSpreadsheetDocument xSheetDoc = null;
151 * Creates Spreadsheet document.
153 protected void initialize( TestParameters tParam, PrintWriter log ) {
154 // get a soffice factory object
155 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
157 try {
158 log.println( "creating a sheetdocument" );
159 xSheetDoc = SOF.createCalcDoc(null);;
160 } catch (com.sun.star.uno.Exception e) {
161 // Some exception occures.FAILED
162 e.printStackTrace( log );
163 throw new StatusException( "Couldn't create document", e );
168 * Disposes Spreadsheet document.
170 protected void cleanup( TestParameters tParam, PrintWriter log ) {
171 log.println( " closing xSheetDoc " );
172 util.DesktopTools.closeDoc(xSheetDoc);
176 * Creating a Testenvironment for the interfaces to be tested.
177 * Retrieves a collection of spreadsheets from a document
178 * and takes one of them. Inserts some values into the cells of the some cell
179 * range address. Adds and retrieves the chart that using the data from
180 * the cells of this cell range address. Obtains the chart document which is
181 * embedded into the retrieved chart using the interface
182 * <code>XEmbeddedObjectSupplier</code>. Retrieves the diagram from
183 * the obtained chart document. The retrieved diagram is the instance of
184 * the service <code>com.sun.star.chart.Diagram</code>.
185 * Obtains the data source of the chart from the chart document.
186 * Creates a stock-diagram, a bar-diagram, a XY-diagram and line-diagram
187 * that are the instances of the following services:
188 * <ul>
189 * <li> <code>com.sun.star.chart.StockDiagram</code> </li>
190 * <li> <code>com.sun.star.chart.BarDiagram</code> </li>
191 * <li> <code>com.sun.star.chart.LineDiagram</code> </li>
192 * <li> <code>com.sun.star.chart.StackableDiagram</code> </li>
193 * </ul>.
194 * Object relations created :
195 * <ul>
196 * <li> <code>'CHARTDOC'</code> for
197 * {@link ifc.chart._Dim3DDiagram}, {@link ifc.chart._StockDiagram},
198 * {@link ifc.chart._ChartAxisZSupplier}, {@link _LineDiagram},
199 * {@link ifc.chart._BarDiagram}, {@link ifc.chart._Diagram},
200 * {@link ifc.chart._ChartTwoAxisYSupplier},
201 * {@link ifc.chart._StackableDiagram}, {@link ifc.chart._Diagram},
202 * {@link ifc.chart._ChartAxisYSupplier},
203 * {@link ifc.chart._ChartTwoAxisXSupplier},
204 * {@link ifc.chart._ChartStatistics} (the obtained chart document)</li>
205 * <li> <code>'ROWAMOUNT', 'COLAMOUNT'</code> for
206 * {@link ifc.chart._XDiagram}(the number of chart columns and
207 * the number of chart rows) </li>
208 * <li> <code>'STOCK'</code> for
209 * {@link ifc.chart._StockDiagram}(the created stock-diagram) </li>
210 * <li> <code>'BAR'</code> for
211 * {@link ifc.chart._BarDiagram}, {@link ifc.chart._ChartAxisZSupplier},
212 * {@link ifc.chart._ChartTwoAxisXSupplier},
213 * {@link ifc.chart._ChartTwoAxisYSupplier}(the created bar-diagram)</li>
214 * <li> <code>'LINE'</code> for
215 * {@link ifc.chart._LineDiagram}(the created XY-diagram) </li>
216 * <li> <code>'STACK'</code> for
217 * {@link ifc.chart._StackableDiagram}(the created Line-diagram) </li>
218 * </ul>
219 * @see com.sun.star.document.XEmbeddedObjectSupplier
220 * @see com.sun.star.chart.Diagram
221 * @see com.sun.star.chart.StockDiagram
223 protected synchronized TestEnvironment createTestEnvironment
224 (TestParameters Param, PrintWriter log) {
226 XSpreadsheet oSheet=null;
227 XChartDocument xChartDoc=null;
228 XDiagram oObj = null;
230 System.out.println("Getting spreadsheet") ;
231 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
232 XIndexAccess oIndexSheets = (XIndexAccess)
233 UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
234 try {
235 oSheet = (XSpreadsheet) AnyConverter.toObject(
236 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
237 } catch(com.sun.star.lang.WrappedTargetException e) {
238 e.printStackTrace(log);
239 throw new StatusException("Couldn't get sheet", e);
240 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
241 e.printStackTrace(log);
242 throw new StatusException("Couldn't get sheet", e);
243 } catch(com.sun.star.lang.IllegalArgumentException e) {
244 e.printStackTrace(log);
245 throw new StatusException("Couldn't get sheet", e);
248 log.println("Creating the Header") ;
250 insertIntoCell(1,0,"JAN",oSheet,"");
251 insertIntoCell(2,0,"FEB",oSheet,"");
252 insertIntoCell(3,0,"MAR",oSheet,"");
253 insertIntoCell(4,0,"APR",oSheet,"");
254 insertIntoCell(5,0,"MAI",oSheet,"");
255 insertIntoCell(6,0,"JUN",oSheet,"");
256 insertIntoCell(7,0,"JUL",oSheet,"");
257 insertIntoCell(8,0,"AUG",oSheet,"");
258 insertIntoCell(9,0,"SEP",oSheet,"");
259 insertIntoCell(10,0,"OCT",oSheet,"");
260 insertIntoCell(11,0,"NOV",oSheet,"");
261 insertIntoCell(12,0,"DEC",oSheet,"");
262 insertIntoCell(13,0,"SUM",oSheet,"");
264 log.println("Fill the lines");
266 insertIntoCell(0,1,"Smith",oSheet,"");
267 insertIntoCell(1,1,"42",oSheet,"V");
268 insertIntoCell(2,1,"58.9",oSheet,"V");
269 insertIntoCell(3,1,"-66.5",oSheet,"V");
270 insertIntoCell(4,1,"43.4",oSheet,"V");
271 insertIntoCell(5,1,"44.5",oSheet,"V");
272 insertIntoCell(6,1,"45.3",oSheet,"V");
273 insertIntoCell(7,1,"-67.3",oSheet,"V");
274 insertIntoCell(8,1,"30.5",oSheet,"V");
275 insertIntoCell(9,1,"23.2",oSheet,"V");
276 insertIntoCell(10,1,"-97.3",oSheet,"V");
277 insertIntoCell(11,1,"22.4",oSheet,"V");
278 insertIntoCell(12,1,"23.5",oSheet,"V");
279 insertIntoCell(13,1,"=SUM(B2:M2)",oSheet,"");
281 insertIntoCell(0,2,"Jones",oSheet,"");
282 insertIntoCell(1,2,"21",oSheet,"V");
283 insertIntoCell(2,2,"40.9",oSheet,"V");
284 insertIntoCell(3,2,"-57.5",oSheet,"V");
285 insertIntoCell(4,2,"-23.4",oSheet,"V");
286 insertIntoCell(5,2,"34.5",oSheet,"V");
287 insertIntoCell(6,2,"59.3",oSheet,"V");
288 insertIntoCell(7,2,"27.3",oSheet,"V");
289 insertIntoCell(8,2,"-38.5",oSheet,"V");
290 insertIntoCell(9,2,"43.2",oSheet,"V");
291 insertIntoCell(10,2,"57.3",oSheet,"V");
292 insertIntoCell(11,2,"25.4",oSheet,"V");
293 insertIntoCell(12,2,"28.5",oSheet,"V");
294 insertIntoCell(13,2,"=SUM(B3:M3)",oSheet,"");
296 insertIntoCell(0,3,"Brown",oSheet,"");
297 insertIntoCell(1,3,"31.45",oSheet,"V");
298 insertIntoCell(2,3,"-20.9",oSheet,"V");
299 insertIntoCell(3,3,"-117.5",oSheet,"V");
300 insertIntoCell(4,3,"23.4",oSheet,"V");
301 insertIntoCell(5,3,"-114.5",oSheet,"V");
302 insertIntoCell(6,3,"115.3",oSheet,"V");
303 insertIntoCell(7,3,"-171.3",oSheet,"V");
304 insertIntoCell(8,3,"89.5",oSheet,"V");
305 insertIntoCell(9,3,"41.2",oSheet,"V");
306 insertIntoCell(10,3,"71.3",oSheet,"V");
307 insertIntoCell(11,3,"25.4",oSheet,"V");
308 insertIntoCell(12,3,"38.5",oSheet,"V");
309 insertIntoCell(13,3,"=SUM(A4:L4)",oSheet,"");
311 // insert a chart
312 Rectangle oRect = new Rectangle(500, 3000, 25000, 11000);
314 XCellRange oRange = (XCellRange)
315 UnoRuntime.queryInterface(XCellRange.class, oSheet);
316 XCellRange myRange = oRange.getCellRangeByName("A1:N4");
317 XCellRangeAddressable oRangeAddr = (XCellRangeAddressable)
318 UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange);
319 CellRangeAddress myAddr = oRangeAddr.getRangeAddress();
321 CellRangeAddress[] oAddr = new CellRangeAddress[1];
322 oAddr[0] = myAddr;
323 XTableChartsSupplier oSupp = (XTableChartsSupplier)
324 UnoRuntime.queryInterface(XTableChartsSupplier.class, oSheet);
326 log.println("Insert Chart");
327 XTableCharts oCharts = oSupp.getCharts();
330 if (!oCharts.hasByName("ChXDiagram")) {
331 oCharts.addNewByName("ChXDiagram", oRect, oAddr, true, true);
334 // get the TableChart
335 XTableChart oChart = null;
336 try {
337 oChart = (XTableChart) AnyConverter.toObject(
338 new Type(XTableChart.class),((XNameAccess)
339 UnoRuntime.queryInterface(
340 XNameAccess.class, oCharts)).getByName("ChXDiagram"));
341 } catch (com.sun.star.lang.WrappedTargetException e) {
342 e.printStackTrace(log);
343 throw new StatusException("Couldn't get TableChart", e);
344 } catch (com.sun.star.container.NoSuchElementException e) {
345 e.printStackTrace(log);
346 throw new StatusException("Couldn't get TableChart", e);
347 } catch (com.sun.star.lang.IllegalArgumentException e) {
348 e.printStackTrace(log);
349 throw new StatusException("Couldn't get TableChart", e);
352 XEmbeddedObjectSupplier oEOS = (XEmbeddedObjectSupplier)
353 UnoRuntime.queryInterface(XEmbeddedObjectSupplier.class, oChart);
354 XInterface oInt = oEOS.getEmbeddedObject();
355 xChartDoc = (XChartDocument)
356 UnoRuntime.queryInterface(XChartDocument.class,oInt);
357 oObj = (XDiagram) xChartDoc.getDiagram();
359 log.println( "creating a new environment for chartdocument object" );
360 TestEnvironment tEnv = new TestEnvironment( oObj );
362 log.println( "adding ChartDocument as mod relation to environment" );
363 tEnv.addObjRelation("CHARTDOC", xChartDoc);
365 XChartDataArray da = (XChartDataArray)
366 UnoRuntime.queryInterface(XChartDataArray.class, xChartDoc.getData());
367 int cols = da.getColumnDescriptions().length;
368 int rows = da.getRowDescriptions().length;
370 tEnv.addObjRelation("ROWAMOUNT", new Integer(rows));
371 tEnv.addObjRelation("COLAMOUNT", new Integer(cols));
373 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
374 Object stock = SOF.createDiagram(xChartDoc,"StockDiagram");
375 tEnv.addObjRelation("STOCK",stock);
377 Object bar = SOF.createDiagram(xChartDoc,"BarDiagram");
378 tEnv.addObjRelation("BAR",bar);
380 Object line = SOF.createDiagram(xChartDoc,"XYDiagram");
381 tEnv.addObjRelation("LINE",line);
383 Object stack = SOF.createDiagram(xChartDoc,"LineDiagram");
384 tEnv.addObjRelation("STACK",stack);
386 return tEnv;
387 } // finish method getTestEnvironment
390 * Inserts a value or a formula in the cell of the spreasheet.
391 * @param CellX is the column index of the cell
392 * @param CellY is the row index of the cell
393 * @param theValue string representation of the value
394 * @param TT1 specify the spreadsheet, the interface
395 * <code>com.sun.star.sheet.XSpreadsheet</code>
396 * @param flag if it's equal to <code>'V'</code> then the method inserts
397 * a double-value in the cell else it inserts a formula in the cell
399 public static void insertIntoCell(
400 int CellX, int CellY, String theValue, XSpreadsheet TT1, String flag) {
402 XCell oCell = null;
404 try {
405 oCell = TT1.getCellByPosition(CellX, CellY);
406 } catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
407 System.out.println("Could not get Cell");
409 if (flag.equals("V")) {oCell.setValue((new Float(theValue)).floatValue());}
410 else {oCell.setFormula(theValue);}
412 } // end of insertIntoCell
415 } // finish class ChXDiagram