1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="accessibility_XAccessibleEventBroadcaster" script:language="StarBasic">
4cdf0e10cSrcweir&apos;*************************************************************************
5cdf0e10cSrcweir&apos;*
6cdf0e10cSrcweir'
7*4c454ea9SAndrew Rist'  Licensed to the Apache Software Foundation (ASF) under one
8*4c454ea9SAndrew Rist'  or more contributor license agreements.  See the NOTICE file
9*4c454ea9SAndrew Rist'  distributed with this work for additional information
10*4c454ea9SAndrew Rist'  regarding copyright ownership.  The ASF licenses this file
11*4c454ea9SAndrew Rist'  to you under the Apache License, Version 2.0 (the
12*4c454ea9SAndrew Rist'  "License"); you may not use this file except in compliance
13*4c454ea9SAndrew Rist'  with the License.  You may obtain a copy of the License at
14*4c454ea9SAndrew Rist'
15*4c454ea9SAndrew Rist'    http://www.apache.org/licenses/LICENSE-2.0
16*4c454ea9SAndrew Rist'
17*4c454ea9SAndrew Rist'  Unless required by applicable law or agreed to in writing,
18*4c454ea9SAndrew Rist'  software distributed under the License is distributed on an
19*4c454ea9SAndrew Rist'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20*4c454ea9SAndrew Rist'  KIND, either express or implied.  See the License for the
21*4c454ea9SAndrew Rist'  specific language governing permissions and limitations
22*4c454ea9SAndrew Rist'  under the License.
23cdf0e10cSrcweir'
24cdf0e10cSrcweir&apos;*************************************************************************
25cdf0e10cSrcweir&apos;*************************************************************************
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir&apos; Be sure that all variables are dimensioned:
30cdf0e10cSrcweiroption explicit
31cdf0e10cSrcweir
32cdf0e10cSrcweir&apos;*************************************************************************
33cdf0e10cSrcweir&apos; This Interface/Service test depends on the following GLOBAL variables,
34cdf0e10cSrcweir&apos; which must be specified in the object creation:
35cdf0e10cSrcweir
36cdf0e10cSrcweir&apos; fireEvent() precedure
37cdf0e10cSrcweir&apos; located in component test
38cdf0e10cSrcweir
39cdf0e10cSrcweir&apos;*************************************************************************
40cdf0e10cSrcweir
41cdf0e10cSrcweir
42cdf0e10cSrcweir
43cdf0e10cSrcweir
44cdf0e10cSrcweir
45cdf0e10cSrcweirDim oListener1 As Object
46cdf0e10cSrcweirDim oListener2 As Object
47cdf0e10cSrcweirDim bL1called As Boolean
48cdf0e10cSrcweirDim bL2called As Boolean
49cdf0e10cSrcweir
50cdf0e10cSrcweir
51cdf0e10cSrcweirSub RunTest()
52cdf0e10cSrcweir
53cdf0e10cSrcweir&apos;*************************************************************************
54cdf0e10cSrcweir&apos; INTERFACE:
55cdf0e10cSrcweir&apos; com.sun.star.accessibility.XAccessibleEventBroadcaster
56cdf0e10cSrcweir&apos;*************************************************************************
57cdf0e10cSrcweirOn Error Goto ErrHndl
58cdf0e10cSrcweir    Dim bOK As Boolean
59cdf0e10cSrcweir    Dim isTransient As Boolean
60cdf0e10cSrcweir    Dim stateSet As Variant
61cdf0e10cSrcweir    bOK = true
62cdf0e10cSrcweir
63cdf0e10cSrcweir    &apos;out.log(&quot;Creating Listeners...&quot;)
64cdf0e10cSrcweir    oListener1 = createUNOListener(&quot;EL1_&quot;,&quot;com.sun.star.accessibility.XAccessibleEventListener&quot;)
65cdf0e10cSrcweir    oListener2 = createUNOListener(&quot;EL2_&quot;,&quot;com.sun.star.accessibility.XAccessibleEventListener&quot;)
66cdf0e10cSrcweir    bOK = bOK AND NOT isNULL(oListener1) AND NOT isNULL(oListener2)
67cdf0e10cSrcweir    if NOT bOK then out.log( &quot;ERROR: Cannot create listeners...&quot;)
68cdf0e10cSrcweir
69cdf0e10cSrcweir    if NOT hasUNOInterfaces(oObj,&quot;com.sun.star.accessibility.XAccessibleContext&quot;) then
70cdf0e10cSrcweir        &apos;out.log(&quot;Object does not implement XAccessibleContext.&quot;)
71cdf0e10cSrcweir        isTransient = false
72cdf0e10cSrcweir    else
73cdf0e10cSrcweir        stateSet = oObj.getAccessibleStateSet()
74cdf0e10cSrcweir        isTransient = stateSet.contains(27)
75cdf0e10cSrcweir    End If
76cdf0e10cSrcweir
77cdf0e10cSrcweir    Test.StartMethod(&quot;addEventListener()&quot;)
78cdf0e10cSrcweir    bOK = true
79cdf0e10cSrcweir    bL1called = false
80cdf0e10cSrcweir    bL2called = false
81cdf0e10cSrcweir    &apos;out.log(&quot;Adding two listeners...&quot;)
82cdf0e10cSrcweir    oObj.com_sun_star_accessibility_XAccessibleEventBroadcaster_addEventListener(oListener1)
83cdf0e10cSrcweir    oObj.com_sun_star_accessibility_XAccessibleEventBroadcaster_addEventListener(oListener2)
84cdf0e10cSrcweir    &apos;out.log(&quot;fire event&quot;)
85cdf0e10cSrcweir    fireEvent()
86cdf0e10cSrcweir    wait(500)
87cdf0e10cSrcweir    out.log(&quot;Listener1 called: &quot;+bL1called)
88cdf0e10cSrcweir    out.log(&quot;Listener2 called: &quot;+bL2called)
89cdf0e10cSrcweir    if NOT isTransient then
90cdf0e10cSrcweir        bOK = bOK AND bL1called AND bL2called
91cdf0e10cSrcweir    else
92cdf0e10cSrcweir        &apos;out.log(&quot;Object is transient, listeners aren&apos;t expected to call.&quot;)
93cdf0e10cSrcweir        bOK = true
94cdf0e10cSrcweir    End If
95cdf0e10cSrcweir    Test.MethodTested(&quot;addEventListener()&quot;,bOK)
96cdf0e10cSrcweir
97cdf0e10cSrcweir
98cdf0e10cSrcweir    Test.StartMethod(&quot;removeEventListener()&quot;)
99cdf0e10cSrcweir    bOK = true
100cdf0e10cSrcweir    bL1called = false
101cdf0e10cSrcweir    bL2called = false
102cdf0e10cSrcweir    &apos;out.log(&quot;Removing one listener...&quot;)
103cdf0e10cSrcweir    oObj.com_sun_star_accessibility_XAccessibleEventBroadcaster_removeEventListener(oListener1)
104cdf0e10cSrcweir    &apos;out.log(&quot;fire event&quot;)
105cdf0e10cSrcweir    fireEvent()
106cdf0e10cSrcweir    wait(500)
107cdf0e10cSrcweir    out.log(&quot;Listener1 called: &quot;+bL1called)
108cdf0e10cSrcweir    out.log(&quot;Listener2 called: &quot;+bL2called)
109cdf0e10cSrcweir    if NOT isTransient then
110cdf0e10cSrcweir        bOK = bOK AND NOT bL1called AND bL2called
111cdf0e10cSrcweir    else
112cdf0e10cSrcweir        &apos;out.log(&quot;Object is transient, listeners aren&apos;t expected to call.&quot;)
113cdf0e10cSrcweir        bOK = true
114cdf0e10cSrcweir    End If
115cdf0e10cSrcweir    Test.MethodTested(&quot;removeEventListener()&quot;,bOK)
116cdf0e10cSrcweir
117cdf0e10cSrcweir    &apos; Removing the second listener...
118cdf0e10cSrcweir    oObj.com_sun_star_accessibility_XAccessibleEventBroadcaster_removeEventListener(oListener2)
119cdf0e10cSrcweir
120cdf0e10cSrcweir
121cdf0e10cSrcweirExit Sub
122cdf0e10cSrcweirErrHndl:
123cdf0e10cSrcweir    Test.Exception()
124cdf0e10cSrcweir    bOK = false
125cdf0e10cSrcweir    resume next
126cdf0e10cSrcweirEnd Sub
127cdf0e10cSrcweir
128cdf0e10cSrcweirSub EL1_notifyEvent(ev As Variant)
129cdf0e10cSrcweir    &apos;out.log(&quot;CallBack for Listener1 notifyEvent was called.&quot;)
130cdf0e10cSrcweir    bL1called = true
131cdf0e10cSrcweirEnd Sub
132cdf0e10cSrcweir
133cdf0e10cSrcweirSub EL1_disposing()
134cdf0e10cSrcweirEnd Sub
135cdf0e10cSrcweir
136cdf0e10cSrcweirSub EL2_notifyEvent(ev As Variant)
137cdf0e10cSrcweir    &apos;out.log(&quot;CallBack for Listener2 notifyEvent was called.&quot;)
138cdf0e10cSrcweir    bL2called = true
139cdf0e10cSrcweirEnd Sub
140cdf0e10cSrcweir
141cdf0e10cSrcweirSub EL2_disposing()
142cdf0e10cSrcweirEnd Sub
143cdf0e10cSrcweir
144*4c454ea9SAndrew Rist</script:module>
145