Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxShapeCircle.java
blob13d76012aa8b2ae8c6977bff36d21ad0c5687d3d
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.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;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.drawing.EllipseShape</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
48 * <li> <code>com::sun::star::drawing::LineProperties</code></li>
49 * <li> <code>com::sun::star::drawing::EllipseShape</code></li>
50 * <li> <code>com::sun::star::drawing::FillProperties</code></li>
51 * <li> <code>com::sun::star::drawing::ShadowProperties</code></li>
52 * <li> <code>com::sun::star::drawing::XGluePointsSupplier</code></li>
53 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
54 * <li> <code>com::sun::star::drawing::RotationDescriptor</code></li>
55 * <li> <code>com::sun::star::text::XTextRange</code></li>
56 * <li> <code>com::sun::star::drawing::XShape</code></li>
57 * <li> <code>com::sun::star::lang::XComponent</code></li>
58 * <li> <code>com::sun::star::drawing::TextProperties</code></li>
59 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
60 * <li> <code>com::sun::star::text::XText</code></li>
61 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
62 * <li> <code>com::sun::star::text::XSimpleText</code></li>
63 * <li> <code>com::sun::star::drawing::Shape</code></li>
64 * </ul> <p>
65 * The following files used by this test :
66 * <ul>
67 * <li><b> SvxShape.sxd </b> : this document is loaded for
68 * adding a shape tested to it. </li>
69 * </ul> <p>
70 * This object test <b> is NOT </b> designed to be run in several
71 * threads concurently.
73 * @see com.sun.star.style.ParagraphProperties
74 * @see com.sun.star.drawing.LineProperties
75 * @see com.sun.star.drawing.EllipseShape
76 * @see com.sun.star.drawing.FillProperties
77 * @see com.sun.star.drawing.ShadowProperties
78 * @see com.sun.star.drawing.XGluePointsSupplier
79 * @see com.sun.star.style.CharacterProperties
80 * @see com.sun.star.drawing.RotationDescriptor
81 * @see com.sun.star.text.XTextRange
82 * @see com.sun.star.drawing.XShape
83 * @see com.sun.star.lang.XComponent
84 * @see com.sun.star.drawing.TextProperties
85 * @see com.sun.star.beans.XPropertySet
86 * @see com.sun.star.text.XText
87 * @see com.sun.star.drawing.XShapeDescriptor
88 * @see com.sun.star.text.XSimpleText
89 * @see com.sun.star.drawing.Shape
90 * @see ifc.style._ParagraphProperties
91 * @see ifc.drawing._LineProperties
92 * @see ifc.drawing._EllipseShape
93 * @see ifc.drawing._FillProperties
94 * @see ifc.drawing._ShadowProperties
95 * @see ifc.drawing._XGluePointsSupplier
96 * @see ifc.style._CharacterProperties
97 * @see ifc.drawing._RotationDescriptor
98 * @see ifc.text._XTextRange
99 * @see ifc.drawing._XShape
100 * @see ifc.lang._XComponent
101 * @see ifc.drawing._TextProperties
102 * @see ifc.beans._XPropertySet
103 * @see ifc.text._XText
104 * @see ifc.drawing._XShapeDescriptor
105 * @see ifc.text._XSimpleText
106 * @see ifc.drawing._Shape
108 public class SvxShapeCircle extends TestCase {
110 static XComponent xDrawDoc;
113 * Loads a Draw document with name 'SvxShape.sxd' from test
114 * documents directory
116 @Override
117 protected void initialize( TestParameters tParam, PrintWriter log ) {
119 SOfficeFactory SOF = SOfficeFactory.getFactory( 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 @Override
136 protected void cleanup( TestParameters tParam, PrintWriter log ) {
137 log.println( " disposing xDrawDoc " );
138 util.DesktopTools.closeDoc(xDrawDoc);
143 * Creating a Testenvironment for the interfaces to be tested.
144 * Creates an instance of the service
145 * <code>com.sun.star.drawing.EllipseShape</code> as tested component
146 * and adds it to the document. Then the FULL type of circle is set.
148 * Object relations created :
149 * <ul>
150 * <li> <code>'Style1', 'Style2'</code> for
151 * {@link ifc.drawing._Shape} :
152 * two values of 'Style' property. The first is taken
153 * from the shape tested, the second from another
154 * shape added to the draw page. </li>
155 * <li> <code>'XTEXTINFO'</code> for
156 * {@link ifc.text._XText} :
157 * creator which can create instnaces of
158 * <code>com.sun.star.text.TextField.URL</code>
159 * service. </li>
160 * </ul>
162 @Override
163 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
165 XInterface oObj = null;
166 XShape oShape = null;
168 // creation of testobject here
169 // first we write what we are intend to do to log file
170 log.println( "creating a test environment" );
172 SOfficeFactory SOF = SOfficeFactory.getFactory(tParam.getMSF()) ;
173 oShape = SOF.createShape(xDrawDoc,5000,5000,3000,3000,"Ellipse");
175 XPropertySet props = UnoRuntime.queryInterface
176 (XPropertySet.class, oShape) ;
178 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
179 try {
180 props.setPropertyValue("CircleKind",
181 com.sun.star.drawing.CircleKind.FULL) ;
182 } catch (com.sun.star.lang.WrappedTargetException e) {
183 log.println("Cann't set 'CircleKind' property : " + e);
184 throw new StatusException("Can't create component", e) ;
185 } catch (com.sun.star.lang.IllegalArgumentException e) {
186 log.println("Cann't set 'CircleKind' property : " + e);
187 throw new StatusException("Can't create component", e) ;
188 } catch (com.sun.star.beans.PropertyVetoException e) {
189 log.println("Cann't set 'CircleKind' property : " + e);
190 throw new StatusException("Can't create component", e) ;
191 } catch (com.sun.star.beans.UnknownPropertyException e) {
192 log.println("Cann't set 'CircleKind' property : " + e);
193 throw new StatusException("Can't create component", e) ;
197 oObj = oShape ;
199 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Line");
200 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
202 // test environment creation
204 TestEnvironment tEnv = new TestEnvironment(oObj);
206 log.println( "adding two styles as ObjRelation for ShapeDescriptor" );
207 XPropertySet oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oObj);
208 XStyle aStyle = null;
210 try {
211 aStyle = (XStyle) AnyConverter.toObject(
212 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
213 } catch (com.sun.star.lang.WrappedTargetException e) {
214 } catch (com.sun.star.beans.UnknownPropertyException e) {
215 } catch (com.sun.star.lang.IllegalArgumentException e) {
218 tEnv.addObjRelation("Style1",aStyle);
219 oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oShape);
220 try {
221 aStyle = (XStyle) AnyConverter.toObject(
222 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
223 } catch (com.sun.star.lang.WrappedTargetException e) {
224 } catch (com.sun.star.beans.UnknownPropertyException e) {
225 } catch (com.sun.star.lang.IllegalArgumentException e) {
228 tEnv.addObjRelation("Style2",aStyle);
230 DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
231 "com.sun.star.text.TextField.URL");
232 log.println( " adding InstCreator object" );
233 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
235 return tEnv;
236 } // finish method getTestEnvironment
238 } // finish class SvxShapeCircle