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