1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package ifc.awt;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import com.sun.star.awt.FocusEvent;
31*cdf0e10cSrcweir import com.sun.star.awt.KeyEvent;
32*cdf0e10cSrcweir import com.sun.star.awt.MouseEvent;
33*cdf0e10cSrcweir import com.sun.star.awt.PaintEvent;
34*cdf0e10cSrcweir import com.sun.star.awt.Point;
35*cdf0e10cSrcweir import com.sun.star.awt.PosSize;
36*cdf0e10cSrcweir import com.sun.star.awt.Rectangle;
37*cdf0e10cSrcweir import com.sun.star.awt.Size;
38*cdf0e10cSrcweir import com.sun.star.awt.WindowEvent;
39*cdf0e10cSrcweir import com.sun.star.awt.XFocusListener;
40*cdf0e10cSrcweir import com.sun.star.awt.XKeyListener;
41*cdf0e10cSrcweir import com.sun.star.awt.XMouseListener;
42*cdf0e10cSrcweir import com.sun.star.awt.XMouseMotionListener;
43*cdf0e10cSrcweir import com.sun.star.awt.XPaintListener;
44*cdf0e10cSrcweir import com.sun.star.awt.XWindow;
45*cdf0e10cSrcweir import com.sun.star.awt.XWindowListener;
46*cdf0e10cSrcweir import com.sun.star.drawing.XControlShape;
47*cdf0e10cSrcweir import com.sun.star.lang.EventObject;
48*cdf0e10cSrcweir import lib.MultiMethodTest;
49*cdf0e10cSrcweir import util.ValueComparer;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir /**
52*cdf0e10cSrcweir * Testing <code>com.sun.star.awt.XWindow</code>
53*cdf0e10cSrcweir * interface methods :
54*cdf0e10cSrcweir * <ul>
55*cdf0e10cSrcweir *  <li><code> setPosSize()</code></li>
56*cdf0e10cSrcweir *  <li><code> getPosSize()</code></li>
57*cdf0e10cSrcweir *  <li><code> setVisible()</code></li>
58*cdf0e10cSrcweir *  <li><code> setEnable()</code></li>
59*cdf0e10cSrcweir *  <li><code> setFocus()</code></li>
60*cdf0e10cSrcweir *  <li><code> addWindowListener()</code></li>
61*cdf0e10cSrcweir *  <li><code> removeWindowListener()</code></li>
62*cdf0e10cSrcweir *  <li><code> addFocusListener()</code></li>
63*cdf0e10cSrcweir *  <li><code> removeFocusListener()</code></li>
64*cdf0e10cSrcweir *  <li><code> addKeyListener()</code></li>
65*cdf0e10cSrcweir *  <li><code> removeKeyListener()</code></li>
66*cdf0e10cSrcweir *  <li><code> addMouseListener()</code></li>
67*cdf0e10cSrcweir *  <li><code> removeMouseListener()</code></li>
68*cdf0e10cSrcweir *  <li><code> addMouseMotionListener()</code></li>
69*cdf0e10cSrcweir *  <li><code> removeMouseMotionListener()</code></li>
70*cdf0e10cSrcweir *  <li><code> addPaintListener()</code></li>
71*cdf0e10cSrcweir *  <li><code> removePaintListener()</code></li>
72*cdf0e10cSrcweir * </ul> <p>
73*cdf0e10cSrcweir * This test needs the following object relations :
74*cdf0e10cSrcweir * <ul>
75*cdf0e10cSrcweir *  <li> <code>'XWindow.AnotherWindow'</code> (of type <code>XWindow</code>):
76*cdf0e10cSrcweir *   Some another window which can gain focus so the tested one
77*cdf0e10cSrcweir *   must lost it. </li>
78*cdf0e10cSrcweir *  <li> <code>'XWindow.ControlShape'</code> <b>optional</b>
79*cdf0e10cSrcweir *   (of type <code>XControlShape</code>):
80*cdf0e10cSrcweir *   Some shapes cann't change their size within fixed ControlShape
81*cdf0e10cSrcweir *   and their size could be changed only if size of container
82*cdf0e10cSrcweir *   ControlShape is changed. For such shapes this relation should
83*cdf0e10cSrcweir *   be passed for proper <code>addWindowListener</code> test. </li>
84*cdf0e10cSrcweir * </ul> <p>
85*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
86*cdf0e10cSrcweir * @see com.sun.star.awt.XWindow
87*cdf0e10cSrcweir */
88*cdf0e10cSrcweir public class _XWindow extends MultiMethodTest {
89*cdf0e10cSrcweir     public XWindow oObj = null;
90*cdf0e10cSrcweir     private Rectangle posSize = null ;
91*cdf0e10cSrcweir     private XWindow win = null;
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir     /**
94*cdf0e10cSrcweir     * Test calls the method. <p>
95*cdf0e10cSrcweir     * Has <b> OK </b> status if the method does not return null.
96*cdf0e10cSrcweir     */
97*cdf0e10cSrcweir     public void _getPosSize() {
98*cdf0e10cSrcweir         posSize = oObj.getPosSize() ;
99*cdf0e10cSrcweir         tRes.tested("getPosSize()", posSize != null) ;
100*cdf0e10cSrcweir     }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir     /**
103*cdf0e10cSrcweir     * After defining Rectangle structure to be set, test calls the method. <p>
104*cdf0e10cSrcweir     * Has <b> OK </b> status if structure obtained using getPosSize() is
105*cdf0e10cSrcweir     * equal to structure previously set using setPosSize(). <p>
106*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
107*cdf0e10cSrcweir     * <ul>
108*cdf0e10cSrcweir     *  <li> <code> getPosSize() </code> :  returns the outer bounds of
109*cdf0e10cSrcweir     *  the window </li>
110*cdf0e10cSrcweir     * </ul>
111*cdf0e10cSrcweir     */
112*cdf0e10cSrcweir     public void _setPosSize() {
113*cdf0e10cSrcweir         Rectangle newRec = new Rectangle();
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir         requiredMethod("getPosSize()");
116*cdf0e10cSrcweir         newRec.X = posSize.X + 1;
117*cdf0e10cSrcweir         newRec.Y = posSize.Y + 1;
118*cdf0e10cSrcweir         newRec.Width = posSize.Width - 3;
119*cdf0e10cSrcweir         newRec.Height = posSize.Height - 3;
120*cdf0e10cSrcweir         oObj.setPosSize(newRec.X, newRec.Y, newRec.Width, newRec.Height,
121*cdf0e10cSrcweir             PosSize.POSSIZE);
122*cdf0e10cSrcweir         Rectangle gPS = oObj.getPosSize();
123*cdf0e10cSrcweir         log.println("Was : (" + posSize.X + ", " + posSize.Y + ", " +
124*cdf0e10cSrcweir             posSize.Width + ", " + posSize.Height + "), ");
125*cdf0e10cSrcweir         log.println("Set : (" + newRec.X + ", " + newRec.Y + ", " +
126*cdf0e10cSrcweir             newRec.Width + ", " + newRec.Height + "), ");
127*cdf0e10cSrcweir         log.println("Get : (" + gPS.X + ", " + gPS.Y + ", " +
128*cdf0e10cSrcweir             gPS.Width + ", " + gPS.Height + "). ");
129*cdf0e10cSrcweir         tRes.tested("setPosSize()", ValueComparer.equalValue(newRec, gPS) );
130*cdf0e10cSrcweir     }
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir     /**
133*cdf0e10cSrcweir     * At first object relation 'XWindow.AnotherWindow' is obtained.
134*cdf0e10cSrcweir     * Then test calls the methods of two 'XWindow' objects several times to be
135*cdf0e10cSrcweir     * sure that the focus has changed. <p>
136*cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns
137*cdf0e10cSrcweir     * and no exceptions were thrown.
138*cdf0e10cSrcweir     */
139*cdf0e10cSrcweir     public void _setFocus() {
140*cdf0e10cSrcweir         win = (XWindow) tEnv.getObjRelation("XWindow.AnotherWindow");
141*cdf0e10cSrcweir         oObj.setFocus();
142*cdf0e10cSrcweir         win.setFocus();
143*cdf0e10cSrcweir         oObj.setFocus();
144*cdf0e10cSrcweir         tRes.tested("setFocus()", true);
145*cdf0e10cSrcweir     }
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir     /**
148*cdf0e10cSrcweir     * Test calls the method twice with two parameters: 'true' and 'false'. <p>
149*cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns
150*cdf0e10cSrcweir     * and no exceptions were thrown.
151*cdf0e10cSrcweir     */
152*cdf0e10cSrcweir     public void _setVisible() {
153*cdf0e10cSrcweir         oObj.setVisible(false);
154*cdf0e10cSrcweir         oObj.setVisible(true);
155*cdf0e10cSrcweir         tRes.tested("setVisible()", true);
156*cdf0e10cSrcweir     }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir     /**
159*cdf0e10cSrcweir     * Test calls the method twice with two parameters: 'true' and 'false'. <p>
160*cdf0e10cSrcweir     * Has <b> OK </b> status if the method successfully returns
161*cdf0e10cSrcweir     * and no exceptions were thrown.
162*cdf0e10cSrcweir     */
163*cdf0e10cSrcweir     public void _setEnable() {
164*cdf0e10cSrcweir         oObj.setEnable(false);
165*cdf0e10cSrcweir         oObj.setEnable(true);
166*cdf0e10cSrcweir         tRes.tested("setEnable()", true);
167*cdf0e10cSrcweir     }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir     /**
171*cdf0e10cSrcweir     * A class we use to test addWindowListener() and
172*cdf0e10cSrcweir     * removeWindowListener()
173*cdf0e10cSrcweir     */
174*cdf0e10cSrcweir     public class TestWindowListener implements XWindowListener {
175*cdf0e10cSrcweir         public boolean resized = false ;
176*cdf0e10cSrcweir         public boolean moved = false ;
177*cdf0e10cSrcweir         public boolean hidden = false ;
178*cdf0e10cSrcweir         public boolean shown = false ;
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir         public void init() {
181*cdf0e10cSrcweir             resized = false ;
182*cdf0e10cSrcweir             moved = false ;
183*cdf0e10cSrcweir             hidden = false ;
184*cdf0e10cSrcweir             shown = false ;
185*cdf0e10cSrcweir         }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir         public void windowResized(WindowEvent e) {
188*cdf0e10cSrcweir             resized = true ;
189*cdf0e10cSrcweir         }
190*cdf0e10cSrcweir         public void windowMoved(WindowEvent e) {
191*cdf0e10cSrcweir             moved = true ;
192*cdf0e10cSrcweir         }
193*cdf0e10cSrcweir         public void windowHidden(EventObject e) {
194*cdf0e10cSrcweir             hidden = true ;
195*cdf0e10cSrcweir         }
196*cdf0e10cSrcweir         public void windowShown(EventObject e) {
197*cdf0e10cSrcweir             shown = true ;
198*cdf0e10cSrcweir         }
199*cdf0e10cSrcweir         public void disposing(EventObject e) {}
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir     }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir     private TestWindowListener wListener = new TestWindowListener() ;
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir     /**
207*cdf0e10cSrcweir     * Test calls the method. Then we check if listener's methods were called
208*cdf0e10cSrcweir     * when we move, resize, hide and show the window. The resizing is
209*cdf0e10cSrcweir     * performed depending on 'XWindow.ControlShape' existance. If this
210*cdf0e10cSrcweir     * relation exists then the size and position of container control
211*cdf0e10cSrcweir     * shape is changed, else the position and size of window itself is
212*cdf0e10cSrcweir     * chaged<p>
213*cdf0e10cSrcweir     *
214*cdf0e10cSrcweir     * Has <b> OK </b> status if methods of wListener were called when
215*cdf0e10cSrcweir     * corresponding events occured. <p>
216*cdf0e10cSrcweir     *
217*cdf0e10cSrcweir     * The following method tests are to be executed before :
218*cdf0e10cSrcweir     * <ul>
219*cdf0e10cSrcweir     *  <li> <code> setPosSize() </code>: sets the outer bounds of the
220*cdf0e10cSrcweir     *  window</li>
221*cdf0e10cSrcweir     *  <li> <code> setVisible() </code>: shows or hides the window
222*cdf0e10cSrcweir     *  depending on the parameter</li>
223*cdf0e10cSrcweir     * </ul>
224*cdf0e10cSrcweir     */
225*cdf0e10cSrcweir     public void _addWindowListener() {
226*cdf0e10cSrcweir         executeMethod("setPosSize()");
227*cdf0e10cSrcweir         executeMethod("setVisible()");
228*cdf0e10cSrcweir         boolean result = true ;
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir         oObj.addWindowListener(wListener);
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir         // testing wListener.windowMoved()
233*cdf0e10cSrcweir         XControlShape ctrlShape = (XControlShape)
234*cdf0e10cSrcweir             tEnv.getObjRelation("XWindow.ControlShape");
235*cdf0e10cSrcweir         log.println("change object position and size...");
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir         if (ctrlShape != null) {
238*cdf0e10cSrcweir             try {
239*cdf0e10cSrcweir                 Size sz = ctrlShape.getSize();
240*cdf0e10cSrcweir                 sz.Height += 100;
241*cdf0e10cSrcweir                 ctrlShape.setSize(sz);
242*cdf0e10cSrcweir                 Point pos = ctrlShape.getPosition();
243*cdf0e10cSrcweir                 pos.X += 100 ;
244*cdf0e10cSrcweir                 ctrlShape.setPosition(pos);
245*cdf0e10cSrcweir             } catch (com.sun.star.beans.PropertyVetoException e) {
246*cdf0e10cSrcweir                 log.println("Couldn't change size or position: ");
247*cdf0e10cSrcweir                 e.printStackTrace(log);
248*cdf0e10cSrcweir             }
249*cdf0e10cSrcweir         } else {
250*cdf0e10cSrcweir             oObj.setPosSize(posSize.X + 2, 0, 0, 0, PosSize.X);
251*cdf0e10cSrcweir             oObj.setPosSize(0, 0, 100, 100, PosSize.WIDTH);
252*cdf0e10cSrcweir         }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir         shortWait();
255*cdf0e10cSrcweir         boolean res = wListener.resized && wListener.moved &&
256*cdf0e10cSrcweir             !wListener.hidden && !wListener.shown;
257*cdf0e10cSrcweir         result &= res;
258*cdf0e10cSrcweir         if (!res) {
259*cdf0e10cSrcweir             log.println("\twindowHidden()  wasn't called: " + !wListener.hidden);
260*cdf0e10cSrcweir             log.println("\twindowShown()   wasn't called: " + !wListener.shown);
261*cdf0e10cSrcweir             log.println("\twindowResized()    was called: " + wListener.resized);
262*cdf0e10cSrcweir             log.println("\twindowMoved()      was called: " + wListener.moved);
263*cdf0e10cSrcweir         } else {
264*cdf0e10cSrcweir             log.println("windowMoved() and windowResized() was called");
265*cdf0e10cSrcweir         }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir         // testing wListener.windowHidden()
268*cdf0e10cSrcweir         wListener.init();
269*cdf0e10cSrcweir         shortWait();
270*cdf0e10cSrcweir         log.println("set object invisible...");
271*cdf0e10cSrcweir         oObj.setVisible(false);
272*cdf0e10cSrcweir         shortWait();
273*cdf0e10cSrcweir         res = wListener.hidden && !wListener.resized
274*cdf0e10cSrcweir                         && !wListener.moved && !wListener.shown;
275*cdf0e10cSrcweir         result &= res;
276*cdf0e10cSrcweir         if (!res) {
277*cdf0e10cSrcweir             log.println("\twindowHidden()     was called: " + wListener.hidden);
278*cdf0e10cSrcweir             log.println("\twindowShown()   wasn't called: " + !wListener.shown);
279*cdf0e10cSrcweir             log.println("\twindowResized() wasn't called: " + !wListener.resized);
280*cdf0e10cSrcweir             log.println("\twindowMoved()   wasn't called: " + !wListener.moved);
281*cdf0e10cSrcweir         } else {
282*cdf0e10cSrcweir             log.println("windowHidden() was called");
283*cdf0e10cSrcweir         }
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir         // testing wListener.windowShown()
286*cdf0e10cSrcweir         wListener.init() ;
287*cdf0e10cSrcweir         shortWait();
288*cdf0e10cSrcweir         log.println("set object visible...");
289*cdf0e10cSrcweir         oObj.setVisible(true) ;
290*cdf0e10cSrcweir         shortWait();
291*cdf0e10cSrcweir         res = wListener.shown && !wListener.resized &&
292*cdf0e10cSrcweir                 !wListener.hidden && !wListener.moved;
293*cdf0e10cSrcweir         result &= res;
294*cdf0e10cSrcweir         if (!res) {
295*cdf0e10cSrcweir             log.println("\twindowHidden()  wasn't called: " + !wListener.hidden);
296*cdf0e10cSrcweir             log.println("\twindowShown()      was called: " + wListener.shown);
297*cdf0e10cSrcweir             log.println("\twindowResized() wasn't called: " + !wListener.resized);
298*cdf0e10cSrcweir             log.println("\twindowMoved()   wasn't called: " + !wListener.moved);
299*cdf0e10cSrcweir         } else {
300*cdf0e10cSrcweir             log.println("windowShown() was called");
301*cdf0e10cSrcweir         }
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir         tRes.tested("addWindowListener()", result) ;
304*cdf0e10cSrcweir     }
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir     /**
308*cdf0e10cSrcweir     * Test calls the method. Then we change window and check that listener's
309*cdf0e10cSrcweir     * methods were not called. <p>
310*cdf0e10cSrcweir     * Has <b> OK </b> status if listener does not react on window events.<p>
311*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
312*cdf0e10cSrcweir     * <ul>
313*cdf0e10cSrcweir     *  <li> <code> addWindowListener() </code>: adds window listener to the
314*cdf0e10cSrcweir     *  object </li>
315*cdf0e10cSrcweir     * </ul>
316*cdf0e10cSrcweir     */
317*cdf0e10cSrcweir     public void _removeWindowListener() {
318*cdf0e10cSrcweir         requiredMethod("addWindowListener()");
319*cdf0e10cSrcweir         oObj.removeWindowListener(wListener);
320*cdf0e10cSrcweir         wListener.init();
321*cdf0e10cSrcweir         oObj.setPosSize(posSize.X, posSize.Y,
322*cdf0e10cSrcweir             posSize.Width , posSize.Height, PosSize.POSSIZE);
323*cdf0e10cSrcweir         oObj.setVisible(false);
324*cdf0e10cSrcweir         oObj.setVisible(true);
325*cdf0e10cSrcweir         boolean res = !(wListener.resized || wListener.moved
326*cdf0e10cSrcweir             || wListener.hidden || wListener.shown);
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir         tRes.tested("removeWindowListener()", res);
329*cdf0e10cSrcweir     }
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir     /**
332*cdf0e10cSrcweir     * A class we use to test addFocusListener() and
333*cdf0e10cSrcweir     * removeFocusListener()
334*cdf0e10cSrcweir     */
335*cdf0e10cSrcweir     public class TestFocusListener implements XFocusListener {
336*cdf0e10cSrcweir         public boolean gained = false ;
337*cdf0e10cSrcweir         public boolean lost = false ;
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir         public void focusGained(FocusEvent e) {
340*cdf0e10cSrcweir             gained = true ;
341*cdf0e10cSrcweir         }
342*cdf0e10cSrcweir         public void focusLost(FocusEvent e) {
343*cdf0e10cSrcweir             lost = true ;
344*cdf0e10cSrcweir         }
345*cdf0e10cSrcweir         public void init() {
346*cdf0e10cSrcweir             gained = false;
347*cdf0e10cSrcweir             lost = false;
348*cdf0e10cSrcweir         }
349*cdf0e10cSrcweir         public void disposing(EventObject e) {}
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir     }
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir     private TestFocusListener fListener = new TestFocusListener();
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir     /**
356*cdf0e10cSrcweir     * Test calls the method. Then we change focus and check that listener's
357*cdf0e10cSrcweir     * methods were called. <p>
358*cdf0e10cSrcweir     * Has <b> OK </b> status if methods of fListener were called when
359*cdf0e10cSrcweir     * corresponding events occured. <p>
360*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
361*cdf0e10cSrcweir     * <ul>
362*cdf0e10cSrcweir     *  <li> <code> setFocus() </code>: sets the focus to the window </li>
363*cdf0e10cSrcweir     * </ul>
364*cdf0e10cSrcweir     */
365*cdf0e10cSrcweir     public void _addFocusListener() {
366*cdf0e10cSrcweir         boolean result = true ;
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir         requiredMethod("setFocus()");
369*cdf0e10cSrcweir         oObj.addFocusListener(fListener) ;
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir         // testing fListener.lost()
372*cdf0e10cSrcweir         oObj.setFocus();
373*cdf0e10cSrcweir         shortWait();
374*cdf0e10cSrcweir         win.setFocus();
375*cdf0e10cSrcweir         shortWait();
376*cdf0e10cSrcweir         result &= fListener.lost;
377*cdf0e10cSrcweir         if (!fListener.lost) {
378*cdf0e10cSrcweir             log.println("Lost focus was not notified about") ;
379*cdf0e10cSrcweir         }
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir         // testing fListener.gained()
382*cdf0e10cSrcweir         oObj.setFocus() ;
383*cdf0e10cSrcweir         shortWait();
384*cdf0e10cSrcweir         result &= fListener.gained;
385*cdf0e10cSrcweir         if (!fListener.gained) {
386*cdf0e10cSrcweir             log.println("Gained focus was not notified about") ;
387*cdf0e10cSrcweir         }
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir         tRes.tested("addFocusListener()", result) ;
390*cdf0e10cSrcweir     }
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir     /**
393*cdf0e10cSrcweir     * Test calls the method. Then we change focus and check that listener's
394*cdf0e10cSrcweir     * methods were not called. <p>
395*cdf0e10cSrcweir     * Has <b> OK </b> status if listener does not react on focus changing. <p>
396*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
397*cdf0e10cSrcweir     * <ul>
398*cdf0e10cSrcweir     *  <li> <code> addFocusListener() </code> : adds focus listener to
399*cdf0e10cSrcweir     * the object </li>
400*cdf0e10cSrcweir     * </ul>
401*cdf0e10cSrcweir     */
402*cdf0e10cSrcweir     public void _removeFocusListener() {
403*cdf0e10cSrcweir         requiredMethod("addFocusListener()");
404*cdf0e10cSrcweir         oObj.removeFocusListener(fListener);
405*cdf0e10cSrcweir         fListener.init();
406*cdf0e10cSrcweir         oObj.setFocus();
407*cdf0e10cSrcweir         win.setFocus();
408*cdf0e10cSrcweir         oObj.setFocus();
409*cdf0e10cSrcweir         boolean res = !(fListener.gained || fListener.lost);
410*cdf0e10cSrcweir         tRes.tested("removeFocusListener()", res);
411*cdf0e10cSrcweir     }
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir     /**
414*cdf0e10cSrcweir     * A class we use to test addKeyListener() and
415*cdf0e10cSrcweir     * removeKeyListener()
416*cdf0e10cSrcweir     */
417*cdf0e10cSrcweir     public class TestKeyListener implements XKeyListener {
418*cdf0e10cSrcweir         public boolean pressed = false;
419*cdf0e10cSrcweir         public boolean released = false;
420*cdf0e10cSrcweir         public void keyPressed(KeyEvent e) { pressed = true; }
421*cdf0e10cSrcweir         public void keyReleased(KeyEvent e) { released = true; }
422*cdf0e10cSrcweir         public void disposing(EventObject e) {}
423*cdf0e10cSrcweir         public void init() { pressed = false; released = false; }
424*cdf0e10cSrcweir     }
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir     private TestKeyListener kListener = new TestKeyListener();
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir     /**
429*cdf0e10cSrcweir     * Test calls the method. <p>
430*cdf0e10cSrcweir     * Has <b> OK </b> status if no exceptions were thrown. <p>
431*cdf0e10cSrcweir     */
432*cdf0e10cSrcweir     public void _addKeyListener() {
433*cdf0e10cSrcweir         oObj.addKeyListener(kListener);
434*cdf0e10cSrcweir         tRes.tested("addKeyListener()", true);
435*cdf0e10cSrcweir     }
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir     /**
438*cdf0e10cSrcweir     * Test calls the method. <p>
439*cdf0e10cSrcweir     * Has <b> OK </b> status if no exceptions were thrown. <p>
440*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
441*cdf0e10cSrcweir     * <ul>
442*cdf0e10cSrcweir     *  <li> <code> addKeyListener() </code> : adds key listener to
443*cdf0e10cSrcweir     *  the object </li>
444*cdf0e10cSrcweir     * </ul>
445*cdf0e10cSrcweir     */
446*cdf0e10cSrcweir     public void _removeKeyListener() {
447*cdf0e10cSrcweir         requiredMethod("addKeyListener()");
448*cdf0e10cSrcweir         oObj.removeKeyListener(kListener);
449*cdf0e10cSrcweir         tRes.tested("removeKeyListener()", true);
450*cdf0e10cSrcweir     }
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir     /**
453*cdf0e10cSrcweir     * A class we use to test addMouseListener() and
454*cdf0e10cSrcweir     * removeMouseListener()
455*cdf0e10cSrcweir     */
456*cdf0e10cSrcweir     public class TestMouseListener implements XMouseListener {
457*cdf0e10cSrcweir         public boolean pressed = false;
458*cdf0e10cSrcweir         public boolean released = false;
459*cdf0e10cSrcweir         public boolean entered = false;
460*cdf0e10cSrcweir         public boolean exited = false;
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir         public void mousePressed(MouseEvent e) {
463*cdf0e10cSrcweir             pressed = true;
464*cdf0e10cSrcweir         }
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir         public void mouseReleased(MouseEvent e) {
467*cdf0e10cSrcweir             released = true;
468*cdf0e10cSrcweir         }
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir         public void mouseEntered(MouseEvent e) {
471*cdf0e10cSrcweir             entered = true;
472*cdf0e10cSrcweir         }
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir         public void mouseExited(MouseEvent e) {
475*cdf0e10cSrcweir             exited = true;
476*cdf0e10cSrcweir         }
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir         public void disposing(EventObject e) {}
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir         public void init() {
481*cdf0e10cSrcweir             pressed = false;
482*cdf0e10cSrcweir             released = false;
483*cdf0e10cSrcweir             exited = false;
484*cdf0e10cSrcweir             entered = false;
485*cdf0e10cSrcweir         }
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir     }
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir     private TestMouseListener mListener = new TestMouseListener();
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir     /**
492*cdf0e10cSrcweir     * Test calls the method. <p>
493*cdf0e10cSrcweir     * Has <b> OK </b> status if no exceptions were thrown. <p>
494*cdf0e10cSrcweir     */
495*cdf0e10cSrcweir     public void _addMouseListener() {
496*cdf0e10cSrcweir         oObj.addMouseListener(mListener);
497*cdf0e10cSrcweir         tRes.tested("addMouseListener()", true);
498*cdf0e10cSrcweir     }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir     /**
501*cdf0e10cSrcweir     * Test calls the method. <p>
502*cdf0e10cSrcweir     * Has <b> OK </b> status if no exceptions were thrown. <p>
503*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
504*cdf0e10cSrcweir     * <ul>
505*cdf0e10cSrcweir     *  <li> <code> addMouseListener() </code> : adds mouse listener to
506*cdf0e10cSrcweir     * the object</li>
507*cdf0e10cSrcweir     * </ul>
508*cdf0e10cSrcweir     */
509*cdf0e10cSrcweir     public void _removeMouseListener() {
510*cdf0e10cSrcweir         requiredMethod("addMouseListener()");
511*cdf0e10cSrcweir         oObj.removeMouseListener(mListener);
512*cdf0e10cSrcweir         tRes.tested("removeMouseListener()", true);
513*cdf0e10cSrcweir     }
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir     /**
516*cdf0e10cSrcweir     * A class we use to test addMouseMotionListener() and
517*cdf0e10cSrcweir     * removeMouseMotionListener()
518*cdf0e10cSrcweir     */
519*cdf0e10cSrcweir     public class TestMouseMotionListener implements XMouseMotionListener {
520*cdf0e10cSrcweir         public boolean dragged = false;
521*cdf0e10cSrcweir         public boolean moved = false;
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir         public void mouseDragged(MouseEvent e) {
524*cdf0e10cSrcweir             dragged = true;
525*cdf0e10cSrcweir         }
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir         public void mouseMoved(MouseEvent e) {
528*cdf0e10cSrcweir             moved = true;
529*cdf0e10cSrcweir         }
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir         public void disposing(EventObject e) {}
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir         public void init() {
534*cdf0e10cSrcweir             dragged = false;
535*cdf0e10cSrcweir             moved = false;
536*cdf0e10cSrcweir         }
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir     }
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir     private TestMouseMotionListener mmListener = new TestMouseMotionListener();
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir     /**
543*cdf0e10cSrcweir     * Test calls the method. <p>
544*cdf0e10cSrcweir     * Has <b> OK </b> status if no exceptions were thrown. <p>
545*cdf0e10cSrcweir     */
546*cdf0e10cSrcweir     public void _addMouseMotionListener() {
547*cdf0e10cSrcweir         oObj.addMouseMotionListener(mmListener);
548*cdf0e10cSrcweir         tRes.tested("addMouseMotionListener()", true);
549*cdf0e10cSrcweir     }
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir     /**
552*cdf0e10cSrcweir     * Test calls the method. <p>
553*cdf0e10cSrcweir     * Has <b> OK </b> status if no exceptions were thrown. <p>
554*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
555*cdf0e10cSrcweir     * <ul>
556*cdf0e10cSrcweir     *  <li> <code> addMouseMotionListener() </code> : adds mouse motion
557*cdf0e10cSrcweir     * listener to the object</li>
558*cdf0e10cSrcweir     * </ul>
559*cdf0e10cSrcweir     */
560*cdf0e10cSrcweir     public void _removeMouseMotionListener() {
561*cdf0e10cSrcweir         requiredMethod("addMouseMotionListener()");
562*cdf0e10cSrcweir         oObj.removeMouseMotionListener(mmListener);
563*cdf0e10cSrcweir         tRes.tested("removeMouseMotionListener()", true);
564*cdf0e10cSrcweir     }
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir     /**
567*cdf0e10cSrcweir     * A class we use to test addPaintListener() and
568*cdf0e10cSrcweir     * removePaintListener()
569*cdf0e10cSrcweir     */
570*cdf0e10cSrcweir     public class TestPaintListener implements XPaintListener {
571*cdf0e10cSrcweir         public boolean paint = false;
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir         public void windowPaint(PaintEvent e) {
574*cdf0e10cSrcweir             paint = true;
575*cdf0e10cSrcweir         }
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir         public void disposing(EventObject e) {}
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir         public void init() {
580*cdf0e10cSrcweir             paint = false;
581*cdf0e10cSrcweir         }
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir     }
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir     private TestPaintListener pListener = new TestPaintListener();
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir     /**
588*cdf0e10cSrcweir     * Test calls the method. <p>
589*cdf0e10cSrcweir     * Has <b> OK </b> status if no exceptions were thrown. <p>
590*cdf0e10cSrcweir     */
591*cdf0e10cSrcweir     public void _addPaintListener() {
592*cdf0e10cSrcweir         oObj.addPaintListener(pListener);
593*cdf0e10cSrcweir         tRes.tested("addPaintListener()", true);
594*cdf0e10cSrcweir     }
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir     /**
597*cdf0e10cSrcweir     * Test calls the method. <p>
598*cdf0e10cSrcweir     * Has <b> OK </b> status if no exceptions were thrown. <p>
599*cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
600*cdf0e10cSrcweir     * <ul>
601*cdf0e10cSrcweir     *  <li> <code> addPaintListener() </code> : adds paint listener to
602*cdf0e10cSrcweir     * the object </li>
603*cdf0e10cSrcweir     * </ul>
604*cdf0e10cSrcweir     */
605*cdf0e10cSrcweir     public void _removePaintListener() {
606*cdf0e10cSrcweir         requiredMethod("addPaintListener()");
607*cdf0e10cSrcweir         oObj.removePaintListener(pListener);
608*cdf0e10cSrcweir         tRes.tested("removePaintListener()", true);
609*cdf0e10cSrcweir     }
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir     /**
612*cdf0e10cSrcweir     * Sleeps for 0.2 sec. to allow StarOffice to react on <code>
613*cdf0e10cSrcweir     * reset</code> call.
614*cdf0e10cSrcweir     */
615*cdf0e10cSrcweir     private void shortWait() {
616*cdf0e10cSrcweir         try {
617*cdf0e10cSrcweir             Thread.sleep(2000) ;
618*cdf0e10cSrcweir         } catch (InterruptedException e) {
619*cdf0e10cSrcweir             log.println("While waiting :" + e) ;
620*cdf0e10cSrcweir         }
621*cdf0e10cSrcweir     }
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir }
624*cdf0e10cSrcweir 
625