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="form_XUpdateBroadcaster" 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 bCustomUpdate As Boolean
39'       properties are not changed to call listener
40'       Sub UpdateComponent()
41
42'*************************************************************************
43
44
45
46
47Const BOUND = 2
48Const CONSTRAINED = 4
49Const MAYBENULL = 8
50Const READONLY = 16
51
52Dim oListener1 As Object
53Dim oListener2 As Object
54Dim nCB1appVal As Boolean
55Dim nCB2appVal As Boolean
56Dim nCB1updVal As Boolean
57Dim nCB2updVal As Boolean
58
59
60Sub RunTest()
61
62'*************************************************************************
63' INTERFACE:
64' com.sun.star.form.XUpdateBroadcaster
65'*************************************************************************
66On Error Goto ErrHndl
67    Dim bOK As Boolean
68    Dim bAllOK As Boolean
69
70    Out.Log("Creating Listeners...")
71    oListener1 = createUNOListener("CB1_","com.sun.star.form.XUpdateListener")
72    oListener2 = createUNOListener("CB2_","com.sun.star.form.XUpdateListener")
73    bOK = NOT isNULL(oListener1) AND NOT isNULL(oListener2)
74
75    CountersReset()
76
77    bAllOK = bOK
78
79    Test.StartMethod("addUpdateListener()")
80    bOK = true
81    oObj.addUpdateListener(oListener1)
82    oObj.addUpdateListener(oListener2)
83
84    if bCustomUpdate then
85		Out.Log("Object specific update function was called.")
86        UpdateComponent()
87    else
88		Out.Log("Interfacetest update function was called.")
89        TryToUpdate()
90    end if
91	wait(1000)
92
93    bOK = bOK AND nCB1appVal AND nCB2appVal AND nCB1updVal AND nCB2updVal
94
95    Test.MethodTested("addUpdateListener()", bOK)
96
97    Test.StartMethod("removeUpdateListener()")
98    bOK = true
99    Out.Log("Removing Listener 1")
100    oObj.removeUpdateListener(oListener1)
101    countersReset()
102
103    if bCustomUpdate then
104		Out.Log("Object specific update function was called.")
105        UpdateComponent()
106    else
107		Out.Log("Interfacetest update function was called.")
108        TryToUpdate()
109    end if
110	wait(1000)
111
112    bOK = bOK AND NOT nCB1appVal AND nCB2appVal AND NOT nCB1updVal AND nCB2updVal
113    Test.MethodTested("removeUpdateListener()", bOK)
114
115    Out.Log("Removing Listener 2")
116    oObj.removeUpdateListener(oListener2)
117
118Exit Sub
119ErrHndl:
120    Test.Exception()
121    bOK = false
122    resume next
123End Sub
124Function CB1_approveUpdate As Boolean
125    Out.Log("CallBack for Listener1 approveUpdate was called.")
126    nCB1appVal = TRUE
127    CB1_approveUpdate = TRUE
128End Function
129
130Function CB2_approveUpdate As Boolean
131    Out.Log("CallBack for Listener2 approveUpdate was called.")
132    nCB2appVal = TRUE
133    CB2_approveUpdate = TRUE
134End Function
135
136Sub CB1_Updated
137    Out.Log("CallBack for Listener1 Updated was called.")
138    nCB1updVal = TRUE
139End Sub
140
141Sub CB2_Updated
142    Out.Log("CallBack for Listener2 Updated was called.")
143    nCB2updVal = TRUE
144End Sub
145
146Sub TryToUpdate()
147    Dim i as Integer
148    Dim props as Variant, attr As Variant
149
150    if hasUnoInterfaces(oObj, "com.sun.star.beans.XPropertySet") then
151        props() = oObj.getPropertySetInfo().getProperties()
152
153        for i = lbound(props()) to ubound(props())
154            PropertyTester.TestProperty(props(i).Name)
155        next i
156    else
157        Out.Log("XPropertySet isn't supported.")
158    end if
159End Sub
160
161Sub countersReset()
162    nCB1updVal = FALSE
163    nCB2updVal = FALSE
164    nCB1appVal = FALSE
165    nCB2appVal = FALSE
166End sub
167</script:module>
168