1*b1cdbd2cSJim Jagielski<?xml version="1.0" encoding="UTF-8"?> 2*b1cdbd2cSJim Jagielski<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3*b1cdbd2cSJim Jagielski<script:module xmlns:script="http://openoffice.org/2000/script" script:name="beans_XMultiPropertyStates" script:language="StarBasic"> 4*b1cdbd2cSJim Jagielski 5*b1cdbd2cSJim Jagielski 6*b1cdbd2cSJim Jagielski'************************************************************************* 7*b1cdbd2cSJim Jagielski' 8*b1cdbd2cSJim Jagielski' Licensed to the Apache Software Foundation (ASF) under one 9*b1cdbd2cSJim Jagielski' or more contributor license agreements. See the NOTICE file 10*b1cdbd2cSJim Jagielski' distributed with this work for additional information 11*b1cdbd2cSJim Jagielski' regarding copyright ownership. The ASF licenses this file 12*b1cdbd2cSJim Jagielski' to you under the Apache License, Version 2.0 (the 13*b1cdbd2cSJim Jagielski' "License"); you may not use this file except in compliance 14*b1cdbd2cSJim Jagielski' with the License. You may obtain a copy of the License at 15*b1cdbd2cSJim Jagielski' 16*b1cdbd2cSJim Jagielski' http://www.apache.org/licenses/LICENSE-2.0 17*b1cdbd2cSJim Jagielski' 18*b1cdbd2cSJim Jagielski' Unless required by applicable law or agreed to in writing, 19*b1cdbd2cSJim Jagielski' software distributed under the License is distributed on an 20*b1cdbd2cSJim Jagielski' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21*b1cdbd2cSJim Jagielski' KIND, either express or implied. See the License for the 22*b1cdbd2cSJim Jagielski' specific language governing permissions and limitations 23*b1cdbd2cSJim Jagielski' under the License. 24*b1cdbd2cSJim Jagielski' 25*b1cdbd2cSJim Jagielski'************************************************************************* 26*b1cdbd2cSJim Jagielski 27*b1cdbd2cSJim Jagielski 28*b1cdbd2cSJim Jagielski 29*b1cdbd2cSJim Jagielski 30*b1cdbd2cSJim Jagielski 31*b1cdbd2cSJim Jagielski' Be sure that all variables are dimensioned: 32*b1cdbd2cSJim Jagielskioption explicit 33*b1cdbd2cSJim Jagielski 34*b1cdbd2cSJim Jagielski 35*b1cdbd2cSJim JagielskiFunction getPropNames(xPropSet As Object) As Variant 36*b1cdbd2cSJim Jagielski Dim props As Variant 37*b1cdbd2cSJim Jagielski Dim propNames As Variant 38*b1cdbd2cSJim Jagielski Dim i As Integer, propCount As Integer 39*b1cdbd2cSJim Jagielski 40*b1cdbd2cSJim Jagielski props = xPropSet.getPropertySetInfo().getProperties() 41*b1cdbd2cSJim Jagielski propCount = 0 42*b1cdbd2cSJim Jagielski for i = 0 to ubound (props) 43*b1cdbd2cSJim Jagielski if (props(i).Attributes AND com.sun.star.beans.PropertyAttribute.READONLY) = 0 _ 44*b1cdbd2cSJim Jagielski then propCount = propCount + 1 45*b1cdbd2cSJim Jagielski next i 46*b1cdbd2cSJim Jagielski 47*b1cdbd2cSJim Jagielski propNames = DimArray(propCount - 1) 48*b1cdbd2cSJim Jagielski aProps = DimArray(propCount - 1) 49*b1cdbd2cSJim Jagielski 50*b1cdbd2cSJim Jagielski propCount = 0 51*b1cdbd2cSJim Jagielski for i = 0 to ubound(props) 52*b1cdbd2cSJim Jagielski if (props(i).Attributes AND com.sun.star.beans.PropertyAttribute.READONLY) = 0 then 53*b1cdbd2cSJim Jagielski propNames(propCount) = props(i).Name 54*b1cdbd2cSJim Jagielski aProps(propCount) = props(i) 55*b1cdbd2cSJim Jagielski propCount = propCount + 1 56*b1cdbd2cSJim Jagielski endif 57*b1cdbd2cSJim Jagielski next i 58*b1cdbd2cSJim Jagielski 59*b1cdbd2cSJim Jagielski getPropNames = propNames 60*b1cdbd2cSJim JagielskiEnd Function 61*b1cdbd2cSJim Jagielski 62*b1cdbd2cSJim JagielskiDim aProps As Variant 63*b1cdbd2cSJim Jagielski 64*b1cdbd2cSJim Jagielski 65*b1cdbd2cSJim JagielskiSub RunTest() 66*b1cdbd2cSJim Jagielski 67*b1cdbd2cSJim Jagielski'************************************************************************* 68*b1cdbd2cSJim Jagielski' INTERFACE: 69*b1cdbd2cSJim Jagielski' com.sun.star.beans.XMultiPropertyStates 70*b1cdbd2cSJim Jagielski'************************************************************************* 71*b1cdbd2cSJim JagielskiOn Error Goto ErrHndl 72*b1cdbd2cSJim Jagielski Dim bOK As Boolean 73*b1cdbd2cSJim Jagielski 74*b1cdbd2cSJim Jagielski Dim aPropNames As Variant 75*b1cdbd2cSJim Jagielski Dim aDefaults As Variant 76*b1cdbd2cSJim Jagielski Dim aStates As Variant 77*b1cdbd2cSJim Jagielski 78*b1cdbd2cSJim Jagielski if NOT hasUnoInterfaces(oObj, "com.sun.star.beans.XPropertySet") then 79*b1cdbd2cSJim Jagielski Out.Log("The compoent doesn't support XPropertySet this test must be reviewed !!!") 80*b1cdbd2cSJim Jagielski exit sub 81*b1cdbd2cSJim Jagielski end if 82*b1cdbd2cSJim Jagielski 83*b1cdbd2cSJim Jagielski bOK = true 84*b1cdbd2cSJim Jagielski aPropNames = getPropNames(oObj) 85*b1cdbd2cSJim Jagielski 86*b1cdbd2cSJim Jagielski if NOT utils.isSorted(aPropNames) then 87*b1cdbd2cSJim Jagielski Out.Log("Property names are not sorted : sorting ...") 88*b1cdbd2cSJim Jagielski utils.bubbleSort(aPropNames, false, aProps) 89*b1cdbd2cSJim Jagielski end if 90*b1cdbd2cSJim Jagielski 91*b1cdbd2cSJim Jagielski Out.Log("Totally " + (ubound(aPropNames) + 1) + " properties encountered.") 92*b1cdbd2cSJim Jagielski 93*b1cdbd2cSJim Jagielski Test.StartMethod("getPropertyDefaults()") 94*b1cdbd2cSJim Jagielski 95*b1cdbd2cSJim Jagielski aDefaults = oObj.getPropertyDefaults(aPropNames) 96*b1cdbd2cSJim Jagielski Out.Log("Number of default values: " + (ubound(aDefaults) + 1)) 97*b1cdbd2cSJim Jagielski bOK = ubound(aDefaults) = ubound(aPropNames) 98*b1cdbd2cSJim Jagielski 99*b1cdbd2cSJim Jagielski Test.MethodTested("getPropertyDefaults()", bOK) 100*b1cdbd2cSJim Jagielski 101*b1cdbd2cSJim Jagielski 102*b1cdbd2cSJim Jagielski Test.StartMethod("getPropertyStates()") 103*b1cdbd2cSJim Jagielski bOK = true 104*b1cdbd2cSJim Jagielski 105*b1cdbd2cSJim Jagielski aStates = oObj.getPropertyStates(aPropNames) 106*b1cdbd2cSJim Jagielski Out.Log("Number of states: " + (ubound(aStates) + 1)) 107*b1cdbd2cSJim Jagielski bOK = ubound(aStates) = ubound(aPropNames) 108*b1cdbd2cSJim Jagielski 109*b1cdbd2cSJim Jagielski Test.MethodTested("getPropertyStates()", bOK) 110*b1cdbd2cSJim Jagielski 111*b1cdbd2cSJim Jagielski Test.StartMethod("setPropertiesToDefault()") 112*b1cdbd2cSJim Jagielski bOK = true 113*b1cdbd2cSJim Jagielski 114*b1cdbd2cSJim Jagielski Dim propName As String 115*b1cdbd2cSJim Jagielski Dim propIdx As Integer 116*b1cdbd2cSJim Jagielski Dim mayBeDef As Boolean 117*b1cdbd2cSJim Jagielski Dim i As Integer 118*b1cdbd2cSJim Jagielski propName = aPropNames(0) 119*b1cdbd2cSJim Jagielski propIdx = 0 120*b1cdbd2cSJim Jagielski mayBeDef = false 121*b1cdbd2cSJim Jagielski 122*b1cdbd2cSJim Jagielski ' searching for property which currently don't have default value and preferable has MAYBEDEFAULT attr 123*b1cdbd2cSJim Jagielski ' if no such properties are found then the first one is selected 124*b1cdbd2cSJim Jagielski for i = 0 to ubound(aPropNames) 125*b1cdbd2cSJim Jagielski if NOT mayBeDef AND aStates(i) <> com.sun.star.beans.PropertyState.DEFAULT_VALUE then 126*b1cdbd2cSJim Jagielski propName = aPropNames(i) 127*b1cdbd2cSJim Jagielski propIdx = i 128*b1cdbd2cSJim Jagielski if (aProps(i).Attributes AND com.sun.star.beans.PropertyAttribute.MAYBEDEFAULT) > 0 then 129*b1cdbd2cSJim Jagielski Out.Log("Property " + propName + " 'may be default' and doesn't have default value") 130*b1cdbd2cSJim Jagielski mayBeDef = true 131*b1cdbd2cSJim Jagielski end if 132*b1cdbd2cSJim Jagielski end if 133*b1cdbd2cSJim Jagielski next i 134*b1cdbd2cSJim Jagielski Out.Log("The property " + propName + " selected") 135*b1cdbd2cSJim Jagielski 136*b1cdbd2cSJim Jagielski oObj.setPropertiesToDefault(Array(propName)) 137*b1cdbd2cSJim Jagielski 138*b1cdbd2cSJim Jagielski aStates = oObj.getPropertyStates(aPropNames) 139*b1cdbd2cSJim Jagielski if aStates(propIdx) <> com.sun.star.beans.PropertyState.DEFAULT_VALUE then 140*b1cdbd2cSJim Jagielski Out.Log("The property didn't change its state to default ...") 141*b1cdbd2cSJim Jagielski if mayBeDef then 142*b1cdbd2cSJim Jagielski Out.Log(" ... and it may be default - FAILED") 143*b1cdbd2cSJim Jagielski bOK = false 144*b1cdbd2cSJim Jagielski else 145*b1cdbd2cSJim Jagielski Out.Log(" ... but it may not be default - OK") 146*b1cdbd2cSJim Jagielski end if 147*b1cdbd2cSJim Jagielski end if 148*b1cdbd2cSJim Jagielski 149*b1cdbd2cSJim Jagielski Test.MethodTested("setPropertiesToDefault()", bOK) 150*b1cdbd2cSJim Jagielski 151*b1cdbd2cSJim Jagielski Test.StartMethod("setAllPropertiesToDefault()") 152*b1cdbd2cSJim Jagielski bOK = true 153*b1cdbd2cSJim Jagielski 154*b1cdbd2cSJim Jagielski oObj.setAllPropertiesToDefault() 155*b1cdbd2cSJim Jagielski 156*b1cdbd2cSJim Jagielski Out.Log("Checking that all properties are now in DEFAULT state excepting may be those which 'cann't be default'") 157*b1cdbd2cSJim Jagielski aStates = oObj.getPropertyStates(aPropNames) 158*b1cdbd2cSJim Jagielski for i = 0 to ubound(aStates) 159*b1cdbd2cSJim Jagielski if aStates(i) <> com.sun.star.beans.PropertyState.DEFAULT_VALUE then 160*b1cdbd2cSJim Jagielski Out.Log("The property " + aPropNames(i) + " didn't change its state to default ...") 161*b1cdbd2cSJim Jagielski if (aProps(i).Attributes AND com.sun.star.beans.PropertyAttribute.MAYBEDEFAULT) > 0 then 162*b1cdbd2cSJim Jagielski Out.Log(" ... and it has MAYBEDEFAULT attribute - FAILED") 163*b1cdbd2cSJim Jagielski bOK = false 164*b1cdbd2cSJim Jagielski else 165*b1cdbd2cSJim Jagielski Out.Log(" ... but it has no MAYBEDEFAULT attribute - OK") 166*b1cdbd2cSJim Jagielski end if 167*b1cdbd2cSJim Jagielski end if 168*b1cdbd2cSJim Jagielski next i 169*b1cdbd2cSJim Jagielski 170*b1cdbd2cSJim Jagielski Test.MethodTested("setAllPropertiesToDefault()", bOK) 171*b1cdbd2cSJim Jagielski 172*b1cdbd2cSJim JagielskiExit Sub 173*b1cdbd2cSJim JagielskiErrHndl: 174*b1cdbd2cSJim Jagielski Test.Exception() 175*b1cdbd2cSJim Jagielski bOK = false 176*b1cdbd2cSJim Jagielski resume next 177*b1cdbd2cSJim JagielskiEnd Sub 178*b1cdbd2cSJim Jagielski</script:module> 179