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