1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XComponent.java,v $
10 * $Revision: 1.5.8.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import com
.sun
.star
.container
.XNameContainer
;
34 import lib
.MultiMethodTest
;
36 import com
.sun
.star
.frame
.XDesktop
;
37 import com
.sun
.star
.lang
.EventObject
;
38 import com
.sun
.star
.lang
.XComponent
;
39 import com
.sun
.star
.lang
.XEventListener
;
42 * Testing <code>com.sun.star.lang.XComponent</code>
45 * <li><code> dispose()</code></li>
46 * <li><code> addEventListener()</code></li>
47 * <li><code> removeEventListener()</code></li>
49 * After this interface test object <b>must be recreated</b>. <p>
50 * Multithreaded test ability <b>not implemented</b> yet.
51 * @see com.sun.star.lang.XComponent
53 public class _XComponent
extends MultiMethodTest
{
55 public static XComponent oObj
= null;
56 private XNameContainer xContainer
= null;
57 private XComponent altDispose
= null;
59 boolean listenerDisposed
[] = new boolean[2];
60 String
[] Loutput
= new String
[2];
63 * Listener which added but not removed, and its method must be called
64 * on <code>dispose</code> call.
66 public class MyEventListener
implements XEventListener
{
67 public void disposing ( EventObject oEvent
) {
68 Loutput
[0] = Thread
.currentThread() + " is DISPOSING EV1" + this;
69 listenerDisposed
[0] = true;
74 * Listener which added and then removed, and its method must <b>not</b>
75 * be called on <code>dispose</code> call.
77 public class MyEventListener2
implements XEventListener
{
78 public void disposing ( EventObject oEvent
) {
79 Loutput
[0] = Thread
.currentThread() + " is DISPOSING EV2" + this;
80 listenerDisposed
[1] = true;
84 XEventListener listener1
= new MyEventListener();
85 XEventListener listener2
= new MyEventListener2();
88 * For the cfgmgr2.OSetElement tests: dispose the owner element.
90 protected void before() {
91 // do not dispose this component, but parent instead
92 altDispose
= (XComponent
)tEnv
.getObjRelation("XComponent.DisposeThis");
97 * Adds two listeners. <p>
98 * Has OK status if then the first listener will receive an event
99 * on <code>dispose</code> method call.
101 public void _addEventListener() {
103 listenerDisposed
[0] = false;
104 listenerDisposed
[1] = false;
106 oObj
.addEventListener( listener1
);
107 oObj
.addEventListener( listener2
);
110 } // finished _addEventListener()
113 * Removes the second of two added listeners. <p>
114 * Method tests to be completed successfully :
116 * <li> <code>addEventListener</code> : method must add two listeners. </li>
118 * Has OK status if no events will be sent to the second listener on
119 * <code>dispose</code> method call.
121 public void _removeEventListener() {
122 executeMethod("addEventListener()");
123 if (disposed
) return;
124 // the second listener should not be called
125 oObj
.removeEventListener( listener2
);
126 log
.println(Thread
.currentThread() + " is removing EL " + listener2
);
127 } // finished _removeEventListener()
129 static boolean disposed
= false;
132 * Disposes the object and then check appropriate listeners were
134 * Method tests to be completed successfully :
136 * <li> <code>removeEventListener</code> : method must remove one of two
139 * Has OK status if liseter removed wasn't called and other listener
142 public void _dispose() {
144 executeMethod("removeEventListener()");
146 log
.println( "begin dispose in thread " + Thread
.currentThread());
147 XDesktop oDesk
= (XDesktop
) tEnv
.getObjRelation("Desktop");
152 if (altDispose
== null)
155 altDispose
.dispose();
160 } catch (InterruptedException e
) {}
161 if (Loutput
[0]!=null) log
.println(Loutput
[0]);
162 if (Loutput
[1]!=null) log
.println(Loutput
[1]);
163 log
.println( "end dispose" + Thread
.currentThread());
166 // check that dispose() works OK.
167 tRes
.tested("addEventListener()", listenerDisposed
[0]);
168 tRes
.tested("removeEventListener()", !listenerDisposed
[1]);
169 tRes
.tested("dispose()", listenerDisposed
[0] && !listenerDisposed
[1]);
171 } // finished _dispose()
174 * Forces object recreation.
176 protected void after() {
177 disposeEnvironment();
180 } // finished class _XComponent