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_XPropertyState" 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 32Const BOUND = 2 33Const CONSTRAINED = 4 34Const MAYBENULL = 8 35Const READONLY = 16 36 37 38Sub RunTest() 39 40'************************************************************************* 41' INTERFACE: 42' com.sun.star.beans.XPropertyState 43'************************************************************************* 44On Error Goto ErrHndl 45 Dim bOK As Boolean 46 47 Dim oProperties As Variant 48 Dim nAllProps As Integer 49 Dim aValue As Variant 50 Dim n As Integer 51 Dim oCoreRefl As Object 52 Dim bTypesEq As Boolean 53 54 bOK = true 55 56 oCoreRefl = createUnoService("com.sun.star.reflection.CoreReflection") 57 58 oProperties = oObj.GetPropertySetInfo().Properties 59 nAllProps = uBound(oProperties) 60 Dim AllPropsNames(nAllProps) As String 61 Out.Log("Found " & nAllProps & " properties.") 62 63 for n = 0 to (nAllProps) 64 AllPropsNames(n) = oProperties(n).Name 65 next n 66 67 Test.StartMethod("getPropertyStates()") 68 Out.Log("getting states for all properties.") 69 bOK = true 70 71 Dim aStates As Variant 72 73 aStates() = oObj.getPropertyStates(AllPropsNames()) 74 bOK = bOK AND isArray(aStates()) 75 if (bOK) then Out.Log("Length of returned array is " & ubound(aStates())) 76 bOK = bOK AND ubound(aStates()) = nAllProps 77 78 Dim nState As Integer 79 nState = aStates(nAllProps / 2) 80 bOK = bOK AND (nState = com.sun.star.beans.PropertyState.DIRECT_VALUE OR _ 81 nState = com.sun.star.beans.PropertyState.DEFAULT_VALUE OR _ 82 nState = com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE) 83 Test.MethodTested("getPropertyStates()", bOK) 84 85 Test.StartMethod("getPropertyState()") 86 bOK = false 87 n = 0 88 89 ' Here testing getPropertyState method. Method is OK when at least one 90 ' property works correctly. 91 92 while (bOK = false AND n < nAllProps) 93 bOK = true 94 nState = oObj.getPropertyState(AllPropsNames(n)) 95 bOK = bOK AND (nState = com.sun.star.beans.PropertyState.DIRECT_VALUE OR _ 96 nState = com.sun.star.beans.PropertyState.DEFAULT_VALUE OR _ 97 nState = com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE) 98 n = n + 1 99 wend 100 Test.MethodTested("getPropertyState()", bOK) 101 102 Test.StartMethod("getPropertyDefault()") 103 bOK = false 104 n = 0 105 106 ' Here testing getPropertyDefault method. Method is OK when at least one 107 ' property works correctly. 108 109 while (bOK = false AND n < nAllProps) 110 bOK = true 111 aValue = oObj.getPropertyDefault(AllPropsNames(n)) 112 bOK = bOK AND (oProperties(n).Type.Name = oCoreRefl.getType(aValue).Name) 113 n = n + 1 114 wend 115 Test.MethodTested("getPropertyDefault()", bOK) 116 117 Test.StartMethod("setPropertyToDefault()") 118 bOK = false 119 n = 0 120 121 ' Here testing setPropertyToDefault method. Method is OK when at least one 122 ' property works correctly. 123 124 while (bOK = false AND n < nAllProps) 125 bOK = true 126 oObj.setPropertyToDefault(AllPropsNames(n)) 127 n = n + 1 128 wend 129 Test.MethodTested("setPropertyToDefault()", bOK) 130 131 132 ' Here testing getPropertyState for ALL properties. This will 133 ' put all exceptions to .log file (if this method doesn't work with some properties) 134 ' but without any affect to test status. 135 136 n = 0 137 while (n < nAllProps) 138 bOK = true 139 nState = oObj.getPropertyState(AllPropsNames(n)) 140 bOK = bOK AND (nState = com.sun.star.beans.PropertyState.DIRECT_VALUE OR _ 141 nState = com.sun.star.beans.PropertyState.DEFAULT_VALUE OR _ 142 nState = com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE) 143 144 if (NOT bOK) then 145 Out.Log("Error while testing getPropertyState() for '" & AllPropsNames(n) & "' FAILED.") 146 else 147 Out.Log("getPropertyState() for property '" & AllPropsNames(n) & "' is OK") 148 end if 149 150 bOK = true 151 aValue = oObj.getPropertyDefault(AllPropsNames(n)) 152 bTypesEq = false 153 if (bOK AND (TypeName(aValue) <> "Empty")) then 154 bTypesEq = (oProperties(n).Type.Name = oCoreRefl.getType(aValue).Name) 155 end if 156 157 if (NOT bOK) then ' exception was occured 158 Out.Log("Error while testing getPropertyDefault() for '" & AllPropsNames(n) & "' FAILED.") 159 elseif ((TypeName(aValue) <> "Empty") AND (NOT bTypesEq)) then 160 Out.Log("Types: '" & oProperties(n).Type.Name & "' and '" & oCoreRefl.getType(aValue).Name & "' are different.") 161 else 162 Out.Log("getPropertyDefault() for property '" & AllPropsNames(n) & "' is OK") 163 end if 164 n = n + 1 165 wend 166 167Exit Sub 168ErrHndl: 169 Test.Exception() 170 bOK = false 171 resume next 172End Sub 173</script:module> 174