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 .
21 import lib
.MultiMethodTest
;
23 import lib
.StatusException
;
25 import com
.sun
.star
.io
.XActiveDataControl
;
26 import com
.sun
.star
.io
.XStreamListener
;
27 import com
.sun
.star
.lang
.EventObject
;
30 * Testing <code>com.sun.star.io.XActiveDataControl</code>
33 * <li><code> addListener()</code></li>
34 * <li><code> removeListener()</code></li>
35 * <li><code> start()</code></li>
36 * <li><code> terminate()</code></li>
39 * Tests <code>XActiveDataControl</code> interface. First, it registers a listener
40 * and performs <code>start()</code> and <code>terminate()</code> calls. The
41 * events received in the listener are analyzed to verify the result.<p>
43 * @see com.sun.star.io.XActiveDataControl
45 public class _XActiveDataControl
extends MultiMethodTest
{
48 * Contains the object under test.
50 public XActiveDataControl oObj
= null;
53 * Indicates that the <code>XStreamListener.started()</code> method has
56 private boolean startCalled
= false;
59 * Indicates that the <code>XStreamListener.terminated()</code> method has
62 private boolean terminateCalled
= false;
65 * Indicates that the <code>XEventListener.closed()</code> method has
68 private boolean closeCalled
= false;
71 * Indicates that the <code>XStreamListener.error()</code> method has
74 private boolean errorCalled
= false;
77 * Contains the error, if <code>XStreamListener.error(Object error)</code>
83 * Indicates that the <code>XEventListener.disposing()</code> method has
86 private boolean smthngElseCalled
= false;
89 * The listener is used to verify results of the methods.
91 private final TestStreamListener listener
= new TestStreamListener();
94 * XStreamListener implementation. Sets variables
95 * (<cod>estartedCalled</code>, <code>terminatedCalled</code>, etc.) to
96 * <tt>true</tt> if the appropriate method was called (for example, if
97 * <code>started()</code> was called, the <code>startedCalled</code>
100 private class TestStreamListener
implements XStreamListener
{
101 public void started() {
104 public void terminated() {
105 terminateCalled
= true ;
107 public void error(Object e
) {
111 public void closed() {
114 public void disposing(EventObject e
) {
115 smthngElseCalled
= true ;
121 * Tests <code>addListener()</code>. The verification is performed later, in
122 * <code>_terminate()</code> method.
124 public void _addListener() {
125 oObj
.addListener(listener
);
129 * Starts the data activity (e.g. data pump). Verifictation is performed
130 * later, in <code>_terminate()</code> method.
132 public void _start() {
133 executeMethod("addListener()");
137 // waiting a little bit for data transferred
138 util
.utils
.pause(200);
141 } catch (InterruptedException e
) {
142 throw new StatusException(e
, Status
.failed(e
.getMessage()));
147 * Tests <code>removeListener()</code>. Before, it ensures that other
148 * tests are perforemed and that <code>addListener()</code> is okay. Then,
149 * calls <code>XActiveDataControl.start()</code> and checks that no method
150 * of the listener was called.
152 public void _removeListener() {
153 // performing other tests before, so, that don't break them
155 executeMethod("terminate()");
156 } catch (StatusException e
) {
157 // the result doesn't matter
160 // check that addListener() is okay
161 requiredMethod("addListener()");
163 // clearing previous records
165 terminateCalled
= false;
168 smthngElseCalled
= false;
170 // removing the listener
171 oObj
.removeListener(listener
);
173 // starting the activity
176 // wait a little bit to allow for listeners to be called
179 } catch (InterruptedException e
) {
180 throw new StatusException(e
, Status
.failed(e
.getMessage()));
183 // check that no removed listener's method was called
184 tRes
.tested("removeListener()",!startCalled
&&
185 !terminateCalled
&& !errorCalled
&& !smthngElseCalled
) ;
189 * Tests <code>terminate()</code>. First, ensures that <code>start()</code>
190 * has been called. Then, verifies <code>start()</code>,
191 * <code>addListener()</code> and <code>terminate()</code> results, by
192 * checking that the appropriate listener's methods have been called.
194 public void _terminate() {
195 // ensuring that the activity has been started
196 executeMethod("start()");
198 // terminating the activity
201 // waiting a little bit for listeners to be called
204 } catch (InterruptedException e
) {
205 throw new StatusException(e
, Status
.failed(e
.getMessage()));
208 // check, if any error occurred
210 Status
.failed("Unexpected error");
211 log
.println("Unexpected error " + error
);
212 ((Exception
)error
).printStackTrace(log
);
215 // verification of start() method - startedCalled method should be
217 if (!tRes
.tested("start()", startCalled
)) {
218 log
.println("XStreamListener.started() was not called()");
221 // check that any listener method is called
222 tRes
.tested("addListener()", startCalled
||
223 terminateCalled
|| errorCalled
|| smthngElseCalled
);
225 // checking that terminated() has been called or streams were closed
226 // before terminate() call, in this case termination has no sense.
227 tRes
.tested("terminate()", terminateCalled
|| closeCalled
);
231 * Disposes the test environment, since it is used.
234 public void after() {
235 this.disposeEnvironment();