bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / lang / _XComponent.java
blob66fe850e5ab05f484b77103e14c72a3039b83d42
1 /*
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 .
19 package ifc.lang;
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;
28 /**
29 * Testing <code>com.sun.star.lang.XComponent</code>
30 * interface methods :
31 * <ul>
32 * <li><code> dispose()</code></li>
33 * <li><code> addEventListener()</code></li>
34 * <li><code> removeEventListener()</code></li>
35 * </ul>
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];
48 /**
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;
59 /**
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();
73 /**
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
76 * removed?
78 protected void before() {
79 // do not dispose this component, but parent instead
80 altDispose = (XComponent)tEnv.getObjRelation("XComponent.DisposeThis");
84 /**
85 * Adds two listeners. <p>
86 * Has OK status if then the first listener will receive an event
87 * on <code>dispose</code> method call.
89 public void _addEventListener() {
91 listenerDisposed[0] = false;
92 listenerDisposed[1] = false;
94 oObj.addEventListener( listener1 );
95 oObj.addEventListener( listener2 );
97 return;
98 } // finished _addEventListener()
101 * Removes the second of two added listeners. <p>
102 * Method tests to be completed successfully :
103 * <ul>
104 * <li> <code>addEventListener</code> : method must add two listeners. </li>
105 * </ul> <p>
106 * Has OK status if no events will be sent to the second listener on
107 * <code>dispose</code> method call.
109 public void _removeEventListener() {
110 executeMethod("addEventListener()");
111 if (disposed) return;
112 // the second listener should not be called
113 oObj.removeEventListener( listener2 );
114 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
121 * called or not. <p>
122 * Method tests to be completed successfully :
123 * <ul>
124 * <li> <code>removeEventListener</code> : method must remove one of two
125 * listeners. </li>
126 * </ul> <p>
127 * Has OK status if liseter removed wasn't called and other listener
128 * was.
130 public void _dispose() {
131 disposed = false;
132 executeMethod("removeEventListener()");
134 log.println( "begin dispose in thread " + Thread.currentThread());
135 XDesktop oDesk = (XDesktop) tEnv.getObjRelation("Desktop");
136 if (oDesk !=null) {
137 oDesk.terminate();
139 else {
140 if (altDispose == null)
141 oObj.dispose();
142 else
143 altDispose.dispose();
146 try {
147 Thread.sleep(500) ;
148 } catch (InterruptedException e) {}
149 if (Loutput[0]!=null) log.println(Loutput[0]);
150 if (Loutput[1]!=null) log.println(Loutput[1]);
151 log.println( "end dispose" + Thread.currentThread());
152 disposed = true;
154 // check that dispose() works OK.
155 tRes.tested("addEventListener()", listenerDisposed[0]);
156 tRes.tested("removeEventListener()", !listenerDisposed[1]);
157 tRes.tested("dispose()", listenerDisposed[0] && !listenerDisposed[1]);
159 } // finished _dispose()
162 * Forces object recreation.
164 protected void after() {
165 disposeEnvironment();
168 } // finished class _XComponent