merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / form / _XFormController.java
blobb54857e334e37eef706d953986cd1e3bdac916ee
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: _XFormController.java,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
31 package ifc.form;
33 import lib.MultiMethodTest;
35 import com.sun.star.awt.XControl;
36 import com.sun.star.awt.XWindow;
37 import com.sun.star.form.XFormController;
38 import com.sun.star.form.XFormControllerListener;
39 import com.sun.star.lang.EventObject;
40 import com.sun.star.uno.UnoRuntime;
42 /**
43 * Testing <code>com.sun.star.form.XFormController</code>
44 * interface methods :
45 * <ul>
46 * <li><code> getCurrentControl()</code></li>
47 * <li><code> addActivateListener()</code></li>
48 * <li><code> removeActivateListener()</code></li>
49 * </ul> <p>
50 * This test needs the following object relations :
51 * <ul>
52 * <li> <code>'otherWindow'</code>
53 * (of type <code>com.sun.star.awt.XWindow</code>):
54 * The another window is used to activate it, causing deactivating
55 * of the component tested. </li>
56 * <ul> <p>
57 * Test is <b> NOT </b> multithread compilant. <p>
58 * @see com.sun.star.form.XFormController
60 public class _XFormController extends MultiMethodTest {
62 public static XFormController oObj = null;
63 XWindow otherWind = null;
65 /**
66 * Listener which determines and stores events occured.
68 protected class MyListener implements XFormControllerListener {
69 public boolean activated = false ;
70 public boolean deactivated = false ;
71 public void disposing ( EventObject oEvent ) {}
73 public void init() {
74 activated = false;
75 deactivated = false;
78 public void formActivated(EventObject ev) {
79 activated = true ;
82 public void formDeactivated(EventObject ev) {
83 deactivated = true ;
87 MyListener listener = new MyListener() ;
89 /**
90 * Adds a listener, then switches focus between two windows.
91 * The current controller must be deactivated and activated.<p>
93 * Has <b> OK </b> status if listener <code>deactivate</code>
94 * and <code>activate</code> methods was called. <p>
96 public void _addActivateListener() {
97 requiredMethod("getCurrentControl()");
98 oObj.addActivateListener(listener) ;
100 XWindow wind = (XWindow)UnoRuntime.queryInterface(XWindow.class, cntrl);
101 wind.setFocus();
102 shortWait();
103 XWindow otherWind = (XWindow)tEnv.getObjRelation("otherWindow");
104 otherWind.setFocus();
105 shortWait();
106 log.println("activated = " + listener.activated +
107 ", deactivated = " + listener.deactivated) ;
109 tRes.tested("addActivateListener()",
110 listener.deactivated && listener.activated) ;
114 * Removes the litener added before, then switches focus between two windows.
116 * Has <b> OK </b> status if no listener methods were called. <p>
118 public void _removeActivateListener() {
119 requiredMethod("addActivateListener()") ;
121 oObj.removeActivateListener(listener);
122 log.println("ActiveListener removed");
123 listener.init();
125 XWindow wind = (XWindow)UnoRuntime.queryInterface(XWindow.class, cntrl);
126 wind.setFocus();
127 shortWait();
128 XWindow otherWind = (XWindow)tEnv.getObjRelation("otherWindow");
129 otherWind.setFocus();
130 shortWait();
131 log.println("activated = " + listener.activated +
132 ", deactivated = " + listener.deactivated) ;
134 tRes.tested("removeActivateListener()",
135 !listener.activated && !listener.deactivated);
138 XControl cntrl;
141 * Retrieves current control and searches for it among child controls.
143 * Has <b>OK</b> status if the current control was found among component
144 * children.
146 public void _getCurrentControl() {
147 cntrl = oObj.getCurrentControl();
148 XControl[] children = oObj.getControls() ;
150 boolean res = false;
151 for(int i = 0; i < children.length; i++) {
152 if (children[i].equals(cntrl)) {
153 log.println("Current control is equal to the object control" +
154 " #" + i + ":");
155 log.println(cntrl);
156 res = true;
157 break;
161 tRes.tested("getCurrentControl()", res) ;
165 * Sleeps for 0.2 sec. to allow StarOffice to react on <code>
166 * reset</code> call.
168 private void shortWait() {
169 try {
170 Thread.sleep(1000) ;
171 } catch (InterruptedException e) {
172 System.out.println("While waiting :" + e) ;