cid#1607171 Data race condition
[LibreOffice.git] / qadevOOo / tests / java / ifc / io / _XInputStream.java
blob90ee86afb63cdaa394c9e906f34705c345b5f397
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;
24 import com.sun.star.io.XInputStream;
25 import com.sun.star.io.XOutputStream;
26 import com.sun.star.uno.UnoRuntime;
27 import com.sun.star.uno.XInterface;
29 /**
30 * Testing <code>com.sun.star.io.XInputStream</code>
31 * interface methods:
32 * <ul>
33 * <li><code>readBytes()</code></li>
34 * <li><code>readSomeBytes()</code></li>
35 * <li><code>skipBytes()</code></li>
36 * <li><code>available()</code></li>
37 * <li><code>closeInput()</code></li>
38 * </ul> <p>
39 * This test needs the following object relations :
40 * <ul>
41 * <li> <code>'StreamWriter'</code>:
42 * object that supports interface <code>XOutputStream</code>;
43 * a stream to write data to</li>
44 * <li> <code>'ByteData'</code> (of type <code>byte []</code>):
45 * data to write to the stream</li>
46 * <ul> <p>
48 * @see com.sun.star.io.XInputStream
50 public class _XInputStream extends MultiMethodTest {
52 public XInputStream oObj = null;
53 public XOutputStream oStream = null;
55 byte[] bytes = null;
57 int bytesReady = 0 ;
59 /**
60 * Before the test, the stream writer and the data are extracted from
61 * the object relations and the data is written to the stream.
63 @Override
64 public void before() {
65 XInterface x = (XInterface)tEnv.getObjRelation("StreamWriter");
66 oStream = UnoRuntime.queryInterface(
67 XOutputStream.class, x) ;
68 bytes = (byte[])tEnv.getObjRelation("ByteData");
69 try {
70 oStream.writeBytes(bytes);
72 catch(com.sun.star.io.NotConnectedException e) {}
73 catch(com.sun.star.io.BufferSizeExceededException e) {}
74 catch(com.sun.star.io.IOException e) {}
77 /**
78 * After the test, the stream writer is closed and the
79 * environment is disposed.
81 @Override
82 public void after() {
83 try {
84 oStream.flush();
85 oStream.closeOutput();
87 catch(com.sun.star.io.NotConnectedException e) {}
88 catch(com.sun.star.io.BufferSizeExceededException e) {}
89 catch(com.sun.star.io.IOException e) {}
90 this.disposeEnvironment();
92 /**
93 * Test calls the method and stores number of available bytes. <p>
94 * Has <b> OK </b> status if the method successfully returns
95 * and no exceptions were thrown. <p>
97 public void _available() {
98 boolean result = true ;
99 try {
100 bytesReady = oObj.available() ;
101 log.println("Bytes available :" + bytesReady) ;
102 } catch (com.sun.star.io.IOException e){
103 e.printStackTrace(log) ;
104 result = false ;
107 tRes.tested("available()", result) ;
111 * Test reads one byte from stream. If no bytes available
112 * then test of method is skipped. <p>
113 * Has <b> OK </b> status if returned value equal to number of read bytes,
114 * no exceptions were thrown and read data is not null. <p>
115 * The following method tests are to be completed successfully before :
116 * <ul>
117 * <li> <code> available() </code> : to have available number
118 * of bytes in stream </li>
119 * </ul>
121 public void _readBytes() {
122 requiredMethod("available()") ;
123 boolean result ;
125 if (bytesReady-- > 0) {
126 try {
127 byte[][] data = new byte[1][1] ;
128 int read = oObj.readBytes(data, 1) ;
130 result = read == 1 &&
131 data.length == 1 ;
132 } catch (com.sun.star.io.IOException e){
133 e.printStackTrace(log) ;
134 result = false ;
137 tRes.tested("readBytes()", result) ;
138 } else {
139 log.println("No more bytes available in the stream");
140 tRes.tested("readBytes()", Status.skipped(false));
145 * Test reads one byte from stream. If no bytes available
146 * then test of method is skipped. <p>
147 * Has <b> OK </b> status if returned value equal to number of read bytes,
148 * no exceptions were thrown and read data is not null. <p>
149 * The following method tests are to be completed successfully before :
150 * <ul>
151 * <li> <code> available() </code> : to have available number
152 * of bytes in stream </li>
153 * </ul>
155 public void _readSomeBytes() {
156 requiredMethod("available()") ;
157 boolean result ;
159 if (bytesReady-- > 0) {
160 try {
161 byte[][] data = new byte [1][1] ;
162 int read = oObj.readSomeBytes(data, 1) ;
164 result = read == 1 &&
165 data.length == 1 ;
166 } catch (com.sun.star.io.IOException e){
167 e.printStackTrace(log) ;
168 result = false ;
170 tRes.tested("readSomeBytes()", result) ;
171 } else {
172 log.println("No more bytes available in the stream") ;
173 tRes.tested("readBytes()", Status.skipped(false));
178 * Test skips one byte from stream. If no bytes available
179 * then test of method is skipped. <p>
180 * Has <b> OK </b> status if the method successfully returns
181 * and no exceptions were thrown. <p>
182 * The following method tests are to be completed successfully before :
183 * <ul>
184 * <li> <code> available() </code> : to have available number
185 * of bytes in stream </li>
186 * </ul>
188 public void _skipBytes() {
189 requiredMethod("available()") ;
190 boolean result ;
192 if (bytesReady-- > 0) {
193 try {
194 oObj.skipBytes(1) ;
196 result = true ;
197 } catch (com.sun.star.io.IOException e){
198 e.printStackTrace(log) ;
199 result = false ;
201 tRes.tested("skipBytes()", result) ;
202 } else {
203 log.println("No more bytes available in the stream") ;
204 tRes.tested("readBytes()", Status.skipped(false));
209 * Test calls the method and forces object environment recreation. <p>
210 * Has <b> OK </b> status if the method successfully returns
211 * and no exceptions were thrown. <p>
212 * The following method tests are to be executed before :
213 * <ul>
214 * <li> <code> available() </code> </li>
215 * <li> <code> readBytes() </code> </li>
216 * <li> <code> readSomeBytes() </code> </li>
217 * <li> <code> skipBytes() </code> </li>
218 * </ul>
220 public void _closeInput() {
221 executeMethod("available()") ;
222 executeMethod("readBytes()") ;
223 executeMethod("readSomeBytes()") ;
224 executeMethod("skipBytes()") ;
226 boolean result = true ;
227 try {
228 oObj.closeInput() ;
229 } catch (com.sun.star.io.IOException e){
230 e.printStackTrace(log) ;
231 result = false ;
234 tRes.tested("closeInput()", result) ;
235 this.disposeEnvironment() ;