bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / io / _XInputStream.java
blob738b252b96d12d92a9b866b632be29551b7b698e
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 ecxtracted from
61 * the object relations and the data is written to the stream.
63 public void before() {
64 XInterface x = (XInterface)tEnv.getObjRelation("StreamWriter");
65 oStream = UnoRuntime.queryInterface(
66 XOutputStream.class, x) ;
67 bytes = (byte[])tEnv.getObjRelation("ByteData");
68 try {
69 oStream.writeBytes(bytes);
71 catch(com.sun.star.io.NotConnectedException e) {}
72 catch(com.sun.star.io.BufferSizeExceededException e) {}
73 catch(com.sun.star.io.IOException e) {}
76 /**
77 * After the test, the stream writer is closed and the
78 * environment is disposed.
80 public void after() {
81 try {
82 oStream.flush();
83 oStream.closeOutput();
85 catch(com.sun.star.io.NotConnectedException e) {}
86 catch(com.sun.star.io.BufferSizeExceededException e) {}
87 catch(com.sun.star.io.IOException e) {}
88 this.disposeEnvironment();
90 /**
91 * Test calls the method and stores number of available bytes. <p>
92 * Has <b> OK </b> status if the method successfully returns
93 * and no exceptions were thrown. <p>
95 public void _available() {
96 boolean result = true ;
97 try {
98 bytesReady = oObj.available() ;
99 log.println("Bytes available :" + bytesReady) ;
100 } catch (com.sun.star.io.IOException e){
101 e.printStackTrace(log) ;
102 result = false ;
105 tRes.tested("available()", result) ;
109 * Test reads one byte from stream. If no bytes available
110 * then test of method is skipped. <p>
111 * Has <b> OK </b> status if returned value equal to number of read bytes,
112 * no exceptions were thrown and read data is not null. <p>
113 * The following method tests are to be completed successfully before :
114 * <ul>
115 * <li> <code> available() </code> : to have available number
116 * of bytes in stream </li>
117 * </ul>
119 public void _readBytes() {
120 requiredMethod("available()") ;
121 boolean result ;
123 if (bytesReady-- > 0) {
124 try {
125 byte[][] data = new byte[1][1] ;
126 int read = oObj.readBytes(data, 1) ;
128 result = read == 1 &&
129 data != null &&
130 data.length == 1 ;
131 } catch (com.sun.star.io.IOException e){
132 e.printStackTrace(log) ;
133 result = false ;
136 tRes.tested("readBytes()", result) ;
137 } else {
138 log.println("No more bytes available in the stream");
139 tRes.tested("readBytes()", Status.skipped(false));
144 * Test reads one byte from stream. If no bytes available
145 * then test of method is skipped. <p>
146 * Has <b> OK </b> status if returned value equal to number of read bytes,
147 * no exceptions were thrown and read data is not null. <p>
148 * The following method tests are to be completed successfully before :
149 * <ul>
150 * <li> <code> available() </code> : to have available number
151 * of bytes in stream </li>
152 * </ul>
154 public void _readSomeBytes() {
155 requiredMethod("available()") ;
156 boolean result ;
158 if (bytesReady-- > 0) {
159 try {
160 byte[][] data = new byte [1][1] ;
161 int read = oObj.readSomeBytes(data, 1) ;
163 result = read == 1 &&
164 data != null &&
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() ;