bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / io / _XDataInputStream.java
blob2671b4baf620aa08e232767635570c5c92520d0b
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 java.util.List;
23 import lib.MultiMethodTest;
24 import lib.Status;
25 import lib.StatusException;
27 import com.sun.star.io.XDataInputStream;
28 import com.sun.star.io.XDataOutputStream;
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.uno.XInterface;
32 /**
33 * Testing <code>com.sun.star.io.XDataInputStream</code>
34 * interface methods:
35 * <ul>
36 * <li><code>readBoolean()</code></li>
37 * <li><code>readByte()</code></li>
38 * <li><code>readChar()</code></li>
39 * <li><code>readShort()</code></li>
40 * <li><code>readLong()</code></li>
41 * <li><code>readHyper()</code></li>
42 * <li><code>readFloat()</code></li>
43 * <li><code>readDouble()</code></li>
44 * <li><code>readUTF()</code></li>
45 * </ul> <p>
46 * This test needs the following object relations :
47 * <ul>
48 * <li> <code>'StreamData'</code> (of type <code>Vector</code>):
49 * vector of data for comparing with data that obtained from stream </li>
50 * <li> <code>'StreamWriter'</code> (of type <code>XDataOutputStream</code>):
51 * a possiblitiy to write values to the stream. </li>
52 * <ul> <p>
53 * After test completion object environment has to be recreated.
54 * @see com.sun.star.io.XDataInputStream
55 * @see java.util.Vector
57 public class _XDataInputStream extends MultiMethodTest {
59 public XDataInputStream oObj = null;
60 public XDataOutputStream oStream = null;
62 // values that are written
63 private boolean writeBoolean;
64 private byte writeByte;
65 private char writeChar;
66 private double writeDouble;
67 private float writeFloat;
68 private long writeHyper;
69 private int writeLong;
70 private short writeShort;
71 private String writeUTF;
74 /**
75 * Retrieves relations. From relation 'StreamData' extracts
76 * data of different types and fills the appropriate variables.
77 * @throws StatusException If one of relations not found.
79 public void before(){
81 XInterface x = (XInterface)tEnv.getObjRelation("StreamWriter") ;
82 oStream = UnoRuntime.queryInterface(
83 XDataOutputStream.class, x);
84 List<Object> data = (List<Object>) tEnv.getObjRelation("StreamData") ;
85 if (data == null || oStream == null) {
86 throw new StatusException(Status.failed("Object relation not found."));
89 // extract data from vector
90 Object dataElem = null ;
91 for (int i = 0; i < data.size(); i++) {
92 dataElem = data.get(i) ;
94 if (dataElem instanceof Boolean) {
95 writeBoolean = ((Boolean)dataElem).booleanValue();
96 } else
97 if (dataElem instanceof Byte) {
98 writeByte = ((Byte)dataElem).byteValue();
99 } else
100 if (dataElem instanceof Character) {
101 writeChar = ((Character)dataElem).charValue();
102 } else
103 if (dataElem instanceof Short) {
104 writeShort = ((Short)dataElem).shortValue();
105 } else
106 if (dataElem instanceof Integer) {
107 writeLong = ((Integer)dataElem).intValue();
108 } else
109 if (dataElem instanceof Long) {
110 writeHyper = ((Long)dataElem).longValue();
111 } else
112 if (dataElem instanceof Float) {
113 writeFloat = ((Float)dataElem).floatValue();
114 } else
115 if (dataElem instanceof Double) {
116 writeDouble = ((Double)dataElem).doubleValue();
117 } else
118 if (dataElem instanceof String) {
119 writeUTF = (String)dataElem;
125 * First writes a value to outStream then reads it from input. <p>
127 * Has <b> OK </b> status if read and written values are equal. <p>
129 public void _readBoolean() {
130 boolean res = true ;
131 try {
132 oStream.writeBoolean(writeBoolean);
133 } catch (com.sun.star.io.IOException e) {
134 e.printStackTrace(log);
135 throw new StatusException("Can't write data to the stream", e);
137 byte readElem;
138 try {
139 readElem = oObj.readBoolean();
140 res = ((readElem != 0) == writeBoolean);
142 if (!res)
143 log.println("Must be read " +
144 writeBoolean +
145 " but was read " + (readElem != 0)) ;
146 } catch (com.sun.star.io.IOException e) {
147 log.println("Couldn't read Boolean from stream");
148 e.printStackTrace(log);
149 res = false;
152 tRes.tested("readBoolean()", res) ;
156 * First writes a value to outStream then reads it from input. <p>
158 * Has <b> OK </b> status if read and written values are equal. <p>
160 public void _readByte() {
161 boolean res = true ;
162 try {
163 oStream.writeByte(writeByte);
164 } catch (com.sun.star.io.IOException e) {
165 e.printStackTrace(log);
166 throw new StatusException("Can't write data to the stream", e);
168 byte readElem;
169 try {
170 readElem = oObj.readByte() ;
171 res = (readElem == writeByte);
173 if (!res)
174 log.println("Must be read " +
175 writeByte +
176 " but was read " + readElem);
177 } catch(com.sun.star.io.IOException e) {
178 log.println("Couldn't read Byte from stream");
179 e.printStackTrace(log);
180 res = false;
183 tRes.tested("readByte()", res) ;
187 * First writes a value to outStream then reads it from input. <p>
189 * Has <b> OK </b> status if read and written values are equal. <p>
191 public void _readChar() {
192 boolean res = true ;
193 try {
194 oStream.writeChar(writeChar);
195 } catch (com.sun.star.io.IOException e) {
196 e.printStackTrace(log);
197 throw new StatusException("Can't write data to the stream", e);
199 char readElem;
200 try {
201 readElem = oObj.readChar() ;
202 res = (readElem == writeChar);
204 if (!res)
205 log.println("Must be read " +
206 writeChar +
207 " but was read " + readElem) ;
208 } catch( com.sun.star.io.IOException e ) {
209 log.println("Couldn't read Char from stream");
210 e.printStackTrace(log);
211 res = false;
213 tRes.tested("readChar()", res);
217 * First writes a value to outStream then reads it from input. <p>
219 * Has <b> OK </b> status if read and written values are equal. <p>
221 public void _readShort() {
222 boolean res = true ;
223 try {
224 oStream.writeShort(writeShort);
225 } catch (com.sun.star.io.IOException e) {
226 e.printStackTrace(log);
227 throw new StatusException("Can't write data to the stream", e);
229 short readElem;
230 try {
231 readElem = oObj.readShort() ;
232 res = (readElem == writeShort);
234 if (!res)
235 log.println("Must be read " +
236 writeShort +
237 " but was read " + readElem) ;
238 } catch( com.sun.star.io.IOException e ) {
239 log.println("Couldn't read Short from stream");
240 e.printStackTrace(log);
241 res = false;
243 tRes.tested("readShort()", res);
247 * First writes a value to outStream then reads it from input. <p>
249 * Has <b> OK </b> status if read and written values are equal. <p>
251 public void _readLong() {
252 try {
253 oStream.writeLong(writeLong);
254 } catch (com.sun.star.io.IOException e) {
255 e.printStackTrace(log);
256 throw new StatusException("Can't write data to the stream", e);
258 boolean res = true ;
259 int readElem;
260 try {
261 readElem = oObj.readLong() ;
262 res = (readElem == writeLong);
264 if (!res)
265 log.println("Must be read " +
266 writeLong +
267 " but was read " + readElem) ;
268 } catch( com.sun.star.io.IOException e ) {
269 log.println("Couldn't read Long from stream");
270 e.printStackTrace(log);
271 res = false;
273 tRes.tested("readLong()", res);
277 * First writes a value to outStream then reads it from input. <p>
279 * Has <b> OK </b> status if read and written values are equal. <p>
281 public void _readHyper() {
282 boolean res = true ;
283 try {
284 oStream.writeHyper(writeHyper);
285 } catch (com.sun.star.io.IOException e) {
286 e.printStackTrace(log);
287 throw new StatusException("Can't write data to the stream", e);
289 long readElem;
290 try {
291 readElem = oObj.readHyper() ;
292 res = (readElem == writeHyper);
294 if (!res)
295 log.println("Must be read " +
296 writeHyper +
297 " but was read " + readElem) ;
298 } catch( com.sun.star.io.IOException e ) {
299 log.println("Couldn't read Hyper from stream");
300 e.printStackTrace(log);
301 res = false;
303 tRes.tested("readHyper()", res);
307 * First writes a value to outStream then reads it from input. <p>
309 * Has <b> OK </b> status if read and written values are equal. <p>
311 public void _readFloat() {
312 boolean res = true ;
313 try {
314 oStream.writeFloat(writeFloat);
315 } catch (com.sun.star.io.IOException e) {
316 e.printStackTrace(log);
317 throw new StatusException("Can't write data to the stream", e);
319 float readElem;
320 try {
321 readElem = oObj.readFloat() ;
322 res = (readElem == writeFloat);
324 if (!res)
325 log.println("Must be read " +
326 writeFloat +
327 " but was read " + readElem) ;
328 } catch( com.sun.star.io.IOException e ) {
329 log.println("Couldn't read Float from stream");
330 e.printStackTrace(log);
331 res = false;
333 tRes.tested("readFloat()", res);
337 * First writes a value to outStream then reads it from input. <p>
339 * Has <b> OK </b> status if read and written values are equal. <p>
341 public void _readDouble() {
342 boolean res = true ;
343 try {
344 oStream.writeDouble(writeDouble);
345 } catch (com.sun.star.io.IOException e) {
346 e.printStackTrace(log);
347 throw new StatusException("Can't write data to the stream", e);
349 double readElem;
350 try {
351 readElem = oObj.readDouble() ;
352 res = (readElem == writeDouble);
354 if (!res)
355 log.println("Must be read " +
356 writeDouble +
357 " but was read " + readElem) ;
358 } catch( com.sun.star.io.IOException e ) {
359 log.println("Couldn't read Double from stream");
360 e.printStackTrace(log);
361 res = false;
363 tRes.tested("readDouble()", res);
367 * First writes a value to outStream then reads it from input. <p>
369 * Has <b> OK </b> status if read and written values are equal. <p>
371 public void _readUTF() {
372 boolean res = true ;
373 try {
374 oStream.writeUTF(writeUTF);
375 } catch (com.sun.star.io.IOException e) {
376 e.printStackTrace(log);
377 throw new StatusException("Can't write data to the stream", e);
379 String readElem;
380 try {
381 readElem = oObj.readUTF() ;
382 res = writeUTF.equals(readElem) ;
384 if (!res)
385 log.println("Must be read '" +
386 writeUTF +
387 "' but was read '" + readElem + "'") ;
388 } catch( com.sun.star.io.IOException e ) {
389 log.println("Couldn't read String from stream");
390 e.printStackTrace(log);
391 res = false;
393 tRes.tested("readUTF()", res);
397 * Forces object environment recreation.
399 public void after() {
400 try {
401 oStream.flush();
402 } catch (com.sun.star.io.NotConnectedException e) {
403 e.printStackTrace(log);
404 } catch (com.sun.star.io.BufferSizeExceededException e) {
405 e.printStackTrace(log);
406 } catch (com.sun.star.io.IOException e) {
407 e.printStackTrace(log);
409 this.disposeEnvironment() ;