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