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.DrawTools;
33 import util.FormTools;
34 import util.SOfficeFactory;
35 
36 import com.sun.star.beans.XPropertySet;
37 import com.sun.star.drawing.XShape;
38 import com.sun.star.lang.XComponent;
39 import com.sun.star.lang.XMultiServiceFactory;
40 import com.sun.star.style.XStyle;
41 import com.sun.star.uno.AnyConverter;
42 import com.sun.star.uno.Type;
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.uno.XInterface;
45 
46 public class SvxShapeControl extends TestCase {
47 
48     static XComponent xDrawDoc;
49 
50     /**
51      * in general this method creates a testdocument
52      *
53      *  @param tParam    class which contains additional test parameters
54      *  @param log        class to log the test state and result
55      *
56      *
57      *  @see TestParameters
58      *    @see PrintWriter
59      *
60      */
initialize( TestParameters tParam, PrintWriter log )61     protected void initialize( TestParameters tParam, PrintWriter log ) {
62 
63         try {
64             log.println( "creating a drawdoc" );
65             xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF());
66         } catch ( Exception e ) {
67             // Some exception occured.FAILED
68             e.printStackTrace( log );
69             throw new StatusException( "Couldn't create document", e );
70         }
71     }
72 
73     /**
74      * in general this method disposes the testenvironment and document
75      *
76      *  @param tParam    class which contains additional test parameters
77      *  @param log        class to log the test state and result
78      *
79      *
80      *  @see TestParameters
81      *    @see PrintWriter
82      *
83      */
cleanup( TestParameters tParam, PrintWriter log )84     protected void cleanup( TestParameters tParam, PrintWriter log ) {
85         log.println( "    disposing xDrawDoc " );
86         util.DesktopTools.closeDoc(xDrawDoc);
87     }
88 
89 
90     /**
91      *    creating a Testenvironment for the interfaces to be tested
92      *
93      *  @param tParam    class which contains additional test parameters
94      *  @param log        class to log the test state and result
95      *
96      *  @return    Status class
97      *
98      *  @see TestParameters
99      *    @see PrintWriter
100      */
createTestEnvironment(TestParameters tParam, PrintWriter log)101     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
102 
103         XInterface oObj = null;
104         XShape oShape = null;
105 
106         // creation of testobject here
107         // first we write what we are intend to do to log file
108         log.println( "creating a test environment" );
109 
110         try {
111 
112             oShape = FormTools.insertControlShape(
113                   xDrawDoc,3000,4500,15000,1000,"CommandButton");
114 
115             oObj = oShape ;
116 
117             SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ;
118             oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Line");
119             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
120         }
121         catch (Exception e) {
122             log.println("Couldn't create insance");
123             e.printStackTrace(log);
124         }
125 
126         // test environment creation
127 
128          TestEnvironment tEnv = new TestEnvironment(oObj);
129 
130         log.println( "adding two styles as ObjRelation for ShapeDescriptor" );
131         XPropertySet oShapeProps = (XPropertySet)
132                             UnoRuntime.queryInterface(XPropertySet.class,oObj);
133         XStyle aStyle = null;
134         try {
135             aStyle = (XStyle) AnyConverter.toObject(
136                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
137         } catch (Exception e) {}
138         tEnv.addObjRelation("Style1",aStyle);
139         oShapeProps = (XPropertySet)
140                             UnoRuntime.queryInterface(XPropertySet.class,oShape);
141         try {
142             aStyle = (XStyle) AnyConverter.toObject(
143                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
144         } catch (Exception e) {}
145         tEnv.addObjRelation("Style2",aStyle);
146 
147         log.println( "adding document relation for XControlShape" );
148         tEnv.addObjRelation("xDoc", xDrawDoc) ;
149 
150         return tEnv;
151     } // finish method getTestEnvironment
152 
153 }    // finish class SvxShapeControl
154 
155