1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XFrame.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import com
.sun
.star
.awt
.XWindow
;
34 //import com.sun.star.awt.XWindow;
35 import com
.sun
.star
.frame
.FrameAction
;
36 import com
.sun
.star
.frame
.FrameActionEvent
;
37 import com
.sun
.star
.frame
.XController
;
38 import com
.sun
.star
.frame
.XFrame
;
39 import com
.sun
.star
.frame
.XFrameActionListener
;
40 import com
.sun
.star
.frame
.XFramesSupplier
;
41 import com
.sun
.star
.lang
.EventObject
;
42 import java
.io
.PrintWriter
;
43 import lib
.MultiMethodTest
;
44 import lib
.TestEnvironment
;
47 * Testing <code>com.sun.star.frame.XFrame</code>
50 * <li><code> getName() </code></li>
51 * <li><code> setName() </code></li>
52 * <li><code> activate() </code></li>
53 * <li><code> deactivate() </code></li>
54 * <li><code> isActive() </code></li>
55 * <li><code> addFrameActionListener() </code></li>
56 * <li><code> removeFrameActionListener() </code></li>
57 * <li><code> getCreator() </code></li>
58 * <li><code> getComponentWindow() </code></li>
59 * <li><code> getContainerWindow() </code></li>
60 * <li><code> getController() </code></li>
61 * <li><code> isTop() </code></li>
62 * <li><code> findFrame() </code></li>
63 * <li><code> contextChanged() </code></li>
64 * <li><code> setCreator() </code></li>
65 * <li><code> setComponent() </code></li>
66 * <li><code> initialize() </code></li>
68 * This test needs the following object relations :
70 * <li> <code>'XFrame'</code> (of type <code>XFrame</code>)
71 * <b>optional</b>: any frame named 'XFrame'.
72 * Could be used by <code>findFrame</code> method to try
73 * to find other frame than itself.</li>
75 * <li> <code>'Desktop'</code> (of type <code>Object</code>):
76 * if exsists, then desktop component is tested</li>
78 * Test is <b> NOT </b> multithread compilant. <p>
79 * @see com.sun.star.frame.XFrame
81 public class _XFrame
extends MultiMethodTest
{
82 final FrameAction
[] actionEvent
= new FrameAction
[1] ;
83 final boolean[] listenerCalled
= new boolean[] {false} ;
84 final boolean[] activatedCalled
= new boolean[] {false} ;
85 final boolean[] deactivatedCalled
= new boolean[] {false} ;
86 final TestFrameActionListener listener
=
87 new TestFrameActionListener() ;
88 public static XFrame oObj
= null;
91 * Class used to test listeners.
93 private class TestFrameActionListener
94 implements XFrameActionListener
{
96 public void frameAction(FrameActionEvent e
) {
97 listenerCalled
[0] = true ;
98 activatedCalled
[0] |= e
.Action
== FrameAction
.FRAME_ACTIVATED
;
99 deactivatedCalled
[0] |= e
.Action
== FrameAction
.FRAME_DEACTIVATING
;
100 actionEvent
[0] = e
.Action
;
103 public void disposing(EventObject e
) {}
108 * Test calls the method. <p>
109 * Has <b> OK </b> status if the method does not return null.
111 public void _getName() {
112 String name
= oObj
.getName() ;
114 log
.println("getName() returned null: FAILED") ;
116 tRes
.tested("getName()", name
!=null) ;
120 * Test calls the method. <p>
121 * Has <b> OK </b> status if set and gotten names are equal.
123 public void _setName() {
124 String sName
= "XFrame" ;
127 String gName
= oObj
.getName();
128 boolean res
= sName
.equals(gName
);
130 log
.println("setName('" + sName
+
131 "'), but getName() return '" + gName
+ "'") ;
132 tRes
.tested("setName()", res
);
136 * Test calls the method. <p>
137 * Has <b> OK </b> status if the method successfully returns
138 * and no exceptions were thrown.
140 public void _activate() {
142 tRes
.tested("activate()", true) ;
146 * Test calls the method. <p>
147 * Has <b> OK </b> status if the method successfully returns
148 * and no exceptions were thrown.
150 public void _deactivate() {
153 tRes
.tested("deactivate()", true) ;
157 * Test calls the method. Then frame is deactivated and method called
159 * Has <b> OK </b> status if isDesktop() returns true or if the method
160 * always display real status of a frame during activation/deactivation.
162 public void _isActive() {
163 boolean result
= true;
165 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
166 log
.println("Desktop is always active");
167 tRes
.tested("isActive()", oObj
.isActive()) ;
172 result
&= !oObj
.isActive();
174 log
.println("after deactivate() method call, isActive() returned true");
176 result
&= oObj
.isActive();
177 if (!oObj
.isActive())
178 log
.println("after activate() method call, isActive() returned false") ;
179 boolean res
= isDesktop(log
,tEnv
,"isActive()");
182 tRes
.tested("isActive()", result
) ;
186 * Test calls the method. Then frame status (activated/deactivated) is
187 * changed, and the listener is checked.<p>
188 * Has <b> OK </b> status if isDesktop() method returnes true, or if the
189 * listener was called and frame was activated.
191 public void _addFrameActionListener() {
192 boolean result
= true ;
194 oObj
.addFrameActionListener(listener
) ;
199 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
200 log
.println("No actions supported by Desktop");
201 tRes
.tested("addFrameActionListener()", true) ;
207 }catch (InterruptedException ex
) {}
210 if (!listenerCalled
[0]) {
211 log
.println("listener was not called.") ;
214 if (!activatedCalled
[0]) {
215 log
.println("Listener was called, FRAME_ACTIVATED was not") ;
218 if (!deactivatedCalled
[0]) {
219 log
.println("Listener was called, FRAME_DEACTIVATING was not") ;
224 boolean res
= isDesktop(log
, tEnv
, "addFrameActionListener()");
227 tRes
.tested("addFrameActionListener()", result
) ;
231 * Test calls the method. Then frame status (activated/deactivated) is
232 * changed, and the listener is checked.<p>
233 * Has <b> OK </b> status if isDesktop() method returns true, or if the
234 * method actually removes listener so it does not react on
235 * activate/deactivate events. <p>
236 * The following method tests are to be completed successfully before :
238 * <li> <code> addFrameActionListener() </code>: adds action listener
242 public void _removeFrameActionListener() {
243 boolean result
= true;
245 requiredMethod("addFrameActionListener()");
246 listenerCalled
[0] = false;
247 oObj
.removeFrameActionListener(listener
);
251 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
252 log
.println("No actions supported by Desktop");
253 tRes
.tested("removeFrameActionListener()", true) ;
257 if (listenerCalled
[0])
258 log
.println("Listener wasn't removed, and was called");
259 boolean res
= isDesktop(log
, tEnv
, "removeFrameActionListener()");
260 if (res
) result
=res
; else result
= (!listenerCalled
[0]);
262 tRes
.tested("removeFrameActionListener()", result
);
266 * Test calls the method. <p>
267 * Has <b> OK </b> status if isDesktop() method returns true or if the method
268 * does not return null.
270 public void _getCreator() {
271 boolean result
= true;
273 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
274 log
.println("Desktop has no creator");
275 tRes
.tested("getCreator()", true) ;
279 XFramesSupplier creator
= oObj
.getCreator() ;
281 log
.println("getCreator() returns null") ;
282 boolean res
= isDesktop(log
,tEnv
,"getCreator()");
283 if (res
) result
=res
; else result
= (creator
!= null);
284 tRes
.tested("getCreator()", result
) ;
288 * Test calls the method. <p>
289 * Has <b> OK </b> status if isDesktop() method returns true or if the method
290 * does not return null.
292 public void _getComponentWindow() {
293 boolean result
= true;
295 XWindow win
= oObj
.getComponentWindow() ;
297 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
298 log
.println("Desktop has no component window");
299 tRes
.tested("getComponentWindow()", true) ;
304 log
.println("getComponentWindow() returns null") ;
305 boolean res
= isDesktop(log
,tEnv
,"getComponentWindow()");
306 if (res
) result
=res
; else result
= (win
!= null);
307 tRes
.tested("getComponentWindow()", result
) ;
311 * Test calls the method. <p>
312 * Has <b> OK </b> status if isDesktop() method returns true or if the method
313 * does not return null.
315 public void _getContainerWindow() {
316 boolean result
= true;
318 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
319 log
.println("Desktop has no container window");
320 tRes
.tested("getContainerWindow()", true) ;
324 XWindow win
= oObj
.getContainerWindow() ;
326 log
.println("getContainerWindow() returns null") ;
327 boolean res
= isDesktop(log
,tEnv
,"getContainerWindow()");
328 if (res
) result
=res
; else result
= (win
!= null);
329 tRes
.tested("getContainerWindow()", result
) ;
333 * Test calls the method. Then returned controller is checked. <p>
334 * Has <b> OK </b> status if isDesktop() method returns true or
335 * if the method returns non-null controller, having frame that's equal to
338 public void _getController() {
339 boolean result
= true;
340 XController ctrl
= oObj
.getController();
342 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
343 log
.println("Desktop has no controller");
344 tRes
.tested("getController()", true) ;
349 log
.println("getController() returns null");
352 XFrame frm
= ctrl
.getFrame();
353 if (!oObj
.equals(frm
)) {
354 log
.println("Frame returned by controller not " +
355 "equals to frame testing");
359 boolean res
= isDesktop(log
, tEnv
, "getController()");
361 tRes
.tested("getController()", result
) ;
365 * Test calls the method. <p>
366 * Has <b> OK </b> status if the method successfully returns
367 * and no exceptions were thrown.
369 public void _isTop() {
370 log
.println("isTop() = " + oObj
.isTop());
371 tRes
.tested("isTop()", true) ;
375 * After obtaining an object relation 'XFrame', test tries to find a frame
376 * named 'XFrame'. <p>
377 * Has <b> OK </b> status if the method returns non-null object that's equal
378 * to previously obtained object relation.
380 public void _findFrame() {
381 boolean result
= true ;
383 XFrame aFrame
= (XFrame
) tEnv
.getObjRelation("XFrame");
385 if (aFrame
!= null) {
386 log
.println("Trying to find a frame with name 'XFrame' ...");
387 XFrame frame
= oObj
.findFrame("XFrame",
388 com
.sun
.star
.frame
.FrameSearchFlag
.GLOBAL
) ;
390 log
.println("findFrame(\"XFrame,com.sun.star.frame.FrameSearchFlag.GLOBAL\") returns null") ;
392 } else if ( !aFrame
.equals(frame
) ) {
393 log
.println("findFrame(\"XFrame,com.sun.star.frame.FrameSearchFlag.GLOBAL\") "
394 + " returns frame which is not equal to passed in relation") ;
399 log
.println("Trying to find a frame with name '_self' ...");
400 XFrame frame
= oObj
.findFrame("_self",
401 com
.sun
.star
.frame
.FrameSearchFlag
.AUTO
) ;
403 log
.println("findFrame(\"_self\") returns null") ;
405 } else if ( !oObj
.equals(frame
) ) {
406 log
.println("findFrame(\"_self\") "
407 + " returns frame which is not equal to tested") ;
411 tRes
.tested("findFrame()", result
) ;
415 * At first new listener is added, then test calls the method and result
417 * Has <b> OK </b> status if isDesktop() method returnes true or if the
418 * listener was called and proper event past to listener.
420 public void _contextChanged() {
421 boolean result
= true;
422 TestFrameActionListener listener
= new TestFrameActionListener();
424 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
425 log
.println("Desktop cann't change context");
426 tRes
.tested("contextChanged()", true) ;
430 listenerCalled
[0] = false;
431 oObj
.addFrameActionListener(listener
);
433 oObj
.contextChanged();
434 if ( !listenerCalled
[0] ) {
435 log
.println("listener was not called on contextChanged() call.") ;
437 } else if (actionEvent
[0] != FrameAction
.CONTEXT_CHANGED
) {
438 log
.println("listener was called, but Action != CONTEXT_CHANGED") ;
442 oObj
.removeFrameActionListener(listener
);
445 boolean res
= isDesktop(log
, tEnv
, "contextChanged()");
446 if (res
) result
= res
;
447 tRes
.tested("contextChanged()", result
);
452 * Test calls the method. Remembered old creater is restored at the end. <p>
453 * Has <b> OK </b> status if the method sucessfully set new value to (XFrame)
456 public void _setCreator() {
457 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
458 log
.println("Desktop has no creator");
459 tRes
.tested("setCreator()", true) ;
463 XFramesSupplier oldCreator
= oObj
.getCreator() ;
464 oObj
.setCreator(null) ;
465 tRes
.tested("setCreator()", oObj
.getCreator() == null) ;
466 oObj
.setCreator(oldCreator
) ;
470 * Test calls the method, then result is checked.<p>
471 * Has <b> OK </b> status if method returns true, and values, set by the
472 * method are nulls, or if method returns false, and values are not changed.
473 * This method destroy the object. Therfore all other methods have to be
476 * <li> <code> getName() </code>
477 * <li> <code> setName() </code>
478 * <li> <code> activate() </code>
479 * <li> <code> deactivate() </code>
480 * <li> <code> isActive() </code>
481 * <li> <code> addFrameActionListener() </code>
482 * <li> <code> getComponentWindow() </code>
483 * <li> <code> getContainerWindow() </code>
484 * <li> <code> getController() </code>
485 * <li> <code> isTop() </code>
486 * <li> <code> findFrame() </code>
487 * <li> <code> contextChanged() </code>
488 * <li> <code> setCreator() </code>
492 public void _setComponent() {
493 // setComponent() destr
494 requiredMethod("getName()") ;
495 requiredMethod("setName()") ;
496 requiredMethod("activate()") ;
497 requiredMethod("deactivate()") ;
498 requiredMethod("isActive()") ;
499 requiredMethod("addFrameActionListener()") ;
500 requiredMethod("getComponentWindow()") ;
501 requiredMethod("getContainerWindow()") ;
502 requiredMethod("getController()") ;
503 requiredMethod("isTop()") ;
504 requiredMethod("findFrame()") ;
505 requiredMethod("contextChanged()") ;
506 requiredMethod("setCreator()") ;
508 boolean result
= true;
510 XWindow oldWindow
= oObj
.getComponentWindow();
511 XController oldController
= oObj
.getController();
512 boolean rs
= oObj
.setComponent(null, null);
513 if (rs
) { // component must be changed
514 result
&= oObj
.getComponentWindow() == null;
515 result
&= oObj
.getController() == null;
517 log
.println("setComponent() returns true, but component is " +
519 } else { // frame is not allowed to change component
520 result
&= oObj
.getComponentWindow() == oldWindow
;
521 result
&= oObj
.getController() == oldController
;
523 log
.println("setComponent() returns false, but component is" +
526 tRes
.tested("setComponent()", result
);
531 * Test calls the method. <p>
532 * Has <b> OK </b> status if the method successfully returns.
533 * In case a frame should initialised twice, a
534 * <CODE>com.sun.star.uno.RuntimeException</CODE> was thron. This is ok. But since
535 * a com.sun.star.uno.RuntimeException could thrown in any state the message of
536 * the exception must contain a defined string. In this case the test get an
537 * <CODE>OK</CODE> status.
538 * The following method tests are to be completed successfully before :
540 * <li> <code> setComponent() </code> : sets window and controller to the
544 public void _initialize() {
545 requiredMethod("setComponent()") ;
546 XWindow win
= oObj
.getContainerWindow() ;
549 oObj
.initialize(win
) ;
550 } catch (com
.sun
.star
.uno
.RuntimeException e
){
551 String message
="Frame::initialized() is called more then once, which isnt usefull nor allowed.";
552 if (e
.toString().indexOf(message
) != -1){
553 log
.println(e
.toString());
554 log
.println("methods throws exception, but it's OK");
556 log
.println(e
.toString());
561 tRes
.tested("initialize()", bOK
) ;
565 * Checks does relation 'Desktop' exist. Returns true if exist.
567 public static boolean isDesktop(PrintWriter log
,
568 TestEnvironment env
, String method
) {
569 Object isD
= env
.getObjRelation("Desktop");
571 log
.println("The Desktop doesn't support the method " + method
);
572 log
.println("It will always return true");
581 * Forces environment recreation.
583 public void after() {
584 disposeEnvironment();