1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._svx;
29 
30 import java.io.PrintWriter;
31 
32 import lib.TestCase;
33 import lib.TestEnvironment;
34 import lib.TestParameters;
35 import util.DefaultDsc;
36 import util.DrawTools;
37 import util.InstCreator;
38 import util.SOfficeFactory;
39 
40 import com.sun.star.awt.XBitmap;
41 import com.sun.star.beans.XPropertySet;
42 import com.sun.star.drawing.XShape;
43 import com.sun.star.lang.XComponent;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.style.XStyle;
46 import com.sun.star.uno.AnyConverter;
47 import com.sun.star.uno.Type;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
50 
51 /**
52  * Test for object which is represented by service
53  * <code>com.sun.star.drawing.GraphicObject</code>. <p>
54  * Object implements the following interfaces :
55  * <ul>
56  *  <li> <code>com::sun::star::drawing::ShadowProperties</code></li>
57  *  <li> <code>com::sun::star::drawing::RotationDescriptor</code></li>
58  *  <li> <code>com::sun::star::text::XSimpleText</code></li>
59  *  <li> <code>com::sun::star::drawing::XShape</code></li>
60  *  <li> <code>com::sun::star::drawing::GraphicObjectShape</code></li>
61  *  <li> <code>com::sun::star::drawing::Shape</code></li>
62  *  <li> <code>com::sun::star::text::XTextRange</code></li>
63  *  <li> <code>com::sun::star::drawing::XGluePointsSupplier</code></li>
64  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
65  *  <li> <code>com::sun::star::drawing::TextProperties</code></li>
66  *  <li> <code>com::sun::star::style::CharacterProperties</code></li>
67  *  <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
68  *  <li> <code>com::sun::star::style::ParagraphProperties</code></li>
69  *  <li> <code>com::sun::star::text::XText</code></li>
70  *  <li> <code>com::sun::star::lang::XComponent</code></li>
71  * </ul> <p>
72  *
73  * This object test <b> is NOT </b> designed to be run in several
74  * threads concurently.
75  *
76  * @see com.sun.star.drawing.ShadowProperties
77  * @see com.sun.star.drawing.RotationDescriptor
78  * @see com.sun.star.text.XSimpleText
79  * @see com.sun.star.drawing.XShape
80  * @see com.sun.star.drawing.GraphicObjectShape
81  * @see com.sun.star.drawing.Shape
82  * @see com.sun.star.text.XTextRange
83  * @see com.sun.star.drawing.XGluePointsSupplier
84  * @see com.sun.star.beans.XPropertySet
85  * @see com.sun.star.drawing.TextProperties
86  * @see com.sun.star.style.CharacterProperties
87  * @see com.sun.star.drawing.XShapeDescriptor
88  * @see com.sun.star.style.ParagraphProperties
89  * @see com.sun.star.text.XText
90  * @see com.sun.star.lang.XComponent
91  * @see ifc.drawing._ShadowProperties
92  * @see ifc.drawing._RotationDescriptor
93  * @see ifc.text._XSimpleText
94  * @see ifc.drawing._XShape
95  * @see ifc.drawing._GraphicObjectShape
96  * @see ifc.drawing._Shape
97  * @see ifc.text._XTextRange
98  * @see ifc.drawing._XGluePointsSupplier
99  * @see ifc.beans._XPropertySet
100  * @see ifc.drawing._TextProperties
101  * @see ifc.style._CharacterProperties
102  * @see ifc.drawing._XShapeDescriptor
103  * @see ifc.style._ParagraphProperties
104  * @see ifc.text._XText
105  * @see ifc.lang._XComponent
106  */
107 public class SvxGraphicObject extends TestCase {
108 
109     static XComponent xDrawDoc;
110 
111     /**
112      * Creates a new Draw document.
113      */
114     protected void initialize( TestParameters tParam, PrintWriter log ) {
115 
116         log.println( "creating a drawdoc" );
117         xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF());
118     }
119 
120     /**
121      * Disposes the Draw document created before
122      */
123     protected void cleanup( TestParameters tParam, PrintWriter log ) {
124         log.println( "    disposing xDrawDoc " );
125         util.DesktopTools.closeDoc(xDrawDoc);
126     }
127 
128     /**
129      * Creating a Testenvironment for the interfaces to be tested.
130      * Creates an instance of the service
131      * <code>com.sun.star.drawing.GraphicObject</code> as a tested
132      * component and inserts it to one of draw pages of the document.
133      * <p>
134      *
135      *     Object relations created :
136      * <ul>
137      *  <li> <code>'Style1', 'Style2'</code> for
138      *      {@link ifc.drawing._Shape} :
139      *       two values of 'Style' property. The first is taken
140      *       from the shape tested, the second from another
141      *       shape added to the draw page. </li>
142      *  <li> <code>'Bitmap1', 'Bitmap2'</code> for
143      *      {@link ifc.drawing._GraphicObjectShape} :</li>
144      *      two bitmap objects which are created by setting
145      *      'GraphicURL' property of component tested and
146      *      getting its 'GraphicObjectFillBitmap' property.
147      *  <li> <code>'IMAP'</code> for
148      *      {@link ifc.drawing._GraphicObjectShape} :
149      *      <code>com.sun.star.image.ImageMapRectangleObject</code>
150      *      service instance. </li>
151      *  <li> <code>'XTEXTINFO'</code> for
152      *      {@link ifc.text._XText} :
153      *      creator which can create instnaces of
154      *      <code>com.sun.star.text.TextField.URL</code>
155      *      service. </li>
156      * </ul>
157      */
158     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
159 
160         XInterface oObj = null;
161         XShape oShape = null;
162         Object imap=null;
163 
164         // creation of testobject here
165         // first we write what we are intend to do to log file
166         log.println( "creating a test environment" );
167 
168         // create testobject here
169         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
170         oShape = SOF.createShape(xDrawDoc,5000,5000,1500,1000,"GraphicObject");
171         DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
172         oObj = oShape;
173 
174         TestEnvironment tEnv = new TestEnvironment( oShape );
175 
176         // adding two styles as ObjRelation for Shape
177         oShape = SOF.createShape(xDrawDoc,3000,4500,15000,1000,"Ellipse");
178         DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
179 
180         XPropertySet oShapeProps = (XPropertySet)
181                             UnoRuntime.queryInterface(XPropertySet.class,oObj);
182         XStyle aStyle = null;
183         try {
184             aStyle = (XStyle) AnyConverter.toObject(
185                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
186         } catch (com.sun.star.lang.WrappedTargetException e) {
187         } catch (com.sun.star.beans.UnknownPropertyException e) {
188         } catch (com.sun.star.lang.IllegalArgumentException e) {
189         }
190         tEnv.addObjRelation("Style1",aStyle);
191 
192         oShapeProps = (XPropertySet)
193                             UnoRuntime.queryInterface(XPropertySet.class,oShape);
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("Style2",aStyle);
202 
203 
204         // adding graphic as ObjRelation for GraphicObjectShape
205         oShapeProps = (XPropertySet)
206                             UnoRuntime.queryInterface(XPropertySet.class,oObj);
207         XBitmap aBitmap = null;
208         try {
209             oShapeProps.setPropertyValue(
210                 "GraphicURL",util.utils.getFullTestURL("space-metal.jpg"));
211             aBitmap = (XBitmap) AnyConverter.toObject(
212                 new Type(XBitmap.class),oShapeProps.getPropertyValue
213                     ("GraphicObjectFillBitmap"));
214         } catch (com.sun.star.lang.WrappedTargetException e) {
215         } catch (com.sun.star.lang.IllegalArgumentException e) {
216         } catch (com.sun.star.beans.PropertyVetoException e) {
217         } catch (com.sun.star.beans.UnknownPropertyException e) {
218         }
219 
220 
221         tEnv.addObjRelation("Bitmap1",aBitmap);
222 
223         try {
224              oShapeProps.setPropertyValue(
225                 "GraphicURL",util.utils.getFullTestURL("crazy-blue.jpg"));
226             aBitmap = (XBitmap) AnyConverter.toObject(
227                 new Type(XBitmap.class),oShapeProps.getPropertyValue
228                     ("GraphicObjectFillBitmap"));
229         } catch (com.sun.star.lang.WrappedTargetException e) {
230         } catch (com.sun.star.lang.IllegalArgumentException e) {
231         } catch (com.sun.star.beans.PropertyVetoException e) {
232         } catch (com.sun.star.beans.UnknownPropertyException e) {
233         }
234 
235         tEnv.addObjRelation("Bitmap2",aBitmap);
236 
237         try {
238             XMultiServiceFactory oDocMSF = (XMultiServiceFactory)
239                 UnoRuntime.queryInterface(XMultiServiceFactory.class,xDrawDoc);
240             imap = oDocMSF.createInstance
241                 ( "com.sun.star.image.ImageMapRectangleObject" );
242         } catch (com.sun.star.uno.Exception e) {
243             log.println("Couldn't create instance");
244             e.printStackTrace(log);
245         }
246 
247 
248         tEnv.addObjRelation("IMAP",imap);
249         tEnv.addObjRelation("ImapObject",imap);
250 
251         // adding relation for XText interface
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         tEnv.addObjRelation("NoShear",new Boolean(true));
258 
259         return tEnv;
260 
261     } // finish method getTestEnvironment
262 
263 }    // finish class SvxGraphicObject
264