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.TestCase;
29 import lib.TestEnvironment;
30 import lib.TestParameters;
31 import util.DefaultDsc;
32 import util.DrawTools;
33 import util.InstCreator;
34 import util.SOfficeFactory;
35 
36 import com.sun.star.awt.XBitmap;
37 import com.sun.star.beans.XPropertySet;
38 import com.sun.star.drawing.XShape;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.style.XStyle;
42 import com.sun.star.uno.AnyConverter;
43 import com.sun.star.uno.Type;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 
47 /**
48  * Test for object which is represented by service
49  * <code>com.sun.star.drawing.GraphicObject</code>. <p>
50  * Object implements the following interfaces :
51  * <ul>
52  *  <li> <code>com::sun::star::drawing::ShadowProperties</code></li>
53  *  <li> <code>com::sun::star::drawing::RotationDescriptor</code></li>
54  *  <li> <code>com::sun::star::text::XSimpleText</code></li>
55  *  <li> <code>com::sun::star::drawing::XShape</code></li>
56  *  <li> <code>com::sun::star::drawing::GraphicObjectShape</code></li>
57  *  <li> <code>com::sun::star::drawing::Shape</code></li>
58  *  <li> <code>com::sun::star::text::XTextRange</code></li>
59  *  <li> <code>com::sun::star::drawing::XGluePointsSupplier</code></li>
60  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
61  *  <li> <code>com::sun::star::drawing::TextProperties</code></li>
62  *  <li> <code>com::sun::star::style::CharacterProperties</code></li>
63  *  <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
64  *  <li> <code>com::sun::star::style::ParagraphProperties</code></li>
65  *  <li> <code>com::sun::star::text::XText</code></li>
66  *  <li> <code>com::sun::star::lang::XComponent</code></li>
67  * </ul> <p>
68  *
69  * This object test <b> is NOT </b> designed to be run in several
70  * threads concurently.
71  *
72  * @see com.sun.star.drawing.ShadowProperties
73  * @see com.sun.star.drawing.RotationDescriptor
74  * @see com.sun.star.text.XSimpleText
75  * @see com.sun.star.drawing.XShape
76  * @see com.sun.star.drawing.GraphicObjectShape
77  * @see com.sun.star.drawing.Shape
78  * @see com.sun.star.text.XTextRange
79  * @see com.sun.star.drawing.XGluePointsSupplier
80  * @see com.sun.star.beans.XPropertySet
81  * @see com.sun.star.drawing.TextProperties
82  * @see com.sun.star.style.CharacterProperties
83  * @see com.sun.star.drawing.XShapeDescriptor
84  * @see com.sun.star.style.ParagraphProperties
85  * @see com.sun.star.text.XText
86  * @see com.sun.star.lang.XComponent
87  * @see ifc.drawing._ShadowProperties
88  * @see ifc.drawing._RotationDescriptor
89  * @see ifc.text._XSimpleText
90  * @see ifc.drawing._XShape
91  * @see ifc.drawing._GraphicObjectShape
92  * @see ifc.drawing._Shape
93  * @see ifc.text._XTextRange
94  * @see ifc.drawing._XGluePointsSupplier
95  * @see ifc.beans._XPropertySet
96  * @see ifc.drawing._TextProperties
97  * @see ifc.style._CharacterProperties
98  * @see ifc.drawing._XShapeDescriptor
99  * @see ifc.style._ParagraphProperties
100  * @see ifc.text._XText
101  * @see ifc.lang._XComponent
102  */
103 public class SvxGraphicObject extends TestCase {
104 
105     static XComponent xDrawDoc;
106 
107     /**
108      * Creates a new Draw document.
109      */
initialize( TestParameters tParam, PrintWriter log )110     protected void initialize( TestParameters tParam, PrintWriter log ) {
111 
112         log.println( "creating a drawdoc" );
113         xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF());
114     }
115 
116     /**
117      * Disposes the Draw document created before
118      */
cleanup( TestParameters tParam, PrintWriter log )119     protected void cleanup( TestParameters tParam, PrintWriter log ) {
120         log.println( "    disposing xDrawDoc " );
121         util.DesktopTools.closeDoc(xDrawDoc);
122     }
123 
124     /**
125      * Creating a Testenvironment for the interfaces to be tested.
126      * Creates an instance of the service
127      * <code>com.sun.star.drawing.GraphicObject</code> as a tested
128      * component and inserts it to one of draw pages of the document.
129      * <p>
130      *
131      *     Object relations created :
132      * <ul>
133      *  <li> <code>'Style1', 'Style2'</code> for
134      *      {@link ifc.drawing._Shape} :
135      *       two values of 'Style' property. The first is taken
136      *       from the shape tested, the second from another
137      *       shape added to the draw page. </li>
138      *  <li> <code>'Bitmap1', 'Bitmap2'</code> for
139      *      {@link ifc.drawing._GraphicObjectShape} :</li>
140      *      two bitmap objects which are created by setting
141      *      'GraphicURL' property of component tested and
142      *      getting its 'GraphicObjectFillBitmap' property.
143      *  <li> <code>'IMAP'</code> for
144      *      {@link ifc.drawing._GraphicObjectShape} :
145      *      <code>com.sun.star.image.ImageMapRectangleObject</code>
146      *      service instance. </li>
147      *  <li> <code>'XTEXTINFO'</code> for
148      *      {@link ifc.text._XText} :
149      *      creator which can create instnaces of
150      *      <code>com.sun.star.text.TextField.URL</code>
151      *      service. </li>
152      * </ul>
153      */
createTestEnvironment(TestParameters tParam, PrintWriter log)154     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
155 
156         XInterface oObj = null;
157         XShape oShape = null;
158         Object imap=null;
159 
160         // creation of testobject here
161         // first we write what we are intend to do to log file
162         log.println( "creating a test environment" );
163 
164         // create testobject here
165         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
166         oShape = SOF.createShape(xDrawDoc,5000,5000,1500,1000,"GraphicObject");
167         DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
168         oObj = oShape;
169 
170         TestEnvironment tEnv = new TestEnvironment( oShape );
171 
172         // adding two styles as ObjRelation for Shape
173         oShape = SOF.createShape(xDrawDoc,3000,4500,15000,1000,"Ellipse");
174         DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
175 
176         XPropertySet oShapeProps = (XPropertySet)
177                             UnoRuntime.queryInterface(XPropertySet.class,oObj);
178         XStyle aStyle = null;
179         try {
180             aStyle = (XStyle) AnyConverter.toObject(
181                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
182         } catch (com.sun.star.lang.WrappedTargetException e) {
183         } catch (com.sun.star.beans.UnknownPropertyException e) {
184         } catch (com.sun.star.lang.IllegalArgumentException e) {
185         }
186         tEnv.addObjRelation("Style1",aStyle);
187 
188         oShapeProps = (XPropertySet)
189                             UnoRuntime.queryInterface(XPropertySet.class,oShape);
190         try {
191             aStyle = (XStyle) AnyConverter.toObject(
192                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
193         } catch (com.sun.star.lang.WrappedTargetException e) {
194         } catch (com.sun.star.beans.UnknownPropertyException e) {
195         } catch (com.sun.star.lang.IllegalArgumentException e) {
196         }
197         tEnv.addObjRelation("Style2",aStyle);
198 
199 
200         // adding graphic as ObjRelation for GraphicObjectShape
201         oShapeProps = (XPropertySet)
202                             UnoRuntime.queryInterface(XPropertySet.class,oObj);
203         XBitmap aBitmap = null;
204         try {
205             oShapeProps.setPropertyValue(
206                 "GraphicURL",util.utils.getFullTestURL("space-metal.jpg"));
207             aBitmap = (XBitmap) AnyConverter.toObject(
208                 new Type(XBitmap.class),oShapeProps.getPropertyValue
209                     ("GraphicObjectFillBitmap"));
210         } catch (com.sun.star.lang.WrappedTargetException e) {
211         } catch (com.sun.star.lang.IllegalArgumentException e) {
212         } catch (com.sun.star.beans.PropertyVetoException e) {
213         } catch (com.sun.star.beans.UnknownPropertyException e) {
214         }
215 
216 
217         tEnv.addObjRelation("Bitmap1",aBitmap);
218 
219         try {
220              oShapeProps.setPropertyValue(
221                 "GraphicURL",util.utils.getFullTestURL("crazy-blue.jpg"));
222             aBitmap = (XBitmap) AnyConverter.toObject(
223                 new Type(XBitmap.class),oShapeProps.getPropertyValue
224                     ("GraphicObjectFillBitmap"));
225         } catch (com.sun.star.lang.WrappedTargetException e) {
226         } catch (com.sun.star.lang.IllegalArgumentException e) {
227         } catch (com.sun.star.beans.PropertyVetoException e) {
228         } catch (com.sun.star.beans.UnknownPropertyException e) {
229         }
230 
231         tEnv.addObjRelation("Bitmap2",aBitmap);
232 
233         try {
234             XMultiServiceFactory oDocMSF = (XMultiServiceFactory)
235                 UnoRuntime.queryInterface(XMultiServiceFactory.class,xDrawDoc);
236             imap = oDocMSF.createInstance
237                 ( "com.sun.star.image.ImageMapRectangleObject" );
238         } catch (com.sun.star.uno.Exception e) {
239             log.println("Couldn't create instance");
240             e.printStackTrace(log);
241         }
242 
243 
244         tEnv.addObjRelation("IMAP",imap);
245         tEnv.addObjRelation("ImapObject",imap);
246 
247         // adding relation for XText interface
248         DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
249                                             "com.sun.star.text.TextField.URL");
250         log.println( "    adding InstCreator object" );
251         tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
252 
253         tEnv.addObjRelation("NoShear",new Boolean(true));
254 
255         return tEnv;
256 
257     } // finish method getTestEnvironment
258 
259 }    // finish class SvxGraphicObject
260