1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?> 2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="frame_XFrame" script:language="StarBasic"> 4cdf0e10cSrcweir 5cdf0e10cSrcweir 6cdf0e10cSrcweir'************************************************************************* 7cdf0e10cSrcweir' 8*eebed415SAndrew Rist' Licensed to the Apache Software Foundation (ASF) under one 9*eebed415SAndrew Rist' or more contributor license agreements. See the NOTICE file 10*eebed415SAndrew Rist' distributed with this work for additional information 11*eebed415SAndrew Rist' regarding copyright ownership. The ASF licenses this file 12*eebed415SAndrew Rist' to you under the Apache License, Version 2.0 (the 13*eebed415SAndrew Rist' "License"); you may not use this file except in compliance 14*eebed415SAndrew Rist' with the License. You may obtain a copy of the License at 15*eebed415SAndrew Rist' 16*eebed415SAndrew Rist' http://www.apache.org/licenses/LICENSE-2.0 17*eebed415SAndrew Rist' 18*eebed415SAndrew Rist' Unless required by applicable law or agreed to in writing, 19*eebed415SAndrew Rist' software distributed under the License is distributed on an 20*eebed415SAndrew Rist' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21*eebed415SAndrew Rist' KIND, either express or implied. See the License for the 22*eebed415SAndrew Rist' specific language governing permissions and limitations 23*eebed415SAndrew Rist' under the License. 24cdf0e10cSrcweir' 25cdf0e10cSrcweir'************************************************************************* 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir 29*eebed415SAndrew Rist 30*eebed415SAndrew Rist 31cdf0e10cSrcweir' Be sure that all variables are dimensioned: 32cdf0e10cSrcweiroption explicit 33cdf0e10cSrcweir 34cdf0e10cSrcweir'************************************************************************* 35cdf0e10cSrcweir' This Interface/Service test depends on the following GLOBAL variables, 36cdf0e10cSrcweir' which must be specified in the object creation: 37cdf0e10cSrcweir 38cdf0e10cSrcweir' - Global XFrame As Object optional 39cdf0e10cSrcweir 40cdf0e10cSrcweir'************************************************************************* 41cdf0e10cSrcweir 42cdf0e10cSrcweir 43cdf0e10cSrcweir 44cdf0e10cSrcweir 45cdf0e10cSrcweir 46cdf0e10cSrcweir 47cdf0e10cSrcweirSub RunTest() 48cdf0e10cSrcweir 49cdf0e10cSrcweir'************************************************************************* 50cdf0e10cSrcweir' INTERFACE: 51cdf0e10cSrcweir' com.sun.star.frame.XFrame 52cdf0e10cSrcweir'************************************************************************* 53cdf0e10cSrcweirOn Error Goto ErrHndl 54cdf0e10cSrcweir Dim bOK As Boolean 55cdf0e10cSrcweir 56cdf0e10cSrcweir Test.StartMethod("getName()") 57cdf0e10cSrcweir bOK = true 58cdf0e10cSrcweir Dim oldName As String 59cdf0e10cSrcweir oldName = oObj.getName() 60cdf0e10cSrcweir Out.log("getName(): " + oldName) 61cdf0e10cSrcweir bOK = Not isNull(oldName) 62cdf0e10cSrcweir Test.MethodTested("getName()", bOK) 63cdf0e10cSrcweir 64cdf0e10cSrcweir Test.StartMethod("setName()") 65cdf0e10cSrcweir bOK = true 66cdf0e10cSrcweir Dim sName As String, gName As String 67cdf0e10cSrcweir sName = "XFrame" 68cdf0e10cSrcweir oObj.setName(sName) 69cdf0e10cSrcweir gName = oObj.getName() 70cdf0e10cSrcweir bOK = gName = sName 71cdf0e10cSrcweir Out.log("setName('" + sName + "'), getName() return '" + gName + "'") 72cdf0e10cSrcweir oObj.setName(oldName) 73cdf0e10cSrcweir Test.MethodTested("setName()", bOK) 74cdf0e10cSrcweir 75cdf0e10cSrcweir Test.StartMethod("activate()") 76cdf0e10cSrcweir bOK = true 77cdf0e10cSrcweir oObj.activate() 78cdf0e10cSrcweir Test.MethodTested("activate()", bOK) 79cdf0e10cSrcweir 80cdf0e10cSrcweir Test.StartMethod("deactivate()") 81cdf0e10cSrcweir bOK = true 82cdf0e10cSrcweir oObj.deactivate() 83cdf0e10cSrcweir Test.MethodTested("deactivate()", bOK) 84cdf0e10cSrcweir 85cdf0e10cSrcweir Test.StartMethod("isActive()") 86cdf0e10cSrcweir bOK = true 87cdf0e10cSrcweir if (instr(cObjectName,"Desktop") > -1) then 88cdf0e10cSrcweir Out.log("Desktop is always active") 89cdf0e10cSrcweir bOK = oObj.isActive() 90cdf0e10cSrcweir else 91cdf0e10cSrcweir oObj.activate() 92cdf0e10cSrcweir bOK = oObj.isActive() 93cdf0e10cSrcweir if (Not bOK) then 94cdf0e10cSrcweir Out.log("after activate() method call, isActive() returned false") 95cdf0e10cSrcweir end if 96cdf0e10cSrcweir oObj.deactivate() 97cdf0e10cSrcweir bOK = Not oObj.isActive() 98cdf0e10cSrcweir if (oObj.isActive()) then 99cdf0e10cSrcweir Out.log("after deactivate() method call, isActive() returned true") 100cdf0e10cSrcweir end if 101cdf0e10cSrcweir end if 102cdf0e10cSrcweir Test.MethodTested("isActive()", bOK) 103cdf0e10cSrcweir 104cdf0e10cSrcweir Test.StartMethod("getCreator()") 105cdf0e10cSrcweir bOK = true 106cdf0e10cSrcweir Dim creator As Object 107cdf0e10cSrcweir creator = oObj.getCreator() 108cdf0e10cSrcweir if (instr(cObjectName,"Desktop") > -1) then 109cdf0e10cSrcweir Out.log("Desktop has no creator") 110cdf0e10cSrcweir else 111cdf0e10cSrcweir bOK = Not isNull(creator) 112cdf0e10cSrcweir end if 113cdf0e10cSrcweir Test.MethodTested("getCreator()", bOK) 114cdf0e10cSrcweir 115cdf0e10cSrcweir Test.StartMethod("getComponentWindow()") 116cdf0e10cSrcweir bOK = true 117cdf0e10cSrcweir Dim compWin As Object 118cdf0e10cSrcweir compWin = oObj.getComponentWindow() 119cdf0e10cSrcweir if (instr(cObjectName,"Desktop") > -1) then 120cdf0e10cSrcweir Out.log("Desktop has no component window") 121cdf0e10cSrcweir else 122cdf0e10cSrcweir bOK = Not isNull(compWin) 123cdf0e10cSrcweir end if 124cdf0e10cSrcweir Test.MethodTested("getComponentWindow()", bOK) 125cdf0e10cSrcweir 126cdf0e10cSrcweir Test.StartMethod("getContainerWindow()") 127cdf0e10cSrcweir bOK = true 128cdf0e10cSrcweir Dim contWin As Object 129cdf0e10cSrcweir contWin = oObj.getContainerWindow() 130cdf0e10cSrcweir if (instr(cObjectName,"Desktop") > -1) then 131cdf0e10cSrcweir Out.log("Desktop has no container window") 132cdf0e10cSrcweir else 133cdf0e10cSrcweir bOK = Not isNull(contWin) 134cdf0e10cSrcweir end if 135cdf0e10cSrcweir Test.MethodTested("getContainerWindow()", bOK) 136cdf0e10cSrcweir 137cdf0e10cSrcweir Test.StartMethod("getController()") 138cdf0e10cSrcweir bOK = true 139cdf0e10cSrcweir Dim controller As Object 140cdf0e10cSrcweir controller = oObj.getController() 141cdf0e10cSrcweir if (instr(cObjectName,"Desktop") > -1) then 142cdf0e10cSrcweir Out.log("Desktop has no controller") 143cdf0e10cSrcweir else 144cdf0e10cSrcweir if (isNull(controller)) then 145cdf0e10cSrcweir Out.log("getController() returns null") 146cdf0e10cSrcweir bOK = false 147cdf0e10cSrcweir else 148cdf0e10cSrcweir Dim frm As Object 149cdf0e10cSrcweir frm = controller.getFrame() 150cdf0e10cSrcweir if (frm.getName() <> oObj.getName()) then 151cdf0e10cSrcweir Out.log("Frame returned by controller not " + _ 152cdf0e10cSrcweir "equals to frame testing") 153cdf0e10cSrcweir bOK = false 154cdf0e10cSrcweir end if 155cdf0e10cSrcweir end if 156cdf0e10cSrcweir end if 157cdf0e10cSrcweir Test.MethodTested("getController()", bOK) 158cdf0e10cSrcweir 159cdf0e10cSrcweir Test.StartMethod("isTop()") 160cdf0e10cSrcweir bOK = true 161cdf0e10cSrcweir Out.log("isTop() = " + oObj.isTop()) 162cdf0e10cSrcweir Test.MethodTested("isTop()", bOK) 163cdf0e10cSrcweir 164cdf0e10cSrcweir Test.StartMethod("findFrame()") 165cdf0e10cSrcweir bOK = true 166cdf0e10cSrcweir if (Not isNull(XFrame)) then 167cdf0e10cSrcweir Out.log("Trying to find a frame with name 'XFrame' ...") 168cdf0e10cSrcweir Dim aFrame As Object 169cdf0e10cSrcweir aFrame = oObj.findFrame("XFrame", com.sun.star.frame.FrameSearchFlag.GLOBAL) 170cdf0e10cSrcweir if (isNull(aFrame)) then 171cdf0e10cSrcweir Out.log("findFrame('XFrame',com.sun.star.frame.FrameSearchFlag.GLOBAL) returns null") 172cdf0e10cSrcweir bOK = false 173cdf0e10cSrcweir elseif (XFrame.getName() <> aFrame.getName()) then 174cdf0e10cSrcweir Out.log("findFrame('XFrame',com.sun.star.frame.FrameSearchFlag.GLOBAL)" _ 175cdf0e10cSrcweir + " returns frame which is not equal to passed in relation") 176cdf0e10cSrcweir bOK = false 177cdf0e10cSrcweir end if 178cdf0e10cSrcweir end if 179cdf0e10cSrcweir Out.log("Trying to find a frame with name '_self' ...") 180cdf0e10cSrcweir Dim frame As Object 181cdf0e10cSrcweir frame = oObj.findFrame("_self", com.sun.star.frame.FrameSearchFlag.AUTO) 182cdf0e10cSrcweir if (isNull(frame)) then 183cdf0e10cSrcweir Out.log("findFrame('_self') returns null") 184cdf0e10cSrcweir bOK = false 185cdf0e10cSrcweir elseif (frame.getName() <> oObj.getName()) then 186cdf0e10cSrcweir Out.log("findFrame('_self') returns frame which is not equal to tested") 187cdf0e10cSrcweir bOK = false 188cdf0e10cSrcweir end if 189cdf0e10cSrcweir Test.MethodTested("findFrame()", bOK) 190cdf0e10cSrcweir 191cdf0e10cSrcweir Test.StartMethod("setCreator()") 192cdf0e10cSrcweir bOK = true 193cdf0e10cSrcweir oObj.setCreator(NULL_OBJECT) 194cdf0e10cSrcweir if (instr(cObjectName,"Desktop") > -1) then 195cdf0e10cSrcweir Out.log("Desktop has no creator") 196cdf0e10cSrcweir else 197cdf0e10cSrcweir bOK = isNull(oObj.getCreator()) 198cdf0e10cSrcweir oObj.setCreator(creator) 199cdf0e10cSrcweir end if 200cdf0e10cSrcweir Test.MethodTested("setCreator()", bOK) 201cdf0e10cSrcweir 202cdf0e10cSrcweir Test.StartMethod("setComponent()") 203cdf0e10cSrcweir bOK = true 204cdf0e10cSrcweir Dim res As Boolean 205cdf0e10cSrcweir res = oObj.setComponent(NULL_OBJECT, NULL_OBJECT) 206cdf0e10cSrcweir if (res) then 207cdf0e10cSrcweir ' component must be changed 208cdf0e10cSrcweir bOK = isNull(oObj.getComponentWindow()) 209cdf0e10cSrcweir bOK = bOK and isNull(oObj.getController()) 210cdf0e10cSrcweir if (Not bOK) then 211cdf0e10cSrcweir Out.log("setComponent() returns true, but component is not changed.") 212cdf0e10cSrcweir end if 213cdf0e10cSrcweir else 214cdf0e10cSrcweir Out.log("frame is not allowed to change component") 215cdf0e10cSrcweir end if 216cdf0e10cSrcweir oObj.setComponent(compWin, controller) 217cdf0e10cSrcweir Test.MethodTested("setComponent()", bOK) 218cdf0e10cSrcweir 219cdf0e10cSrcweir Test.StartMethod("initialize()") 220cdf0e10cSrcweir bOK = true 221cdf0e10cSrcweir oObj.initialize(contWin) 222cdf0e10cSrcweir Test.MethodTested("initialize()", bOK) 223cdf0e10cSrcweir 224cdf0e10cSrcweir Test.StartMethod("addFrameActionListener()") 225cdf0e10cSrcweir bOK = true 226cdf0e10cSrcweir Dim listener1 As Object, listener2 As Object 227cdf0e10cSrcweir listener1 = createUnoListener("FA1_", "com.sun.star.frame.XFrameActionListener") 228cdf0e10cSrcweir listener2 = createUnoListener("FA2_", "com.sun.star.frame.XFrameActionListener") 229cdf0e10cSrcweir initListeners() 230cdf0e10cSrcweir oObj.activate() 231cdf0e10cSrcweir oObj.deactivate() 232cdf0e10cSrcweir oObj.activate() 233cdf0e10cSrcweir if (instr(cObjectName,"Desktop") > -1) then 234cdf0e10cSrcweir Out.log("No actions supported by Desktop") 235cdf0e10cSrcweir else 236cdf0e10cSrcweir wait(1000) 237cdf0e10cSrcweir if (Not listener1Called) then 238cdf0e10cSrcweir bOK = false 239cdf0e10cSrcweir Out.log("Listener1 wasn't called") 240cdf0e10cSrcweir end if 241cdf0e10cSrcweir if (Not listener2Called) then 242cdf0e10cSrcweir bOK = false 243cdf0e10cSrcweir Out.log("Listener2 wasn't called") 244cdf0e10cSrcweir end if 245cdf0e10cSrcweir if (Not activatedCalled1 or Not activatedCalled2) then 246cdf0e10cSrcweir bOK = false 247cdf0e10cSrcweir Out.log("Listener was called, FRAME_ACTIVATED was not") 248cdf0e10cSrcweir endif 249cdf0e10cSrcweir if (Not deactivatedCalled1 or Not deactivatedCalled2) then 250cdf0e10cSrcweir bOK = false 251cdf0e10cSrcweir Out.log("Listener was called, FRAME_DEACTIVATED was not") 252cdf0e10cSrcweir endif 253cdf0e10cSrcweir end if 254cdf0e10cSrcweir Test.MethodTested("addFrameActionListener()", bOK) 255cdf0e10cSrcweir 256cdf0e10cSrcweir Test.StartMethod("removeFrameActionListener()") 257cdf0e10cSrcweir bOK = true 258cdf0e10cSrcweir Out.log("removes listener2") 259cdf0e10cSrcweir oObj.removeFrameActionListener(listener2) 260cdf0e10cSrcweir initListeners() 261cdf0e10cSrcweir oObj.activate() 262cdf0e10cSrcweir oObj.deactivate() 263cdf0e10cSrcweir oObj.activate() 264cdf0e10cSrcweir if (instr(cObjectName,"Desktop") > -1) then 265cdf0e10cSrcweir Out.log("No actions supported by Desktop") 266cdf0e10cSrcweir else 267cdf0e10cSrcweir wait(1000) 268cdf0e10cSrcweir if (Not listener1Called) then 269cdf0e10cSrcweir bOK = false 270cdf0e10cSrcweir Out.log("Listener1 wasn't called") 271cdf0e10cSrcweir end if 272cdf0e10cSrcweir if (listener2Called) then 273cdf0e10cSrcweir bOK = false 274cdf0e10cSrcweir Out.log("Listener2 was called, but it was removed") 275cdf0e10cSrcweir end if 276cdf0e10cSrcweir end if 277cdf0e10cSrcweir Test.MethodTested("removeFrameActionListener()", bOK) 278cdf0e10cSrcweir 279cdf0e10cSrcweir Test.StartMethod("contextChanged()") 280cdf0e10cSrcweir bOK = true 281cdf0e10cSrcweir oObj.addFrameActionListener(listener1) 282cdf0e10cSrcweir initListeners() 283cdf0e10cSrcweir oObj.contextChanged() 284cdf0e10cSrcweir if (instr(cObjectName,"Desktop") > -1) then 285cdf0e10cSrcweir Out.log("Desktop cann't change context") 286cdf0e10cSrcweir elseif(contextChanged1) then 287cdf0e10cSrcweir bOK = true 288cdf0e10cSrcweir elseif(listener1Called) then 289cdf0e10cSrcweir bOK = false 290cdf0e10cSrcweir Out.log("listener was called, but Action != CONTEXT_CHANGED") 291cdf0e10cSrcweir else 292cdf0e10cSrcweir bOK = false 293cdf0e10cSrcweir Out.log("listener was not called on contextChanged() call") 294cdf0e10cSrcweir end if 295cdf0e10cSrcweir Test.MethodTested("contextChanged()", bOK) 296cdf0e10cSrcweirExit Sub 297cdf0e10cSrcweirErrHndl: 298cdf0e10cSrcweir Test.Exception() 299cdf0e10cSrcweir bOK = false 300cdf0e10cSrcweir resume next 301cdf0e10cSrcweirEnd Sub 302cdf0e10cSrcweir 303cdf0e10cSrcweirDim listener1Called As Boolean 304cdf0e10cSrcweirDim listener2Called As Boolean 305cdf0e10cSrcweirDim activatedCalled1 As Boolean 306cdf0e10cSrcweirDim deactivatedCalled1 As Boolean 307cdf0e10cSrcweirDim contextChanged1 As Boolean 308cdf0e10cSrcweirDim activatedCalled2 As Boolean 309cdf0e10cSrcweirDim deactivatedCalled2 As Boolean 310cdf0e10cSrcweir 311cdf0e10cSrcweirSub initListeners() 312cdf0e10cSrcweir listener1Called = false 313cdf0e10cSrcweir listener2Called = false 314cdf0e10cSrcweir contextChanged1 = false 315cdf0e10cSrcweir activatedCalled1 = false 316cdf0e10cSrcweir deactivatedCalled1 = false 317cdf0e10cSrcweir activatedCalled2 = false 318cdf0e10cSrcweir deactivatedCalled2 = false 319cdf0e10cSrcweirEnd Sub 320cdf0e10cSrcweir 321cdf0e10cSrcweirSub FA1_frameAction(event As Object) 322cdf0e10cSrcweir listener1Called = true 323cdf0e10cSrcweir Out.Log("Listener1: frameAction: " + event.Action) 324cdf0e10cSrcweir if (event.Action = com.sun.star.frame.FrameAction.FRAME_ACTIVATED) then 325cdf0e10cSrcweir activatedCalled1 = true 326cdf0e10cSrcweir elseif (event.Action = com.sun.star.frame.FrameAction.FRAME_DEACTIVATING) then 327cdf0e10cSrcweir deactivatedCalled1 = true 328cdf0e10cSrcweir elseif (event.Action = com.sun.star.frame.FrameAction.CONTEXT_CHANGED) then 329cdf0e10cSrcweir contextChanged1 = true 330cdf0e10cSrcweir endif 331cdf0e10cSrcweirEnd Sub 332cdf0e10cSrcweir 333cdf0e10cSrcweirSub FA2_frameAction(event As Object) 334cdf0e10cSrcweir listener2Called = true 335cdf0e10cSrcweir Out.Log("Listener2: frameAction: " + event.Action) 336cdf0e10cSrcweir if (event.Action = com.sun.star.frame.FrameAction.FRAME_ACTIVATED) then 337cdf0e10cSrcweir activatedCalled2 = true 338cdf0e10cSrcweir elseif (event.Action = com.sun.star.frame.FrameAction.FRAME_DEACTIVATING) then 339cdf0e10cSrcweir deactivatedCalled2 = true 340cdf0e10cSrcweir endif 341cdf0e10cSrcweirEnd Sub 342cdf0e10cSrcweir</script:module> 343