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