xref: /aoo42x/main/chart2/qa/TestCaseOldAPI.java (revision 18dbfb8c)
1*18dbfb8cSAndrew Rist /**************************************************************
2*18dbfb8cSAndrew Rist  *
3*18dbfb8cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*18dbfb8cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*18dbfb8cSAndrew Rist  * distributed with this work for additional information
6*18dbfb8cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*18dbfb8cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*18dbfb8cSAndrew Rist  * "License"); you may not use this file except in compliance
9*18dbfb8cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*18dbfb8cSAndrew Rist  *
11*18dbfb8cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*18dbfb8cSAndrew Rist  *
13*18dbfb8cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*18dbfb8cSAndrew Rist  * software distributed under the License is distributed on an
15*18dbfb8cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*18dbfb8cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*18dbfb8cSAndrew Rist  * specific language governing permissions and limitations
18*18dbfb8cSAndrew Rist  * under the License.
19*18dbfb8cSAndrew Rist  *
20*18dbfb8cSAndrew Rist  *************************************************************/
21*18dbfb8cSAndrew Rist 
22cdf0e10cSrcweir // package name: as default, start with complex
23cdf0e10cSrcweir package qa;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir // imports
26cdf0e10cSrcweir import complexlib.ComplexTestCase;
27cdf0e10cSrcweir import com.sun.star.uno.XInterface;
28cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
29cdf0e10cSrcweir import com.sun.star.uno.Type;
30cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir import java.io.PrintWriter;
33cdf0e10cSrcweir import java.util.Hashtable;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir import com.sun.star.lang.*;
36cdf0e10cSrcweir import com.sun.star.beans.*;
37cdf0e10cSrcweir import com.sun.star.frame.*;
38cdf0e10cSrcweir import com.sun.star.chart.*;
39cdf0e10cSrcweir import com.sun.star.drawing.*;
40cdf0e10cSrcweir import com.sun.star.awt.*;
41cdf0e10cSrcweir import com.sun.star.container.*;
42cdf0e10cSrcweir import com.sun.star.util.XCloseable;
43cdf0e10cSrcweir import com.sun.star.util.CloseVetoException;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
46cdf0e10cSrcweir import com.sun.star.comp.helper.ComponentContext;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir /**
49cdf0e10cSrcweir  * The following Complex Test will test the
50cdf0e10cSrcweir  * com.sun.star.document.IndexedPropertyValues
51cdf0e10cSrcweir  * service
52cdf0e10cSrcweir  */
53cdf0e10cSrcweir 
54cdf0e10cSrcweir public class TestCaseOldAPI extends ComplexTestCase {
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     // The name of the tested service
57cdf0e10cSrcweir     private final String testedServiceName =
58cdf0e10cSrcweir           "com.sun.star.chart.ChartDocument";
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     // The first of the mandatory functions:
61cdf0e10cSrcweir     /**
62cdf0e10cSrcweir      * Return the name of the test.
63cdf0e10cSrcweir      * In this case it is the actual name of the service.
64cdf0e10cSrcweir      * @return The tested service.
65cdf0e10cSrcweir      */
getTestObjectName()66cdf0e10cSrcweir     public String getTestObjectName() {
67cdf0e10cSrcweir         return testedServiceName;
68cdf0e10cSrcweir     }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     // The second of the mandatory functions: return all test methods as an
71cdf0e10cSrcweir     // array. There is only one test function in this example.
72cdf0e10cSrcweir     /**
73cdf0e10cSrcweir      * Return all test methods.
74cdf0e10cSrcweir      * @return The test methods.
75cdf0e10cSrcweir      */
getTestMethodNames()76cdf0e10cSrcweir     public String[] getTestMethodNames() {
77cdf0e10cSrcweir         // For some tests a view needs to be created. Accessing the model via
78cdf0e10cSrcweir         // this program and the view may lead to problems
79cdf0e10cSrcweir         boolean bAvoidViewCreation = false;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir         if( bAvoidViewCreation )
82cdf0e10cSrcweir             return new String[] {
83cdf0e10cSrcweir                 "testData",
84cdf0e10cSrcweir                 "testChartType",
85cdf0e10cSrcweir                 "testArea",
86cdf0e10cSrcweir                 "testAggregation",
87cdf0e10cSrcweir                 "testFactory",
88cdf0e10cSrcweir                 "testDataSeriesAndPoints",
89cdf0e10cSrcweir                 "testStatistics",
90cdf0e10cSrcweir                 "testStockProperties"
91cdf0e10cSrcweir             };
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         return new String[] {
94cdf0e10cSrcweir             "testData",
95cdf0e10cSrcweir             "testChartType",
96cdf0e10cSrcweir             "testTitle",
97cdf0e10cSrcweir             "testSubTitle",
98cdf0e10cSrcweir             "testDiagram",
99cdf0e10cSrcweir             "testAxis",
100cdf0e10cSrcweir             "testLegend",
101cdf0e10cSrcweir             "testArea",
102cdf0e10cSrcweir             "testAggregation",
103cdf0e10cSrcweir             "testFactory",
104cdf0e10cSrcweir             "testDataSeriesAndPoints",
105cdf0e10cSrcweir             "testStatistics",
106cdf0e10cSrcweir             "testStockProperties"
107cdf0e10cSrcweir         };
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     // ____________
111cdf0e10cSrcweir 
before()112cdf0e10cSrcweir     public void before()
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir         // set to "true" to get a view
115cdf0e10cSrcweir         mbCreateView = true;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir         if( mbCreateView )
118cdf0e10cSrcweir             mxChartModel = createDocument( "schart" );
119cdf0e10cSrcweir         else
120cdf0e10cSrcweir             mxChartModel = createChartModel();
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         mxOldDoc = (XChartDocument) UnoRuntime.queryInterface(
123cdf0e10cSrcweir             XChartDocument.class, mxChartModel );
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     // ____________
127cdf0e10cSrcweir 
after()128cdf0e10cSrcweir     public void after()
129cdf0e10cSrcweir     {
130cdf0e10cSrcweir         XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(
131cdf0e10cSrcweir             XCloseable.class, mxChartModel );
132cdf0e10cSrcweir         assure( "document is no XCloseable", xCloseable != null );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir         // do not close document if there exists a view
135cdf0e10cSrcweir         if( ! mbCreateView )
136cdf0e10cSrcweir         {
137cdf0e10cSrcweir             try
138cdf0e10cSrcweir             {
139cdf0e10cSrcweir                 xCloseable.close( true );
140cdf0e10cSrcweir             }
141cdf0e10cSrcweir             catch( CloseVetoException ex )
142cdf0e10cSrcweir             {
143cdf0e10cSrcweir                 failed( ex.getMessage() );
144cdf0e10cSrcweir                 ex.printStackTrace( (PrintWriter)log );
145cdf0e10cSrcweir             }
146cdf0e10cSrcweir         }
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     // ____________
150cdf0e10cSrcweir 
testTitle()151cdf0e10cSrcweir     public void testTitle()
152cdf0e10cSrcweir     {
153cdf0e10cSrcweir         try
154cdf0e10cSrcweir         {
155cdf0e10cSrcweir             XPropertySet xDocProp = (XPropertySet) UnoRuntime.queryInterface(
156cdf0e10cSrcweir                 XPropertySet.class, mxOldDoc );
157cdf0e10cSrcweir             assure( "Chart Document is no XPropertySet", xDocProp != null );
158cdf0e10cSrcweir             xDocProp.setPropertyValue( "HasMainTitle", new Boolean( true ));
159cdf0e10cSrcweir             assure( "Property HasMainTitle", AnyConverter.toBoolean(
160cdf0e10cSrcweir                         xDocProp.getPropertyValue( "HasMainTitle" )));
161cdf0e10cSrcweir 
162cdf0e10cSrcweir             XShape xTitleShape = mxOldDoc.getTitle();
163cdf0e10cSrcweir             XPropertySet xTitleProp = (XPropertySet) UnoRuntime.queryInterface(
164cdf0e10cSrcweir                 XPropertySet.class, xTitleShape );
165cdf0e10cSrcweir 
166cdf0e10cSrcweir             // set property via old API
167cdf0e10cSrcweir             if( xTitleProp != null )
168cdf0e10cSrcweir             {
169cdf0e10cSrcweir                 String aTitle = " Overwritten by Old API ";
170cdf0e10cSrcweir                 float fHeight = (float)17.0;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir                 xTitleProp.setPropertyValue( "String", aTitle );
173cdf0e10cSrcweir                 xTitleProp.setPropertyValue( "CharHeight", new Float( fHeight ) );
174cdf0e10cSrcweir 
175cdf0e10cSrcweir                 float fNewHeight = AnyConverter.toFloat( xTitleProp.getPropertyValue( "CharHeight" ) );
176cdf0e10cSrcweir                 assure( "Changing CharHeight via old API failed", fNewHeight == fHeight );
177cdf0e10cSrcweir 
178cdf0e10cSrcweir                 String aNewTitle = AnyConverter.toString( xTitleProp.getPropertyValue( "String" ) );
179cdf0e10cSrcweir                 assure( "Property \"String\" failed", aNewTitle.equals( aTitle ));
180cdf0e10cSrcweir             }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir             // move title
183cdf0e10cSrcweir             Point aSetPos = new Point();
184cdf0e10cSrcweir             aSetPos.X = 1000;
185cdf0e10cSrcweir             aSetPos.Y = 200;
186cdf0e10cSrcweir             xTitleShape.setPosition( aSetPos );
187cdf0e10cSrcweir 
188cdf0e10cSrcweir             Point aNewPos = xTitleShape.getPosition();
189cdf0e10cSrcweir             assure( "Title Position X", approxEqual( aNewPos.X, aSetPos.X, 1 ));
190cdf0e10cSrcweir             assure( "Title Position Y", approxEqual( aNewPos.Y, aSetPos.Y, 1 ));
191cdf0e10cSrcweir         }
192cdf0e10cSrcweir         catch( Exception ex )
193cdf0e10cSrcweir         {
194cdf0e10cSrcweir             failed( ex.getMessage() );
195cdf0e10cSrcweir             ex.printStackTrace( (PrintWriter)log );
196cdf0e10cSrcweir         }
197cdf0e10cSrcweir     }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     // ____________
200cdf0e10cSrcweir 
testSubTitle()201cdf0e10cSrcweir     public void testSubTitle()
202cdf0e10cSrcweir     {
203cdf0e10cSrcweir         try
204cdf0e10cSrcweir         {
205cdf0e10cSrcweir             XPropertySet xDocProp = (XPropertySet) UnoRuntime.queryInterface(
206cdf0e10cSrcweir                 XPropertySet.class, mxOldDoc );
207cdf0e10cSrcweir             assure( "Chart Document is no XPropertySet", xDocProp != null );
208cdf0e10cSrcweir             xDocProp.setPropertyValue( "HasSubTitle", new Boolean( true ));
209cdf0e10cSrcweir             assure( "Property HasSubTitle", AnyConverter.toBoolean(
210cdf0e10cSrcweir                         xDocProp.getPropertyValue( "HasSubTitle" )));
211cdf0e10cSrcweir 
212cdf0e10cSrcweir             XShape xTitleShape = mxOldDoc.getSubTitle();
213cdf0e10cSrcweir             XPropertySet xTitleProp = (XPropertySet) UnoRuntime.queryInterface(
214cdf0e10cSrcweir                 XPropertySet.class, xTitleShape );
215cdf0e10cSrcweir 
216cdf0e10cSrcweir             // set Property via old API
217cdf0e10cSrcweir             if( xTitleProp != null )
218cdf0e10cSrcweir             {
219cdf0e10cSrcweir                 int nColor = 0x009acd; // DeepSkyBlue3
220cdf0e10cSrcweir                 float fWeight = FontWeight.BOLD;
221cdf0e10cSrcweir                 float fHeight = (float)14.0;
222cdf0e10cSrcweir 
223cdf0e10cSrcweir                 xTitleProp.setPropertyValue( "CharColor", new Integer( nColor ) );
224cdf0e10cSrcweir                 xTitleProp.setPropertyValue( "CharWeight", new Float( fWeight ));
225cdf0e10cSrcweir                 xTitleProp.setPropertyValue( "CharHeight", new Float( fHeight ) );
226cdf0e10cSrcweir 
227cdf0e10cSrcweir                 int nNewColor = AnyConverter.toInt( xTitleProp.getPropertyValue( "CharColor" ) );
228cdf0e10cSrcweir                 assure( "Changing CharColor via old API failed", nNewColor == nColor );
229cdf0e10cSrcweir 
230cdf0e10cSrcweir                 float fNewWeight = AnyConverter.toFloat( xTitleProp.getPropertyValue( "CharWeight" ) );
231cdf0e10cSrcweir                 assure( "Changing CharWeight via old API failed", fNewWeight == fWeight );
232cdf0e10cSrcweir 
233cdf0e10cSrcweir                 float fNewHeight = AnyConverter.toFloat( xTitleProp.getPropertyValue( "CharHeight" ) );
234cdf0e10cSrcweir                 assure( "Changing CharHeight via old API failed", fNewHeight == fHeight );
235cdf0e10cSrcweir             }
236cdf0e10cSrcweir         }
237cdf0e10cSrcweir         catch( Exception ex )
238cdf0e10cSrcweir         {
239cdf0e10cSrcweir             failed( ex.getMessage() );
240cdf0e10cSrcweir             ex.printStackTrace( (PrintWriter)log );
241cdf0e10cSrcweir         }
242cdf0e10cSrcweir     }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir     // ------------
245cdf0e10cSrcweir 
testDiagram()246cdf0e10cSrcweir     public void testDiagram()
247cdf0e10cSrcweir     {
248cdf0e10cSrcweir         try
249cdf0e10cSrcweir         {
250cdf0e10cSrcweir             // testing wall
251cdf0e10cSrcweir             XDiagram xDia = mxOldDoc.getDiagram();
252cdf0e10cSrcweir             if( xDia != null )
253cdf0e10cSrcweir             {
254cdf0e10cSrcweir                 X3DDisplay xDisp = (X3DDisplay) UnoRuntime.queryInterface(
255cdf0e10cSrcweir                     X3DDisplay.class, xDia );
256cdf0e10cSrcweir                 assure( "X3DDisplay not supported", xDisp != null );
257cdf0e10cSrcweir 
258cdf0e10cSrcweir                 // Wall
259cdf0e10cSrcweir                 XPropertySet xProp = xDisp.getWall();
260cdf0e10cSrcweir                 if( xProp != null )
261cdf0e10cSrcweir                 {
262cdf0e10cSrcweir                     int nColor = 0xffe1ff; // thistle1
263cdf0e10cSrcweir                     xProp.setPropertyValue( "FillColor", new Integer( nColor ) );
264cdf0e10cSrcweir                     int nNewColor = AnyConverter.toInt( xProp.getPropertyValue( "FillColor" ) );
265cdf0e10cSrcweir                     assure( "Changing FillColor via old API failed", nNewColor == nColor );
266cdf0e10cSrcweir                 }
267cdf0e10cSrcweir 
268cdf0e10cSrcweir                 assure( "Wrong Diagram Type", xDia.getDiagramType().equals(
269cdf0e10cSrcweir                             "com.sun.star.chart.BarDiagram" ));
270cdf0e10cSrcweir 
271cdf0e10cSrcweir                 // Diagram properties
272cdf0e10cSrcweir                 xProp = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xDia );
273cdf0e10cSrcweir                 assure( "Diagram is no property set", xProp != null );
274cdf0e10cSrcweir 
275cdf0e10cSrcweir                 // y-axis
276cdf0e10cSrcweir                 boolean bFirstYAxisText = false;
277cdf0e10cSrcweir                 xProp.setPropertyValue( "HasYAxisDescription", new Boolean( bFirstYAxisText ));
278cdf0e10cSrcweir                 boolean bNewFirstYAxisText = AnyConverter.toBoolean(
279cdf0e10cSrcweir                     xProp.getPropertyValue( "HasYAxisDescription" ));
280cdf0e10cSrcweir                 assure( "Removing description of first y-axis", bNewFirstYAxisText == bFirstYAxisText );
281cdf0e10cSrcweir 
282cdf0e10cSrcweir //                 boolean bYAxisTitle = true;
283cdf0e10cSrcweir //                 xProp.setPropertyValue( "HasYAxisTitle", new Boolean( bYAxisTitle ));
284cdf0e10cSrcweir //                 boolean bNewYAxisTitle = AnyConverter.toBoolean(
285cdf0e10cSrcweir //                     xProp.getPropertyValue( "HasYAxisTitle" ));
286cdf0e10cSrcweir //                 assure( "Adding y-axis title", bNewYAxisTitle == bYAxisTitle );
287cdf0e10cSrcweir 
288cdf0e10cSrcweir                 // set title text
289cdf0e10cSrcweir //                 XAxisYSupplier xYAxisSuppl = (XAxisYSupplier) UnoRuntime.queryInterface(
290cdf0e10cSrcweir //                     XAxisYSupplier.class, mxOldDoc.getDiagram() );
291cdf0e10cSrcweir //                 assure( "Diagram is no y-axis supplier", xYAxisSuppl != null );
292cdf0e10cSrcweir //                 XPropertySet xAxisTitleProp = (XPropertySet) UnoRuntime.queryInterface(
293cdf0e10cSrcweir //                     XPropertySet.class, xYAxisSuppl.getYAxisTitle() );
294cdf0e10cSrcweir //                 assure( "Y-Axis Title is no XPropertySet", xAxisTitleProp != null );
295cdf0e10cSrcweir //                 xAxisTitleProp.setPropertyValue( "String", "New y axis title" );
296cdf0e10cSrcweir 
297cdf0e10cSrcweir                 // second y-axis
298cdf0e10cSrcweir                 boolean bSecondaryYAxis = true;
299cdf0e10cSrcweir                 xProp.setPropertyValue( "HasSecondaryYAxis", new Boolean( bSecondaryYAxis ));
300cdf0e10cSrcweir                 boolean bNewSecYAxisValue = AnyConverter.toBoolean(
301cdf0e10cSrcweir                     xProp.getPropertyValue( "HasSecondaryYAxis" ));
302cdf0e10cSrcweir                 assure( "Adding a second y-axis does not work", bNewSecYAxisValue == bSecondaryYAxis );
303cdf0e10cSrcweir 
304cdf0e10cSrcweir                 XTwoAxisYSupplier xSecYAxisSuppl = (XTwoAxisYSupplier) UnoRuntime.queryInterface(
305cdf0e10cSrcweir                     XTwoAxisYSupplier.class, xDia );
306cdf0e10cSrcweir                 assure( "XTwoAxisYSupplier not implemented", xSecYAxisSuppl != null );
307cdf0e10cSrcweir                 assure( "No second y-axis found", xSecYAxisSuppl.getSecondaryYAxis() != null );
308cdf0e10cSrcweir             }
309cdf0e10cSrcweir 
310cdf0e10cSrcweir             // move diagram
311cdf0e10cSrcweir             {
312cdf0e10cSrcweir                 XShape xDiagramShape = (XShape) UnoRuntime.queryInterface(
313cdf0e10cSrcweir                     XShape.class, xDia );
314cdf0e10cSrcweir 
315cdf0e10cSrcweir                 Point aOldPos = xDiagramShape.getPosition();
316cdf0e10cSrcweir                 int xDiff = 20;
317cdf0e10cSrcweir                 int yDiff = 20;
318cdf0e10cSrcweir                 Point aSetPos = new Point();
319cdf0e10cSrcweir                 aSetPos.X = aOldPos.X + xDiff;
320cdf0e10cSrcweir                 aSetPos.Y = aOldPos.Y + yDiff;
321cdf0e10cSrcweir                 xDiagramShape.setPosition( aSetPos );
322cdf0e10cSrcweir 
323cdf0e10cSrcweir                 Point aNewPos = xDiagramShape.getPosition();
324cdf0e10cSrcweir                 //System.out.println( "set X = " + aSetPos.X + ", new X = " + aNewPos.X );
325cdf0e10cSrcweir                 //System.out.println( "set Y = " + aSetPos.Y + ", new Y = " + aNewPos.Y );
326cdf0e10cSrcweir                 assure( "Diagram Position X", approxEqual( aNewPos.X, aSetPos.X, 1 ));
327cdf0e10cSrcweir                 assure( "Diagram Position Y", approxEqual( aNewPos.Y, aSetPos.Y, 1 ));
328cdf0e10cSrcweir             }
329cdf0e10cSrcweir 
330cdf0e10cSrcweir             // size diagram
331cdf0e10cSrcweir             {
332cdf0e10cSrcweir                 XShape xDiagramShape = (XShape) UnoRuntime.queryInterface(
333cdf0e10cSrcweir                     XShape.class, xDia );
334cdf0e10cSrcweir 
335cdf0e10cSrcweir                 Size aOldSize = xDiagramShape.getSize();
336cdf0e10cSrcweir                 int xDiff = aOldSize.Width/2+2;
337cdf0e10cSrcweir                 int yDiff = aOldSize.Height/2+2;
338cdf0e10cSrcweir                 Size aSetSize = new Size();
339cdf0e10cSrcweir                 aSetSize.Width = aOldSize.Width - xDiff;
340cdf0e10cSrcweir                 aSetSize.Height = aOldSize.Height - yDiff;
341cdf0e10cSrcweir                 xDiagramShape.setSize( aSetSize );
342cdf0e10cSrcweir 
343cdf0e10cSrcweir                 Size aNewSize = xDiagramShape.getSize();
344cdf0e10cSrcweir                 //System.out.println( "set width = " + aSetSize.Width + ", new width = " + aNewSize.Width );
345cdf0e10cSrcweir                 //System.out.println( "set height = " + aSetSize.Height + ", new height = " + aNewSize.Height );
346cdf0e10cSrcweir                 assure( "Diagram Width", approxEqual( aNewSize.Width, aSetSize.Width, 2 ));
347cdf0e10cSrcweir                 assure( "Diagram Height", approxEqual( aNewSize.Height, aSetSize.Height, 2 ));
348cdf0e10cSrcweir             }
349cdf0e10cSrcweir         }
350cdf0e10cSrcweir         catch( Exception ex )
351cdf0e10cSrcweir         {
352cdf0e10cSrcweir             failed( ex.getMessage() );
353cdf0e10cSrcweir             ex.printStackTrace( (PrintWriter)log );
354cdf0e10cSrcweir         }
355cdf0e10cSrcweir     }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir     // ------------
358cdf0e10cSrcweir 
testAxis()359cdf0e10cSrcweir     public void testAxis()
360cdf0e10cSrcweir     {
361cdf0e10cSrcweir         try
362cdf0e10cSrcweir         {
363cdf0e10cSrcweir             XAxisYSupplier xYAxisSuppl = (XAxisYSupplier) UnoRuntime.queryInterface(
364cdf0e10cSrcweir                 XAxisYSupplier.class, mxOldDoc.getDiagram() );
365cdf0e10cSrcweir             assure( "Diagram is no y-axis supplier", xYAxisSuppl != null );
366cdf0e10cSrcweir 
367cdf0e10cSrcweir             XPropertySet xProp = xYAxisSuppl.getYAxis();
368cdf0e10cSrcweir             assure( "No y-axis found", xProp != null );
369cdf0e10cSrcweir 
370cdf0e10cSrcweir             double fMax1, fMax2;
371cdf0e10cSrcweir             Object oMax = xProp.getPropertyValue( "Max" );
372cdf0e10cSrcweir             assure( "No Maximum set", AnyConverter.isDouble( oMax ));
373cdf0e10cSrcweir             fMax1 = AnyConverter.toDouble( oMax );
374cdf0e10cSrcweir             log.println( "Maximum retrieved: " + fMax1 );
375cdf0e10cSrcweir             //todo: the view has to be built before there is an explicit value
376cdf0e10cSrcweir //             assure( "Max is 0.0", fMax1 > 0.0 );
377cdf0e10cSrcweir             xProp.setPropertyValue( "AutoMax", new Boolean( false ));
378cdf0e10cSrcweir             oMax = xProp.getPropertyValue( "Max" );
379cdf0e10cSrcweir             assure( "No Maximum set", AnyConverter.isDouble( oMax ));
380cdf0e10cSrcweir             fMax2 = AnyConverter.toDouble( oMax );
381cdf0e10cSrcweir             log.println( "Maximum with AutoMax off: " + fMax2 );
382cdf0e10cSrcweir             assure( "maxima differ", fMax1 == fMax2 );
383cdf0e10cSrcweir 
384cdf0e10cSrcweir             double nNewMax = 12.3;
385cdf0e10cSrcweir             double nNewOrigin = 2.7;
386cdf0e10cSrcweir 
387cdf0e10cSrcweir             xProp.setPropertyValue( "Max", new Double( nNewMax ));
388cdf0e10cSrcweir             assure( "AutoMax is on", ! AnyConverter.toBoolean( xProp.getPropertyValue( "AutoMax" )) );
389cdf0e10cSrcweir 
390cdf0e10cSrcweir             assure( "Maximum value invalid",
391cdf0e10cSrcweir                     approxEqual(
392cdf0e10cSrcweir                         AnyConverter.toDouble( xProp.getPropertyValue( "Max" )),
393cdf0e10cSrcweir                         nNewMax ));
394cdf0e10cSrcweir 
395cdf0e10cSrcweir             xProp.setPropertyValue( "AutoMin", new Boolean( true ));
396cdf0e10cSrcweir             assure( "AutoMin is off", AnyConverter.toBoolean( xProp.getPropertyValue( "AutoMin" )) );
397cdf0e10cSrcweir 
398cdf0e10cSrcweir             xProp.setPropertyValue( "Origin", new Double( nNewOrigin ));
399cdf0e10cSrcweir             assure( "Origin invalid",
400cdf0e10cSrcweir                     approxEqual(
401cdf0e10cSrcweir                         AnyConverter.toDouble( xProp.getPropertyValue( "Origin" )),
402cdf0e10cSrcweir                         nNewOrigin ));
403cdf0e10cSrcweir             xProp.setPropertyValue( "AutoOrigin", new Boolean( true ));
404cdf0e10cSrcweir             assure( "AutoOrigin is off", AnyConverter.toBoolean( xProp.getPropertyValue( "AutoOrigin" )) );
405cdf0e10cSrcweir             Object oOrigin = xProp.getPropertyValue( "Origin" );
406cdf0e10cSrcweir             assure( "No Origin set", AnyConverter.isDouble( oOrigin ));
407cdf0e10cSrcweir             log.println( "Origin retrieved: " + AnyConverter.toDouble( oOrigin ));
408cdf0e10cSrcweir 
409cdf0e10cSrcweir             xProp.setPropertyValue( "Logarithmic", new Boolean( true ));
410cdf0e10cSrcweir             assure( "Scaling is not logarithmic",
411cdf0e10cSrcweir                     AnyConverter.toBoolean( xProp.getPropertyValue( "Logarithmic" )) );
412cdf0e10cSrcweir             xProp.setPropertyValue( "Logarithmic", new Boolean( false ));
413cdf0e10cSrcweir             assure( "Scaling is not logarithmic",
414cdf0e10cSrcweir                     ! AnyConverter.toBoolean( xProp.getPropertyValue( "Logarithmic" )) );
415cdf0e10cSrcweir 
416cdf0e10cSrcweir             int nNewColor =  0xcd853f; // peru
417cdf0e10cSrcweir             xProp.setPropertyValue( "LineColor", new Integer( nNewColor ));
418cdf0e10cSrcweir             assure( "Property LineColor",
419cdf0e10cSrcweir                     AnyConverter.toInt( xProp.getPropertyValue( "LineColor" )) == nNewColor );
420cdf0e10cSrcweir             float fNewCharHeight = (float)(16.0);
421cdf0e10cSrcweir             xProp.setPropertyValue( "CharHeight", new Float( fNewCharHeight ));
422cdf0e10cSrcweir             assure( "Property CharHeight",
423cdf0e10cSrcweir                     AnyConverter.toFloat( xProp.getPropertyValue( "CharHeight" )) == fNewCharHeight );
424cdf0e10cSrcweir 
425cdf0e10cSrcweir             int nNewTextRotation = 700; // in 1/100 degrees
426cdf0e10cSrcweir             xProp.setPropertyValue( "TextRotation", new Integer( nNewTextRotation ));
427cdf0e10cSrcweir             assure( "Property TextRotation",
428cdf0e10cSrcweir                     AnyConverter.toInt( xProp.getPropertyValue( "TextRotation" )) == nNewTextRotation );
429cdf0e10cSrcweir 
430cdf0e10cSrcweir             double fStepMain = 10.0;
431cdf0e10cSrcweir             xProp.setPropertyValue( "StepMain", new Double( fStepMain ));
432cdf0e10cSrcweir             assure( "Property StepMain",
433cdf0e10cSrcweir                     AnyConverter.toDouble( xProp.getPropertyValue( "StepMain" )) == fStepMain );
434cdf0e10cSrcweir 
435cdf0e10cSrcweir             // note: fStepHelp must be a divider of fStepMain, because
436cdf0e10cSrcweir             // internally, the help-step is stored as an integer number of
437cdf0e10cSrcweir             // substeps
438cdf0e10cSrcweir             double fStepHelp = 5.0;
439cdf0e10cSrcweir             xProp.setPropertyValue( "StepHelp", new Double( fStepHelp ));
440cdf0e10cSrcweir             assure( "Property StepHelp",
441cdf0e10cSrcweir                     AnyConverter.toDouble( xProp.getPropertyValue( "StepHelp" )) == fStepHelp );
442cdf0e10cSrcweir 
443cdf0e10cSrcweir             xProp.setPropertyValue( "DisplayLabels", new Boolean( false ));
444cdf0e10cSrcweir             assure( "Property DisplayLabels", ! AnyConverter.toBoolean(
445cdf0e10cSrcweir                         xProp.getPropertyValue( "DisplayLabels" )));
446cdf0e10cSrcweir         }
447cdf0e10cSrcweir         catch( Exception ex )
448cdf0e10cSrcweir         {
449cdf0e10cSrcweir             failed( ex.getMessage() );
450cdf0e10cSrcweir             ex.printStackTrace( (PrintWriter)log );
451cdf0e10cSrcweir         }
452cdf0e10cSrcweir     }
453cdf0e10cSrcweir 
454cdf0e10cSrcweir     // ------------
455cdf0e10cSrcweir 
testLegend()456cdf0e10cSrcweir     public void testLegend()
457cdf0e10cSrcweir     {
458cdf0e10cSrcweir         XShape xLegend = mxOldDoc.getLegend();
459cdf0e10cSrcweir         assure( "No Legend returned", xLegend != null );
460cdf0e10cSrcweir 
461cdf0e10cSrcweir         XPropertySet xLegendProp = (XPropertySet) UnoRuntime.queryInterface(
462cdf0e10cSrcweir             XPropertySet.class, xLegend );
463cdf0e10cSrcweir         assure( "Legend is no property set", xLegendProp != null );
464cdf0e10cSrcweir 
465cdf0e10cSrcweir         try
466cdf0e10cSrcweir         {
467cdf0e10cSrcweir             ChartLegendPosition eNewPos = ChartLegendPosition.BOTTOM;
468cdf0e10cSrcweir             xLegendProp.setPropertyValue( "Alignment", eNewPos );
469cdf0e10cSrcweir             assure( "Property Alignment",
470cdf0e10cSrcweir                     AnyConverter.toObject(
471cdf0e10cSrcweir                         new Type( ChartLegendPosition.class ),
472cdf0e10cSrcweir                         xLegendProp.getPropertyValue( "Alignment" )) == eNewPos );
473cdf0e10cSrcweir 
474cdf0e10cSrcweir             float fNewCharHeight = (float)(11.0);
475cdf0e10cSrcweir             xLegendProp.setPropertyValue( "CharHeight", new Float( fNewCharHeight ));
476cdf0e10cSrcweir             assure( "Property CharHeight",
477cdf0e10cSrcweir                     AnyConverter.toFloat( xLegendProp.getPropertyValue( "CharHeight" )) == fNewCharHeight );
478cdf0e10cSrcweir 
479cdf0e10cSrcweir             // move legend
480cdf0e10cSrcweir             {
481cdf0e10cSrcweir                 Point aOldPos = xLegend.getPosition();
482cdf0e10cSrcweir                 int xDiff = 20;
483cdf0e10cSrcweir                 int yDiff = 20;
484cdf0e10cSrcweir                 Point aSetPos = new Point();
485cdf0e10cSrcweir                 aSetPos.X = aOldPos.X + xDiff;
486cdf0e10cSrcweir                 aSetPos.Y = aOldPos.Y + yDiff;
487cdf0e10cSrcweir                 xLegend.setPosition( aSetPos );
488cdf0e10cSrcweir 
489cdf0e10cSrcweir                 Point aNewPos = xLegend.getPosition();
490cdf0e10cSrcweir                 assure( "Legend Position X", approxEqual( aNewPos.X, aSetPos.X, 1 ));
491cdf0e10cSrcweir                 assure( "Legend Position Y", approxEqual( aNewPos.Y, aSetPos.Y, 1 ));
492cdf0e10cSrcweir             }
493cdf0e10cSrcweir         }
494cdf0e10cSrcweir         catch( Exception ex )
495cdf0e10cSrcweir         {
496cdf0e10cSrcweir             failed( ex.getMessage() );
497cdf0e10cSrcweir             ex.printStackTrace( (PrintWriter)log );
498cdf0e10cSrcweir         }
499cdf0e10cSrcweir     }
500cdf0e10cSrcweir 
501cdf0e10cSrcweir     // ------------
502cdf0e10cSrcweir 
testArea()503cdf0e10cSrcweir     public void testArea()
504cdf0e10cSrcweir     {
505cdf0e10cSrcweir         XPropertySet xArea = mxOldDoc.getArea();
506cdf0e10cSrcweir         assure( "No Area", xArea != null );
507cdf0e10cSrcweir 
508cdf0e10cSrcweir         try
509cdf0e10cSrcweir         {
510cdf0e10cSrcweir             int nColor = 0xf5fffa; // mint cream
511cdf0e10cSrcweir             xArea.setPropertyValue( "FillColor", new Integer( nColor ) );
512cdf0e10cSrcweir             xArea.setPropertyValue( "FillStyle", FillStyle.SOLID );
513cdf0e10cSrcweir //             XPropertySetInfo xInfo = xArea.getPropertySetInfo();
514cdf0e10cSrcweir //             assure( "Area does not support ChartUserDefinedAttributes",
515cdf0e10cSrcweir //                     xInfo.hasPropertyByName( "ChartUserDefinedAttributes" ));
516cdf0e10cSrcweir 
517cdf0e10cSrcweir //             String aTestAttributeName = "test:foo";
518cdf0e10cSrcweir //             String aTestAttributeValue = "content";
519cdf0e10cSrcweir //             XNameContainer xUserDefAttributes = (XNameContainer) AnyConverter.toObject(
520cdf0e10cSrcweir //                 new Type( XNameContainer.class ), xArea.getPropertyValue( "ChartUserDefinedAttributes" ));
521cdf0e10cSrcweir //             xUserDefAttributes.insertByName( aTestAttributeName, aTestAttributeValue );
522cdf0e10cSrcweir 
523cdf0e10cSrcweir //             String aContent = AnyConverter.toString( xUserDefAttributes.getByName( aTestAttributeName ));
524cdf0e10cSrcweir //             assure( "Wrong content in UserDefinedAttributes container",
525cdf0e10cSrcweir //                     aContent.equals( aTestAttributeValue ));
526cdf0e10cSrcweir 
527cdf0e10cSrcweir             int nNewColor = AnyConverter.toInt( xArea.getPropertyValue( "FillColor" ) );
528cdf0e10cSrcweir             assure( "Changing FillColor of Area failed", nNewColor == nColor );
529cdf0e10cSrcweir         }
530cdf0e10cSrcweir         catch( Exception ex )
531cdf0e10cSrcweir         {
532cdf0e10cSrcweir             failed( ex.getMessage() );
533cdf0e10cSrcweir             ex.printStackTrace( (PrintWriter)log );
534cdf0e10cSrcweir         }
535cdf0e10cSrcweir     }
536cdf0e10cSrcweir 
537cdf0e10cSrcweir     // ------------
538cdf0e10cSrcweir 
testChartType()539cdf0e10cSrcweir     public void testChartType()
540cdf0e10cSrcweir     {
541cdf0e10cSrcweir         XMultiServiceFactory xFact = (XMultiServiceFactory) UnoRuntime.queryInterface(
542cdf0e10cSrcweir             XMultiServiceFactory.class, mxOldDoc );
543cdf0e10cSrcweir         assure( "document is no factory", xFact != null );
544cdf0e10cSrcweir 
545cdf0e10cSrcweir         try
546cdf0e10cSrcweir         {
547cdf0e10cSrcweir             String aMyServiceName = new String( "com.sun.star.chart.BarDiagram" );
548cdf0e10cSrcweir             String aServices[] = xFact.getAvailableServiceNames();
549cdf0e10cSrcweir             boolean bServiceFound = false;
550cdf0e10cSrcweir             for( int i = 0; i < aServices.length; ++i )
551cdf0e10cSrcweir             {
552cdf0e10cSrcweir                 if( aServices[ i ].equals( aMyServiceName ))
553cdf0e10cSrcweir                 {
554cdf0e10cSrcweir                     bServiceFound = true;
555cdf0e10cSrcweir                     break;
556cdf0e10cSrcweir                 }
557cdf0e10cSrcweir             }
558cdf0e10cSrcweir             assure( "getAvailableServiceNames did not return " + aMyServiceName, bServiceFound );
559cdf0e10cSrcweir 
560cdf0e10cSrcweir             if( bServiceFound )
561cdf0e10cSrcweir             {
562cdf0e10cSrcweir                 XDiagram xDia = (XDiagram) UnoRuntime.queryInterface(
563cdf0e10cSrcweir                     XDiagram.class, xFact.createInstance( aMyServiceName ));
564cdf0e10cSrcweir                 assure( aMyServiceName + " could not be created", xDia != null );
565cdf0e10cSrcweir 
566cdf0e10cSrcweir                 mxOldDoc.setDiagram( xDia );
567cdf0e10cSrcweir 
568cdf0e10cSrcweir                 XPropertySet xDiaProp = (XPropertySet) UnoRuntime.queryInterface(
569cdf0e10cSrcweir                     XPropertySet.class, xDia );
570cdf0e10cSrcweir                 assure( "Diagram is no XPropertySet", xDiaProp != null );
571cdf0e10cSrcweir 
572cdf0e10cSrcweir                 xDiaProp.setPropertyValue( "Stacked", new Boolean( true ));
573cdf0e10cSrcweir                 assure( "StackMode could not be set correctly",
574cdf0e10cSrcweir                         AnyConverter.toBoolean(
575cdf0e10cSrcweir                             xDiaProp.getPropertyValue( "Stacked" )));
576cdf0e10cSrcweir 
577cdf0e10cSrcweir                 xDiaProp.setPropertyValue( "Dim3D", new Boolean( false ));
578cdf0e10cSrcweir                 assure( "Dim3D could not be set correctly",
579cdf0e10cSrcweir                         ! AnyConverter.toBoolean(
580cdf0e10cSrcweir                             xDiaProp.getPropertyValue( "Dim3D" )));
581cdf0e10cSrcweir 
582cdf0e10cSrcweir                 xDiaProp.setPropertyValue( "Vertical", new Boolean( true ));
583cdf0e10cSrcweir                 assure( "Vertical could not be set correctly",
584cdf0e10cSrcweir                         AnyConverter.toBoolean(
585cdf0e10cSrcweir                             xDiaProp.getPropertyValue( "Vertical" )));
586cdf0e10cSrcweir             }
587cdf0e10cSrcweir 
588cdf0e10cSrcweir             // reset to bar-chart
589cdf0e10cSrcweir //             aMyServiceName = new String( "com.sun.star.chart.BarDiagram" );
590cdf0e10cSrcweir //             XDiagram xDia = (XDiagram) UnoRuntime.queryInterface(
591cdf0e10cSrcweir //                 XDiagram.class, xFact.createInstance( aMyServiceName ));
592cdf0e10cSrcweir //             assure( aMyServiceName + " could not be created", xDia != null );
593cdf0e10cSrcweir 
594cdf0e10cSrcweir //             mxOldDoc.setDiagram( xDia );
595cdf0e10cSrcweir         }
596cdf0e10cSrcweir         catch( Exception ex )
597cdf0e10cSrcweir         {
598cdf0e10cSrcweir             failed( ex.getMessage() );
599cdf0e10cSrcweir             ex.printStackTrace( (PrintWriter)log );
600cdf0e10cSrcweir         }
601cdf0e10cSrcweir     }
602cdf0e10cSrcweir 
603cdf0e10cSrcweir     // ------------
604cdf0e10cSrcweir 
testAggregation()605cdf0e10cSrcweir     public void testAggregation()
606cdf0e10cSrcweir     {
607cdf0e10cSrcweir         // query to new type
608cdf0e10cSrcweir         XChartDocument xDiaProv = (XChartDocument) UnoRuntime.queryInterface(
609cdf0e10cSrcweir             XChartDocument.class, mxOldDoc );
610cdf0e10cSrcweir         assure( "query to new interface failed", xDiaProv != null );
611cdf0e10cSrcweir 
612cdf0e10cSrcweir         com.sun.star.chart.XChartDocument xDoc = (com.sun.star.chart.XChartDocument) UnoRuntime.queryInterface(
613cdf0e10cSrcweir             com.sun.star.chart.XChartDocument.class, xDiaProv );
614cdf0e10cSrcweir         assure( "querying back to old interface failed", xDoc != null );
615cdf0e10cSrcweir     }
616cdf0e10cSrcweir 
617cdf0e10cSrcweir     // ------------
618cdf0e10cSrcweir 
testDataSeriesAndPoints()619cdf0e10cSrcweir     public void testDataSeriesAndPoints()
620cdf0e10cSrcweir     {
621cdf0e10cSrcweir         try
622cdf0e10cSrcweir         {
623cdf0e10cSrcweir             XDiagram xDia = mxOldDoc.getDiagram();
624cdf0e10cSrcweir             assure( "Invalid Diagram", xDia != null );
625cdf0e10cSrcweir             XMultiServiceFactory xFact = (XMultiServiceFactory) UnoRuntime.queryInterface(
626cdf0e10cSrcweir                 XMultiServiceFactory.class, mxOldDoc );
627cdf0e10cSrcweir             assure( "document is no factory", xFact != null );
628cdf0e10cSrcweir 
629cdf0e10cSrcweir             // FillColor
630cdf0e10cSrcweir             XPropertySet xProp = xDia.getDataRowProperties( 0 );
631cdf0e10cSrcweir             int nColor = 0xffd700; // gold
632cdf0e10cSrcweir             xProp.setPropertyValue( "FillColor", new Integer( nColor ));
633cdf0e10cSrcweir             int nNewColor = AnyConverter.toInt( xProp.getPropertyValue( "FillColor" ) );
634cdf0e10cSrcweir             assure( "Changing FillColor of Data Series failed", nNewColor == nColor );
635cdf0e10cSrcweir 
636cdf0e10cSrcweir             // Gradient
637cdf0e10cSrcweir             assure( "No DataRowProperties for series 0", xProp != null );
638cdf0e10cSrcweir 
639cdf0e10cSrcweir             // note: the FillGradient property is optional, however it was
640cdf0e10cSrcweir             // supported in the old chart's API
641cdf0e10cSrcweir             XNameContainer xGradientTable = (XNameContainer) UnoRuntime.queryInterface(
642cdf0e10cSrcweir                 XNameContainer.class,
643cdf0e10cSrcweir                 xFact.createInstance( "com.sun.star.drawing.GradientTable" ));
644cdf0e10cSrcweir             assure( "no gradient table", xGradientTable != null );
645cdf0e10cSrcweir             String aGradientName = "NewAPITestGradient";
646cdf0e10cSrcweir             Gradient aGradient = new Gradient();
647cdf0e10cSrcweir             aGradient.Style = GradientStyle.LINEAR;
648cdf0e10cSrcweir             aGradient.StartColor = 0xe0ffff; // light cyan
649cdf0e10cSrcweir             aGradient.EndColor  = 0xff8c00; // dark orange
650cdf0e10cSrcweir             aGradient.Angle = 300;          // 30 degrees
651cdf0e10cSrcweir             aGradient.Border = 15;
652cdf0e10cSrcweir             aGradient.XOffset = 0;
653cdf0e10cSrcweir             aGradient.YOffset = 0;
654cdf0e10cSrcweir             aGradient.StartIntensity = 100;
655cdf0e10cSrcweir             aGradient.EndIntensity = 80;
656cdf0e10cSrcweir             aGradient.StepCount = 23;
657cdf0e10cSrcweir 
658cdf0e10cSrcweir             xGradientTable.insertByName( aGradientName, aGradient );
659cdf0e10cSrcweir             xProp.setPropertyValue( "FillStyle", FillStyle.GRADIENT );
660cdf0e10cSrcweir             xProp.setPropertyValue( "FillGradientName", aGradientName );
661cdf0e10cSrcweir             String aNewGradientName = AnyConverter.toString( xProp.getPropertyValue( "FillGradientName" ));
662cdf0e10cSrcweir             assure( "GradientName", aNewGradientName.equals( aGradientName ));
663cdf0e10cSrcweir             Gradient aNewGradient = (Gradient) AnyConverter.toObject(
664cdf0e10cSrcweir                 new Type( Gradient.class ),
665cdf0e10cSrcweir                 xGradientTable.getByName( aNewGradientName ));
666cdf0e10cSrcweir             assure( "Gradient Style", aNewGradient.Style == aGradient.Style );
667cdf0e10cSrcweir             assure( "Gradient StartColor", aNewGradient.StartColor == aGradient.StartColor );
668cdf0e10cSrcweir             assure( "Gradient EndColor", aNewGradient.EndColor == aGradient.EndColor );
669cdf0e10cSrcweir             assure( "Gradient Angle", aNewGradient.Angle == aGradient.Angle );
670cdf0e10cSrcweir             assure( "Gradient Border", aNewGradient.Border == aGradient.Border );
671cdf0e10cSrcweir             assure( "Gradient XOffset", aNewGradient.XOffset == aGradient.XOffset );
672cdf0e10cSrcweir             assure( "Gradient YOffset", aNewGradient.YOffset == aGradient.YOffset );
673cdf0e10cSrcweir             assure( "Gradient StartIntensity", aNewGradient.StartIntensity == aGradient.StartIntensity );
674cdf0e10cSrcweir             assure( "Gradient EndIntensity", aNewGradient.EndIntensity == aGradient.EndIntensity );
675cdf0e10cSrcweir             assure( "Gradient StepCount", aNewGradient.StepCount == aGradient.StepCount );
676cdf0e10cSrcweir 
677cdf0e10cSrcweir             // Hatch
678cdf0e10cSrcweir             xProp = xDia.getDataPointProperties( 1, 0 );
679cdf0e10cSrcweir             assure( "No DataPointProperties for (1,0)", xProp != null );
680cdf0e10cSrcweir 
681cdf0e10cSrcweir             // note: the FillHatch property is optional, however it was
682cdf0e10cSrcweir             // supported in the old chart's API
683cdf0e10cSrcweir             XNameContainer xHatchTable = (XNameContainer) UnoRuntime.queryInterface(
684cdf0e10cSrcweir                 XNameContainer.class,
685cdf0e10cSrcweir                 xFact.createInstance( "com.sun.star.drawing.HatchTable" ));
686cdf0e10cSrcweir             assure( "no hatch table", xHatchTable != null );
687cdf0e10cSrcweir             String aHatchName = "NewAPITestHatch";
688cdf0e10cSrcweir             Hatch aHatch = new Hatch();
689cdf0e10cSrcweir             aHatch.Style = HatchStyle.DOUBLE;
690cdf0e10cSrcweir             aHatch.Color = 0xd2691e; // chocolate
691cdf0e10cSrcweir             aHatch.Distance = 200;   // 2 mm (?)
692cdf0e10cSrcweir             aHatch.Angle = 230;      // 23 degrees
693cdf0e10cSrcweir 
694cdf0e10cSrcweir             xHatchTable.insertByName( aHatchName, aHatch );
695cdf0e10cSrcweir             xProp.setPropertyValue( "FillHatchName", aHatchName );
696cdf0e10cSrcweir             xProp.setPropertyValue( "FillStyle", FillStyle.HATCH );
697cdf0e10cSrcweir             xProp.setPropertyValue( "FillBackground", new Boolean( true ));
698cdf0e10cSrcweir             String aNewHatchName = AnyConverter.toString( xProp.getPropertyValue( "FillHatchName" ));
699cdf0e10cSrcweir             assure( "HatchName", aNewHatchName.equals( aHatchName ));
700cdf0e10cSrcweir             Hatch aNewHatch = (Hatch) AnyConverter.toObject(
701cdf0e10cSrcweir                 new Type( Hatch.class ),
702cdf0e10cSrcweir                 xHatchTable.getByName( aNewHatchName ));
703cdf0e10cSrcweir             assure( "Hatch Style", aNewHatch.Style == aHatch.Style );
704cdf0e10cSrcweir             assure( "Hatch Color", aNewHatch.Color == aHatch.Color );
705cdf0e10cSrcweir             assure( "Hatch Distance", aNewHatch.Distance == aHatch.Distance );
706cdf0e10cSrcweir             assure( "Hatch Angle", aNewHatch.Angle == aHatch.Angle );
707cdf0e10cSrcweir             assure( "FillBackground", AnyConverter.toBoolean( xProp.getPropertyValue( "FillBackground" )) );
708cdf0e10cSrcweir         }
709cdf0e10cSrcweir         catch( Exception ex )
710cdf0e10cSrcweir         {
711cdf0e10cSrcweir             failed( ex.getMessage() );
712cdf0e10cSrcweir             ex.printStackTrace( (PrintWriter)log );
713cdf0e10cSrcweir         }
714cdf0e10cSrcweir     }
715cdf0e10cSrcweir 
716cdf0e10cSrcweir     // ------------
717cdf0e10cSrcweir 
testStatistics()718cdf0e10cSrcweir     public void testStatistics()
719cdf0e10cSrcweir     {
720cdf0e10cSrcweir         try
721cdf0e10cSrcweir         {
722cdf0e10cSrcweir             XDiagram xDia = mxOldDoc.getDiagram();
723cdf0e10cSrcweir             assure( "Invalid Diagram", xDia != null );
724cdf0e10cSrcweir 
725cdf0e10cSrcweir             XPropertySet xProp = xDia.getDataRowProperties( 0 );
726cdf0e10cSrcweir             assure( "No DataRowProperties for first series", xProp != null );
727cdf0e10cSrcweir 
728cdf0e10cSrcweir             xProp.setPropertyValue( "MeanValue", new Boolean( true ));
729cdf0e10cSrcweir             assure( "No MeanValue", AnyConverter.toBoolean( xProp.getPropertyValue( "MeanValue" )) );
730cdf0e10cSrcweir         }
731cdf0e10cSrcweir         catch( Exception ex )
732cdf0e10cSrcweir         {
733cdf0e10cSrcweir             failed( ex.getMessage() );
734cdf0e10cSrcweir             ex.printStackTrace( (PrintWriter)log );
735cdf0e10cSrcweir         }
736cdf0e10cSrcweir     }
737cdf0e10cSrcweir 
738cdf0e10cSrcweir     // ------------
739cdf0e10cSrcweir 
setStockData_Type4()740cdf0e10cSrcweir     public void setStockData_Type4()
741cdf0e10cSrcweir     {
742cdf0e10cSrcweir         try
743cdf0e10cSrcweir         {
744cdf0e10cSrcweir             XPropertySet xDiaProp = (XPropertySet) UnoRuntime.queryInterface(
745cdf0e10cSrcweir                 XPropertySet.class, mxOldDoc.getDiagram() );
746cdf0e10cSrcweir 
747cdf0e10cSrcweir             ChartDataRowSource eNewSource = ChartDataRowSource.ROWS;
748cdf0e10cSrcweir             xDiaProp.setPropertyValue( "DataRowSource", eNewSource );
749cdf0e10cSrcweir             assure( "Couldn't set \"DataRowSource\" property at Diagram",
750cdf0e10cSrcweir                     AnyConverter.toObject(
751cdf0e10cSrcweir                         new Type( ChartDataRowSource.class ),
752cdf0e10cSrcweir                         xDiaProp.getPropertyValue( "DataRowSource" )) == eNewSource );
753cdf0e10cSrcweir 
754cdf0e10cSrcweir             double aData[][] =
755cdf0e10cSrcweir                 {
756cdf0e10cSrcweir                     { 100.0, 200.0, 300.0, 250.0, 300.0 },
757cdf0e10cSrcweir                     { 6.5, 4.5, 6.0, 5.5, 3.5 },
758cdf0e10cSrcweir                     { 1.0, 1.5, 2.0, 2.5, 3.0 },
759cdf0e10cSrcweir                     { 6.0, 6.5, 7.0, 6.5, 5.0 },
760cdf0e10cSrcweir                     { 6.0, 5.5, 4.0, 4.5, 4.0 }
761cdf0e10cSrcweir                 };
762cdf0e10cSrcweir 
763cdf0e10cSrcweir             String[] aRowDescriptions =
764cdf0e10cSrcweir                 {
765cdf0e10cSrcweir                     "Volume", "Open", "Min", "Max", "Close"
766cdf0e10cSrcweir                 };
767cdf0e10cSrcweir 
768cdf0e10cSrcweir              String[] aColumnDescriptions =
769cdf0e10cSrcweir              {
770cdf0e10cSrcweir                  "First Row", "Second Row", "Third Row", "Fourth Row", "Fifth Row"
771cdf0e10cSrcweir              };
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 
774cdf0e10cSrcweir             XChartData xData = mxOldDoc.getData();
775cdf0e10cSrcweir             XChartDataArray xDataArray = (XChartDataArray) UnoRuntime.queryInterface(
776cdf0e10cSrcweir                 XChartDataArray.class, xData );
777cdf0e10cSrcweir             assure( "document has no XChartDataArray", xDataArray != null );
778cdf0e10cSrcweir 
779cdf0e10cSrcweir             xDataArray.setData( aData );
780cdf0e10cSrcweir             xDataArray.setRowDescriptions( aRowDescriptions );
781cdf0e10cSrcweir             xDataArray.setColumnDescriptions( aColumnDescriptions );
782cdf0e10cSrcweir 
783cdf0e10cSrcweir             mxOldDoc.attachData( xData );
784cdf0e10cSrcweir         }
785cdf0e10cSrcweir         catch( Exception ex )
786cdf0e10cSrcweir         {
787cdf0e10cSrcweir             failed( ex.getMessage() );
788cdf0e10cSrcweir             ex.printStackTrace( (PrintWriter)log );
789cdf0e10cSrcweir         }
790cdf0e10cSrcweir     }
791cdf0e10cSrcweir 
792cdf0e10cSrcweir     // ------------
793cdf0e10cSrcweir 
testStockProperties()794cdf0e10cSrcweir     public void testStockProperties()
795cdf0e10cSrcweir     {
796cdf0e10cSrcweir         try
797cdf0e10cSrcweir         {
798cdf0e10cSrcweir             setStockData_Type4();
799cdf0e10cSrcweir 
800cdf0e10cSrcweir             XMultiServiceFactory xFact = (XMultiServiceFactory) UnoRuntime.queryInterface(
801cdf0e10cSrcweir                 XMultiServiceFactory.class, mxOldDoc );
802cdf0e10cSrcweir             assure( "document is no factory", xFact != null );
803cdf0e10cSrcweir 
804cdf0e10cSrcweir             String aMyServiceName = new String( "com.sun.star.chart.StockDiagram" );
805cdf0e10cSrcweir             XDiagram xDia = (XDiagram) UnoRuntime.queryInterface(
806cdf0e10cSrcweir                 XDiagram.class, xFact.createInstance( aMyServiceName ));
807cdf0e10cSrcweir             assure( aMyServiceName + " could not be created", xDia != null );
808cdf0e10cSrcweir 
809cdf0e10cSrcweir             mxOldDoc.setDiagram( xDia );
810cdf0e10cSrcweir 
811cdf0e10cSrcweir             XPropertySet xDiaProp = (XPropertySet) UnoRuntime.queryInterface(
812cdf0e10cSrcweir                 XPropertySet.class, xDia );
813cdf0e10cSrcweir             assure( "Diagram is no XPropertySet", xDiaProp != null );
814cdf0e10cSrcweir 
815cdf0e10cSrcweir             xDiaProp.setPropertyValue( "Volume", new Boolean( true ));
816cdf0e10cSrcweir             assure( "Has Volume", AnyConverter.toBoolean( xDiaProp.getPropertyValue( "Volume" )));
817cdf0e10cSrcweir 
818cdf0e10cSrcweir             xDiaProp.setPropertyValue( "UpDown", new Boolean( true ));
819cdf0e10cSrcweir             assure( "Has UpDown", AnyConverter.toBoolean( xDiaProp.getPropertyValue( "UpDown" )));
820cdf0e10cSrcweir 
821cdf0e10cSrcweir             // MinMaxLine
822cdf0e10cSrcweir             XStatisticDisplay xMinMaxProvider = (XStatisticDisplay) UnoRuntime.queryInterface(
823cdf0e10cSrcweir                 XStatisticDisplay.class, xDia );
824cdf0e10cSrcweir             assure( "Diagram is no XStatisticDisplay", xMinMaxProvider != null );
825cdf0e10cSrcweir             XPropertySet xMinMaxProp = xMinMaxProvider.getMinMaxLine();
826cdf0e10cSrcweir             assure( "No MinMaxLine", xMinMaxProp != null );
827cdf0e10cSrcweir 
828cdf0e10cSrcweir             int nLineColor = 0x458b00; // chartreuse4
829cdf0e10cSrcweir             xMinMaxProp.setPropertyValue( "LineColor", new Integer( nLineColor ));
830cdf0e10cSrcweir             int nNewColor = AnyConverter.toInt( xMinMaxProp.getPropertyValue( "LineColor" ) );
831cdf0e10cSrcweir             assure( "Changing LineColor of MinMax Line", nNewColor == nLineColor );
832cdf0e10cSrcweir         }
833cdf0e10cSrcweir         catch( Exception ex )
834cdf0e10cSrcweir         {
835cdf0e10cSrcweir             failed( ex.getMessage() );
836cdf0e10cSrcweir             ex.printStackTrace( (PrintWriter)log );
837cdf0e10cSrcweir         }
838cdf0e10cSrcweir     }
839cdf0e10cSrcweir 
840cdf0e10cSrcweir     // ------------
841cdf0e10cSrcweir 
testFactory()842cdf0e10cSrcweir     public void testFactory()
843cdf0e10cSrcweir     {
844cdf0e10cSrcweir         try
845cdf0e10cSrcweir         {
846cdf0e10cSrcweir             XMultiServiceFactory xFact = (XMultiServiceFactory) UnoRuntime.queryInterface(
847cdf0e10cSrcweir                 XMultiServiceFactory.class, mxOldDoc );
848cdf0e10cSrcweir             assure( "document is no factory", xFact != null );
849cdf0e10cSrcweir 
850cdf0e10cSrcweir             Object aTestTable = xFact.createInstance( "com.sun.star.drawing.GradientTable" );
851cdf0e10cSrcweir             assure( "Couldn't create gradient table via factory", aTestTable != null );
852cdf0e10cSrcweir         }
853cdf0e10cSrcweir         catch( Exception ex )
854cdf0e10cSrcweir         {
855cdf0e10cSrcweir             failed( ex.getMessage() );
856cdf0e10cSrcweir             ex.printStackTrace( (PrintWriter)log );
857cdf0e10cSrcweir         }
858cdf0e10cSrcweir     }
859cdf0e10cSrcweir 
860cdf0e10cSrcweir     // ------------
861cdf0e10cSrcweir 
testData()862cdf0e10cSrcweir     public void testData()
863cdf0e10cSrcweir     {
864cdf0e10cSrcweir         try
865cdf0e10cSrcweir         {
866cdf0e10cSrcweir             // set data
867cdf0e10cSrcweir             double aData[][] = {
868cdf0e10cSrcweir                 { 1.0, 1.5, 2.0, 2.5, 3.0 },
869cdf0e10cSrcweir                 { 2.0, 2.5, 3.0, 3.5, 4.0 },
870cdf0e10cSrcweir                 { 3.0, 3.5, 4.0, 4.5, 5.0 }
871cdf0e10cSrcweir             };
872cdf0e10cSrcweir 
873cdf0e10cSrcweir             String[] aColumnDescriptions = {
874cdf0e10cSrcweir                 "First Column", "Second Column", "Third Column",
875cdf0e10cSrcweir                 "Fourth Column", "Fifth Column"
876cdf0e10cSrcweir             };
877cdf0e10cSrcweir 
878cdf0e10cSrcweir             String[] aRowDescriptions = {
879cdf0e10cSrcweir                 "First Row", "Second Row", "Third Row"
880cdf0e10cSrcweir             };
881cdf0e10cSrcweir 
882cdf0e10cSrcweir             XPropertySet xDiaProp = (XPropertySet) UnoRuntime.queryInterface(
883cdf0e10cSrcweir                     XPropertySet.class, mxOldDoc.getDiagram() );
884cdf0e10cSrcweir             ChartDataRowSource eNewSource = ChartDataRowSource.ROWS;
885cdf0e10cSrcweir             xDiaProp.setPropertyValue( "DataRowSource", eNewSource );
886cdf0e10cSrcweir             assure( "Couldn't set \"DataRowSource\" property at Diagram",
887cdf0e10cSrcweir                     AnyConverter.toObject(
888cdf0e10cSrcweir                         new Type( ChartDataRowSource.class ),
889cdf0e10cSrcweir                         xDiaProp.getPropertyValue( "DataRowSource" )) == eNewSource );
890cdf0e10cSrcweir 
891cdf0e10cSrcweir             XChartData xData = mxOldDoc.getData();
892cdf0e10cSrcweir             XChartDataArray xDataArray = (XChartDataArray) UnoRuntime.queryInterface(
893cdf0e10cSrcweir                 XChartDataArray.class, xData );
894cdf0e10cSrcweir             assure( "document has no XChartDataArray", xDataArray != null );
895cdf0e10cSrcweir 
896cdf0e10cSrcweir             xDataArray.setData( aData );
897cdf0e10cSrcweir             xDataArray.setRowDescriptions( aRowDescriptions );
898cdf0e10cSrcweir             xDataArray.setColumnDescriptions( aColumnDescriptions );
899cdf0e10cSrcweir 
900cdf0e10cSrcweir             mxOldDoc.attachData( xData );
901cdf0e10cSrcweir 
902cdf0e10cSrcweir             // get data
903cdf0e10cSrcweir             double aReadData[][];
904cdf0e10cSrcweir             String[] aReadColumnDescriptions;
905cdf0e10cSrcweir             String[] aReadRowDescriptions;
906cdf0e10cSrcweir 
907cdf0e10cSrcweir             // refetch data
908cdf0e10cSrcweir             xData = mxOldDoc.getData();
909cdf0e10cSrcweir             xDataArray = (XChartDataArray) UnoRuntime.queryInterface(
910cdf0e10cSrcweir                 XChartDataArray.class, xData );
911cdf0e10cSrcweir             assure( "document has no XChartDataArray", xDataArray != null );
912cdf0e10cSrcweir 
913cdf0e10cSrcweir             aReadData = xDataArray.getData();
914cdf0e10cSrcweir             aReadRowDescriptions = xDataArray.getRowDescriptions();
915cdf0e10cSrcweir             aReadColumnDescriptions = xDataArray.getColumnDescriptions();
916cdf0e10cSrcweir 
917cdf0e10cSrcweir             // compare to values set before
918cdf0e10cSrcweir             assure( "Data size differs", aData.length == aReadData.length );
919cdf0e10cSrcweir             for( int i=0; i<aReadData.length; ++i )
920cdf0e10cSrcweir             {
921cdf0e10cSrcweir                 assure( "Data size differs", aData[i].length == aReadData[i].length );
922cdf0e10cSrcweir                 for( int j=0; j<aReadData[i].length; ++j )
923cdf0e10cSrcweir                     assure( "Data differs", aData[i][j] == aReadData[i][j] );
924cdf0e10cSrcweir             }
925cdf0e10cSrcweir 
926cdf0e10cSrcweir             assure( "Column Description size differs", aColumnDescriptions.length == aReadColumnDescriptions.length );
927cdf0e10cSrcweir             for( int i=0; i<aReadColumnDescriptions.length; ++i )
928cdf0e10cSrcweir                 assure( "Column Descriptions differ", aColumnDescriptions[i].equals( aReadColumnDescriptions[i] ));
929cdf0e10cSrcweir 
930cdf0e10cSrcweir             assure( "Row Description size differs", aRowDescriptions.length == aReadRowDescriptions.length );
931cdf0e10cSrcweir             for( int i=0; i<aReadRowDescriptions.length; ++i )
932cdf0e10cSrcweir                 assure( "Row Descriptions differ", aRowDescriptions[i].equals( aReadRowDescriptions[i] ));
933cdf0e10cSrcweir         }
934cdf0e10cSrcweir         catch( Exception ex )
935cdf0e10cSrcweir         {
936cdf0e10cSrcweir             failed( ex.getMessage() );
937cdf0e10cSrcweir             ex.printStackTrace( (PrintWriter)log );
938cdf0e10cSrcweir         }
939cdf0e10cSrcweir     }
940cdf0e10cSrcweir 
941cdf0e10cSrcweir     // ================================================================================
942cdf0e10cSrcweir 
943cdf0e10cSrcweir     private XModel                    mxChartModel;
944cdf0e10cSrcweir     private XChartDocument            mxOldDoc;
945cdf0e10cSrcweir     private boolean                   mbCreateView;
946cdf0e10cSrcweir 
947cdf0e10cSrcweir     // --------------------------------------------------------------------------------
948cdf0e10cSrcweir 
createDocument( String sDocType )949cdf0e10cSrcweir     private XModel createDocument( String sDocType )
950cdf0e10cSrcweir     {
951cdf0e10cSrcweir         XModel aResult = null;
952cdf0e10cSrcweir         try
953cdf0e10cSrcweir         {
954cdf0e10cSrcweir             XComponentLoader aLoader = (XComponentLoader) UnoRuntime.queryInterface(
955cdf0e10cSrcweir                 XComponentLoader.class,
956cdf0e10cSrcweir                 ((XMultiServiceFactory)param.getMSF()).createInstance( "com.sun.star.frame.Desktop" ) );
957cdf0e10cSrcweir 
958cdf0e10cSrcweir             aResult = (XModel) UnoRuntime.queryInterface(
959cdf0e10cSrcweir                 XModel.class,
960cdf0e10cSrcweir                 aLoader.loadComponentFromURL( "private:factory/" + sDocType,
961cdf0e10cSrcweir                                               "_blank",
962cdf0e10cSrcweir                                               0,
963cdf0e10cSrcweir                                               new PropertyValue[ 0 ] ) );
964cdf0e10cSrcweir         }
965cdf0e10cSrcweir         catch( Exception ex )
966cdf0e10cSrcweir         {
967cdf0e10cSrcweir             failed( ex.getMessage() );
968cdf0e10cSrcweir             ex.printStackTrace( (PrintWriter)log );
969cdf0e10cSrcweir         }
970cdf0e10cSrcweir 
971cdf0e10cSrcweir         return aResult;
972cdf0e10cSrcweir     }
973cdf0e10cSrcweir 
974cdf0e10cSrcweir     // ------------
975cdf0e10cSrcweir 
createChartModel()976cdf0e10cSrcweir     public XModel createChartModel()
977cdf0e10cSrcweir     {
978cdf0e10cSrcweir         XModel aResult = null;
979cdf0e10cSrcweir         try
980cdf0e10cSrcweir         {
981cdf0e10cSrcweir             aResult = (XModel) UnoRuntime.queryInterface(
982cdf0e10cSrcweir                 XModel.class,
983cdf0e10cSrcweir                 ((XMultiServiceFactory)param.getMSF()).createInstance( "com.sun.star.comp.chart2.ChartModel" ) );
984cdf0e10cSrcweir         }
985cdf0e10cSrcweir         catch( Exception ex )
986cdf0e10cSrcweir         {
987cdf0e10cSrcweir             failed( ex.getMessage() );
988cdf0e10cSrcweir             ex.printStackTrace( (PrintWriter)log );
989cdf0e10cSrcweir         }
990cdf0e10cSrcweir 
991cdf0e10cSrcweir         return aResult;
992cdf0e10cSrcweir     }
993cdf0e10cSrcweir 
994cdf0e10cSrcweir     // ------------
995cdf0e10cSrcweir 
getComponentContext( XMultiServiceFactory xFact )996cdf0e10cSrcweir     private XComponentContext getComponentContext( XMultiServiceFactory xFact )
997cdf0e10cSrcweir     {
998cdf0e10cSrcweir         XComponentContext xResult = null;
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir         XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface(
1001cdf0e10cSrcweir             XPropertySet.class, xFact );
1002cdf0e10cSrcweir         if( xProp != null )
1003cdf0e10cSrcweir             try
1004cdf0e10cSrcweir             {
1005cdf0e10cSrcweir                 xResult = (XComponentContext)
1006cdf0e10cSrcweir                     AnyConverter.toObject(
1007cdf0e10cSrcweir                         new Type( XComponentContext.class ),
1008cdf0e10cSrcweir                         xProp.getPropertyValue( "DefaultContext" ) );
1009cdf0e10cSrcweir             }
1010cdf0e10cSrcweir             catch( Exception ex )
1011cdf0e10cSrcweir             {
1012cdf0e10cSrcweir                 failed( ex.getMessage() );
1013cdf0e10cSrcweir                 ex.printStackTrace( (PrintWriter)log );
1014cdf0e10cSrcweir             }
1015cdf0e10cSrcweir 
1016cdf0e10cSrcweir         return xResult;
1017cdf0e10cSrcweir     }
1018cdf0e10cSrcweir 
1019cdf0e10cSrcweir     // ------------
1020cdf0e10cSrcweir 
printInterfacesAndServices( Object oObj )1021cdf0e10cSrcweir     private void printInterfacesAndServices( Object oObj )
1022cdf0e10cSrcweir     {
1023cdf0e10cSrcweir         log.println( "Services:" );
1024cdf0e10cSrcweir         util.dbg.getSuppServices( oObj );
1025cdf0e10cSrcweir         log.println( "Interfaces:" );
1026cdf0e10cSrcweir         util.dbg.printInterfaces( (XInterface)oObj, true );
1027cdf0e10cSrcweir     }
1028cdf0e10cSrcweir 
1029cdf0e10cSrcweir     // ------------
1030cdf0e10cSrcweir 
1031cdf0e10cSrcweir     /// see rtl/math.hxx
approxEqual( double a, double b )1032cdf0e10cSrcweir     private boolean approxEqual( double a, double b )
1033cdf0e10cSrcweir     {
1034cdf0e10cSrcweir         if( a == b )
1035cdf0e10cSrcweir             return true;
1036cdf0e10cSrcweir         double x = a - b;
1037cdf0e10cSrcweir         return (x < 0.0 ? -x : x)
1038cdf0e10cSrcweir             < ((a < 0.0 ? -a : a) * (1.0 / (16777216.0 * 16777216.0)));
1039cdf0e10cSrcweir     }
1040cdf0e10cSrcweir 
1041cdf0e10cSrcweir     // ------------
1042cdf0e10cSrcweir     /** returns true if a and b differ no more than tolerance.
1043cdf0e10cSrcweir 
1044cdf0e10cSrcweir         @param tolerance
1045cdf0e10cSrcweir             must be non-negative
1046cdf0e10cSrcweir      */
approxEqual( int a, int b, int tolerance )1047cdf0e10cSrcweir     private boolean approxEqual( int a, int b, int tolerance )
1048cdf0e10cSrcweir     {
1049cdf0e10cSrcweir         if( a != b )
1050cdf0e10cSrcweir             log.println( "Integer values differ by " + java.lang.Math.abs( a-b ));
1051cdf0e10cSrcweir         return ( ( a - tolerance <= b ) ||
1052cdf0e10cSrcweir                  ( a + tolerance >= b ));
1053cdf0e10cSrcweir     }
1054cdf0e10cSrcweir }
1055