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