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.beans.XPropertySet;
39 import com.sun.star.drawing.XShape;
40 import com.sun.star.lang.XComponent;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.style.XStyle;
43 import com.sun.star.uno.AnyConverter;
44 import com.sun.star.uno.Type;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
47 
48 /**
49  * Test for object which is represented by service
50  * <code>com.sun.star.drawing.EllipseShape</code>. <p>
51  * Object implements the following interfaces :
52  * <ul>
53  *  <li> <code>com::sun::star::style::ParagraphProperties</code></li>
54  *  <li> <code>com::sun::star::drawing::LineProperties</code></li>
55  *  <li> <code>com::sun::star::drawing::EllipseShape</code></li>
56  *  <li> <code>com::sun::star::drawing::FillProperties</code></li>
57  *  <li> <code>com::sun::star::drawing::ShadowProperties</code></li>
58  *  <li> <code>com::sun::star::drawing::XGluePointsSupplier</code></li>
59  *  <li> <code>com::sun::star::style::CharacterProperties</code></li>
60  *  <li> <code>com::sun::star::drawing::RotationDescriptor</code></li>
61  *  <li> <code>com::sun::star::text::XTextRange</code></li>
62  *  <li> <code>com::sun::star::drawing::XShape</code></li>
63  *  <li> <code>com::sun::star::lang::XComponent</code></li>
64  *  <li> <code>com::sun::star::drawing::TextProperties</code></li>
65  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
66  *  <li> <code>com::sun::star::text::XText</code></li>
67  *  <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
68  *  <li> <code>com::sun::star::text::XSimpleText</code></li>
69  *  <li> <code>com::sun::star::drawing::Shape</code></li>
70  * </ul> <p>
71  * The following files used by this test :
72  * <ul>
73  *  <li><b> SvxShape.sxd </b> : this document is loaded for
74  *  adding a shape tested to it. </li>
75  * </ul> <p>
76  * This object test <b> is NOT </b> designed to be run in several
77  * threads concurently.
78  *
79  * @see com.sun.star.style.ParagraphProperties
80  * @see com.sun.star.drawing.LineProperties
81  * @see com.sun.star.drawing.EllipseShape
82  * @see com.sun.star.drawing.FillProperties
83  * @see com.sun.star.drawing.ShadowProperties
84  * @see com.sun.star.drawing.XGluePointsSupplier
85  * @see com.sun.star.style.CharacterProperties
86  * @see com.sun.star.drawing.RotationDescriptor
87  * @see com.sun.star.text.XTextRange
88  * @see com.sun.star.drawing.XShape
89  * @see com.sun.star.lang.XComponent
90  * @see com.sun.star.drawing.TextProperties
91  * @see com.sun.star.beans.XPropertySet
92  * @see com.sun.star.text.XText
93  * @see com.sun.star.drawing.XShapeDescriptor
94  * @see com.sun.star.text.XSimpleText
95  * @see com.sun.star.drawing.Shape
96  * @see ifc.style._ParagraphProperties
97  * @see ifc.drawing._LineProperties
98  * @see ifc.drawing._EllipseShape
99  * @see ifc.drawing._FillProperties
100  * @see ifc.drawing._ShadowProperties
101  * @see ifc.drawing._XGluePointsSupplier
102  * @see ifc.style._CharacterProperties
103  * @see ifc.drawing._RotationDescriptor
104  * @see ifc.text._XTextRange
105  * @see ifc.drawing._XShape
106  * @see ifc.lang._XComponent
107  * @see ifc.drawing._TextProperties
108  * @see ifc.beans._XPropertySet
109  * @see ifc.text._XText
110  * @see ifc.drawing._XShapeDescriptor
111  * @see ifc.text._XSimpleText
112  * @see ifc.drawing._Shape
113  */
114 public class SvxShapeCircle extends TestCase {
115 
116     static XComponent xDrawDoc;
117 
118     /**
119      * Loads a Draw document with name 'SvxShape.sxd' from test
120      * documents directory
121      */
initialize( TestParameters tParam, PrintWriter log )122     protected void initialize( TestParameters tParam, PrintWriter log ) {
123 
124         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
125 
126         try {
127             log.println( "creating a drawdoc" );
128             xDrawDoc = SOF.loadDocument(
129                              utils.getFullTestURL("SvxShape.sxd"));
130         } catch ( com.sun.star.uno.Exception e ) {
131             // Some exception occured.FAILED
132             e.printStackTrace( log );
133             throw new StatusException( "Couldn't create document", e );
134         }
135     }
136 
137     /**
138      * Disposes the Draw document loaded before.
139      */
cleanup( TestParameters tParam, PrintWriter log )140     protected void cleanup( TestParameters tParam, PrintWriter log ) {
141         log.println( "    disposing xDrawDoc " );
142         util.DesktopTools.closeDoc(xDrawDoc);
143     }
144 
145 
146     /**
147      * Creating a Testenvironment for the interfaces to be tested.
148      * Creates an instance of the service
149      * <code>com.sun.star.drawing.EllipseShape</code> as tested component
150      * and adds it to the document. Then the FULL type of circle is set.
151      *
152      *     Object relations created :
153      * <ul>
154      *  <li> <code>'Style1', 'Style2'</code> for
155      *      {@link ifc.drawing._Shape} :
156      *       two values of 'Style' property. The first is taken
157      *       from the shape tested, the second from another
158      *       shape added to the draw page. </li>
159      *  <li> <code>'XTEXTINFO'</code> for
160      *      {@link ifc.text._XText} :
161      *      creator which can create instnaces of
162      *      <code>com.sun.star.text.TextField.URL</code>
163      *      service. </li>
164      * </ul>
165      */
createTestEnvironment(TestParameters tParam, PrintWriter log)166     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
167 
168         XInterface oObj = null;
169         XShape oShape = null;
170 
171         // creation of testobject here
172         // first we write what we are intend to do to log file
173         log.println( "creating a test environment" );
174 
175         SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ;
176         oShape = SOF.createShape(xDrawDoc,5000,5000,3000,3000,"Ellipse");
177 
178         XPropertySet props = (XPropertySet) UnoRuntime.queryInterface
179             (XPropertySet.class, oShape) ;
180 
181         DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
182         try {
183             props.setPropertyValue("CircleKind",
184                 com.sun.star.drawing.CircleKind.FULL) ;
185         } catch (com.sun.star.lang.WrappedTargetException e) {
186             log.println("Cann't set 'CircleKind' property : " + e);
187             throw new StatusException("Can't create component", e) ;
188         } catch (com.sun.star.lang.IllegalArgumentException e) {
189             log.println("Cann't set 'CircleKind' property : " + e);
190             throw new StatusException("Can't create component", e) ;
191         } catch (com.sun.star.beans.PropertyVetoException e) {
192             log.println("Cann't set 'CircleKind' property : " + e);
193             throw new StatusException("Can't create component", e) ;
194         } catch (com.sun.star.beans.UnknownPropertyException e) {
195             log.println("Cann't set 'CircleKind' property : " + e);
196             throw new StatusException("Can't create component", e) ;
197         }
198 
199 
200         oObj = oShape ;
201 
202         oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Line");
203         DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
204 
205         // test environment creation
206 
207         TestEnvironment tEnv = new TestEnvironment(oObj);
208 
209         log.println( "adding two styles as ObjRelation for ShapeDescriptor" );
210         XPropertySet oShapeProps = (XPropertySet)
211                             UnoRuntime.queryInterface(XPropertySet.class,oObj);
212         XStyle aStyle = null;
213 
214         try {
215             aStyle = (XStyle) AnyConverter.toObject(
216                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
217         } catch (com.sun.star.lang.WrappedTargetException e) {
218         } catch (com.sun.star.beans.UnknownPropertyException e) {
219         } catch (com.sun.star.lang.IllegalArgumentException e) {
220         }
221 
222         tEnv.addObjRelation("Style1",aStyle);
223         oShapeProps = (XPropertySet)
224             UnoRuntime.queryInterface(XPropertySet.class,oShape);
225         try {
226             aStyle = (XStyle) AnyConverter.toObject(
227                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
228         } catch (com.sun.star.lang.WrappedTargetException e) {
229         } catch (com.sun.star.beans.UnknownPropertyException e) {
230         } catch (com.sun.star.lang.IllegalArgumentException e) {
231         }
232 
233         tEnv.addObjRelation("Style2",aStyle);
234 
235         DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
236                                             "com.sun.star.text.TextField.URL");
237         log.println( "    adding InstCreator object" );
238         tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
239 
240         return tEnv;
241     } // finish method getTestEnvironment
242 
243 }    // finish class SvxShapeCircle
244