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     /**
127      * Creating a Testenvironment for the interfaces to be tested.
128      * From the Draw document created a collection of its draw
129      * pages is obtained. Two new pages are inserted. And one
130      * page is obtained as a testing component. A shape is added
131      * to this page. <p>
132      *
133      *     Object relations created :
134      * <ul>
135      *  <li> <code>'DrawPage'</code> for
136      *      {@link ifc.drawing._XShapeGrouper} :
137      *      the draw page tested. </li>
138      *  <li> <code>'Shape'</code> for
139      *      {@link ifc.drawing._XShapes} :
140      *      the creator which can create instances of
141      *      <code>com.sun.star.drawing.Line</code> service </li>
142      * </ul>
143      */
144     protected TestEnvironment createTestEnvironment(TestParameters tParam,
145                                                     PrintWriter log) {
146         XInterface oObj = null;
147         XShape oShape = null;
148         XDrawPages oDP = null;
149 
150         XComponent xComp = (XComponent) UnoRuntime.queryInterface(
151                                    XComponent.class, xDoc);
152 
153 
154         // creation of testobject here
155         // first we write what we are intend to do to log file
156         log.println("creating a test environment");
157 
158         try {
159             log.println("getting Drawpages");
160 
161             XDrawPagesSupplier oDPS = (XDrawPagesSupplier) UnoRuntime.queryInterface(
162                                               XDrawPagesSupplier.class, xDoc);
163             oDP = (XDrawPages) oDPS.getDrawPages();
164             oDP.insertNewByIndex(1);
165             oDP.insertNewByIndex(2);
166             oObj = (XDrawPage) AnyConverter.toObject(new Type(XDrawPage.class),
167                                                      oDP.getByIndex(0));
168 
169             SOfficeFactory SOF = SOfficeFactory.getFactory(
170                                          (XMultiServiceFactory) tParam.getMSF());
171 
172             oShape = SOF.createShape(xComp, 5000, 3500, 7500, 5000,
173                                      "Rectangle");
174             DrawTools.getShapes((XDrawPage) oObj).add(oShape);
175 
176             XShape oShape1 = SOF.createShape(xComp, 5000, 5500, 5000, 5000,
177                                              "Rectangle");
178             DrawTools.getShapes((XDrawPage) oObj).add(oShape1);
179         } catch (com.sun.star.lang.WrappedTargetException e) {
180             log.println("Couldn't create insance");
181             e.printStackTrace(log);
182             throw new StatusException("Can't create enviroment", e);
183         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
184             log.println("Couldn't create insance");
185             e.printStackTrace(log);
186             throw new StatusException("Can't create enviroment", e);
187         } catch (com.sun.star.lang.IllegalArgumentException e) {
188             log.println("Couldn't create insance");
189             e.printStackTrace(log);
190             throw new StatusException("Can't create enviroment", e);
191         }
192 
193         // create test environment here
194         TestEnvironment tEnv = new TestEnvironment(oObj);
195 
196 
197         //adding a controlButton to have a Form
198         FormTools.insertControlShape(
199                 (XComponent) UnoRuntime.queryInterface(XComponent.class, xDoc),
200                 3000, 4500, 15000, 1000, "CommandButton");
201 
202         // relation for XShapes interface
203         ShapeDsc sDsc = new ShapeDsc(5000, 3500, 7500, 10000, "Line");
204         tEnv.addObjRelation("Shape", new InstCreator(xDoc, sDsc));
205 
206         log.println("ImplementationName: " + util.utils.getImplName(oObj));
207 
208 
209         // adding relation for XShapeGrouper
210         tEnv.addObjRelation("DrawPage", oObj);
211 
212         // adding relation for XMasterPageTarget
213 
214         /*XMasterPagesSupplier oMPS = (XMasterPagesSupplier)
215             UnoRuntime.queryInterface(XMasterPagesSupplier.class, xDoc);
216         XDrawPages oGroup = oMPS.getMasterPages();
217         tEnv.addObjRelation("MasterPageSupplier",oGroup); */
218         return tEnv;
219     } // finish method getTestEnvironment
220 } // finish class SvxDrawPage
221