Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / SdXShape.java
blob535d30062fec2f74873dfbe787cc202e70be554e
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.style.XStyle;
38 import com.sun.star.uno.AnyConverter;
39 import com.sun.star.uno.Type;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
43 /**
44 * Test for object which is represented by service
45 * <code>com.sun.star.drawing.Shape</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>com::sun::star::lang::XComponent</code></li>
49 * <li> <code>com::sun::star::drawing::XShape</code></li>
50 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
51 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
52 * <li> <code>com::sun::star::drawing::Shape</code></li>
53 * </ul>
54 * @see com.sun.star.lang.XComponent
55 * @see com.sun.star.drawing.XShape
56 * @see com.sun.star.drawing.XShapeDescriptor
57 * @see com.sun.star.beans.XPropertySet
58 * @see com.sun.star.drawing.Shape
59 * @see ifc.lang._XComponent
60 * @see ifc.drawing._XShape
61 * @see ifc.drawing._XShapeDescriptor
62 * @see ifc.beans._XPropertySet
63 * @see ifc.drawing._Shape
65 public class SdXShape extends TestCase {
66 XComponent xDrawDoc;
68 /**
69 * Creates Drawing document.
71 @Override
72 protected void initialize(TestParameters Param, PrintWriter log) {
73 // get a soffice factory object
74 SOfficeFactory SOF = SOfficeFactory.getFactory(
75 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 @Override
90 protected void cleanup( TestParameters Param, PrintWriter log) {
91 log.println("disposing xDrawDoc");
92 util.DesktopTools.closeDoc(xDrawDoc);
95 /**
96 * Creating a Testenvironment for the interfaces to be tested.
97 * Retrieves the collection of the draw pages from the drawing document using
98 * the interface <code>XDrawPagesSupplier</code>. Creates a rectangle shape
99 * that is the instance of the service <code>com.sun.star.drawing.Shape</code>.
100 * Creates and adds several new rectangle shapes and one ellipse shape to
101 * the retrieved draw page. Sets and gets some properties of the created
102 * rectangle shape.
103 * Object relations created :
104 * <ul>
105 * <li> <code>'Style1'</code> for
106 * {@link ifc.drawing._XShapeDescriptor}, {@link ifc.drawing._XShape}
107 * (the value of the property 'Style' that was retrieved from the created
108 * rectangle shape) </li>
109 * <li> <code>'Style2'</code> for
110 * {@link ifc.drawing._XShapeDescriptor}, {@link ifc.drawing._XShape}
111 * (the value of the property 'Style' that was retrieved from the created
112 * ellipse shape) </li>
113 * </ul>
114 * @see com.sun.star.drawing.XDrawPagesSupplier
115 * @see com.sun.star.drawing.Shape
117 @Override
118 protected synchronized TestEnvironment createTestEnvironment(
119 TestParameters Param, PrintWriter log) {
121 log.println( "creating a test environment" );
123 // get a soffice factory object
124 SOfficeFactory SOF = SOfficeFactory.getFactory(
125 Param.getMSF());
127 // get the drawpage of drawing here
128 log.println( "getting Drawpage" );
129 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc);
130 XDrawPages oDPn = oDPS.getDrawPages();
131 XIndexAccess oDPi = UnoRuntime.queryInterface(XIndexAccess.class, oDPn);
132 XDrawPage oDP = null;
133 try {
134 oDP = (XDrawPage) AnyConverter.toObject(
135 new Type(XDrawPage.class),oDPi.getByIndex(0));
136 } catch (com.sun.star.lang.WrappedTargetException e) {
137 e.printStackTrace( log );
138 throw new StatusException("Couldn't get by index", e);
139 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
140 e.printStackTrace( log );
141 throw new StatusException("Couldn't get by index", e);
142 } catch (com.sun.star.lang.IllegalArgumentException e) {
143 e.printStackTrace( log );
144 throw new StatusException("Couldn't get by index", e);
147 //get a Shape
148 log.println( "getting Shape" );
149 XShapes oShapes = UnoRuntime.queryInterface
150 (XShapes.class, oDP);
151 XInterface oObj = SOF.createShape
152 (xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle");
153 for (int i=0; i < 10; i++) {
154 oShapes.add(
155 SOF.createShape(xDrawDoc,
156 5000, 3500, 7510 + 10 * i, 5010 + 10 * i, "Rectangle"));
158 XShape oShape = SOF.createShape
159 (xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse");
160 oShapes.add((XShape) oObj);
161 oShapes.add(oShape);
163 log.println( "creating a new environment for XShape object" );
164 TestEnvironment tEnv = new TestEnvironment( oObj );
166 log.println( "adding two style as ObjRelation for ShapeDescriptor" );
167 XPropertySet oShapeProps = UnoRuntime.queryInterface(XPropertySet.class, oObj);
168 XStyle aStyle = null;
169 try {
170 aStyle = (XStyle) AnyConverter.toObject(
171 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
172 oShapeProps.setPropertyValue("ZOrder", Integer.valueOf(1));
173 } catch (com.sun.star.lang.WrappedTargetException e) {
174 e.printStackTrace(log);
175 throw new StatusException("Couldn't set or get property value", e);
176 } catch (com.sun.star.beans.UnknownPropertyException e) {
177 e.printStackTrace(log);
178 throw new StatusException("Couldn't set or get property value", e);
179 } catch (com.sun.star.lang.IllegalArgumentException e) {
180 e.printStackTrace(log);
181 throw new StatusException("Couldn't set or get property value", e);
182 } catch (com.sun.star.beans.PropertyVetoException e) {
183 e.printStackTrace(log);
184 throw new StatusException("Couldn't set or get property value", e);
187 tEnv.addObjRelation("Style1", aStyle);
188 oShapeProps = UnoRuntime.queryInterface(XPropertySet.class, oShape);
189 try {
190 aStyle = (XStyle) AnyConverter.toObject(
191 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
192 } catch (com.sun.star.lang.WrappedTargetException e) {
193 e.printStackTrace(log);
194 throw new StatusException("Couldn't get property value", e);
195 } catch (com.sun.star.beans.UnknownPropertyException e) {
196 e.printStackTrace(log);
197 throw new StatusException("Couldn't get property value", e);
198 } catch (com.sun.star.lang.IllegalArgumentException e) {
199 e.printStackTrace(log);
200 throw new StatusException("Couldn't get property value", e);
203 tEnv.addObjRelation("Style2", aStyle);
205 return tEnv;
206 } // finish method createTestEnvironment
208 } // finish class SdXShape