bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / io / _XActiveDataControl.java
bloba13145edf334c34532c2cc964bf8aab8a05e2783
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 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 try {
139 Thread.sleep(200);
140 } catch (InterruptedException e) {
141 e.printStackTrace(log) ;
142 throw new StatusException(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 e.printStackTrace(log) ;
181 throw new StatusException(Status.failed(e.getMessage()));
184 // check that no removed listener's method was called
185 tRes.tested("removeListener()",!startCalled &&
186 !terminateCalled && !errorCalled && !smthngElseCalled) ;
190 * Tests <code>terminate()</code>. First, ensures that <code>start()</code>
191 * has been called. Then, verifies <code>start()</code>,
192 * <code>addListener()</code> and <code>terminate()</code> results, by
193 * checking that the appropriate listener's methods have been called.
195 public void _terminate() {
196 // ensuring that the activity has been started
197 executeMethod("start()");
199 // terminating the activity
200 oObj.terminate();
202 // waiting a little bit for listeners to be called
203 try {
204 Thread.sleep(200);
205 } catch (InterruptedException e) {
206 e.printStackTrace(log) ;
207 throw new StatusException(Status.failed(e.getMessage()));
210 // check, if any error occurred
211 if (errorCalled) {
212 Status.failed("Unexpected error");
213 log.println("Unexpected error " + error);
214 ((Exception)error).printStackTrace(log);
217 // verification of start() method - startedCalled method should be
218 // called
219 if (!tRes.tested("start()", startCalled)) {
220 log.println("XStreamListener.started() was not called()");
223 // check that any listener method is called
224 tRes.tested("addListener()", startCalled ||
225 terminateCalled || errorCalled || smthngElseCalled);
227 // checking that terminated() has been called or streams were closed
228 // before terminate() call, in this case termination has no sense.
229 tRes.tested("terminate()", terminateCalled || closeCalled);
233 * Disposes the test environment, since it is used.
235 public void after() {
236 this.disposeEnvironment();