Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / lang / _XComponent.java
blobe7493e3771418c489db5f44566cd2fdd0dcf8c8a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package ifc.lang;
30 import com.sun.star.container.XNameContainer;
31 import lib.MultiMethodTest;
33 import com.sun.star.frame.XDesktop;
34 import com.sun.star.lang.EventObject;
35 import com.sun.star.lang.XComponent;
36 import com.sun.star.lang.XEventListener;
38 /**
39 * Testing <code>com.sun.star.lang.XComponent</code>
40 * interface methods :
41 * <ul>
42 * <li><code> dispose()</code></li>
43 * <li><code> addEventListener()</code></li>
44 * <li><code> removeEventListener()</code></li>
45 * </ul>
46 * After this interface test object <b>must be recreated</b>. <p>
47 * Multithreaded test ability <b>not implemented</b> yet.
48 * @see com.sun.star.lang.XComponent
50 public class _XComponent extends MultiMethodTest {
52 public static XComponent oObj = null;
53 private XNameContainer xContainer = null;
54 private XComponent altDispose = null;
56 boolean listenerDisposed[] = new boolean[2];
57 String[] Loutput = new String[2];
59 /**
60 * Listener which added but not removed, and its method must be called
61 * on <code>dispose</code> call.
63 public class MyEventListener implements XEventListener {
64 public void disposing ( EventObject oEvent ) {
65 Loutput[0] = Thread.currentThread() + " is DISPOSING EV1" + this;
66 listenerDisposed[0] = true;
70 /**
71 * Listener which added and then removed, and its method must <b>not</b>
72 * be called on <code>dispose</code> call.
74 public class MyEventListener2 implements XEventListener {
75 public void disposing ( EventObject oEvent ) {
76 Loutput[0] = Thread.currentThread() + " is DISPOSING EV2" + this;
77 listenerDisposed[1] = true;
81 XEventListener listener1 = new MyEventListener();
82 XEventListener listener2 = new MyEventListener2();
84 /**
85 * For the (no longer existing) cfgmgr2.OSetElement tests: dispose the owner
86 * element. TODO: Is this needed for anything else, too, or should it be
87 * removed?
89 protected void before() {
90 // do not dispose this component, but parent instead
91 altDispose = (XComponent)tEnv.getObjRelation("XComponent.DisposeThis");
95 /**
96 * Adds two listeners. <p>
97 * Has OK status if then the first listener will receive an event
98 * on <code>dispose</code> method call.
100 public void _addEventListener() {
102 listenerDisposed[0] = false;
103 listenerDisposed[1] = false;
105 oObj.addEventListener( listener1 );
106 oObj.addEventListener( listener2 );
108 return;
109 } // finished _addEventListener()
112 * Removes the second of two added listeners. <p>
113 * Method tests to be completed successfully :
114 * <ul>
115 * <li> <code>addEventListener</code> : method must add two listeners. </li>
116 * </ul> <p>
117 * Has OK status if no events will be sent to the second listener on
118 * <code>dispose</code> method call.
120 public void _removeEventListener() {
121 executeMethod("addEventListener()");
122 if (disposed) return;
123 // the second listener should not be called
124 oObj.removeEventListener( listener2 );
125 log.println(Thread.currentThread() + " is removing EL " + listener2);
126 } // finished _removeEventListener()
128 static boolean disposed = false;
131 * Disposes the object and then check appropriate listeners were
132 * called or not. <p>
133 * Method tests to be completed successfully :
134 * <ul>
135 * <li> <code>removeEventListener</code> : method must remove one of two
136 * listeners. </li>
137 * </ul> <p>
138 * Has OK status if liseter removed wasn't called and other listener
139 * was.
141 public void _dispose() {
142 disposed = false;
143 executeMethod("removeEventListener()");
145 log.println( "begin dispose in thread " + Thread.currentThread());
146 XDesktop oDesk = (XDesktop) tEnv.getObjRelation("Desktop");
147 if (oDesk !=null) {
148 oDesk.terminate();
150 else {
151 if (altDispose == null)
152 oObj.dispose();
153 else
154 altDispose.dispose();
157 try {
158 Thread.sleep(500) ;
159 } catch (InterruptedException e) {}
160 if (Loutput[0]!=null) log.println(Loutput[0]);
161 if (Loutput[1]!=null) log.println(Loutput[1]);
162 log.println( "end dispose" + Thread.currentThread());
163 disposed = true;
165 // check that dispose() works OK.
166 tRes.tested("addEventListener()", listenerDisposed[0]);
167 tRes.tested("removeEventListener()", !listenerDisposed[1]);
168 tRes.tested("dispose()", listenerDisposed[0] && !listenerDisposed[1]);
170 } // finished _dispose()
173 * Forces object recreation.
175 protected void after() {
176 disposeEnvironment();
179 } // finished class _XComponent