1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._svx;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.DefaultDsc;
33 import util.DrawTools;
34 import util.InstCreator;
35 import util.SOfficeFactory;
36 import util.utils;
37 
38 import com.sun.star.awt.Point;
39 import com.sun.star.awt.Size;
40 import com.sun.star.beans.XPropertySet;
41 import com.sun.star.drawing.XShape;
42 import com.sun.star.lang.XComponent;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.style.XStyle;
45 import com.sun.star.uno.AnyConverter;
46 import com.sun.star.uno.Type;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 
50 /**
51  * Test for object which is represented by service
52  * <code>com.sun.star.drawing.PolyPolygonShape</code>. <p>
53  * Object implements the following interfaces :
54  * <ul>
55  *  <li> <code>com::sun::star::style::ParagraphProperties</code></li>
56  *  <li> <code>com::sun::star::drawing::LineProperties</code></li>
57  *  <li> <code>com::sun::star::drawing::FillProperties</code></li>
58  *  <li> <code>com::sun::star::drawing::PolyPolygonDescriptor</code></li>
59  *  <li> <code>com::sun::star::drawing::ShadowProperties</code></li>
60  *  <li> <code>com::sun::star::drawing::XGluePointsSupplier</code></li>
61  *  <li> <code>com::sun::star::style::CharacterProperties</code></li>
62  *  <li> <code>com::sun::star::drawing::RotationDescriptor</code></li>
63  *  <li> <code>com::sun::star::text::XTextRange</code></li>
64  *  <li> <code>com::sun::star::drawing::XShape</code></li>
65  *  <li> <code>com::sun::star::lang::XComponent</code></li>
66  *  <li> <code>com::sun::star::drawing::TextProperties</code></li>
67  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
68  *  <li> <code>com::sun::star::text::XText</code></li>
69  *  <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
70  *  <li> <code>com::sun::star::text::XSimpleText</code></li>
71  *  <li> <code>com::sun::star::drawing::Shape</code></li>
72  * </ul> <p>
73  * The following files used by this test :
74  * <ul>
75  *  <li><b> TransparencyChart.sxs </b> : to load predefined chart
76  *       document where two 'automatic' transparency styles exists :
77  *       'Transparency 1' and 'Transparency 2'.</li>
78  * </ul> <p>
79  *
80  * This object test <b> is NOT </b> designed to be run in several
81  * threads concurently.
82  *
83  * @see com.sun.star.style.ParagraphProperties
84  * @see com.sun.star.drawing.LineProperties
85  * @see com.sun.star.drawing.FillProperties
86  * @see com.sun.star.drawing.PolyPolygonDescriptor
87  * @see com.sun.star.drawing.ShadowProperties
88  * @see com.sun.star.drawing.XGluePointsSupplier
89  * @see com.sun.star.style.CharacterProperties
90  * @see com.sun.star.drawing.RotationDescriptor
91  * @see com.sun.star.text.XTextRange
92  * @see com.sun.star.drawing.XShape
93  * @see com.sun.star.lang.XComponent
94  * @see com.sun.star.drawing.TextProperties
95  * @see com.sun.star.beans.XPropertySet
96  * @see com.sun.star.text.XText
97  * @see com.sun.star.drawing.XShapeDescriptor
98  * @see com.sun.star.text.XSimpleText
99  * @see com.sun.star.drawing.Shape
100  * @see ifc.style._ParagraphProperties
101  * @see ifc.drawing._LineProperties
102  * @see ifc.drawing._FillProperties
103  * @see ifc.drawing._PolyPolygonDescriptor
104  * @see ifc.drawing._ShadowProperties
105  * @see ifc.drawing._XGluePointsSupplier
106  * @see ifc.style._CharacterProperties
107  * @see ifc.drawing._RotationDescriptor
108  * @see ifc.text._XTextRange
109  * @see ifc.drawing._XShape
110  * @see ifc.lang._XComponent
111  * @see ifc.drawing._TextProperties
112  * @see ifc.beans._XPropertySet
113  * @see ifc.text._XText
114  * @see ifc.drawing._XShapeDescriptor
115  * @see ifc.text._XSimpleText
116  * @see ifc.drawing._Shape
117  */
118 public class SvxShapePolyPolygon extends TestCase {
119 
120     static XComponent xDrawDoc;
121 
122     /**
123      * in general this method creates a testdocument
124      *
125      *  @param tParam    class which contains additional test parameters
126      *  @param log        class to log the test state and result
127      *
128      *
129      *  @see TestParameters
130      *  *    @see PrintWriter
131      *
132      */
initialize( TestParameters tParam, PrintWriter log )133     protected void initialize( TestParameters tParam, PrintWriter log ) {
134         // get a soffice factory object
135         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
136 
137         try {
138             log.println( "creating a chartdocument" );
139             xDrawDoc = SOF.loadDocument(
140                              utils.getFullTestURL("SvxShape.sxd"));
141         } catch (com.sun.star.uno.Exception e) {
142             // Some exception occured.FAILED
143             e.printStackTrace( log );
144             throw new StatusException( "Couldn't create document", e );
145         }
146     }
147 
148     /**
149      * in general this method disposes the testenvironment and document
150      *
151      *  @param tParam    class which contains additional test parameters
152      *  @param log        class to log the test state and result
153      *
154      *
155      *  @see TestParameters
156      *  *    @see PrintWriter
157      *
158      */
cleanup( TestParameters tParam, PrintWriter log )159     protected void cleanup( TestParameters tParam, PrintWriter log ) {
160         log.println( "    disposing xDrawDoc " );
161         util.DesktopTools.closeDoc(xDrawDoc);
162     }
163 
164 
165     /**
166      *  *    creating a Testenvironment for the interfaces to be tested
167      *
168      *  @param tParam    class which contains additional test parameters
169      *  @param log        class to log the test state and result
170      *
171      *  @return    Status class
172      *
173      *  @see TestParameters
174      *  *    @see PrintWriter
175      */
createTestEnvironment(TestParameters tParam, PrintWriter log)176     protected TestEnvironment createTestEnvironment
177             (TestParameters tParam, PrintWriter log) {
178 
179         XInterface oObj = null;
180         XShape oShape = null;
181 
182         // creation of testobject here
183         // first we write what we are intend to do to log file
184         log.println( "creating a test environment" );
185 
186         try {
187             // adding some shapes for testing.
188             //SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
189             //oShape = SOF.createShape(xDrawDoc,6000,6000,5000,5000,"PolyPolygon");
190             XMultiServiceFactory xMSF = (XMultiServiceFactory)
191                 UnoRuntime.queryInterface(XMultiServiceFactory.class, xDrawDoc) ;
192             XInterface oInst = (XInterface) xMSF.createInstance
193                 ("com.sun.star.drawing.PolyPolygonShape") ;
194             oShape = (XShape) UnoRuntime.queryInterface
195                 (XShape.class, oInst) ;
196 
197             oShape.setSize(new Size(0,0)) ;
198             oShape.setPosition(new Point(0,0)) ;
199 
200             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
201 
202             Point[] square1 = new Point[] {
203                 new Point(5000, 5000),
204                 new Point(10000, 5000),
205                 new Point(10000, 10000),
206                 new Point(5000, 10000)} ;
207 
208             Point[] square2 = new Point[] {
209                 new Point(6500, 6500),
210                 new Point(8500, 6500),
211                 new Point(8500, 8500),
212                 new Point(6500, 8500)} ;
213 
214             Point[][] polygon = new Point[][] {square1, square2};
215 
216             ((XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
217                 oShape)).setPropertyValue("PolyPolygon", polygon) ;
218 
219             oObj = oShape ;
220 
221             SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ;
222             oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Line");
223             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
224         }
225         catch (Exception e) {
226             log.println("Couldn't create insance");
227             e.printStackTrace(log);
228         }
229 
230         // test environment creation
231 
232         TestEnvironment tEnv = new TestEnvironment(oObj);
233 
234         log.println( "adding two styles as ObjRelation for ShapeDescriptor" );
235         XPropertySet oShapeProps = (XPropertySet)
236                             UnoRuntime.queryInterface(XPropertySet.class,oObj);
237         XStyle aStyle = null;
238         try {
239             aStyle = (XStyle) AnyConverter.toObject(
240                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
241         } catch (Exception e) {}
242         tEnv.addObjRelation("Style1",aStyle);
243         oShapeProps = (XPropertySet)
244             UnoRuntime.queryInterface(XPropertySet.class,oShape);
245         try {
246             aStyle = (XStyle) AnyConverter.toObject(
247                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
248         } catch (Exception e) {}
249         tEnv.addObjRelation("Style2",aStyle);
250 
251         // adding relation for XText
252         DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
253                                             "com.sun.star.text.TextField.URL");
254         log.println( "    adding InstCreator object" );
255         tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
256 
257         return tEnv;
258     } // finish method getTestEnvironment
259 
260 }    // finish class SvxShapeCollection
261 
262