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.ChartDataRowProperties</code>. <p>
49 * Object implements the following interfaces :
50 * <ul>
51 *  <li> <code>com::sun::star::drawing::FillProperties</code></li>
52 *  <li> <code>com::sun::star::chart::ChartStatistics</code></li>
53 *  <li> <code>com::sun::star::chart::ChartDataRowProperties</code></li>
54 *  <li> <code>com::sun::star::drawing::LineProperties</code></li>
55 *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
56 *  <li> <code>com::sun::star::chart::ChartDataPointProperties</code></li>
57 *  <li> <code>com::sun::star::chart::Chart3DBarProperties</code></li>
58 *  <li> <code>com::sun::star::style::CharacterProperties</code></li>
59 * </ul>
60 * The following files used by this test :
61 * <ul>
62 *  <li><b> TransparencyChart.sxs </b> : to load predefined chart
63 *       document where two 'automatic' transparency styles exists :
64 *       'Transparency 1' and 'Transparency 2'.</li>
65 * </ul> <p>
66 * @see com.sun.star.drawing.FillProperties
67 * @see com.sun.star.chart.ChartStatistics
68 * @see com.sun.star.chart.ChartDataRowProperties
69 * @see com.sun.star.drawing.LineProperties
70 * @see com.sun.star.beans.XPropertySet
71 * @see com.sun.star.chart.ChartDataPointProperties
72 * @see com.sun.star.chart.Chart3DBarProperties
73 * @see com.sun.star.style.CharacterProperties
74 * @see ifc.drawing._FillProperties
75 * @see ifc.chart._ChartStatistics
76 * @see ifc.chart._ChartDataRowProperties
77 * @see ifc.drawing._LineProperties
78 * @see ifc.beans._XPropertySet
79 * @see ifc.chart._ChartDataPointProperties
80 * @see ifc.chart._Chart3DBarProperties
81 * @see ifc.style._CharacterProperties
82 */
83 public class ChXDataRow extends TestCase {
84     XChartDocument xChartDoc = null;
85 
86     /**
87     * Creates Chart document.
88     */
89     protected void initialize( TestParameters tParam, PrintWriter log ) {
90         // get a soffice factory object
91         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
92 
93         try {
94             log.println( "creating a chartdocument" );
95             XComponent xComp = SOF.loadDocument(
96                              utils.getFullTestURL("TransparencyChart.sxs"));
97             xChartDoc = (XChartDocument)
98                 UnoRuntime.queryInterface(XChartDocument.class,xComp);
99         } catch (com.sun.star.uno.Exception e) {
100             // Some exception occures.FAILED
101             e.printStackTrace( log );
102             throw new StatusException( "Couldn't create document", e );
103         }
104     }
105 
106     /**
107     * Disposes Chart document.
108     */
109     protected synchronized void cleanup( TestParameters tParam, PrintWriter log ) {
110         if( xChartDoc!=null ) {
111             log.println( "    closing xChartDoc" );
112             util.DesktopTools.closeDoc(xChartDoc);
113             xChartDoc = null;
114         }
115     }
116 
117 
118     /**
119     * Creating a Testenvironment for the interfaces to be tested.
120     * Retrieves the diagram of the chart document. Obtains the properties of
121     * the specified data row. The obtained properties is the instance of
122     * the service <code>com.sun.star.chart.ChartDataRowProperties</code>.
123     * Creates a XY-diagram and bar-diagram also.
124     * Object relations created :
125     * <ul>
126     *  <li> <code>'LINE'</code> for
127     *      {@link ifc.chart._ChartDataPointProperties}(the created XY-diagram)</li>
128     *  <li> <code>'CHARTDOC'</code> for
129     *      {@link ifc.chart._ChartDataPointProperties},
130     *      {@link ifc.chart._Chart3DBarProperties}(the chart document)</li>
131     *  <li> <code>'BAR'</code> for
132     *      {@link ifc.chart._Chart3DBarProperties}(the created bar-diagram)</li>
133     * </ul>
134     */
135     protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
136 
137         XPropertySet  oObj = null;
138         XDiagram oDiagram = null;
139         // get the ChXDataRowPoint_Row
140         try {
141             log.println( "getting ChXDataRowPoint_Row" );
142             oDiagram = (XDiagram) xChartDoc.getDiagram();
143             oObj = (XPropertySet) oDiagram.getDataRowProperties(1);
144         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
145             // Some exception occures.FAILED
146             e.printStackTrace( log );
147             throw new StatusException( "Couldn't get ChXDataRowPoint_Row", e );
148         }
149 
150         log.println( "creating a new environment for chartdocument object" );
151         TestEnvironment tEnv = new TestEnvironment( oObj );
152 
153         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
154 
155         Object line = SOF.createDiagram(xChartDoc,"XYDiagram");
156         tEnv.addObjRelation("LINE",line);
157 
158         Object bar = SOF.createDiagram(xChartDoc,"BarDiagram");
159         tEnv.addObjRelation("BAR",bar);
160 
161         log.println( "adding ChartDocument as mod relation to environment" );
162         tEnv.addObjRelation("CHARTDOC", xChartDoc);
163 
164         return tEnv;
165     } // finish method getTestEnvironment
166 
167 
168 }    // finish class ChXDataRow
169 
170