bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / ORadioButtonControl.java
blob1cdda7745d53a4f8d92613e1ae6230bede87b681
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.text.XTextDocument;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
41 import com.sun.star.util.XCloseable;
42 import com.sun.star.view.XControlAccess;
45 /**
46 * Test for object which is represented by default controller
47 * of the <code>com.sun.star.form.component.RadioButton</code>
48 * component. <p>
50 * Object implements the following interfaces :
51 * <ul>
52 * <li> <code>com::sun::star::lang::XComponent</code></li>
53 * <li> <code>com::sun::star::awt::XWindow</code></li>
54 * <li> <code>com::sun::star::form::XBoundControl</code></li>
55 * <li> <code>com::sun::star::awt::XRadioButton</code></li>
56 * <li> <code>com::sun::star::awt::XControl</code></li>
57 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
58 * <li> <code>com::sun::star::awt::XView</code></li>
59 * </ul> <p>
60 * This object test <b> is NOT </b> designed to be run in several
61 * threads concurently.
63 * @see com.sun.star.lang.XComponent
64 * @see com.sun.star.awt.XWindow
65 * @see com.sun.star.form.XBoundControl
66 * @see com.sun.star.awt.XRadioButton
67 * @see com.sun.star.awt.XControl
68 * @see com.sun.star.awt.XLayoutConstrains
69 * @see com.sun.star.awt.XView
70 * @see ifc.lang._XComponent
71 * @see ifc.awt._XWindow
72 * @see ifc.form._XBoundControl
73 * @see ifc.awt._XRadioButton
74 * @see ifc.awt._XControl
75 * @see ifc.awt._XLayoutConstrains
76 * @see ifc.awt._XView
78 public class ORadioButtonControl extends TestCase {
79 XTextDocument xTextDoc;
81 /**
82 * Creates a new text document.
84 @Override
85 protected void initialize(TestParameters Param, PrintWriter log) {
86 SOfficeFactory SOF = SOfficeFactory.getFactory((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 @Override
102 protected void cleanup(TestParameters tParam, PrintWriter log) {
103 log.println(" disposing xTextDoc ");
105 try {
106 XCloseable closer = UnoRuntime.queryInterface(
107 XCloseable.class, xTextDoc);
108 closer.close(true);
109 } catch (com.sun.star.util.CloseVetoException e) {
110 log.println("couldn't close document");
111 } catch (com.sun.star.lang.DisposedException e) {
112 log.println("couldn't close document");
117 * Creates two components and inserts them to the form of
118 * text document. One component
119 * (<code>com.sun.star.form.component.RadioButton</code>) is created
120 * for testing, another to be passed as relation. Using a controller
121 * of the text document the controller of the first component is
122 * obtained and returned in environment as a test object. <p>
124 * Object relations created :
125 * <ul>
126 * <li> <code>'GRAPHICS'</code> for
127 * {@link ifc.awt._XView} : a graphics component
128 * created using screen device of the window peer of
129 * the controller tested. </li>
130 * <li> <code>'CONTEXT'</code> for
131 * {@link ifc.awt._XControl} : the text document
132 * where the component is inserted. </li>
133 * <li> <code>'WINPEER'</code> for
134 * {@link ifc.awt._XControl} : Window peer of the
135 * controller tested. </li>
136 * <li> <code>'TOOLKIT'</code> for
137 * {@link ifc.awt._XControl} : toolkit of the component.</li>
138 * <li> <code>'MODEL'</code> for
139 * {@link ifc.awt._XControl} : the model of the controller.</li>
140 * <li> <code>'XWindow.AnotherWindow'</code> for
141 * {@link ifc.awt._XWindow} : the controller of another
142 * component. </li>
143 * </ul>
145 @Override
146 protected TestEnvironment createTestEnvironment(TestParameters Param,
147 PrintWriter log) {
148 XInterface oObj = null;
149 XWindowPeer the_win = null;
150 XToolkit the_kit = null;
151 XDevice aDevice = null;
152 XGraphics aGraphic = null;
153 XControl aControl = null;
155 //Insert a ControlShape and get the ControlModel
156 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
157 4500, 15000, 10000,
158 "RadioButton");
160 WriterTools.getDrawPage(xTextDoc).add(aShape);
162 XControlModel the_Model = aShape.getControl();
164 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
165 4500, 5000, 10000,
166 "TextField");
168 WriterTools.getDrawPage(xTextDoc).add(aShape2);
170 XControlModel the_Model2 = aShape2.getControl();
172 //Try to query XControlAccess
173 XControlAccess the_access = UnoRuntime.queryInterface(
174 XControlAccess.class,
175 xTextDoc.getCurrentController());
177 //now get the ORadioButtonControl
178 try {
179 oObj = the_access.getControl(the_Model);
180 aControl = the_access.getControl(the_Model2);
181 the_win = the_access.getControl(the_Model).getPeer();
182 the_kit = the_win.getToolkit();
183 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
184 aGraphic = aDevice.createGraphics();
185 } catch (com.sun.star.container.NoSuchElementException e) {
186 log.println("Couldn't get ORadioButtonControl");
187 e.printStackTrace(log);
188 throw new StatusException("Couldn't get ORadioButtonControl", e);
191 log.println(
192 "creating a new environment for ORadioButtonControl object");
194 TestEnvironment tEnv = new TestEnvironment(oObj);
197 //Adding ObjRelation for XView
198 tEnv.addObjRelation("GRAPHICS", aGraphic);
201 //Adding ObjRelation for XControl
202 tEnv.addObjRelation("CONTEXT", xTextDoc);
203 tEnv.addObjRelation("WINPEER", the_win);
204 tEnv.addObjRelation("TOOLKIT", the_kit);
205 tEnv.addObjRelation("MODEL", the_Model);
207 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,
208 aControl);
210 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
212 return tEnv;
213 } // finish method getTestEnvironment
214 } // finish class ORadioButtonControl