merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _forms / OButtonControl.java
blob0f49ed70525e7449e6410ca9c1583428dddf2c18
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: OButtonControl.java,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
30 package mod._forms;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 import util.FormTools;
39 import util.SOfficeFactory;
40 import util.WriterTools;
42 import com.sun.star.awt.XControl;
43 import com.sun.star.awt.XControlModel;
44 import com.sun.star.awt.XDevice;
45 import com.sun.star.awt.XGraphics;
46 import com.sun.star.awt.XToolkit;
47 import com.sun.star.awt.XWindow;
48 import com.sun.star.awt.XWindowPeer;
49 import com.sun.star.drawing.XControlShape;
50 import com.sun.star.drawing.XShape;
51 import com.sun.star.lang.XMultiServiceFactory;
52 import com.sun.star.text.XTextDocument;
53 import com.sun.star.uno.UnoRuntime;
54 import com.sun.star.uno.XInterface;
55 import com.sun.star.util.XCloseable;
56 import com.sun.star.view.XControlAccess;
59 /**
60 * Test for object which is represented by default controller
61 * of the <code>com.sun.star.form.component.CommandButton</code>
62 * component. <p>
64 * Object implements the following interfaces :
65 * <ul>
66 * <li> <code>com::sun::star::lang::XComponent</code></li>
67 * <li> <code>com::sun::star::awt::XWindow</code></li>
68 * <li> <code>com::sun::star::form::XApproveActionBroadcaster</code></li>
69 * <li> <code>com::sun::star::awt::XControl</code></li>
70 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
71 * <li> <code>com::sun::star::awt::XButton</code></li>
72 * <li> <code>com::sun::star::awt::XView</code></li>
73 * </ul> <p>
75 * This object test <b> is NOT </b> designed to be run in several
76 * threads concurently.
78 * @see com.sun.star.lang.XComponent
79 * @see com.sun.star.awt.XWindow
80 * @see com.sun.star.form.XApproveActionBroadcaster
81 * @see com.sun.star.awt.XControl
82 * @see com.sun.star.awt.XLayoutConstrains
83 * @see com.sun.star.awt.XButton
84 * @see com.sun.star.awt.XView
85 * @see ifc.lang._XComponent
86 * @see ifc.awt._XWindow
87 * @see ifc.form._XApproveActionBroadcaster
88 * @see ifc.awt._XControl
89 * @see ifc.awt._XLayoutConstrains
90 * @see ifc.awt._XButton
91 * @see ifc.awt._XView
93 public class OButtonControl extends TestCase {
94 XTextDocument xTextDoc;
96 /**
97 * Creates a text document.
99 protected void initialize(TestParameters Param, PrintWriter log) {
100 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory) Param.getMSF());
102 try {
103 log.println("creating a textdocument");
104 xTextDoc = SOF.createTextDoc(null);
105 } catch (com.sun.star.uno.Exception e) {
106 // Some exception occures.FAILED
107 e.printStackTrace(log);
108 throw new StatusException("Couldn't create document", e);
113 * Disposes the text document created before
115 protected void cleanup(TestParameters tParam, PrintWriter log) {
116 log.println(" disposing xTextDoc ");
118 try {
119 XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
120 XCloseable.class, xTextDoc);
121 closer.close(true);
122 } catch (com.sun.star.util.CloseVetoException e) {
123 log.println("couldn't close document");
124 } catch (com.sun.star.lang.DisposedException e) {
125 log.println("couldn't close document");
130 * Creates two components and inserts them to the form of
131 * text document. One component
132 * (<code>com.sun.star.form.component.CommandButton</code>) is created
133 * for testing, another to be passed as relation. Using a controller
134 * of the text document the controller of the first component is
135 * obtained and returned in environment as a test object. <p>
137 * Object relations created :
138 * <ul>
139 * <li> <code>'GRAPHICS'</code> for
140 * {@link ifc.awt._XView} : a graphics component
141 * created using screen device of the window peer of
142 * the controller tested. </li>
143 * <li> <code>'CONTEXT'</code> for
144 * {@link ifc.awt._XControl} : the text document
145 * where the component is inserted. </li>
146 * <li> <code>'WINPEER'</code> for
147 * {@link ifc.awt._XControl} : Window peer of the
148 * controller tested. </li>
149 * <li> <code>'TOOLKIT'</code> for
150 * {@link ifc.awt._XControl} : toolkit of the component.</li>
151 * <li> <code>'MODEL'</code> for
152 * {@link ifc.awt._XControl} : the model of the controller.</li>
153 * <li> <code>'XWindow.AnotherWindow'</code> for
154 * {@link ifc.awt._XWindow} : the controller of another
155 * component. </li>
156 * </ul>
158 protected TestEnvironment createTestEnvironment(TestParameters Param,
159 PrintWriter log) {
160 XInterface oObj = null;
161 XWindowPeer the_win = null;
162 XToolkit the_kit = null;
163 XDevice aDevice = null;
164 XGraphics aGraphic = null;
165 XControl aControl = null;
167 //Insert a ControlShape and get the ControlModel
168 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
169 4500, 15000, 10000,
170 "CommandButton");
172 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
174 XControlModel the_Model = aShape.getControl();
176 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
177 4500, 5000, 10000,
178 "TextField");
180 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2);
182 XControlModel the_Model2 = aShape2.getControl();
184 //Try to query XControlAccess
185 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
186 XControlAccess.class,
187 xTextDoc.getCurrentController());
189 //now get the OButtonControl
190 try {
191 oObj = the_access.getControl(the_Model);
192 aControl = the_access.getControl(the_Model2);
193 the_win = the_access.getControl(the_Model).getPeer();
194 the_kit = the_win.getToolkit();
195 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
196 aGraphic = aDevice.createGraphics();
197 } catch (com.sun.star.container.NoSuchElementException e) {
198 log.println("Couldn't get OButtonControl");
199 e.printStackTrace(log);
200 throw new StatusException("Couldn't get OButtonControl", e);
203 log.println("creating a new environment for OButtonControl object");
205 TestEnvironment tEnv = new TestEnvironment(oObj);
208 //Adding ObjRelation for XView
209 tEnv.addObjRelation("GRAPHICS", aGraphic);
212 //Adding ObjRelation for XControl
213 tEnv.addObjRelation("CONTEXT", xTextDoc);
214 tEnv.addObjRelation("WINPEER", the_win);
215 tEnv.addObjRelation("TOOLKIT", the_kit);
216 tEnv.addObjRelation("MODEL", the_Model);
218 XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class,
219 aControl);
221 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
222 tEnv.addObjRelation("XWindow.ControlShape", aShape);
224 return tEnv;
225 } // finish method getTestEnvironment
226 } // finish class OButtonControl