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' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9'
10' Copyright 2000, 2010 Oracle and/or its affiliates.
11'
12' OpenOffice.org - a multi-platform office productivity suite
13'
14' This file is part of OpenOffice.org.
15'
16' OpenOffice.org is free software: you can redistribute it and/or modify
17' it under the terms of the GNU Lesser General Public License version 3
18' only, as published by the Free Software Foundation.
19'
20' OpenOffice.org is distributed in the hope that it will be useful,
21' but WITHOUT ANY WARRANTY; without even the implied warranty of
22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23' GNU Lesser General Public License version 3 for more details
24' (a copy is included in the LICENSE file that accompanied this code).
25'
26' You should have received a copy of the GNU Lesser General Public License
27' version 3 along with OpenOffice.org.  If not, see
28' <http://www.openoffice.org/license.html>
29' for a copy of the LGPLv3 License.
30'
31'*************************************************************************
32'*************************************************************************
33
34
35
36
37Const BOUND = 2
38Const CONSTRAINED = 4
39Const MAYBENULL = 8
40Const READONLY = 16
41
42
43Sub RunTest()
44
45'*************************************************************************
46' INTERFACE:
47' com.sun.star.beans.XPropertyState
48'*************************************************************************
49On Error Goto ErrHndl
50    Dim bOK As Boolean
51
52    Dim oProperties As Variant
53    Dim nAllProps As Integer
54    Dim aValue As Variant
55    Dim n As Integer
56    Dim oCoreRefl As Object
57    Dim bTypesEq As Boolean
58
59    bOK = true
60
61    oCoreRefl = createUnoService("com.sun.star.reflection.CoreReflection")
62
63    oProperties = oObj.GetPropertySetInfo().Properties
64    nAllProps = uBound(oProperties)
65    Dim AllPropsNames(nAllProps) As String
66    Out.Log("Found " &amp; nAllProps &amp; " properties.")
67
68    for n = 0 to (nAllProps)
69        AllPropsNames(n) = oProperties(n).Name
70    next n
71
72    Test.StartMethod("getPropertyStates()")
73    Out.Log("getting states for all properties.")
74    bOK = true
75
76    Dim aStates As Variant
77
78    aStates() = oObj.getPropertyStates(AllPropsNames())
79    bOK = bOK AND isArray(aStates())
80    if (bOK) then Out.Log("Length of returned array is " &amp; ubound(aStates()))
81    bOK = bOK AND ubound(aStates()) = nAllProps
82
83    Dim nState As Integer
84    nState = aStates(nAllProps / 2)
85    bOK = bOK AND (nState = com.sun.star.beans.PropertyState.DIRECT_VALUE OR _
86                   nState = com.sun.star.beans.PropertyState.DEFAULT_VALUE OR _
87                   nState = com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE)
88    Test.MethodTested("getPropertyStates()", bOK)
89
90    Test.StartMethod("getPropertyState()")
91    bOK = false
92    n = 0
93
94    ' Here testing getPropertyState method. Method is OK when at least one
95    ' property works correctly.
96
97    while (bOK = false AND n &lt; nAllProps)
98        bOK = true
99        nState = oObj.getPropertyState(AllPropsNames(n))
100        bOK = bOK AND (nState = com.sun.star.beans.PropertyState.DIRECT_VALUE OR _
101                       nState = com.sun.star.beans.PropertyState.DEFAULT_VALUE OR _
102                       nState = com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE)
103        n = n + 1
104    wend
105    Test.MethodTested("getPropertyState()", bOK)
106
107    Test.StartMethod("getPropertyDefault()")
108    bOK = false
109    n = 0
110
111    ' Here testing getPropertyDefault method. Method is OK when at least one
112    ' property works correctly.
113
114    while (bOK = false AND n &lt; nAllProps)
115        bOK = true
116        aValue = oObj.getPropertyDefault(AllPropsNames(n))
117        bOK = bOK AND (oProperties(n).Type.Name = oCoreRefl.getType(aValue).Name)
118        n = n + 1
119    wend
120    Test.MethodTested("getPropertyDefault()", bOK)
121
122    Test.StartMethod("setPropertyToDefault()")
123    bOK = false
124    n = 0
125
126    ' Here testing setPropertyToDefault method. Method is OK when at least one
127    ' property works correctly.
128
129    while (bOK = false AND n &lt; nAllProps)
130        bOK = true
131        oObj.setPropertyToDefault(AllPropsNames(n))
132        n = n + 1
133    wend
134    Test.MethodTested("setPropertyToDefault()", bOK)
135
136
137    ' Here testing getPropertyState for ALL properties. This will
138    ' put all exceptions to .log file (if this method doesn't work with some properties)
139    ' but without any affect to test status.
140
141    n = 0
142    while (n &lt; nAllProps)
143        bOK = true
144        nState = oObj.getPropertyState(AllPropsNames(n))
145        bOK = bOK AND (nState = com.sun.star.beans.PropertyState.DIRECT_VALUE OR _
146                       nState = com.sun.star.beans.PropertyState.DEFAULT_VALUE OR _
147                       nState = com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE)
148
149        if (NOT bOK) then
150            Out.Log("Error while testing getPropertyState() for '" &amp; AllPropsNames(n) &amp; "' FAILED.")
151        else
152            Out.Log("getPropertyState() for property '" &amp; AllPropsNames(n) &amp; "' is OK")
153        end if
154
155        bOK = true
156        aValue = oObj.getPropertyDefault(AllPropsNames(n))
157        bTypesEq = false
158        if (bOK AND (TypeName(aValue) &lt;&gt; "Empty")) then
159            bTypesEq = (oProperties(n).Type.Name = oCoreRefl.getType(aValue).Name)
160        end if
161
162        if (NOT bOK) then ' exception was occured
163            Out.Log("Error while testing getPropertyDefault() for '" &amp; AllPropsNames(n) &amp; "' FAILED.")
164        elseif ((TypeName(aValue) &lt;&gt; "Empty") AND (NOT bTypesEq)) then
165            Out.Log("Types: '" &amp; oProperties(n).Type.Name &amp; "' and '" &amp; oCoreRefl.getType(aValue).Name &amp; "' are different.")
166        else
167            Out.Log("getPropertyDefault() for property '" &amp; AllPropsNames(n) &amp; "' is OK")
168        end if
169        n = n + 1
170    wend
171
172Exit Sub
173ErrHndl:
174    Test.Exception()
175    bOK = false
176    resume next
177End Sub
178</script:module>
179