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' 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' This Interface/Service test depends on the following GLOBAL variables,
37' which must be specified in the object creation:
38
39'     Global oComponentInstance As Object it will be disposed
40
41'*************************************************************************
42
43
44Dim bCB1 As Boolean, bCB2 As Boolean
45
46' Be sure that all variables are dimensioned:
47option explicit
48
49
50
51Sub RunTest()
52
53'*************************************************************************
54' INTERFACE:
55' com.sun.star.lang.XEventListener
56
57On Error Goto ErrHndl
58    Dim bOK As Boolean
59    Dim oListener1 as Object, oListener2 As Object
60
61    If isNull(oComponentInstance) Then Out.Log("oComponentInstance is not initialized")
62
63    bCB1 = false
64    bCB2 = false
65
66    Out.Log("create two listeners")
67    oListener1 = createUNOListener("CB1_", "com.sun.star.lang.XEventListener")
68    oListener2 = createUNOListener("CB2_", "com.sun.star.lang.XEventListener")
69
70    ' add listeners to object if initialized
71    if NOT(isNull(oListener2)) then
72        oComponentInstance.addEventListener(oListener2)
73    end if
74    if NOT(isNull(oListener1)) then
75        oComponentInstance.addEventListener(oListener1)
76    end if
77
78    Out.Log("remove Listener2")
79    oComponentInstance.removeEventListener(oListener2)
80
81    ' dispose object and check the count
82    Test.StartMethod("dispose()")
83    bOK = true
84    oComponentInstance.dispose()
85    bOK = bCB1 AND NOT bCB2
86    Test.MethodTested("dispose()", bOK)
87
88    ' check if only one eventlistener-callback was executed
89    Test.StartMethod("addEventListener()")
90    bOK = bCB1 AND NOT bCB2
91    Test.MethodTested("addEventListener()", bOK)
92
93    ' check if there was only one of the listener callbacks executed
94    Test.StartMethod("removeEventListener()")
95    bOK = bCB1 AND NOT bCB2
96    Test.MethodTested("removeEventListener()", bOK)
97
98Exit Sub
99ErrHndl:
100    Test.Exception()
101    bOK = false
102    resume next
103End Sub
104Sub CB1_disposing
105    Out.Log("CallBack for Listener1 disposing was called.")
106    bCB1 = true
107End Sub
108Sub CB2_disposing
109    Out.Log("CallBack for Listener2 disposing was called.")
110    bCB2 = true
111End Sub
112
113</script:module>
114