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 can'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 static 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
);
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()
261 log
.println("set object invisible...");
262 oObj
.setVisible(false);
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()
279 log
.println("set object visible...");
280 oObj
.setVisible(true) ;
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 static 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()
367 result
&= fListener
.lost
;
368 if (!fListener
.lost
) {
369 log
.println("Lost focus was not notified about") ;
372 // testing fListener.gained()
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 static class TestKeyListener
implements XKeyListener
{
409 public void keyPressed(KeyEvent e
) {}
410 public void keyReleased(KeyEvent e
) {}
411 public void disposing(EventObject e
) {}
412 public void init() {}
415 private final TestKeyListener kListener
= new TestKeyListener();
418 * Test calls the method. <p>
419 * Has <b> OK </b> status if no exceptions were thrown. <p>
421 public void _addKeyListener() {
422 oObj
.addKeyListener(kListener
);
423 tRes
.tested("addKeyListener()", true);
427 * Test calls the method. <p>
428 * Has <b> OK </b> status if no exceptions were thrown. <p>
429 * The following method tests are to be completed successfully before :
431 * <li> <code> addKeyListener() </code> : adds key listener to
435 public void _removeKeyListener() {
436 requiredMethod("addKeyListener()");
437 oObj
.removeKeyListener(kListener
);
438 tRes
.tested("removeKeyListener()", true);
442 * A class we use to test addMouseListener() and
443 * removeMouseListener()
445 public static class TestMouseListener
implements XMouseListener
{
447 public void mousePressed(MouseEvent e
) {
450 public void mouseReleased(MouseEvent e
) {
453 public void mouseEntered(MouseEvent e
) {
456 public void mouseExited(MouseEvent e
) {
459 public void disposing(EventObject e
) {}
466 private final TestMouseListener mListener
= new TestMouseListener();
469 * Test calls the method. <p>
470 * Has <b> OK </b> status if no exceptions were thrown. <p>
472 public void _addMouseListener() {
473 oObj
.addMouseListener(mListener
);
474 tRes
.tested("addMouseListener()", true);
478 * Test calls the method. <p>
479 * Has <b> OK </b> status if no exceptions were thrown. <p>
480 * The following method tests are to be completed successfully before :
482 * <li> <code> addMouseListener() </code> : adds mouse listener to
486 public void _removeMouseListener() {
487 requiredMethod("addMouseListener()");
488 oObj
.removeMouseListener(mListener
);
489 tRes
.tested("removeMouseListener()", true);
493 * A class we use to test addMouseMotionListener() and
494 * removeMouseMotionListener()
496 public static class TestMouseMotionListener
implements XMouseMotionListener
{
498 public void mouseDragged(MouseEvent e
) {
501 public void mouseMoved(MouseEvent e
) {
504 public void disposing(EventObject e
) {
512 private final TestMouseMotionListener mmListener
= new TestMouseMotionListener();
515 * Test calls the method. <p>
516 * Has <b> OK </b> status if no exceptions were thrown. <p>
518 public void _addMouseMotionListener() {
519 oObj
.addMouseMotionListener(mmListener
);
520 tRes
.tested("addMouseMotionListener()", true);
524 * Test calls the method. <p>
525 * Has <b> OK </b> status if no exceptions were thrown. <p>
526 * The following method tests are to be completed successfully before :
528 * <li> <code> addMouseMotionListener() </code> : adds mouse motion
529 * listener to the object</li>
532 public void _removeMouseMotionListener() {
533 requiredMethod("addMouseMotionListener()");
534 oObj
.removeMouseMotionListener(mmListener
);
535 tRes
.tested("removeMouseMotionListener()", true);
539 * A class we use to test addPaintListener() and
540 * removePaintListener()
542 public static class TestPaintListener
implements XPaintListener
{
544 public void windowPaint(PaintEvent e
) {
547 public void disposing(EventObject e
) {}
554 private final TestPaintListener pListener
= new TestPaintListener();
557 * Test calls the method. <p>
558 * Has <b> OK </b> status if no exceptions were thrown. <p>
560 public void _addPaintListener() {
561 oObj
.addPaintListener(pListener
);
562 tRes
.tested("addPaintListener()", true);
566 * Test calls the method. <p>
567 * Has <b> OK </b> status if no exceptions were thrown. <p>
568 * The following method tests are to be completed successfully before :
570 * <li> <code> addPaintListener() </code> : adds paint listener to
574 public void _removePaintListener() {
575 requiredMethod("addPaintListener()");
576 oObj
.removePaintListener(pListener
);
577 tRes
.tested("removePaintListener()", true);