bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxShape.java
blobadbc98dc3dd24774083a63cddc02dbff4c815127
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.Shape</code>. <p>
47 * Object implements the following interfaces :
48 * <ul>
49 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
50 * <li> <code>com::sun::star::drawing::LineProperties</code></li>
51 * <li> <code>com::sun::star::drawing::FillProperties</code></li>
52 * <li> <code>com::sun::star::drawing::TextShape</code></li>
53 * <li> <code>com::sun::star::drawing::ShadowProperties</code></li>
54 * <li> <code>com::sun::star::drawing::XGluePointsSupplier</code></li>
55 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
56 * <li> <code>com::sun::star::drawing::RotationDescriptor</code></li>
57 * <li> <code>com::sun::star::text::XTextRange</code></li>
58 * <li> <code>com::sun::star::drawing::XShape</code></li>
59 * <li> <code>com::sun::star::lang::XComponent</code></li>
60 * <li> <code>com::sun::star::drawing::TextProperties</code></li>
61 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
62 * <li> <code>com::sun::star::text::XText</code></li>
63 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li>
64 * <li> <code>com::sun::star::text::XSimpleText</code></li>
65 * <li> <code>com::sun::star::drawing::Shape</code></li>
66 * </ul> <p>
68 * The following files used by this test :
69 * <ul>
70 * <li><b> SvxShape.sxd </b> : this document is loaded for
71 * adding a shape tested to it. </li>
72 * </ul> <p>
74 * This object test <b> is NOT </b> designed to be run in several
75 * threads concurently.
77 * @see com.sun.star.style.ParagraphProperties
78 * @see com.sun.star.drawing.LineProperties
79 * @see com.sun.star.drawing.FillProperties
80 * @see com.sun.star.drawing.TextShape
81 * @see com.sun.star.drawing.ShadowProperties
82 * @see com.sun.star.drawing.XGluePointsSupplier
83 * @see com.sun.star.style.CharacterProperties
84 * @see com.sun.star.drawing.RotationDescriptor
85 * @see com.sun.star.text.XTextRange
86 * @see com.sun.star.drawing.XShape
87 * @see com.sun.star.lang.XComponent
88 * @see com.sun.star.drawing.TextProperties
89 * @see com.sun.star.beans.XPropertySet
90 * @see com.sun.star.text.XText
91 * @see com.sun.star.drawing.XShapeDescriptor
92 * @see com.sun.star.text.XSimpleText
93 * @see com.sun.star.drawing.Shape
94 * @see ifc.style._ParagraphProperties
95 * @see ifc.drawing._LineProperties
96 * @see ifc.drawing._FillProperties
97 * @see ifc.drawing._TextShape
98 * @see ifc.drawing._ShadowProperties
99 * @see ifc.drawing._XGluePointsSupplier
100 * @see ifc.style._CharacterProperties
101 * @see ifc.drawing._RotationDescriptor
102 * @see ifc.text._XTextRange
103 * @see ifc.drawing._XShape
104 * @see ifc.lang._XComponent
105 * @see ifc.drawing._TextProperties
106 * @see ifc.beans._XPropertySet
107 * @see ifc.text._XText
108 * @see ifc.drawing._XShapeDescriptor
109 * @see ifc.text._XSimpleText
110 * @see ifc.drawing._Shape
112 public class SvxShape extends TestCase {
114 static XComponent xDrawDoc;
117 * Loads a Draw document with name 'SvxShape.sxd' from test
118 * documents directory
120 protected void initialize( TestParameters tParam, PrintWriter log ) {
122 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
124 try {
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.
138 protected void cleanup( TestParameters tParam, PrintWriter log ) {
139 log.println( " disposing xDrawDoc " );
140 util.DesktopTools.closeDoc(xDrawDoc);
144 * Creating a Testenvironment for the interfaces to be tested.
145 * Creates an instance of the service
146 * <code>com.sun.star.drawing.EllipseShape</code> as tested component
147 * and adds it to the document.
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 protected TestEnvironment createTestEnvironment
163 (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( (XMultiServiceFactory)tParam.getMSF());
173 oShape = SOF.createShape(xDrawDoc,3000,4500,15000,1000,"Text");
174 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
175 oObj = oShape ;
178 // create test environment here
179 TestEnvironment tEnv = new TestEnvironment( oShape );
181 // adding relations for Shape service
182 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Text");
183 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
185 log.println( "adding two style as ObjRelation for ShapeDescriptor" );
186 XPropertySet oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oObj);
187 XStyle aStyle = null;
188 try {
189 aStyle = (XStyle) AnyConverter.toObject(
190 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
191 } catch (com.sun.star.lang.WrappedTargetException e) {
192 } catch (com.sun.star.beans.UnknownPropertyException e) {
193 } catch (com.sun.star.lang.IllegalArgumentException e) {
195 tEnv.addObjRelation("Style1",aStyle);
197 oShapeProps = UnoRuntime.queryInterface
198 (XPropertySet.class,oShape);
199 try {
200 aStyle = (XStyle) AnyConverter.toObject(
201 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
202 } catch (com.sun.star.lang.WrappedTargetException e) {
203 } catch (com.sun.star.beans.UnknownPropertyException e) {
204 } catch (com.sun.star.lang.IllegalArgumentException e) {
206 tEnv.addObjRelation("Style2",aStyle);
208 // adding relation for XText
209 DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
210 "com.sun.star.text.TextField.URL");
211 log.println( " adding InstCreator object" );
212 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
214 return tEnv;
215 } // finish method getTestEnvironment
217 } // finish class SvxShape