merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _svx / SvxShapePolyPolygon.java
blob7bc1ad98bd8e747d049cc933086e64ea82f38cdf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SvxShapePolyPolygon.java,v $
10 * $Revision: 1.7.8.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._svx;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.DefaultDsc;
40 import util.DrawTools;
41 import util.InstCreator;
42 import util.SOfficeFactory;
43 import util.utils;
45 import com.sun.star.awt.Point;
46 import com.sun.star.awt.Size;
47 import com.sun.star.beans.XPropertySet;
48 import com.sun.star.drawing.XShape;
49 import com.sun.star.lang.XComponent;
50 import com.sun.star.lang.XMultiServiceFactory;
51 import com.sun.star.style.XStyle;
52 import com.sun.star.uno.AnyConverter;
53 import com.sun.star.uno.Type;
54 import com.sun.star.uno.UnoRuntime;
55 import com.sun.star.uno.XInterface;
57 /**
58 * Test for object which is represented by service
59 * <code>com.sun.star.drawing.PolyPolygonShape</code>. <p>
60 * Object implements the following interfaces :
61 * <ul>
62 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
63 * <li> <code>com::sun::star::drawing::LineProperties</code></li>
64 * <li> <code>com::sun::star::drawing::FillProperties</code></li>
65 * <li> <code>com::sun::star::drawing::PolyPolygonDescriptor</code></li>
66 * <li> <code>com::sun::star::drawing::ShadowProperties</code></li>
67 * <li> <code>com::sun::star::drawing::XGluePointsSupplier</code></li>
68 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
69 * <li> <code>com::sun::star::drawing::RotationDescriptor</code></li>
70 * <li> <code>com::sun::star::text::XTextRange</code></li>
71 * <li> <code>com::sun::star::drawing::XShape</code></li>
72 * <li> <code>com::sun::star::lang::XComponent</code></li>
73 * <li> <code>com::sun::star::drawing::TextProperties</code></li>
74 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
75 * <li> <code>com::sun::star::text::XText</code></li>
76 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
77 * <li> <code>com::sun::star::text::XSimpleText</code></li>
78 * <li> <code>com::sun::star::drawing::Shape</code></li>
79 * </ul> <p>
80 * The following files used by this test :
81 * <ul>
82 * <li><b> TransparencyChart.sxs </b> : to load predefined chart
83 * document where two 'automatic' transparency styles exists :
84 * 'Transparency 1' and 'Transparency 2'.</li>
85 * </ul> <p>
87 * This object test <b> is NOT </b> designed to be run in several
88 * threads concurently.
90 * @see com.sun.star.style.ParagraphProperties
91 * @see com.sun.star.drawing.LineProperties
92 * @see com.sun.star.drawing.FillProperties
93 * @see com.sun.star.drawing.PolyPolygonDescriptor
94 * @see com.sun.star.drawing.ShadowProperties
95 * @see com.sun.star.drawing.XGluePointsSupplier
96 * @see com.sun.star.style.CharacterProperties
97 * @see com.sun.star.drawing.RotationDescriptor
98 * @see com.sun.star.text.XTextRange
99 * @see com.sun.star.drawing.XShape
100 * @see com.sun.star.lang.XComponent
101 * @see com.sun.star.drawing.TextProperties
102 * @see com.sun.star.beans.XPropertySet
103 * @see com.sun.star.text.XText
104 * @see com.sun.star.drawing.XShapeDescriptor
105 * @see com.sun.star.text.XSimpleText
106 * @see com.sun.star.drawing.Shape
107 * @see ifc.style._ParagraphProperties
108 * @see ifc.drawing._LineProperties
109 * @see ifc.drawing._FillProperties
110 * @see ifc.drawing._PolyPolygonDescriptor
111 * @see ifc.drawing._ShadowProperties
112 * @see ifc.drawing._XGluePointsSupplier
113 * @see ifc.style._CharacterProperties
114 * @see ifc.drawing._RotationDescriptor
115 * @see ifc.text._XTextRange
116 * @see ifc.drawing._XShape
117 * @see ifc.lang._XComponent
118 * @see ifc.drawing._TextProperties
119 * @see ifc.beans._XPropertySet
120 * @see ifc.text._XText
121 * @see ifc.drawing._XShapeDescriptor
122 * @see ifc.text._XSimpleText
123 * @see ifc.drawing._Shape
125 public class SvxShapePolyPolygon extends TestCase {
127 static XComponent xDrawDoc;
130 * in general this method creates a testdocument
132 * @param tParam class which contains additional test parameters
133 * @param log class to log the test state and result
136 * @see TestParameters
137 * * @see PrintWriter
140 protected void initialize( TestParameters tParam, PrintWriter log ) {
141 // get a soffice factory object
142 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
144 try {
145 log.println( "creating a chartdocument" );
146 xDrawDoc = SOF.loadDocument(
147 utils.getFullTestURL("SvxShape.sxd"));
148 } catch (com.sun.star.uno.Exception e) {
149 // Some exception occures.FAILED
150 e.printStackTrace( log );
151 throw new StatusException( "Couldn't create document", e );
156 * in general this method disposes the testenvironment and document
158 * @param tParam class which contains additional test parameters
159 * @param log class to log the test state and result
162 * @see TestParameters
163 * * @see PrintWriter
166 protected void cleanup( TestParameters tParam, PrintWriter log ) {
167 log.println( " disposing xDrawDoc " );
168 util.DesktopTools.closeDoc(xDrawDoc);
173 * * creating a Testenvironment for the interfaces to be tested
175 * @param tParam class which contains additional test parameters
176 * @param log class to log the test state and result
178 * @return Status class
180 * @see TestParameters
181 * * @see PrintWriter
183 protected TestEnvironment createTestEnvironment
184 (TestParameters tParam, PrintWriter log) {
186 XInterface oObj = null;
187 XShape oShape = null;
189 // creation of testobject here
190 // first we write what we are intend to do to log file
191 log.println( "creating a test environment" );
193 try {
194 // adding some shapes for testing.
195 //SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
196 //oShape = SOF.createShape(xDrawDoc,6000,6000,5000,5000,"PolyPolygon");
197 XMultiServiceFactory xMSF = (XMultiServiceFactory)
198 UnoRuntime.queryInterface(XMultiServiceFactory.class, xDrawDoc) ;
199 XInterface oInst = (XInterface) xMSF.createInstance
200 ("com.sun.star.drawing.PolyPolygonShape") ;
201 oShape = (XShape) UnoRuntime.queryInterface
202 (XShape.class, oInst) ;
204 oShape.setSize(new Size(0,0)) ;
205 oShape.setPosition(new Point(0,0)) ;
207 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
209 Point[] square1 = new Point[] {
210 new Point(5000, 5000),
211 new Point(10000, 5000),
212 new Point(10000, 10000),
213 new Point(5000, 10000)} ;
215 Point[] square2 = new Point[] {
216 new Point(6500, 6500),
217 new Point(8500, 6500),
218 new Point(8500, 8500),
219 new Point(6500, 8500)} ;
221 Point[][] polygon = new Point[][] {square1, square2};
223 ((XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
224 oShape)).setPropertyValue("PolyPolygon", polygon) ;
226 oObj = oShape ;
228 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ;
229 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Line");
230 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
232 catch (Exception e) {
233 log.println("Couldn't create insance");
234 e.printStackTrace(log);
237 // test environment creation
239 TestEnvironment tEnv = new TestEnvironment(oObj);
241 log.println( "adding two styles as ObjRelation for ShapeDescriptor" );
242 XPropertySet oShapeProps = (XPropertySet)
243 UnoRuntime.queryInterface(XPropertySet.class,oObj);
244 XStyle aStyle = null;
245 try {
246 aStyle = (XStyle) AnyConverter.toObject(
247 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
248 } catch (Exception e) {}
249 tEnv.addObjRelation("Style1",aStyle);
250 oShapeProps = (XPropertySet)
251 UnoRuntime.queryInterface(XPropertySet.class,oShape);
252 try {
253 aStyle = (XStyle) AnyConverter.toObject(
254 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
255 } catch (Exception e) {}
256 tEnv.addObjRelation("Style2",aStyle);
258 // adding relation for XText
259 DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
260 "com.sun.star.text.TextField.URL");
261 log.println( " adding InstCreator object" );
262 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
264 return tEnv;
265 } // finish method getTestEnvironment
267 } // finish class SvxShapeCollection