Update ooo320-m1
[ooovba.git] / chart2 / qa / TestCaseOldAPI.java
blob26de0ba61e0b9ed8b275ccae8f19969e50143d28
1 // package name: as default, start with complex
2 package qa;
4 // imports
5 import complexlib.ComplexTestCase;
6 import com.sun.star.uno.XInterface;
7 import com.sun.star.uno.UnoRuntime;
8 import com.sun.star.uno.Type;
9 import com.sun.star.uno.XComponentContext;
11 import java.io.PrintWriter;
12 import java.util.Hashtable;
14 import com.sun.star.lang.*;
15 import com.sun.star.beans.*;
16 import com.sun.star.frame.*;
17 import com.sun.star.chart.*;
18 import com.sun.star.drawing.*;
19 import com.sun.star.awt.*;
20 import com.sun.star.container.*;
21 import com.sun.star.util.XCloseable;
22 import com.sun.star.util.CloseVetoException;
24 import com.sun.star.uno.AnyConverter;
25 import com.sun.star.comp.helper.ComponentContext;
27 /**
28 * The following Complex Test will test the
29 * com.sun.star.document.IndexedPropertyValues
30 * service
33 public class TestCaseOldAPI extends ComplexTestCase {
35 // The name of the tested service
36 private final String testedServiceName =
37 "com.sun.star.chart.ChartDocument";
39 // The first of the mandatory functions:
40 /**
41 * Return the name of the test.
42 * In this case it is the actual name of the service.
43 * @return The tested service.
45 public String getTestObjectName() {
46 return testedServiceName;
49 // The second of the mandatory functions: return all test methods as an
50 // array. There is only one test function in this example.
51 /**
52 * Return all test methods.
53 * @return The test methods.
55 public String[] getTestMethodNames() {
56 // For some tests a view needs to be created. Accessing the model via
57 // this program and the view may lead to problems
58 boolean bAvoidViewCreation = false;
60 if( bAvoidViewCreation )
61 return new String[] {
62 "testData",
63 "testChartType",
64 "testArea",
65 "testAggregation",
66 "testFactory",
67 "testDataSeriesAndPoints",
68 "testStatistics",
69 "testStockProperties"
72 return new String[] {
73 "testData",
74 "testChartType",
75 "testTitle",
76 "testSubTitle",
77 "testDiagram",
78 "testAxis",
79 "testLegend",
80 "testArea",
81 "testAggregation",
82 "testFactory",
83 "testDataSeriesAndPoints",
84 "testStatistics",
85 "testStockProperties"
89 // ____________
91 public void before()
93 // set to "true" to get a view
94 mbCreateView = true;
96 if( mbCreateView )
97 mxChartModel = createDocument( "schart" );
98 else
99 mxChartModel = createChartModel();
101 mxOldDoc = (XChartDocument) UnoRuntime.queryInterface(
102 XChartDocument.class, mxChartModel );
105 // ____________
107 public void after()
109 XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(
110 XCloseable.class, mxChartModel );
111 assure( "document is no XCloseable", xCloseable != null );
113 // do not close document if there exists a view
114 if( ! mbCreateView )
118 xCloseable.close( true );
120 catch( CloseVetoException ex )
122 failed( ex.getMessage() );
123 ex.printStackTrace( (PrintWriter)log );
128 // ____________
130 public void testTitle()
134 XPropertySet xDocProp = (XPropertySet) UnoRuntime.queryInterface(
135 XPropertySet.class, mxOldDoc );
136 assure( "Chart Document is no XPropertySet", xDocProp != null );
137 xDocProp.setPropertyValue( "HasMainTitle", new Boolean( true ));
138 assure( "Property HasMainTitle", AnyConverter.toBoolean(
139 xDocProp.getPropertyValue( "HasMainTitle" )));
141 XShape xTitleShape = mxOldDoc.getTitle();
142 XPropertySet xTitleProp = (XPropertySet) UnoRuntime.queryInterface(
143 XPropertySet.class, xTitleShape );
145 // set property via old API
146 if( xTitleProp != null )
148 String aTitle = " Overwritten by Old API ";
149 float fHeight = (float)17.0;
151 xTitleProp.setPropertyValue( "String", aTitle );
152 xTitleProp.setPropertyValue( "CharHeight", new Float( fHeight ) );
154 float fNewHeight = AnyConverter.toFloat( xTitleProp.getPropertyValue( "CharHeight" ) );
155 assure( "Changing CharHeight via old API failed", fNewHeight == fHeight );
157 String aNewTitle = AnyConverter.toString( xTitleProp.getPropertyValue( "String" ) );
158 assure( "Property \"String\" failed", aNewTitle.equals( aTitle ));
161 // move title
162 Point aSetPos = new Point();
163 aSetPos.X = 1000;
164 aSetPos.Y = 200;
165 xTitleShape.setPosition( aSetPos );
167 Point aNewPos = xTitleShape.getPosition();
168 assure( "Title Position X", approxEqual( aNewPos.X, aSetPos.X, 1 ));
169 assure( "Title Position Y", approxEqual( aNewPos.Y, aSetPos.Y, 1 ));
171 catch( Exception ex )
173 failed( ex.getMessage() );
174 ex.printStackTrace( (PrintWriter)log );
178 // ____________
180 public void testSubTitle()
184 XPropertySet xDocProp = (XPropertySet) UnoRuntime.queryInterface(
185 XPropertySet.class, mxOldDoc );
186 assure( "Chart Document is no XPropertySet", xDocProp != null );
187 xDocProp.setPropertyValue( "HasSubTitle", new Boolean( true ));
188 assure( "Property HasSubTitle", AnyConverter.toBoolean(
189 xDocProp.getPropertyValue( "HasSubTitle" )));
191 XShape xTitleShape = mxOldDoc.getSubTitle();
192 XPropertySet xTitleProp = (XPropertySet) UnoRuntime.queryInterface(
193 XPropertySet.class, xTitleShape );
195 // set Property via old API
196 if( xTitleProp != null )
198 int nColor = 0x009acd; // DeepSkyBlue3
199 float fWeight = FontWeight.BOLD;
200 float fHeight = (float)14.0;
202 xTitleProp.setPropertyValue( "CharColor", new Integer( nColor ) );
203 xTitleProp.setPropertyValue( "CharWeight", new Float( fWeight ));
204 xTitleProp.setPropertyValue( "CharHeight", new Float( fHeight ) );
206 int nNewColor = AnyConverter.toInt( xTitleProp.getPropertyValue( "CharColor" ) );
207 assure( "Changing CharColor via old API failed", nNewColor == nColor );
209 float fNewWeight = AnyConverter.toFloat( xTitleProp.getPropertyValue( "CharWeight" ) );
210 assure( "Changing CharWeight via old API failed", fNewWeight == fWeight );
212 float fNewHeight = AnyConverter.toFloat( xTitleProp.getPropertyValue( "CharHeight" ) );
213 assure( "Changing CharHeight via old API failed", fNewHeight == fHeight );
216 catch( Exception ex )
218 failed( ex.getMessage() );
219 ex.printStackTrace( (PrintWriter)log );
223 // ------------
225 public void testDiagram()
229 // testing wall
230 XDiagram xDia = mxOldDoc.getDiagram();
231 if( xDia != null )
233 X3DDisplay xDisp = (X3DDisplay) UnoRuntime.queryInterface(
234 X3DDisplay.class, xDia );
235 assure( "X3DDisplay not supported", xDisp != null );
237 // Wall
238 XPropertySet xProp = xDisp.getWall();
239 if( xProp != null )
241 int nColor = 0xffe1ff; // thistle1
242 xProp.setPropertyValue( "FillColor", new Integer( nColor ) );
243 int nNewColor = AnyConverter.toInt( xProp.getPropertyValue( "FillColor" ) );
244 assure( "Changing FillColor via old API failed", nNewColor == nColor );
247 assure( "Wrong Diagram Type", xDia.getDiagramType().equals(
248 "com.sun.star.chart.BarDiagram" ));
250 // Diagram properties
251 xProp = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xDia );
252 assure( "Diagram is no property set", xProp != null );
254 // y-axis
255 boolean bFirstYAxisText = false;
256 xProp.setPropertyValue( "HasYAxisDescription", new Boolean( bFirstYAxisText ));
257 boolean bNewFirstYAxisText = AnyConverter.toBoolean(
258 xProp.getPropertyValue( "HasYAxisDescription" ));
259 assure( "Removing description of first y-axis", bNewFirstYAxisText == bFirstYAxisText );
261 // boolean bYAxisTitle = true;
262 // xProp.setPropertyValue( "HasYAxisTitle", new Boolean( bYAxisTitle ));
263 // boolean bNewYAxisTitle = AnyConverter.toBoolean(
264 // xProp.getPropertyValue( "HasYAxisTitle" ));
265 // assure( "Adding y-axis title", bNewYAxisTitle == bYAxisTitle );
267 // set title text
268 // XAxisYSupplier xYAxisSuppl = (XAxisYSupplier) UnoRuntime.queryInterface(
269 // XAxisYSupplier.class, mxOldDoc.getDiagram() );
270 // assure( "Diagram is no y-axis supplier", xYAxisSuppl != null );
271 // XPropertySet xAxisTitleProp = (XPropertySet) UnoRuntime.queryInterface(
272 // XPropertySet.class, xYAxisSuppl.getYAxisTitle() );
273 // assure( "Y-Axis Title is no XPropertySet", xAxisTitleProp != null );
274 // xAxisTitleProp.setPropertyValue( "String", "New y axis title" );
276 // second y-axis
277 boolean bSecondaryYAxis = true;
278 xProp.setPropertyValue( "HasSecondaryYAxis", new Boolean( bSecondaryYAxis ));
279 boolean bNewSecYAxisValue = AnyConverter.toBoolean(
280 xProp.getPropertyValue( "HasSecondaryYAxis" ));
281 assure( "Adding a second y-axis does not work", bNewSecYAxisValue == bSecondaryYAxis );
283 XTwoAxisYSupplier xSecYAxisSuppl = (XTwoAxisYSupplier) UnoRuntime.queryInterface(
284 XTwoAxisYSupplier.class, xDia );
285 assure( "XTwoAxisYSupplier not implemented", xSecYAxisSuppl != null );
286 assure( "No second y-axis found", xSecYAxisSuppl.getSecondaryYAxis() != null );
289 // move diagram
291 XShape xDiagramShape = (XShape) UnoRuntime.queryInterface(
292 XShape.class, xDia );
294 Point aOldPos = xDiagramShape.getPosition();
295 int xDiff = 20;
296 int yDiff = 20;
297 Point aSetPos = new Point();
298 aSetPos.X = aOldPos.X + xDiff;
299 aSetPos.Y = aOldPos.Y + yDiff;
300 xDiagramShape.setPosition( aSetPos );
302 Point aNewPos = xDiagramShape.getPosition();
303 //System.out.println( "set X = " + aSetPos.X + ", new X = " + aNewPos.X );
304 //System.out.println( "set Y = " + aSetPos.Y + ", new Y = " + aNewPos.Y );
305 assure( "Diagram Position X", approxEqual( aNewPos.X, aSetPos.X, 1 ));
306 assure( "Diagram Position Y", approxEqual( aNewPos.Y, aSetPos.Y, 1 ));
309 // size diagram
311 XShape xDiagramShape = (XShape) UnoRuntime.queryInterface(
312 XShape.class, xDia );
314 Size aOldSize = xDiagramShape.getSize();
315 int xDiff = aOldSize.Width/2+2;
316 int yDiff = aOldSize.Height/2+2;
317 Size aSetSize = new Size();
318 aSetSize.Width = aOldSize.Width - xDiff;
319 aSetSize.Height = aOldSize.Height - yDiff;
320 xDiagramShape.setSize( aSetSize );
322 Size aNewSize = xDiagramShape.getSize();
323 //System.out.println( "set width = " + aSetSize.Width + ", new width = " + aNewSize.Width );
324 //System.out.println( "set height = " + aSetSize.Height + ", new height = " + aNewSize.Height );
325 assure( "Diagram Width", approxEqual( aNewSize.Width, aSetSize.Width, 2 ));
326 assure( "Diagram Height", approxEqual( aNewSize.Height, aSetSize.Height, 2 ));
329 catch( Exception ex )
331 failed( ex.getMessage() );
332 ex.printStackTrace( (PrintWriter)log );
336 // ------------
338 public void testAxis()
342 XAxisYSupplier xYAxisSuppl = (XAxisYSupplier) UnoRuntime.queryInterface(
343 XAxisYSupplier.class, mxOldDoc.getDiagram() );
344 assure( "Diagram is no y-axis supplier", xYAxisSuppl != null );
346 XPropertySet xProp = xYAxisSuppl.getYAxis();
347 assure( "No y-axis found", xProp != null );
349 double fMax1, fMax2;
350 Object oMax = xProp.getPropertyValue( "Max" );
351 assure( "No Maximum set", AnyConverter.isDouble( oMax ));
352 fMax1 = AnyConverter.toDouble( oMax );
353 log.println( "Maximum retrieved: " + fMax1 );
354 //todo: the view has to be built before there is an explicit value
355 // assure( "Max is 0.0", fMax1 > 0.0 );
356 xProp.setPropertyValue( "AutoMax", new Boolean( false ));
357 oMax = xProp.getPropertyValue( "Max" );
358 assure( "No Maximum set", AnyConverter.isDouble( oMax ));
359 fMax2 = AnyConverter.toDouble( oMax );
360 log.println( "Maximum with AutoMax off: " + fMax2 );
361 assure( "maxima differ", fMax1 == fMax2 );
363 double nNewMax = 12.3;
364 double nNewOrigin = 2.7;
366 xProp.setPropertyValue( "Max", new Double( nNewMax ));
367 assure( "AutoMax is on", ! AnyConverter.toBoolean( xProp.getPropertyValue( "AutoMax" )) );
369 assure( "Maximum value invalid",
370 approxEqual(
371 AnyConverter.toDouble( xProp.getPropertyValue( "Max" )),
372 nNewMax ));
374 xProp.setPropertyValue( "AutoMin", new Boolean( true ));
375 assure( "AutoMin is off", AnyConverter.toBoolean( xProp.getPropertyValue( "AutoMin" )) );
377 xProp.setPropertyValue( "Origin", new Double( nNewOrigin ));
378 assure( "Origin invalid",
379 approxEqual(
380 AnyConverter.toDouble( xProp.getPropertyValue( "Origin" )),
381 nNewOrigin ));
382 xProp.setPropertyValue( "AutoOrigin", new Boolean( true ));
383 assure( "AutoOrigin is off", AnyConverter.toBoolean( xProp.getPropertyValue( "AutoOrigin" )) );
384 Object oOrigin = xProp.getPropertyValue( "Origin" );
385 assure( "No Origin set", AnyConverter.isDouble( oOrigin ));
386 log.println( "Origin retrieved: " + AnyConverter.toDouble( oOrigin ));
388 xProp.setPropertyValue( "Logarithmic", new Boolean( true ));
389 assure( "Scaling is not logarithmic",
390 AnyConverter.toBoolean( xProp.getPropertyValue( "Logarithmic" )) );
391 xProp.setPropertyValue( "Logarithmic", new Boolean( false ));
392 assure( "Scaling is not logarithmic",
393 ! AnyConverter.toBoolean( xProp.getPropertyValue( "Logarithmic" )) );
395 int nNewColor = 0xcd853f; // peru
396 xProp.setPropertyValue( "LineColor", new Integer( nNewColor ));
397 assure( "Property LineColor",
398 AnyConverter.toInt( xProp.getPropertyValue( "LineColor" )) == nNewColor );
399 float fNewCharHeight = (float)(16.0);
400 xProp.setPropertyValue( "CharHeight", new Float( fNewCharHeight ));
401 assure( "Property CharHeight",
402 AnyConverter.toFloat( xProp.getPropertyValue( "CharHeight" )) == fNewCharHeight );
404 int nNewTextRotation = 700; // in 1/100 degrees
405 xProp.setPropertyValue( "TextRotation", new Integer( nNewTextRotation ));
406 assure( "Property TextRotation",
407 AnyConverter.toInt( xProp.getPropertyValue( "TextRotation" )) == nNewTextRotation );
409 double fStepMain = 10.0;
410 xProp.setPropertyValue( "StepMain", new Double( fStepMain ));
411 assure( "Property StepMain",
412 AnyConverter.toDouble( xProp.getPropertyValue( "StepMain" )) == fStepMain );
414 // note: fStepHelp must be a divider of fStepMain, because
415 // internally, the help-step is stored as an integer number of
416 // substeps
417 double fStepHelp = 5.0;
418 xProp.setPropertyValue( "StepHelp", new Double( fStepHelp ));
419 assure( "Property StepHelp",
420 AnyConverter.toDouble( xProp.getPropertyValue( "StepHelp" )) == fStepHelp );
422 xProp.setPropertyValue( "DisplayLabels", new Boolean( false ));
423 assure( "Property DisplayLabels", ! AnyConverter.toBoolean(
424 xProp.getPropertyValue( "DisplayLabels" )));
426 catch( Exception ex )
428 failed( ex.getMessage() );
429 ex.printStackTrace( (PrintWriter)log );
433 // ------------
435 public void testLegend()
437 XShape xLegend = mxOldDoc.getLegend();
438 assure( "No Legend returned", xLegend != null );
440 XPropertySet xLegendProp = (XPropertySet) UnoRuntime.queryInterface(
441 XPropertySet.class, xLegend );
442 assure( "Legend is no property set", xLegendProp != null );
446 ChartLegendPosition eNewPos = ChartLegendPosition.BOTTOM;
447 xLegendProp.setPropertyValue( "Alignment", eNewPos );
448 assure( "Property Alignment",
449 AnyConverter.toObject(
450 new Type( ChartLegendPosition.class ),
451 xLegendProp.getPropertyValue( "Alignment" )) == eNewPos );
453 float fNewCharHeight = (float)(11.0);
454 xLegendProp.setPropertyValue( "CharHeight", new Float( fNewCharHeight ));
455 assure( "Property CharHeight",
456 AnyConverter.toFloat( xLegendProp.getPropertyValue( "CharHeight" )) == fNewCharHeight );
458 // move legend
460 Point aOldPos = xLegend.getPosition();
461 int xDiff = 20;
462 int yDiff = 20;
463 Point aSetPos = new Point();
464 aSetPos.X = aOldPos.X + xDiff;
465 aSetPos.Y = aOldPos.Y + yDiff;
466 xLegend.setPosition( aSetPos );
468 Point aNewPos = xLegend.getPosition();
469 assure( "Legend Position X", approxEqual( aNewPos.X, aSetPos.X, 1 ));
470 assure( "Legend Position Y", approxEqual( aNewPos.Y, aSetPos.Y, 1 ));
473 catch( Exception ex )
475 failed( ex.getMessage() );
476 ex.printStackTrace( (PrintWriter)log );
480 // ------------
482 public void testArea()
484 XPropertySet xArea = mxOldDoc.getArea();
485 assure( "No Area", xArea != null );
489 int nColor = 0xf5fffa; // mint cream
490 xArea.setPropertyValue( "FillColor", new Integer( nColor ) );
491 xArea.setPropertyValue( "FillStyle", FillStyle.SOLID );
492 // XPropertySetInfo xInfo = xArea.getPropertySetInfo();
493 // assure( "Area does not support ChartUserDefinedAttributes",
494 // xInfo.hasPropertyByName( "ChartUserDefinedAttributes" ));
496 // String aTestAttributeName = "test:foo";
497 // String aTestAttributeValue = "content";
498 // XNameContainer xUserDefAttributes = (XNameContainer) AnyConverter.toObject(
499 // new Type( XNameContainer.class ), xArea.getPropertyValue( "ChartUserDefinedAttributes" ));
500 // xUserDefAttributes.insertByName( aTestAttributeName, aTestAttributeValue );
502 // String aContent = AnyConverter.toString( xUserDefAttributes.getByName( aTestAttributeName ));
503 // assure( "Wrong content in UserDefinedAttributes container",
504 // aContent.equals( aTestAttributeValue ));
506 int nNewColor = AnyConverter.toInt( xArea.getPropertyValue( "FillColor" ) );
507 assure( "Changing FillColor of Area failed", nNewColor == nColor );
509 catch( Exception ex )
511 failed( ex.getMessage() );
512 ex.printStackTrace( (PrintWriter)log );
516 // ------------
518 public void testChartType()
520 XMultiServiceFactory xFact = (XMultiServiceFactory) UnoRuntime.queryInterface(
521 XMultiServiceFactory.class, mxOldDoc );
522 assure( "document is no factory", xFact != null );
526 String aMyServiceName = new String( "com.sun.star.chart.BarDiagram" );
527 String aServices[] = xFact.getAvailableServiceNames();
528 boolean bServiceFound = false;
529 for( int i = 0; i < aServices.length; ++i )
531 if( aServices[ i ].equals( aMyServiceName ))
533 bServiceFound = true;
534 break;
537 assure( "getAvailableServiceNames did not return " + aMyServiceName, bServiceFound );
539 if( bServiceFound )
541 XDiagram xDia = (XDiagram) UnoRuntime.queryInterface(
542 XDiagram.class, xFact.createInstance( aMyServiceName ));
543 assure( aMyServiceName + " could not be created", xDia != null );
545 mxOldDoc.setDiagram( xDia );
547 XPropertySet xDiaProp = (XPropertySet) UnoRuntime.queryInterface(
548 XPropertySet.class, xDia );
549 assure( "Diagram is no XPropertySet", xDiaProp != null );
551 xDiaProp.setPropertyValue( "Stacked", new Boolean( true ));
552 assure( "StackMode could not be set correctly",
553 AnyConverter.toBoolean(
554 xDiaProp.getPropertyValue( "Stacked" )));
556 xDiaProp.setPropertyValue( "Dim3D", new Boolean( false ));
557 assure( "Dim3D could not be set correctly",
558 ! AnyConverter.toBoolean(
559 xDiaProp.getPropertyValue( "Dim3D" )));
561 xDiaProp.setPropertyValue( "Vertical", new Boolean( true ));
562 assure( "Vertical could not be set correctly",
563 AnyConverter.toBoolean(
564 xDiaProp.getPropertyValue( "Vertical" )));
567 // reset to bar-chart
568 // aMyServiceName = new String( "com.sun.star.chart.BarDiagram" );
569 // XDiagram xDia = (XDiagram) UnoRuntime.queryInterface(
570 // XDiagram.class, xFact.createInstance( aMyServiceName ));
571 // assure( aMyServiceName + " could not be created", xDia != null );
573 // mxOldDoc.setDiagram( xDia );
575 catch( Exception ex )
577 failed( ex.getMessage() );
578 ex.printStackTrace( (PrintWriter)log );
582 // ------------
584 public void testAggregation()
586 // query to new type
587 XChartDocument xDiaProv = (XChartDocument) UnoRuntime.queryInterface(
588 XChartDocument.class, mxOldDoc );
589 assure( "query to new interface failed", xDiaProv != null );
591 com.sun.star.chart.XChartDocument xDoc = (com.sun.star.chart.XChartDocument) UnoRuntime.queryInterface(
592 com.sun.star.chart.XChartDocument.class, xDiaProv );
593 assure( "querying back to old interface failed", xDoc != null );
596 // ------------
598 public void testDataSeriesAndPoints()
602 XDiagram xDia = mxOldDoc.getDiagram();
603 assure( "Invalid Diagram", xDia != null );
604 XMultiServiceFactory xFact = (XMultiServiceFactory) UnoRuntime.queryInterface(
605 XMultiServiceFactory.class, mxOldDoc );
606 assure( "document is no factory", xFact != null );
608 // FillColor
609 XPropertySet xProp = xDia.getDataRowProperties( 0 );
610 int nColor = 0xffd700; // gold
611 xProp.setPropertyValue( "FillColor", new Integer( nColor ));
612 int nNewColor = AnyConverter.toInt( xProp.getPropertyValue( "FillColor" ) );
613 assure( "Changing FillColor of Data Series failed", nNewColor == nColor );
615 // Gradient
616 assure( "No DataRowProperties for series 0", xProp != null );
618 // note: the FillGradient property is optional, however it was
619 // supported in the old chart's API
620 XNameContainer xGradientTable = (XNameContainer) UnoRuntime.queryInterface(
621 XNameContainer.class,
622 xFact.createInstance( "com.sun.star.drawing.GradientTable" ));
623 assure( "no gradient table", xGradientTable != null );
624 String aGradientName = "NewAPITestGradient";
625 Gradient aGradient = new Gradient();
626 aGradient.Style = GradientStyle.LINEAR;
627 aGradient.StartColor = 0xe0ffff; // light cyan
628 aGradient.EndColor = 0xff8c00; // dark orange
629 aGradient.Angle = 300; // 30 degrees
630 aGradient.Border = 15;
631 aGradient.XOffset = 0;
632 aGradient.YOffset = 0;
633 aGradient.StartIntensity = 100;
634 aGradient.EndIntensity = 80;
635 aGradient.StepCount = 23;
637 xGradientTable.insertByName( aGradientName, aGradient );
638 xProp.setPropertyValue( "FillStyle", FillStyle.GRADIENT );
639 xProp.setPropertyValue( "FillGradientName", aGradientName );
640 String aNewGradientName = AnyConverter.toString( xProp.getPropertyValue( "FillGradientName" ));
641 assure( "GradientName", aNewGradientName.equals( aGradientName ));
642 Gradient aNewGradient = (Gradient) AnyConverter.toObject(
643 new Type( Gradient.class ),
644 xGradientTable.getByName( aNewGradientName ));
645 assure( "Gradient Style", aNewGradient.Style == aGradient.Style );
646 assure( "Gradient StartColor", aNewGradient.StartColor == aGradient.StartColor );
647 assure( "Gradient EndColor", aNewGradient.EndColor == aGradient.EndColor );
648 assure( "Gradient Angle", aNewGradient.Angle == aGradient.Angle );
649 assure( "Gradient Border", aNewGradient.Border == aGradient.Border );
650 assure( "Gradient XOffset", aNewGradient.XOffset == aGradient.XOffset );
651 assure( "Gradient YOffset", aNewGradient.YOffset == aGradient.YOffset );
652 assure( "Gradient StartIntensity", aNewGradient.StartIntensity == aGradient.StartIntensity );
653 assure( "Gradient EndIntensity", aNewGradient.EndIntensity == aGradient.EndIntensity );
654 assure( "Gradient StepCount", aNewGradient.StepCount == aGradient.StepCount );
656 // Hatch
657 xProp = xDia.getDataPointProperties( 1, 0 );
658 assure( "No DataPointProperties for (1,0)", xProp != null );
660 // note: the FillHatch property is optional, however it was
661 // supported in the old chart's API
662 XNameContainer xHatchTable = (XNameContainer) UnoRuntime.queryInterface(
663 XNameContainer.class,
664 xFact.createInstance( "com.sun.star.drawing.HatchTable" ));
665 assure( "no hatch table", xHatchTable != null );
666 String aHatchName = "NewAPITestHatch";
667 Hatch aHatch = new Hatch();
668 aHatch.Style = HatchStyle.DOUBLE;
669 aHatch.Color = 0xd2691e; // chocolate
670 aHatch.Distance = 200; // 2 mm (?)
671 aHatch.Angle = 230; // 23 degrees
673 xHatchTable.insertByName( aHatchName, aHatch );
674 xProp.setPropertyValue( "FillHatchName", aHatchName );
675 xProp.setPropertyValue( "FillStyle", FillStyle.HATCH );
676 xProp.setPropertyValue( "FillBackground", new Boolean( true ));
677 String aNewHatchName = AnyConverter.toString( xProp.getPropertyValue( "FillHatchName" ));
678 assure( "HatchName", aNewHatchName.equals( aHatchName ));
679 Hatch aNewHatch = (Hatch) AnyConverter.toObject(
680 new Type( Hatch.class ),
681 xHatchTable.getByName( aNewHatchName ));
682 assure( "Hatch Style", aNewHatch.Style == aHatch.Style );
683 assure( "Hatch Color", aNewHatch.Color == aHatch.Color );
684 assure( "Hatch Distance", aNewHatch.Distance == aHatch.Distance );
685 assure( "Hatch Angle", aNewHatch.Angle == aHatch.Angle );
686 assure( "FillBackground", AnyConverter.toBoolean( xProp.getPropertyValue( "FillBackground" )) );
688 catch( Exception ex )
690 failed( ex.getMessage() );
691 ex.printStackTrace( (PrintWriter)log );
695 // ------------
697 public void testStatistics()
701 XDiagram xDia = mxOldDoc.getDiagram();
702 assure( "Invalid Diagram", xDia != null );
704 XPropertySet xProp = xDia.getDataRowProperties( 0 );
705 assure( "No DataRowProperties for first series", xProp != null );
707 xProp.setPropertyValue( "MeanValue", new Boolean( true ));
708 assure( "No MeanValue", AnyConverter.toBoolean( xProp.getPropertyValue( "MeanValue" )) );
710 catch( Exception ex )
712 failed( ex.getMessage() );
713 ex.printStackTrace( (PrintWriter)log );
717 // ------------
719 public void setStockData_Type4()
723 XPropertySet xDiaProp = (XPropertySet) UnoRuntime.queryInterface(
724 XPropertySet.class, mxOldDoc.getDiagram() );
726 ChartDataRowSource eNewSource = ChartDataRowSource.ROWS;
727 xDiaProp.setPropertyValue( "DataRowSource", eNewSource );
728 assure( "Couldn't set \"DataRowSource\" property at Diagram",
729 AnyConverter.toObject(
730 new Type( ChartDataRowSource.class ),
731 xDiaProp.getPropertyValue( "DataRowSource" )) == eNewSource );
733 double aData[][] =
735 { 100.0, 200.0, 300.0, 250.0, 300.0 },
736 { 6.5, 4.5, 6.0, 5.5, 3.5 },
737 { 1.0, 1.5, 2.0, 2.5, 3.0 },
738 { 6.0, 6.5, 7.0, 6.5, 5.0 },
739 { 6.0, 5.5, 4.0, 4.5, 4.0 }
742 String[] aRowDescriptions =
744 "Volume", "Open", "Min", "Max", "Close"
747 String[] aColumnDescriptions =
749 "First Row", "Second Row", "Third Row", "Fourth Row", "Fifth Row"
753 XChartData xData = mxOldDoc.getData();
754 XChartDataArray xDataArray = (XChartDataArray) UnoRuntime.queryInterface(
755 XChartDataArray.class, xData );
756 assure( "document has no XChartDataArray", xDataArray != null );
758 xDataArray.setData( aData );
759 xDataArray.setRowDescriptions( aRowDescriptions );
760 xDataArray.setColumnDescriptions( aColumnDescriptions );
762 mxOldDoc.attachData( xData );
764 catch( Exception ex )
766 failed( ex.getMessage() );
767 ex.printStackTrace( (PrintWriter)log );
771 // ------------
773 public void testStockProperties()
777 setStockData_Type4();
779 XMultiServiceFactory xFact = (XMultiServiceFactory) UnoRuntime.queryInterface(
780 XMultiServiceFactory.class, mxOldDoc );
781 assure( "document is no factory", xFact != null );
783 String aMyServiceName = new String( "com.sun.star.chart.StockDiagram" );
784 XDiagram xDia = (XDiagram) UnoRuntime.queryInterface(
785 XDiagram.class, xFact.createInstance( aMyServiceName ));
786 assure( aMyServiceName + " could not be created", xDia != null );
788 mxOldDoc.setDiagram( xDia );
790 XPropertySet xDiaProp = (XPropertySet) UnoRuntime.queryInterface(
791 XPropertySet.class, xDia );
792 assure( "Diagram is no XPropertySet", xDiaProp != null );
794 xDiaProp.setPropertyValue( "Volume", new Boolean( true ));
795 assure( "Has Volume", AnyConverter.toBoolean( xDiaProp.getPropertyValue( "Volume" )));
797 xDiaProp.setPropertyValue( "UpDown", new Boolean( true ));
798 assure( "Has UpDown", AnyConverter.toBoolean( xDiaProp.getPropertyValue( "UpDown" )));
800 // MinMaxLine
801 XStatisticDisplay xMinMaxProvider = (XStatisticDisplay) UnoRuntime.queryInterface(
802 XStatisticDisplay.class, xDia );
803 assure( "Diagram is no XStatisticDisplay", xMinMaxProvider != null );
804 XPropertySet xMinMaxProp = xMinMaxProvider.getMinMaxLine();
805 assure( "No MinMaxLine", xMinMaxProp != null );
807 int nLineColor = 0x458b00; // chartreuse4
808 xMinMaxProp.setPropertyValue( "LineColor", new Integer( nLineColor ));
809 int nNewColor = AnyConverter.toInt( xMinMaxProp.getPropertyValue( "LineColor" ) );
810 assure( "Changing LineColor of MinMax Line", nNewColor == nLineColor );
812 catch( Exception ex )
814 failed( ex.getMessage() );
815 ex.printStackTrace( (PrintWriter)log );
819 // ------------
821 public void testFactory()
825 XMultiServiceFactory xFact = (XMultiServiceFactory) UnoRuntime.queryInterface(
826 XMultiServiceFactory.class, mxOldDoc );
827 assure( "document is no factory", xFact != null );
829 Object aTestTable = xFact.createInstance( "com.sun.star.drawing.GradientTable" );
830 assure( "Couldn't create gradient table via factory", aTestTable != null );
832 catch( Exception ex )
834 failed( ex.getMessage() );
835 ex.printStackTrace( (PrintWriter)log );
839 // ------------
841 public void testData()
845 // set data
846 double aData[][] = {
847 { 1.0, 1.5, 2.0, 2.5, 3.0 },
848 { 2.0, 2.5, 3.0, 3.5, 4.0 },
849 { 3.0, 3.5, 4.0, 4.5, 5.0 }
852 String[] aColumnDescriptions = {
853 "First Column", "Second Column", "Third Column",
854 "Fourth Column", "Fifth Column"
857 String[] aRowDescriptions = {
858 "First Row", "Second Row", "Third Row"
861 XPropertySet xDiaProp = (XPropertySet) UnoRuntime.queryInterface(
862 XPropertySet.class, mxOldDoc.getDiagram() );
863 ChartDataRowSource eNewSource = ChartDataRowSource.ROWS;
864 xDiaProp.setPropertyValue( "DataRowSource", eNewSource );
865 assure( "Couldn't set \"DataRowSource\" property at Diagram",
866 AnyConverter.toObject(
867 new Type( ChartDataRowSource.class ),
868 xDiaProp.getPropertyValue( "DataRowSource" )) == eNewSource );
870 XChartData xData = mxOldDoc.getData();
871 XChartDataArray xDataArray = (XChartDataArray) UnoRuntime.queryInterface(
872 XChartDataArray.class, xData );
873 assure( "document has no XChartDataArray", xDataArray != null );
875 xDataArray.setData( aData );
876 xDataArray.setRowDescriptions( aRowDescriptions );
877 xDataArray.setColumnDescriptions( aColumnDescriptions );
879 mxOldDoc.attachData( xData );
881 // get data
882 double aReadData[][];
883 String[] aReadColumnDescriptions;
884 String[] aReadRowDescriptions;
886 // refetch data
887 xData = mxOldDoc.getData();
888 xDataArray = (XChartDataArray) UnoRuntime.queryInterface(
889 XChartDataArray.class, xData );
890 assure( "document has no XChartDataArray", xDataArray != null );
892 aReadData = xDataArray.getData();
893 aReadRowDescriptions = xDataArray.getRowDescriptions();
894 aReadColumnDescriptions = xDataArray.getColumnDescriptions();
896 // compare to values set before
897 assure( "Data size differs", aData.length == aReadData.length );
898 for( int i=0; i<aReadData.length; ++i )
900 assure( "Data size differs", aData[i].length == aReadData[i].length );
901 for( int j=0; j<aReadData[i].length; ++j )
902 assure( "Data differs", aData[i][j] == aReadData[i][j] );
905 assure( "Column Description size differs", aColumnDescriptions.length == aReadColumnDescriptions.length );
906 for( int i=0; i<aReadColumnDescriptions.length; ++i )
907 assure( "Column Descriptions differ", aColumnDescriptions[i].equals( aReadColumnDescriptions[i] ));
909 assure( "Row Description size differs", aRowDescriptions.length == aReadRowDescriptions.length );
910 for( int i=0; i<aReadRowDescriptions.length; ++i )
911 assure( "Row Descriptions differ", aRowDescriptions[i].equals( aReadRowDescriptions[i] ));
913 catch( Exception ex )
915 failed( ex.getMessage() );
916 ex.printStackTrace( (PrintWriter)log );
920 // ================================================================================
922 private XModel mxChartModel;
923 private XChartDocument mxOldDoc;
924 private boolean mbCreateView;
926 // --------------------------------------------------------------------------------
928 private XModel createDocument( String sDocType )
930 XModel aResult = null;
933 XComponentLoader aLoader = (XComponentLoader) UnoRuntime.queryInterface(
934 XComponentLoader.class,
935 ((XMultiServiceFactory)param.getMSF()).createInstance( "com.sun.star.frame.Desktop" ) );
937 aResult = (XModel) UnoRuntime.queryInterface(
938 XModel.class,
939 aLoader.loadComponentFromURL( "private:factory/" + sDocType,
940 "_blank",
942 new PropertyValue[ 0 ] ) );
944 catch( Exception ex )
946 failed( ex.getMessage() );
947 ex.printStackTrace( (PrintWriter)log );
950 return aResult;
953 // ------------
955 public XModel createChartModel()
957 XModel aResult = null;
960 aResult = (XModel) UnoRuntime.queryInterface(
961 XModel.class,
962 ((XMultiServiceFactory)param.getMSF()).createInstance( "com.sun.star.comp.chart2.ChartModel" ) );
964 catch( Exception ex )
966 failed( ex.getMessage() );
967 ex.printStackTrace( (PrintWriter)log );
970 return aResult;
973 // ------------
975 private XComponentContext getComponentContext( XMultiServiceFactory xFact )
977 XComponentContext xResult = null;
979 XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface(
980 XPropertySet.class, xFact );
981 if( xProp != null )
984 xResult = (XComponentContext)
985 AnyConverter.toObject(
986 new Type( XComponentContext.class ),
987 xProp.getPropertyValue( "DefaultContext" ) );
989 catch( Exception ex )
991 failed( ex.getMessage() );
992 ex.printStackTrace( (PrintWriter)log );
995 return xResult;
998 // ------------
1000 private void printInterfacesAndServices( Object oObj )
1002 log.println( "Services:" );
1003 util.dbg.getSuppServices( oObj );
1004 log.println( "Interfaces:" );
1005 util.dbg.printInterfaces( (XInterface)oObj, true );
1008 // ------------
1010 /// see rtl/math.hxx
1011 private boolean approxEqual( double a, double b )
1013 if( a == b )
1014 return true;
1015 double x = a - b;
1016 return (x < 0.0 ? -x : x)
1017 < ((a < 0.0 ? -a : a) * (1.0 / (16777216.0 * 16777216.0)));
1020 // ------------
1021 /** returns true if a and b differ no more than tolerance.
1023 @param tolerance
1024 must be non-negative
1026 private boolean approxEqual( int a, int b, int tolerance )
1028 if( a != b )
1029 log.println( "Integer values differ by " + java.lang.Math.abs( a-b ));
1030 return ( ( a - tolerance <= b ) ||
1031 ( a + tolerance >= b ));