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