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 import java.util.Comparator;
28 
29 import lib.StatusException;
30 import lib.TestCase;
31 import lib.TestEnvironment;
32 import lib.TestParameters;
33 import util.SOfficeFactory;
34 
35 import com.sun.star.chart.XChartDocument;
36 import com.sun.star.drawing.XShapeDescriptor;
37 import com.sun.star.frame.XController;
38 import com.sun.star.frame.XModel;
39 import com.sun.star.lang.XMultiServiceFactory;
40 import com.sun.star.uno.UnoRuntime;
41 
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.view.OfficeDocumentView</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 *  <li> <code>com::sun::star::view::XViewSettingsSupplier</code></li>
48 *  <li> <code>com::sun::star::view::XControlAccess</code></li>
49 *  <li> <code>com::sun::star::view::XSelectionSupplier</code></li>
50 * </ul>
51 * @see com.sun.star.view.OfficeDocumentView
52 * @see com.sun.star.view.XViewSettingsSupplier
53 * @see com.sun.star.view.XControlAccess
54 * @see com.sun.star.view.XSelectionSupplier
55 * @see ifc.view._XViewSettingsSupplier
56 * @see ifc.view._XControlAccess
57 * @see ifc.view._XSelectionSupplier
58 */
59 public class ChXChartView extends TestCase {
60     XChartDocument xChartDoc = null;
61 
62     /**
63     * Creates Chart document.
64     */
65     protected void initialize( TestParameters tParam, PrintWriter log ) {
66         // get a soffice factory object
67         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
68 
69         try {
70             log.println( "creating a chartdocument" );
71             xChartDoc = SOF.createChartDoc(null);
72         } catch (com.sun.star.uno.Exception e) {
73             // Some exception occures.FAILED
74             e.printStackTrace( log );
75             throw new StatusException( "Couldn't create document", e );
76         }
77     }
78 
79     /**
80     * Disposes Chart document.
81     */
82     protected void cleanup( TestParameters tParam, PrintWriter log ) {
83         if( xChartDoc!=null ) {
84             log.println( "    closing xChartDoc" );
85             util.DesktopTools.closeDoc(xChartDoc);
86             xChartDoc = null;
87         }
88     }
89 
90     /**
91     * Creating a Testenvironment for the interfaces to be tested.
92     * Retrieves the current controller of the chart document using
93     * the interface <code>XModel</code>.The retrieved controller is the instance
94     * of the service  <code>com.sun.star.view.OfficeDocumentView</code>.
95     * Obtains the main title and the legend of the chart document.
96     * Object relations created :
97     * <ul>
98     *
99     * </ul>
100     * @see com.sun.star.frame.XModel
101     */
102     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
103 
104         XController oObj = null;
105         XModel oModel = null;
106 
107         // get the ChartView
108         log.println( "getting ChartView" );
109         oModel = (XModel)UnoRuntime.queryInterface(XModel.class, xChartDoc);
110         oObj = (XController)oModel.getCurrentController();
111 
112         log.println( "creating a new environment for chartdocument object" );
113         TestEnvironment tEnv = new TestEnvironment( oObj );
114 
115         tEnv.addObjRelation("Selections", new Object[]
116             {xChartDoc.getArea(), xChartDoc.getDiagram(), xChartDoc.getTitle(),
117              xChartDoc.getLegend()} );
118 
119         tEnv.addObjRelation("Comparer", new Comparator() {
120             public int compare(Object o1, Object o2) {
121                 XShapeDescriptor descr1 = (XShapeDescriptor)
122                     UnoRuntime.queryInterface(XShapeDescriptor.class, o1);
123                 XShapeDescriptor descr2 = (XShapeDescriptor)
124                     UnoRuntime.queryInterface(XShapeDescriptor.class, o2);
125                 if (descr1 == null || descr2 == null) {
126                     return -1;
127                 }
128                 if (descr1.getShapeType().equals(descr2.getShapeType())) {
129                     return 0;
130                 }
131                 return 1;
132             }
133             public boolean equals(Object obj) {
134                 return compare(this, obj) == 0;
135             }
136         } );
137 
138         return tEnv;
139     } // finish method getTestEnvironment
140 
141 
142 }    // finish class ChXChartView
143 
144