bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxShapeCircle.java
blob6858a56451dbfd2e5143e11306746990419b2f0d
1 /*
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 .
19 package mod._svx;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.DefaultDsc;
28 import util.DrawTools;
29 import util.InstCreator;
30 import util.SOfficeFactory;
31 import util.utils;
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.lang.XMultiServiceFactory;
37 import com.sun.star.style.XStyle;
38 import com.sun.star.uno.AnyConverter;
39 import com.sun.star.uno.Type;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
43 /**
44 * Test for object which is represented by service
45 * <code>com.sun.star.drawing.EllipseShape</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
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::EllipseShape</code></li>
51 * <li> <code>com::sun::star::drawing::FillProperties</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>
65 * </ul> <p>
66 * The following files used by this test :
67 * <ul>
68 * <li><b> SvxShape.sxd </b> : this document is loaded for
69 * adding a shape tested to it. </li>
70 * </ul> <p>
71 * This object test <b> is NOT </b> designed to be run in several
72 * threads concurently.
74 * @see com.sun.star.style.ParagraphProperties
75 * @see com.sun.star.drawing.LineProperties
76 * @see com.sun.star.drawing.EllipseShape
77 * @see com.sun.star.drawing.FillProperties
78 * @see com.sun.star.drawing.ShadowProperties
79 * @see com.sun.star.drawing.XGluePointsSupplier
80 * @see com.sun.star.style.CharacterProperties
81 * @see com.sun.star.drawing.RotationDescriptor
82 * @see com.sun.star.text.XTextRange
83 * @see com.sun.star.drawing.XShape
84 * @see com.sun.star.lang.XComponent
85 * @see com.sun.star.drawing.TextProperties
86 * @see com.sun.star.beans.XPropertySet
87 * @see com.sun.star.text.XText
88 * @see com.sun.star.drawing.XShapeDescriptor
89 * @see com.sun.star.text.XSimpleText
90 * @see com.sun.star.drawing.Shape
91 * @see ifc.style._ParagraphProperties
92 * @see ifc.drawing._LineProperties
93 * @see ifc.drawing._EllipseShape
94 * @see ifc.drawing._FillProperties
95 * @see ifc.drawing._ShadowProperties
96 * @see ifc.drawing._XGluePointsSupplier
97 * @see ifc.style._CharacterProperties
98 * @see ifc.drawing._RotationDescriptor
99 * @see ifc.text._XTextRange
100 * @see ifc.drawing._XShape
101 * @see ifc.lang._XComponent
102 * @see ifc.drawing._TextProperties
103 * @see ifc.beans._XPropertySet
104 * @see ifc.text._XText
105 * @see ifc.drawing._XShapeDescriptor
106 * @see ifc.text._XSimpleText
107 * @see ifc.drawing._Shape
109 public class SvxShapeCircle extends TestCase {
111 static XComponent xDrawDoc;
114 * Loads a Draw document with name 'SvxShape.sxd' from test
115 * documents directory
117 protected void initialize( TestParameters tParam, PrintWriter log ) {
119 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
121 try {
122 log.println( "creating a drawdoc" );
123 xDrawDoc = SOF.loadDocument(
124 utils.getFullTestURL("SvxShape.sxd"));
125 } catch ( com.sun.star.uno.Exception e ) {
126 // Some exception occurs.FAILED
127 e.printStackTrace( log );
128 throw new StatusException( "Couldn't create document", e );
133 * Disposes the Draw document loaded before.
135 protected void cleanup( TestParameters tParam, PrintWriter log ) {
136 log.println( " disposing xDrawDoc " );
137 util.DesktopTools.closeDoc(xDrawDoc);
142 * Creating a Testenvironment for the interfaces to be tested.
143 * Creates an instance of the service
144 * <code>com.sun.star.drawing.EllipseShape</code> as tested component
145 * and adds it to the document. Then the FULL type of circle is set.
147 * Object relations created :
148 * <ul>
149 * <li> <code>'Style1', 'Style2'</code> for
150 * {@link ifc.drawing._Shape} :
151 * two values of 'Style' property. The first is taken
152 * from the shape tested, the second from another
153 * shape added to the draw page. </li>
154 * <li> <code>'XTEXTINFO'</code> for
155 * {@link ifc.text._XText} :
156 * creator which can create instnaces of
157 * <code>com.sun.star.text.TextField.URL</code>
158 * service. </li>
159 * </ul>
161 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
163 XInterface oObj = null;
164 XShape oShape = null;
166 // creation of testobject here
167 // first we write what we are intend to do to log file
168 log.println( "creating a test environment" );
170 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ;
171 oShape = SOF.createShape(xDrawDoc,5000,5000,3000,3000,"Ellipse");
173 XPropertySet props = UnoRuntime.queryInterface
174 (XPropertySet.class, oShape) ;
176 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
177 try {
178 props.setPropertyValue("CircleKind",
179 com.sun.star.drawing.CircleKind.FULL) ;
180 } catch (com.sun.star.lang.WrappedTargetException e) {
181 log.println("Cann't set 'CircleKind' property : " + e);
182 throw new StatusException("Can't create component", e) ;
183 } catch (com.sun.star.lang.IllegalArgumentException e) {
184 log.println("Cann't set 'CircleKind' property : " + e);
185 throw new StatusException("Can't create component", e) ;
186 } catch (com.sun.star.beans.PropertyVetoException e) {
187 log.println("Cann't set 'CircleKind' property : " + e);
188 throw new StatusException("Can't create component", e) ;
189 } catch (com.sun.star.beans.UnknownPropertyException e) {
190 log.println("Cann't set 'CircleKind' property : " + e);
191 throw new StatusException("Can't create component", e) ;
195 oObj = oShape ;
197 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Line");
198 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
200 // test environment creation
202 TestEnvironment tEnv = new TestEnvironment(oObj);
204 log.println( "adding two styles as ObjRelation for ShapeDescriptor" );
205 XPropertySet oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oObj);
206 XStyle aStyle = null;
208 try {
209 aStyle = (XStyle) AnyConverter.toObject(
210 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
211 } catch (com.sun.star.lang.WrappedTargetException e) {
212 } catch (com.sun.star.beans.UnknownPropertyException e) {
213 } catch (com.sun.star.lang.IllegalArgumentException e) {
216 tEnv.addObjRelation("Style1",aStyle);
217 oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oShape);
218 try {
219 aStyle = (XStyle) AnyConverter.toObject(
220 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
221 } catch (com.sun.star.lang.WrappedTargetException e) {
222 } catch (com.sun.star.beans.UnknownPropertyException e) {
223 } catch (com.sun.star.lang.IllegalArgumentException e) {
226 tEnv.addObjRelation("Style2",aStyle);
228 DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
229 "com.sun.star.text.TextField.URL");
230 log.println( " adding InstCreator object" );
231 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
233 return tEnv;
234 } // finish method getTestEnvironment
236 } // finish class SvxShapeCircle