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