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._sw;
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.drawing.XDrawPage;
37 import com.sun.star.drawing.XDrawPageSupplier;
38 import com.sun.star.drawing.XShapes;
39 import com.sun.star.lang.XMultiServiceFactory;
40 import com.sun.star.text.XTextDocument;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
43 
44 /**
45  * Test for object which is represented by service
46  * <code>com.sun.star.drawing.DrawPage</code>. <p>
47  * Object implements the following interfaces :
48  * <ul>
49  *  <li> <code>com::sun::star::drawing::GenericDrawPage</code></li>
50  *  <li> <code>com::sun::star::drawing::XShapeBinder</code></li>
51  *  <li> <code>com::sun::star::drawing::XShapeGrouper</code></li>
52  *  <li> <code>com::sun::star::drawing::XShapes</code></li>
53  *  <li> <code>com::sun::star::lang::XServiceInfo</code></li>
54  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
55  *  <li> <code>com::sun::star::container::XIndexAccess</code></li>
56  *  <li> <code>com::sun::star::container::XElementAccess</code></li>
57  *  <li> <code>com::sun::star::drawing::XMasterPageTarget</code></li>
58  *  <li> <code>com::sun::star::container::XNamed</code></li>
59  *  <li> <code>com::sun::star::drawing::XShapeCombiner</code></li>
60  * </ul> <p>
61  * This object test <b> is NOT </b> designed to be run in several
62  * threads concurently.
63  * @see com.sun.star.drawing.GenericDrawPage
64  * @see com.sun.star.drawing.XShapeBinder
65  * @see com.sun.star.drawing.XShapeGrouper
66  * @see com.sun.star.drawing.XShapes
67  * @see com.sun.star.lang.XServiceInfo
68  * @see com.sun.star.beans.XPropertySet
69  * @see com.sun.star.container.XIndexAccess
70  * @see com.sun.star.container.XElementAccess
71  * @see com.sun.star.drawing.XMasterPageTarget
72  * @see com.sun.star.container.XNamed
73  * @see com.sun.star.drawing.XShapeCombiner
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._XMasterPageTarget
83  * @see ifc.container._XNamed
84  * @see ifc.drawing._XShapeCombiner
85  */
86 public class SwXDrawPage extends TestCase {
87     XTextDocument xTextDoc;
88 
89     /**
90     * Creates text document.
91     */
initialize( TestParameters tParam, PrintWriter log )92     protected void initialize( TestParameters tParam, PrintWriter log ) {
93         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
94         try {
95             log.println( "creating a textdocument" );
96             xTextDoc = SOF.createTextDoc( null );
97         } catch ( com.sun.star.uno.Exception e ) {
98             e.printStackTrace( log );
99             throw new StatusException( "Couldn't create document", e );
100         }
101     }
102 
103     /**
104     * Disposes text document.
105     */
cleanup( TestParameters tParam, PrintWriter log )106     protected void cleanup( TestParameters tParam, PrintWriter log ) {
107         log.println( "    disposing xTextDoc " );
108         util.DesktopTools.closeDoc(xTextDoc);
109     }
110 
111     /**
112     * Creating a Testenvironment for the interfaces to be tested. After
113     * obtaining DrawPage object several shapes are inserted to it.
114     *     Object relations created :
115     * <ul>
116     *  <li> <code>'Shape'</code> for
117     *      {@link ifc.drawing._XShapes} : shape creator. </li>
118     *  <li> <code>'DrawPage'</code> for
119     *      {@link ifc.drawing._XShapeBinder},
120     *      {@link ifc.drawing._XShapeCombiner},
121     *      {@link ifc.drawing._XShapeGrouper} : DrawPage component we are
122     *      testing.</li>
123     * </ul>
124     */
createTestEnvironment( TestParameters Param, PrintWriter log )125     public synchronized TestEnvironment createTestEnvironment(
126             TestParameters Param, PrintWriter log ) throws StatusException {
127         XInterface oObj = null;
128         XDrawPageSupplier XDPSupp;
129         XDrawPage xDP = null;
130         XShapes oShapes = null;
131 
132         log.println( "creating a test environment" );
133         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF() );
134         XDPSupp = (XDrawPageSupplier) UnoRuntime.queryInterface
135             (XDrawPageSupplier.class, xTextDoc);
136         xDP = XDPSupp.getDrawPage();
137         oObj = xDP;
138 
139         //dbg.printInterfaces(oObj);
140         //System.exit(0);
141 
142         log.println( "inserting some Shapes" );
143         oShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, oObj);
144         oShapes.add(SOF.createShape(xTextDoc,2000,1500,1000,1000,"Line"));
145         oShapes.add(SOF.createShape(xTextDoc,3000,4500,15000,1000,"Ellipse"));
146         oShapes.add(SOF.createShape(xTextDoc,5000,3500,7500,5000,"Rectangle"));
147 
148         log.println( "creating a new environment for bodytext object" );
149         TestEnvironment tEnv = new TestEnvironment( oObj );
150 
151         ShapeDsc sDsc = new ShapeDsc(15000,13500,7500,10000,"Rectangle");
152         log.println( "adding Shape as mod relation to environment" );
153         tEnv.addObjRelation("Shape", new InstCreator( xTextDoc, sDsc));
154         tEnv.addObjRelation("DrawPage", oObj);
155 
156         return tEnv;
157     } // finish method getTestEnvironment
158 
159 }    // finish class SwXDrawPage
160 
161