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