merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / io / _XActiveDataControl.java
blob4d6f11448beb4d2f8a8e58a22ef238e08d24b33d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XActiveDataControl.java,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
31 package ifc.io;
33 import lib.MultiMethodTest;
34 import lib.Status;
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;
41 /**
42 * Testing <code>com.sun.star.io.XActiveDataControl</code>
43 * interface methods :
44 * <ul>
45 * <li><code> addListener()</code></li>
46 * <li><code> removeListener()</code></li>
47 * <li><code> start()</code></li>
48 * <li><code> terminate()</code></li>
49 * </ul> <p>
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 {
59 /**
60 * Contains the object under test.
62 public XActiveDataControl oObj = null;
64 /**
65 * Indicates that the <code>XStreamListener.started()</code> method has
66 * been called.
68 private boolean startCalled = false;
70 /**
71 * Indicates that the <code>XStreamListener.terminated()</code> method has
72 * been called.
74 private boolean terminateCalled = false;
76 /**
77 * Indicates that the <code>XEventListener.closed()</code> method has
78 * been called.
80 private boolean closeCalled = false;
82 /**
83 * Indicates that the <code>XStreamListener.error()</code> method has
84 * been called.
86 private boolean errorCalled = false;
88 /**
89 * Contains the error, if <code>XStreamListener.error(Object error)</code>
90 * method was called.
92 private Object error;
94 /**
95 * Indicates that the <code>XEventListener.disposing()</code> method has
96 * been called.
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>
110 * field is set).
112 private class TestStreamListener implements XStreamListener {
113 public void started() {
114 startCalled = true ;
116 public void terminated() {
117 terminateCalled = true ;
119 public void error(Object e) {
120 error = e;
121 errorCalled = true ;
123 public void closed() {
124 closeCalled = true ;
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()");
147 oObj.start();
149 // waiting a little bit for data transfered
150 try {
151 Thread.sleep(200);
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
166 try {
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
176 startCalled = false;
177 terminateCalled = false;
178 errorCalled = false;
179 error = null;
180 smthngElseCalled = false;
182 // removing the listener
183 oObj.removeListener(listener);
185 // starting the activity
186 oObj.start();
188 // wait a little bit to allow for listeners to be called
189 try {
190 Thread.sleep(200);
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
212 oObj.terminate();
214 // waiting a little bit for listeners to be called
215 try {
216 Thread.sleep(200);
217 } catch (InterruptedException e) {
218 e.printStackTrace(log) ;
219 throw new StatusException(Status.failed(e.getMessage()));
222 // check, if any error occured
223 if (errorCalled) {
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
230 // called
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();