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