<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="beans_XPropertySet" script:language="StarBasic">


'*************************************************************************
'
'  Licensed to the Apache Software Foundation (ASF) under one
'  or more contributor license agreements.  See the NOTICE file
'  distributed with this work for additional information
'  regarding copyright ownership.  The ASF licenses this file
'  to you under the Apache License, Version 2.0 (the
'  "License"); you may not use this file except in compliance
'  with the License.  You may obtain a copy of the License at
'  
'    http://www.apache.org/licenses/LICENSE-2.0
'  
'  Unless required by applicable law or agreed to in writing,
'  software distributed under the License is distributed on an
'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
'  KIND, either express or implied.  See the License for the
'  specific language governing permissions and limitations
'  under the License.
'
'*************************************************************************





'*************************************************************************
'Change-Listener needs bound-Properties
'Veto-Listener needs constrained-Propperties

'*************************************************************************




Const BOUND = 2
Const CONSTRAINED = 4
Const MAYBENULL = 8
Const READONLY = 16

Dim aBoundProps() As String
Dim aConstrainedProps() As String
Dim aNormalProps() As String
Dim aReadOnlyProps() As String

Dim nBoundCount As Integer
Dim nConstrainedCount As Integer
Dim nNormalCount As Integer
Dim nReadOnlyCount As Integer

Dim aAllProps As Object

Dim vetoCalled1 As Boolean
Dim propCalled1 As Boolean
Dim vetoCalled2 As Boolean
Dim propCalled2 As Boolean


Sub RunTest()

'*************************************************************************
' INTERFACE: 
' com.sun.star.beans.XPropertySet
'*************************************************************************
On Error Goto ErrHndl
If (bErrHndl) Then On Error Goto ErrHndl
    Dim oPCListener1 As Object
    Dim oVListener1 As Object
    Dim oPCListener2 As Object
    Dim oVListener2 As Object
    Dim bOK As boolean

    Test.StartMethod("getPropertySetInfo()")
    bOK = true
    bOK = NOT isNULL(oObj.PropertySetInfo)
    Test.MethodTested("getPropertySetInfo()", bOK)

    Out.Log("Get properties()")
    bOK = GetProps()

    Out.Log("Create Listeners")
    oPCListener1 = createUNOListener("CB1_","com.sun.star.beans.XPropertyChangeListener")
    oVListener1 = createUNOListener("CB1_","com.sun.star.beans.XVetoableChangeListener")
    oPCListener2 = createUNOListener("CB2_","com.sun.star.beans.XPropertyChangeListener")
    oVListener2 = createUNOListener("CB2_","com.sun.star.beans.XVetoableChangeListener")

    Test.StartMethod("getPropertyValue()")
    bOK = true
    bOK = bOK AND test_getPropertyValue()
    Test.MethodTested("getPropertyValue()", bOK)

    Test.StartMethod("setPropertyValue()")
    bOK = true
    Dim bReadOnlyOK As Boolean
    Dim bNormalOK As Boolean
    bReadOnlyOK = false
    bNormalOK = false
    Dim bCVOK As boolean

    if (nReadOnlyCount = 0) then
        bReadOnlyOK = true
        Out.Log("No ReadOnly properties!")
    else
        for i = 0 to nReadOnlyCount - 1
            Out.Log("READONLY: '" &amp; aReadOnlyProps(i) &amp; "'")
            if (aReadOnlyProps(i) = "Preview") then
                bCVOK = true
            else
                bCVOK = PropertyTester.TestPropertyWithoutParams(aReadOnlyProps(i), true)
            end if
            Out.Log(bCVOK)
            Out.Log("")
            bReadOnlyOK = bReadOnlyOK OR bCVOK
        next i
    end if

    bOK = bOK AND bReadOnlyOK

    if (nNormalCount = 0) then
        bNormalOK = true
        Out.Log("No Normal properties!")
    else
        for i = 0 to nNormalCount - 1
            Out.Log("NORMAL: '" &amp; aNormalProps(i) &amp; "'")
            bCVOK = PropertyTester.TestPropertyWithoutParams(aNormalProps(i), false)
            Out.Log(bCVOK)
            Out.Log("")
            bNormalOK = bNormalOK OR bCVOK
        next i
    end if

    bOK = bOK AND bNormalOK

    Test.MethodTested("setPropertyValue()", bOK)

    Test.StartMethod("addVetoableChangeListener()")
    Test.StartMethod("removeVetoableChangeListener()")
    Dim bAddVeto As Boolean
    Dim bRmvVeto As Boolean
    bRmvVeto = true
    bAddVeto = true

    if (nConstrainedCount = 0) then
        Out.Log("No Constrained properties!")
        bAddVeto = true
        bRmvVeto = true
    else
        for i = 0 to nConstrainedCount - 1
            vetoCalled1 = false
            vetoCalled2 = false
            oObj.addVetoableChangeListener(aConstrainedProps(i), oVListener1)
            oObj.addVetoableChangeListener(aConstrainedProps(i), oVListener2)
            PropertyTester.TestPropertyWithoutParams(aConstrainedProps(i), false)
            bAddVeto = bAddVeto OR (vetoCalled1 AND vetoCalled2)
            Out.Log("addVetoableChangeListener: " &amp; aConstrainedProps(i) &amp; " Listener1 must be called: " &amp; vetoCalled1)
            Out.Log("addVetoableChangeListener: " &amp; aConstrainedProps(i) &amp; " Listener2 must be called: " &amp; vetoCalled2)

            vetoCalled1 = false
            vetoCalled2 = false
            oObj.removeVetoableChangeListener(aConstrainedProps(i), oVListener1)
            PropertyTester.TestPropertyWithoutParams(aConstrainedProps(i), false)
            bRmvVeto = bRmvVeto OR (NOT vetoCalled1 AND vetoCalled2)
            Out.Log("removeVetoableChangeListener: " &amp; aConstrainedProps(i) &amp; " Listener1 must not be called: " &amp; NOT vetoCalled1)
            Out.Log("removeVetoableChangeListener: " &amp; aConstrainedProps(i) &amp; " Listener2 must not be called: " &amp; NOT vetoCalled2)
            oObj.removeVetoableChangeListener(aConstrainedProps(i), oVListener2)
        next i
    end if
    Test.MethodTested("addVetoableChangeListener()", bAddVeto)
    Test.MethodTested("removeVetoableChangeListener()", bRmvVeto)

    Test.StartMethod("addPropertyChangeListener()")
    Test.StartMethod("removePropertyChangeListener()")
    Dim bAddProp As Boolean
    Dim bRmvProp As Boolean
    bRmvProp = true
    bAddProp = true

    if (nBoundCount = 0) then
        Out.Log("No Bound properties!")
        bAddProp = true
        bRmvProp = true
    else
        for i = 0 to nBoundCount - 1
            propCalled1 = false
            propCalled2 = false
            oObj.addPropertyChangeListener(aBoundProps(i), oPCListener1)
            oObj.addPropertyChangeListener(aBoundProps(i), oPCListener2)
            PropertyTester.TestPropertyWithoutParams(aBoundProps(i), false)
            bAddProp = bAddProp OR (propCalled1 AND propCalled2)
            Out.Log("addPropertyChangeListener: " &amp; aBoundProps(i) &amp; " Listener1 must be called :" &amp; propCalled1)
            Out.Log("addPropertyChangeListener: " &amp; aBoundProps(i) &amp; " Listener2 must be called :" &amp; propCalled2)

            propCalled1 = false
            propCalled2 = false
            oObj.removePropertyChangeListener(aBoundProps(i), oPCListener1)
            PropertyTester.TestPropertyWithoutParams(aBoundProps(i), false)
            bRmvProp = bRmvProp OR (NOT propCalled1 AND propCalled2)
            Out.Log("removePropertyChangeListener: " &amp; aBoundProps(i) &amp; " Listener must not be called: " &amp; NOT propCalled)
            oObj.removePropertyChangeListener(aBoundProps(i), oPCListener2)
        next i
    end if

    Test.MethodTested("addPropertyChangeListener()", bAddProp)
    Test.MethodTested("removePropertyChangeListener()", bRmvProp)

    ReCreateObj()

Exit Sub
ErrHndl:
    Test.Exception()
    bOK = false
    resume next
End Sub

Function GetProps() As Boolean
On Error Goto ErrHndl
    Dim bOK as Boolean
    Dim i As Integer
    Dim attr As Variant
    bOK = true

    aAllProps = oObj.propertySetInfo.getProperties
    nNormalCount = 0
    nBoundCount = 0
    nConstrainedCount = 0
    nReadOnlyCount = 0

    'first we should find out how many properties of different kinds exists
    for i = lbound(aAllProps) to ubound(aAllProps)
        attr = aAllProps(i).Attributes
        if (attr AND READONLY) OR (attr AND BOUND) OR (attr AND CONSTRAINED) then
            if (attr AND BOUND) then
                nBoundCount = nBoundCount + 1
            end if
            if (attr AND CONSTRAINED) then
                nConstrainedCount = nConstrainedCount + 1
            end if
            if (attr AND READONLY) then
                nReadOnlyCount = nReadOnlyCount + 1
            end if
        else
            if (NOT isNULL(oObj.getPropertyValue(aAllProps(i).Name))) then
                nNormalCount = nNormalCount + 1
            end if
        end if
    next i

    Out.Log("" &amp; nNormalCount &amp; " Normal properties found")
    Out.Log("" &amp; nBoundCount &amp; " Bound properties found")
    Out.Log("" &amp; nConstrainedCount &amp; " Constrained properties found")
    Out.Log("" &amp; nReadOnlyCount &amp; " ReadOnly properties found")

    Dim AN(nNormalCount) As String
    aNormalProps = AN()

    Dim AB(nBoundCount) As String
    aBoundProps = AB()

    Dim AC(nConstrainedCount) As String
    aConstrainedProps = AC()

    Dim AR(nReadOnlyCount) As String
    aReadOnlyProps = AR()

   'Filling up arrays...

    nNormalCount = 0
    nBoundCount = 0
    nConstrainedCount = 0
    nReadOnlyCount = 0
    for i = lbound(aAllProps) to ubound(aAllProps)
        attr = aAllProps(i).Attributes
        if (attr AND READONLY) OR (attr AND BOUND) OR (attr AND CONSTRAINED) then
            if (attr AND BOUND) then
                aBoundProps(nBoundCount) = aAllProps(i).Name
                nBoundCount = nBoundCount + 1
            end if
            if (attr AND CONSTRAINED) then
                aConstrainedProps(nConstrainedCount) = aAllProps(i).Name
                nConstrainedCount = nConstrainedCount + 1
            end if
            if (attr AND READONLY) then
                aReadOnlyProps(nReadOnlyCount) = aAllProps(i).Name
                nReadOnlyCount = nReadOnlyCount + 1
            end if
        else
            if (NOT isNULL(oObj.getPropertyValue(aAllProps(i).Name))) then
                aNormalProps(nNormalCount) = aAllProps(i).Name
                nNormalCount = nNormalCount + 1
            end if
        end if
    next i

    GetProps = bOK
Exit Function
ErrHndl:
    Test.Exception()
    resume next
End Function

Function test_GetPropertyValue() As Boolean
On Error goto ErrHndl

    Dim bOK As Boolean
    Dim i As Integer
    Dim propName As String
    Dim propVal As Variant
    bOK = false

    for i = lbound(aAllProps) to ubound(aAllProps)
        propName = aAllProps(i).Name
        propVal = oObj.getPropertyValue(propName)
        bOK = true
        if (isNULL(propVal)) AND NOT(aAllProps(i).Attributes AND MAYBENULL) then
                Out.Log(cIfcShortName &amp; " " &amp; aAllProps(i).Name &amp; " is NULL, but it is not MAYBENULL")
        end if
    next i

    test_GetPropertyValue() = bOK
Exit Function
ErrHndl:
    Test.Exception()
    bOK = false
    resume next
End Function

Sub CB1_propertyChange
    Out.Log("CallBack 'PropertyChange' for listener 1 was called.")
    propCalled1 = true
    CB1_propertyChange = true
End Sub

Sub CB1_vetoableChange
    Out.Log("CallBack 'vetoableChange' for listener 1 was called.")
    vetoCalled1 = true
End Sub

Sub CB2_propertyChange
    Out.Log("CallBack 'PropertyChange' for listener 2 was called.")
    propCalled2 = true
    CB2_propertyChange = true
End Sub

Sub CB2_vetoableChange
    Out.Log("CallBack 'vetoableChange' for listener 2 was called.")
    vetoCalled2 = true
End Sub
</script:module>
