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 package mod._svx;
24 
25 import com.sun.star.drawing.XDrawPage;
26 import com.sun.star.drawing.XDrawPages;
27 import com.sun.star.drawing.XDrawPagesSupplier;
28 import com.sun.star.drawing.XShape;
29 import com.sun.star.lang.XComponent;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.sheet.XSpreadsheetDocument;
32 import com.sun.star.uno.AnyConverter;
33 import com.sun.star.uno.Type;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
36 
37 import java.io.PrintWriter;
38 
39 import lib.StatusException;
40 import lib.TestCase;
41 import lib.TestEnvironment;
42 import lib.TestParameters;
43 
44 import util.DrawTools;
45 import util.FormTools;
46 import util.InstCreator;
47 import util.SOfficeFactory;
48 import util.ShapeDsc;
49 
50 
51 /**
52  * Test for object which is represented by service
53  * <code>com.sun.star.drawing.DrawPage</code>. <p>
54  *
55  * Object implements the following interfaces :
56  * <ul>
57  *  <li> <code>com::sun::star::drawing::GenericDrawPage</code></li>
58  *  <li> <code>com::sun::star::drawing::XShapeBinder</code></li>
59  *  <li> <code>com::sun::star::drawing::XShapeGrouper</code></li>
60  *  <li> <code>com::sun::star::drawing::XShapes</code></li>
61  *  <li> <code>com::sun::star::lang::XServiceInfo</code></li>
62  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
63  *  <li> <code>com::sun::star::container::XIndexAccess</code></li>
64  *  <li> <code>com::sun::star::container::XElementAccess</code></li>
65  *  <li> <code>com::sun::star::drawing::XMasterPageTarget</code></li>
66  *  <li> <code>com::sun::star::container::XNamed</code></li>
67  *  <li> <code>com::sun::star::drawing::XShapeCombiner</code></li>
68  * </ul> <p>
69  *
70  * This object test <b> is NOT </b> designed to be run in several
71  * threads concurently.
72  *
73  * @see com.sun.star.drawing.GenericDrawPage
74  * @see com.sun.star.drawing.XShapeBinder
75  * @see com.sun.star.drawing.XShapeGrouper
76  * @see com.sun.star.drawing.XShapes
77  * @see com.sun.star.lang.XServiceInfo
78  * @see com.sun.star.beans.XPropertySet
79  * @see com.sun.star.container.XIndexAccess
80  * @see com.sun.star.container.XElementAccess
81  * @see com.sun.star.drawing.XMasterPageTarget
82  * @see com.sun.star.container.XNamed
83  * @see com.sun.star.drawing.XShapeCombiner
84  * @see ifc.drawing._GenericDrawPage
85  * @see ifc.drawing._XShapeBinder
86  * @see ifc.drawing._XShapeGrouper
87  * @see ifc.drawing._XShapes
88  * @see ifc.lang._XServiceInfo
89  * @see ifc.beans._XPropertySet
90  * @see ifc.container._XIndexAccess
91  * @see ifc.container._XElementAccess
92  * @see ifc.drawing._XMasterPageTarget
93  * @see ifc.container._XNamed
94  * @see ifc.drawing._XShapeCombiner
95  */
96 public class SvxDrawPage extends TestCase {
97     static XSpreadsheetDocument xDoc = null;
98 
99     /**
100      * Creates a new Draw document.
101      */
102     protected void initialize(TestParameters tParam, PrintWriter log) {
103         // get a soffice factory object
104         SOfficeFactory SOF = SOfficeFactory.getFactory(
105                                      (XMultiServiceFactory) tParam.getMSF());
106 
107         try {
108             log.println("creating a sheetdocument");
109             xDoc = SOF.createCalcDoc(null);
110         } catch (com.sun.star.uno.Exception e) {
111             // Some exception occures.FAILED
112             e.printStackTrace(log);
113             throw new StatusException("Couldn't create document", e);
114         }
115     }
116 
117     /**
118      * Disposes the Draw document created before
119      */
120     protected void cleanup(TestParameters tParam, PrintWriter log) {
121         log.println("    disposing xSheetDoc ");
122         util.DesktopTools.closeDoc(xDoc);
123     }
124 
125     /**
126      * Creating a Testenvironment for the interfaces to be tested.
127      * From the Draw document created a collection of its draw
128      * pages is obtained. Two new pages are inserted. And one
129      * page is obtained as a testing component. A shape is added
130      * to this page. <p>
131      *
132      *     Object relations created :
133      * <ul>
134      *  <li> <code>'DrawPage'</code> for
135      *      {@link ifc.drawing._XShapeGrouper} :
136      *      the draw page tested. </li>
137      *  <li> <code>'Shape'</code> for
138      *      {@link ifc.drawing._XShapes} :
139      *      the creator which can create instances of
140      *      <code>com.sun.star.drawing.Line</code> service </li>
141      * </ul>
142      */
143     protected TestEnvironment createTestEnvironment(TestParameters tParam,
144                                                     PrintWriter log) {
145         XInterface oObj = null;
146         XShape oShape = null;
147         XDrawPages oDP = null;
148 
149         XComponent xComp = (XComponent) UnoRuntime.queryInterface(
150                                    XComponent.class, xDoc);
151 
152 
153         // creation of testobject here
154         // first we write what we are intend to do to log file
155         log.println("creating a test environment");
156 
157         try {
158             log.println("getting Drawpages");
159 
160             XDrawPagesSupplier oDPS = (XDrawPagesSupplier) UnoRuntime.queryInterface(
161                                               XDrawPagesSupplier.class, xDoc);
162             oDP = (XDrawPages) oDPS.getDrawPages();
163             oDP.insertNewByIndex(1);
164             oDP.insertNewByIndex(2);
165             oObj = (XDrawPage) AnyConverter.toObject(new Type(XDrawPage.class),
166                                                      oDP.getByIndex(0));
167 
168             SOfficeFactory SOF = SOfficeFactory.getFactory(
169                                          (XMultiServiceFactory) tParam.getMSF());
170 
171             oShape = SOF.createShape(xComp, 5000, 3500, 7500, 5000,
172                                      "Rectangle");
173             DrawTools.getShapes((XDrawPage) oObj).add(oShape);
174 
175             XShape oShape1 = SOF.createShape(xComp, 5000, 5500, 5000, 5000,
176                                              "Rectangle");
177             DrawTools.getShapes((XDrawPage) oObj).add(oShape1);
178         } catch (com.sun.star.lang.WrappedTargetException e) {
179             log.println("Couldn't create insance");
180             e.printStackTrace(log);
181             throw new StatusException("Can't create environment", e);
182         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
183             log.println("Couldn't create insance");
184             e.printStackTrace(log);
185             throw new StatusException("Can't create environment", e);
186         } catch (com.sun.star.lang.IllegalArgumentException e) {
187             log.println("Couldn't create insance");
188             e.printStackTrace(log);
189             throw new StatusException("Can't create environment", e);
190         }
191 
192         // create test environment here
193         TestEnvironment tEnv = new TestEnvironment(oObj);
194 
195 
196         //adding a controlButton to have a Form
197         FormTools.insertControlShape(
198                 (XComponent) UnoRuntime.queryInterface(XComponent.class, xDoc),
199                 3000, 4500, 15000, 1000, "CommandButton");
200 
201         // relation for XShapes interface
202         ShapeDsc sDsc = new ShapeDsc(5000, 3500, 7500, 10000, "Line");
203         tEnv.addObjRelation("Shape", new InstCreator(xDoc, sDsc));
204 
205         log.println("ImplementationName: " + util.utils.getImplName(oObj));
206 
207 
208         // adding relation for XShapeGrouper
209         tEnv.addObjRelation("DrawPage", oObj);
210 
211         // adding relation for XMasterPageTarget
212 
213         /*XMasterPagesSupplier oMPS = (XMasterPagesSupplier)
214             UnoRuntime.queryInterface(XMasterPagesSupplier.class, xDoc);
215         XDrawPages oGroup = oMPS.getMasterPages();
216         tEnv.addObjRelation("MasterPageSupplier",oGroup); */
217         return tEnv;
218     } // finish method getTestEnvironment
219 } // finish class SvxDrawPage
220