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 .
21 import com
.sun
.star
.awt
.FocusEvent
;
22 import com
.sun
.star
.awt
.KeyEvent
;
23 import com
.sun
.star
.awt
.MouseEvent
;
24 import com
.sun
.star
.awt
.PaintEvent
;
25 import com
.sun
.star
.awt
.Point
;
26 import com
.sun
.star
.awt
.PosSize
;
27 import com
.sun
.star
.awt
.Rectangle
;
28 import com
.sun
.star
.awt
.Size
;
29 import com
.sun
.star
.awt
.WindowEvent
;
30 import com
.sun
.star
.awt
.XFocusListener
;
31 import com
.sun
.star
.awt
.XKeyListener
;
32 import com
.sun
.star
.awt
.XMouseListener
;
33 import com
.sun
.star
.awt
.XMouseMotionListener
;
34 import com
.sun
.star
.awt
.XPaintListener
;
35 import com
.sun
.star
.awt
.XWindow
;
36 import com
.sun
.star
.awt
.XWindowListener
;
37 import com
.sun
.star
.drawing
.XControlShape
;
38 import com
.sun
.star
.lang
.EventObject
;
39 import lib
.MultiMethodTest
;
40 import util
.ValueComparer
;
43 * Testing <code>com.sun.star.awt.XWindow</code>
46 * <li><code> setPosSize()</code></li>
47 * <li><code> getPosSize()</code></li>
48 * <li><code> setVisible()</code></li>
49 * <li><code> setEnable()</code></li>
50 * <li><code> setFocus()</code></li>
51 * <li><code> addWindowListener()</code></li>
52 * <li><code> removeWindowListener()</code></li>
53 * <li><code> addFocusListener()</code></li>
54 * <li><code> removeFocusListener()</code></li>
55 * <li><code> addKeyListener()</code></li>
56 * <li><code> removeKeyListener()</code></li>
57 * <li><code> addMouseListener()</code></li>
58 * <li><code> removeMouseListener()</code></li>
59 * <li><code> addMouseMotionListener()</code></li>
60 * <li><code> removeMouseMotionListener()</code></li>
61 * <li><code> addPaintListener()</code></li>
62 * <li><code> removePaintListener()</code></li>
64 * This test needs the following object relations :
66 * <li> <code>'XWindow.AnotherWindow'</code> (of type <code>XWindow</code>):
67 * Some another window which can gain focus so the tested one
69 * <li> <code>'XWindow.ControlShape'</code> <b>optional</b>
70 * (of type <code>XControlShape</code>):
71 * Some shapes cann't change their size within fixed ControlShape
72 * and their size could be changed only if size of container
73 * ControlShape is changed. For such shapes this relation should
74 * be passed for proper <code>addWindowListener</code> test. </li>
76 * Test is <b> NOT </b> multithread compliant. <p>
77 * @see com.sun.star.awt.XWindow
79 public class _XWindow
extends MultiMethodTest
{
80 public XWindow oObj
= null;
81 private Rectangle posSize
= null ;
82 private XWindow win
= null;
85 * Test calls the method. <p>
86 * Has <b> OK </b> status if the method does not return null.
88 public void _getPosSize() {
89 posSize
= oObj
.getPosSize() ;
90 tRes
.tested("getPosSize()", posSize
!= null) ;
94 * After defining Rectangle structure to be set, test calls the method. <p>
95 * Has <b> OK </b> status if structure obtained using getPosSize() is
96 * equal to structure previously set using setPosSize(). <p>
97 * The following method tests are to be completed successfully before :
99 * <li> <code> getPosSize() </code> : returns the outer bounds of
103 public void _setPosSize() {
104 Rectangle newRec
= new Rectangle();
106 requiredMethod("getPosSize()");
107 newRec
.X
= posSize
.X
+ 1;
108 newRec
.Y
= posSize
.Y
+ 1;
109 newRec
.Width
= posSize
.Width
- 3;
110 newRec
.Height
= posSize
.Height
- 3;
111 oObj
.setPosSize(newRec
.X
, newRec
.Y
, newRec
.Width
, newRec
.Height
,
113 Rectangle gPS
= oObj
.getPosSize();
114 log
.println("Was : (" + posSize
.X
+ ", " + posSize
.Y
+ ", " +
115 posSize
.Width
+ ", " + posSize
.Height
+ "), ");
116 log
.println("Set : (" + newRec
.X
+ ", " + newRec
.Y
+ ", " +
117 newRec
.Width
+ ", " + newRec
.Height
+ "), ");
118 log
.println("Get : (" + gPS
.X
+ ", " + gPS
.Y
+ ", " +
119 gPS
.Width
+ ", " + gPS
.Height
+ "). ");
120 tRes
.tested("setPosSize()", ValueComparer
.equalValue(newRec
, gPS
) );
124 * At first object relation 'XWindow.AnotherWindow' is obtained.
125 * Then test calls the methods of two 'XWindow' objects several times to be
126 * sure that the focus has changed. <p>
127 * Has <b> OK </b> status if the method successfully returns
128 * and no exceptions were thrown.
130 public void _setFocus() {
131 win
= (XWindow
) tEnv
.getObjRelation("XWindow.AnotherWindow");
135 tRes
.tested("setFocus()", true);
139 * Test calls the method twice with two parameters: 'true' and 'false'. <p>
140 * Has <b> OK </b> status if the method successfully returns
141 * and no exceptions were thrown.
143 public void _setVisible() {
144 oObj
.setVisible(false);
145 oObj
.setVisible(true);
146 tRes
.tested("setVisible()", true);
150 * Test calls the method twice with two parameters: 'true' and 'false'. <p>
151 * Has <b> OK </b> status if the method successfully returns
152 * and no exceptions were thrown.
154 public void _setEnable() {
155 oObj
.setEnable(false);
156 oObj
.setEnable(true);
157 tRes
.tested("setEnable()", true);
162 * A class we use to test addWindowListener() and
163 * removeWindowListener()
165 public class TestWindowListener
implements XWindowListener
{
166 public boolean resized
= false ;
167 public boolean moved
= false ;
168 public boolean hidden
= false ;
169 public boolean shown
= false ;
178 public void windowResized(WindowEvent e
) {
181 public void windowMoved(WindowEvent e
) {
184 public void windowHidden(EventObject e
) {
187 public void windowShown(EventObject e
) {
190 public void disposing(EventObject e
) {}
194 private final TestWindowListener wListener
= new TestWindowListener() ;
198 * Test calls the method. Then we check if listener's methods were called
199 * when we move, resize, hide and show the window. The resizing is
200 * performed depending on 'XWindow.ControlShape' existence. If this
201 * relation exists then the size and position of container control
202 * shape is changed, else the position and size of window itself is
205 * Has <b> OK </b> status if methods of wListener were called when
206 * corresponding events occurred. <p>
208 * The following method tests are to be executed before :
210 * <li> <code> setPosSize() </code>: sets the outer bounds of the
212 * <li> <code> setVisible() </code>: shows or hides the window
213 * depending on the parameter</li>
216 public void _addWindowListener() {
217 executeMethod("setPosSize()");
218 executeMethod("setVisible()");
219 boolean result
= true ;
221 oObj
.addWindowListener(wListener
);
223 // testing wListener.windowMoved()
224 XControlShape ctrlShape
= (XControlShape
)
225 tEnv
.getObjRelation("XWindow.ControlShape");
226 log
.println("change object position and size...");
228 if (ctrlShape
!= null) {
230 Size sz
= ctrlShape
.getSize();
232 ctrlShape
.setSize(sz
);
233 Point pos
= ctrlShape
.getPosition();
235 ctrlShape
.setPosition(pos
);
236 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
237 log
.println("Couldn't change size or position: ");
238 e
.printStackTrace(log
);
241 oObj
.setPosSize(posSize
.X
+ 2, 0, 0, 0, PosSize
.X
);
242 oObj
.setPosSize(0, 0, 100, 100, PosSize
.WIDTH
);
245 util
.utils
.pause(200);
246 boolean res
= wListener
.resized
&& wListener
.moved
&&
247 !wListener
.hidden
&& !wListener
.shown
;
250 log
.println("\twindowHidden() wasn't called: " + !wListener
.hidden
);
251 log
.println("\twindowShown() wasn't called: " + !wListener
.shown
);
252 log
.println("\twindowResized() was called: " + wListener
.resized
);
253 log
.println("\twindowMoved() was called: " + wListener
.moved
);
255 log
.println("windowMoved() and windowResized() was called");
258 // testing wListener.windowHidden()
260 util
.utils
.pause(200);
261 log
.println("set object invisible...");
262 oObj
.setVisible(false);
263 util
.utils
.pause(200);
264 res
= wListener
.hidden
&& !wListener
.resized
265 && !wListener
.moved
&& !wListener
.shown
;
268 log
.println("\twindowHidden() was called: " + wListener
.hidden
);
269 log
.println("\twindowShown() wasn't called: " + !wListener
.shown
);
270 log
.println("\twindowResized() wasn't called: " + !wListener
.resized
);
271 log
.println("\twindowMoved() wasn't called: " + !wListener
.moved
);
273 log
.println("windowHidden() was called");
276 // testing wListener.windowShown()
278 util
.utils
.pause(200);
279 log
.println("set object visible...");
280 oObj
.setVisible(true) ;
281 util
.utils
.pause(200);
282 res
= wListener
.shown
&& !wListener
.resized
&&
283 !wListener
.hidden
&& !wListener
.moved
;
286 log
.println("\twindowHidden() wasn't called: " + !wListener
.hidden
);
287 log
.println("\twindowShown() was called: " + wListener
.shown
);
288 log
.println("\twindowResized() wasn't called: " + !wListener
.resized
);
289 log
.println("\twindowMoved() wasn't called: " + !wListener
.moved
);
291 log
.println("windowShown() was called");
294 tRes
.tested("addWindowListener()", result
) ;
299 * Test calls the method. Then we change window and check that listener's
300 * methods were not called. <p>
301 * Has <b> OK </b> status if listener does not react on window events.<p>
302 * The following method tests are to be completed successfully before :
304 * <li> <code> addWindowListener() </code>: adds window listener to the
308 public void _removeWindowListener() {
309 requiredMethod("addWindowListener()");
310 oObj
.removeWindowListener(wListener
);
312 oObj
.setPosSize(posSize
.X
, posSize
.Y
,
313 posSize
.Width
, posSize
.Height
, PosSize
.POSSIZE
);
314 oObj
.setVisible(false);
315 oObj
.setVisible(true);
316 boolean res
= !(wListener
.resized
|| wListener
.moved
317 || wListener
.hidden
|| wListener
.shown
);
319 tRes
.tested("removeWindowListener()", res
);
323 * A class we use to test addFocusListener() and
324 * removeFocusListener()
326 public class TestFocusListener
implements XFocusListener
{
327 public boolean gained
= false ;
328 public boolean lost
= false ;
330 public void focusGained(FocusEvent e
) {
333 public void focusLost(FocusEvent e
) {
340 public void disposing(EventObject e
) {}
344 private final TestFocusListener fListener
= new TestFocusListener();
347 * Test calls the method. Then we change focus and check that listener's
348 * methods were called. <p>
349 * Has <b> OK </b> status if methods of fListener were called when
350 * corresponding events occurred. <p>
351 * The following method tests are to be completed successfully before :
353 * <li> <code> setFocus() </code>: sets the focus to the window </li>
356 public void _addFocusListener() {
357 boolean result
= true ;
359 requiredMethod("setFocus()");
360 oObj
.addFocusListener(fListener
) ;
362 // testing fListener.lost()
364 util
.utils
.pause(200);
366 util
.utils
.pause(200);
367 result
&= fListener
.lost
;
368 if (!fListener
.lost
) {
369 log
.println("Lost focus was not notified about") ;
372 // testing fListener.gained()
374 util
.utils
.pause(200);
375 result
&= fListener
.gained
;
376 if (!fListener
.gained
) {
377 log
.println("Gained focus was not notified about") ;
380 tRes
.tested("addFocusListener()", result
) ;
384 * Test calls the method. Then we change focus and check that listener's
385 * methods were not called. <p>
386 * Has <b> OK </b> status if listener does not react on focus changing. <p>
387 * The following method tests are to be completed successfully before :
389 * <li> <code> addFocusListener() </code> : adds focus listener to
393 public void _removeFocusListener() {
394 requiredMethod("addFocusListener()");
395 oObj
.removeFocusListener(fListener
);
400 boolean res
= !(fListener
.gained
|| fListener
.lost
);
401 tRes
.tested("removeFocusListener()", res
);
405 * A class we use to test addKeyListener() and
406 * removeKeyListener()
408 public class TestKeyListener
implements XKeyListener
{
409 public boolean pressed
= false;
410 public boolean released
= false;
411 public void keyPressed(KeyEvent e
) { pressed
= true; }
412 public void keyReleased(KeyEvent e
) { released
= true; }
413 public void disposing(EventObject e
) {}
414 public void init() { pressed
= false; released
= false; }
417 private final TestKeyListener kListener
= new TestKeyListener();
420 * Test calls the method. <p>
421 * Has <b> OK </b> status if no exceptions were thrown. <p>
423 public void _addKeyListener() {
424 oObj
.addKeyListener(kListener
);
425 tRes
.tested("addKeyListener()", true);
429 * Test calls the method. <p>
430 * Has <b> OK </b> status if no exceptions were thrown. <p>
431 * The following method tests are to be completed successfully before :
433 * <li> <code> addKeyListener() </code> : adds key listener to
437 public void _removeKeyListener() {
438 requiredMethod("addKeyListener()");
439 oObj
.removeKeyListener(kListener
);
440 tRes
.tested("removeKeyListener()", true);
444 * A class we use to test addMouseListener() and
445 * removeMouseListener()
447 public class TestMouseListener
implements XMouseListener
{
448 public boolean pressed
= false;
449 public boolean released
= false;
450 public boolean entered
= false;
451 public boolean exited
= false;
453 public void mousePressed(MouseEvent e
) {
457 public void mouseReleased(MouseEvent e
) {
461 public void mouseEntered(MouseEvent e
) {
465 public void mouseExited(MouseEvent e
) {
469 public void disposing(EventObject e
) {}
480 private final TestMouseListener mListener
= new TestMouseListener();
483 * Test calls the method. <p>
484 * Has <b> OK </b> status if no exceptions were thrown. <p>
486 public void _addMouseListener() {
487 oObj
.addMouseListener(mListener
);
488 tRes
.tested("addMouseListener()", true);
492 * Test calls the method. <p>
493 * Has <b> OK </b> status if no exceptions were thrown. <p>
494 * The following method tests are to be completed successfully before :
496 * <li> <code> addMouseListener() </code> : adds mouse listener to
500 public void _removeMouseListener() {
501 requiredMethod("addMouseListener()");
502 oObj
.removeMouseListener(mListener
);
503 tRes
.tested("removeMouseListener()", true);
507 * A class we use to test addMouseMotionListener() and
508 * removeMouseMotionListener()
510 public class TestMouseMotionListener
implements XMouseMotionListener
{
511 public boolean dragged
= false;
512 public boolean moved
= false;
514 public void mouseDragged(MouseEvent e
) {
518 public void mouseMoved(MouseEvent e
) {
522 public void disposing(EventObject e
) {}
531 private final TestMouseMotionListener mmListener
= new TestMouseMotionListener();
534 * Test calls the method. <p>
535 * Has <b> OK </b> status if no exceptions were thrown. <p>
537 public void _addMouseMotionListener() {
538 oObj
.addMouseMotionListener(mmListener
);
539 tRes
.tested("addMouseMotionListener()", true);
543 * Test calls the method. <p>
544 * Has <b> OK </b> status if no exceptions were thrown. <p>
545 * The following method tests are to be completed successfully before :
547 * <li> <code> addMouseMotionListener() </code> : adds mouse motion
548 * listener to the object</li>
551 public void _removeMouseMotionListener() {
552 requiredMethod("addMouseMotionListener()");
553 oObj
.removeMouseMotionListener(mmListener
);
554 tRes
.tested("removeMouseMotionListener()", true);
558 * A class we use to test addPaintListener() and
559 * removePaintListener()
561 public class TestPaintListener
implements XPaintListener
{
562 public boolean paint
= false;
564 public void windowPaint(PaintEvent e
) {
568 public void disposing(EventObject e
) {}
576 private final TestPaintListener pListener
= new TestPaintListener();
579 * Test calls the method. <p>
580 * Has <b> OK </b> status if no exceptions were thrown. <p>
582 public void _addPaintListener() {
583 oObj
.addPaintListener(pListener
);
584 tRes
.tested("addPaintListener()", true);
588 * Test calls the method. <p>
589 * Has <b> OK </b> status if no exceptions were thrown. <p>
590 * The following method tests are to be completed successfully before :
592 * <li> <code> addPaintListener() </code> : adds paint listener to
596 public void _removePaintListener() {
597 requiredMethod("addPaintListener()");
598 oObj
.removePaintListener(pListener
);
599 tRes
.tested("removePaintListener()", true);