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
23 import complexlib
.ComplexTestCase
;
24 import com
.sun
.star
.uno
.XInterface
;
25 import com
.sun
.star
.uno
.UnoRuntime
;
26 import com
.sun
.star
.uno
.Type
;
27 import com
.sun
.star
.uno
.XComponentContext
;
29 import java
.io
.PrintWriter
;
30 import com
.sun
.star
.lang
.*;
31 import com
.sun
.star
.beans
.*;
32 import com
.sun
.star
.frame
.*;
33 import com
.sun
.star
.chart
.*;
34 import com
.sun
.star
.drawing
.*;
35 import com
.sun
.star
.awt
.*;
36 import com
.sun
.star
.container
.*;
37 import com
.sun
.star
.util
.XCloseable
;
38 import com
.sun
.star
.util
.CloseVetoException
;
40 import com
.sun
.star
.uno
.AnyConverter
;
43 * The following Complex Test will test the
44 * com.sun.star.document.IndexedPropertyValues
48 public class TestCaseOldAPI
extends ComplexTestCase
{
50 // The name of the tested service
51 private final String testedServiceName
=
52 "com.sun.star.chart.ChartDocument";
54 // The first of the mandatory functions:
56 * Return the name of the test.
57 * In this case it is the actual name of the service.
58 * @return The tested service.
60 public String
getTestObjectName() {
61 return testedServiceName
;
64 // The second of the mandatory functions: return all test methods as an
65 // array. There is only one test function in this example.
67 * Return all test methods.
68 * @return The test methods.
70 public String
[] getTestMethodNames() {
71 // For some tests a view needs to be created. Accessing the model via
72 // this program and the view may lead to problems
73 boolean bAvoidViewCreation
= false;
75 if( bAvoidViewCreation
)
82 "testDataSeriesAndPoints",
98 "testDataSeriesAndPoints",
100 "testStockProperties"
108 // set to "true" to get a view
112 mxChartModel
= createDocument( "schart" );
114 mxChartModel
= createChartModel();
116 mxOldDoc
= (XChartDocument
) UnoRuntime
.queryInterface(
117 XChartDocument
.class, mxChartModel
);
124 XCloseable xCloseable
= (XCloseable
) UnoRuntime
.queryInterface(
125 XCloseable
.class, mxChartModel
);
126 assure( "document is no XCloseable", xCloseable
!= null );
128 // do not close document if there exists a view
133 xCloseable
.close( true );
135 catch( CloseVetoException ex
)
137 failed( ex
.getMessage() );
138 ex
.printStackTrace( (PrintWriter
)log
);
145 public void testTitle()
149 XPropertySet xDocProp
= (XPropertySet
) UnoRuntime
.queryInterface(
150 XPropertySet
.class, mxOldDoc
);
151 assure( "Chart Document is no XPropertySet", xDocProp
!= null );
152 xDocProp
.setPropertyValue( "HasMainTitle", new Boolean( true ));
153 assure( "Property HasMainTitle", AnyConverter
.toBoolean(
154 xDocProp
.getPropertyValue( "HasMainTitle" )));
156 XShape xTitleShape
= mxOldDoc
.getTitle();
157 XPropertySet xTitleProp
= (XPropertySet
) UnoRuntime
.queryInterface(
158 XPropertySet
.class, xTitleShape
);
160 // set property via old API
161 if( xTitleProp
!= null )
163 String aTitle
= " Overwritten by Old API ";
164 float fHeight
= (float)17.0;
166 xTitleProp
.setPropertyValue( "String", aTitle
);
167 xTitleProp
.setPropertyValue( "CharHeight", new Float( fHeight
) );
169 float fNewHeight
= AnyConverter
.toFloat( xTitleProp
.getPropertyValue( "CharHeight" ) );
170 assure( "Changing CharHeight via old API failed", fNewHeight
== fHeight
);
172 String aNewTitle
= AnyConverter
.toString( xTitleProp
.getPropertyValue( "String" ) );
173 assure( "Property \"String\" failed", aNewTitle
.equals( aTitle
));
177 Point aSetPos
= new Point();
180 xTitleShape
.setPosition( aSetPos
);
182 Point aNewPos
= xTitleShape
.getPosition();
183 assure( "Title Position X", approxEqual( aNewPos
.X
, aSetPos
.X
, 1 ));
184 assure( "Title Position Y", approxEqual( aNewPos
.Y
, aSetPos
.Y
, 1 ));
186 catch( Exception ex
)
188 failed( ex
.getMessage() );
189 ex
.printStackTrace( (PrintWriter
)log
);
195 public void testSubTitle()
199 XPropertySet xDocProp
= (XPropertySet
) UnoRuntime
.queryInterface(
200 XPropertySet
.class, mxOldDoc
);
201 assure( "Chart Document is no XPropertySet", xDocProp
!= null );
202 xDocProp
.setPropertyValue( "HasSubTitle", new Boolean( true ));
203 assure( "Property HasSubTitle", AnyConverter
.toBoolean(
204 xDocProp
.getPropertyValue( "HasSubTitle" )));
206 XShape xTitleShape
= mxOldDoc
.getSubTitle();
207 XPropertySet xTitleProp
= (XPropertySet
) UnoRuntime
.queryInterface(
208 XPropertySet
.class, xTitleShape
);
210 // set Property via old API
211 if( xTitleProp
!= null )
213 int nColor
= 0x009acd; // DeepSkyBlue3
214 float fWeight
= FontWeight
.BOLD
;
215 float fHeight
= (float)14.0;
217 xTitleProp
.setPropertyValue( "CharColor", new Integer( nColor
) );
218 xTitleProp
.setPropertyValue( "CharWeight", new Float( fWeight
));
219 xTitleProp
.setPropertyValue( "CharHeight", new Float( fHeight
) );
221 int nNewColor
= AnyConverter
.toInt( xTitleProp
.getPropertyValue( "CharColor" ) );
222 assure( "Changing CharColor via old API failed", nNewColor
== nColor
);
224 float fNewWeight
= AnyConverter
.toFloat( xTitleProp
.getPropertyValue( "CharWeight" ) );
225 assure( "Changing CharWeight via old API failed", fNewWeight
== fWeight
);
227 float fNewHeight
= AnyConverter
.toFloat( xTitleProp
.getPropertyValue( "CharHeight" ) );
228 assure( "Changing CharHeight via old API failed", fNewHeight
== fHeight
);
231 catch( Exception ex
)
233 failed( ex
.getMessage() );
234 ex
.printStackTrace( (PrintWriter
)log
);
240 public void testDiagram()
245 XDiagram xDia
= mxOldDoc
.getDiagram();
248 X3DDisplay xDisp
= (X3DDisplay
) UnoRuntime
.queryInterface(
249 X3DDisplay
.class, xDia
);
250 assure( "X3DDisplay not supported", xDisp
!= null );
253 XPropertySet xProp
= xDisp
.getWall();
256 int nColor
= 0xffe1ff; // thistle1
257 xProp
.setPropertyValue( "FillColor", new Integer( nColor
) );
258 int nNewColor
= AnyConverter
.toInt( xProp
.getPropertyValue( "FillColor" ) );
259 assure( "Changing FillColor via old API failed", nNewColor
== nColor
);
262 assure( "Wrong Diagram Type", xDia
.getDiagramType().equals(
263 "com.sun.star.chart.BarDiagram" ));
265 // Diagram properties
266 xProp
= (XPropertySet
) UnoRuntime
.queryInterface( XPropertySet
.class, xDia
);
267 assure( "Diagram is no property set", xProp
!= null );
270 boolean bFirstYAxisText
= false;
271 xProp
.setPropertyValue( "HasYAxisDescription", new Boolean( bFirstYAxisText
));
272 boolean bNewFirstYAxisText
= AnyConverter
.toBoolean(
273 xProp
.getPropertyValue( "HasYAxisDescription" ));
274 assure( "Removing description of first y-axis", bNewFirstYAxisText
== bFirstYAxisText
);
276 // boolean bYAxisTitle = true;
277 // xProp.setPropertyValue( "HasYAxisTitle", new Boolean( bYAxisTitle ));
278 // boolean bNewYAxisTitle = AnyConverter.toBoolean(
279 // xProp.getPropertyValue( "HasYAxisTitle" ));
280 // assure( "Adding y-axis title", bNewYAxisTitle == bYAxisTitle );
283 // XAxisYSupplier xYAxisSuppl = (XAxisYSupplier) UnoRuntime.queryInterface(
284 // XAxisYSupplier.class, mxOldDoc.getDiagram() );
285 // assure( "Diagram is no y-axis supplier", xYAxisSuppl != null );
286 // XPropertySet xAxisTitleProp = (XPropertySet) UnoRuntime.queryInterface(
287 // XPropertySet.class, xYAxisSuppl.getYAxisTitle() );
288 // assure( "Y-Axis Title is no XPropertySet", xAxisTitleProp != null );
289 // xAxisTitleProp.setPropertyValue( "String", "New y axis title" );
292 boolean bSecondaryYAxis
= true;
293 xProp
.setPropertyValue( "HasSecondaryYAxis", new Boolean( bSecondaryYAxis
));
294 boolean bNewSecYAxisValue
= AnyConverter
.toBoolean(
295 xProp
.getPropertyValue( "HasSecondaryYAxis" ));
296 assure( "Adding a second y-axis does not work", bNewSecYAxisValue
== bSecondaryYAxis
);
298 XTwoAxisYSupplier xSecYAxisSuppl
= (XTwoAxisYSupplier
) UnoRuntime
.queryInterface(
299 XTwoAxisYSupplier
.class, xDia
);
300 assure( "XTwoAxisYSupplier not implemented", xSecYAxisSuppl
!= null );
301 assure( "No second y-axis found", xSecYAxisSuppl
.getSecondaryYAxis() != null );
306 XShape xDiagramShape
= (XShape
) UnoRuntime
.queryInterface(
307 XShape
.class, xDia
);
309 Point aOldPos
= xDiagramShape
.getPosition();
312 Point aSetPos
= new Point();
313 aSetPos
.X
= aOldPos
.X
+ xDiff
;
314 aSetPos
.Y
= aOldPos
.Y
+ yDiff
;
315 xDiagramShape
.setPosition( aSetPos
);
317 Point aNewPos
= xDiagramShape
.getPosition();
318 //System.out.println( "set X = " + aSetPos.X + ", new X = " + aNewPos.X );
319 //System.out.println( "set Y = " + aSetPos.Y + ", new Y = " + aNewPos.Y );
320 assure( "Diagram Position X", approxEqual( aNewPos
.X
, aSetPos
.X
, 1 ));
321 assure( "Diagram Position Y", approxEqual( aNewPos
.Y
, aSetPos
.Y
, 1 ));
326 XShape xDiagramShape
= (XShape
) UnoRuntime
.queryInterface(
327 XShape
.class, xDia
);
329 Size aOldSize
= xDiagramShape
.getSize();
330 int xDiff
= aOldSize
.Width
/2+2;
331 int yDiff
= aOldSize
.Height
/2+2;
332 Size aSetSize
= new Size();
333 aSetSize
.Width
= aOldSize
.Width
- xDiff
;
334 aSetSize
.Height
= aOldSize
.Height
- yDiff
;
335 xDiagramShape
.setSize( aSetSize
);
337 Size aNewSize
= xDiagramShape
.getSize();
338 //System.out.println( "set width = " + aSetSize.Width + ", new width = " + aNewSize.Width );
339 //System.out.println( "set height = " + aSetSize.Height + ", new height = " + aNewSize.Height );
340 assure( "Diagram Width", approxEqual( aNewSize
.Width
, aSetSize
.Width
, 2 ));
341 assure( "Diagram Height", approxEqual( aNewSize
.Height
, aSetSize
.Height
, 2 ));
344 catch( Exception ex
)
346 failed( ex
.getMessage() );
347 ex
.printStackTrace( (PrintWriter
)log
);
353 public void testAxis()
357 XAxisYSupplier xYAxisSuppl
= (XAxisYSupplier
) UnoRuntime
.queryInterface(
358 XAxisYSupplier
.class, mxOldDoc
.getDiagram() );
359 assure( "Diagram is no y-axis supplier", xYAxisSuppl
!= null );
361 XPropertySet xProp
= xYAxisSuppl
.getYAxis();
362 assure( "No y-axis found", xProp
!= null );
365 Object oMax
= xProp
.getPropertyValue( "Max" );
366 assure( "No Maximum set", AnyConverter
.isDouble( oMax
));
367 fMax1
= AnyConverter
.toDouble( oMax
);
368 log
.println( "Maximum retrieved: " + fMax1
);
369 //todo: the view has to be built before there is an explicit value
370 // assure( "Max is 0.0", fMax1 > 0.0 );
371 xProp
.setPropertyValue( "AutoMax", new Boolean( false ));
372 oMax
= xProp
.getPropertyValue( "Max" );
373 assure( "No Maximum set", AnyConverter
.isDouble( oMax
));
374 fMax2
= AnyConverter
.toDouble( oMax
);
375 log
.println( "Maximum with AutoMax off: " + fMax2
);
376 assure( "maxima differ", fMax1
== fMax2
);
378 double nNewMax
= 12.3;
379 double nNewOrigin
= 2.7;
381 xProp
.setPropertyValue( "Max", new Double( nNewMax
));
382 assure( "AutoMax is on", ! AnyConverter
.toBoolean( xProp
.getPropertyValue( "AutoMax" )) );
384 assure( "Maximum value invalid",
386 AnyConverter
.toDouble( xProp
.getPropertyValue( "Max" )),
389 xProp
.setPropertyValue( "AutoMin", new Boolean( true ));
390 assure( "AutoMin is off", AnyConverter
.toBoolean( xProp
.getPropertyValue( "AutoMin" )) );
392 xProp
.setPropertyValue( "Origin", new Double( nNewOrigin
));
393 assure( "Origin invalid",
395 AnyConverter
.toDouble( xProp
.getPropertyValue( "Origin" )),
397 xProp
.setPropertyValue( "AutoOrigin", new Boolean( true ));
398 assure( "AutoOrigin is off", AnyConverter
.toBoolean( xProp
.getPropertyValue( "AutoOrigin" )) );
399 Object oOrigin
= xProp
.getPropertyValue( "Origin" );
400 assure( "No Origin set", AnyConverter
.isDouble( oOrigin
));
401 log
.println( "Origin retrieved: " + AnyConverter
.toDouble( oOrigin
));
403 xProp
.setPropertyValue( "Logarithmic", new Boolean( true ));
404 assure( "Scaling is not logarithmic",
405 AnyConverter
.toBoolean( xProp
.getPropertyValue( "Logarithmic" )) );
406 xProp
.setPropertyValue( "Logarithmic", new Boolean( false ));
407 assure( "Scaling is not logarithmic",
408 ! AnyConverter
.toBoolean( xProp
.getPropertyValue( "Logarithmic" )) );
410 int nNewColor
= 0xcd853f; // peru
411 xProp
.setPropertyValue( "LineColor", new Integer( nNewColor
));
412 assure( "Property LineColor",
413 AnyConverter
.toInt( xProp
.getPropertyValue( "LineColor" )) == nNewColor
);
414 float fNewCharHeight
= (float)(16.0);
415 xProp
.setPropertyValue( "CharHeight", new Float( fNewCharHeight
));
416 assure( "Property CharHeight",
417 AnyConverter
.toFloat( xProp
.getPropertyValue( "CharHeight" )) == fNewCharHeight
);
419 int nNewTextRotation
= 700; // in 1/100 degrees
420 xProp
.setPropertyValue( "TextRotation", new Integer( nNewTextRotation
));
421 assure( "Property TextRotation",
422 AnyConverter
.toInt( xProp
.getPropertyValue( "TextRotation" )) == nNewTextRotation
);
424 double fStepMain
= 10.0;
425 xProp
.setPropertyValue( "StepMain", new Double( fStepMain
));
426 assure( "Property StepMain",
427 AnyConverter
.toDouble( xProp
.getPropertyValue( "StepMain" )) == fStepMain
);
429 // note: fStepHelp must be a divider of fStepMain, because
430 // internally, the help-step is stored as an integer number of
432 double fStepHelp
= 5.0;
433 xProp
.setPropertyValue( "StepHelp", new Double( fStepHelp
));
434 assure( "Property StepHelp",
435 AnyConverter
.toDouble( xProp
.getPropertyValue( "StepHelp" )) == fStepHelp
);
437 xProp
.setPropertyValue( "DisplayLabels", new Boolean( false ));
438 assure( "Property DisplayLabels", ! AnyConverter
.toBoolean(
439 xProp
.getPropertyValue( "DisplayLabels" )));
441 catch( Exception ex
)
443 failed( ex
.getMessage() );
444 ex
.printStackTrace( (PrintWriter
)log
);
450 public void testLegend()
452 XShape xLegend
= mxOldDoc
.getLegend();
453 assure( "No Legend returned", xLegend
!= null );
455 XPropertySet xLegendProp
= (XPropertySet
) UnoRuntime
.queryInterface(
456 XPropertySet
.class, xLegend
);
457 assure( "Legend is no property set", xLegendProp
!= null );
461 ChartLegendPosition eNewPos
= ChartLegendPosition
.BOTTOM
;
462 xLegendProp
.setPropertyValue( "Alignment", eNewPos
);
463 assure( "Property Alignment",
464 AnyConverter
.toObject(
465 new Type( ChartLegendPosition
.class ),
466 xLegendProp
.getPropertyValue( "Alignment" )) == eNewPos
);
468 float fNewCharHeight
= (float)(11.0);
469 xLegendProp
.setPropertyValue( "CharHeight", new Float( fNewCharHeight
));
470 assure( "Property CharHeight",
471 AnyConverter
.toFloat( xLegendProp
.getPropertyValue( "CharHeight" )) == fNewCharHeight
);
475 Point aOldPos
= xLegend
.getPosition();
478 Point aSetPos
= new Point();
479 aSetPos
.X
= aOldPos
.X
+ xDiff
;
480 aSetPos
.Y
= aOldPos
.Y
+ yDiff
;
481 xLegend
.setPosition( aSetPos
);
483 Point aNewPos
= xLegend
.getPosition();
484 assure( "Legend Position X", approxEqual( aNewPos
.X
, aSetPos
.X
, 1 ));
485 assure( "Legend Position Y", approxEqual( aNewPos
.Y
, aSetPos
.Y
, 1 ));
488 catch( Exception ex
)
490 failed( ex
.getMessage() );
491 ex
.printStackTrace( (PrintWriter
)log
);
497 public void testArea()
499 XPropertySet xArea
= mxOldDoc
.getArea();
500 assure( "No Area", xArea
!= null );
504 int nColor
= 0xf5fffa; // mint cream
505 xArea
.setPropertyValue( "FillColor", new Integer( nColor
) );
506 xArea
.setPropertyValue( "FillStyle", FillStyle
.SOLID
);
507 // XPropertySetInfo xInfo = xArea.getPropertySetInfo();
508 // assure( "Area does not support ChartUserDefinedAttributes",
509 // xInfo.hasPropertyByName( "ChartUserDefinedAttributes" ));
511 // String aTestAttributeName = "test:foo";
512 // String aTestAttributeValue = "content";
513 // XNameContainer xUserDefAttributes = (XNameContainer) AnyConverter.toObject(
514 // new Type( XNameContainer.class ), xArea.getPropertyValue( "ChartUserDefinedAttributes" ));
515 // xUserDefAttributes.insertByName( aTestAttributeName, aTestAttributeValue );
517 // String aContent = AnyConverter.toString( xUserDefAttributes.getByName( aTestAttributeName ));
518 // assure( "Wrong content in UserDefinedAttributes container",
519 // aContent.equals( aTestAttributeValue ));
521 int nNewColor
= AnyConverter
.toInt( xArea
.getPropertyValue( "FillColor" ) );
522 assure( "Changing FillColor of Area failed", nNewColor
== nColor
);
524 catch( Exception ex
)
526 failed( ex
.getMessage() );
527 ex
.printStackTrace( (PrintWriter
)log
);
533 public void testChartType()
535 XMultiServiceFactory xFact
= (XMultiServiceFactory
) UnoRuntime
.queryInterface(
536 XMultiServiceFactory
.class, mxOldDoc
);
537 assure( "document is no factory", xFact
!= null );
541 String aMyServiceName
= new String( "com.sun.star.chart.BarDiagram" );
542 String aServices
[] = xFact
.getAvailableServiceNames();
543 boolean bServiceFound
= false;
544 for( int i
= 0; i
< aServices
.length
; ++i
)
546 if( aServices
[ i
].equals( aMyServiceName
))
548 bServiceFound
= true;
552 assure( "getAvailableServiceNames did not return " + aMyServiceName
, bServiceFound
);
556 XDiagram xDia
= (XDiagram
) UnoRuntime
.queryInterface(
557 XDiagram
.class, xFact
.createInstance( aMyServiceName
));
558 assure( aMyServiceName
+ " could not be created", xDia
!= null );
560 mxOldDoc
.setDiagram( xDia
);
562 XPropertySet xDiaProp
= (XPropertySet
) UnoRuntime
.queryInterface(
563 XPropertySet
.class, xDia
);
564 assure( "Diagram is no XPropertySet", xDiaProp
!= null );
566 xDiaProp
.setPropertyValue( "Stacked", new Boolean( true ));
567 assure( "StackMode could not be set correctly",
568 AnyConverter
.toBoolean(
569 xDiaProp
.getPropertyValue( "Stacked" )));
571 xDiaProp
.setPropertyValue( "Dim3D", new Boolean( false ));
572 assure( "Dim3D could not be set correctly",
573 ! AnyConverter
.toBoolean(
574 xDiaProp
.getPropertyValue( "Dim3D" )));
576 xDiaProp
.setPropertyValue( "Vertical", new Boolean( true ));
577 assure( "Vertical could not be set correctly",
578 AnyConverter
.toBoolean(
579 xDiaProp
.getPropertyValue( "Vertical" )));
582 // reset to bar-chart
583 // aMyServiceName = new String( "com.sun.star.chart.BarDiagram" );
584 // XDiagram xDia = (XDiagram) UnoRuntime.queryInterface(
585 // XDiagram.class, xFact.createInstance( aMyServiceName ));
586 // assure( aMyServiceName + " could not be created", xDia != null );
588 // mxOldDoc.setDiagram( xDia );
590 catch( Exception ex
)
592 failed( ex
.getMessage() );
593 ex
.printStackTrace( (PrintWriter
)log
);
599 public void testAggregation()
602 XChartDocument xDiaProv
= (XChartDocument
) UnoRuntime
.queryInterface(
603 XChartDocument
.class, mxOldDoc
);
604 assure( "query to new interface failed", xDiaProv
!= null );
606 com
.sun
.star
.chart
.XChartDocument xDoc
= (com
.sun
.star
.chart
.XChartDocument
) UnoRuntime
.queryInterface(
607 com
.sun
.star
.chart
.XChartDocument
.class, xDiaProv
);
608 assure( "querying back to old interface failed", xDoc
!= null );
613 public void testDataSeriesAndPoints()
617 XDiagram xDia
= mxOldDoc
.getDiagram();
618 assure( "Invalid Diagram", xDia
!= null );
619 XMultiServiceFactory xFact
= (XMultiServiceFactory
) UnoRuntime
.queryInterface(
620 XMultiServiceFactory
.class, mxOldDoc
);
621 assure( "document is no factory", xFact
!= null );
624 XPropertySet xProp
= xDia
.getDataRowProperties( 0 );
625 int nColor
= 0xffd700; // gold
626 xProp
.setPropertyValue( "FillColor", new Integer( nColor
));
627 int nNewColor
= AnyConverter
.toInt( xProp
.getPropertyValue( "FillColor" ) );
628 assure( "Changing FillColor of Data Series failed", nNewColor
== nColor
);
631 assure( "No DataRowProperties for series 0", xProp
!= null );
633 // note: the FillGradient property is optional, however it was
634 // supported in the old chart's API
635 XNameContainer xGradientTable
= (XNameContainer
) UnoRuntime
.queryInterface(
636 XNameContainer
.class,
637 xFact
.createInstance( "com.sun.star.drawing.GradientTable" ));
638 assure( "no gradient table", xGradientTable
!= null );
639 String aGradientName
= "NewAPITestGradient";
640 Gradient aGradient
= new Gradient();
641 aGradient
.Style
= GradientStyle
.LINEAR
;
642 aGradient
.StartColor
= 0xe0ffff; // light cyan
643 aGradient
.EndColor
= 0xff8c00; // dark orange
644 aGradient
.Angle
= 300; // 30 degrees
645 aGradient
.Border
= 15;
646 aGradient
.XOffset
= 0;
647 aGradient
.YOffset
= 0;
648 aGradient
.StartIntensity
= 100;
649 aGradient
.EndIntensity
= 80;
650 aGradient
.StepCount
= 23;
652 xGradientTable
.insertByName( aGradientName
, aGradient
);
653 xProp
.setPropertyValue( "FillStyle", FillStyle
.GRADIENT
);
654 xProp
.setPropertyValue( "FillGradientName", aGradientName
);
655 String aNewGradientName
= AnyConverter
.toString( xProp
.getPropertyValue( "FillGradientName" ));
656 assure( "GradientName", aNewGradientName
.equals( aGradientName
));
657 Gradient aNewGradient
= (Gradient
) AnyConverter
.toObject(
658 new Type( Gradient
.class ),
659 xGradientTable
.getByName( aNewGradientName
));
660 assure( "Gradient Style", aNewGradient
.Style
== aGradient
.Style
);
661 assure( "Gradient StartColor", aNewGradient
.StartColor
== aGradient
.StartColor
);
662 assure( "Gradient EndColor", aNewGradient
.EndColor
== aGradient
.EndColor
);
663 assure( "Gradient Angle", aNewGradient
.Angle
== aGradient
.Angle
);
664 assure( "Gradient Border", aNewGradient
.Border
== aGradient
.Border
);
665 assure( "Gradient XOffset", aNewGradient
.XOffset
== aGradient
.XOffset
);
666 assure( "Gradient YOffset", aNewGradient
.YOffset
== aGradient
.YOffset
);
667 assure( "Gradient StartIntensity", aNewGradient
.StartIntensity
== aGradient
.StartIntensity
);
668 assure( "Gradient EndIntensity", aNewGradient
.EndIntensity
== aGradient
.EndIntensity
);
669 assure( "Gradient StepCount", aNewGradient
.StepCount
== aGradient
.StepCount
);
672 xProp
= xDia
.getDataPointProperties( 1, 0 );
673 assure( "No DataPointProperties for (1,0)", xProp
!= null );
675 // note: the FillHatch property is optional, however it was
676 // supported in the old chart's API
677 XNameContainer xHatchTable
= (XNameContainer
) UnoRuntime
.queryInterface(
678 XNameContainer
.class,
679 xFact
.createInstance( "com.sun.star.drawing.HatchTable" ));
680 assure( "no hatch table", xHatchTable
!= null );
681 String aHatchName
= "NewAPITestHatch";
682 Hatch aHatch
= new Hatch();
683 aHatch
.Style
= HatchStyle
.DOUBLE
;
684 aHatch
.Color
= 0xd2691e; // chocolate
685 aHatch
.Distance
= 200; // 2 mm (?)
686 aHatch
.Angle
= 230; // 23 degrees
688 xHatchTable
.insertByName( aHatchName
, aHatch
);
689 xProp
.setPropertyValue( "FillHatchName", aHatchName
);
690 xProp
.setPropertyValue( "FillStyle", FillStyle
.HATCH
);
691 xProp
.setPropertyValue( "FillBackground", new Boolean( true ));
692 String aNewHatchName
= AnyConverter
.toString( xProp
.getPropertyValue( "FillHatchName" ));
693 assure( "HatchName", aNewHatchName
.equals( aHatchName
));
694 Hatch aNewHatch
= (Hatch
) AnyConverter
.toObject(
695 new Type( Hatch
.class ),
696 xHatchTable
.getByName( aNewHatchName
));
697 assure( "Hatch Style", aNewHatch
.Style
== aHatch
.Style
);
698 assure( "Hatch Color", aNewHatch
.Color
== aHatch
.Color
);
699 assure( "Hatch Distance", aNewHatch
.Distance
== aHatch
.Distance
);
700 assure( "Hatch Angle", aNewHatch
.Angle
== aHatch
.Angle
);
701 assure( "FillBackground", AnyConverter
.toBoolean( xProp
.getPropertyValue( "FillBackground" )) );
703 catch( Exception ex
)
705 failed( ex
.getMessage() );
706 ex
.printStackTrace( (PrintWriter
)log
);
712 public void testStatistics()
716 XDiagram xDia
= mxOldDoc
.getDiagram();
717 assure( "Invalid Diagram", xDia
!= null );
719 XPropertySet xProp
= xDia
.getDataRowProperties( 0 );
720 assure( "No DataRowProperties for first series", xProp
!= null );
722 xProp
.setPropertyValue( "MeanValue", new Boolean( true ));
723 assure( "No MeanValue", AnyConverter
.toBoolean( xProp
.getPropertyValue( "MeanValue" )) );
725 catch( Exception ex
)
727 failed( ex
.getMessage() );
728 ex
.printStackTrace( (PrintWriter
)log
);
734 public void setStockData_Type4()
738 XPropertySet xDiaProp
= (XPropertySet
) UnoRuntime
.queryInterface(
739 XPropertySet
.class, mxOldDoc
.getDiagram() );
741 ChartDataRowSource eNewSource
= ChartDataRowSource
.ROWS
;
742 xDiaProp
.setPropertyValue( "DataRowSource", eNewSource
);
743 assure( "Couldn't set \"DataRowSource\" property at Diagram",
744 AnyConverter
.toObject(
745 new Type( ChartDataRowSource
.class ),
746 xDiaProp
.getPropertyValue( "DataRowSource" )) == eNewSource
);
750 { 100.0, 200.0, 300.0, 250.0, 300.0 },
751 { 6.5, 4.5, 6.0, 5.5, 3.5 },
752 { 1.0, 1.5, 2.0, 2.5, 3.0 },
753 { 6.0, 6.5, 7.0, 6.5, 5.0 },
754 { 6.0, 5.5, 4.0, 4.5, 4.0 }
757 String
[] aRowDescriptions
=
759 "Volume", "Open", "Min", "Max", "Close"
762 String
[] aColumnDescriptions
=
764 "First Row", "Second Row", "Third Row", "Fourth Row", "Fifth Row"
768 XChartData xData
= mxOldDoc
.getData();
769 XChartDataArray xDataArray
= (XChartDataArray
) UnoRuntime
.queryInterface(
770 XChartDataArray
.class, xData
);
771 assure( "document has no XChartDataArray", xDataArray
!= null );
773 xDataArray
.setData( aData
);
774 xDataArray
.setRowDescriptions( aRowDescriptions
);
775 xDataArray
.setColumnDescriptions( aColumnDescriptions
);
777 mxOldDoc
.attachData( xData
);
779 catch( Exception ex
)
781 failed( ex
.getMessage() );
782 ex
.printStackTrace( (PrintWriter
)log
);
788 public void testStockProperties()
792 setStockData_Type4();
794 XMultiServiceFactory xFact
= (XMultiServiceFactory
) UnoRuntime
.queryInterface(
795 XMultiServiceFactory
.class, mxOldDoc
);
796 assure( "document is no factory", xFact
!= null );
798 String aMyServiceName
= new String( "com.sun.star.chart.StockDiagram" );
799 XDiagram xDia
= (XDiagram
) UnoRuntime
.queryInterface(
800 XDiagram
.class, xFact
.createInstance( aMyServiceName
));
801 assure( aMyServiceName
+ " could not be created", xDia
!= null );
803 mxOldDoc
.setDiagram( xDia
);
805 XPropertySet xDiaProp
= (XPropertySet
) UnoRuntime
.queryInterface(
806 XPropertySet
.class, xDia
);
807 assure( "Diagram is no XPropertySet", xDiaProp
!= null );
809 xDiaProp
.setPropertyValue( "Volume", new Boolean( true ));
810 assure( "Has Volume", AnyConverter
.toBoolean( xDiaProp
.getPropertyValue( "Volume" )));
812 xDiaProp
.setPropertyValue( "UpDown", new Boolean( true ));
813 assure( "Has UpDown", AnyConverter
.toBoolean( xDiaProp
.getPropertyValue( "UpDown" )));
816 XStatisticDisplay xMinMaxProvider
= (XStatisticDisplay
) UnoRuntime
.queryInterface(
817 XStatisticDisplay
.class, xDia
);
818 assure( "Diagram is no XStatisticDisplay", xMinMaxProvider
!= null );
819 XPropertySet xMinMaxProp
= xMinMaxProvider
.getMinMaxLine();
820 assure( "No MinMaxLine", xMinMaxProp
!= null );
822 int nLineColor
= 0x458b00; // chartreuse4
823 xMinMaxProp
.setPropertyValue( "LineColor", new Integer( nLineColor
));
824 int nNewColor
= AnyConverter
.toInt( xMinMaxProp
.getPropertyValue( "LineColor" ) );
825 assure( "Changing LineColor of MinMax Line", nNewColor
== nLineColor
);
827 catch( Exception ex
)
829 failed( ex
.getMessage() );
830 ex
.printStackTrace( (PrintWriter
)log
);
836 public void testFactory()
840 XMultiServiceFactory xFact
= (XMultiServiceFactory
) UnoRuntime
.queryInterface(
841 XMultiServiceFactory
.class, mxOldDoc
);
842 assure( "document is no factory", xFact
!= null );
844 Object aTestTable
= xFact
.createInstance( "com.sun.star.drawing.GradientTable" );
845 assure( "Couldn't create gradient table via factory", aTestTable
!= null );
847 catch( Exception ex
)
849 failed( ex
.getMessage() );
850 ex
.printStackTrace( (PrintWriter
)log
);
856 public void testData()
862 { 1.0, 1.5, 2.0, 2.5, 3.0 },
863 { 2.0, 2.5, 3.0, 3.5, 4.0 },
864 { 3.0, 3.5, 4.0, 4.5, 5.0 }
867 String
[] aColumnDescriptions
= {
868 "First Column", "Second Column", "Third Column",
869 "Fourth Column", "Fifth Column"
872 String
[] aRowDescriptions
= {
873 "First Row", "Second Row", "Third Row"
876 XPropertySet xDiaProp
= (XPropertySet
) UnoRuntime
.queryInterface(
877 XPropertySet
.class, mxOldDoc
.getDiagram() );
878 ChartDataRowSource eNewSource
= ChartDataRowSource
.ROWS
;
879 xDiaProp
.setPropertyValue( "DataRowSource", eNewSource
);
880 assure( "Couldn't set \"DataRowSource\" property at Diagram",
881 AnyConverter
.toObject(
882 new Type( ChartDataRowSource
.class ),
883 xDiaProp
.getPropertyValue( "DataRowSource" )) == eNewSource
);
885 XChartData xData
= mxOldDoc
.getData();
886 XChartDataArray xDataArray
= (XChartDataArray
) UnoRuntime
.queryInterface(
887 XChartDataArray
.class, xData
);
888 assure( "document has no XChartDataArray", xDataArray
!= null );
890 xDataArray
.setData( aData
);
891 xDataArray
.setRowDescriptions( aRowDescriptions
);
892 xDataArray
.setColumnDescriptions( aColumnDescriptions
);
894 mxOldDoc
.attachData( xData
);
897 double aReadData
[][];
898 String
[] aReadColumnDescriptions
;
899 String
[] aReadRowDescriptions
;
902 xData
= mxOldDoc
.getData();
903 xDataArray
= (XChartDataArray
) UnoRuntime
.queryInterface(
904 XChartDataArray
.class, xData
);
905 assure( "document has no XChartDataArray", xDataArray
!= null );
907 aReadData
= xDataArray
.getData();
908 aReadRowDescriptions
= xDataArray
.getRowDescriptions();
909 aReadColumnDescriptions
= xDataArray
.getColumnDescriptions();
911 // compare to values set before
912 assure( "Data size differs", aData
.length
== aReadData
.length
);
913 for( int i
=0; i
<aReadData
.length
; ++i
)
915 assure( "Data size differs", aData
[i
].length
== aReadData
[i
].length
);
916 for( int j
=0; j
<aReadData
[i
].length
; ++j
)
917 assure( "Data differs", aData
[i
][j
] == aReadData
[i
][j
] );
920 assure( "Column Description size differs", aColumnDescriptions
.length
== aReadColumnDescriptions
.length
);
921 for( int i
=0; i
<aReadColumnDescriptions
.length
; ++i
)
922 assure( "Column Descriptions differ", aColumnDescriptions
[i
].equals( aReadColumnDescriptions
[i
] ));
924 assure( "Row Description size differs", aRowDescriptions
.length
== aReadRowDescriptions
.length
);
925 for( int i
=0; i
<aReadRowDescriptions
.length
; ++i
)
926 assure( "Row Descriptions differ", aRowDescriptions
[i
].equals( aReadRowDescriptions
[i
] ));
928 catch( Exception ex
)
930 failed( ex
.getMessage() );
931 ex
.printStackTrace( (PrintWriter
)log
);
935 // ================================================================================
937 private XModel mxChartModel
;
938 private XChartDocument mxOldDoc
;
939 private boolean mbCreateView
;
941 // --------------------------------------------------------------------------------
943 private XModel
createDocument( String sDocType
)
945 XModel aResult
= null;
948 XComponentLoader aLoader
= (XComponentLoader
) UnoRuntime
.queryInterface(
949 XComponentLoader
.class,
950 ((XMultiServiceFactory
)param
.getMSF()).createInstance( "com.sun.star.frame.Desktop" ) );
952 aResult
= (XModel
) UnoRuntime
.queryInterface(
954 aLoader
.loadComponentFromURL( "private:factory/" + sDocType
,
957 new PropertyValue
[ 0 ] ) );
959 catch( Exception ex
)
961 failed( ex
.getMessage() );
962 ex
.printStackTrace( (PrintWriter
)log
);
970 public XModel
createChartModel()
972 XModel aResult
= null;
975 aResult
= (XModel
) UnoRuntime
.queryInterface(
977 ((XMultiServiceFactory
)param
.getMSF()).createInstance( "com.sun.star.comp.chart2.ChartModel" ) );
979 catch( Exception ex
)
981 failed( ex
.getMessage() );
982 ex
.printStackTrace( (PrintWriter
)log
);
990 private XComponentContext
getComponentContext( XMultiServiceFactory xFact
)
992 XComponentContext xResult
= null;
994 XPropertySet xProp
= (XPropertySet
) UnoRuntime
.queryInterface(
995 XPropertySet
.class, xFact
);
999 xResult
= (XComponentContext
)
1000 AnyConverter
.toObject(
1001 new Type( XComponentContext
.class ),
1002 xProp
.getPropertyValue( "DefaultContext" ) );
1004 catch( Exception ex
)
1006 failed( ex
.getMessage() );
1007 ex
.printStackTrace( (PrintWriter
)log
);
1015 private void printInterfacesAndServices( Object oObj
)
1017 log
.println( "Services:" );
1018 util
.dbg
.getSuppServices( oObj
);
1019 log
.println( "Interfaces:" );
1020 util
.dbg
.printInterfaces( (XInterface
)oObj
, true );
1025 /// see rtl/math.hxx
1026 private boolean approxEqual( double a
, double b
)
1031 return (x
< 0.0 ?
-x
: x
)
1032 < ((a
< 0.0 ?
-a
: a
) * (1.0 / (16777216.0 * 16777216.0)));
1036 /** returns true if a and b differ no more than tolerance.
1039 must be non-negative
1041 private boolean approxEqual( int a
, int b
, int tolerance
)
1044 log
.println( "Integer values differ by " + java
.lang
.Math
.abs( a
-b
));
1045 return ( ( a
- tolerance
<= b
) ||
1046 ( a
+ tolerance
>= b
));