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: _XActiveDataControl.java,v $
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 lib
.MultiMethodTest
;
35 import lib
.StatusException
;
37 import com
.sun
.star
.io
.XActiveDataControl
;
38 import com
.sun
.star
.io
.XStreamListener
;
39 import com
.sun
.star
.lang
.EventObject
;
42 * Testing <code>com.sun.star.io.XActiveDataControl</code>
45 * <li><code> addListener()</code></li>
46 * <li><code> removeListener()</code></li>
47 * <li><code> start()</code></li>
48 * <li><code> terminate()</code></li>
51 * Tests <code>XActiveDataControl</code> interface. First, it registers a listener
52 * and performs <code>start()</code> and <code>terminate()</code> calls. The
53 * events received in the listener are analyzed to verify the result.<p>
55 * @see com.sun.star.io.XActiveDataControl
57 public class _XActiveDataControl
extends MultiMethodTest
{
60 * Contains the object under test.
62 public XActiveDataControl oObj
= null;
65 * Indicates that the <code>XStreamListener.started()</code> method has
68 private boolean startCalled
= false;
71 * Indicates that the <code>XStreamListener.terminated()</code> method has
74 private boolean terminateCalled
= false;
77 * Indicates that the <code>XEventListener.closed()</code> method has
80 private boolean closeCalled
= false;
83 * Indicates that the <code>XStreamListener.error()</code> method has
86 private boolean errorCalled
= false;
89 * Contains the error, if <code>XStreamListener.error(Object error)</code>
95 * Indicates that the <code>XEventListener.disposing()</code> method has
98 private boolean smthngElseCalled
= false;
101 * The listener is used to verify results of the methods.
103 private TestStreamListener listener
= new TestStreamListener();
106 * XStreamListener implementation. Sets variables
107 * (<cod>estartedCalled</code>, <code>terminatedCalled</code>, etc.) to
108 * <tt>true</tt> if the appropriate method was called (for example, if
109 * <code>started()</code> was called, the <code>startedCalled</code>
112 private class TestStreamListener
implements XStreamListener
{
113 public void started() {
116 public void terminated() {
117 terminateCalled
= true ;
119 public void error(Object e
) {
123 public void closed() {
126 public void disposing(EventObject e
) {
127 smthngElseCalled
= true ;
133 * Tests <code>addListener()</code>. The verification is performed later, in
134 * <code>_terminate()</code> method.
136 public void _addListener() {
137 oObj
.addListener(listener
);
141 * Starts the data activity (e.g. data pump). Verifictation is performed
142 * later, in <code>_terminate()</code> method.
144 public void _start() {
145 executeMethod("addListener()");
149 // waiting a little bit for data transfered
152 } catch (InterruptedException e
) {
153 e
.printStackTrace(log
) ;
154 throw new StatusException(Status
.failed(e
.getMessage()));
159 * Tests <code>removeListener()</code>. Before, it ensures that other
160 * tests are perforemed and that <code>addListener()</code> is okay. Then,
161 * calls <code>XActiveDataControl.start()</code> and checks that no method
162 * of the listener was called.
164 public void _removeListener() {
165 // performing other tests before, so, that don't break them
167 executeMethod("terminate()");
168 } catch (StatusException e
) {
169 // the result doesn't matter
172 // check that addListener() is okay
173 requiredMethod("addListener()");
175 // clearing previous records
177 terminateCalled
= false;
180 smthngElseCalled
= false;
182 // removing the listener
183 oObj
.removeListener(listener
);
185 // starting the activity
188 // wait a little bit to allow for listeners to be called
191 } catch (InterruptedException e
) {
192 e
.printStackTrace(log
) ;
193 throw new StatusException(Status
.failed(e
.getMessage()));
196 // check that no removed listener's method was called
197 tRes
.tested("removeListener()",!startCalled
&&
198 !terminateCalled
&& !errorCalled
&& !smthngElseCalled
) ;
202 * Tests <code>terminate()</code>. First, ensures that <code>start()</code>
203 * has been called. Then, verifies <code>start()</code>,
204 * <code>addListener()</code> and <code>terminate()</code> results, by
205 * checking that the appropriate listener's methods have been called.
207 public void _terminate() {
208 // ensuring that the activity has been started
209 executeMethod("start()");
211 // terminating the activity
214 // waiting a little bit for listeners to be called
217 } catch (InterruptedException e
) {
218 e
.printStackTrace(log
) ;
219 throw new StatusException(Status
.failed(e
.getMessage()));
222 // check, if any error occured
224 Status
.failed("Unexpected error");
225 log
.println("Unexpected error " + error
);
226 ((Exception
)error
).printStackTrace(log
);
229 // verification of start() method - startedCalled method should be
231 if (!tRes
.tested("start()", startCalled
)) {
232 log
.println("XStreamListener.started() was not called()");
235 // check that any listener method is called
236 tRes
.tested("addListener()", startCalled
||
237 terminateCalled
|| errorCalled
|| smthngElseCalled
);
239 // checking that terminated() has been called or streams were closed
240 // before terminate() call, in this case termination has no sense.
241 tRes
.tested("terminate()", terminateCalled
|| closeCalled
);
245 * Disposes the test environment, since it is used.
247 public void after() {
248 this.disposeEnvironment();