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