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
.XWindow
;
22 import com
.sun
.star
.frame
.FrameAction
;
23 import com
.sun
.star
.frame
.FrameActionEvent
;
24 import com
.sun
.star
.frame
.XController
;
25 import com
.sun
.star
.frame
.XFrame
;
26 import com
.sun
.star
.frame
.XFrameActionListener
;
27 import com
.sun
.star
.frame
.XFramesSupplier
;
28 import com
.sun
.star
.lang
.EventObject
;
29 import java
.io
.PrintWriter
;
30 import lib
.MultiMethodTest
;
31 import lib
.TestEnvironment
;
34 * Testing <code>com.sun.star.frame.XFrame</code>
37 * <li><code> getName() </code></li>
38 * <li><code> setName() </code></li>
39 * <li><code> activate() </code></li>
40 * <li><code> deactivate() </code></li>
41 * <li><code> isActive() </code></li>
42 * <li><code> addFrameActionListener() </code></li>
43 * <li><code> removeFrameActionListener() </code></li>
44 * <li><code> getCreator() </code></li>
45 * <li><code> getComponentWindow() </code></li>
46 * <li><code> getContainerWindow() </code></li>
47 * <li><code> getController() </code></li>
48 * <li><code> isTop() </code></li>
49 * <li><code> findFrame() </code></li>
50 * <li><code> contextChanged() </code></li>
51 * <li><code> setCreator() </code></li>
52 * <li><code> setComponent() </code></li>
53 * <li><code> initialize() </code></li>
55 * This test needs the following object relations :
57 * <li> <code>'XFrame'</code> (of type <code>XFrame</code>)
58 * <b>optional</b>: any frame named 'XFrame'.
59 * Could be used by <code>findFrame</code> method to try
60 * to find other frame than itself.</li>
62 * <li> <code>'Desktop'</code> (of type <code>Object</code>):
63 * if exsists, then desktop component is tested</li>
65 * Test is <b> NOT </b> multithread compliant. <p>
66 * @see com.sun.star.frame.XFrame
68 public class _XFrame
extends MultiMethodTest
{
69 final FrameAction
[] actionEvent
= new FrameAction
[1] ;
70 final boolean[] listenerCalled
= new boolean[] {false} ;
71 final boolean[] activatedCalled
= new boolean[] {false} ;
72 final boolean[] deactivatedCalled
= new boolean[] {false} ;
73 final TestFrameActionListener listener
=
74 new TestFrameActionListener() ;
75 public static XFrame oObj
= null;
78 * Class used to test listeners.
80 private class TestFrameActionListener
81 implements XFrameActionListener
{
83 public void frameAction(FrameActionEvent e
) {
84 listenerCalled
[0] = true ;
85 activatedCalled
[0] |= e
.Action
== FrameAction
.FRAME_ACTIVATED
;
86 deactivatedCalled
[0] |= e
.Action
== FrameAction
.FRAME_DEACTIVATING
;
87 actionEvent
[0] = e
.Action
;
90 public void disposing(EventObject e
) {}
95 * Test calls the method. <p>
96 * Has <b> OK </b> status if the method does not return null.
98 public void _getName() {
99 String name
= oObj
.getName() ;
101 log
.println("getName() returned null: FAILED") ;
103 tRes
.tested("getName()", name
!=null) ;
107 * Test calls the method. <p>
108 * Has <b> OK </b> status if set and gotten names are equal.
110 public void _setName() {
111 String sName
= "XFrame" ;
114 String gName
= oObj
.getName();
115 boolean res
= sName
.equals(gName
);
117 log
.println("setName('" + sName
+
118 "'), but getName() return '" + gName
+ "'") ;
119 tRes
.tested("setName()", res
);
123 * Test calls the method. <p>
124 * Has <b> OK </b> status if the method successfully returns
125 * and no exceptions were thrown.
127 public void _activate() {
129 tRes
.tested("activate()", true) ;
133 * Test calls the method. <p>
134 * Has <b> OK </b> status if the method successfully returns
135 * and no exceptions were thrown.
137 public void _deactivate() {
140 tRes
.tested("deactivate()", true) ;
144 * Test calls the method. Then frame is deactivated and method called
146 * Has <b> OK </b> status if isDesktop() returns true or if the method
147 * always display real status of a frame during activation/deactivation.
149 public void _isActive() {
150 boolean result
= true;
152 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
153 log
.println("Desktop is always active");
154 tRes
.tested("isActive()", oObj
.isActive()) ;
159 result
&= !oObj
.isActive();
161 log
.println("after deactivate() method call, isActive() returned true");
163 result
&= oObj
.isActive();
164 if (!oObj
.isActive())
165 log
.println("after activate() method call, isActive() returned false") ;
166 boolean res
= isDesktop(log
,tEnv
,"isActive()");
169 tRes
.tested("isActive()", result
) ;
173 * Test calls the method. Then frame status (activated/deactivated) is
174 * changed, and the listener is checked.<p>
175 * Has <b> OK </b> status if isDesktop() method returnes true, or if the
176 * listener was called and frame was activated.
178 public void _addFrameActionListener() {
179 boolean result
= true ;
181 oObj
.addFrameActionListener(listener
) ;
186 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
187 log
.println("No actions supported by Desktop");
188 tRes
.tested("addFrameActionListener()", true) ;
192 util
.utils
.shortWait();
195 if (!listenerCalled
[0]) {
196 log
.println("listener was not called.") ;
199 if (!activatedCalled
[0]) {
200 log
.println("Listener was called, FRAME_ACTIVATED was not") ;
203 if (!deactivatedCalled
[0]) {
204 log
.println("Listener was called, FRAME_DEACTIVATING was not") ;
209 boolean res
= isDesktop(log
, tEnv
, "addFrameActionListener()");
212 tRes
.tested("addFrameActionListener()", result
) ;
216 * Test calls the method. Then frame status (activated/deactivated) is
217 * changed, and the listener is checked.<p>
218 * Has <b> OK </b> status if isDesktop() method returns true, or if the
219 * method actually removes listener so it does not react on
220 * activate/deactivate events. <p>
221 * The following method tests are to be completed successfully before :
223 * <li> <code> addFrameActionListener() </code>: adds action listener
227 public void _removeFrameActionListener() {
228 boolean result
= true;
230 requiredMethod("addFrameActionListener()");
231 listenerCalled
[0] = false;
232 oObj
.removeFrameActionListener(listener
);
236 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
237 log
.println("No actions supported by Desktop");
238 tRes
.tested("removeFrameActionListener()", true) ;
242 if (listenerCalled
[0])
243 log
.println("Listener wasn't removed, and was called");
244 boolean res
= isDesktop(log
, tEnv
, "removeFrameActionListener()");
245 if (res
) result
=res
; else result
= (!listenerCalled
[0]);
247 tRes
.tested("removeFrameActionListener()", result
);
251 * Test calls the method. <p>
252 * Has <b> OK </b> status if isDesktop() method returns true or if the method
253 * does not return null.
255 public void _getCreator() {
256 boolean result
= true;
258 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
259 log
.println("Desktop has no creator");
260 tRes
.tested("getCreator()", true) ;
264 XFramesSupplier creator
= oObj
.getCreator() ;
266 log
.println("getCreator() returns null") ;
267 boolean res
= isDesktop(log
,tEnv
,"getCreator()");
268 if (res
) result
=res
; else result
= (creator
!= null);
269 tRes
.tested("getCreator()", result
) ;
273 * Test calls the method. <p>
274 * Has <b> OK </b> status if isDesktop() method returns true or if the method
275 * does not return null.
277 public void _getComponentWindow() {
278 boolean result
= true;
280 XWindow win
= oObj
.getComponentWindow() ;
282 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
283 log
.println("Desktop has no component window");
284 tRes
.tested("getComponentWindow()", true) ;
289 log
.println("getComponentWindow() returns null") ;
290 boolean res
= isDesktop(log
,tEnv
,"getComponentWindow()");
291 if (res
) result
=res
; else result
= (win
!= null);
292 tRes
.tested("getComponentWindow()", result
) ;
296 * Test calls the method. <p>
297 * Has <b> OK </b> status if isDesktop() method returns true or if the method
298 * does not return null.
300 public void _getContainerWindow() {
301 boolean result
= true;
303 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
304 log
.println("Desktop has no container window");
305 tRes
.tested("getContainerWindow()", true) ;
309 XWindow win
= oObj
.getContainerWindow() ;
311 log
.println("getContainerWindow() returns null") ;
312 boolean res
= isDesktop(log
,tEnv
,"getContainerWindow()");
313 if (res
) result
=res
; else result
= (win
!= null);
314 tRes
.tested("getContainerWindow()", result
) ;
318 * Test calls the method. Then returned controller is checked. <p>
319 * Has <b> OK </b> status if isDesktop() method returns true or
320 * if the method returns non-null controller, having frame that's equal to
323 public void _getController() {
324 boolean result
= true;
325 XController ctrl
= oObj
.getController();
327 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
328 log
.println("Desktop has no controller");
329 tRes
.tested("getController()", true) ;
334 log
.println("getController() returns null");
337 XFrame frm
= ctrl
.getFrame();
338 if (!oObj
.equals(frm
)) {
339 log
.println("Frame returned by controller not " +
340 "equals to frame testing");
344 boolean res
= isDesktop(log
, tEnv
, "getController()");
346 tRes
.tested("getController()", result
) ;
350 * Test calls the method. <p>
351 * Has <b> OK </b> status if the method successfully returns
352 * and no exceptions were thrown.
354 public void _isTop() {
355 log
.println("isTop() = " + oObj
.isTop());
356 tRes
.tested("isTop()", true) ;
360 * After obtaining an object relation 'XFrame', test tries to find a frame
361 * named 'XFrame'. <p>
362 * Has <b> OK </b> status if the method returns non-null object that's equal
363 * to previously obtained object relation.
365 public void _findFrame() {
366 boolean result
= true ;
368 XFrame aFrame
= (XFrame
) tEnv
.getObjRelation("XFrame");
370 if (aFrame
!= null) {
371 log
.println("Trying to find a frame with name 'XFrame' ...");
372 XFrame frame
= oObj
.findFrame("XFrame",
373 com
.sun
.star
.frame
.FrameSearchFlag
.GLOBAL
) ;
375 log
.println("findFrame(\"XFrame,com.sun.star.frame.FrameSearchFlag.GLOBAL\") returns null") ;
377 } else if ( !aFrame
.equals(frame
) ) {
378 log
.println("findFrame(\"XFrame,com.sun.star.frame.FrameSearchFlag.GLOBAL\") "
379 + " returns frame which is not equal to passed in relation") ;
384 log
.println("Trying to find a frame with name '_self' ...");
385 XFrame frame
= oObj
.findFrame("_self",
386 com
.sun
.star
.frame
.FrameSearchFlag
.AUTO
) ;
388 log
.println("findFrame(\"_self\") returns null") ;
390 } else if ( !oObj
.equals(frame
) ) {
391 log
.println("findFrame(\"_self\") "
392 + " returns frame which is not equal to tested") ;
396 tRes
.tested("findFrame()", result
) ;
400 * At first new listener is added, then test calls the method and result
402 * Has <b> OK </b> status if isDesktop() method returnes true or if the
403 * listener was called and proper event past to listener.
405 public void _contextChanged() {
406 boolean result
= true;
407 TestFrameActionListener listener
= new TestFrameActionListener();
409 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
410 log
.println("Desktop cann't change context");
411 tRes
.tested("contextChanged()", true) ;
415 listenerCalled
[0] = false;
416 oObj
.addFrameActionListener(listener
);
418 oObj
.contextChanged();
419 if ( !listenerCalled
[0] ) {
420 log
.println("listener was not called on contextChanged() call.") ;
422 } else if (actionEvent
[0] != FrameAction
.CONTEXT_CHANGED
) {
423 log
.println("listener was called, but Action != CONTEXT_CHANGED") ;
427 oObj
.removeFrameActionListener(listener
);
430 boolean res
= isDesktop(log
, tEnv
, "contextChanged()");
431 if (res
) result
= res
;
432 tRes
.tested("contextChanged()", result
);
437 * Test calls the method. Remembered old creater is restored at the end. <p>
438 * Has <b> OK </b> status if the method successfully set new value to (XFrame)
441 public void _setCreator() {
442 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
443 log
.println("Desktop has no creator");
444 tRes
.tested("setCreator()", true) ;
448 XFramesSupplier oldCreator
= oObj
.getCreator() ;
449 oObj
.setCreator(null) ;
450 tRes
.tested("setCreator()", oObj
.getCreator() == null) ;
451 oObj
.setCreator(oldCreator
) ;
455 * Test calls the method, then result is checked.<p>
456 * Has <b> OK </b> status if method returns true, and values, set by the
457 * method are nulls, or if method returns false, and values are not changed.
458 * This method destroy the object. Therfore all other methods have to be
461 * <li> <code> getName() </code>
462 * <li> <code> setName() </code>
463 * <li> <code> activate() </code>
464 * <li> <code> deactivate() </code>
465 * <li> <code> isActive() </code>
466 * <li> <code> addFrameActionListener() </code>
467 * <li> <code> getComponentWindow() </code>
468 * <li> <code> getContainerWindow() </code>
469 * <li> <code> getController() </code>
470 * <li> <code> isTop() </code>
471 * <li> <code> findFrame() </code>
472 * <li> <code> contextChanged() </code>
473 * <li> <code> setCreator() </code>
477 public void _setComponent() {
478 // setComponent() destr
479 requiredMethod("getName()") ;
480 requiredMethod("setName()") ;
481 requiredMethod("activate()") ;
482 requiredMethod("deactivate()") ;
483 requiredMethod("isActive()") ;
484 requiredMethod("addFrameActionListener()") ;
485 requiredMethod("getComponentWindow()") ;
486 requiredMethod("getContainerWindow()") ;
487 requiredMethod("getController()") ;
488 requiredMethod("isTop()") ;
489 requiredMethod("findFrame()") ;
490 requiredMethod("contextChanged()") ;
491 requiredMethod("setCreator()") ;
493 boolean result
= true;
495 XWindow oldWindow
= oObj
.getComponentWindow();
496 XController oldController
= oObj
.getController();
497 boolean rs
= oObj
.setComponent(null, null);
498 if (rs
) { // component must be changed
499 result
&= oObj
.getComponentWindow() == null;
500 result
&= oObj
.getController() == null;
502 log
.println("setComponent() returns true, but component is " +
504 } else { // frame is not allowed to change component
505 result
&= oObj
.getComponentWindow() == oldWindow
;
506 result
&= oObj
.getController() == oldController
;
508 log
.println("setComponent() returns false, but component is" +
511 tRes
.tested("setComponent()", result
);
516 * Test calls the method. <p>
517 * Has <b> OK </b> status if the method successfully returns.
518 * In case a frame should initialised twice, a
519 * <CODE>com.sun.star.uno.RuntimeException</CODE> was thron. This is ok. But since
520 * a com.sun.star.uno.RuntimeException could thrown in any state the message of
521 * the exception must contain a defined string. In this case the test get an
522 * <CODE>OK</CODE> status.
523 * The following method tests are to be completed successfully before :
525 * <li> <code> setComponent() </code> : sets window and controller to the
529 public void _initialize() {
530 requiredMethod("setComponent()") ;
531 XWindow win
= oObj
.getContainerWindow() ;
534 oObj
.initialize(win
) ;
535 } catch (com
.sun
.star
.uno
.RuntimeException e
){
536 String message
="Frame::initialized() is called more than once, which is not useful nor allowed.";
537 if (e
.toString().indexOf(message
) != -1){
538 log
.println(e
.toString());
539 log
.println("methods throws exception, but it's OK");
541 log
.println(e
.toString());
546 tRes
.tested("initialize()", bOK
) ;
550 * Checks does relation 'Desktop' exist. Returns true if exist.
552 public static boolean isDesktop(PrintWriter log
,
553 TestEnvironment env
, String method
) {
554 Object isD
= env
.getObjRelation("Desktop");
556 log
.println("The Desktop doesn't support the method " + method
);
557 log
.println("It will always return true");
566 * Forces environment recreation.
569 public void after() {
570 disposeEnvironment();