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="form_XUpdateBroadcaster" script:language="StarBasic">
4cdf0e10cSrcweir
5cdf0e10cSrcweir
6cdf0e10cSrcweir'*************************************************************************
7cdf0e10cSrcweir'
8*3709053cSAndrew Rist'  Licensed to the Apache Software Foundation (ASF) under one
9*3709053cSAndrew Rist'  or more contributor license agreements.  See the NOTICE file
10*3709053cSAndrew Rist'  distributed with this work for additional information
11*3709053cSAndrew Rist'  regarding copyright ownership.  The ASF licenses this file
12*3709053cSAndrew Rist'  to you under the Apache License, Version 2.0 (the
13*3709053cSAndrew Rist'  "License"); you may not use this file except in compliance
14*3709053cSAndrew Rist'  with the License.  You may obtain a copy of the License at
15*3709053cSAndrew Rist'
16*3709053cSAndrew Rist'    http://www.apache.org/licenses/LICENSE-2.0
17*3709053cSAndrew Rist'
18*3709053cSAndrew Rist'  Unless required by applicable law or agreed to in writing,
19*3709053cSAndrew Rist'  software distributed under the License is distributed on an
20*3709053cSAndrew Rist'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21*3709053cSAndrew Rist'  KIND, either express or implied.  See the License for the
22*3709053cSAndrew Rist'  specific language governing permissions and limitations
23*3709053cSAndrew Rist'  under the License.
24cdf0e10cSrcweir'
25cdf0e10cSrcweir'*************************************************************************
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29*3709053cSAndrew Rist
30*3709053cSAndrew 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 bCustomUpdate As Boolean
39cdf0e10cSrcweir'       properties are not changed to call listener
40cdf0e10cSrcweir'       Sub UpdateComponent()
41cdf0e10cSrcweir
42cdf0e10cSrcweir'*************************************************************************
43cdf0e10cSrcweir
44cdf0e10cSrcweir
45cdf0e10cSrcweir
46cdf0e10cSrcweir
47cdf0e10cSrcweirConst BOUND = 2
48cdf0e10cSrcweirConst CONSTRAINED = 4
49cdf0e10cSrcweirConst MAYBENULL = 8
50cdf0e10cSrcweirConst READONLY = 16
51cdf0e10cSrcweir
52cdf0e10cSrcweirDim oListener1 As Object
53cdf0e10cSrcweirDim oListener2 As Object
54cdf0e10cSrcweirDim nCB1appVal As Boolean
55cdf0e10cSrcweirDim nCB2appVal As Boolean
56cdf0e10cSrcweirDim nCB1updVal As Boolean
57cdf0e10cSrcweirDim nCB2updVal As Boolean
58cdf0e10cSrcweir
59cdf0e10cSrcweir
60cdf0e10cSrcweirSub RunTest()
61cdf0e10cSrcweir
62cdf0e10cSrcweir'*************************************************************************
63cdf0e10cSrcweir' INTERFACE:
64cdf0e10cSrcweir' com.sun.star.form.XUpdateBroadcaster
65cdf0e10cSrcweir'*************************************************************************
66cdf0e10cSrcweirOn Error Goto ErrHndl
67cdf0e10cSrcweir    Dim bOK As Boolean
68cdf0e10cSrcweir    Dim bAllOK As Boolean
69cdf0e10cSrcweir
70cdf0e10cSrcweir    Out.Log("Creating Listeners...")
71cdf0e10cSrcweir    oListener1 = createUNOListener("CB1_","com.sun.star.form.XUpdateListener")
72cdf0e10cSrcweir    oListener2 = createUNOListener("CB2_","com.sun.star.form.XUpdateListener")
73cdf0e10cSrcweir    bOK = NOT isNULL(oListener1) AND NOT isNULL(oListener2)
74cdf0e10cSrcweir
75cdf0e10cSrcweir    CountersReset()
76cdf0e10cSrcweir
77cdf0e10cSrcweir    bAllOK = bOK
78cdf0e10cSrcweir
79cdf0e10cSrcweir    Test.StartMethod("addUpdateListener()")
80cdf0e10cSrcweir    bOK = true
81cdf0e10cSrcweir    oObj.addUpdateListener(oListener1)
82cdf0e10cSrcweir    oObj.addUpdateListener(oListener2)
83cdf0e10cSrcweir
84cdf0e10cSrcweir    if bCustomUpdate then
85cdf0e10cSrcweir		Out.Log("Object specific update function was called.")
86cdf0e10cSrcweir        UpdateComponent()
87cdf0e10cSrcweir    else
88cdf0e10cSrcweir		Out.Log("Interfacetest update function was called.")
89cdf0e10cSrcweir        TryToUpdate()
90cdf0e10cSrcweir    end if
91cdf0e10cSrcweir	wait(1000)
92cdf0e10cSrcweir
93cdf0e10cSrcweir    bOK = bOK AND nCB1appVal AND nCB2appVal AND nCB1updVal AND nCB2updVal
94cdf0e10cSrcweir
95cdf0e10cSrcweir    Test.MethodTested("addUpdateListener()", bOK)
96cdf0e10cSrcweir
97cdf0e10cSrcweir    Test.StartMethod("removeUpdateListener()")
98cdf0e10cSrcweir    bOK = true
99cdf0e10cSrcweir    Out.Log("Removing Listener 1")
100cdf0e10cSrcweir    oObj.removeUpdateListener(oListener1)
101cdf0e10cSrcweir    countersReset()
102cdf0e10cSrcweir
103cdf0e10cSrcweir    if bCustomUpdate then
104cdf0e10cSrcweir		Out.Log("Object specific update function was called.")
105cdf0e10cSrcweir        UpdateComponent()
106cdf0e10cSrcweir    else
107cdf0e10cSrcweir		Out.Log("Interfacetest update function was called.")
108cdf0e10cSrcweir        TryToUpdate()
109cdf0e10cSrcweir    end if
110cdf0e10cSrcweir	wait(1000)
111cdf0e10cSrcweir
112cdf0e10cSrcweir    bOK = bOK AND NOT nCB1appVal AND nCB2appVal AND NOT nCB1updVal AND nCB2updVal
113cdf0e10cSrcweir    Test.MethodTested("removeUpdateListener()", bOK)
114cdf0e10cSrcweir
115cdf0e10cSrcweir    Out.Log("Removing Listener 2")
116cdf0e10cSrcweir    oObj.removeUpdateListener(oListener2)
117cdf0e10cSrcweir
118cdf0e10cSrcweirExit Sub
119cdf0e10cSrcweirErrHndl:
120cdf0e10cSrcweir    Test.Exception()
121cdf0e10cSrcweir    bOK = false
122cdf0e10cSrcweir    resume next
123cdf0e10cSrcweirEnd Sub
124cdf0e10cSrcweirFunction CB1_approveUpdate As Boolean
125cdf0e10cSrcweir    Out.Log("CallBack for Listener1 approveUpdate was called.")
126cdf0e10cSrcweir    nCB1appVal = TRUE
127cdf0e10cSrcweir    CB1_approveUpdate = TRUE
128cdf0e10cSrcweirEnd Function
129cdf0e10cSrcweir
130cdf0e10cSrcweirFunction CB2_approveUpdate As Boolean
131cdf0e10cSrcweir    Out.Log("CallBack for Listener2 approveUpdate was called.")
132cdf0e10cSrcweir    nCB2appVal = TRUE
133cdf0e10cSrcweir    CB2_approveUpdate = TRUE
134cdf0e10cSrcweirEnd Function
135cdf0e10cSrcweir
136cdf0e10cSrcweirSub CB1_Updated
137cdf0e10cSrcweir    Out.Log("CallBack for Listener1 Updated was called.")
138cdf0e10cSrcweir    nCB1updVal = TRUE
139cdf0e10cSrcweirEnd Sub
140cdf0e10cSrcweir
141cdf0e10cSrcweirSub CB2_Updated
142cdf0e10cSrcweir    Out.Log("CallBack for Listener2 Updated was called.")
143cdf0e10cSrcweir    nCB2updVal = TRUE
144cdf0e10cSrcweirEnd Sub
145cdf0e10cSrcweir
146cdf0e10cSrcweirSub TryToUpdate()
147cdf0e10cSrcweir    Dim i as Integer
148cdf0e10cSrcweir    Dim props as Variant, attr As Variant
149cdf0e10cSrcweir
150cdf0e10cSrcweir    if hasUnoInterfaces(oObj, "com.sun.star.beans.XPropertySet") then
151cdf0e10cSrcweir        props() = oObj.getPropertySetInfo().getProperties()
152cdf0e10cSrcweir
153cdf0e10cSrcweir        for i = lbound(props()) to ubound(props())
154cdf0e10cSrcweir            PropertyTester.TestProperty(props(i).Name)
155cdf0e10cSrcweir        next i
156cdf0e10cSrcweir    else
157cdf0e10cSrcweir        Out.Log("XPropertySet isn't supported.")
158cdf0e10cSrcweir    end if
159cdf0e10cSrcweirEnd Sub
160cdf0e10cSrcweir
161cdf0e10cSrcweirSub countersReset()
162cdf0e10cSrcweir    nCB1updVal = FALSE
163cdf0e10cSrcweir    nCB2updVal = FALSE
164cdf0e10cSrcweir    nCB1appVal = FALSE
165cdf0e10cSrcweir    nCB2appVal = FALSE
166cdf0e10cSrcweirEnd sub
167cdf0e10cSrcweir</script:module>
168