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