| 1 |
/* |
| 2 |
* This file is part of the LibreOffice project. |
| 3 |
* |
| 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/. |
| 7 |
* |
| 8 |
* This file incorporates work covered by the following license notice: |
| 9 |
* |
| 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 . |
| 17 |
*/ |
| 18 |
|
| 19 |
package complex.imageManager; |
| 20 |
|
| 21 |
import com.sun.star.frame.XDesktop; |
| 22 |
import com.sun.star.lang.EventObject; |
| 23 |
import com.sun.star.lang.XComponent; |
| 24 |
import com.sun.star.lang.XEventListener; |
| 25 |
import lib.TestParameters; |
| 26 |
|
| 27 |
/** |
| 28 |
* Testing <code>com.sun.star.lang.XComponent</code> |
| 29 |
* interface methods : |
| 30 |
* <ul> |
| 31 |
* <li><code> dispose()</code></li> |
| 32 |
* <li><code> addEventListener()</code></li> |
| 33 |
* <li><code> removeEventListener()</code></li> |
| 34 |
* </ul> |
| 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 |
| 38 |
*/ |
| 39 |
public class _XComponent { |
| 40 |
|
| 41 |
private XComponent oObj = null; |
| 42 |
private XComponent altDispose = null; |
| 43 |
private final TestParameters tEnv; |
| 44 |
private boolean listenerDisposed[] = new boolean[2]; |
| 45 |
private String[] Loutput = new String[2]; |
| 46 |
|
| 47 |
/** |
| 48 |
* Listener which added but not removed, and its method must be called |
| 49 |
* on <code>dispose</code> call. |
| 50 |
*/ |
| 51 |
private class MyEventListener implements XEventListener { |
| 52 |
private final int number; |
| 53 |
private final String message; |
| 54 |
private MyEventListener(int number, String message) { |
| 55 |
this.message = message; |
| 56 |
this.number = number; |
| 57 |
} |
| 58 |
public void disposing ( EventObject oEvent ) { |
| 59 |
Loutput[number] = Thread.currentThread() + " is DISPOSING " + message + this; |
| 60 |
listenerDisposed[number] = true; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
private final XEventListener listener1 = new MyEventListener(0, "EV1"); |
| 65 |
private final XEventListener listener2 = new MyEventListener(1, "EV2"); |
| 66 |
|
| 67 |
public _XComponent(TestParameters tEnv, XComponent oObj) { |
| 68 |
this.tEnv = tEnv; |
| 69 |
this.oObj = oObj; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* For the cfgmgr2.OSetElement tests: dispose the owner element. |
| 74 |
*/ |
| 75 |
public void before() { |
| 76 |
// do not dispose this component, but parent instead |
| 77 |
altDispose = (XComponent)tEnv.get("XComponent.DisposeThis"); |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Adds two listeners. <p> |
| 83 |
* Has OK status if then the first listener will receive an event |
| 84 |
* on <code>dispose</code> method call. |
| 85 |
*/ |
| 86 |
public boolean _addEventListener() { |
| 87 |
|
| 88 |
listenerDisposed[0] = false; |
| 89 |
listenerDisposed[1] = false; |
| 90 |
|
| 91 |
oObj.addEventListener( listener1 ); |
| 92 |
oObj.addEventListener( listener2 ); |
| 93 |
|
| 94 |
return true; |
| 95 |
} // finished _addEventListener() |
| 96 |
|
| 97 |
/** |
| 98 |
* Removes the second of two added listeners. <p> |
| 99 |
* Method tests to be completed successfully : |
| 100 |
* <ul> |
| 101 |
* <li> <code>addEventListener</code> : method must add two listeners. </li> |
| 102 |
* </ul> <p> |
| 103 |
* Has OK status if no events will be sent to the second listener on |
| 104 |
* <code>dispose</code> method call. |
| 105 |
*/ |
| 106 |
public boolean _removeEventListener() { |
| 107 |
if (disposed) |
| 108 |
{ |
| 109 |
System.out.println("Hint: already disposed."); |
| 110 |
return false; |
| 111 |
} |
| 112 |
// the second listener should not be called |
| 113 |
oObj.removeEventListener( listener2 ); |
| 114 |
System.out.println(Thread.currentThread() + " is removing EL " + listener2); |
| 115 |
return true; |
| 116 |
} // finished _removeEventListener() |
| 117 |
|
| 118 |
private boolean disposed = false; |
| 119 |
|
| 120 |
/** |
| 121 |
* Disposes the object and then check appropriate listeners were |
| 122 |
* called or not. <p> |
| 123 |
* Method tests to be completed successfully : |
| 124 |
* <ul> |
| 125 |
* <li> <code>removeEventListener</code> : method must remove one of two |
| 126 |
* listeners. </li> |
| 127 |
* </ul> <p> |
| 128 |
* Has OK status if liseter removed wasn't called and other listener |
| 129 |
* was. |
| 130 |
*/ |
| 131 |
public boolean _dispose() { |
| 132 |
disposed = false; |
| 133 |
|
| 134 |
System.out.println( "begin dispose" + Thread.currentThread()); |
| 135 |
XDesktop oDesk = (XDesktop) tEnv.get("Desktop"); |
| 136 |
if (oDesk !=null) { |
| 137 |
oDesk.terminate(); |
| 138 |
} |
| 139 |
else { |
| 140 |
if (altDispose == null) |
| 141 |
{ |
| 142 |
oObj.dispose(); |
| 143 |
} |
| 144 |
else |
| 145 |
{ |
| 146 |
altDispose.dispose(); |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
util.utils.shortWait(); |
| 151 |
if (Loutput[0]!=null){ |
| 152 |
System.out.println(Loutput[0]); |
| 153 |
} |
| 154 |
if (Loutput[1]!=null) { |
| 155 |
System.out.println(Loutput[1]); |
| 156 |
} |
| 157 |
System.out.println( "end dispose" + Thread.currentThread()); |
| 158 |
disposed = true; |
| 159 |
|
| 160 |
// check that dispose() works OK. |
| 161 |
return listenerDisposed[0] && !listenerDisposed[1]; |
| 162 |
|
| 163 |
} // finished _dispose() |
| 164 |
|
| 165 |
} // finished class _XComponent |
| 166 |
|
| 167 |
|