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