1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package mod._sch;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.chart.XChartData;
26cdf0e10cSrcweir import com.sun.star.chart.XChartDocument;
27cdf0e10cSrcweir import com.sun.star.frame.XController;
28cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
29cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
30cdf0e10cSrcweir import com.sun.star.uno.XInterface;
31cdf0e10cSrcweir import com.sun.star.view.XSelectionSupplier;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir import java.io.PrintWriter;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir import lib.StatusException;
36cdf0e10cSrcweir import lib.TestCase;
37cdf0e10cSrcweir import lib.TestEnvironment;
38cdf0e10cSrcweir import lib.TestParameters;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir import util.SOfficeFactory;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
43cdf0e10cSrcweir /**
44cdf0e10cSrcweir * Test for object which is represented by service
45cdf0e10cSrcweir * <code>com.sun.star.chart.ChartDocument</code>. <p>
46cdf0e10cSrcweir * Object implements the following interfaces :
47cdf0e10cSrcweir * <ul>
48cdf0e10cSrcweir *  <li> <code>com::sun::star::lang::XComponent</code></li>
49cdf0e10cSrcweir *  <li> <code>com::sun::star::frame::XModel</code></li>
50cdf0e10cSrcweir *  <li> <code>com::sun::star::chart::XChartDocument</code></li>
51cdf0e10cSrcweir *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
52cdf0e10cSrcweir *  <li> <code>com::sun::star::chart::ChartTableAddressSupplier</code></li>
53cdf0e10cSrcweir *  <li> <code>com::sun::star::chart::ChartDocument</code></li>
54cdf0e10cSrcweir * </ul>
55cdf0e10cSrcweir * @see com.sun.star.lang.XComponent
56cdf0e10cSrcweir * @see com.sun.star.frame.XModel
57cdf0e10cSrcweir * @see com.sun.star.chart.XChartDocument
58cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet
59cdf0e10cSrcweir * @see com.sun.star.chart.ChartTableAddressSupplier
60cdf0e10cSrcweir * @see com.sun.star.chart.ChartDocument
61cdf0e10cSrcweir * @see ifc.lang._XComponent
62cdf0e10cSrcweir * @see ifc.frame._XModel
63cdf0e10cSrcweir * @see ifc.chart._XChartDocument
64cdf0e10cSrcweir * @see ifc.beans._XPropertySet
65cdf0e10cSrcweir * @see ifc.chart._ChartTableAddressSupplier
66cdf0e10cSrcweir * @see ifc.chart._ChartDocument
67cdf0e10cSrcweir */
68cdf0e10cSrcweir public class ChXChartDocument extends TestCase {
69cdf0e10cSrcweir     XChartDocument xChartDoc = null;
70cdf0e10cSrcweir     XChartDocument doc2 = null;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     /**
73cdf0e10cSrcweir     * Disposes Chart documents.
74cdf0e10cSrcweir     */
75cdf0e10cSrcweir     protected void cleanup(TestParameters Param, PrintWriter log) {
76cdf0e10cSrcweir         if( xChartDoc!=null ) {
77cdf0e10cSrcweir             log.println( "    closing xChartDoc" );
78cdf0e10cSrcweir             util.DesktopTools.closeDoc(xChartDoc);
79cdf0e10cSrcweir             xChartDoc = null;
80cdf0e10cSrcweir         }
81cdf0e10cSrcweir         if( doc2!=null ) {
82cdf0e10cSrcweir             log.println( "    closing xChartDoc2" );
83cdf0e10cSrcweir             util.DesktopTools.closeDoc(doc2);
84cdf0e10cSrcweir             doc2 = null;
85cdf0e10cSrcweir         }
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     /**
89cdf0e10cSrcweir     * Creating a Testenvironment for the interfaces to be tested.
90cdf0e10cSrcweir     * Creates two chart documents and retrieves current controllers from them
91cdf0e10cSrcweir     * using the interface <code>XChartDocument</code>. The created documents
92cdf0e10cSrcweir     * is the instances of the service <code>com.sun.star.chart.ChartDocument</code>.
93cdf0e10cSrcweir     * Obtains the data source of the second created chart and creates
94cdf0e10cSrcweir     * a pie diagram.
95cdf0e10cSrcweir     * Object relations created :
96cdf0e10cSrcweir     * <ul>
97cdf0e10cSrcweir     *  <li> <code>'SELSUPP'</code> for
98cdf0e10cSrcweir     *      {@link ifc.frame._XModel}(the controller of the first created chart
99cdf0e10cSrcweir     *      document)</li>
100cdf0e10cSrcweir     *  <li> <code>'TOSELECT'</code> for
101cdf0e10cSrcweir     *      {@link ifc.frame._XModel}(the shape of the main title of
102cdf0e10cSrcweir     *      the first created chart document)</li>
103cdf0e10cSrcweir     *  <li> <code>'CONT2'</code> for
104cdf0e10cSrcweir     *      {@link ifc.frame._XModel}(the second created chart document)</li>
105cdf0e10cSrcweir     *  <li> <code>'DIAGRAM'</code> for
106cdf0e10cSrcweir     *      {@link ifc.chart._XChartDocument}(the created pie diagram)</li>
107cdf0e10cSrcweir     *  <li> <code>'CHARTDATA'</code> for
108cdf0e10cSrcweir     *      {@link ifc.chart._XChartDocument}(the data source of the second
109cdf0e10cSrcweir     *      created chart)</li>
110cdf0e10cSrcweir     * </ul>
111cdf0e10cSrcweir     * @see com.sun.star.chart.XChartData
112cdf0e10cSrcweir     * @see com.sun.star.chart.ChartDocument
113cdf0e10cSrcweir     */
114cdf0e10cSrcweir     protected synchronized TestEnvironment createTestEnvironment(TestParameters tParam,
115cdf0e10cSrcweir                                                                  PrintWriter log) {
116cdf0e10cSrcweir         // get a soffice factory object
117cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory(
118cdf0e10cSrcweir                                      (XMultiServiceFactory) tParam.getMSF());
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         try {
121cdf0e10cSrcweir             log.println("creating a chartdocument");
122cdf0e10cSrcweir             xChartDoc = SOF.createChartDoc(null);
123cdf0e10cSrcweir             log.println("Waiting before opening second document");
124cdf0e10cSrcweir             doc2 = SOF.createChartDoc(null);
125cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
126cdf0e10cSrcweir             // Some exception occures.FAILED
127cdf0e10cSrcweir             e.printStackTrace(log);
128cdf0e10cSrcweir             throw new StatusException("Couldn't create document", e);
129cdf0e10cSrcweir         }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 
132cdf0e10cSrcweir         // get the chartdocument
133cdf0e10cSrcweir         log.println("getting ChartDocument");
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         XInterface oObj = (XChartDocument) xChartDoc;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir         XController cont1 = xChartDoc.getCurrentController();
138cdf0e10cSrcweir         XController cont2 = doc2.getCurrentController();
139cdf0e10cSrcweir 
140cdf0e10cSrcweir         cont1.getFrame().setName("cont1");
141cdf0e10cSrcweir         cont2.getFrame().setName("cont2");
142cdf0e10cSrcweir 
143cdf0e10cSrcweir         XSelectionSupplier sel = (XSelectionSupplier) UnoRuntime.queryInterface(
144cdf0e10cSrcweir                                          XSelectionSupplier.class, cont1);
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         log.println("creating a new environment for chartdocument object");
147cdf0e10cSrcweir 
148cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment(oObj);
149cdf0e10cSrcweir 
150cdf0e10cSrcweir         log.println("Adding SelectionSupplier and Shape to select for XModel");
151cdf0e10cSrcweir         tEnv.addObjRelation("SELSUPP", sel);
152cdf0e10cSrcweir         tEnv.addObjRelation("TOSELECT", xChartDoc.getTitle());
153cdf0e10cSrcweir 
154cdf0e10cSrcweir         log.println("adding Controller as ObjRelation for XModel");
155cdf0e10cSrcweir         tEnv.addObjRelation("CONT2", cont2);
156cdf0e10cSrcweir 
157cdf0e10cSrcweir         log.println("adding another Diagram as mod relation to environment");
158cdf0e10cSrcweir         tEnv.addObjRelation("DIAGRAM",
159cdf0e10cSrcweir                             SOF.createDiagram(xChartDoc, "PieDiagram"));
160cdf0e10cSrcweir 
161cdf0e10cSrcweir         log.println("adding another ChartData as mod relation to environment");
162cdf0e10cSrcweir 
163cdf0e10cSrcweir         XChartData ChartData = doc2.getData();
164cdf0e10cSrcweir         tEnv.addObjRelation("CHARTDATA", ChartData);
165cdf0e10cSrcweir 
166cdf0e10cSrcweir         return tEnv;
167cdf0e10cSrcweir     } // finish method getTestEnvironment
168cdf0e10cSrcweir } // finish class ChXChartDocument
169