bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / ORadioButtonControl.java
blobd15a961544a9c4f7e9c8eee76ee9f67a5a7217c6
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package mod._forms;
20 import java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.FormTools;
27 import util.SOfficeFactory;
28 import util.WriterTools;
30 import com.sun.star.awt.XControl;
31 import com.sun.star.awt.XControlModel;
32 import com.sun.star.awt.XDevice;
33 import com.sun.star.awt.XGraphics;
34 import com.sun.star.awt.XToolkit;
35 import com.sun.star.awt.XWindow;
36 import com.sun.star.awt.XWindowPeer;
37 import com.sun.star.drawing.XControlShape;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.text.XTextDocument;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
42 import com.sun.star.util.XCloseable;
43 import com.sun.star.view.XControlAccess;
46 /**
47 * Test for object which is represented by default controller
48 * of the <code>com.sun.star.form.component.RadioButton</code>
49 * component. <p>
51 * Object implements the following interfaces :
52 * <ul>
53 * <li> <code>com::sun::star::lang::XComponent</code></li>
54 * <li> <code>com::sun::star::awt::XWindow</code></li>
55 * <li> <code>com::sun::star::form::XBoundControl</code></li>
56 * <li> <code>com::sun::star::awt::XRadioButton</code></li>
57 * <li> <code>com::sun::star::awt::XControl</code></li>
58 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
59 * <li> <code>com::sun::star::awt::XView</code></li>
60 * </ul> <p>
61 * This object test <b> is NOT </b> designed to be run in several
62 * threads concurently.
64 * @see com.sun.star.lang.XComponent
65 * @see com.sun.star.awt.XWindow
66 * @see com.sun.star.form.XBoundControl
67 * @see com.sun.star.awt.XRadioButton
68 * @see com.sun.star.awt.XControl
69 * @see com.sun.star.awt.XLayoutConstrains
70 * @see com.sun.star.awt.XView
71 * @see ifc.lang._XComponent
72 * @see ifc.awt._XWindow
73 * @see ifc.form._XBoundControl
74 * @see ifc.awt._XRadioButton
75 * @see ifc.awt._XControl
76 * @see ifc.awt._XLayoutConstrains
77 * @see ifc.awt._XView
79 public class ORadioButtonControl extends TestCase {
80 XTextDocument xTextDoc;
82 /**
83 * Creates a new text document.
85 protected void initialize(TestParameters Param, PrintWriter log) {
86 SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) Param.getMSF()));
88 try {
89 log.println("creating a textdocument");
90 xTextDoc = SOF.createTextDoc(null);
91 } catch (com.sun.star.uno.Exception e) {
92 // Some exception occurs.FAILED
93 e.printStackTrace(log);
94 throw new StatusException("Couldn't create document", e);
98 /**
99 * Disposes the text document created before
101 protected void cleanup(TestParameters tParam, PrintWriter log) {
102 log.println(" disposing xTextDoc ");
104 try {
105 XCloseable closer = UnoRuntime.queryInterface(
106 XCloseable.class, xTextDoc);
107 closer.close(true);
108 } catch (com.sun.star.util.CloseVetoException e) {
109 log.println("couldn't close document");
110 } catch (com.sun.star.lang.DisposedException e) {
111 log.println("couldn't close document");
116 * Creates two components and inserts them to the form of
117 * text document. One component
118 * (<code>com.sun.star.form.component.RadioButton</code>) is created
119 * for testing, another to be passed as relation. Using a controller
120 * of the text document the controller of the first component is
121 * obtained and returned in environment as a test object. <p>
123 * Object relations created :
124 * <ul>
125 * <li> <code>'GRAPHICS'</code> for
126 * {@link ifc.awt._XView} : a graphics component
127 * created using screen device of the window peer of
128 * the controller tested. </li>
129 * <li> <code>'CONTEXT'</code> for
130 * {@link ifc.awt._XControl} : the text document
131 * where the component is inserted. </li>
132 * <li> <code>'WINPEER'</code> for
133 * {@link ifc.awt._XControl} : Window peer of the
134 * controller tested. </li>
135 * <li> <code>'TOOLKIT'</code> for
136 * {@link ifc.awt._XControl} : toolkit of the component.</li>
137 * <li> <code>'MODEL'</code> for
138 * {@link ifc.awt._XControl} : the model of the controller.</li>
139 * <li> <code>'XWindow.AnotherWindow'</code> for
140 * {@link ifc.awt._XWindow} : the controller of another
141 * component. </li>
142 * </ul>
144 protected TestEnvironment createTestEnvironment(TestParameters Param,
145 PrintWriter log) {
146 XInterface oObj = null;
147 XWindowPeer the_win = null;
148 XToolkit the_kit = null;
149 XDevice aDevice = null;
150 XGraphics aGraphic = null;
151 XControl aControl = null;
153 //Insert a ControlShape and get the ControlModel
154 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
155 4500, 15000, 10000,
156 "RadioButton");
158 WriterTools.getDrawPage(xTextDoc).add(aShape);
160 XControlModel the_Model = aShape.getControl();
162 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
163 4500, 5000, 10000,
164 "TextField");
166 WriterTools.getDrawPage(xTextDoc).add(aShape2);
168 XControlModel the_Model2 = aShape2.getControl();
170 //Try to query XControlAccess
171 XControlAccess the_access = UnoRuntime.queryInterface(
172 XControlAccess.class,
173 xTextDoc.getCurrentController());
175 //now get the ORadioButtonControl
176 try {
177 oObj = the_access.getControl(the_Model);
178 aControl = the_access.getControl(the_Model2);
179 the_win = the_access.getControl(the_Model).getPeer();
180 the_kit = the_win.getToolkit();
181 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
182 aGraphic = aDevice.createGraphics();
183 } catch (com.sun.star.container.NoSuchElementException e) {
184 log.println("Couldn't get ORadioButtonControl");
185 e.printStackTrace(log);
186 throw new StatusException("Couldn't get ORadioButtonControl", e);
189 log.println(
190 "creating a new environment for ORadioButtonControl object");
192 TestEnvironment tEnv = new TestEnvironment(oObj);
195 //Adding ObjRelation for XView
196 tEnv.addObjRelation("GRAPHICS", aGraphic);
199 //Adding ObjRelation for XControl
200 tEnv.addObjRelation("CONTEXT", xTextDoc);
201 tEnv.addObjRelation("WINPEER", the_win);
202 tEnv.addObjRelation("TOOLKIT", the_kit);
203 tEnv.addObjRelation("MODEL", the_Model);
205 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,
206 aControl);
208 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
210 return tEnv;
211 } // finish method getTestEnvironment
212 } // finish class ORadioButtonControl