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.awt.XWindow;
23 import com
.sun
.star
.frame
.FrameAction
;
24 import com
.sun
.star
.frame
.FrameActionEvent
;
25 import com
.sun
.star
.frame
.XController
;
26 import com
.sun
.star
.frame
.XFrame
;
27 import com
.sun
.star
.frame
.XFrameActionListener
;
28 import com
.sun
.star
.frame
.XFramesSupplier
;
29 import com
.sun
.star
.lang
.EventObject
;
30 import java
.io
.PrintWriter
;
31 import lib
.MultiMethodTest
;
32 import lib
.TestEnvironment
;
35 * Testing <code>com.sun.star.frame.XFrame</code>
38 * <li><code> getName() </code></li>
39 * <li><code> setName() </code></li>
40 * <li><code> activate() </code></li>
41 * <li><code> deactivate() </code></li>
42 * <li><code> isActive() </code></li>
43 * <li><code> addFrameActionListener() </code></li>
44 * <li><code> removeFrameActionListener() </code></li>
45 * <li><code> getCreator() </code></li>
46 * <li><code> getComponentWindow() </code></li>
47 * <li><code> getContainerWindow() </code></li>
48 * <li><code> getController() </code></li>
49 * <li><code> isTop() </code></li>
50 * <li><code> findFrame() </code></li>
51 * <li><code> contextChanged() </code></li>
52 * <li><code> setCreator() </code></li>
53 * <li><code> setComponent() </code></li>
54 * <li><code> initialize() </code></li>
56 * This test needs the following object relations :
58 * <li> <code>'XFrame'</code> (of type <code>XFrame</code>)
59 * <b>optional</b>: any frame named 'XFrame'.
60 * Could be used by <code>findFrame</code> method to try
61 * to find other frame than itself.</li>
63 * <li> <code>'Desktop'</code> (of type <code>Object</code>):
64 * if exsists, then desktop component is tested</li>
66 * Test is <b> NOT </b> multithread compilant. <p>
67 * @see com.sun.star.frame.XFrame
69 public class _XFrame
extends MultiMethodTest
{
70 final FrameAction
[] actionEvent
= new FrameAction
[1] ;
71 final boolean[] listenerCalled
= new boolean[] {false} ;
72 final boolean[] activatedCalled
= new boolean[] {false} ;
73 final boolean[] deactivatedCalled
= new boolean[] {false} ;
74 final TestFrameActionListener listener
=
75 new TestFrameActionListener() ;
76 public static XFrame oObj
= null;
79 * Class used to test listeners.
81 private class TestFrameActionListener
82 implements XFrameActionListener
{
84 public void frameAction(FrameActionEvent e
) {
85 listenerCalled
[0] = true ;
86 activatedCalled
[0] |= e
.Action
== FrameAction
.FRAME_ACTIVATED
;
87 deactivatedCalled
[0] |= e
.Action
== FrameAction
.FRAME_DEACTIVATING
;
88 actionEvent
[0] = e
.Action
;
91 public void disposing(EventObject e
) {}
96 * Test calls the method. <p>
97 * Has <b> OK </b> status if the method does not return null.
99 public void _getName() {
100 String name
= oObj
.getName() ;
102 log
.println("getName() returned null: FAILED") ;
104 tRes
.tested("getName()", name
!=null) ;
108 * Test calls the method. <p>
109 * Has <b> OK </b> status if set and gotten names are equal.
111 public void _setName() {
112 String sName
= "XFrame" ;
115 String gName
= oObj
.getName();
116 boolean res
= sName
.equals(gName
);
118 log
.println("setName('" + sName
+
119 "'), but getName() return '" + gName
+ "'") ;
120 tRes
.tested("setName()", res
);
124 * Test calls the method. <p>
125 * Has <b> OK </b> status if the method successfully returns
126 * and no exceptions were thrown.
128 public void _activate() {
130 tRes
.tested("activate()", true) ;
134 * Test calls the method. <p>
135 * Has <b> OK </b> status if the method successfully returns
136 * and no exceptions were thrown.
138 public void _deactivate() {
141 tRes
.tested("deactivate()", true) ;
145 * Test calls the method. Then frame is deactivated and method called
147 * Has <b> OK </b> status if isDesktop() returns true or if the method
148 * always display real status of a frame during activation/deactivation.
150 public void _isActive() {
151 boolean result
= true;
153 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
154 log
.println("Desktop is always active");
155 tRes
.tested("isActive()", oObj
.isActive()) ;
160 result
&= !oObj
.isActive();
162 log
.println("after deactivate() method call, isActive() returned true");
164 result
&= oObj
.isActive();
165 if (!oObj
.isActive())
166 log
.println("after activate() method call, isActive() returned false") ;
167 boolean res
= isDesktop(log
,tEnv
,"isActive()");
170 tRes
.tested("isActive()", result
) ;
174 * Test calls the method. Then frame status (activated/deactivated) is
175 * changed, and the listener is checked.<p>
176 * Has <b> OK </b> status if isDesktop() method returnes true, or if the
177 * listener was called and frame was activated.
179 public void _addFrameActionListener() {
180 boolean result
= true ;
182 oObj
.addFrameActionListener(listener
) ;
187 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
188 log
.println("No actions supported by Desktop");
189 tRes
.tested("addFrameActionListener()", true) ;
195 }catch (InterruptedException ex
) {}
198 if (!listenerCalled
[0]) {
199 log
.println("listener was not called.") ;
202 if (!activatedCalled
[0]) {
203 log
.println("Listener was called, FRAME_ACTIVATED was not") ;
206 if (!deactivatedCalled
[0]) {
207 log
.println("Listener was called, FRAME_DEACTIVATING was not") ;
212 boolean res
= isDesktop(log
, tEnv
, "addFrameActionListener()");
215 tRes
.tested("addFrameActionListener()", result
) ;
219 * Test calls the method. Then frame status (activated/deactivated) is
220 * changed, and the listener is checked.<p>
221 * Has <b> OK </b> status if isDesktop() method returns true, or if the
222 * method actually removes listener so it does not react on
223 * activate/deactivate events. <p>
224 * The following method tests are to be completed successfully before :
226 * <li> <code> addFrameActionListener() </code>: adds action listener
230 public void _removeFrameActionListener() {
231 boolean result
= true;
233 requiredMethod("addFrameActionListener()");
234 listenerCalled
[0] = false;
235 oObj
.removeFrameActionListener(listener
);
239 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
240 log
.println("No actions supported by Desktop");
241 tRes
.tested("removeFrameActionListener()", true) ;
245 if (listenerCalled
[0])
246 log
.println("Listener wasn't removed, and was called");
247 boolean res
= isDesktop(log
, tEnv
, "removeFrameActionListener()");
248 if (res
) result
=res
; else result
= (!listenerCalled
[0]);
250 tRes
.tested("removeFrameActionListener()", result
);
254 * Test calls the method. <p>
255 * Has <b> OK </b> status if isDesktop() method returns true or if the method
256 * does not return null.
258 public void _getCreator() {
259 boolean result
= true;
261 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
262 log
.println("Desktop has no creator");
263 tRes
.tested("getCreator()", true) ;
267 XFramesSupplier creator
= oObj
.getCreator() ;
269 log
.println("getCreator() returns null") ;
270 boolean res
= isDesktop(log
,tEnv
,"getCreator()");
271 if (res
) result
=res
; else result
= (creator
!= null);
272 tRes
.tested("getCreator()", result
) ;
276 * Test calls the method. <p>
277 * Has <b> OK </b> status if isDesktop() method returns true or if the method
278 * does not return null.
280 public void _getComponentWindow() {
281 boolean result
= true;
283 XWindow win
= oObj
.getComponentWindow() ;
285 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
286 log
.println("Desktop has no component window");
287 tRes
.tested("getComponentWindow()", true) ;
292 log
.println("getComponentWindow() returns null") ;
293 boolean res
= isDesktop(log
,tEnv
,"getComponentWindow()");
294 if (res
) result
=res
; else result
= (win
!= null);
295 tRes
.tested("getComponentWindow()", result
) ;
299 * Test calls the method. <p>
300 * Has <b> OK </b> status if isDesktop() method returns true or if the method
301 * does not return null.
303 public void _getContainerWindow() {
304 boolean result
= true;
306 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
307 log
.println("Desktop has no container window");
308 tRes
.tested("getContainerWindow()", true) ;
312 XWindow win
= oObj
.getContainerWindow() ;
314 log
.println("getContainerWindow() returns null") ;
315 boolean res
= isDesktop(log
,tEnv
,"getContainerWindow()");
316 if (res
) result
=res
; else result
= (win
!= null);
317 tRes
.tested("getContainerWindow()", result
) ;
321 * Test calls the method. Then returned controller is checked. <p>
322 * Has <b> OK </b> status if isDesktop() method returns true or
323 * if the method returns non-null controller, having frame that's equal to
326 public void _getController() {
327 boolean result
= true;
328 XController ctrl
= oObj
.getController();
330 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
331 log
.println("Desktop has no controller");
332 tRes
.tested("getController()", true) ;
337 log
.println("getController() returns null");
340 XFrame frm
= ctrl
.getFrame();
341 if (!oObj
.equals(frm
)) {
342 log
.println("Frame returned by controller not " +
343 "equals to frame testing");
347 boolean res
= isDesktop(log
, tEnv
, "getController()");
349 tRes
.tested("getController()", result
) ;
353 * Test calls the method. <p>
354 * Has <b> OK </b> status if the method successfully returns
355 * and no exceptions were thrown.
357 public void _isTop() {
358 log
.println("isTop() = " + oObj
.isTop());
359 tRes
.tested("isTop()", true) ;
363 * After obtaining an object relation 'XFrame', test tries to find a frame
364 * named 'XFrame'. <p>
365 * Has <b> OK </b> status if the method returns non-null object that's equal
366 * to previously obtained object relation.
368 public void _findFrame() {
369 boolean result
= true ;
371 XFrame aFrame
= (XFrame
) tEnv
.getObjRelation("XFrame");
373 if (aFrame
!= null) {
374 log
.println("Trying to find a frame with name 'XFrame' ...");
375 XFrame frame
= oObj
.findFrame("XFrame",
376 com
.sun
.star
.frame
.FrameSearchFlag
.GLOBAL
) ;
378 log
.println("findFrame(\"XFrame,com.sun.star.frame.FrameSearchFlag.GLOBAL\") returns null") ;
380 } else if ( !aFrame
.equals(frame
) ) {
381 log
.println("findFrame(\"XFrame,com.sun.star.frame.FrameSearchFlag.GLOBAL\") "
382 + " returns frame which is not equal to passed in relation") ;
387 log
.println("Trying to find a frame with name '_self' ...");
388 XFrame frame
= oObj
.findFrame("_self",
389 com
.sun
.star
.frame
.FrameSearchFlag
.AUTO
) ;
391 log
.println("findFrame(\"_self\") returns null") ;
393 } else if ( !oObj
.equals(frame
) ) {
394 log
.println("findFrame(\"_self\") "
395 + " returns frame which is not equal to tested") ;
399 tRes
.tested("findFrame()", result
) ;
403 * At first new listener is added, then test calls the method and result
405 * Has <b> OK </b> status if isDesktop() method returnes true or if the
406 * listener was called and proper event past to listener.
408 public void _contextChanged() {
409 boolean result
= true;
410 TestFrameActionListener listener
= new TestFrameActionListener();
412 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
413 log
.println("Desktop cann't change context");
414 tRes
.tested("contextChanged()", true) ;
418 listenerCalled
[0] = false;
419 oObj
.addFrameActionListener(listener
);
421 oObj
.contextChanged();
422 if ( !listenerCalled
[0] ) {
423 log
.println("listener was not called on contextChanged() call.") ;
425 } else if (actionEvent
[0] != FrameAction
.CONTEXT_CHANGED
) {
426 log
.println("listener was called, but Action != CONTEXT_CHANGED") ;
430 oObj
.removeFrameActionListener(listener
);
433 boolean res
= isDesktop(log
, tEnv
, "contextChanged()");
434 if (res
) result
= res
;
435 tRes
.tested("contextChanged()", result
);
440 * Test calls the method. Remembered old creater is restored at the end. <p>
441 * Has <b> OK </b> status if the method successfully set new value to (XFrame)
444 public void _setCreator() {
445 if (tEnv
.getTestCase().getObjectName().equals("Desktop")) {
446 log
.println("Desktop has no creator");
447 tRes
.tested("setCreator()", true) ;
451 XFramesSupplier oldCreator
= oObj
.getCreator() ;
452 oObj
.setCreator(null) ;
453 tRes
.tested("setCreator()", oObj
.getCreator() == null) ;
454 oObj
.setCreator(oldCreator
) ;
458 * Test calls the method, then result is checked.<p>
459 * Has <b> OK </b> status if method returns true, and values, set by the
460 * method are nulls, or if method returns false, and values are not changed.
461 * This method destroy the object. Therfore all other methods have to be
464 * <li> <code> getName() </code>
465 * <li> <code> setName() </code>
466 * <li> <code> activate() </code>
467 * <li> <code> deactivate() </code>
468 * <li> <code> isActive() </code>
469 * <li> <code> addFrameActionListener() </code>
470 * <li> <code> getComponentWindow() </code>
471 * <li> <code> getContainerWindow() </code>
472 * <li> <code> getController() </code>
473 * <li> <code> isTop() </code>
474 * <li> <code> findFrame() </code>
475 * <li> <code> contextChanged() </code>
476 * <li> <code> setCreator() </code>
480 public void _setComponent() {
481 // setComponent() destr
482 requiredMethod("getName()") ;
483 requiredMethod("setName()") ;
484 requiredMethod("activate()") ;
485 requiredMethod("deactivate()") ;
486 requiredMethod("isActive()") ;
487 requiredMethod("addFrameActionListener()") ;
488 requiredMethod("getComponentWindow()") ;
489 requiredMethod("getContainerWindow()") ;
490 requiredMethod("getController()") ;
491 requiredMethod("isTop()") ;
492 requiredMethod("findFrame()") ;
493 requiredMethod("contextChanged()") ;
494 requiredMethod("setCreator()") ;
496 boolean result
= true;
498 XWindow oldWindow
= oObj
.getComponentWindow();
499 XController oldController
= oObj
.getController();
500 boolean rs
= oObj
.setComponent(null, null);
501 if (rs
) { // component must be changed
502 result
&= oObj
.getComponentWindow() == null;
503 result
&= oObj
.getController() == null;
505 log
.println("setComponent() returns true, but component is " +
507 } else { // frame is not allowed to change component
508 result
&= oObj
.getComponentWindow() == oldWindow
;
509 result
&= oObj
.getController() == oldController
;
511 log
.println("setComponent() returns false, but component is" +
514 tRes
.tested("setComponent()", result
);
519 * Test calls the method. <p>
520 * Has <b> OK </b> status if the method successfully returns.
521 * In case a frame should initialised twice, a
522 * <CODE>com.sun.star.uno.RuntimeException</CODE> was thron. This is ok. But since
523 * a com.sun.star.uno.RuntimeException could thrown in any state the message of
524 * the exception must contain a defined string. In this case the test get an
525 * <CODE>OK</CODE> status.
526 * The following method tests are to be completed successfully before :
528 * <li> <code> setComponent() </code> : sets window and controller to the
532 public void _initialize() {
533 requiredMethod("setComponent()") ;
534 XWindow win
= oObj
.getContainerWindow() ;
537 oObj
.initialize(win
) ;
538 } catch (com
.sun
.star
.uno
.RuntimeException e
){
539 String message
="Frame::initialized() is called more then once, which isnt useful nor allowed.";
540 if (e
.toString().indexOf(message
) != -1){
541 log
.println(e
.toString());
542 log
.println("methods throws exception, but it's OK");
544 log
.println(e
.toString());
549 tRes
.tested("initialize()", bOK
) ;
553 * Checks does relation 'Desktop' exist. Returns true if exist.
555 public static boolean isDesktop(PrintWriter log
,
556 TestEnvironment env
, String method
) {
557 Object isD
= env
.getObjRelation("Desktop");
559 log
.println("The Desktop doesn't support the method " + method
);
560 log
.println("It will always return true");
569 * Forces environment recreation.
571 public void after() {
572 disposeEnvironment();