Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxShapePolyPolygon.java
blob97a5cd03c56c22f6b92daba926bad1084fa784eb
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._svx;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.DefaultDsc;
28 import util.DrawTools;
29 import util.InstCreator;
30 import util.SOfficeFactory;
31 import util.utils;
33 import com.sun.star.awt.Point;
34 import com.sun.star.awt.Size;
35 import com.sun.star.beans.XPropertySet;
36 import com.sun.star.drawing.XShape;
37 import com.sun.star.lang.XComponent;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.style.XStyle;
40 import com.sun.star.uno.AnyConverter;
41 import com.sun.star.uno.Type;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
45 /**
46 * Test for object which is represented by service
47 * <code>com.sun.star.drawing.PolyPolygonShape</code>. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
51 * <li> <code>com::sun::star::drawing::LineProperties</code></li>
52 * <li> <code>com::sun::star::drawing::FillProperties</code></li>
53 * <li> <code>com::sun::star::drawing::PolyPolygonDescriptor</code></li>
54 * <li> <code>com::sun::star::drawing::ShadowProperties</code></li>
55 * <li> <code>com::sun::star::drawing::XGluePointsSupplier</code></li>
56 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
57 * <li> <code>com::sun::star::drawing::RotationDescriptor</code></li>
58 * <li> <code>com::sun::star::text::XTextRange</code></li>
59 * <li> <code>com::sun::star::drawing::XShape</code></li>
60 * <li> <code>com::sun::star::lang::XComponent</code></li>
61 * <li> <code>com::sun::star::drawing::TextProperties</code></li>
62 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
63 * <li> <code>com::sun::star::text::XText</code></li>
64 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
65 * <li> <code>com::sun::star::text::XSimpleText</code></li>
66 * <li> <code>com::sun::star::drawing::Shape</code></li>
67 * </ul> <p>
68 * The following files used by this test :
69 * <ul>
70 * <li><b> TransparencyChart.sxs </b> : to load predefined chart
71 * document where two 'automatic' transparency styles exists :
72 * 'Transparency 1' and 'Transparency 2'.</li>
73 * </ul> <p>
75 * This object test <b> is NOT </b> designed to be run in several
76 * threads concurently.
78 * @see com.sun.star.style.ParagraphProperties
79 * @see com.sun.star.drawing.LineProperties
80 * @see com.sun.star.drawing.FillProperties
81 * @see com.sun.star.drawing.PolyPolygonDescriptor
82 * @see com.sun.star.drawing.ShadowProperties
83 * @see com.sun.star.drawing.XGluePointsSupplier
84 * @see com.sun.star.style.CharacterProperties
85 * @see com.sun.star.drawing.RotationDescriptor
86 * @see com.sun.star.text.XTextRange
87 * @see com.sun.star.drawing.XShape
88 * @see com.sun.star.lang.XComponent
89 * @see com.sun.star.drawing.TextProperties
90 * @see com.sun.star.beans.XPropertySet
91 * @see com.sun.star.text.XText
92 * @see com.sun.star.drawing.XShapeDescriptor
93 * @see com.sun.star.text.XSimpleText
94 * @see com.sun.star.drawing.Shape
95 * @see ifc.style._ParagraphProperties
96 * @see ifc.drawing._LineProperties
97 * @see ifc.drawing._FillProperties
98 * @see ifc.drawing._PolyPolygonDescriptor
99 * @see ifc.drawing._ShadowProperties
100 * @see ifc.drawing._XGluePointsSupplier
101 * @see ifc.style._CharacterProperties
102 * @see ifc.drawing._RotationDescriptor
103 * @see ifc.text._XTextRange
104 * @see ifc.drawing._XShape
105 * @see ifc.lang._XComponent
106 * @see ifc.drawing._TextProperties
107 * @see ifc.beans._XPropertySet
108 * @see ifc.text._XText
109 * @see ifc.drawing._XShapeDescriptor
110 * @see ifc.text._XSimpleText
111 * @see ifc.drawing._Shape
113 public class SvxShapePolyPolygon extends TestCase {
115 static XComponent xDrawDoc;
118 * in general this method creates a testdocument
120 * @param tParam class which contains additional test parameters
121 * @param log class to log the test state and result
124 * @see TestParameters
125 * * @see PrintWriter
128 @Override
129 protected void initialize( TestParameters tParam, PrintWriter log ) {
130 // get a soffice factory object
131 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
133 try {
134 log.println( "creating a chartdocument" );
135 xDrawDoc = SOF.loadDocument(
136 utils.getFullTestURL("SvxShape.sxd"));
137 } catch (com.sun.star.uno.Exception e) {
138 // Some exception occurs.FAILED
139 e.printStackTrace( log );
140 throw new StatusException( "Couldn't create document", e );
145 * in general this method disposes the testenvironment and document
147 * @param tParam class which contains additional test parameters
148 * @param log class to log the test state and result
151 * @see TestParameters
152 * * @see PrintWriter
155 @Override
156 protected void cleanup( TestParameters tParam, PrintWriter log ) {
157 log.println( " disposing xDrawDoc " );
158 util.DesktopTools.closeDoc(xDrawDoc);
163 * * creating a Testenvironment for the interfaces to be tested
165 * @param tParam class which contains additional test parameters
166 * @param log class to log the test state and result
168 * @return Status class
170 * @see TestParameters
171 * * @see PrintWriter
173 @Override
174 protected TestEnvironment createTestEnvironment
175 (TestParameters tParam, PrintWriter log) {
177 XInterface oObj = null;
178 XShape oShape = null;
180 // creation of testobject here
181 // first we write what we are intend to do to log file
182 log.println( "creating a test environment" );
184 try {
185 // adding some shapes for testing.
186 XMultiServiceFactory xMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xDrawDoc) ;
187 XInterface oInst = (XInterface) xMSF.createInstance
188 ("com.sun.star.drawing.PolyPolygonShape") ;
189 oShape = UnoRuntime.queryInterface
190 (XShape.class, oInst) ;
192 oShape.setSize(new Size(0,0)) ;
193 oShape.setPosition(new Point(0,0)) ;
195 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
197 Point[] square1 = new Point[] {
198 new Point(5000, 5000),
199 new Point(10000, 5000),
200 new Point(10000, 10000),
201 new Point(5000, 10000)} ;
203 Point[] square2 = new Point[] {
204 new Point(6500, 6500),
205 new Point(8500, 6500),
206 new Point(8500, 8500),
207 new Point(6500, 8500)} ;
209 Point[][] polygon = new Point[][] {square1, square2};
211 UnoRuntime.queryInterface(XPropertySet.class,
212 oShape).setPropertyValue("PolyPolygon", polygon) ;
214 oObj = oShape ;
216 SOfficeFactory SOF = SOfficeFactory.getFactory(tParam.getMSF()) ;
217 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Line");
218 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
220 catch (Exception e) {
221 log.println("Couldn't create insance");
222 e.printStackTrace(log);
225 // test environment creation
227 TestEnvironment tEnv = new TestEnvironment(oObj);
229 log.println( "adding two styles as ObjRelation for ShapeDescriptor" );
230 XPropertySet oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oObj);
231 XStyle aStyle = null;
232 try {
233 aStyle = (XStyle) AnyConverter.toObject(
234 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
235 } catch (Exception e) {}
236 tEnv.addObjRelation("Style1",aStyle);
237 oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oShape);
238 try {
239 aStyle = (XStyle) AnyConverter.toObject(
240 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
241 } catch (Exception e) {}
242 tEnv.addObjRelation("Style2",aStyle);
244 // adding relation for XText
245 DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
246 "com.sun.star.text.TextField.URL");
247 log.println( " adding InstCreator object" );
248 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
250 return tEnv;
251 } // finish method getTestEnvironment
253 } // finish class SvxShapeCollection