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