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