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: SvxShape.java,v $
10 * $Revision: 1.7.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
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.DefaultDsc
;
40 import util
.DrawTools
;
41 import util
.InstCreator
;
42 import util
.SOfficeFactory
;
45 import com
.sun
.star
.beans
.XPropertySet
;
46 import com
.sun
.star
.drawing
.XShape
;
47 import com
.sun
.star
.lang
.XComponent
;
48 import com
.sun
.star
.lang
.XMultiServiceFactory
;
49 import com
.sun
.star
.style
.XStyle
;
50 import com
.sun
.star
.uno
.AnyConverter
;
51 import com
.sun
.star
.uno
.Type
;
52 import com
.sun
.star
.uno
.UnoRuntime
;
53 import com
.sun
.star
.uno
.XInterface
;
56 * Test for object which is represented by service
57 * <code>com.sun.star.drawing.Shape</code>. <p>
59 * Object implements the following interfaces :
61 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
62 * <li> <code>com::sun::star::drawing::LineProperties</code></li>
63 * <li> <code>com::sun::star::drawing::FillProperties</code></li>
64 * <li> <code>com::sun::star::drawing::TextShape</code></li>
65 * <li> <code>com::sun::star::drawing::ShadowProperties</code></li>
66 * <li> <code>com::sun::star::drawing::XGluePointsSupplier</code></li>
67 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
68 * <li> <code>com::sun::star::drawing::RotationDescriptor</code></li>
69 * <li> <code>com::sun::star::text::XTextRange</code></li>
70 * <li> <code>com::sun::star::drawing::XShape</code></li>
71 * <li> <code>com::sun::star::lang::XComponent</code></li>
72 * <li> <code>com::sun::star::drawing::TextProperties</code></li>
73 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
74 * <li> <code>com::sun::star::text::XText</code></li>
75 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
76 * <li> <code>com::sun::star::text::XSimpleText</code></li>
77 * <li> <code>com::sun::star::drawing::Shape</code></li>
80 * The following files used by this test :
82 * <li><b> SvxShape.sxd </b> : this document is loaded for
83 * adding a shape tested to it. </li>
86 * This object test <b> is NOT </b> designed to be run in several
87 * threads concurently.
89 * @see com.sun.star.style.ParagraphProperties
90 * @see com.sun.star.drawing.LineProperties
91 * @see com.sun.star.drawing.FillProperties
92 * @see com.sun.star.drawing.TextShape
93 * @see com.sun.star.drawing.ShadowProperties
94 * @see com.sun.star.drawing.XGluePointsSupplier
95 * @see com.sun.star.style.CharacterProperties
96 * @see com.sun.star.drawing.RotationDescriptor
97 * @see com.sun.star.text.XTextRange
98 * @see com.sun.star.drawing.XShape
99 * @see com.sun.star.lang.XComponent
100 * @see com.sun.star.drawing.TextProperties
101 * @see com.sun.star.beans.XPropertySet
102 * @see com.sun.star.text.XText
103 * @see com.sun.star.drawing.XShapeDescriptor
104 * @see com.sun.star.text.XSimpleText
105 * @see com.sun.star.drawing.Shape
106 * @see ifc.style._ParagraphProperties
107 * @see ifc.drawing._LineProperties
108 * @see ifc.drawing._FillProperties
109 * @see ifc.drawing._TextShape
110 * @see ifc.drawing._ShadowProperties
111 * @see ifc.drawing._XGluePointsSupplier
112 * @see ifc.style._CharacterProperties
113 * @see ifc.drawing._RotationDescriptor
114 * @see ifc.text._XTextRange
115 * @see ifc.drawing._XShape
116 * @see ifc.lang._XComponent
117 * @see ifc.drawing._TextProperties
118 * @see ifc.beans._XPropertySet
119 * @see ifc.text._XText
120 * @see ifc.drawing._XShapeDescriptor
121 * @see ifc.text._XSimpleText
122 * @see ifc.drawing._Shape
124 public class SvxShape
extends TestCase
{
126 static XComponent xDrawDoc
;
129 * Loads a Draw document with name 'SvxShape.sxd' from test
130 * documents directory
132 protected void initialize( TestParameters tParam
, PrintWriter log
) {
134 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
137 log
.println( "creating a drawdoc" );
138 xDrawDoc
= SOF
.loadDocument(
139 utils
.getFullTestURL("SvxShape.sxd"));
140 } catch ( com
.sun
.star
.uno
.Exception e
) {
141 // Some exception occures.FAILED
142 e
.printStackTrace( log
);
143 throw new StatusException( "Couldn't create document", e
);
148 * Disposes the Draw document loaded before.
150 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
151 log
.println( " disposing xDrawDoc " );
152 util
.DesktopTools
.closeDoc(xDrawDoc
);
156 * Creating a Testenvironment for the interfaces to be tested.
157 * Creates an instance of the service
158 * <code>com.sun.star.drawing.EllipseShape</code> as tested component
159 * and adds it to the document.
160 * Object relations created :
162 * <li> <code>'Style1', 'Style2'</code> for
163 * {@link ifc.drawing._Shape} :
164 * two values of 'Style' property. The first is taken
165 * from the shape tested, the second from another
166 * shape added to the draw page. </li>
167 * <li> <code>'XTEXTINFO'</code> for
168 * {@link ifc.text._XText} :
169 * creator which can create instnaces of
170 * <code>com.sun.star.text.TextField.URL</code>
174 protected TestEnvironment createTestEnvironment
175 (TestParameters tParam
, PrintWriter log
) {
177 XInterface oObj
= null;
178 XShape oShape
= null;
180 // creation of testobject here
181 // first we write what we are intend to do to log file
182 log
.println( "creating a test environment" );
184 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
185 oShape
= SOF
.createShape(xDrawDoc
,3000,4500,15000,1000,"Text");
186 DrawTools
.getShapes(DrawTools
.getDrawPage(xDrawDoc
,0)).add(oShape
);
190 // create test environment here
191 TestEnvironment tEnv
= new TestEnvironment( oShape
);
193 // adding relations for Shape service
194 oShape
= SOF
.createShape(xDrawDoc
,5000,3500,7500,5000,"Text");
195 DrawTools
.getShapes(DrawTools
.getDrawPage(xDrawDoc
,0)).add(oShape
);
197 log
.println( "adding two style as ObjRelation for ShapeDescriptor" );
198 XPropertySet oShapeProps
= (XPropertySet
)
199 UnoRuntime
.queryInterface(XPropertySet
.class,oObj
);
200 XStyle aStyle
= null;
202 aStyle
= (XStyle
) AnyConverter
.toObject(
203 new Type(XStyle
.class),oShapeProps
.getPropertyValue("Style"));
204 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
205 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
206 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
208 tEnv
.addObjRelation("Style1",aStyle
);
210 oShapeProps
= (XPropertySet
) UnoRuntime
.queryInterface
211 (XPropertySet
.class,oShape
);
213 aStyle
= (XStyle
) AnyConverter
.toObject(
214 new Type(XStyle
.class),oShapeProps
.getPropertyValue("Style"));
215 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
216 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
217 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
219 tEnv
.addObjRelation("Style2",aStyle
);
221 // adding relation for XText
222 DefaultDsc tDsc
= new DefaultDsc("com.sun.star.text.XTextContent",
223 "com.sun.star.text.TextField.URL");
224 log
.println( " adding InstCreator object" );
225 tEnv
.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc
, tDsc
) );
228 } // finish method getTestEnvironment
230 } // finish class SvxShape