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
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.DefaultDsc
;
28 import util
.DrawTools
;
29 import util
.InstCreator
;
30 import util
.SOfficeFactory
;
33 import com
.sun
.star
.beans
.XPropertySet
;
34 import com
.sun
.star
.drawing
.XShape
;
35 import com
.sun
.star
.lang
.XComponent
;
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.Shape</code>. <p>
46 * Object implements the following interfaces :
48 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
49 * <li> <code>com::sun::star::drawing::LineProperties</code></li>
50 * <li> <code>com::sun::star::drawing::FillProperties</code></li>
51 * <li> <code>com::sun::star::drawing::TextShape</code></li>
52 * <li> <code>com::sun::star::drawing::ShadowProperties</code></li>
53 * <li> <code>com::sun::star::drawing::XGluePointsSupplier</code></li>
54 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
55 * <li> <code>com::sun::star::drawing::RotationDescriptor</code></li>
56 * <li> <code>com::sun::star::text::XTextRange</code></li>
57 * <li> <code>com::sun::star::drawing::XShape</code></li>
58 * <li> <code>com::sun::star::lang::XComponent</code></li>
59 * <li> <code>com::sun::star::drawing::TextProperties</code></li>
60 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
61 * <li> <code>com::sun::star::text::XText</code></li>
62 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
63 * <li> <code>com::sun::star::text::XSimpleText</code></li>
64 * <li> <code>com::sun::star::drawing::Shape</code></li>
67 * The following files used by this test :
69 * <li><b> SvxShape.sxd </b> : this document is loaded for
70 * adding a shape tested to it. </li>
73 * This object test <b> is NOT </b> designed to be run in several
74 * threads concurently.
76 * @see com.sun.star.style.ParagraphProperties
77 * @see com.sun.star.drawing.LineProperties
78 * @see com.sun.star.drawing.FillProperties
79 * @see com.sun.star.drawing.TextShape
80 * @see com.sun.star.drawing.ShadowProperties
81 * @see com.sun.star.drawing.XGluePointsSupplier
82 * @see com.sun.star.style.CharacterProperties
83 * @see com.sun.star.drawing.RotationDescriptor
84 * @see com.sun.star.text.XTextRange
85 * @see com.sun.star.drawing.XShape
86 * @see com.sun.star.lang.XComponent
87 * @see com.sun.star.drawing.TextProperties
88 * @see com.sun.star.beans.XPropertySet
89 * @see com.sun.star.text.XText
90 * @see com.sun.star.drawing.XShapeDescriptor
91 * @see com.sun.star.text.XSimpleText
92 * @see com.sun.star.drawing.Shape
93 * @see ifc.style._ParagraphProperties
94 * @see ifc.drawing._LineProperties
95 * @see ifc.drawing._FillProperties
96 * @see ifc.drawing._TextShape
97 * @see ifc.drawing._ShadowProperties
98 * @see ifc.drawing._XGluePointsSupplier
99 * @see ifc.style._CharacterProperties
100 * @see ifc.drawing._RotationDescriptor
101 * @see ifc.text._XTextRange
102 * @see ifc.drawing._XShape
103 * @see ifc.lang._XComponent
104 * @see ifc.drawing._TextProperties
105 * @see ifc.beans._XPropertySet
106 * @see ifc.text._XText
107 * @see ifc.drawing._XShapeDescriptor
108 * @see ifc.text._XSimpleText
109 * @see ifc.drawing._Shape
111 public class SvxShape
extends TestCase
{
113 static XComponent xDrawDoc
;
116 * Loads a Draw document with name 'SvxShape.sxd' from test
117 * documents directory
120 protected void initialize( TestParameters tParam
, PrintWriter log
) {
122 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
125 log
.println( "creating a drawdoc" );
126 xDrawDoc
= SOF
.loadDocument(
127 utils
.getFullTestURL("SvxShape.sxd"));
128 } catch ( com
.sun
.star
.uno
.Exception e
) {
129 // Some exception occurs.FAILED
130 e
.printStackTrace( log
);
131 throw new StatusException( "Couldn't create document", e
);
136 * Disposes the Draw document loaded before.
139 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
140 log
.println( " disposing xDrawDoc " );
141 util
.DesktopTools
.closeDoc(xDrawDoc
);
145 * Creating a Testenvironment for the interfaces to be tested.
146 * Creates an instance of the service
147 * <code>com.sun.star.drawing.EllipseShape</code> as tested component
148 * and adds it to the document.
149 * Object relations created :
151 * <li> <code>'Style1', 'Style2'</code> for
152 * {@link ifc.drawing._Shape} :
153 * two values of 'Style' property. The first is taken
154 * from the shape tested, the second from another
155 * shape added to the draw page. </li>
156 * <li> <code>'XTEXTINFO'</code> for
157 * {@link ifc.text._XText} :
158 * creator which can create instnaces of
159 * <code>com.sun.star.text.TextField.URL</code>
164 protected TestEnvironment createTestEnvironment
165 (TestParameters tParam
, PrintWriter log
) {
167 XInterface oObj
= null;
168 XShape oShape
= null;
170 // creation of testobject here
171 // first we write what we are intend to do to log file
172 log
.println( "creating a test environment" );
174 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
175 oShape
= SOF
.createShape(xDrawDoc
,3000,4500,15000,1000,"Text");
176 DrawTools
.getShapes(DrawTools
.getDrawPage(xDrawDoc
,0)).add(oShape
);
180 // create test environment here
181 TestEnvironment tEnv
= new TestEnvironment( oShape
);
183 // adding relations for Shape service
184 oShape
= SOF
.createShape(xDrawDoc
,5000,3500,7500,5000,"Text");
185 DrawTools
.getShapes(DrawTools
.getDrawPage(xDrawDoc
,0)).add(oShape
);
187 log
.println( "adding two style as ObjRelation for ShapeDescriptor" );
188 XPropertySet oShapeProps
= UnoRuntime
.queryInterface(XPropertySet
.class,oObj
);
189 XStyle aStyle
= null;
191 aStyle
= (XStyle
) AnyConverter
.toObject(
192 new Type(XStyle
.class),oShapeProps
.getPropertyValue("Style"));
193 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
194 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
195 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
197 tEnv
.addObjRelation("Style1",aStyle
);
199 oShapeProps
= UnoRuntime
.queryInterface
200 (XPropertySet
.class,oShape
);
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("Style2",aStyle
);
210 // adding relation for XText
211 DefaultDsc tDsc
= new DefaultDsc("com.sun.star.text.XTextContent",
212 "com.sun.star.text.TextField.URL");
213 log
.println( " adding InstCreator object" );
214 tEnv
.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc
, tDsc
) );
217 } // finish method getTestEnvironment
219 } // finish class SvxShape