2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.DefaultDsc
;
27 import util
.DrawTools
;
28 import util
.InstCreator
;
29 import util
.SOfficeFactory
;
31 import com
.sun
.star
.awt
.XBitmap
;
32 import com
.sun
.star
.beans
.XPropertySet
;
33 import com
.sun
.star
.drawing
.XShape
;
34 import com
.sun
.star
.lang
.XComponent
;
35 import com
.sun
.star
.lang
.XMultiServiceFactory
;
36 import com
.sun
.star
.style
.XStyle
;
37 import com
.sun
.star
.uno
.AnyConverter
;
38 import com
.sun
.star
.uno
.Type
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
40 import com
.sun
.star
.uno
.XInterface
;
43 * Test for object which is represented by service
44 * <code>com.sun.star.drawing.GraphicObject</code>. <p>
45 * Object implements the following interfaces :
47 * <li> <code>com::sun::star::drawing::ShadowProperties</code></li>
48 * <li> <code>com::sun::star::drawing::RotationDescriptor</code></li>
49 * <li> <code>com::sun::star::text::XSimpleText</code></li>
50 * <li> <code>com::sun::star::drawing::XShape</code></li>
51 * <li> <code>com::sun::star::drawing::GraphicObjectShape</code></li>
52 * <li> <code>com::sun::star::drawing::Shape</code></li>
53 * <li> <code>com::sun::star::text::XTextRange</code></li>
54 * <li> <code>com::sun::star::drawing::XGluePointsSupplier</code></li>
55 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
56 * <li> <code>com::sun::star::drawing::TextProperties</code></li>
57 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
58 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
59 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
60 * <li> <code>com::sun::star::text::XText</code></li>
61 * <li> <code>com::sun::star::lang::XComponent</code></li>
64 * This object test <b> is NOT </b> designed to be run in several
65 * threads concurently.
67 * @see com.sun.star.drawing.ShadowProperties
68 * @see com.sun.star.drawing.RotationDescriptor
69 * @see com.sun.star.text.XSimpleText
70 * @see com.sun.star.drawing.XShape
71 * @see com.sun.star.drawing.GraphicObjectShape
72 * @see com.sun.star.drawing.Shape
73 * @see com.sun.star.text.XTextRange
74 * @see com.sun.star.drawing.XGluePointsSupplier
75 * @see com.sun.star.beans.XPropertySet
76 * @see com.sun.star.drawing.TextProperties
77 * @see com.sun.star.style.CharacterProperties
78 * @see com.sun.star.drawing.XShapeDescriptor
79 * @see com.sun.star.style.ParagraphProperties
80 * @see com.sun.star.text.XText
81 * @see com.sun.star.lang.XComponent
82 * @see ifc.drawing._ShadowProperties
83 * @see ifc.drawing._RotationDescriptor
84 * @see ifc.text._XSimpleText
85 * @see ifc.drawing._XShape
86 * @see ifc.drawing._GraphicObjectShape
87 * @see ifc.drawing._Shape
88 * @see ifc.text._XTextRange
89 * @see ifc.drawing._XGluePointsSupplier
90 * @see ifc.beans._XPropertySet
91 * @see ifc.drawing._TextProperties
92 * @see ifc.style._CharacterProperties
93 * @see ifc.drawing._XShapeDescriptor
94 * @see ifc.style._ParagraphProperties
95 * @see ifc.text._XText
96 * @see ifc.lang._XComponent
98 public class SvxGraphicObject
extends TestCase
{
100 static XComponent xDrawDoc
;
103 * Creates a new Draw document.
105 protected void initialize( TestParameters tParam
, PrintWriter log
) {
107 log
.println( "creating a drawdoc" );
108 xDrawDoc
= DrawTools
.createDrawDoc((XMultiServiceFactory
)tParam
.getMSF());
112 * Disposes the Draw document created before
114 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
115 log
.println( " disposing xDrawDoc " );
116 util
.DesktopTools
.closeDoc(xDrawDoc
);
120 * Creating a Testenvironment for the interfaces to be tested.
121 * Creates an instance of the service
122 * <code>com.sun.star.drawing.GraphicObject</code> as a tested
123 * component and inserts it to one of draw pages of the document.
126 * Object relations created :
128 * <li> <code>'Style1', 'Style2'</code> for
129 * {@link ifc.drawing._Shape} :
130 * two values of 'Style' property. The first is taken
131 * from the shape tested, the second from another
132 * shape added to the draw page. </li>
133 * <li> <code>'Bitmap1', 'Bitmap2'</code> for
134 * {@link ifc.drawing._GraphicObjectShape} :</li>
135 * two bitmap objects which are created by setting
136 * 'GraphicURL' property of component tested and
137 * getting its 'GraphicObjectFillBitmap' property.
138 * <li> <code>'IMAP'</code> for
139 * {@link ifc.drawing._GraphicObjectShape} :
140 * <code>com.sun.star.image.ImageMapRectangleObject</code>
141 * service instance. </li>
142 * <li> <code>'XTEXTINFO'</code> for
143 * {@link ifc.text._XText} :
144 * creator which can create instnaces of
145 * <code>com.sun.star.text.TextField.URL</code>
149 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
151 XInterface oObj
= null;
152 XShape oShape
= null;
155 // creation of testobject here
156 // first we write what we are intend to do to log file
157 log
.println( "creating a test environment" );
159 // create testobject here
160 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
161 oShape
= SOF
.createShape(xDrawDoc
,5000,5000,1500,1000,"GraphicObject");
162 DrawTools
.getShapes(DrawTools
.getDrawPage(xDrawDoc
,0)).add(oShape
);
165 TestEnvironment tEnv
= new TestEnvironment( oShape
);
167 // adding two styles as ObjRelation for Shape
168 oShape
= SOF
.createShape(xDrawDoc
,3000,4500,15000,1000,"Ellipse");
169 DrawTools
.getShapes(DrawTools
.getDrawPage(xDrawDoc
,0)).add(oShape
);
171 XPropertySet oShapeProps
= UnoRuntime
.queryInterface(XPropertySet
.class,oObj
);
172 XStyle aStyle
= null;
174 aStyle
= (XStyle
) AnyConverter
.toObject(
175 new Type(XStyle
.class),oShapeProps
.getPropertyValue("Style"));
176 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
177 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
178 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
180 tEnv
.addObjRelation("Style1",aStyle
);
182 oShapeProps
= UnoRuntime
.queryInterface(XPropertySet
.class,oShape
);
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
) {
190 tEnv
.addObjRelation("Style2",aStyle
);
193 // adding graphic as ObjRelation for GraphicObjectShape
194 oShapeProps
= UnoRuntime
.queryInterface(XPropertySet
.class,oObj
);
195 XBitmap aBitmap
= null;
197 oShapeProps
.setPropertyValue(
198 "GraphicURL",util
.utils
.getFullTestURL("space-metal.jpg"));
199 aBitmap
= (XBitmap
) AnyConverter
.toObject(
200 new Type(XBitmap
.class),oShapeProps
.getPropertyValue
201 ("GraphicObjectFillBitmap"));
202 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
203 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
204 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
205 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
209 tEnv
.addObjRelation("Bitmap1",aBitmap
);
212 oShapeProps
.setPropertyValue(
213 "GraphicURL",util
.utils
.getFullTestURL("crazy-blue.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
) {
223 tEnv
.addObjRelation("Bitmap2",aBitmap
);
226 XMultiServiceFactory oDocMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class,xDrawDoc
);
227 imap
= oDocMSF
.createInstance
228 ( "com.sun.star.image.ImageMapRectangleObject" );
229 } catch (com
.sun
.star
.uno
.Exception e
) {
230 log
.println("Couldn't create instance");
231 e
.printStackTrace(log
);
235 tEnv
.addObjRelation("IMAP",imap
);
236 tEnv
.addObjRelation("ImapObject",imap
);
238 // adding relation for XText interface
239 DefaultDsc tDsc
= new DefaultDsc("com.sun.star.text.XTextContent",
240 "com.sun.star.text.TextField.URL");
241 log
.println( " adding InstCreator object" );
242 tEnv
.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc
, tDsc
) );
244 tEnv
.addObjRelation("NoShear",new Boolean(true));
248 } // finish method getTestEnvironment
250 } // finish class SvxGraphicObject