Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / qa / TestCaseOldAPI.java
blobf5bc4f571c4c3d6758026fcfe9c6b62621c61b5c
1 /*
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 .
19 // package name: as default, start with complex
20 package qa;
22 import complexlib.ComplexTestCase;
23 import com.sun.star.uno.UnoRuntime;
24 import com.sun.star.uno.Type;
25 import java.io.PrintWriter;
26 import com.sun.star.lang.*;
27 import com.sun.star.beans.*;
28 import com.sun.star.frame.*;
29 import com.sun.star.chart.*;
30 import com.sun.star.drawing.*;
31 import com.sun.star.awt.*;
32 import com.sun.star.container.*;
33 import com.sun.star.util.XCloseable;
34 import com.sun.star.util.CloseVetoException;
35 import com.sun.star.uno.AnyConverter;
36 import util.utils;
38 /**
39 * The following Complex Test will test the
40 * com.sun.star.document.IndexedPropertyValues
41 * service
44 public class TestCaseOldAPI extends ComplexTestCase {
46 // The name of the tested service
47 private static final String testedServiceName =
48 "com.sun.star.chart.ChartDocument";
50 // The first of the mandatory functions:
51 /**
52 * Return the name of the test.
53 * In this case it is the actual name of the service.
54 * @return The tested service.
56 @Override
57 public String getTestObjectName() {
58 return testedServiceName;
61 // The second of the mandatory functions: return all test methods as an
62 // array. There is only one test function in this example.
63 /**
64 * Return all test methods.
65 * @return The test methods.
67 @Override
68 public String[] getTestMethodNames() {
69 // For some tests a view needs to be created. Accessing the model via
70 // this program and the view may lead to problems
71 boolean bAvoidViewCreation = false;
73 if( bAvoidViewCreation )
74 return new String[] {
75 "testData",
76 "testChartType",
77 "testArea",
78 "testAggregation",
79 "testFactory",
80 "testDataSeriesAndPoints",
81 "testStatistics",
82 "testStockProperties"
85 return new String[] {
86 "testData",
87 "testChartType",
88 "testTitle",
89 "testSubTitle",
90 "testDiagram",
91 "testAxis",
92 "testLegend",
93 "testArea",
94 "testAggregation",
95 "testFactory",
96 "testDataSeriesAndPoints",
97 "testStatistics",
98 "testStockProperties"
104 public void before()
106 // set to "true" to get a view
107 mbCreateView = true;
109 if( mbCreateView )
110 mxChartModel = createDocument( "schart" );
111 else
112 mxChartModel = createChartModel();
114 mxOldDoc = UnoRuntime.queryInterface(
115 XChartDocument.class, mxChartModel );
120 public void after()
122 XCloseable xCloseable = UnoRuntime.queryInterface(
123 XCloseable.class, mxChartModel );
124 assure( "document is no XCloseable", xCloseable != null );
126 // do not close document if there exists a view
127 if( ! mbCreateView )
131 xCloseable.close( true );
133 catch( CloseVetoException ex )
135 failed( ex.getMessage() );
136 ex.printStackTrace( (PrintWriter)log );
143 public void testTitle()
147 XPropertySet xDocProp = UnoRuntime.queryInterface(
148 XPropertySet.class, mxOldDoc );
149 assure( "Chart Document is no XPropertySet", xDocProp != null );
150 xDocProp.setPropertyValue( "HasMainTitle", Boolean.TRUE);
151 assure( "Property HasMainTitle", AnyConverter.toBoolean(
152 xDocProp.getPropertyValue( "HasMainTitle" )));
154 XShape xTitleShape = mxOldDoc.getTitle();
155 XPropertySet xTitleProp = UnoRuntime.queryInterface(
156 XPropertySet.class, xTitleShape );
158 // set property via old API
159 if( xTitleProp != null )
161 String aTitle = " Overwritten by Old API ";
162 float fHeight = (float)17.0;
164 xTitleProp.setPropertyValue( "String", aTitle );
165 xTitleProp.setPropertyValue( "CharHeight", Float.valueOf( fHeight ) );
167 float fNewHeight = AnyConverter.toFloat( xTitleProp.getPropertyValue( "CharHeight" ) );
168 assure( "Changing CharHeight via old API failed", fNewHeight == fHeight );
170 String aNewTitle = AnyConverter.toString( xTitleProp.getPropertyValue( "String" ) );
171 assure( "Property \"String\" failed", aNewTitle.equals( aTitle ));
174 // move title
175 Point aSetPos = new Point();
176 aSetPos.X = 1000;
177 aSetPos.Y = 200;
178 xTitleShape.setPosition( aSetPos );
180 Point aNewPos = xTitleShape.getPosition();
181 assure( "Title Position X", approxEqual( aNewPos.X, aSetPos.X, 1 ));
182 assure( "Title Position Y", approxEqual( aNewPos.Y, aSetPos.Y, 1 ));
184 catch( Exception ex )
186 failed( ex.getMessage() );
187 ex.printStackTrace( (PrintWriter)log );
193 public void testSubTitle()
197 XPropertySet xDocProp = UnoRuntime.queryInterface(
198 XPropertySet.class, mxOldDoc );
199 assure( "Chart Document is no XPropertySet", xDocProp != null );
200 xDocProp.setPropertyValue( "HasSubTitle", Boolean.TRUE);
201 assure( "Property HasSubTitle", AnyConverter.toBoolean(
202 xDocProp.getPropertyValue( "HasSubTitle" )));
204 XShape xTitleShape = mxOldDoc.getSubTitle();
205 XPropertySet xTitleProp = UnoRuntime.queryInterface(
206 XPropertySet.class, xTitleShape );
208 // set Property via old API
209 if( xTitleProp != null )
211 int nColor = 0x009acd; // DeepSkyBlue3
212 float fWeight = FontWeight.BOLD;
213 float fHeight = (float)14.0;
215 xTitleProp.setPropertyValue( "CharColor", Integer.valueOf( nColor ) );
216 xTitleProp.setPropertyValue( "CharWeight", Float.valueOf( fWeight ));
217 xTitleProp.setPropertyValue( "CharHeight", Float.valueOf( fHeight ) );
219 int nNewColor = AnyConverter.toInt( xTitleProp.getPropertyValue( "CharColor" ) );
220 assure( "Changing CharColor via old API failed", nNewColor == nColor );
222 float fNewWeight = AnyConverter.toFloat( xTitleProp.getPropertyValue( "CharWeight" ) );
223 assure( "Changing CharWeight via old API failed", fNewWeight == fWeight );
225 float fNewHeight = AnyConverter.toFloat( xTitleProp.getPropertyValue( "CharHeight" ) );
226 assure( "Changing CharHeight via old API failed", fNewHeight == fHeight );
229 catch( Exception ex )
231 failed( ex.getMessage() );
232 ex.printStackTrace( (PrintWriter)log );
238 public void testDiagram()
242 // testing wall
243 XDiagram xDia = mxOldDoc.getDiagram();
244 if( xDia != null )
246 X3DDisplay xDisp = UnoRuntime.queryInterface(
247 X3DDisplay.class, xDia );
248 assure( "X3DDisplay not supported", xDisp != null );
250 // Wall
251 XPropertySet xProp = xDisp.getWall();
252 if( xProp != null )
254 int nColor = 0xffe1ff; // thistle1
255 xProp.setPropertyValue( "FillColor", Integer.valueOf( nColor ) );
256 int nNewColor = AnyConverter.toInt( xProp.getPropertyValue( "FillColor" ) );
257 assure( "Changing FillColor via old API failed", nNewColor == nColor );
260 assure( "Wrong Diagram Type", xDia.getDiagramType().equals(
261 "com.sun.star.chart.BarDiagram" ));
263 // Diagram properties
264 xProp = UnoRuntime.queryInterface( XPropertySet.class, xDia );
265 assure( "Diagram is no property set", xProp != null );
267 // y-axis
268 boolean bFirstYAxisText = false;
269 xProp.setPropertyValue( "HasYAxisDescription", Boolean.valueOf( bFirstYAxisText ));
270 boolean bNewFirstYAxisText = AnyConverter.toBoolean(
271 xProp.getPropertyValue( "HasYAxisDescription" ));
272 assure( "Removing description of first y-axis", bNewFirstYAxisText == bFirstYAxisText );
274 // second y-axis
275 boolean bSecondaryYAxis = true;
276 xProp.setPropertyValue( "HasSecondaryYAxis", Boolean.valueOf( bSecondaryYAxis ));
277 boolean bNewSecYAxisValue = AnyConverter.toBoolean(
278 xProp.getPropertyValue( "HasSecondaryYAxis" ));
279 assure( "Adding a second y-axis does not work", bNewSecYAxisValue == bSecondaryYAxis );
281 XTwoAxisYSupplier xSecYAxisSuppl = UnoRuntime.queryInterface(
282 XTwoAxisYSupplier.class, xDia );
283 assure( "XTwoAxisYSupplier not implemented", xSecYAxisSuppl != null );
284 assure( "No second y-axis found", xSecYAxisSuppl.getSecondaryYAxis() != null );
287 // move diagram
289 XShape xDiagramShape = UnoRuntime.queryInterface(
290 XShape.class, xDia );
292 Point aOldPos = xDiagramShape.getPosition();
293 int xDiff = 20;
294 int yDiff = 20;
295 Point aSetPos = new Point();
296 aSetPos.X = aOldPos.X + xDiff;
297 aSetPos.Y = aOldPos.Y + yDiff;
298 xDiagramShape.setPosition( aSetPos );
300 Point aNewPos = xDiagramShape.getPosition();
301 assure( "Diagram Position X", approxEqual( aNewPos.X, aSetPos.X, 1 ));
302 assure( "Diagram Position Y", approxEqual( aNewPos.Y, aSetPos.Y, 1 ));
305 // size diagram
307 XShape xDiagramShape = UnoRuntime.queryInterface(
308 XShape.class, xDia );
310 Size aOldSize = xDiagramShape.getSize();
311 int xDiff = aOldSize.Width/2+2;
312 int yDiff = aOldSize.Height/2+2;
313 Size aSetSize = new Size();
314 aSetSize.Width = aOldSize.Width - xDiff;
315 aSetSize.Height = aOldSize.Height - yDiff;
316 xDiagramShape.setSize( aSetSize );
318 Size aNewSize = xDiagramShape.getSize();
319 assure( "Diagram Width", approxEqual( aNewSize.Width, aSetSize.Width, 2 ));
320 assure( "Diagram Height", approxEqual( aNewSize.Height, aSetSize.Height, 2 ));
323 catch( Exception ex )
325 failed( ex.getMessage() );
326 ex.printStackTrace( (PrintWriter)log );
332 public void testAxis()
336 XAxisYSupplier xYAxisSuppl = UnoRuntime.queryInterface(
337 XAxisYSupplier.class, mxOldDoc.getDiagram() );
338 assure( "Diagram is no y-axis supplier", xYAxisSuppl != null );
340 XPropertySet xProp = xYAxisSuppl.getYAxis();
341 assure( "No y-axis found", xProp != null );
343 double fMax1, fMax2;
344 Object oMax = xProp.getPropertyValue( "Max" );
345 assure( "No Maximum set", AnyConverter.isDouble( oMax ));
346 fMax1 = AnyConverter.toDouble( oMax );
347 log.println( "Maximum retrieved: " + fMax1 );
348 //todo: the view has to be built before there is an explicit value
349 xProp.setPropertyValue( "AutoMax", Boolean.FALSE);
350 oMax = xProp.getPropertyValue( "Max" );
351 assure( "No Maximum set", AnyConverter.isDouble( oMax ));
352 fMax2 = AnyConverter.toDouble( oMax );
353 log.println( "Maximum with AutoMax off: " + fMax2 );
354 assure( "maxima differ", fMax1 == fMax2 );
356 double nNewMax = 12.3;
357 double nNewOrigin = 2.7;
359 xProp.setPropertyValue( "Max", Double.valueOf( nNewMax ));
360 assure( "AutoMax is on", ! AnyConverter.toBoolean( xProp.getPropertyValue( "AutoMax" )) );
362 assure( "Maximum value invalid",
363 utils.approxEqual(
364 AnyConverter.toDouble( xProp.getPropertyValue( "Max" )),
365 nNewMax ));
367 xProp.setPropertyValue( "AutoMin", Boolean.TRUE);
368 assure( "AutoMin is off", AnyConverter.toBoolean( xProp.getPropertyValue( "AutoMin" )) );
370 xProp.setPropertyValue( "Origin", Double.valueOf( nNewOrigin ));
371 assure( "Origin invalid",
372 utils.approxEqual(
373 AnyConverter.toDouble( xProp.getPropertyValue( "Origin" )),
374 nNewOrigin ));
375 xProp.setPropertyValue( "AutoOrigin", Boolean.TRUE);
376 assure( "AutoOrigin is off", AnyConverter.toBoolean( xProp.getPropertyValue( "AutoOrigin" )) );
377 Object oOrigin = xProp.getPropertyValue( "Origin" );
378 assure( "No Origin set", AnyConverter.isDouble( oOrigin ));
379 log.println( "Origin retrieved: " + AnyConverter.toDouble( oOrigin ));
381 xProp.setPropertyValue( "Logarithmic", Boolean.TRUE);
382 assure( "Scaling is not logarithmic",
383 AnyConverter.toBoolean( xProp.getPropertyValue( "Logarithmic" )) );
384 xProp.setPropertyValue( "Logarithmic", Boolean.FALSE);
385 assure( "Scaling is not logarithmic",
386 ! AnyConverter.toBoolean( xProp.getPropertyValue( "Logarithmic" )) );
388 int nNewColor = 0xcd853f; // peru
389 xProp.setPropertyValue( "LineColor", Integer.valueOf( nNewColor ));
390 assure( "Property LineColor",
391 AnyConverter.toInt( xProp.getPropertyValue( "LineColor" )) == nNewColor );
392 float fNewCharHeight = (float)(16.0);
393 xProp.setPropertyValue( "CharHeight", Float.valueOf( fNewCharHeight ));
394 assure( "Property CharHeight",
395 AnyConverter.toFloat( xProp.getPropertyValue( "CharHeight" )) == fNewCharHeight );
397 int nNewTextRotation = 700; // in 1/100 degrees
398 xProp.setPropertyValue( "TextRotation", Integer.valueOf( nNewTextRotation ));
399 assure( "Property TextRotation",
400 AnyConverter.toInt( xProp.getPropertyValue( "TextRotation" )) == nNewTextRotation );
402 double fStepMain = 10.0;
403 xProp.setPropertyValue( "StepMain", Double.valueOf( fStepMain ));
404 assure( "Property StepMain",
405 AnyConverter.toDouble( xProp.getPropertyValue( "StepMain" )) == fStepMain );
407 // note: fStepHelp must be a divider of fStepMain, because
408 // internally, the help-step is stored as an integer number of
409 // substeps
410 double fStepHelp = 5.0;
411 xProp.setPropertyValue( "StepHelp", Double.valueOf( fStepHelp ));
412 assure( "Property StepHelp",
413 AnyConverter.toDouble( xProp.getPropertyValue( "StepHelp" )) == fStepHelp );
415 xProp.setPropertyValue( "DisplayLabels", Boolean.FALSE);
416 assure( "Property DisplayLabels", ! AnyConverter.toBoolean(
417 xProp.getPropertyValue( "DisplayLabels" )));
419 catch( Exception ex )
421 failed( ex.getMessage() );
422 ex.printStackTrace( (PrintWriter)log );
428 public void testLegend()
430 XShape xLegend = mxOldDoc.getLegend();
431 assure( "No Legend returned", xLegend != null );
433 XPropertySet xLegendProp = UnoRuntime.queryInterface(
434 XPropertySet.class, xLegend );
435 assure( "Legend is no property set", xLegendProp != null );
439 ChartLegendPosition eNewPos = ChartLegendPosition.BOTTOM;
440 xLegendProp.setPropertyValue( "Alignment", eNewPos );
441 assure( "Property Alignment",
442 AnyConverter.toObject(
443 new Type( ChartLegendPosition.class ),
444 xLegendProp.getPropertyValue( "Alignment" )) == eNewPos );
446 float fNewCharHeight = (float)(11.0);
447 xLegendProp.setPropertyValue( "CharHeight", Float.valueOf( fNewCharHeight ));
448 assure( "Property CharHeight",
449 AnyConverter.toFloat( xLegendProp.getPropertyValue( "CharHeight" )) == fNewCharHeight );
451 // move legend
453 Point aOldPos = xLegend.getPosition();
454 int xDiff = 20;
455 int yDiff = 20;
456 Point aSetPos = new Point();
457 aSetPos.X = aOldPos.X + xDiff;
458 aSetPos.Y = aOldPos.Y + yDiff;
459 xLegend.setPosition( aSetPos );
461 Point aNewPos = xLegend.getPosition();
462 assure( "Legend Position X", approxEqual( aNewPos.X, aSetPos.X, 1 ));
463 assure( "Legend Position Y", approxEqual( aNewPos.Y, aSetPos.Y, 1 ));
466 catch( Exception ex )
468 failed( ex.getMessage() );
469 ex.printStackTrace( (PrintWriter)log );
475 public void testArea()
477 XPropertySet xArea = mxOldDoc.getArea();
478 assure( "No Area", xArea != null );
482 int nColor = 0xf5fffa; // mint cream
483 xArea.setPropertyValue( "FillColor", Integer.valueOf( nColor ) );
484 xArea.setPropertyValue( "FillStyle", FillStyle.SOLID );
486 int nNewColor = AnyConverter.toInt( xArea.getPropertyValue( "FillColor" ) );
487 assure( "Changing FillColor of Area failed", nNewColor == nColor );
489 catch( Exception ex )
491 failed( ex.getMessage() );
492 ex.printStackTrace( (PrintWriter)log );
498 public void testChartType()
500 XMultiServiceFactory xFact = UnoRuntime.queryInterface(
501 XMultiServiceFactory.class, mxOldDoc );
502 assure( "document is no factory", xFact != null );
506 String aMyServiceName = "com.sun.star.chart.BarDiagram";
507 String aServices[] = xFact.getAvailableServiceNames();
508 boolean bServiceFound = false;
509 for( int i = 0; i < aServices.length; ++i )
511 if( aServices[ i ].equals( aMyServiceName ))
513 bServiceFound = true;
514 break;
517 assure( "getAvailableServiceNames did not return " + aMyServiceName, bServiceFound );
519 if( bServiceFound )
521 XDiagram xDia = UnoRuntime.queryInterface(
522 XDiagram.class, xFact.createInstance( aMyServiceName ));
523 assure( aMyServiceName + " could not be created", xDia != null );
525 mxOldDoc.setDiagram( xDia );
527 XPropertySet xDiaProp = UnoRuntime.queryInterface(
528 XPropertySet.class, xDia );
529 assure( "Diagram is no XPropertySet", xDiaProp != null );
531 xDiaProp.setPropertyValue( "Stacked", Boolean.TRUE);
532 assure( "StackMode could not be set correctly",
533 AnyConverter.toBoolean(
534 xDiaProp.getPropertyValue( "Stacked" )));
536 xDiaProp.setPropertyValue( "Dim3D", Boolean.FALSE);
537 assure( "Dim3D could not be set correctly",
538 ! AnyConverter.toBoolean(
539 xDiaProp.getPropertyValue( "Dim3D" )));
541 xDiaProp.setPropertyValue( "Vertical", Boolean.TRUE);
542 assure( "Vertical could not be set correctly",
543 AnyConverter.toBoolean(
544 xDiaProp.getPropertyValue( "Vertical" )));
548 catch( Exception ex )
550 failed( ex.getMessage() );
551 ex.printStackTrace( (PrintWriter)log );
557 public void testAggregation()
559 // query to new type
560 XChartDocument xDiaProv = UnoRuntime.queryInterface(
561 XChartDocument.class, mxOldDoc );
562 assure( "query to new interface failed", xDiaProv != null );
564 com.sun.star.chart.XChartDocument xDoc = UnoRuntime.queryInterface(
565 com.sun.star.chart.XChartDocument.class, xDiaProv );
566 assure( "querying back to old interface failed", xDoc != null );
571 public void testDataSeriesAndPoints()
575 XDiagram xDia = mxOldDoc.getDiagram();
576 assure( "Invalid Diagram", xDia != null );
577 XMultiServiceFactory xFact = UnoRuntime.queryInterface(
578 XMultiServiceFactory.class, mxOldDoc );
579 assure( "document is no factory", xFact != null );
581 // FillColor
582 XPropertySet xProp = xDia.getDataRowProperties( 0 );
583 int nColor = 0xffd700; // gold
584 xProp.setPropertyValue( "FillColor", Integer.valueOf( nColor ));
585 int nNewColor = AnyConverter.toInt( xProp.getPropertyValue( "FillColor" ) );
586 assure( "Changing FillColor of Data Series failed", nNewColor == nColor );
588 // Gradient
590 // note: the FillGradient property is optional, however it was
591 // supported in the old chart's API
592 XNameContainer xGradientTable = UnoRuntime.queryInterface(
593 XNameContainer.class,
594 xFact.createInstance( "com.sun.star.drawing.GradientTable" ));
595 assure( "no gradient table", xGradientTable != null );
596 String aGradientName = "NewAPITestGradient";
597 Gradient aGradient = new Gradient();
598 aGradient.Style = GradientStyle.LINEAR;
599 aGradient.StartColor = 0xe0ffff; // light cyan
600 aGradient.EndColor = 0xff8c00; // dark orange
601 aGradient.Angle = 300; // 30 degrees
602 aGradient.Border = 15;
603 aGradient.XOffset = 0;
604 aGradient.YOffset = 0;
605 aGradient.StartIntensity = 100;
606 aGradient.EndIntensity = 80;
607 aGradient.StepCount = 23;
609 xGradientTable.insertByName( aGradientName, aGradient );
610 xProp.setPropertyValue( "FillStyle", FillStyle.GRADIENT );
611 xProp.setPropertyValue( "FillGradientName", aGradientName );
612 String aNewGradientName = AnyConverter.toString( xProp.getPropertyValue( "FillGradientName" ));
613 assure( "GradientName", aNewGradientName.equals( aGradientName ));
614 Gradient aNewGradient = (Gradient) AnyConverter.toObject(
615 new Type( Gradient.class ),
616 xGradientTable.getByName( aNewGradientName ));
617 assure( "Gradient Style", aNewGradient.Style == aGradient.Style );
618 assure( "Gradient StartColor", aNewGradient.StartColor == aGradient.StartColor );
619 assure( "Gradient EndColor", aNewGradient.EndColor == aGradient.EndColor );
620 assure( "Gradient Angle", aNewGradient.Angle == aGradient.Angle );
621 assure( "Gradient Border", aNewGradient.Border == aGradient.Border );
622 assure( "Gradient XOffset", aNewGradient.XOffset == aGradient.XOffset );
623 assure( "Gradient YOffset", aNewGradient.YOffset == aGradient.YOffset );
624 assure( "Gradient StartIntensity", aNewGradient.StartIntensity == aGradient.StartIntensity );
625 assure( "Gradient EndIntensity", aNewGradient.EndIntensity == aGradient.EndIntensity );
626 assure( "Gradient StepCount", aNewGradient.StepCount == aGradient.StepCount );
628 // Hatch
629 xProp = xDia.getDataPointProperties( 1, 0 );
630 assure( "No DataPointProperties for (1,0)", xProp != null );
632 // note: the FillHatch property is optional, however it was
633 // supported in the old chart's API
634 XNameContainer xHatchTable = UnoRuntime.queryInterface(
635 XNameContainer.class,
636 xFact.createInstance( "com.sun.star.drawing.HatchTable" ));
637 assure( "no hatch table", xHatchTable != null );
638 String aHatchName = "NewAPITestHatch";
639 Hatch aHatch = new Hatch();
640 aHatch.Style = HatchStyle.DOUBLE;
641 aHatch.Color = 0xd2691e; // chocolate
642 aHatch.Distance = 200; // 2 mm (?)
643 aHatch.Angle = 230; // 23 degrees
645 xHatchTable.insertByName( aHatchName, aHatch );
646 xProp.setPropertyValue( "FillHatchName", aHatchName );
647 xProp.setPropertyValue( "FillStyle", FillStyle.HATCH );
648 xProp.setPropertyValue( "FillBackground", Boolean.TRUE);
649 String aNewHatchName = AnyConverter.toString( xProp.getPropertyValue( "FillHatchName" ));
650 assure( "HatchName", aNewHatchName.equals( aHatchName ));
651 Hatch aNewHatch = (Hatch) AnyConverter.toObject(
652 new Type( Hatch.class ),
653 xHatchTable.getByName( aNewHatchName ));
654 assure( "Hatch Style", aNewHatch.Style == aHatch.Style );
655 assure( "Hatch Color", aNewHatch.Color == aHatch.Color );
656 assure( "Hatch Distance", aNewHatch.Distance == aHatch.Distance );
657 assure( "Hatch Angle", aNewHatch.Angle == aHatch.Angle );
658 assure( "FillBackground", AnyConverter.toBoolean( xProp.getPropertyValue( "FillBackground" )) );
660 catch( Exception ex )
662 failed( ex.getMessage() );
663 ex.printStackTrace( (PrintWriter)log );
669 public void testStatistics()
673 XDiagram xDia = mxOldDoc.getDiagram();
674 assure( "Invalid Diagram", xDia != null );
676 XPropertySet xProp = xDia.getDataRowProperties( 0 );
677 assure( "No DataRowProperties for first series", xProp != null );
679 xProp.setPropertyValue( "MeanValue", Boolean.TRUE);
680 assure( "No MeanValue", AnyConverter.toBoolean( xProp.getPropertyValue( "MeanValue" )) );
682 catch( Exception ex )
684 failed( ex.getMessage() );
685 ex.printStackTrace( (PrintWriter)log );
691 public void setStockData_Type4()
695 XPropertySet xDiaProp = UnoRuntime.queryInterface(
696 XPropertySet.class, mxOldDoc.getDiagram() );
698 ChartDataRowSource eNewSource = ChartDataRowSource.ROWS;
699 xDiaProp.setPropertyValue( "DataRowSource", eNewSource );
700 assure( "Couldn't set \"DataRowSource\" property at Diagram",
701 AnyConverter.toObject(
702 new Type( ChartDataRowSource.class ),
703 xDiaProp.getPropertyValue( "DataRowSource" )) == eNewSource );
705 double aData[][] =
707 { 100.0, 200.0, 300.0, 250.0, 300.0 },
708 { 6.5, 4.5, 6.0, 5.5, 3.5 },
709 { 1.0, 1.5, 2.0, 2.5, 3.0 },
710 { 6.0, 6.5, 7.0, 6.5, 5.0 },
711 { 6.0, 5.5, 4.0, 4.5, 4.0 }
714 String[] aRowDescriptions =
716 "Volume", "Open", "Min", "Max", "Close"
719 String[] aColumnDescriptions =
721 "First Row", "Second Row", "Third Row", "Fourth Row", "Fifth Row"
725 XChartData xData = mxOldDoc.getData();
726 XChartDataArray xDataArray = UnoRuntime.queryInterface(
727 XChartDataArray.class, xData );
728 assure( "document has no XChartDataArray", xDataArray != null );
730 xDataArray.setData( aData );
731 xDataArray.setRowDescriptions( aRowDescriptions );
732 xDataArray.setColumnDescriptions( aColumnDescriptions );
734 mxOldDoc.attachData( xData );
736 catch( Exception ex )
738 failed( ex.getMessage() );
739 ex.printStackTrace( (PrintWriter)log );
745 public void testStockProperties()
749 setStockData_Type4();
751 XMultiServiceFactory xFact = UnoRuntime.queryInterface(
752 XMultiServiceFactory.class, mxOldDoc );
753 assure( "document is no factory", xFact != null );
755 String aMyServiceName = "com.sun.star.chart.StockDiagram";
756 XDiagram xDia = UnoRuntime.queryInterface(
757 XDiagram.class, xFact.createInstance( aMyServiceName ));
758 assure( aMyServiceName + " could not be created", xDia != null );
760 mxOldDoc.setDiagram( xDia );
762 XPropertySet xDiaProp = UnoRuntime.queryInterface(
763 XPropertySet.class, xDia );
764 assure( "Diagram is no XPropertySet", xDiaProp != null );
766 xDiaProp.setPropertyValue( "Volume", Boolean.TRUE);
767 assure( "Has Volume", AnyConverter.toBoolean( xDiaProp.getPropertyValue( "Volume" )));
769 xDiaProp.setPropertyValue( "UpDown", Boolean.TRUE);
770 assure( "Has UpDown", AnyConverter.toBoolean( xDiaProp.getPropertyValue( "UpDown" )));
772 // MinMaxLine
773 XStatisticDisplay xMinMaxProvider = UnoRuntime.queryInterface(
774 XStatisticDisplay.class, xDia );
775 assure( "Diagram is no XStatisticDisplay", xMinMaxProvider != null );
776 XPropertySet xMinMaxProp = xMinMaxProvider.getMinMaxLine();
777 assure( "No MinMaxLine", xMinMaxProp != null );
779 int nLineColor = 0x458b00; // chartreuse4
780 xMinMaxProp.setPropertyValue( "LineColor", Integer.valueOf( nLineColor ));
781 int nNewColor = AnyConverter.toInt( xMinMaxProp.getPropertyValue( "LineColor" ) );
782 assure( "Changing LineColor of MinMax Line", nNewColor == nLineColor );
784 catch( Exception ex )
786 failed( ex.getMessage() );
787 ex.printStackTrace( (PrintWriter)log );
793 public void testFactory()
797 XMultiServiceFactory xFact = UnoRuntime.queryInterface(
798 XMultiServiceFactory.class, mxOldDoc );
799 assure( "document is no factory", xFact != null );
801 Object aTestTable = xFact.createInstance( "com.sun.star.drawing.GradientTable" );
802 assure( "Couldn't create gradient table via factory", aTestTable != null );
804 catch( Exception ex )
806 failed( ex.getMessage() );
807 ex.printStackTrace( (PrintWriter)log );
813 public void testData()
817 // set data
818 double aData[][] = {
819 { 1.0, 1.5, 2.0, 2.5, 3.0 },
820 { 2.0, 2.5, 3.0, 3.5, 4.0 },
821 { 3.0, 3.5, 4.0, 4.5, 5.0 }
824 String[] aColumnDescriptions = {
825 "First Column", "Second Column", "Third Column",
826 "Fourth Column", "Fifth Column"
829 String[] aRowDescriptions = {
830 "First Row", "Second Row", "Third Row"
833 XPropertySet xDiaProp = UnoRuntime.queryInterface(
834 XPropertySet.class, mxOldDoc.getDiagram() );
835 ChartDataRowSource eNewSource = ChartDataRowSource.ROWS;
836 xDiaProp.setPropertyValue( "DataRowSource", eNewSource );
837 assure( "Couldn't set \"DataRowSource\" property at Diagram",
838 AnyConverter.toObject(
839 new Type( ChartDataRowSource.class ),
840 xDiaProp.getPropertyValue( "DataRowSource" )) == eNewSource );
842 XChartData xData = mxOldDoc.getData();
843 XChartDataArray xDataArray = UnoRuntime.queryInterface(
844 XChartDataArray.class, xData );
845 assure( "document has no XChartDataArray", xDataArray != null );
847 xDataArray.setData( aData );
848 xDataArray.setRowDescriptions( aRowDescriptions );
849 xDataArray.setColumnDescriptions( aColumnDescriptions );
851 mxOldDoc.attachData( xData );
853 // get data
854 double aReadData[][];
855 String[] aReadColumnDescriptions;
856 String[] aReadRowDescriptions;
858 // refetch data
859 xData = mxOldDoc.getData();
860 xDataArray = UnoRuntime.queryInterface(
861 XChartDataArray.class, xData );
862 assure( "document has no XChartDataArray", xDataArray != null );
864 aReadData = xDataArray.getData();
865 aReadRowDescriptions = xDataArray.getRowDescriptions();
866 aReadColumnDescriptions = xDataArray.getColumnDescriptions();
868 // compare to values set before
869 assure( "Data size differs", aData.length == aReadData.length );
870 for( int i=0; i<aReadData.length; ++i )
872 assure( "Data size differs", aData[i].length == aReadData[i].length );
873 for( int j=0; j<aReadData[i].length; ++j )
874 assure( "Data differs", aData[i][j] == aReadData[i][j] );
877 assure( "Column Description size differs", aColumnDescriptions.length == aReadColumnDescriptions.length );
878 for( int i=0; i<aReadColumnDescriptions.length; ++i )
879 assure( "Column Descriptions differ", aColumnDescriptions[i].equals( aReadColumnDescriptions[i] ));
881 assure( "Row Description size differs", aRowDescriptions.length == aReadRowDescriptions.length );
882 for( int i=0; i<aReadRowDescriptions.length; ++i )
883 assure( "Row Descriptions differ", aRowDescriptions[i].equals( aReadRowDescriptions[i] ));
885 catch( Exception ex )
887 failed( ex.getMessage() );
888 ex.printStackTrace( (PrintWriter)log );
894 private XModel mxChartModel;
895 private XChartDocument mxOldDoc;
896 private boolean mbCreateView;
900 private XModel createDocument( String sDocType )
902 XModel aResult = null;
905 XComponentLoader aLoader = UnoRuntime.queryInterface(
906 XComponentLoader.class,
907 param.getMSF().createInstance( "com.sun.star.frame.Desktop" ) );
909 aResult = UnoRuntime.queryInterface(
910 XModel.class,
911 aLoader.loadComponentFromURL( "private:factory/" + sDocType,
912 "_blank",
914 new PropertyValue[ 0 ] ) );
916 catch( Exception ex )
918 failed( ex.getMessage() );
919 ex.printStackTrace( (PrintWriter)log );
922 return aResult;
927 public XModel createChartModel()
929 XModel aResult = null;
932 aResult = UnoRuntime.queryInterface(
933 XModel.class,
934 param.getMSF().createInstance( "com.sun.star.comp.chart2.ChartModel" ) );
936 catch( Exception ex )
938 failed( ex.getMessage() );
939 ex.printStackTrace( (PrintWriter)log );
942 return aResult;
945 /** returns true if a and b differ no more than tolerance.
947 @param tolerance
948 must be non-negative
950 private boolean approxEqual( int a, int b, int tolerance )
952 if( a != b )
953 log.println( "Integer values differ by " + Math.abs( a-b ));
954 return ( ( a - tolerance <= b ) ||
955 ( a + tolerance >= b ));