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