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