1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._svx;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.DefaultDsc;
33 import util.DrawTools;
34 import util.InstCreator;
35 import util.SOfficeFactory;
36 
37 import com.sun.star.beans.XPropertySet;
38 import com.sun.star.drawing.XShape;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.style.XStyle;
42 import com.sun.star.uno.AnyConverter;
43 import com.sun.star.uno.Type;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 
47 public class SvxShapeDimensioning extends TestCase {
48 
49     static XComponent xDrawDoc;
50 
51     /**
52      * in general this method creates a testdocument
53      *
54      *  @param tParam    class which contains additional test parameters
55      *  @param log        class to log the test state and result
56      *
57      *
58      *  @see TestParameters
59      *    @see PrintWriter
60      *
61      */
initialize( TestParameters tParam, PrintWriter log )62     protected void initialize( TestParameters tParam, PrintWriter log ) {
63 
64         try {
65             log.println( "creating a drawdoc" );
66             xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF());
67         } catch ( Exception e ) {
68             // Some exception occured.FAILED
69             e.printStackTrace( log );
70             throw new StatusException( "Couldn't create document", e );
71         }
72     }
73 
74     /**
75      * in general this method disposes the testenvironment and document
76      *
77      *  @param tParam    class which contains additional test parameters
78      *  @param log        class to log the test state and result
79      *
80      *
81      *  @see TestParameters
82      *    @see PrintWriter
83      *
84      */
cleanup( TestParameters tParam, PrintWriter log )85     protected void cleanup( TestParameters tParam, PrintWriter log ) {
86         log.println( "    disposing xDrawDoc " );
87         util.DesktopTools.closeDoc(xDrawDoc);
88     }
89 
90 
91     /**
92      *    creating a Testenvironment for the interfaces to be tested
93      *
94      *  @param tParam    class which contains additional test parameters
95      *  @param log        class to log the test state and result
96      *
97      *  @return    Status class
98      *
99      *  @see TestParameters
100      *    @see PrintWriter
101      */
createTestEnvironment(TestParameters tParam, PrintWriter log)102     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
103 
104         XInterface oObj = null;
105         XShape oShape = null;
106 
107         // creation of testobject here
108         // first we write what we are intend to do to log file
109         log.println( "creating a test environment" );
110 
111         try {
112 
113             SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
114               oShape = SOF.createShape(xDrawDoc,4000,4000,3000,3000,"Measure");
115 
116             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
117 
118             for (int i=0;i<10;i++) {
119                 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(
120                     SOF.createShape(xDrawDoc,
121                     3000,4500,7510+10*i,5010+10*i,"Rectangle"));
122             }
123 
124             oObj = oShape ;
125 
126             //SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ;
127             oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Line");
128             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
129         }
130         catch (Exception e) {
131             log.println("Couldn't create insance");
132             e.printStackTrace(log);
133         }
134 
135         // test environment creation
136 
137          TestEnvironment tEnv = new TestEnvironment(oObj);
138 
139         log.println( "adding two styles as ObjRelation for ShapeDescriptor" );
140         XPropertySet oShapeProps = (XPropertySet)
141                             UnoRuntime.queryInterface(XPropertySet.class,oObj);
142         XStyle aStyle = null;
143         try {
144             aStyle = (XStyle) AnyConverter.toObject(
145                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
146         } catch (Exception e) {}
147         tEnv.addObjRelation("Style1",aStyle);
148         oShapeProps = (XPropertySet)
149             UnoRuntime.queryInterface(XPropertySet.class,oShape);
150         try {
151             aStyle = (XStyle) AnyConverter.toObject(
152                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
153         } catch (Exception e) {}
154         tEnv.addObjRelation("Style2",aStyle);
155 
156         DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
157                                             "com.sun.star.text.TextField.URL");
158         log.println( "    adding InstCreator object" );
159         tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
160 
161         return tEnv;
162     } // finish method getTestEnvironment
163 
164 }    // finish class SvxShapeDimensioning
165 
166