xref: /AOO41X/main/qadevOOo/tests/java/mod/_svx/SvxShapeControl.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._svx;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.DrawTools;
37 import util.FormTools;
38 import util.SOfficeFactory;
39 
40 import com.sun.star.beans.XPropertySet;
41 import com.sun.star.drawing.XShape;
42 import com.sun.star.lang.XComponent;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.style.XStyle;
45 import com.sun.star.uno.AnyConverter;
46 import com.sun.star.uno.Type;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 
50 public class SvxShapeControl extends TestCase {
51 
52     static XComponent xDrawDoc;
53 
54     /**
55      * in general this method creates a testdocument
56      *
57      *  @param tParam    class which contains additional test parameters
58      *  @param log        class to log the test state and result
59      *
60      *
61      *  @see TestParameters
62      *    @see PrintWriter
63      *
64      */
65     protected void initialize( TestParameters tParam, PrintWriter log ) {
66 
67         try {
68             log.println( "creating a drawdoc" );
69             xDrawDoc = DrawTools.createDrawDoc((XMultiServiceFactory)tParam.getMSF());
70         } catch ( Exception e ) {
71             // Some exception occures.FAILED
72             e.printStackTrace( log );
73             throw new StatusException( "Couldn't create document", e );
74         }
75     }
76 
77     /**
78      * in general this method disposes the testenvironment and document
79      *
80      *  @param tParam    class which contains additional test parameters
81      *  @param log        class to log the test state and result
82      *
83      *
84      *  @see TestParameters
85      *    @see PrintWriter
86      *
87      */
88     protected void cleanup( TestParameters tParam, PrintWriter log ) {
89         log.println( "    disposing xDrawDoc " );
90         util.DesktopTools.closeDoc(xDrawDoc);
91     }
92 
93 
94     /**
95      *    creating a Testenvironment for the interfaces to be tested
96      *
97      *  @param tParam    class which contains additional test parameters
98      *  @param log        class to log the test state and result
99      *
100      *  @return    Status class
101      *
102      *  @see TestParameters
103      *    @see PrintWriter
104      */
105     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
106 
107         XInterface oObj = null;
108         XShape oShape = null;
109 
110         // creation of testobject here
111         // first we write what we are intend to do to log file
112         log.println( "creating a test environment" );
113 
114         try {
115 
116             oShape = FormTools.insertControlShape(
117                   xDrawDoc,3000,4500,15000,1000,"CommandButton");
118 
119             oObj = oShape ;
120 
121             SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ;
122             oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Line");
123             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
124         }
125         catch (Exception e) {
126             log.println("Couldn't create insance");
127             e.printStackTrace(log);
128         }
129 
130         // test environment creation
131 
132          TestEnvironment tEnv = new TestEnvironment(oObj);
133 
134         log.println( "adding two styles as ObjRelation for ShapeDescriptor" );
135         XPropertySet oShapeProps = (XPropertySet)
136                             UnoRuntime.queryInterface(XPropertySet.class,oObj);
137         XStyle aStyle = null;
138         try {
139             aStyle = (XStyle) AnyConverter.toObject(
140                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
141         } catch (Exception e) {}
142         tEnv.addObjRelation("Style1",aStyle);
143         oShapeProps = (XPropertySet)
144                             UnoRuntime.queryInterface(XPropertySet.class,oShape);
145         try {
146             aStyle = (XStyle) AnyConverter.toObject(
147                 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
148         } catch (Exception e) {}
149         tEnv.addObjRelation("Style2",aStyle);
150 
151         log.println( "adding document relation for XControlShape" );
152         tEnv.addObjRelation("xDoc", xDrawDoc) ;
153 
154         return tEnv;
155     } // finish method getTestEnvironment
156 
157 }    // finish class SvxShapeControl
158 
159