1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package ifc.frame; 25 26 import com.sun.star.awt.XWindow; 27 //import com.sun.star.awt.XWindow; 28 import com.sun.star.frame.FrameAction; 29 import com.sun.star.frame.FrameActionEvent; 30 import com.sun.star.frame.XController; 31 import com.sun.star.frame.XFrame; 32 import com.sun.star.frame.XFrameActionListener; 33 import com.sun.star.frame.XFramesSupplier; 34 import com.sun.star.lang.EventObject; 35 import java.io.PrintWriter; 36 import lib.MultiMethodTest; 37 import lib.TestEnvironment; 38 39 /** 40 * Testing <code>com.sun.star.frame.XFrame</code> 41 * interface methods: 42 * <ul> 43 * <li><code> getName() </code></li> 44 * <li><code> setName() </code></li> 45 * <li><code> activate() </code></li> 46 * <li><code> deactivate() </code></li> 47 * <li><code> isActive() </code></li> 48 * <li><code> addFrameActionListener() </code></li> 49 * <li><code> removeFrameActionListener() </code></li> 50 * <li><code> getCreator() </code></li> 51 * <li><code> getComponentWindow() </code></li> 52 * <li><code> getContainerWindow() </code></li> 53 * <li><code> getController() </code></li> 54 * <li><code> isTop() </code></li> 55 * <li><code> findFrame() </code></li> 56 * <li><code> contextChanged() </code></li> 57 * <li><code> setCreator() </code></li> 58 * <li><code> setComponent() </code></li> 59 * <li><code> initialize() </code></li> 60 * </ul><p> 61 * This test needs the following object relations : 62 * <ul> 63 * <li> <code>'XFrame'</code> (of type <code>XFrame</code>) 64 * <b>optional</b>: any frame named 'XFrame'. 65 * Could be used by <code>findFrame</code> method to try 66 * to find other frame than itself.</li> 67 * 68 * <li> <code>'Desktop'</code> (of type <code>Object</code>): 69 * if exsists, then desktop component is tested</li> 70 * </ul> <p> 71 * Test is <b> NOT </b> multithread compilant. <p> 72 * @see com.sun.star.frame.XFrame 73 */ 74 public class _XFrame extends MultiMethodTest { 75 final FrameAction[] actionEvent = new FrameAction[1] ; 76 final boolean[] listenerCalled = new boolean[] {false} ; 77 final boolean[] activatedCalled = new boolean[] {false} ; 78 final boolean[] deactivatedCalled = new boolean[] {false} ; 79 final TestFrameActionListener listener = 80 new TestFrameActionListener() ; 81 public static XFrame oObj = null; 82 83 /** 84 * Class used to test listeners. 85 */ 86 private class TestFrameActionListener 87 implements XFrameActionListener { 88 frameAction(FrameActionEvent e)89 public void frameAction(FrameActionEvent e) { 90 listenerCalled[0] = true ; 91 activatedCalled[0] |= e.Action == FrameAction.FRAME_ACTIVATED; 92 deactivatedCalled[0] |= e.Action == FrameAction.FRAME_DEACTIVATING; 93 actionEvent[0] = e.Action; 94 } 95 disposing(EventObject e)96 public void disposing(EventObject e) {} 97 98 } 99 100 /** 101 * Test calls the method. <p> 102 * Has <b> OK </b> status if the method does not return null. 103 */ _getName()104 public void _getName() { 105 String name = oObj.getName() ; 106 if (name == null) 107 log.println("getName() returned null: FAILED") ; 108 109 tRes.tested("getName()", name!=null) ; 110 } 111 112 /** 113 * Test calls the method. <p> 114 * Has <b> OK </b> status if set and gotten names are equal. 115 */ _setName()116 public void _setName() { 117 String sName = "XFrame" ; 118 119 oObj.setName(sName); 120 String gName = oObj.getName(); 121 boolean res = sName.equals(gName); 122 if (! res) 123 log.println("setName('" + sName + 124 "'), but getName() return '" + gName + "'") ; 125 tRes.tested("setName()", res); 126 } 127 128 /** 129 * Test calls the method. <p> 130 * Has <b> OK </b> status if the method successfully returns 131 * and no exceptions were thrown. 132 */ _activate()133 public void _activate() { 134 oObj.activate() ; 135 tRes.tested("activate()", true) ; 136 } 137 138 /** 139 * Test calls the method. <p> 140 * Has <b> OK </b> status if the method successfully returns 141 * and no exceptions were thrown. 142 */ _deactivate()143 public void _deactivate() { 144 oObj.deactivate() ; 145 oObj.activate() ; 146 tRes.tested("deactivate()", true) ; 147 } 148 149 /** 150 * Test calls the method. Then frame is deactivated and method called 151 * again. <p> 152 * Has <b> OK </b> status if isDesktop() returns true or if the method 153 * always display real status of a frame during activation/deactivation. 154 */ _isActive()155 public void _isActive() { 156 boolean result = true; 157 158 if (tEnv.getTestCase().getObjectName().equals("Desktop")) { 159 log.println("Desktop is always active"); 160 tRes.tested("isActive()", oObj.isActive()) ; 161 return; 162 } 163 164 oObj.deactivate(); 165 result &= !oObj.isActive(); 166 if (oObj.isActive()) 167 log.println("after deactivate() method call, isActive() returned true"); 168 oObj.activate(); 169 result &= oObj.isActive(); 170 if (!oObj.isActive()) 171 log.println("after activate() method call, isActive() returned false") ; 172 boolean res = isDesktop(log,tEnv,"isActive()"); 173 if (res) result=res; 174 175 tRes.tested("isActive()", result) ; 176 } 177 178 /** 179 * Test calls the method. Then frame status (activated/deactivated) is 180 * changed, and the listener is checked.<p> 181 * Has <b> OK </b> status if isDesktop() method returnes true, or if the 182 * listener was called and frame was activated. 183 */ _addFrameActionListener()184 public void _addFrameActionListener() { 185 boolean result = true ; 186 187 oObj.addFrameActionListener(listener) ; 188 oObj.activate() ; 189 oObj.deactivate() ; 190 oObj.activate() ; 191 192 if (tEnv.getTestCase().getObjectName().equals("Desktop")) { 193 log.println("No actions supported by Desktop"); 194 tRes.tested("addFrameActionListener()", true) ; 195 return; 196 } 197 198 try { 199 Thread.sleep(500); 200 }catch (InterruptedException ex) {} 201 202 203 if (!listenerCalled[0]) { 204 log.println("listener was not called.") ; 205 result = false ; 206 } else { 207 if (!activatedCalled[0]) { 208 log.println("Listener was called, FRAME_ACTIVATED was not") ; 209 result = false ; 210 } 211 if (!deactivatedCalled[0]) { 212 log.println("Listener was called, FRAME_DEACTIVATING was not") ; 213 result = false ; 214 } 215 } 216 217 boolean res = isDesktop(log, tEnv, "addFrameActionListener()"); 218 if (res) result=res; 219 220 tRes.tested("addFrameActionListener()", result) ; 221 } 222 223 /** 224 * Test calls the method. Then frame status (activated/deactivated) is 225 * changed, and the listener is checked.<p> 226 * Has <b> OK </b> status if isDesktop() method returns true, or if the 227 * method actually removes listener so it does not react on 228 * activate/deactivate events. <p> 229 * The following method tests are to be completed successfully before : 230 * <ul> 231 * <li> <code> addFrameActionListener() </code>: adds action listener 232 * to a frame </li> 233 * </ul> 234 */ _removeFrameActionListener()235 public void _removeFrameActionListener() { 236 boolean result = true; 237 238 requiredMethod("addFrameActionListener()"); 239 listenerCalled[0] = false; 240 oObj.removeFrameActionListener(listener); 241 oObj.activate(); 242 oObj.deactivate(); 243 oObj.activate(); 244 if (tEnv.getTestCase().getObjectName().equals("Desktop")) { 245 log.println("No actions supported by Desktop"); 246 tRes.tested("removeFrameActionListener()", true) ; 247 return; 248 } 249 250 if (listenerCalled[0]) 251 log.println("Listener wasn't removed, and was called"); 252 boolean res = isDesktop(log, tEnv, "removeFrameActionListener()"); 253 if (res) result=res; else result = (!listenerCalled[0]); 254 255 tRes.tested("removeFrameActionListener()", result); 256 } 257 258 /** 259 * Test calls the method. <p> 260 * Has <b> OK </b> status if isDesktop() method returns true or if the method 261 * does not return null. 262 */ _getCreator()263 public void _getCreator() { 264 boolean result = true; 265 266 if (tEnv.getTestCase().getObjectName().equals("Desktop")) { 267 log.println("Desktop has no creator"); 268 tRes.tested("getCreator()", true) ; 269 return; 270 } 271 272 XFramesSupplier creator = oObj.getCreator() ; 273 if (creator == null) 274 log.println("getCreator() returns null") ; 275 boolean res = isDesktop(log,tEnv,"getCreator()"); 276 if (res) result=res; else result = (creator != null); 277 tRes.tested("getCreator()", result) ; 278 } 279 280 /** 281 * Test calls the method. <p> 282 * Has <b> OK </b> status if isDesktop() method returns true or if the method 283 * does not return null. 284 */ _getComponentWindow()285 public void _getComponentWindow() { 286 boolean result = true; 287 288 XWindow win = oObj.getComponentWindow() ; 289 290 if (tEnv.getTestCase().getObjectName().equals("Desktop")) { 291 log.println("Desktop has no component window"); 292 tRes.tested("getComponentWindow()", true) ; 293 return; 294 } 295 296 if (win == null) 297 log.println("getComponentWindow() returns null") ; 298 boolean res = isDesktop(log,tEnv,"getComponentWindow()"); 299 if (res) result=res; else result = (win != null); 300 tRes.tested("getComponentWindow()", result) ; 301 } 302 303 /** 304 * Test calls the method. <p> 305 * Has <b> OK </b> status if isDesktop() method returns true or if the method 306 * does not return null. 307 */ _getContainerWindow()308 public void _getContainerWindow() { 309 boolean result = true; 310 311 if (tEnv.getTestCase().getObjectName().equals("Desktop")) { 312 log.println("Desktop has no container window"); 313 tRes.tested("getContainerWindow()", true) ; 314 return; 315 } 316 317 XWindow win = oObj.getContainerWindow() ; 318 if (win == null) 319 log.println("getContainerWindow() returns null") ; 320 boolean res = isDesktop(log,tEnv,"getContainerWindow()"); 321 if (res) result=res; else result = (win != null); 322 tRes.tested("getContainerWindow()", result) ; 323 } 324 325 /** 326 * Test calls the method. Then returned controller is checked. <p> 327 * Has <b> OK </b> status if isDesktop() method returns true or 328 * if the method returns non-null controller, having frame that's equal to 329 * a (XFrame) oObj. 330 */ _getController()331 public void _getController() { 332 boolean result = true; 333 XController ctrl = oObj.getController(); 334 335 if (tEnv.getTestCase().getObjectName().equals("Desktop")) { 336 log.println("Desktop has no controller"); 337 tRes.tested("getController()", true) ; 338 return; 339 } 340 341 if (ctrl == null) { 342 log.println("getController() returns null"); 343 result = false; 344 } else { 345 XFrame frm = ctrl.getFrame(); 346 if (!oObj.equals(frm)) { 347 log.println("Frame returned by controller not " + 348 "equals to frame testing"); 349 result = false; 350 } 351 } 352 boolean res = isDesktop(log, tEnv, "getController()"); 353 if (res) result=res; 354 tRes.tested("getController()", result) ; 355 } 356 357 /** 358 * Test calls the method. <p> 359 * Has <b> OK </b> status if the method successfully returns 360 * and no exceptions were thrown. 361 */ _isTop()362 public void _isTop() { 363 log.println("isTop() = " + oObj.isTop()); 364 tRes.tested("isTop()", true) ; 365 } 366 367 /** 368 * After obtaining an object relation 'XFrame', test tries to find a frame 369 * named 'XFrame'. <p> 370 * Has <b> OK </b> status if the method returns non-null object that's equal 371 * to previously obtained object relation. 372 */ _findFrame()373 public void _findFrame() { 374 boolean result = true ; 375 376 XFrame aFrame = (XFrame) tEnv.getObjRelation("XFrame"); 377 378 if (aFrame != null) { 379 log.println("Trying to find a frame with name 'XFrame' ..."); 380 XFrame frame = oObj.findFrame("XFrame", 381 com.sun.star.frame.FrameSearchFlag.GLOBAL) ; 382 if (frame == null) { 383 log.println("findFrame(\"XFrame,com.sun.star.frame.FrameSearchFlag.GLOBAL\") returns null") ; 384 result = false ; 385 } else if ( !aFrame.equals(frame) ) { 386 log.println("findFrame(\"XFrame,com.sun.star.frame.FrameSearchFlag.GLOBAL\") " 387 + " returns frame which is not equal to passed in relation") ; 388 result = false ; 389 } 390 } 391 392 log.println("Trying to find a frame with name '_self' ..."); 393 XFrame frame = oObj.findFrame("_self", 394 com.sun.star.frame.FrameSearchFlag.AUTO) ; 395 if (frame == null) { 396 log.println("findFrame(\"_self\") returns null") ; 397 result = false ; 398 } else if ( !oObj.equals(frame) ) { 399 log.println("findFrame(\"_self\") " 400 + " returns frame which is not equal to tested") ; 401 result = false ; 402 } 403 404 tRes.tested("findFrame()", result) ; 405 } 406 407 /** 408 * At first new listener is added, then test calls the method and result 409 * is checked. <p> 410 * Has <b> OK </b> status if isDesktop() method returnes true or if the 411 * listener was called and proper event past to listener. 412 */ _contextChanged()413 public void _contextChanged() { 414 boolean result = true; 415 TestFrameActionListener listener = new TestFrameActionListener(); 416 417 if (tEnv.getTestCase().getObjectName().equals("Desktop")) { 418 log.println("Desktop cann't change context"); 419 tRes.tested("contextChanged()", true) ; 420 return; 421 } 422 423 listenerCalled[0] = false; 424 oObj.addFrameActionListener(listener); 425 try { 426 oObj.contextChanged(); 427 if ( !listenerCalled[0] ) { 428 log.println("listener was not called on contextChanged() call.") ; 429 result = false; 430 } else if (actionEvent[0] != FrameAction.CONTEXT_CHANGED) { 431 log.println("listener was called, but Action != CONTEXT_CHANGED") ; 432 result = false; 433 } 434 } finally { 435 oObj.removeFrameActionListener(listener); 436 } 437 438 boolean res = isDesktop(log, tEnv, "contextChanged()"); 439 if (res) result = res; 440 tRes.tested("contextChanged()", result); 441 } 442 443 444 /** 445 * Test calls the method. Remembered old creater is restored at the end. <p> 446 * Has <b> OK </b> status if the method successfully set new value to (XFrame) 447 * oObj object. 448 */ _setCreator()449 public void _setCreator() { 450 if (tEnv.getTestCase().getObjectName().equals("Desktop")) { 451 log.println("Desktop has no creator"); 452 tRes.tested("setCreator()", true) ; 453 return; 454 } 455 456 XFramesSupplier oldCreator = oObj.getCreator() ; 457 oObj.setCreator(null) ; 458 tRes.tested("setCreator()", oObj.getCreator() == null) ; 459 oObj.setCreator(oldCreator) ; 460 } 461 462 /** 463 * Test calls the method, then result is checked.<p> 464 * Has <b> OK </b> status if method returns true, and values, set by the 465 * method are nulls, or if method returns false, and values are not changed. 466 * This method destroy the object. Therfore all other methods have to be 467 * executed before : 468 * <ul> 469 * <li> <code> getName() </code> 470 * <li> <code> setName() </code> 471 * <li> <code> activate() </code> 472 * <li> <code> deactivate() </code> 473 * <li> <code> isActive() </code> 474 * <li> <code> addFrameActionListener() </code> 475 * <li> <code> getComponentWindow() </code> 476 * <li> <code> getContainerWindow() </code> 477 * <li> <code> getController() </code> 478 * <li> <code> isTop() </code> 479 * <li> <code> findFrame() </code> 480 * <li> <code> contextChanged() </code> 481 * <li> <code> setCreator() </code> 482 * object</li> 483 * </ul> 484 */ _setComponent()485 public void _setComponent() { 486 // setComponent() destr 487 requiredMethod("getName()") ; 488 requiredMethod("setName()") ; 489 requiredMethod("activate()") ; 490 requiredMethod("deactivate()") ; 491 requiredMethod("isActive()") ; 492 requiredMethod("addFrameActionListener()") ; 493 requiredMethod("getComponentWindow()") ; 494 requiredMethod("getContainerWindow()") ; 495 requiredMethod("getController()") ; 496 requiredMethod("isTop()") ; 497 requiredMethod("findFrame()") ; 498 requiredMethod("contextChanged()") ; 499 requiredMethod("setCreator()") ; 500 501 boolean result = true; 502 503 XWindow oldWindow = oObj.getComponentWindow(); 504 XController oldController = oObj.getController(); 505 boolean rs = oObj.setComponent(null, null); 506 if (rs) { // component must be changed 507 result &= oObj.getComponentWindow() == null; 508 result &= oObj.getController() == null; 509 if (!result) 510 log.println("setComponent() returns true, but component is " + 511 "not changed."); 512 } else { // frame is not allowed to change component 513 result &= oObj.getComponentWindow() == oldWindow ; 514 result &= oObj.getController() == oldController ; 515 if (!result) 516 log.println("setComponent() returns false, but component is" + 517 "changed."); 518 } 519 tRes.tested("setComponent()", result); 520 521 } 522 523 /** 524 * Test calls the method. <p> 525 * Has <b> OK </b> status if the method successfully returns. 526 * In case a frame should initialised twice, a 527 * <CODE>com.sun.star.uno.RuntimeException</CODE> was thron. This is ok. But since 528 * a com.sun.star.uno.RuntimeException could thrown in any state the message of 529 * the exception must contain a defined string. In this case the test get an 530 * <CODE>OK</CODE> status. 531 * The following method tests are to be completed successfully before : 532 * <ul> 533 * <li> <code> setComponent() </code> : sets window and controller to the 534 * object</li> 535 * </ul> 536 */ _initialize()537 public void _initialize() { 538 requiredMethod("setComponent()") ; 539 XWindow win = oObj.getContainerWindow() ; 540 boolean bOK = true; 541 try { 542 oObj.initialize(win) ; 543 } catch (com.sun.star.uno.RuntimeException e){ 544 String message="Frame::initialized() is called more then once, which isn't useful nor allowed."; 545 if (e.toString().indexOf(message) != -1){ 546 log.println(e.toString()); 547 log.println("methods throws exception, but it's OK"); 548 }else{ 549 log.println(e.toString()); 550 bOK=false; 551 } 552 553 } 554 tRes.tested("initialize()", bOK) ; 555 } 556 557 /** 558 * Checks does relation 'Desktop' exist. Returns true if exist. 559 */ isDesktop(PrintWriter log, TestEnvironment env, String method)560 public static boolean isDesktop(PrintWriter log, 561 TestEnvironment env, String method) { 562 Object isD = env.getObjRelation("Desktop"); 563 if (isD != null) { 564 log.println("The Desktop doesn't support the method " + method); 565 log.println("It will always return true"); 566 return true; 567 } 568 else { 569 return false; 570 } 571 } 572 573 /** 574 * Forces environment recreation. 575 */ after()576 public void after() { 577 disposeEnvironment(); 578 } 579 } 580