bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XFrame.java
blobc24c4fa2145eede8c4b892d32fd6d738d51b3719
1 /*
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 .
19 package ifc.frame;
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;
33 /**
34 * Testing <code>com.sun.star.frame.XFrame</code>
35 * interface methods:
36 * <ul>
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>
54 * </ul><p>
55 * This test needs the following object relations :
56 * <ul>
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>
64 * </ul> <p>
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;
77 /**
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) {}
94 /**
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() ;
100 if (name == null)
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" ;
113 oObj.setName(sName);
114 String gName = oObj.getName();
115 boolean res = sName.equals(gName);
116 if (! res)
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() {
128 oObj.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() {
138 oObj.deactivate() ;
139 oObj.activate() ;
140 tRes.tested("deactivate()", true) ;
144 * Test calls the method. Then frame is deactivated and method called
145 * again. <p>
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()) ;
155 return;
158 oObj.deactivate();
159 result &= !oObj.isActive();
160 if (oObj.isActive())
161 log.println("after deactivate() method call, isActive() returned true");
162 oObj.activate();
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()");
167 if (res) result=res;
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) ;
182 oObj.activate() ;
183 oObj.deactivate() ;
184 oObj.activate() ;
186 if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
187 log.println("No actions supported by Desktop");
188 tRes.tested("addFrameActionListener()", true) ;
189 return;
192 util.utils.shortWait();
195 if (!listenerCalled[0]) {
196 log.println("listener was not called.") ;
197 result = false ;
198 } else {
199 if (!activatedCalled[0]) {
200 log.println("Listener was called, FRAME_ACTIVATED was not") ;
201 result = false ;
203 if (!deactivatedCalled[0]) {
204 log.println("Listener was called, FRAME_DEACTIVATING was not") ;
205 result = false ;
209 boolean res = isDesktop(log, tEnv, "addFrameActionListener()");
210 if (res) result=res;
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 :
222 * <ul>
223 * <li> <code> addFrameActionListener() </code>: adds action listener
224 * to a frame </li>
225 * </ul>
227 public void _removeFrameActionListener() {
228 boolean result = true;
230 requiredMethod("addFrameActionListener()");
231 listenerCalled[0] = false;
232 oObj.removeFrameActionListener(listener);
233 oObj.activate();
234 oObj.deactivate();
235 oObj.activate();
236 if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
237 log.println("No actions supported by Desktop");
238 tRes.tested("removeFrameActionListener()", true) ;
239 return;
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) ;
261 return;
264 XFramesSupplier creator = oObj.getCreator() ;
265 if (creator == null)
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) ;
285 return;
288 if (win == null)
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) ;
306 return;
309 XWindow win = oObj.getContainerWindow() ;
310 if (win == null)
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
321 * a (XFrame) oObj.
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) ;
330 return;
333 if (ctrl == null) {
334 log.println("getController() returns null");
335 result = false;
336 } else {
337 XFrame frm = ctrl.getFrame();
338 if (!oObj.equals(frm)) {
339 log.println("Frame returned by controller not " +
340 "equals to frame testing");
341 result = false;
344 boolean res = isDesktop(log, tEnv, "getController()");
345 if (res) result=res;
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) ;
374 if (frame == null) {
375 log.println("findFrame(\"XFrame,com.sun.star.frame.FrameSearchFlag.GLOBAL\") returns null") ;
376 result = false ;
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") ;
380 result = false ;
384 log.println("Trying to find a frame with name '_self' ...");
385 XFrame frame = oObj.findFrame("_self",
386 com.sun.star.frame.FrameSearchFlag.AUTO) ;
387 if (frame == null) {
388 log.println("findFrame(\"_self\") returns null") ;
389 result = false ;
390 } else if ( !oObj.equals(frame) ) {
391 log.println("findFrame(\"_self\") "
392 + " returns frame which is not equal to tested") ;
393 result = false ;
396 tRes.tested("findFrame()", result) ;
400 * At first new listener is added, then test calls the method and result
401 * is checked. <p>
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) ;
412 return;
415 listenerCalled[0] = false;
416 oObj.addFrameActionListener(listener);
417 try {
418 oObj.contextChanged();
419 if ( !listenerCalled[0] ) {
420 log.println("listener was not called on contextChanged() call.") ;
421 result = false;
422 } else if (actionEvent[0] != FrameAction.CONTEXT_CHANGED) {
423 log.println("listener was called, but Action != CONTEXT_CHANGED") ;
424 result = false;
426 } finally {
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)
439 * oObj object.
441 public void _setCreator() {
442 if (tEnv.getTestCase().getObjectName().equals("Desktop")) {
443 log.println("Desktop has no creator");
444 tRes.tested("setCreator()", true) ;
445 return;
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
459 * executed before :
460 * <ul>
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>
474 * object</li>
475 * </ul>
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;
501 if (!result)
502 log.println("setComponent() returns true, but component is " +
503 "not changed.");
504 } else { // frame is not allowed to change component
505 result &= oObj.getComponentWindow() == oldWindow ;
506 result &= oObj.getController() == oldController ;
507 if (!result)
508 log.println("setComponent() returns false, but component is" +
509 "changed.");
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 :
524 * <ul>
525 * <li> <code> setComponent() </code> : sets window and controller to the
526 * object</li>
527 * </ul>
529 public void _initialize() {
530 requiredMethod("setComponent()") ;
531 XWindow win = oObj.getContainerWindow() ;
532 boolean bOK = true;
533 try {
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");
540 }else{
541 log.println(e.toString());
542 bOK=false;
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");
555 if (isD != null) {
556 log.println("The Desktop doesn't support the method " + method);
557 log.println("It will always return true");
558 return true;
560 else {
561 return false;
566 * Forces environment recreation.
568 @Override
569 public void after() {
570 disposeEnvironment();