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="beans_XPropertySet" script:language="StarBasic">
4cdf0e10cSrcweir
5cdf0e10cSrcweir
6cdf0e10cSrcweir'*************************************************************************
7cdf0e10cSrcweir'
8*f94e042dSAndrew Rist'  Licensed to the Apache Software Foundation (ASF) under one
9*f94e042dSAndrew Rist'  or more contributor license agreements.  See the NOTICE file
10*f94e042dSAndrew Rist'  distributed with this work for additional information
11*f94e042dSAndrew Rist'  regarding copyright ownership.  The ASF licenses this file
12*f94e042dSAndrew Rist'  to you under the Apache License, Version 2.0 (the
13*f94e042dSAndrew Rist'  "License"); you may not use this file except in compliance
14*f94e042dSAndrew Rist'  with the License.  You may obtain a copy of the License at
15*f94e042dSAndrew Rist'
16*f94e042dSAndrew Rist'    http://www.apache.org/licenses/LICENSE-2.0
17*f94e042dSAndrew Rist'
18*f94e042dSAndrew Rist'  Unless required by applicable law or agreed to in writing,
19*f94e042dSAndrew Rist'  software distributed under the License is distributed on an
20*f94e042dSAndrew Rist'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21*f94e042dSAndrew Rist'  KIND, either express or implied.  See the License for the
22*f94e042dSAndrew Rist'  specific language governing permissions and limitations
23*f94e042dSAndrew Rist'  under the License.
24cdf0e10cSrcweir'
25cdf0e10cSrcweir'*************************************************************************
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29*f94e042dSAndrew Rist
30*f94e042dSAndrew Rist
31cdf0e10cSrcweir'*************************************************************************
32cdf0e10cSrcweir'Change-Listener needs bound-Properties
33cdf0e10cSrcweir'Veto-Listener needs constrained-Propperties
34cdf0e10cSrcweir
35cdf0e10cSrcweir'*************************************************************************
36cdf0e10cSrcweir
37cdf0e10cSrcweir
38cdf0e10cSrcweir
39cdf0e10cSrcweir
40cdf0e10cSrcweirConst BOUND = 2
41cdf0e10cSrcweirConst CONSTRAINED = 4
42cdf0e10cSrcweirConst MAYBENULL = 8
43cdf0e10cSrcweirConst READONLY = 16
44cdf0e10cSrcweir
45cdf0e10cSrcweirDim aBoundProps() As String
46cdf0e10cSrcweirDim aConstrainedProps() As String
47cdf0e10cSrcweirDim aNormalProps() As String
48cdf0e10cSrcweirDim aReadOnlyProps() As String
49cdf0e10cSrcweir
50cdf0e10cSrcweirDim nBoundCount As Integer
51cdf0e10cSrcweirDim nConstrainedCount As Integer
52cdf0e10cSrcweirDim nNormalCount As Integer
53cdf0e10cSrcweirDim nReadOnlyCount As Integer
54cdf0e10cSrcweir
55cdf0e10cSrcweirDim aAllProps As Object
56cdf0e10cSrcweir
57cdf0e10cSrcweirDim vetoCalled1 As Boolean
58cdf0e10cSrcweirDim propCalled1 As Boolean
59cdf0e10cSrcweirDim vetoCalled2 As Boolean
60cdf0e10cSrcweirDim propCalled2 As Boolean
61cdf0e10cSrcweir
62cdf0e10cSrcweir
63cdf0e10cSrcweirSub RunTest()
64cdf0e10cSrcweir
65cdf0e10cSrcweir'*************************************************************************
66cdf0e10cSrcweir' INTERFACE:
67cdf0e10cSrcweir' com.sun.star.beans.XPropertySet
68cdf0e10cSrcweir'*************************************************************************
69cdf0e10cSrcweirOn Error Goto ErrHndl
70cdf0e10cSrcweirIf (bErrHndl) Then On Error Goto ErrHndl
71cdf0e10cSrcweir    Dim oPCListener1 As Object
72cdf0e10cSrcweir    Dim oVListener1 As Object
73cdf0e10cSrcweir    Dim oPCListener2 As Object
74cdf0e10cSrcweir    Dim oVListener2 As Object
75cdf0e10cSrcweir    Dim bOK As boolean
76cdf0e10cSrcweir
77cdf0e10cSrcweir    Test.StartMethod("getPropertySetInfo()")
78cdf0e10cSrcweir    bOK = true
79cdf0e10cSrcweir    bOK = NOT isNULL(oObj.PropertySetInfo)
80cdf0e10cSrcweir    Test.MethodTested("getPropertySetInfo()", bOK)
81cdf0e10cSrcweir
82cdf0e10cSrcweir    Out.Log("Get properties()")
83cdf0e10cSrcweir    bOK = GetProps()
84cdf0e10cSrcweir
85cdf0e10cSrcweir    Out.Log("Create Listeners")
86cdf0e10cSrcweir    oPCListener1 = createUNOListener("CB1_","com.sun.star.beans.XPropertyChangeListener")
87cdf0e10cSrcweir    oVListener1 = createUNOListener("CB1_","com.sun.star.beans.XVetoableChangeListener")
88cdf0e10cSrcweir    oPCListener2 = createUNOListener("CB2_","com.sun.star.beans.XPropertyChangeListener")
89cdf0e10cSrcweir    oVListener2 = createUNOListener("CB2_","com.sun.star.beans.XVetoableChangeListener")
90cdf0e10cSrcweir
91cdf0e10cSrcweir    Test.StartMethod("getPropertyValue()")
92cdf0e10cSrcweir    bOK = true
93cdf0e10cSrcweir    bOK = bOK AND test_getPropertyValue()
94cdf0e10cSrcweir    Test.MethodTested("getPropertyValue()", bOK)
95cdf0e10cSrcweir
96cdf0e10cSrcweir    Test.StartMethod("setPropertyValue()")
97cdf0e10cSrcweir    bOK = true
98cdf0e10cSrcweir    Dim bReadOnlyOK As Boolean
99cdf0e10cSrcweir    Dim bNormalOK As Boolean
100cdf0e10cSrcweir    bReadOnlyOK = false
101cdf0e10cSrcweir    bNormalOK = false
102cdf0e10cSrcweir    Dim bCVOK As boolean
103cdf0e10cSrcweir
104cdf0e10cSrcweir    if (nReadOnlyCount = 0) then
105cdf0e10cSrcweir        bReadOnlyOK = true
106cdf0e10cSrcweir        Out.Log("No ReadOnly properties!")
107cdf0e10cSrcweir    else
108cdf0e10cSrcweir        for i = 0 to nReadOnlyCount - 1
109cdf0e10cSrcweir            Out.Log("READONLY: '" &amp; aReadOnlyProps(i) &amp; "'")
110cdf0e10cSrcweir            if (aReadOnlyProps(i) = "Preview") then
111cdf0e10cSrcweir                bCVOK = true
112cdf0e10cSrcweir            else
113cdf0e10cSrcweir                bCVOK = PropertyTester.TestPropertyWithoutParams(aReadOnlyProps(i), true)
114cdf0e10cSrcweir            end if
115cdf0e10cSrcweir            Out.Log(bCVOK)
116cdf0e10cSrcweir            Out.Log("")
117cdf0e10cSrcweir            bReadOnlyOK = bReadOnlyOK OR bCVOK
118cdf0e10cSrcweir        next i
119cdf0e10cSrcweir    end if
120cdf0e10cSrcweir
121cdf0e10cSrcweir    bOK = bOK AND bReadOnlyOK
122cdf0e10cSrcweir
123cdf0e10cSrcweir    if (nNormalCount = 0) then
124cdf0e10cSrcweir        bNormalOK = true
125cdf0e10cSrcweir        Out.Log("No Normal properties!")
126cdf0e10cSrcweir    else
127cdf0e10cSrcweir        for i = 0 to nNormalCount - 1
128cdf0e10cSrcweir            Out.Log("NORMAL: '" &amp; aNormalProps(i) &amp; "'")
129cdf0e10cSrcweir            bCVOK = PropertyTester.TestPropertyWithoutParams(aNormalProps(i), false)
130cdf0e10cSrcweir            Out.Log(bCVOK)
131cdf0e10cSrcweir            Out.Log("")
132cdf0e10cSrcweir            bNormalOK = bNormalOK OR bCVOK
133cdf0e10cSrcweir        next i
134cdf0e10cSrcweir    end if
135cdf0e10cSrcweir
136cdf0e10cSrcweir    bOK = bOK AND bNormalOK
137cdf0e10cSrcweir
138cdf0e10cSrcweir    Test.MethodTested("setPropertyValue()", bOK)
139cdf0e10cSrcweir
140cdf0e10cSrcweir    Test.StartMethod("addVetoableChangeListener()")
141cdf0e10cSrcweir    Test.StartMethod("removeVetoableChangeListener()")
142cdf0e10cSrcweir    Dim bAddVeto As Boolean
143cdf0e10cSrcweir    Dim bRmvVeto As Boolean
144cdf0e10cSrcweir    bRmvVeto = true
145cdf0e10cSrcweir    bAddVeto = true
146cdf0e10cSrcweir
147cdf0e10cSrcweir    if (nConstrainedCount = 0) then
148cdf0e10cSrcweir        Out.Log("No Constrained properties!")
149cdf0e10cSrcweir        bAddVeto = true
150cdf0e10cSrcweir        bRmvVeto = true
151cdf0e10cSrcweir    else
152cdf0e10cSrcweir        for i = 0 to nConstrainedCount - 1
153cdf0e10cSrcweir            vetoCalled1 = false
154cdf0e10cSrcweir            vetoCalled2 = false
155cdf0e10cSrcweir            oObj.addVetoableChangeListener(aConstrainedProps(i), oVListener1)
156cdf0e10cSrcweir            oObj.addVetoableChangeListener(aConstrainedProps(i), oVListener2)
157cdf0e10cSrcweir            PropertyTester.TestPropertyWithoutParams(aConstrainedProps(i), false)
158cdf0e10cSrcweir            bAddVeto = bAddVeto OR (vetoCalled1 AND vetoCalled2)
159cdf0e10cSrcweir            Out.Log("addVetoableChangeListener: " &amp; aConstrainedProps(i) &amp; " Listener1 must be called: " &amp; vetoCalled1)
160cdf0e10cSrcweir            Out.Log("addVetoableChangeListener: " &amp; aConstrainedProps(i) &amp; " Listener2 must be called: " &amp; vetoCalled2)
161cdf0e10cSrcweir
162cdf0e10cSrcweir            vetoCalled1 = false
163cdf0e10cSrcweir            vetoCalled2 = false
164cdf0e10cSrcweir            oObj.removeVetoableChangeListener(aConstrainedProps(i), oVListener1)
165cdf0e10cSrcweir            PropertyTester.TestPropertyWithoutParams(aConstrainedProps(i), false)
166cdf0e10cSrcweir            bRmvVeto = bRmvVeto OR (NOT vetoCalled1 AND vetoCalled2)
167cdf0e10cSrcweir            Out.Log("removeVetoableChangeListener: " &amp; aConstrainedProps(i) &amp; " Listener1 must not be called: " &amp; NOT vetoCalled1)
168cdf0e10cSrcweir            Out.Log("removeVetoableChangeListener: " &amp; aConstrainedProps(i) &amp; " Listener2 must not be called: " &amp; NOT vetoCalled2)
169cdf0e10cSrcweir            oObj.removeVetoableChangeListener(aConstrainedProps(i), oVListener2)
170cdf0e10cSrcweir        next i
171cdf0e10cSrcweir    end if
172cdf0e10cSrcweir    Test.MethodTested("addVetoableChangeListener()", bAddVeto)
173cdf0e10cSrcweir    Test.MethodTested("removeVetoableChangeListener()", bRmvVeto)
174cdf0e10cSrcweir
175cdf0e10cSrcweir    Test.StartMethod("addPropertyChangeListener()")
176cdf0e10cSrcweir    Test.StartMethod("removePropertyChangeListener()")
177cdf0e10cSrcweir    Dim bAddProp As Boolean
178cdf0e10cSrcweir    Dim bRmvProp As Boolean
179cdf0e10cSrcweir    bRmvProp = true
180cdf0e10cSrcweir    bAddProp = true
181cdf0e10cSrcweir
182cdf0e10cSrcweir    if (nBoundCount = 0) then
183cdf0e10cSrcweir        Out.Log("No Bound properties!")
184cdf0e10cSrcweir        bAddProp = true
185cdf0e10cSrcweir        bRmvProp = true
186cdf0e10cSrcweir    else
187cdf0e10cSrcweir        for i = 0 to nBoundCount - 1
188cdf0e10cSrcweir            propCalled1 = false
189cdf0e10cSrcweir            propCalled2 = false
190cdf0e10cSrcweir            oObj.addPropertyChangeListener(aBoundProps(i), oPCListener1)
191cdf0e10cSrcweir            oObj.addPropertyChangeListener(aBoundProps(i), oPCListener2)
192cdf0e10cSrcweir            PropertyTester.TestPropertyWithoutParams(aBoundProps(i), false)
193cdf0e10cSrcweir            bAddProp = bAddProp OR (propCalled1 AND propCalled2)
194cdf0e10cSrcweir            Out.Log("addPropertyChangeListener: " &amp; aBoundProps(i) &amp; " Listener1 must be called :" &amp; propCalled1)
195cdf0e10cSrcweir            Out.Log("addPropertyChangeListener: " &amp; aBoundProps(i) &amp; " Listener2 must be called :" &amp; propCalled2)
196cdf0e10cSrcweir
197cdf0e10cSrcweir            propCalled1 = false
198cdf0e10cSrcweir            propCalled2 = false
199cdf0e10cSrcweir            oObj.removePropertyChangeListener(aBoundProps(i), oPCListener1)
200cdf0e10cSrcweir            PropertyTester.TestPropertyWithoutParams(aBoundProps(i), false)
201cdf0e10cSrcweir            bRmvProp = bRmvProp OR (NOT propCalled1 AND propCalled2)
202cdf0e10cSrcweir            Out.Log("removePropertyChangeListener: " &amp; aBoundProps(i) &amp; " Listener must not be called: " &amp; NOT propCalled)
203cdf0e10cSrcweir            oObj.removePropertyChangeListener(aBoundProps(i), oPCListener2)
204cdf0e10cSrcweir        next i
205cdf0e10cSrcweir    end if
206cdf0e10cSrcweir
207cdf0e10cSrcweir    Test.MethodTested("addPropertyChangeListener()", bAddProp)
208cdf0e10cSrcweir    Test.MethodTested("removePropertyChangeListener()", bRmvProp)
209cdf0e10cSrcweir
210cdf0e10cSrcweir    ReCreateObj()
211cdf0e10cSrcweir
212cdf0e10cSrcweirExit Sub
213cdf0e10cSrcweirErrHndl:
214cdf0e10cSrcweir    Test.Exception()
215cdf0e10cSrcweir    bOK = false
216cdf0e10cSrcweir    resume next
217cdf0e10cSrcweirEnd Sub
218cdf0e10cSrcweir
219cdf0e10cSrcweirFunction GetProps() As Boolean
220cdf0e10cSrcweirOn Error Goto ErrHndl
221cdf0e10cSrcweir    Dim bOK as Boolean
222cdf0e10cSrcweir    Dim i As Integer
223cdf0e10cSrcweir    Dim attr As Variant
224cdf0e10cSrcweir    bOK = true
225cdf0e10cSrcweir
226cdf0e10cSrcweir    aAllProps = oObj.propertySetInfo.getProperties
227cdf0e10cSrcweir    nNormalCount = 0
228cdf0e10cSrcweir    nBoundCount = 0
229cdf0e10cSrcweir    nConstrainedCount = 0
230cdf0e10cSrcweir    nReadOnlyCount = 0
231cdf0e10cSrcweir
232cdf0e10cSrcweir    'first we should find out how many properties of different kinds exists
233cdf0e10cSrcweir    for i = lbound(aAllProps) to ubound(aAllProps)
234cdf0e10cSrcweir        attr = aAllProps(i).Attributes
235cdf0e10cSrcweir        if (attr AND READONLY) OR (attr AND BOUND) OR (attr AND CONSTRAINED) then
236cdf0e10cSrcweir            if (attr AND BOUND) then
237cdf0e10cSrcweir                nBoundCount = nBoundCount + 1
238cdf0e10cSrcweir            end if
239cdf0e10cSrcweir            if (attr AND CONSTRAINED) then
240cdf0e10cSrcweir                nConstrainedCount = nConstrainedCount + 1
241cdf0e10cSrcweir            end if
242cdf0e10cSrcweir            if (attr AND READONLY) then
243cdf0e10cSrcweir                nReadOnlyCount = nReadOnlyCount + 1
244cdf0e10cSrcweir            end if
245cdf0e10cSrcweir        else
246cdf0e10cSrcweir            if (NOT isNULL(oObj.getPropertyValue(aAllProps(i).Name))) then
247cdf0e10cSrcweir                nNormalCount = nNormalCount + 1
248cdf0e10cSrcweir            end if
249cdf0e10cSrcweir        end if
250cdf0e10cSrcweir    next i
251cdf0e10cSrcweir
252cdf0e10cSrcweir    Out.Log("" &amp; nNormalCount &amp; " Normal properties found")
253cdf0e10cSrcweir    Out.Log("" &amp; nBoundCount &amp; " Bound properties found")
254cdf0e10cSrcweir    Out.Log("" &amp; nConstrainedCount &amp; " Constrained properties found")
255cdf0e10cSrcweir    Out.Log("" &amp; nReadOnlyCount &amp; " ReadOnly properties found")
256cdf0e10cSrcweir
257cdf0e10cSrcweir    Dim AN(nNormalCount) As String
258cdf0e10cSrcweir    aNormalProps = AN()
259cdf0e10cSrcweir
260cdf0e10cSrcweir    Dim AB(nBoundCount) As String
261cdf0e10cSrcweir    aBoundProps = AB()
262cdf0e10cSrcweir
263cdf0e10cSrcweir    Dim AC(nConstrainedCount) As String
264cdf0e10cSrcweir    aConstrainedProps = AC()
265cdf0e10cSrcweir
266cdf0e10cSrcweir    Dim AR(nReadOnlyCount) As String
267cdf0e10cSrcweir    aReadOnlyProps = AR()
268cdf0e10cSrcweir
269cdf0e10cSrcweir   'Filling up arrays...
270cdf0e10cSrcweir
271cdf0e10cSrcweir    nNormalCount = 0
272cdf0e10cSrcweir    nBoundCount = 0
273cdf0e10cSrcweir    nConstrainedCount = 0
274cdf0e10cSrcweir    nReadOnlyCount = 0
275cdf0e10cSrcweir    for i = lbound(aAllProps) to ubound(aAllProps)
276cdf0e10cSrcweir        attr = aAllProps(i).Attributes
277cdf0e10cSrcweir        if (attr AND READONLY) OR (attr AND BOUND) OR (attr AND CONSTRAINED) then
278cdf0e10cSrcweir            if (attr AND BOUND) then
279cdf0e10cSrcweir                aBoundProps(nBoundCount) = aAllProps(i).Name
280cdf0e10cSrcweir                nBoundCount = nBoundCount + 1
281cdf0e10cSrcweir            end if
282cdf0e10cSrcweir            if (attr AND CONSTRAINED) then
283cdf0e10cSrcweir                aConstrainedProps(nConstrainedCount) = aAllProps(i).Name
284cdf0e10cSrcweir                nConstrainedCount = nConstrainedCount + 1
285cdf0e10cSrcweir            end if
286cdf0e10cSrcweir            if (attr AND READONLY) then
287cdf0e10cSrcweir                aReadOnlyProps(nReadOnlyCount) = aAllProps(i).Name
288cdf0e10cSrcweir                nReadOnlyCount = nReadOnlyCount + 1
289cdf0e10cSrcweir            end if
290cdf0e10cSrcweir        else
291cdf0e10cSrcweir            if (NOT isNULL(oObj.getPropertyValue(aAllProps(i).Name))) then
292cdf0e10cSrcweir                aNormalProps(nNormalCount) = aAllProps(i).Name
293cdf0e10cSrcweir                nNormalCount = nNormalCount + 1
294cdf0e10cSrcweir            end if
295cdf0e10cSrcweir        end if
296cdf0e10cSrcweir    next i
297cdf0e10cSrcweir
298cdf0e10cSrcweir    GetProps = bOK
299cdf0e10cSrcweirExit Function
300cdf0e10cSrcweirErrHndl:
301cdf0e10cSrcweir    Test.Exception()
302cdf0e10cSrcweir    resume next
303cdf0e10cSrcweirEnd Function
304cdf0e10cSrcweir
305cdf0e10cSrcweirFunction test_GetPropertyValue() As Boolean
306cdf0e10cSrcweirOn Error goto ErrHndl
307cdf0e10cSrcweir
308cdf0e10cSrcweir    Dim bOK As Boolean
309cdf0e10cSrcweir    Dim i As Integer
310cdf0e10cSrcweir    Dim propName As String
311cdf0e10cSrcweir    Dim propVal As Variant
312cdf0e10cSrcweir    bOK = false
313cdf0e10cSrcweir
314cdf0e10cSrcweir    for i = lbound(aAllProps) to ubound(aAllProps)
315cdf0e10cSrcweir        propName = aAllProps(i).Name
316cdf0e10cSrcweir        propVal = oObj.getPropertyValue(propName)
317cdf0e10cSrcweir        bOK = true
318cdf0e10cSrcweir        if (isNULL(propVal)) AND NOT(aAllProps(i).Attributes AND MAYBENULL) then
319cdf0e10cSrcweir                Out.Log(cIfcShortName &amp; " " &amp; aAllProps(i).Name &amp; " is NULL, but it is not MAYBENULL")
320cdf0e10cSrcweir        end if
321cdf0e10cSrcweir    next i
322cdf0e10cSrcweir
323cdf0e10cSrcweir    test_GetPropertyValue() = bOK
324cdf0e10cSrcweirExit Function
325cdf0e10cSrcweirErrHndl:
326cdf0e10cSrcweir    Test.Exception()
327cdf0e10cSrcweir    bOK = false
328cdf0e10cSrcweir    resume next
329cdf0e10cSrcweirEnd Function
330cdf0e10cSrcweir
331cdf0e10cSrcweirSub CB1_propertyChange
332cdf0e10cSrcweir    Out.Log("CallBack 'PropertyChange' for listener 1 was called.")
333cdf0e10cSrcweir    propCalled1 = true
334cdf0e10cSrcweir    CB1_propertyChange = true
335cdf0e10cSrcweirEnd Sub
336cdf0e10cSrcweir
337cdf0e10cSrcweirSub CB1_vetoableChange
338cdf0e10cSrcweir    Out.Log("CallBack 'vetoableChange' for listener 1 was called.")
339cdf0e10cSrcweir    vetoCalled1 = true
340cdf0e10cSrcweirEnd Sub
341cdf0e10cSrcweir
342cdf0e10cSrcweirSub CB2_propertyChange
343cdf0e10cSrcweir    Out.Log("CallBack 'PropertyChange' for listener 2 was called.")
344cdf0e10cSrcweir    propCalled2 = true
345cdf0e10cSrcweir    CB2_propertyChange = true
346cdf0e10cSrcweirEnd Sub
347cdf0e10cSrcweir
348cdf0e10cSrcweirSub CB2_vetoableChange
349cdf0e10cSrcweir    Out.Log("CallBack 'vetoableChange' for listener 2 was called.")
350cdf0e10cSrcweir    vetoCalled2 = true
351cdf0e10cSrcweirEnd Sub
352cdf0e10cSrcweir</script:module>
353