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