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