2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiMethodTest
;
23 import com
.sun
.star
.frame
.XDesktop
;
24 import com
.sun
.star
.lang
.EventObject
;
25 import com
.sun
.star
.lang
.XComponent
;
26 import com
.sun
.star
.lang
.XEventListener
;
29 * Testing <code>com.sun.star.lang.XComponent</code>
32 * <li><code> dispose()</code></li>
33 * <li><code> addEventListener()</code></li>
34 * <li><code> removeEventListener()</code></li>
36 * After this interface test object <b>must be recreated</b>. <p>
37 * Multithreaded test ability <b>not implemented</b> yet.
38 * @see com.sun.star.lang.XComponent
40 public class _XComponent
extends MultiMethodTest
{
42 public static XComponent oObj
= null;
43 private XComponent altDispose
= null;
45 boolean listenerDisposed
[] = new boolean[2];
46 String
[] Loutput
= new String
[2];
49 * Listener which added but not removed, and its method must be called
50 * on <code>dispose</code> call.
52 public class MyEventListener
implements XEventListener
{
53 public void disposing ( EventObject oEvent
) {
54 Loutput
[0] = Thread
.currentThread() + " is DISPOSING EV1" + this;
55 listenerDisposed
[0] = true;
60 * Listener which added and then removed, and its method must <b>not</b>
61 * be called on <code>dispose</code> call.
63 public class MyEventListener2
implements XEventListener
{
64 public void disposing ( EventObject oEvent
) {
65 Loutput
[0] = Thread
.currentThread() + " is DISPOSING EV2" + this;
66 listenerDisposed
[1] = true;
70 XEventListener listener1
= new MyEventListener();
71 XEventListener listener2
= new MyEventListener2();
74 * For the (no longer existing) cfgmgr2.OSetElement tests: dispose the owner
75 * element. TODO: Is this needed for anything else, too, or should it be
79 protected void before() {
80 // do not dispose this component, but parent instead
81 altDispose
= (XComponent
)tEnv
.getObjRelation("XComponent.DisposeThis");
86 * Adds two listeners. <p>
87 * Has OK status if then the first listener will receive an event
88 * on <code>dispose</code> method call.
90 public void _addEventListener() {
92 listenerDisposed
[0] = false;
93 listenerDisposed
[1] = false;
95 oObj
.addEventListener( listener1
);
96 oObj
.addEventListener( listener2
);
97 } // finished _addEventListener()
100 * Removes the second of two added listeners. <p>
101 * Method tests to be completed successfully :
103 * <li> <code>addEventListener</code> : method must add two listeners. </li>
105 * Has OK status if no events will be sent to the second listener on
106 * <code>dispose</code> method call.
108 public void _removeEventListener() {
109 executeMethod("addEventListener()");
110 if (disposed
) return;
111 // the second listener should not be called
112 oObj
.removeEventListener( listener2
);
113 log
.println(Thread
.currentThread() + " is removing EL " + listener2
);
114 } // finished _removeEventListener()
116 boolean disposed
= false;
119 * Disposes the object and then check appropriate listeners were
121 * Method tests to be completed successfully :
123 * <li> <code>removeEventListener</code> : method must remove one of two
126 * Has OK status if liseter removed wasn't called and other listener
129 public void _dispose() {
131 executeMethod("removeEventListener()");
133 log
.println( "begin dispose in thread " + Thread
.currentThread());
134 XDesktop oDesk
= (XDesktop
) tEnv
.getObjRelation("Desktop");
139 if (altDispose
== null)
142 altDispose
.dispose();
145 util
.utils
.shortWait();
146 if (Loutput
[0]!=null) log
.println(Loutput
[0]);
147 if (Loutput
[1]!=null) log
.println(Loutput
[1]);
148 log
.println( "end dispose" + Thread
.currentThread());
151 // check that dispose() works OK.
152 tRes
.tested("addEventListener()", listenerDisposed
[0]);
153 tRes
.tested("removeEventListener()", !listenerDisposed
[1]);
154 tRes
.tested("dispose()", listenerDisposed
[0] && !listenerDisposed
[1]);
156 } // finished _dispose()
159 * Forces object recreation.
162 protected void after() {
163 disposeEnvironment();
166 } // finished class _XComponent