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