1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._sch;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.SOfficeFactory;
37 import util.utils;
38 
39 import com.sun.star.beans.XPropertySet;
40 import com.sun.star.chart.XChartDocument;
41 import com.sun.star.chart.XDiagram;
42 import com.sun.star.lang.XComponent;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.uno.UnoRuntime;
45 
46 /**
47 * Test for object which is represented by service
48 * <code>com.sun.star.chart.ChartDataPointProperties</code>. <p>
49 * Object implements the following interfaces
50 * <ul>
51 *  <li> <code>com::sun::star::chart::ChartDataPointProperties</code></li>
52 *  <li> <code>com::sun::star::drawing::FillProperties</code></li>
53 *  <li> <code>com::sun::star::drawing::LineProperties</code></li>
54 *  <li> <code>com::sun::star::style::CharacterProperties</code></li>
55 *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
56 *  <li> <code>com::sun::star::chart::Chart3DBarProperties</code></li>
57 * </ul>
58 * The following files used by this test :
59 * <ul>
60 *  <li><b> TransparencyChart.sxs </b> : to load predefined chart
61 *       document where two 'automatic' transparency styles exists :
62 *       'Transparency 1' and 'Transparency 2'.</li>
63 * </ul> <p>
64 * @see com.sun.star.chart.ChartDataPointProperties
65 * @see com.sun.star.drawing.FillProperties
66 * @see com.sun.star.drawing.LineProperties
67 * @see com.sun.star.style.CharacterProperties
68 * @see com.sun.star.beans.XPropertySet
69 * @see com.sun.star.chart.Chart3DBarProperties
70 * @see ifc.chart._ChartDataPointProperties
71 * @see ifc.drawing._FillProperties
72 * @see ifc.drawing._LineProperties
73 * @see ifc.style._CharacterProperties
74 * @see ifc.beans._XPropertySet
75 * @see ifc.chart._Chart3DBarProperties
76 */
77 public class ChXDataPoint extends TestCase {
78     XChartDocument xChartDoc = null;
79 
80     /**
81     * Creates Chart document.
82     */
83     protected void initialize( TestParameters tParam, PrintWriter log ) {
84         // get a soffice factory object
85         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
86 
87         try {
88             log.println( "creating a chartdocument" );
89             XComponent xComp = SOF.loadDocument(
90                              utils.getFullTestURL("TransparencyChart.sxs"));
91             xChartDoc = (XChartDocument)
92                 UnoRuntime.queryInterface(XChartDocument.class,xComp);
93         } catch (com.sun.star.uno.Exception e) {
94             // Some exception occures.FAILED
95             e.printStackTrace( log );
96             throw new StatusException( "Couldn't create document", e );
97         }
98     }
99 
100     /**
101     * Disposes Chart document.
102     */
103     protected void cleanup( TestParameters tParam, PrintWriter log ) {
104         if( xChartDoc!=null ) {
105             log.println( "    closing xChartDoc" );
106             util.DesktopTools.closeDoc(xChartDoc);
107             xChartDoc = null;
108         }
109     }
110 
111     /**
112     * Creating a Testenvironment for the interfaces to be tested.
113     * Retrieves the diagram of the chart document. Obtains the properties of
114     * the specified data point. The obtained properties is the instance of
115     * the service <code>com.sun.star.chart.ChartDataPointProperties</code>.
116     * Creates a XY-diagram and bar-diagram also.
117     * Object relations created :
118     * <ul>
119     *  <li> <code>'LINE'</code> for
120     *      {@link ifc.chart._ChartDataPointProperties}(the created XY-diagram)</li>
121     *  <li> <code>'CHARTDOC'</code> for
122     *      {@link ifc.chart._ChartDataPointProperties},
123     *      {@link ifc.chart._Chart3DBarProperties}(the chart document)</li>
124     *  <li> <code>'BAR'</code> for
125     *      {@link ifc.chart._Chart3DBarProperties}(the created bar-diagram)</li>
126     * </ul>
127     */
128     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
129 
130         XPropertySet  oObj = null;
131         XDiagram oDiagram = null;
132 
133         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
134 
135         // get the DataRowPoint_Point
136         try {
137             log.println( "getting ChXDataRowPoint_Point" );
138             oDiagram = (XDiagram) xChartDoc.getDiagram();
139             oObj = (XPropertySet) oDiagram.getDataPointProperties(1,1);
140         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
141             // Some exception occures.FAILED
142             e.printStackTrace( log );
143             throw new StatusException( "Couldn't get ChXDataRowPoint_Point", e );
144         }
145 
146         log.println( "creating a new environment for chartdocument object" );
147         TestEnvironment tEnv = new TestEnvironment( oObj );
148 
149         Object line = SOF.createDiagram(xChartDoc,"XYDiagram");
150         tEnv.addObjRelation("LINE",line);
151 
152         Object bar = SOF.createDiagram(xChartDoc,"BarDiagram");
153         tEnv.addObjRelation("BAR",bar);
154 
155         log.println( "adding ChartDocument as mod relation to environment" );
156         tEnv.addObjRelation("CHARTDOC", xChartDoc);
157 
158         return tEnv;
159     } // finish method getTestEnvironment
160 
161 }    // finish class ChXDataPoint
162 
163