Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxShapePolyPolygon.java
blobd5a43870a533e0a30a93da63ee0529af98ec5293
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.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.DefaultDsc;
27 import util.DrawTools;
28 import util.InstCreator;
29 import util.SOfficeFactory;
30 import util.utils;
32 import com.sun.star.awt.Point;
33 import com.sun.star.awt.Size;
34 import com.sun.star.beans.XPropertySet;
35 import com.sun.star.drawing.XShape;
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.PolyPolygonShape</code>. <p>
47 * Object implements the following interfaces :
48 * <ul>
49 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
50 * <li> <code>com::sun::star::drawing::LineProperties</code></li>
51 * <li> <code>com::sun::star::drawing::FillProperties</code></li>
52 * <li> <code>com::sun::star::drawing::PolyPolygonDescriptor</code></li>
53 * <li> <code>com::sun::star::drawing::ShadowProperties</code></li>
54 * <li> <code>com::sun::star::drawing::XGluePointsSupplier</code></li>
55 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
56 * <li> <code>com::sun::star::drawing::RotationDescriptor</code></li>
57 * <li> <code>com::sun::star::text::XTextRange</code></li>
58 * <li> <code>com::sun::star::drawing::XShape</code></li>
59 * <li> <code>com::sun::star::lang::XComponent</code></li>
60 * <li> <code>com::sun::star::drawing::TextProperties</code></li>
61 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
62 * <li> <code>com::sun::star::text::XText</code></li>
63 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
64 * <li> <code>com::sun::star::text::XSimpleText</code></li>
65 * <li> <code>com::sun::star::drawing::Shape</code></li>
66 * </ul> <p>
67 * The following files used by this test :
68 * <ul>
69 * <li><b> TransparencyChart.sxs </b> : to load predefined chart
70 * document where two 'automatic' transparency styles exists :
71 * 'Transparency 1' and 'Transparency 2'.</li>
72 * </ul> <p>
74 * This object test <b> is NOT </b> designed to be run in several
75 * threads concurrently.
77 * @see com.sun.star.style.ParagraphProperties
78 * @see com.sun.star.drawing.LineProperties
79 * @see com.sun.star.drawing.FillProperties
80 * @see com.sun.star.drawing.PolyPolygonDescriptor
81 * @see com.sun.star.drawing.ShadowProperties
82 * @see com.sun.star.drawing.XGluePointsSupplier
83 * @see com.sun.star.style.CharacterProperties
84 * @see com.sun.star.drawing.RotationDescriptor
85 * @see com.sun.star.text.XTextRange
86 * @see com.sun.star.drawing.XShape
87 * @see com.sun.star.lang.XComponent
88 * @see com.sun.star.drawing.TextProperties
89 * @see com.sun.star.beans.XPropertySet
90 * @see com.sun.star.text.XText
91 * @see com.sun.star.drawing.XShapeDescriptor
92 * @see com.sun.star.text.XSimpleText
93 * @see com.sun.star.drawing.Shape
94 * @see ifc.style._ParagraphProperties
95 * @see ifc.drawing._LineProperties
96 * @see ifc.drawing._FillProperties
97 * @see ifc.drawing._PolyPolygonDescriptor
98 * @see ifc.drawing._ShadowProperties
99 * @see ifc.drawing._XGluePointsSupplier
100 * @see ifc.style._CharacterProperties
101 * @see ifc.drawing._RotationDescriptor
102 * @see ifc.text._XTextRange
103 * @see ifc.drawing._XShape
104 * @see ifc.lang._XComponent
105 * @see ifc.drawing._TextProperties
106 * @see ifc.beans._XPropertySet
107 * @see ifc.text._XText
108 * @see ifc.drawing._XShapeDescriptor
109 * @see ifc.text._XSimpleText
110 * @see ifc.drawing._Shape
112 public class SvxShapePolyPolygon extends TestCase {
114 static XComponent xDrawDoc;
117 * in general this method creates a testdocument
119 * @param tParam class which contains additional test parameters
120 * @param log class to log the test state and result
123 * @see TestParameters
124 * * @see PrintWriter
127 @Override
128 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
129 // get a soffice factory object
130 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
131 log.println( "creating a chartdocument" );
132 xDrawDoc = SOF.loadDocument(
133 utils.getFullTestURL("SvxShape.sxd"));
137 * in general this method disposes the testenvironment and document
139 * @param tParam class which contains additional test parameters
140 * @param log class to log the test state and result
143 * @see TestParameters
144 * * @see PrintWriter
147 @Override
148 protected void cleanup( TestParameters tParam, PrintWriter log ) {
149 log.println( " disposing xDrawDoc " );
150 util.DesktopTools.closeDoc(xDrawDoc);
155 * * creating a TestEnvironment for the interfaces to be tested
157 * @param tParam class which contains additional test parameters
158 * @param log class to log the test state and result
160 * @return Status class
162 * @see TestParameters
163 * * @see PrintWriter
165 @Override
166 protected TestEnvironment createTestEnvironment
167 (TestParameters tParam, PrintWriter log) {
169 XInterface oObj = null;
170 XShape oShape = null;
172 // creation of testobject here
173 // first we write what we are intend to do to log file
174 log.println( "creating a test environment" );
176 try {
177 // adding some shapes for testing.
178 XMultiServiceFactory xMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xDrawDoc) ;
179 XInterface oInst = (XInterface) xMSF.createInstance
180 ("com.sun.star.drawing.PolyPolygonShape") ;
181 oShape = UnoRuntime.queryInterface
182 (XShape.class, oInst) ;
184 oShape.setSize(new Size(0,0)) ;
185 oShape.setPosition(new Point(0,0)) ;
187 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
189 Point[] square1 = new Point[] {
190 new Point(5000, 5000),
191 new Point(10000, 5000),
192 new Point(10000, 10000),
193 new Point(5000, 10000)} ;
195 Point[] square2 = new Point[] {
196 new Point(6500, 6500),
197 new Point(8500, 6500),
198 new Point(8500, 8500),
199 new Point(6500, 8500)} ;
201 Point[][] polygon = new Point[][] {square1, square2};
203 UnoRuntime.queryInterface(XPropertySet.class,
204 oShape).setPropertyValue("PolyPolygon", polygon) ;
206 oObj = oShape ;
208 SOfficeFactory SOF = SOfficeFactory.getFactory(tParam.getMSF()) ;
209 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Line");
210 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
212 catch (Exception e) {
213 log.println("Couldn't create instance");
214 e.printStackTrace(log);
217 // test environment creation
219 TestEnvironment tEnv = new TestEnvironment(oObj);
221 log.println( "adding two styles as ObjRelation for ShapeDescriptor" );
222 XPropertySet oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oObj);
223 XStyle aStyle = null;
224 try {
225 aStyle = (XStyle) AnyConverter.toObject(
226 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
227 } catch (Exception e) {
228 System.out.println("caught exception: " + e);
230 tEnv.addObjRelation("Style1",aStyle);
231 oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oShape);
232 try {
233 aStyle = (XStyle) AnyConverter.toObject(
234 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
235 } catch (Exception e) {
236 System.out.println("caught exception: " + e);
238 tEnv.addObjRelation("Style2",aStyle);
240 // adding relation for XText
241 DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
242 "com.sun.star.text.TextField.URL");
243 log.println( " adding InstCreator object" );
244 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
246 return tEnv;
247 } // finish method getTestEnvironment
249 } // finish class SvxShapeCollection