1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="beans_XPropertySet" script:language="StarBasic">
'*************************************************************************
'
' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
'
' Copyright 2008 by Sun Microsystems, Inc.
'
' OpenOffice.org - a multi-platform office productivity suite
'
' $RCSfile: beans_XPropertySet.xba,v $
'
' $Revision: 1.3 $
'
' This file is part of OpenOffice.org.
'
' OpenOffice.org is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License version 3
' only, as published by the Free Software Foundation.
'
' OpenOffice.org is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU Lesser General Public License version 3 for more details
' (a copy is included in the LICENSE file that accompanied this code).
'
' You should have received a copy of the GNU Lesser General Public License
' version 3 along with OpenOffice.org. If not, see
' <http://www.openoffice.org/license.html>
' for a copy of the LGPLv3 License.
'
'*************************************************************************
'*************************************************************************
'*************************************************************************
'Change-Listener needs bound-Properties
'Veto-Listener needs constrained-Propperties
'*************************************************************************
Const BOUND = 2
Const CONSTRAINED = 4
Const MAYBENULL = 8
Const READONLY = 16
Dim aBoundProps() As String
Dim aConstrainedProps() As String
Dim aNormalProps() As String
Dim aReadOnlyProps() As String
Dim nBoundCount As Integer
Dim nConstrainedCount As Integer
Dim nNormalCount As Integer
Dim nReadOnlyCount As Integer
Dim aAllProps As Object
Dim vetoCalled1 As Boolean
Dim propCalled1 As Boolean
Dim vetoCalled2 As Boolean
Dim propCalled2 As Boolean
Sub RunTest()
'*************************************************************************
' INTERFACE:
' com.sun.star.beans.XPropertySet
'*************************************************************************
On Error Goto ErrHndl
If (bErrHndl) Then On Error Goto ErrHndl
Dim oPCListener1 As Object
Dim oVListener1 As Object
Dim oPCListener2 As Object
Dim oVListener2 As Object
Dim bOK As boolean
Test.StartMethod("getPropertySetInfo()")
bOK = true
bOK = NOT isNULL(oObj.PropertySetInfo)
Test.MethodTested("getPropertySetInfo()", bOK)
Out.Log("Get properties()")
bOK = GetProps()
Out.Log("Create Listeners")
oPCListener1 = createUNOListener("CB1_","com.sun.star.beans.XPropertyChangeListener")
oVListener1 = createUNOListener("CB1_","com.sun.star.beans.XVetoableChangeListener")
oPCListener2 = createUNOListener("CB2_","com.sun.star.beans.XPropertyChangeListener")
oVListener2 = createUNOListener("CB2_","com.sun.star.beans.XVetoableChangeListener")
Test.StartMethod("getPropertyValue()")
bOK = true
bOK = bOK AND test_getPropertyValue()
Test.MethodTested("getPropertyValue()", bOK)
Test.StartMethod("setPropertyValue()")
bOK = true
Dim bReadOnlyOK As Boolean
Dim bNormalOK As Boolean
bReadOnlyOK = false
bNormalOK = false
Dim bCVOK As boolean
if (nReadOnlyCount = 0) then
bReadOnlyOK = true
Out.Log("No ReadOnly properties!")
else
for i = 0 to nReadOnlyCount - 1
Out.Log("READONLY: '" & aReadOnlyProps(i) & "'")
if (aReadOnlyProps(i) = "Preview") then
bCVOK = true
else
bCVOK = PropertyTester.TestPropertyWithoutParams(aReadOnlyProps(i), true)
end if
Out.Log(bCVOK)
Out.Log("")
bReadOnlyOK = bReadOnlyOK OR bCVOK
next i
end if
bOK = bOK AND bReadOnlyOK
if (nNormalCount = 0) then
bNormalOK = true
Out.Log("No Normal properties!")
else
for i = 0 to nNormalCount - 1
Out.Log("NORMAL: '" & aNormalProps(i) & "'")
bCVOK = PropertyTester.TestPropertyWithoutParams(aNormalProps(i), false)
Out.Log(bCVOK)
Out.Log("")
bNormalOK = bNormalOK OR bCVOK
next i
end if
bOK = bOK AND bNormalOK
Test.MethodTested("setPropertyValue()", bOK)
Test.StartMethod("addVetoableChangeListener()")
Test.StartMethod("removeVetoableChangeListener()")
Dim bAddVeto As Boolean
Dim bRmvVeto As Boolean
bRmvVeto = true
bAddVeto = true
if (nConstrainedCount = 0) then
Out.Log("No Constrained properties!")
bAddVeto = true
bRmvVeto = true
else
for i = 0 to nConstrainedCount - 1
vetoCalled1 = false
vetoCalled2 = false
oObj.addVetoableChangeListener(aConstrainedProps(i), oVListener1)
oObj.addVetoableChangeListener(aConstrainedProps(i), oVListener2)
PropertyTester.TestPropertyWithoutParams(aConstrainedProps(i), false)
bAddVeto = bAddVeto OR (vetoCalled1 AND vetoCalled2)
Out.Log("addVetoableChangeListener: " & aConstrainedProps(i) & " Listener1 must be called: " & vetoCalled1)
Out.Log("addVetoableChangeListener: " & aConstrainedProps(i) & " Listener2 must be called: " & vetoCalled2)
vetoCalled1 = false
vetoCalled2 = false
oObj.removeVetoableChangeListener(aConstrainedProps(i), oVListener1)
PropertyTester.TestPropertyWithoutParams(aConstrainedProps(i), false)
bRmvVeto = bRmvVeto OR (NOT vetoCalled1 AND vetoCalled2)
Out.Log("removeVetoableChangeListener: " & aConstrainedProps(i) & " Listener1 must not be called: " & NOT vetoCalled1)
Out.Log("removeVetoableChangeListener: " & aConstrainedProps(i) & " Listener2 must not be called: " & NOT vetoCalled2)
oObj.removeVetoableChangeListener(aConstrainedProps(i), oVListener2)
next i
end if
Test.MethodTested("addVetoableChangeListener()", bAddVeto)
Test.MethodTested("removeVetoableChangeListener()", bRmvVeto)
Test.StartMethod("addPropertyChangeListener()")
Test.StartMethod("removePropertyChangeListener()")
Dim bAddProp As Boolean
Dim bRmvProp As Boolean
bRmvProp = true
bAddProp = true
if (nBoundCount = 0) then
Out.Log("No Bound properties!")
bAddProp = true
bRmvProp = true
else
for i = 0 to nBoundCount - 1
propCalled1 = false
propCalled2 = false
oObj.addPropertyChangeListener(aBoundProps(i), oPCListener1)
oObj.addPropertyChangeListener(aBoundProps(i), oPCListener2)
PropertyTester.TestPropertyWithoutParams(aBoundProps(i), false)
bAddProp = bAddProp OR (propCalled1 AND propCalled2)
Out.Log("addPropertyChangeListener: " & aBoundProps(i) & " Listener1 must be called :" & propCalled1)
Out.Log("addPropertyChangeListener: " & aBoundProps(i) & " Listener2 must be called :" & propCalled2)
propCalled1 = false
propCalled2 = false
oObj.removePropertyChangeListener(aBoundProps(i), oPCListener1)
PropertyTester.TestPropertyWithoutParams(aBoundProps(i), false)
bRmvProp = bRmvProp OR (NOT propCalled1 AND propCalled2)
Out.Log("removePropertyChangeListener: " & aBoundProps(i) & " Listener must not be called: " & NOT propCalled)
oObj.removePropertyChangeListener(aBoundProps(i), oPCListener2)
next i
end if
Test.MethodTested("addPropertyChangeListener()", bAddProp)
Test.MethodTested("removePropertyChangeListener()", bRmvProp)
ReCreateObj()
Exit Sub
ErrHndl:
Test.Exception()
bOK = false
resume next
End Sub
Function GetProps() As Boolean
On Error Goto ErrHndl
Dim bOK as Boolean
Dim i As Integer
Dim attr As Variant
bOK = true
aAllProps = oObj.propertySetInfo.getProperties
nNormalCount = 0
nBoundCount = 0
nConstrainedCount = 0
nReadOnlyCount = 0
'first we should find out how many properties of different kinds exists
for i = lbound(aAllProps) to ubound(aAllProps)
attr = aAllProps(i).Attributes
if (attr AND READONLY) OR (attr AND BOUND) OR (attr AND CONSTRAINED) then
if (attr AND BOUND) then
nBoundCount = nBoundCount + 1
end if
if (attr AND CONSTRAINED) then
nConstrainedCount = nConstrainedCount + 1
end if
if (attr AND READONLY) then
nReadOnlyCount = nReadOnlyCount + 1
end if
else
if (NOT isNULL(oObj.getPropertyValue(aAllProps(i).Name))) then
nNormalCount = nNormalCount + 1
end if
end if
next i
Out.Log("" & nNormalCount & " Normal properties found")
Out.Log("" & nBoundCount & " Bound properties found")
Out.Log("" & nConstrainedCount & " Constrained properties found")
Out.Log("" & nReadOnlyCount & " ReadOnly properties found")
Dim AN(nNormalCount) As String
aNormalProps = AN()
Dim AB(nBoundCount) As String
aBoundProps = AB()
Dim AC(nConstrainedCount) As String
aConstrainedProps = AC()
Dim AR(nReadOnlyCount) As String
aReadOnlyProps = AR()
'Filling up arrays...
nNormalCount = 0
nBoundCount = 0
nConstrainedCount = 0
nReadOnlyCount = 0
for i = lbound(aAllProps) to ubound(aAllProps)
attr = aAllProps(i).Attributes
if (attr AND READONLY) OR (attr AND BOUND) OR (attr AND CONSTRAINED) then
if (attr AND BOUND) then
aBoundProps(nBoundCount) = aAllProps(i).Name
nBoundCount = nBoundCount + 1
end if
if (attr AND CONSTRAINED) then
aConstrainedProps(nConstrainedCount) = aAllProps(i).Name
nConstrainedCount = nConstrainedCount + 1
end if
if (attr AND READONLY) then
aReadOnlyProps(nReadOnlyCount) = aAllProps(i).Name
nReadOnlyCount = nReadOnlyCount + 1
end if
else
if (NOT isNULL(oObj.getPropertyValue(aAllProps(i).Name))) then
aNormalProps(nNormalCount) = aAllProps(i).Name
nNormalCount = nNormalCount + 1
end if
end if
next i
GetProps = bOK
Exit Function
ErrHndl:
Test.Exception()
resume next
End Function
Function test_GetPropertyValue() As Boolean
On Error goto ErrHndl
Dim bOK As Boolean
Dim i As Integer
Dim propName As String
Dim propVal As Variant
bOK = false
for i = lbound(aAllProps) to ubound(aAllProps)
propName = aAllProps(i).Name
propVal = oObj.getPropertyValue(propName)
bOK = true
if (isNULL(propVal)) AND NOT(aAllProps(i).Attributes AND MAYBENULL) then
Out.Log(cIfcShortName & " " & aAllProps(i).Name & " is NULL, but it is not MAYBENULL")
end if
next i
test_GetPropertyValue() = bOK
Exit Function
ErrHndl:
Test.Exception()
bOK = false
resume next
End Function
Sub CB1_propertyChange
Out.Log("CallBack 'PropertyChange' for listener 1 was called.")
propCalled1 = true
CB1_propertyChange = true
End Sub
Sub CB1_vetoableChange
Out.Log("CallBack 'vetoableChange' for listener 1 was called.")
vetoCalled1 = true
End Sub
Sub CB2_propertyChange
Out.Log("CallBack 'PropertyChange' for listener 2 was called.")
propCalled2 = true
CB2_propertyChange = true
End Sub
Sub CB2_vetoableChange
Out.Log("CallBack 'vetoableChange' for listener 2 was called.")
vetoCalled2 = true
End Sub
</script:module>
|