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="lang_XComponent" script:language="StarBasic">
4
5
6'*************************************************************************
7'
8'  Licensed to the Apache Software Foundation (ASF) under one
9'  or more contributor license agreements.  See the NOTICE file
10'  distributed with this work for additional information
11'  regarding copyright ownership.  The ASF licenses this file
12'  to you under the Apache License, Version 2.0 (the
13'  "License"); you may not use this file except in compliance
14'  with the License.  You may obtain a copy of the License at
15'
16'    http://www.apache.org/licenses/LICENSE-2.0
17'
18'  Unless required by applicable law or agreed to in writing,
19'  software distributed under the License is distributed on an
20'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21'  KIND, either express or implied.  See the License for the
22'  specific language governing permissions and limitations
23'  under the License.
24'
25'*************************************************************************
26
27
28
29'*************************************************************************
30' This Interface/Service test depends on the following GLOBAL variables,
31' which must be specified in the object creation:
32
33'     Global oComponentInstance As Object it will be disposed
34
35'*************************************************************************
36
37
38Dim bCB1 As Boolean, bCB2 As Boolean
39
40' Be sure that all variables are dimensioned:
41option explicit
42
43
44
45Sub RunTest()
46
47'*************************************************************************
48' INTERFACE:
49' com.sun.star.lang.XEventListener
50
51On Error Goto ErrHndl
52    Dim bOK As Boolean
53    Dim oListener1 as Object, oListener2 As Object
54
55    If isNull(oComponentInstance) Then Out.Log("oComponentInstance is not initialized")
56
57    bCB1 = false
58    bCB2 = false
59
60    Out.Log("create two listeners")
61    oListener1 = createUNOListener("CB1_", "com.sun.star.lang.XEventListener")
62    oListener2 = createUNOListener("CB2_", "com.sun.star.lang.XEventListener")
63
64    ' add listeners to object if initialized
65    if NOT(isNull(oListener2)) then
66        oComponentInstance.addEventListener(oListener2)
67    end if
68    if NOT(isNull(oListener1)) then
69        oComponentInstance.addEventListener(oListener1)
70    end if
71
72    Out.Log("remove Listener2")
73    oComponentInstance.removeEventListener(oListener2)
74
75    ' dispose object and check the count
76    Test.StartMethod("dispose()")
77    bOK = true
78    oComponentInstance.dispose()
79    bOK = bCB1 AND NOT bCB2
80    Test.MethodTested("dispose()", bOK)
81
82    ' check if only one eventlistener-callback was executed
83    Test.StartMethod("addEventListener()")
84    bOK = bCB1 AND NOT bCB2
85    Test.MethodTested("addEventListener()", bOK)
86
87    ' check if there was only one of the listener callbacks executed
88    Test.StartMethod("removeEventListener()")
89    bOK = bCB1 AND NOT bCB2
90    Test.MethodTested("removeEventListener()", bOK)
91
92Exit Sub
93ErrHndl:
94    Test.Exception()
95    bOK = false
96    resume next
97End Sub
98Sub CB1_disposing
99    Out.Log("CallBack for Listener1 disposing was called.")
100    bCB1 = true
101End Sub
102Sub CB2_disposing
103    Out.Log("CallBack for Listener2 disposing was called.")
104    bCB2 = true
105End Sub
106
107</script:module>
108