merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _forms / ORadioButtonControl.java
blobda5613aef3366a2ae9d137595e688fdd5bac452d
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: ORadioButtonControl.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.RadioButton</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::XBoundControl</code></li>
69 * <li> <code>com::sun::star::awt::XRadioButton</code></li>
70 * <li> <code>com::sun::star::awt::XControl</code></li>
71 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
72 * <li> <code>com::sun::star::awt::XView</code></li>
73 * </ul> <p>
74 * This object test <b> is NOT </b> designed to be run in several
75 * threads concurently.
77 * @see com.sun.star.lang.XComponent
78 * @see com.sun.star.awt.XWindow
79 * @see com.sun.star.form.XBoundControl
80 * @see com.sun.star.awt.XRadioButton
81 * @see com.sun.star.awt.XControl
82 * @see com.sun.star.awt.XLayoutConstrains
83 * @see com.sun.star.awt.XView
84 * @see ifc.lang._XComponent
85 * @see ifc.awt._XWindow
86 * @see ifc.form._XBoundControl
87 * @see ifc.awt._XRadioButton
88 * @see ifc.awt._XControl
89 * @see ifc.awt._XLayoutConstrains
90 * @see ifc.awt._XView
92 public class ORadioButtonControl extends TestCase {
93 XTextDocument xTextDoc;
95 /**
96 * Creates a new text document.
98 protected void initialize(TestParameters Param, PrintWriter log) {
99 SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) Param.getMSF()));
101 try {
102 log.println("creating a textdocument");
103 xTextDoc = SOF.createTextDoc(null);
104 } catch (com.sun.star.uno.Exception e) {
105 // Some exception occures.FAILED
106 e.printStackTrace(log);
107 throw new StatusException("Couldn't create document", e);
112 * Disposes the text document created before
114 protected void cleanup(TestParameters tParam, PrintWriter log) {
115 log.println(" disposing xTextDoc ");
117 try {
118 XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
119 XCloseable.class, xTextDoc);
120 closer.close(true);
121 } catch (com.sun.star.util.CloseVetoException e) {
122 log.println("couldn't close document");
123 } catch (com.sun.star.lang.DisposedException e) {
124 log.println("couldn't close document");
129 * Creates two components and inserts them to the form of
130 * text document. One component
131 * (<code>com.sun.star.form.component.RadioButton</code>) is created
132 * for testing, another to be passed as relation. Using a controller
133 * of the text document the controller of the first component is
134 * obtained and returned in environment as a test object. <p>
136 * Object relations created :
137 * <ul>
138 * <li> <code>'GRAPHICS'</code> for
139 * {@link ifc.awt._XView} : a graphics component
140 * created using screen device of the window peer of
141 * the controller tested. </li>
142 * <li> <code>'CONTEXT'</code> for
143 * {@link ifc.awt._XControl} : the text document
144 * where the component is inserted. </li>
145 * <li> <code>'WINPEER'</code> for
146 * {@link ifc.awt._XControl} : Window peer of the
147 * controller tested. </li>
148 * <li> <code>'TOOLKIT'</code> for
149 * {@link ifc.awt._XControl} : toolkit of the component.</li>
150 * <li> <code>'MODEL'</code> for
151 * {@link ifc.awt._XControl} : the model of the controller.</li>
152 * <li> <code>'XWindow.AnotherWindow'</code> for
153 * {@link ifc.awt._XWindow} : the controller of another
154 * component. </li>
155 * </ul>
157 protected TestEnvironment createTestEnvironment(TestParameters Param,
158 PrintWriter log) {
159 XInterface oObj = null;
160 XWindowPeer the_win = null;
161 XToolkit the_kit = null;
162 XDevice aDevice = null;
163 XGraphics aGraphic = null;
164 XControl aControl = null;
166 //Insert a ControlShape and get the ControlModel
167 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
168 4500, 15000, 10000,
169 "RadioButton");
171 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
173 XControlModel the_Model = aShape.getControl();
175 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
176 4500, 5000, 10000,
177 "TextField");
179 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2);
181 XControlModel the_Model2 = aShape2.getControl();
183 //Try to query XControlAccess
184 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
185 XControlAccess.class,
186 xTextDoc.getCurrentController());
188 //now get the ORadioButtonControl
189 try {
190 oObj = the_access.getControl(the_Model);
191 aControl = the_access.getControl(the_Model2);
192 the_win = the_access.getControl(the_Model).getPeer();
193 the_kit = the_win.getToolkit();
194 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
195 aGraphic = aDevice.createGraphics();
196 } catch (com.sun.star.container.NoSuchElementException e) {
197 log.println("Couldn't get ORadioButtonControl");
198 e.printStackTrace(log);
199 throw new StatusException("Couldn't get ORadioButtonControl", e);
202 log.println(
203 "creating a new environment for ORadioButtonControl 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);
223 return tEnv;
224 } // finish method getTestEnvironment
225 } // finish class ORadioButtonControl