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