merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _svx / SvxShapePolyPolygonBezier.java
blob14e0d676a9a86d486144e25030124e2893004ff6
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: SvxShapePolyPolygonBezier.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.DrawTools;
40 import util.InstCreator;
41 import util.SOfficeFactory;
42 import util.utils;
44 import com.sun.star.awt.Point;
45 import com.sun.star.awt.Size;
46 import com.sun.star.beans.XPropertySet;
47 import com.sun.star.drawing.PolyPolygonBezierCoords;
48 import com.sun.star.drawing.PolygonFlags;
49 import com.sun.star.drawing.XShape;
50 import com.sun.star.lang.XComponent;
51 import com.sun.star.lang.XMultiServiceFactory;
52 import com.sun.star.style.XStyle;
53 import com.sun.star.uno.AnyConverter;
54 import com.sun.star.uno.Type;
55 import com.sun.star.uno.UnoRuntime;
56 import com.sun.star.uno.XInterface;
58 /**
59 * Test for object which is represented by service
60 * <code>com.sun.star.drawing.ClosedBezierShape</code>. <p>
61 * Object implements the following interfaces :
62 * <ul>
63 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
64 * <li> <code>com::sun::star::drawing::PolyPolygonBezierDescriptor</code></li>
65 * <li> <code>com::sun::star::drawing::LineProperties</code></li>
66 * <li> <code>com::sun::star::drawing::FillProperties</code></li>
67 * <li> <code>com::sun::star::drawing::ShadowProperties</code></li>
68 * <li> <code>com::sun::star::drawing::XGluePointsSupplier</code></li>
69 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
70 * <li> <code>com::sun::star::drawing::RotationDescriptor</code></li>
71 * <li> <code>com::sun::star::text::XTextRange</code></li>
72 * <li> <code>com::sun::star::drawing::XShape</code></li>
73 * <li> <code>com::sun::star::lang::XComponent</code></li>
74 * <li> <code>com::sun::star::drawing::TextProperties</code></li>
75 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
76 * <li> <code>com::sun::star::text::XText</code></li>
77 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
78 * <li> <code>com::sun::star::text::XSimpleText</code></li>
79 * <li> <code>com::sun::star::drawing::Shape</code></li>
80 * </ul> <p>
82 * The following files used by this test :
83 * <ul>
84 * <li><b> TransparencyChart.sxs </b> : to load predefined chart
85 * document where two 'automatic' transparency styles exists :
86 * 'Transparency 1' and 'Transparency 2'.</li>
87 * </ul> <p>
89 * This object test <b> is NOT </b> designed to be run in several
90 * threads concurently.
92 * @see com.sun.star.style.ParagraphProperties
93 * @see com.sun.star.drawing.PolyPolygonBezierDescriptor
94 * @see com.sun.star.drawing.LineProperties
95 * @see com.sun.star.drawing.FillProperties
96 * @see com.sun.star.drawing.ShadowProperties
97 * @see com.sun.star.drawing.XGluePointsSupplier
98 * @see com.sun.star.style.CharacterProperties
99 * @see com.sun.star.drawing.RotationDescriptor
100 * @see com.sun.star.text.XTextRange
101 * @see com.sun.star.drawing.XShape
102 * @see com.sun.star.lang.XComponent
103 * @see com.sun.star.drawing.TextProperties
104 * @see com.sun.star.beans.XPropertySet
105 * @see com.sun.star.text.XText
106 * @see com.sun.star.drawing.XShapeDescriptor
107 * @see com.sun.star.text.XSimpleText
108 * @see com.sun.star.drawing.Shape
109 * @see ifc.style._ParagraphProperties
110 * @see ifc.drawing._PolyPolygonBezierDescriptor
111 * @see ifc.drawing._LineProperties
112 * @see ifc.drawing._FillProperties
113 * @see ifc.drawing._ShadowProperties
114 * @see ifc.drawing._XGluePointsSupplier
115 * @see ifc.style._CharacterProperties
116 * @see ifc.drawing._RotationDescriptor
117 * @see ifc.text._XTextRange
118 * @see ifc.drawing._XShape
119 * @see ifc.lang._XComponent
120 * @see ifc.drawing._TextProperties
121 * @see ifc.beans._XPropertySet
122 * @see ifc.text._XText
123 * @see ifc.drawing._XShapeDescriptor
124 * @see ifc.text._XSimpleText
125 * @see ifc.drawing._Shape
127 public class SvxShapePolyPolygonBezier extends TestCase {
129 static XComponent xDrawDoc;
132 * in general this method creates a testdocument
134 * @param tParam class which contains additional test parameters
135 * @param log class to log the test state and result
138 * @see TestParameters
139 * * @see PrintWriter
142 protected void initialize( TestParameters tParam, PrintWriter log ) {
143 // get a soffice factory object
144 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
146 try {
147 log.println( "creating a chartdocument" );
148 xDrawDoc = SOF.loadDocument(
149 utils.getFullTestURL("SvxShape.sxd"));
150 } catch (com.sun.star.uno.Exception e) {
151 // Some exception occures.FAILED
152 e.printStackTrace( log );
153 throw new StatusException( "Couldn't create document", e );
158 * in general this method disposes the testenvironment and document
160 * @param tParam class which contains additional test parameters
161 * @param log class to log the test state and result
164 * @see TestParameters
165 * * @see PrintWriter
168 protected void cleanup( TestParameters tParam, PrintWriter log ) {
169 log.println( " disposing xDrawDoc " );
170 util.DesktopTools.closeDoc(xDrawDoc);
175 * * creating a Testenvironment for the interfaces to be tested
177 * @param tParam class which contains additional test parameters
178 * @param log class to log the test state and result
180 * @return Status class
182 * @see TestParameters
183 * * @see PrintWriter
185 protected TestEnvironment createTestEnvironment
186 (TestParameters tParam, PrintWriter log) {
188 XInterface oObj = null;
189 XShape oShape = null;
191 // creation of testobject here
192 // first we write what we are intend to do to log file
193 log.println( "creating a test environment" );
195 try {
197 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
199 XMultiServiceFactory xMSF = (XMultiServiceFactory)
200 UnoRuntime.queryInterface(XMultiServiceFactory.class, xDrawDoc) ;
202 XInterface oInst = (XInterface) xMSF.createInstance
203 ("com.sun.star.drawing.ClosedBezierShape") ;
204 oShape = (XShape) UnoRuntime.queryInterface
205 (XShape.class, oInst) ;
207 Point[] points = new Point[2];
208 points[0] = new Point();
209 points[0].X = 50;
210 points[0].Y = 50;
211 points[1] = new Point();
212 points[1].X = 5000;
213 points[1].Y = 5000;
215 Point[][] the_points = new Point[1][2];
216 the_points[0] = points;
218 PolygonFlags[] flags = new PolygonFlags[2];
219 flags[0] = PolygonFlags.NORMAL;
220 flags[1] = PolygonFlags.NORMAL;
222 PolygonFlags[][] the_flags = new PolygonFlags[1][2];
223 the_flags[0] = flags;
225 PolyPolygonBezierCoords coords = new PolyPolygonBezierCoords();
226 coords.Coordinates=the_points;
227 coords.Flags = the_flags;
229 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
231 oShape.setSize(new Size(3000,3000)) ;
232 oShape.setPosition(new Point(4000,4000)) ;
234 oObj = oShape ;
236 XPropertySet shapeProps = (XPropertySet) UnoRuntime.queryInterface
237 (XPropertySet.class, oObj);
239 shapeProps.setPropertyValue("PolyPolygonBezier",coords);
241 //SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ;
242 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Line");
243 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
245 catch (Exception e) {
246 log.println("Couldn't create instance");
247 e.printStackTrace(log);
250 // test environment creation
252 TestEnvironment tEnv = new TestEnvironment(oObj);
254 log.println( "adding two styles as ObjRelation for ShapeDescriptor" );
255 XPropertySet oShapeProps = (XPropertySet)
256 UnoRuntime.queryInterface(XPropertySet.class,oObj);
257 XStyle aStyle = null;
258 try {
259 aStyle = (XStyle) AnyConverter.toObject(
260 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
261 } catch (Exception e) {}
262 tEnv.addObjRelation("Style1",aStyle);
263 oShapeProps = (XPropertySet)
264 UnoRuntime.queryInterface(XPropertySet.class,oShape);
265 try {
266 aStyle = (XStyle) AnyConverter.toObject(
267 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
268 } catch (Exception e) {}
269 tEnv.addObjRelation("Style2",aStyle);
271 // adding relation for XText
272 util.DefaultDsc tDsc = new util.DefaultDsc
273 ("com.sun.star.text.XTextContent",
274 "com.sun.star.text.TextField.URL");
275 log.println( " adding InstCreator object" );
276 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
278 return tEnv;
279 } // finish method getTestEnvironment
281 } // finish class SvxShapePolyPolygonBezier