1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?> 2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="beans_XPropertyState" script:language="StarBasic"> 4cdf0e10cSrcweir 5cdf0e10cSrcweir 6cdf0e10cSrcweir'************************************************************************* 7cdf0e10cSrcweir' 8*eebed415SAndrew Rist' Licensed to the Apache Software Foundation (ASF) under one 9*eebed415SAndrew Rist' or more contributor license agreements. See the NOTICE file 10*eebed415SAndrew Rist' distributed with this work for additional information 11*eebed415SAndrew Rist' regarding copyright ownership. The ASF licenses this file 12*eebed415SAndrew Rist' to you under the Apache License, Version 2.0 (the 13*eebed415SAndrew Rist' "License"); you may not use this file except in compliance 14*eebed415SAndrew Rist' with the License. You may obtain a copy of the License at 15*eebed415SAndrew Rist' 16*eebed415SAndrew Rist' http://www.apache.org/licenses/LICENSE-2.0 17*eebed415SAndrew Rist' 18*eebed415SAndrew Rist' Unless required by applicable law or agreed to in writing, 19*eebed415SAndrew Rist' software distributed under the License is distributed on an 20*eebed415SAndrew Rist' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21*eebed415SAndrew Rist' KIND, either express or implied. See the License for the 22*eebed415SAndrew Rist' specific language governing permissions and limitations 23*eebed415SAndrew Rist' under the License. 24cdf0e10cSrcweir' 25cdf0e10cSrcweir'************************************************************************* 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir 29cdf0e10cSrcweir 30*eebed415SAndrew Rist 31*eebed415SAndrew Rist 32cdf0e10cSrcweirConst BOUND = 2 33cdf0e10cSrcweirConst CONSTRAINED = 4 34cdf0e10cSrcweirConst MAYBENULL = 8 35cdf0e10cSrcweirConst READONLY = 16 36cdf0e10cSrcweir 37cdf0e10cSrcweir 38cdf0e10cSrcweirSub RunTest() 39cdf0e10cSrcweir 40cdf0e10cSrcweir'************************************************************************* 41cdf0e10cSrcweir' INTERFACE: 42cdf0e10cSrcweir' com.sun.star.beans.XPropertyState 43cdf0e10cSrcweir'************************************************************************* 44cdf0e10cSrcweirOn Error Goto ErrHndl 45cdf0e10cSrcweir Dim bOK As Boolean 46cdf0e10cSrcweir 47cdf0e10cSrcweir Dim oProperties As Variant 48cdf0e10cSrcweir Dim nAllProps As Integer 49cdf0e10cSrcweir Dim aValue As Variant 50cdf0e10cSrcweir Dim n As Integer 51cdf0e10cSrcweir Dim oCoreRefl As Object 52cdf0e10cSrcweir Dim bTypesEq As Boolean 53cdf0e10cSrcweir 54cdf0e10cSrcweir bOK = true 55cdf0e10cSrcweir 56cdf0e10cSrcweir oCoreRefl = createUnoService("com.sun.star.reflection.CoreReflection") 57cdf0e10cSrcweir 58cdf0e10cSrcweir oProperties = oObj.GetPropertySetInfo().Properties 59cdf0e10cSrcweir nAllProps = uBound(oProperties) 60cdf0e10cSrcweir Dim AllPropsNames(nAllProps) As String 61cdf0e10cSrcweir Out.Log("Found " & nAllProps & " properties.") 62cdf0e10cSrcweir 63cdf0e10cSrcweir for n = 0 to (nAllProps) 64cdf0e10cSrcweir AllPropsNames(n) = oProperties(n).Name 65cdf0e10cSrcweir next n 66cdf0e10cSrcweir 67cdf0e10cSrcweir Test.StartMethod("getPropertyStates()") 68cdf0e10cSrcweir Out.Log("getting states for all properties.") 69cdf0e10cSrcweir bOK = true 70cdf0e10cSrcweir 71cdf0e10cSrcweir Dim aStates As Variant 72cdf0e10cSrcweir 73cdf0e10cSrcweir aStates() = oObj.getPropertyStates(AllPropsNames()) 74cdf0e10cSrcweir bOK = bOK AND isArray(aStates()) 75cdf0e10cSrcweir if (bOK) then Out.Log("Length of returned array is " & ubound(aStates())) 76cdf0e10cSrcweir bOK = bOK AND ubound(aStates()) = nAllProps 77cdf0e10cSrcweir 78cdf0e10cSrcweir Dim nState As Integer 79cdf0e10cSrcweir nState = aStates(nAllProps / 2) 80cdf0e10cSrcweir bOK = bOK AND (nState = com.sun.star.beans.PropertyState.DIRECT_VALUE OR _ 81cdf0e10cSrcweir nState = com.sun.star.beans.PropertyState.DEFAULT_VALUE OR _ 82cdf0e10cSrcweir nState = com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE) 83cdf0e10cSrcweir Test.MethodTested("getPropertyStates()", bOK) 84cdf0e10cSrcweir 85cdf0e10cSrcweir Test.StartMethod("getPropertyState()") 86cdf0e10cSrcweir bOK = false 87cdf0e10cSrcweir n = 0 88cdf0e10cSrcweir 89cdf0e10cSrcweir ' Here testing getPropertyState method. Method is OK when at least one 90cdf0e10cSrcweir ' property works correctly. 91cdf0e10cSrcweir 92cdf0e10cSrcweir while (bOK = false AND n < nAllProps) 93cdf0e10cSrcweir bOK = true 94cdf0e10cSrcweir nState = oObj.getPropertyState(AllPropsNames(n)) 95cdf0e10cSrcweir bOK = bOK AND (nState = com.sun.star.beans.PropertyState.DIRECT_VALUE OR _ 96cdf0e10cSrcweir nState = com.sun.star.beans.PropertyState.DEFAULT_VALUE OR _ 97cdf0e10cSrcweir nState = com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE) 98cdf0e10cSrcweir n = n + 1 99cdf0e10cSrcweir wend 100cdf0e10cSrcweir Test.MethodTested("getPropertyState()", bOK) 101cdf0e10cSrcweir 102cdf0e10cSrcweir Test.StartMethod("getPropertyDefault()") 103cdf0e10cSrcweir bOK = false 104cdf0e10cSrcweir n = 0 105cdf0e10cSrcweir 106cdf0e10cSrcweir ' Here testing getPropertyDefault method. Method is OK when at least one 107cdf0e10cSrcweir ' property works correctly. 108cdf0e10cSrcweir 109cdf0e10cSrcweir while (bOK = false AND n < nAllProps) 110cdf0e10cSrcweir bOK = true 111cdf0e10cSrcweir aValue = oObj.getPropertyDefault(AllPropsNames(n)) 112cdf0e10cSrcweir bOK = bOK AND (oProperties(n).Type.Name = oCoreRefl.getType(aValue).Name) 113cdf0e10cSrcweir n = n + 1 114cdf0e10cSrcweir wend 115cdf0e10cSrcweir Test.MethodTested("getPropertyDefault()", bOK) 116cdf0e10cSrcweir 117cdf0e10cSrcweir Test.StartMethod("setPropertyToDefault()") 118cdf0e10cSrcweir bOK = false 119cdf0e10cSrcweir n = 0 120cdf0e10cSrcweir 121cdf0e10cSrcweir ' Here testing setPropertyToDefault method. Method is OK when at least one 122cdf0e10cSrcweir ' property works correctly. 123cdf0e10cSrcweir 124cdf0e10cSrcweir while (bOK = false AND n < nAllProps) 125cdf0e10cSrcweir bOK = true 126cdf0e10cSrcweir oObj.setPropertyToDefault(AllPropsNames(n)) 127cdf0e10cSrcweir n = n + 1 128cdf0e10cSrcweir wend 129cdf0e10cSrcweir Test.MethodTested("setPropertyToDefault()", bOK) 130cdf0e10cSrcweir 131cdf0e10cSrcweir 132cdf0e10cSrcweir ' Here testing getPropertyState for ALL properties. This will 133cdf0e10cSrcweir ' put all exceptions to .log file (if this method doesn't work with some properties) 134cdf0e10cSrcweir ' but without any affect to test status. 135cdf0e10cSrcweir 136cdf0e10cSrcweir n = 0 137cdf0e10cSrcweir while (n < nAllProps) 138cdf0e10cSrcweir bOK = true 139cdf0e10cSrcweir nState = oObj.getPropertyState(AllPropsNames(n)) 140cdf0e10cSrcweir bOK = bOK AND (nState = com.sun.star.beans.PropertyState.DIRECT_VALUE OR _ 141cdf0e10cSrcweir nState = com.sun.star.beans.PropertyState.DEFAULT_VALUE OR _ 142cdf0e10cSrcweir nState = com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE) 143cdf0e10cSrcweir 144cdf0e10cSrcweir if (NOT bOK) then 145cdf0e10cSrcweir Out.Log("Error while testing getPropertyState() for '" & AllPropsNames(n) & "' FAILED.") 146cdf0e10cSrcweir else 147cdf0e10cSrcweir Out.Log("getPropertyState() for property '" & AllPropsNames(n) & "' is OK") 148cdf0e10cSrcweir end if 149cdf0e10cSrcweir 150cdf0e10cSrcweir bOK = true 151cdf0e10cSrcweir aValue = oObj.getPropertyDefault(AllPropsNames(n)) 152cdf0e10cSrcweir bTypesEq = false 153cdf0e10cSrcweir if (bOK AND (TypeName(aValue) <> "Empty")) then 154cdf0e10cSrcweir bTypesEq = (oProperties(n).Type.Name = oCoreRefl.getType(aValue).Name) 155cdf0e10cSrcweir end if 156cdf0e10cSrcweir 157cdf0e10cSrcweir if (NOT bOK) then ' exception was occured 158cdf0e10cSrcweir Out.Log("Error while testing getPropertyDefault() for '" & AllPropsNames(n) & "' FAILED.") 159cdf0e10cSrcweir elseif ((TypeName(aValue) <> "Empty") AND (NOT bTypesEq)) then 160cdf0e10cSrcweir Out.Log("Types: '" & oProperties(n).Type.Name & "' and '" & oCoreRefl.getType(aValue).Name & "' are different.") 161cdf0e10cSrcweir else 162cdf0e10cSrcweir Out.Log("getPropertyDefault() for property '" & AllPropsNames(n) & "' is OK") 163cdf0e10cSrcweir end if 164cdf0e10cSrcweir n = n + 1 165cdf0e10cSrcweir wend 166cdf0e10cSrcweir 167cdf0e10cSrcweirExit Sub 168cdf0e10cSrcweirErrHndl: 169cdf0e10cSrcweir Test.Exception() 170cdf0e10cSrcweir bOK = false 171cdf0e10cSrcweir resume next 172cdf0e10cSrcweirEnd Sub 173cdf0e10cSrcweir</script:module> 174