Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / form / _XFormController.java
bloba2175b253b04552173dc1dcea1162e762f680370
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package ifc.form;
30 import lib.MultiMethodTest;
32 import com.sun.star.awt.XControl;
33 import com.sun.star.awt.XWindow;
34 import com.sun.star.form.XFormController;
35 import com.sun.star.form.XFormControllerListener;
36 import com.sun.star.lang.EventObject;
37 import com.sun.star.uno.UnoRuntime;
39 /**
40 * Testing <code>com.sun.star.form.XFormController</code>
41 * interface methods :
42 * <ul>
43 * <li><code> getCurrentControl()</code></li>
44 * <li><code> addActivateListener()</code></li>
45 * <li><code> removeActivateListener()</code></li>
46 * </ul> <p>
47 * This test needs the following object relations :
48 * <ul>
49 * <li> <code>'otherWindow'</code>
50 * (of type <code>com.sun.star.awt.XWindow</code>):
51 * The another window is used to activate it, causing deactivating
52 * of the component tested. </li>
53 * <ul> <p>
54 * Test is <b> NOT </b> multithread compilant. <p>
55 * @see com.sun.star.form.XFormController
57 public class _XFormController extends MultiMethodTest {
59 public static XFormController oObj = null;
60 XWindow otherWind = null;
62 /**
63 * Listener which determines and stores events occurred.
65 protected class MyListener implements XFormControllerListener {
66 public boolean activated = false ;
67 public boolean deactivated = false ;
68 public void disposing ( EventObject oEvent ) {}
70 public void init() {
71 activated = false;
72 deactivated = false;
75 public void formActivated(EventObject ev) {
76 activated = true ;
79 public void formDeactivated(EventObject ev) {
80 deactivated = true ;
84 MyListener listener = new MyListener() ;
86 /**
87 * Adds a listener, then switches focus between two windows.
88 * The current controller must be deactivated and activated.<p>
90 * Has <b> OK </b> status if listener <code>deactivate</code>
91 * and <code>activate</code> methods was called. <p>
93 public void _addActivateListener() {
94 requiredMethod("getCurrentControl()");
95 oObj.addActivateListener(listener) ;
97 XWindow wind = (XWindow)UnoRuntime.queryInterface(XWindow.class, cntrl);
98 wind.setFocus();
99 shortWait();
100 XWindow otherWind = (XWindow)tEnv.getObjRelation("otherWindow");
101 otherWind.setFocus();
102 shortWait();
103 log.println("activated = " + listener.activated +
104 ", deactivated = " + listener.deactivated) ;
106 tRes.tested("addActivateListener()",
107 listener.deactivated && listener.activated) ;
111 * Removes the litener added before, then switches focus between two windows.
113 * Has <b> OK </b> status if no listener methods were called. <p>
115 public void _removeActivateListener() {
116 requiredMethod("addActivateListener()") ;
118 oObj.removeActivateListener(listener);
119 log.println("ActiveListener removed");
120 listener.init();
122 XWindow wind = (XWindow)UnoRuntime.queryInterface(XWindow.class, cntrl);
123 wind.setFocus();
124 shortWait();
125 XWindow otherWind = (XWindow)tEnv.getObjRelation("otherWindow");
126 otherWind.setFocus();
127 shortWait();
128 log.println("activated = " + listener.activated +
129 ", deactivated = " + listener.deactivated) ;
131 tRes.tested("removeActivateListener()",
132 !listener.activated && !listener.deactivated);
135 XControl cntrl;
138 * Retrieves current control and searches for it among child controls.
140 * Has <b>OK</b> status if the current control was found among component
141 * children.
143 public void _getCurrentControl() {
144 cntrl = oObj.getCurrentControl();
145 XControl[] children = oObj.getControls() ;
147 boolean res = false;
148 for(int i = 0; i < children.length; i++) {
149 if (children[i].equals(cntrl)) {
150 log.println("Current control is equal to the object control" +
151 " #" + i + ":");
152 log.println(cntrl);
153 res = true;
154 break;
158 tRes.tested("getCurrentControl()", res) ;
162 * Sleeps for 0.2 sec. to allow StarOffice to react on <code>
163 * reset</code> call.
165 private void shortWait() {
166 try {
167 Thread.sleep(1000) ;
168 } catch (InterruptedException e) {
169 System.out.println("While waiting :" + e) ;