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