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