1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package mod._sd;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import java.io.PrintWriter;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import lib.StatusException;
29cdf0e10cSrcweir import lib.TestCase;
30cdf0e10cSrcweir import lib.TestEnvironment;
31cdf0e10cSrcweir import lib.TestParameters;
32cdf0e10cSrcweir import util.SOfficeFactory;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
35cdf0e10cSrcweir import com.sun.star.container.XIndexAccess;
36cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage;
37cdf0e10cSrcweir import com.sun.star.drawing.XDrawPages;
38cdf0e10cSrcweir import com.sun.star.drawing.XDrawPagesSupplier;
39cdf0e10cSrcweir import com.sun.star.drawing.XShape;
40cdf0e10cSrcweir import com.sun.star.drawing.XShapes;
41cdf0e10cSrcweir import com.sun.star.lang.XComponent;
42cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
43cdf0e10cSrcweir import com.sun.star.style.XStyle;
44cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
45cdf0e10cSrcweir import com.sun.star.uno.Type;
46cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
47cdf0e10cSrcweir import com.sun.star.uno.XInterface;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir /**
50cdf0e10cSrcweir * Test for object which is represented by service
51cdf0e10cSrcweir * <code>com.sun.star.drawing.Shape</code>. <p>
52cdf0e10cSrcweir * Object implements the following interfaces :
53cdf0e10cSrcweir * <ul>
54cdf0e10cSrcweir *  <li> <code>com::sun::star::lang::XComponent</code></li>
55cdf0e10cSrcweir *  <li> <code>com::sun::star::drawing::XShape</code></li>
56cdf0e10cSrcweir *  <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
57cdf0e10cSrcweir *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
58cdf0e10cSrcweir *  <li> <code>com::sun::star::drawing::Shape</code></li>
59cdf0e10cSrcweir * </ul>
60cdf0e10cSrcweir * @see com.sun.star.lang.XComponent
61cdf0e10cSrcweir * @see com.sun.star.drawing.XShape
62cdf0e10cSrcweir * @see com.sun.star.drawing.XShapeDescriptor
63cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet
64cdf0e10cSrcweir * @see com.sun.star.drawing.Shape
65cdf0e10cSrcweir * @see ifc.lang._XComponent
66cdf0e10cSrcweir * @see ifc.drawing._XShape
67cdf0e10cSrcweir * @see ifc.drawing._XShapeDescriptor
68cdf0e10cSrcweir * @see ifc.beans._XPropertySet
69cdf0e10cSrcweir * @see ifc.drawing._Shape
70cdf0e10cSrcweir */
71cdf0e10cSrcweir public class SdXShape extends TestCase {
72cdf0e10cSrcweir     XComponent xDrawDoc;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     /**
75cdf0e10cSrcweir     * Creates Drawing document.
76cdf0e10cSrcweir     */
77cdf0e10cSrcweir     protected void initialize(TestParameters Param, PrintWriter log) {
78cdf0e10cSrcweir         // get a soffice factory object
79cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory(
80cdf0e10cSrcweir                                     (XMultiServiceFactory)Param.getMSF());
81cdf0e10cSrcweir 
82cdf0e10cSrcweir         try {
83cdf0e10cSrcweir             log.println( "creating a draw document" );
84cdf0e10cSrcweir             xDrawDoc = SOF.createDrawDoc(null);
85cdf0e10cSrcweir          } catch (com.sun.star.uno.Exception e) {
86cdf0e10cSrcweir             e.printStackTrace( log );
87cdf0e10cSrcweir             throw new StatusException("Couldn't create document", e);
88cdf0e10cSrcweir          }
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     /**
92cdf0e10cSrcweir     * Disposes Drawing document.
93cdf0e10cSrcweir     */
94cdf0e10cSrcweir     protected void cleanup( TestParameters Param, PrintWriter log) {
95cdf0e10cSrcweir         log.println("disposing xDrawDoc");
96cdf0e10cSrcweir         util.DesktopTools.closeDoc(xDrawDoc);;
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     /**
100cdf0e10cSrcweir     * Creating a Testenvironment for the interfaces to be tested.
101cdf0e10cSrcweir     * Retrieves the collection of the draw pages from the drawing document using
102cdf0e10cSrcweir     * the interface <code>XDrawPagesSupplier</code>. Creates a rectangle shape
103cdf0e10cSrcweir     * that is the instance of the service <code>com.sun.star.drawing.Shape</code>.
104cdf0e10cSrcweir     * Creates and adds several new rectangle shapes and one ellipse shape to
105cdf0e10cSrcweir     * the retrieved draw page. Sets and gets some properties of the created
106cdf0e10cSrcweir     * rectangle shape.
107cdf0e10cSrcweir     * Object relations created :
108cdf0e10cSrcweir     * <ul>
109cdf0e10cSrcweir     *  <li> <code>'Style1'</code> for
110cdf0e10cSrcweir     *      {@link ifc.drawing._XShapeDescriptor}, {@link ifc.drawing._XShape}
111cdf0e10cSrcweir     *      (the value of the property 'Style' that was retrived from the created
112cdf0e10cSrcweir     *      rectangle shape) </li>
113cdf0e10cSrcweir     *  <li> <code>'Style2'</code> for
114cdf0e10cSrcweir     *      {@link ifc.drawing._XShapeDescriptor}, {@link ifc.drawing._XShape}
115cdf0e10cSrcweir     *      (the value of the property 'Style' that was retrived from the created
116cdf0e10cSrcweir     *      ellipse shape) </li>
117cdf0e10cSrcweir     * </ul>
118cdf0e10cSrcweir     * @see com.sun.star.drawing.XDrawPagesSupplier
119cdf0e10cSrcweir     * @see com.sun.star.drawing.Shape
120cdf0e10cSrcweir     */
121cdf0e10cSrcweir     protected synchronized TestEnvironment createTestEnvironment(
122cdf0e10cSrcweir                                     TestParameters Param, PrintWriter log) {
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         log.println( "creating a test environment" );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         // get a soffice factory object
127cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory(
128cdf0e10cSrcweir                                     (XMultiServiceFactory)Param.getMSF());
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         // get the drawpage of drawing here
131cdf0e10cSrcweir         log.println( "getting Drawpage" );
132cdf0e10cSrcweir         XDrawPagesSupplier oDPS = (XDrawPagesSupplier)
133cdf0e10cSrcweir             UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc);
134cdf0e10cSrcweir         XDrawPages oDPn = oDPS.getDrawPages();
135cdf0e10cSrcweir         XIndexAccess oDPi = (XIndexAccess)
136cdf0e10cSrcweir             UnoRuntime.queryInterface(XIndexAccess.class, oDPn);
137cdf0e10cSrcweir         XDrawPage oDP = null;
138cdf0e10cSrcweir         try {
139cdf0e10cSrcweir             oDP = (XDrawPage) AnyConverter.toObject(
140cdf0e10cSrcweir                         new Type(XDrawPage.class),oDPi.getByIndex(0));
141cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
142cdf0e10cSrcweir             e.printStackTrace( log );
143cdf0e10cSrcweir             throw new StatusException("Couldn't get by index", e);
144cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
145cdf0e10cSrcweir             e.printStackTrace( log );
146cdf0e10cSrcweir             throw new StatusException("Couldn't get by index", e);
147cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
148cdf0e10cSrcweir             e.printStackTrace( log );
149cdf0e10cSrcweir             throw new StatusException("Couldn't get by index", e);
150cdf0e10cSrcweir         }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir         //get a Shape
153cdf0e10cSrcweir         log.println( "getting Shape" );
154cdf0e10cSrcweir         XShapes oShapes = (XShapes) UnoRuntime.queryInterface
155cdf0e10cSrcweir             (XShapes.class, oDP);
156cdf0e10cSrcweir         XInterface oObj = SOF.createShape
157cdf0e10cSrcweir             (xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle");
158cdf0e10cSrcweir         for (int i=0; i < 10; i++) {
159cdf0e10cSrcweir             oShapes.add(
160cdf0e10cSrcweir                 SOF.createShape(xDrawDoc,
161cdf0e10cSrcweir                     5000, 3500, 7510 + 10 * i, 5010 + 10 * i, "Rectangle"));
162cdf0e10cSrcweir         }
163cdf0e10cSrcweir         XShape oShape = SOF.createShape
164cdf0e10cSrcweir             (xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse");
165cdf0e10cSrcweir         oShapes.add((XShape) oObj);
166cdf0e10cSrcweir         oShapes.add((XShape) oShape);
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         log.println( "creating a new environment for XShape object" );
169cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment( oObj );
170cdf0e10cSrcweir 
171cdf0e10cSrcweir         log.println( "adding two style as ObjRelation for ShapeDescriptor" );
172cdf0e10cSrcweir         XPropertySet oShapeProps = (XPropertySet)
173cdf0e10cSrcweir             UnoRuntime.queryInterface(XPropertySet.class, oObj);
174cdf0e10cSrcweir         XStyle aStyle = null;
175cdf0e10cSrcweir         try {
176cdf0e10cSrcweir             aStyle = (XStyle) AnyConverter.toObject(
177cdf0e10cSrcweir                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
178cdf0e10cSrcweir             oShapeProps.setPropertyValue("ZOrder", new Integer(1));
179cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
180cdf0e10cSrcweir             e.printStackTrace(log);
181cdf0e10cSrcweir             throw new StatusException("Couldn't set or get property value", e);
182cdf0e10cSrcweir         } catch (com.sun.star.beans.UnknownPropertyException e) {
183cdf0e10cSrcweir             e.printStackTrace(log);
184cdf0e10cSrcweir             throw new StatusException("Couldn't set or get property value", e);
185cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
186cdf0e10cSrcweir             e.printStackTrace(log);
187cdf0e10cSrcweir             throw new StatusException("Couldn't set or get property value", e);
188cdf0e10cSrcweir         } catch (com.sun.star.beans.PropertyVetoException e) {
189cdf0e10cSrcweir             e.printStackTrace(log);
190cdf0e10cSrcweir             throw new StatusException("Couldn't set or get property value", e);
191cdf0e10cSrcweir         }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir         tEnv.addObjRelation("Style1", aStyle);
194cdf0e10cSrcweir         oShapeProps = (XPropertySet)
195cdf0e10cSrcweir             UnoRuntime.queryInterface(XPropertySet.class, oShape);
196cdf0e10cSrcweir         try {
197cdf0e10cSrcweir             aStyle = (XStyle) AnyConverter.toObject(
198cdf0e10cSrcweir                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
199cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
200cdf0e10cSrcweir             e.printStackTrace(log);
201cdf0e10cSrcweir             throw new StatusException("Couldn't get property value", e);
202cdf0e10cSrcweir         } catch (com.sun.star.beans.UnknownPropertyException e) {
203cdf0e10cSrcweir             e.printStackTrace(log);
204cdf0e10cSrcweir             throw new StatusException("Couldn't get property value", e);
205cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e) {
206cdf0e10cSrcweir             e.printStackTrace(log);
207cdf0e10cSrcweir             throw new StatusException("Couldn't get property value", e);
208cdf0e10cSrcweir         }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         tEnv.addObjRelation("Style2", aStyle);
211cdf0e10cSrcweir 
212cdf0e10cSrcweir         return tEnv;
213cdf0e10cSrcweir     } // finish method createTestEnvironment
214cdf0e10cSrcweir 
215cdf0e10cSrcweir }    // finish class SdXShape
216