1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._sch;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.SOfficeFactory;
33 
34 import com.sun.star.beans.XPropertySet;
35 import com.sun.star.chart.XChartDocument;
36 import com.sun.star.chart.XDiagram;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.uno.AnyConverter;
39 import com.sun.star.uno.Type;
40 
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.chart.ChartLine</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 *  <li> <code>com::sun::star::drawing::LineProperties</code></li>
47 *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
48 * </ul>
49 * @see com.sun.star.drawing.LineProperties
50 * @see com.sun.star.beans.XPropertySet
51 * @see ifc.drawing._LineProperties
52 * @see ifc.beans._XPropertySet
53 */
54 public class ChartLine extends TestCase {
55     XChartDocument xChartDoc = null;
56 
57     /**
58     * Creates Chart document.
59     */
initialize( TestParameters tParam, PrintWriter log )60     protected void initialize( TestParameters tParam, PrintWriter log ) {
61         // get a soffice factory object
62         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
63 
64         try {
65             log.println( "creating a chartdocument" );
66             xChartDoc = SOF.createChartDoc(null);
67         } catch (com.sun.star.uno.Exception e) {
68             // Some exception occured.FAILED
69             e.printStackTrace( log );
70             throw new StatusException( "Couldn't create document", e );
71         }
72     }
73 
74     /**
75     * Disposes Chart document.
76     */
cleanup( TestParameters tParam, PrintWriter log )77     protected void cleanup( TestParameters tParam, PrintWriter log ) {
78         if( xChartDoc!=null ) {
79             log.println( "    closing xChartDoc" );
80             util.DesktopTools.closeDoc(xChartDoc);
81             xChartDoc = null;
82         }
83     }
84 
85     /**
86     * Creating a Testenvironment for the interfaces to be tested.
87     * Creates a bar diagram and sets the created diagram for the chart document.
88     * Retrieves the property <code>'DataMeanValueProperties'</code> of
89     * the specified data row. The retrieved property is the instance of
90     * the service <code>com.sun.star.chart.ChartLine</code>.
91     * @see com.sun.star.chart.ChartLine
92     */
createTestEnvironment(TestParameters Param, PrintWriter log)93     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
94 
95         XPropertySet oObj = null;
96         XDiagram oDiagram = null;
97         SOfficeFactory SOF = null;
98 
99         //get LineDiagram
100         SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
101         oDiagram = SOF.createDiagram(xChartDoc, "LineDiagram");
102 
103         log.println( "getting Line-Diagram" );
104         xChartDoc.setDiagram(oDiagram);
105 
106         // get the Line
107         try {
108             log.println( "getting Line" );
109             XPropertySet RowProps = oDiagram.getDataRowProperties(1);
110             RowProps.setPropertyValue("MeanValue", new Boolean( true ));
111             oObj = (XPropertySet) AnyConverter.toObject(
112                 new Type(XPropertySet.class),
113                     RowProps.getPropertyValue("DataMeanValueProperties"));
114         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
115             // Some exception occured.FAILED
116             e.printStackTrace( log );
117             throw new StatusException( "Couldn't get Line", e );
118         } catch (com.sun.star.lang.WrappedTargetException e) {
119             // Some exception occured.FAILED
120             e.printStackTrace( log );
121             throw new StatusException( "Couldn't get Line", e );
122         } catch (com.sun.star.beans.UnknownPropertyException e) {
123             // Some exception occured.FAILED
124             e.printStackTrace( log );
125             throw new StatusException( "Couldn't get Line", e );
126         } catch (com.sun.star.lang.IllegalArgumentException e) {
127             // Some exception occured.FAILED
128             e.printStackTrace( log );
129             throw new StatusException( "Couldn't get Line", e );
130         }
131         catch(com.sun.star.beans.PropertyVetoException e) {
132              // Some exception occured.FAILED
133              e.printStackTrace( log );
134              throw new StatusException( "Couldn't get Line", e );
135          }
136 
137         log.println( "creating a new environment for chartdocument object" );
138         TestEnvironment tEnv = new TestEnvironment( oObj );
139 
140 
141         return tEnv;
142     } // finish method getTestEnvironment
143 
144 
145 }    // finish class ChartLine
146 
147