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