merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / lang / _XComponent.java
blob053baaf269525ff9aa1fe33db8c2b135d1847267
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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 ************************************************************************/
31 package ifc.lang;
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;
41 /**
42 * Testing <code>com.sun.star.lang.XComponent</code>
43 * interface methods :
44 * <ul>
45 * <li><code> dispose()</code></li>
46 * <li><code> addEventListener()</code></li>
47 * <li><code> removeEventListener()</code></li>
48 * </ul>
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];
62 /**
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;
73 /**
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();
87 /**
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");
96 /**
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 );
109 return;
110 } // finished _addEventListener()
113 * Removes the second of two added listeners. <p>
114 * Method tests to be completed successfully :
115 * <ul>
116 * <li> <code>addEventListener</code> : method must add two listeners. </li>
117 * </ul> <p>
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
133 * called or not. <p>
134 * Method tests to be completed successfully :
135 * <ul>
136 * <li> <code>removeEventListener</code> : method must remove one of two
137 * listeners. </li>
138 * </ul> <p>
139 * Has OK status if liseter removed wasn't called and other listener
140 * was.
142 public void _dispose() {
143 disposed = false;
144 executeMethod("removeEventListener()");
146 log.println( "begin dispose in thread " + Thread.currentThread());
147 XDesktop oDesk = (XDesktop) tEnv.getObjRelation("Desktop");
148 if (oDesk !=null) {
149 oDesk.terminate();
151 else {
152 if (altDispose == null)
153 oObj.dispose();
154 else
155 altDispose.dispose();
158 try {
159 Thread.sleep(500) ;
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());
164 disposed = true;
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