Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / mod / _forms / OComboBoxControl.java
blob15ee26c5ff40dfbb5f047d8b1763306c9a2df6a7
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: OComboBoxControl.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.XTextComponent;
47 import com.sun.star.awt.XToolkit;
48 import com.sun.star.awt.XWindow;
49 import com.sun.star.awt.XWindowPeer;
50 import com.sun.star.drawing.XControlShape;
51 import com.sun.star.drawing.XShape;
52 import com.sun.star.lang.XMultiServiceFactory;
53 import com.sun.star.text.XTextDocument;
54 import com.sun.star.uno.UnoRuntime;
55 import com.sun.star.uno.XInterface;
56 import com.sun.star.util.XCloseable;
57 import com.sun.star.view.XControlAccess;
60 /**
61 * Test for object which is represented by default controller
62 * of the <code>com.sun.star.form.component.ComboBox</code>
63 * component. <p>
65 * Object implements the following interfaces :
66 * <ul>
67 * <li> <code>com::sun::star::awt::XView</code></li>
68 * <li> <code>com::sun::star::form::XBoundControl</code></li>
69 * <li> <code>com::sun::star::awt::XControl</code></li>
70 * <li> <code>com::sun::star::awt::XTextComponent</code></li>
71 * <li> <code>com::sun::star::awt::XComboBox</code></li>
72 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
73 * <li> <code>com::sun::star::awt::XTextListener</code></li>
74 * <li> <code>com::sun::star::awt::XWindow</code></li>
75 * <li> <code>com::sun::star::lang::XComponent</code></li>
76 * <li> <code>com::sun::star::awt::XTextLayoutConstrains</code></li>
77 * <li> <code>com::sun::star::lang::XEventListener</code></li>
78 * </ul> <p>
79 * This object test <b> is NOT </b> designed to be run in several
80 * threads concurently.
82 * @see com.sun.star.awt.XView
83 * @see com.sun.star.form.XBoundControl
84 * @see com.sun.star.awt.XControl
85 * @see com.sun.star.awt.XTextComponent
86 * @see com.sun.star.awt.XComboBox
87 * @see com.sun.star.awt.XLayoutConstrains
88 * @see com.sun.star.awt.XTextListener
89 * @see com.sun.star.awt.XWindow
90 * @see com.sun.star.lang.XComponent
91 * @see com.sun.star.awt.XTextLayoutConstrains
92 * @see com.sun.star.lang.XEventListener
93 * @see ifc.awt._XView
94 * @see ifc.form._XBoundControl
95 * @see ifc.awt._XControl
96 * @see ifc.awt._XTextComponent
97 * @see ifc.awt._XComboBox
98 * @see ifc.awt._XLayoutConstrains
99 * @see ifc.awt._XTextListener
100 * @see ifc.awt._XWindow
101 * @see ifc.lang._XComponent
102 * @see ifc.awt._XTextLayoutConstrains
103 * @see ifc.lang._XEventListener
105 public class OComboBoxControl extends TestCase {
106 XTextDocument xTextDoc;
109 * Creates a new text document.
111 protected void initialize(TestParameters Param, PrintWriter log) {
112 SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) Param.getMSF()));
114 try {
115 log.println("creating a textdocument");
116 xTextDoc = SOF.createTextDoc(null);
117 } catch (com.sun.star.uno.Exception e) {
118 // Some exception occures.FAILED
119 e.printStackTrace(log);
120 throw new StatusException("Couldn't create document", e);
125 * Disposes the text document created before
127 protected void cleanup(TestParameters tParam, PrintWriter log) {
128 log.println(" disposing xTextDoc ");
130 try {
131 XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
132 XCloseable.class, xTextDoc);
133 closer.close(true);
134 } catch (com.sun.star.util.CloseVetoException e) {
135 log.println("couldn't close document");
136 } catch (com.sun.star.lang.DisposedException e) {
137 log.println("couldn't close document");
142 * Creates two components and inserts them to the form of
143 * text document. One component
144 * (<code>com.sun.star.form.component.ComboBox</code>) is created
145 * for testing, another to be passed as relation. Using a controller
146 * of the text document the controller of the first component is
147 * obtained and returned in environment as a test object. <p>
149 * Object relations created :
150 * <ul>
151 * <li> <code>'GRAPHICS'</code> for
152 * {@link ifc.awt._XView} : a graphics component
153 * created using screen device of the window peer of
154 * the controller tested. </li>
155 * <li> <code>'CONTEXT'</code> for
156 * {@link ifc.awt._XControl} : the text document
157 * where the component is inserted. </li>
158 * <li> <code>'WINPEER'</code> for
159 * {@link ifc.awt._XControl} : Window peer of the
160 * controller tested. </li>
161 * <li> <code>'TOOLKIT'</code> for
162 * {@link ifc.awt._XControl} : toolkit of the component.</li>
163 * <li> <code>'MODEL'</code> for
164 * {@link ifc.awt._XControl} : the model of the controller.</li>
165 * <li> <code>'XWindow.AnotherWindow'</code> for
166 * {@link ifc.awt._XWindow} : the controller of another
167 * component. </li>
168 * </ul>
170 protected TestEnvironment createTestEnvironment(TestParameters Param,
171 PrintWriter log) {
172 XInterface oObj = null;
173 XWindowPeer the_win = null;
174 XToolkit the_kit = null;
175 XDevice aDevice = null;
176 XGraphics aGraphic = null;
177 XControl aControl = null;
179 //Insert a ControlShape and get the ControlModel
180 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
181 4500, 15000, 10000,
182 "ComboBox");
184 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
186 XControlModel the_Model = aShape.getControl();
188 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
189 4500, 5000, 10000,
190 "TextField");
192 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2);
194 XControlModel the_Model2 = aShape2.getControl();
196 //Try to query XControlAccess
197 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
198 XControlAccess.class,
199 xTextDoc.getCurrentController());
201 //now get the OButtonControl
202 try {
203 oObj = the_access.getControl(the_Model);
204 aControl = the_access.getControl(the_Model2);
205 the_win = the_access.getControl(the_Model).getPeer();
206 the_kit = the_win.getToolkit();
207 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
208 aGraphic = aDevice.createGraphics();
209 } catch (com.sun.star.container.NoSuchElementException e) {
210 log.println("Couldn't get OCheckBoxControl");
211 e.printStackTrace(log);
212 throw new StatusException("Couldn't get OComboBoxControl", e);
215 log.println("creating a new environment for OComboBoxControl object");
217 TestEnvironment tEnv = new TestEnvironment(oObj);
220 //Adding ObjRelation for XView
221 tEnv.addObjRelation("GRAPHICS", aGraphic);
224 //Adding ObjRelation for XControl
225 tEnv.addObjRelation("CONTEXT", xTextDoc);
226 tEnv.addObjRelation("WINPEER", the_win);
227 tEnv.addObjRelation("TOOLKIT", the_kit);
228 tEnv.addObjRelation("MODEL", the_Model);
230 // Adding relation for XWindow
231 XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class,
232 aControl);
234 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
235 tEnv.addObjRelation("XWindow.ControlShape", aShape);
237 // Adding relation for XTextListener
238 ifc.awt._XTextListener.TestTextListener listener =
239 new ifc.awt._XTextListener.TestTextListener();
240 XTextComponent textComp = (XTextComponent) UnoRuntime.queryInterface(
241 XTextComponent.class, oObj);
242 textComp.addTextListener(listener);
243 tEnv.addObjRelation("TestTextListener", listener);
245 return tEnv;
246 } // finish method getTestEnvironment
247 } // finish class OButtonControl