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 
28 package mod._sd;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.FormTools;
37 import util.InstCreator;
38 import util.SOfficeFactory;
39 import util.ShapeDsc;
40 
41 import com.sun.star.container.XIndexAccess;
42 import com.sun.star.drawing.XControlShape;
43 import com.sun.star.drawing.XDrawPage;
44 import com.sun.star.drawing.XDrawPages;
45 import com.sun.star.drawing.XDrawPagesSupplier;
46 import com.sun.star.drawing.XMasterPagesSupplier;
47 import com.sun.star.drawing.XShape;
48 import com.sun.star.drawing.XShapes;
49 import com.sun.star.lang.XComponent;
50 import com.sun.star.lang.XMultiServiceFactory;
51 import com.sun.star.uno.AnyConverter;
52 import com.sun.star.uno.Type;
53 import com.sun.star.uno.UnoRuntime;
54 import com.sun.star.uno.XInterface;
55 
56 /**
57 * Test for object which is represented by service
58 * <code>com.sun.star.drawing.DrawPage</code>. <p>
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>
73 * @see com.sun.star.drawing.DrawPage
74 * @see com.sun.star.drawing.GenericDrawPage
75 * @see com.sun.star.drawing.XShapeBinder
76 * @see com.sun.star.drawing.XShapeGrouper
77 * @see com.sun.star.drawing.XShapes
78 * @see com.sun.star.lang.XServiceInfo
79 * @see com.sun.star.beans.XPropertySet
80 * @see com.sun.star.container.XIndexAccess
81 * @see com.sun.star.container.XElementAccess
82 * @see com.sun.star.drawing.XMasterPageTarget
83 * @see com.sun.star.container.XNamed
84 * @see com.sun.star.drawing.XShapeCombiner
85 * @see ifc.drawing._GenericDrawPage
86 * @see ifc.drawing._XShapeBinder
87 * @see ifc.drawing._XShapeGrouper
88 * @see ifc.drawing._XShapes
89 * @see ifc.lang._XServiceInfo
90 * @see ifc.beans._XPropertySet
91 * @see ifc.container._XIndexAccess
92 * @see ifc.container._XElementAccess
93 * @see ifc.drawing._XMasterPageTarget
94 * @see ifc.container._XNamed
95 * @see ifc.drawing._XShapeCombiner
96 */
97 public class SdDrawPage extends TestCase {
98     XComponent xDrawDoc;
99 
100     /**
101     * Creates Drawing document.
102     */
103     protected void initialize(TestParameters Param, PrintWriter log) {
104         // get a soffice factory object
105         SOfficeFactory SOF = SOfficeFactory.getFactory(
106                                     (XMultiServiceFactory)Param.getMSF());
107 
108         try {
109             log.println( "creating a draw document" );
110             xDrawDoc = SOF.createDrawDoc(null);
111         } catch (com.sun.star.uno.Exception e) {
112             // Some exception occures.FAILED
113             e.printStackTrace( log );
114             throw new StatusException( "Couldn't create document", e );
115         }
116     }
117 
118     /**
119     * Disposes Drawing document.
120     */
121     protected void cleanup( TestParameters Param, PrintWriter log) {
122         log.println("disposing xDrawDoc");
123         util.DesktopTools.closeDoc(xDrawDoc);;
124     }
125 
126     /**
127     * Creating a Testenvironment for the interfaces to be tested.
128     * Retrieves the collection of the draw pages from the drawing document using
129     * the interface <code>XDrawPagesSupplier</code> and take one of them.
130     * The retrieved draw page is the instance of the service
131     * <code>com.sun.star.drawing.DrawPage</code>. Inserts some shapes
132     * into the draw page. Obtains the MasterPages collection. Creates
133     * the rectangle shape.
134     * Object relations created :
135     * <ul>
136     *  <li> <code>'Shape'</code> for
137     *      {@link ifc.drawing._XShapes}( the created rectangle shape )</li>
138     *  <li> <code>'DrawPage'</code> for
139     *      {@link ifc.drawing._XShapeBinder}, {@link ifc.drawing._XShapeGrouper},
140     *      {@link ifc.drawing._XShapeCombiner}( the retrieved draw page )</li>
141     *  <li> <code>'MasterPageSupplier'</code> for
142     *      {@link ifc.drawing._XMasterPageTarget}(the obtained master pages
143     *      collection)</li>
144     * </ul>
145     * @see com.sun.star.drawing.DrawPage
146     * @see com.sun.star.drawing.XDrawPagesSupplier
147     */
148     protected synchronized TestEnvironment createTestEnvironment(
149                                     TestParameters Param, PrintWriter log) {
150 
151         XInterface oObj = null;
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         SOfficeFactory SOF = SOfficeFactory.getFactory(
158                                 (XMultiServiceFactory)Param.getMSF());
159 
160         // get the drawpage of drawing here
161         log.println( "getting Drawpage" );
162         XDrawPagesSupplier oDPS = (XDrawPagesSupplier)
163             UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc);
164         XDrawPages oDPn = oDPS.getDrawPages();
165         XIndexAccess oDPi = (XIndexAccess)
166             UnoRuntime.queryInterface(XIndexAccess.class,oDPn);
167         try {
168             oObj = (XDrawPage) AnyConverter.toObject(
169                     new Type(XDrawPage.class),oDPi.getByIndex(0));
170         } catch (com.sun.star.lang.WrappedTargetException e) {
171             e.printStackTrace( log );
172             throw new StatusException( "Couldn't get DrawPage", e );
173         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
174             e.printStackTrace( log );
175             throw new StatusException( "Couldn't get DrawPage", e );
176         } catch (com.sun.star.lang.IllegalArgumentException e) {
177             e.printStackTrace( log );
178             throw new StatusException( "Couldn't get DrawPage", e );
179         }
180 
181         //put something on the drawpage
182         log.println( "inserting some Shapes" );
183         XShapes oShapes = (XShapes) UnoRuntime.queryInterface
184             (XShapes.class,oObj);
185         oShapes.add(SOF.createShape
186             (xDrawDoc, 2000, 1500, 1000, 1000, "Line"));
187         oShapes.add(SOF.createShape
188             (xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse"));
189         oShapes.add(SOF.createShape
190             (xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle"));
191 
192         //get the XMasterPagesSupplier
193         log.println("get XMasterPagesSupplier");
194         XMasterPagesSupplier oMPS = (XMasterPagesSupplier)
195             UnoRuntime.queryInterface(XMasterPagesSupplier.class, xDrawDoc);
196         XDrawPages oGroup = oMPS.getMasterPages();
197 
198         log.println( "creating a new environment for drawpage object" );
199         TestEnvironment tEnv = new TestEnvironment( oObj );
200 
201         XControlShape aShape = FormTools.createControlShape(
202                                 xDrawDoc,3000,4500,15000,10000,"CommandButton");
203 
204         oShapes.add((XShape) aShape);
205 
206         ShapeDsc sDsc = new ShapeDsc(5000, 3500, 7500, 10000, "Rectangle");
207         log.println( "adding Shape as mod relation to environment" );
208         tEnv.addObjRelation("Shape", new InstCreator( xDrawDoc, sDsc));
209         tEnv.addObjRelation("DrawPage", oObj);
210         tEnv.addObjRelation("MasterPageSupplier",oGroup);
211 
212         return tEnv;
213     } // finish method createTestEnvironment
214 
215 }    // finish class SdDrawPage
216 
217