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