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 com
.sun
.star
.container
.XNameContainer
;
22 import com
.sun
.star
.lang
.EventObject
;
23 import com
.sun
.star
.lang
.XComponent
;
24 import com
.sun
.star
.lang
.XEventListener
;
25 import share
.LogWriter
;
28 * Testing <code>com.sun.star.lang.XComponent</code>
31 * <li><code> dispose()</code></li>
32 * <li><code> addEventListener()</code></li>
33 * <li><code> removeEventListener()</code></li>
35 * After this interface test object <b>must be recreated</b>. <p>
36 * Multithreaded test ability <b>not implemented</b> yet.
37 * @see com.sun.star.lang.XComponent
39 public class _XComponent
{
41 public static XComponent oObj
= null;
42 private XNameContainer xContainer
= null;
43 private XComponent altDispose
= null;
44 public LogWriter log
= null;
46 boolean listenerDisposed
[] = new boolean[2];
47 String
[] Loutput
= new String
[2];
50 * Listener which added but not removed, and its method must be called
51 * on <code>dispose</code> call.
53 public class MyEventListener
implements XEventListener
{
54 public void disposing ( EventObject oEvent
) {
55 Loutput
[0] = Thread
.currentThread() + " is DISPOSING EV1" + this;
56 listenerDisposed
[0] = true;
61 * Listener which added and then removed, and its method must <b>not</b>
62 * be called on <code>dispose</code> call.
64 public class MyEventListener2
implements XEventListener
{
65 public void disposing ( EventObject oEvent
) {
66 Loutput
[0] = Thread
.currentThread() + " is DISPOSING EV2" + this;
67 listenerDisposed
[1] = true;
71 XEventListener listener1
= new MyEventListener();
72 XEventListener listener2
= new MyEventListener2();
75 * For the cfgmgr2.OSetElement tests: dispose the owner element.
77 protected void before() {
78 // do not dispose this component, but parent instead
79 // altDispose = (XComponent)tEnv.getObjRelation("XComponent.DisposeThis");
84 * Adds two listeners. <p>
85 * Has OK status if then the first listener will receive an event
86 * on <code>dispose</code> method call.
88 public boolean _addEventListener() {
90 listenerDisposed
[0] = false;
91 listenerDisposed
[1] = false;
93 oObj
.addEventListener( listener1
);
94 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 boolean _removeEventListener() {
109 // executeMethod("addEventListener()");
110 if (disposed
) return true;
111 // the second listener should not be called
112 oObj
.removeEventListener( listener2
);
113 log
.println(Thread
.currentThread() + " is removing EL " + listener2
);
115 } // finished _removeEventListener()
117 static boolean disposed
= false;
120 * Disposes the object and then check appropriate listeners were
122 * Method tests to be completed successfully :
124 * <li> <code>removeEventListener</code> : method must remove one of two
127 * Has OK status if liseter removed wasn't called and other listener
130 public boolean _dispose() {
132 // executeMethod("removeEventListener()");
134 log
.println( "begin dispose" + Thread
.currentThread());
139 } catch (InterruptedException e
) {}
140 if (Loutput
[0]!=null) log
.println(Loutput
[0]);
141 if (Loutput
[1]!=null) log
.println(Loutput
[1]);
142 log
.println( "end dispose" + Thread
.currentThread());
145 // check that dispose() works OK.
146 return listenerDisposed
[0] && !listenerDisposed
[1];
148 } // finished _dispose()
151 * Forces object recreation.
153 protected void after() {
154 // disposeEnvironment();
157 } // finished class _XComponent