Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / io / _XActiveDataControl.java
blobffcd3d65c147377281cbbe6986410cd896ceaf74
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.io;
21 import lib.MultiMethodTest;
22 import lib.Status;
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;
29 /**
30 * Testing <code>com.sun.star.io.XActiveDataControl</code>
31 * interface methods :
32 * <ul>
33 * <li><code> addListener()</code></li>
34 * <li><code> removeListener()</code></li>
35 * <li><code> start()</code></li>
36 * <li><code> terminate()</code></li>
37 * </ul> <p>
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 {
47 /**
48 * Contains the object under test.
50 public XActiveDataControl oObj = null;
52 /**
53 * Indicates that the <code>XStreamListener.started()</code> method has
54 * been called.
56 private boolean startCalled = false;
58 /**
59 * Indicates that the <code>XStreamListener.terminated()</code> method has
60 * been called.
62 private boolean terminateCalled = false;
64 /**
65 * Indicates that the <code>XEventListener.closed()</code> method has
66 * been called.
68 private boolean closeCalled = false;
70 /**
71 * Indicates that the <code>XStreamListener.error()</code> method has
72 * been called.
74 private boolean errorCalled = false;
76 /**
77 * Contains the error, if <code>XStreamListener.error(Object error)</code>
78 * method was called.
80 private Object error;
82 /**
83 * Indicates that the <code>XEventListener.disposing()</code> method has
84 * been called.
86 private boolean smthngElseCalled = false;
88 /**
89 * The listener is used to verify results of the methods.
91 private final TestStreamListener listener = new TestStreamListener();
93 /**
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>
98 * field is set).
100 private class TestStreamListener implements XStreamListener {
101 public void started() {
102 startCalled = true ;
104 public void terminated() {
105 terminateCalled = true ;
107 public void error(Object e) {
108 error = e;
109 errorCalled = true ;
111 public void closed() {
112 closeCalled = true ;
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()");
135 oObj.start();
137 // waiting a little bit for data transferred
138 util.utils.pause(200);
139 try {
140 Thread.sleep(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
154 try {
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
164 startCalled = false;
165 terminateCalled = false;
166 errorCalled = false;
167 error = null;
168 smthngElseCalled = false;
170 // removing the listener
171 oObj.removeListener(listener);
173 // starting the activity
174 oObj.start();
176 // wait a little bit to allow for listeners to be called
177 try {
178 Thread.sleep(200);
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
199 oObj.terminate();
201 // waiting a little bit for listeners to be called
202 try {
203 Thread.sleep(200);
204 } catch (InterruptedException e) {
205 throw new StatusException(e, Status.failed(e.getMessage()));
208 // check, if any error occurred
209 if (errorCalled) {
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
216 // called
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.
233 @Override
234 public void after() {
235 this.disposeEnvironment();