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