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