Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / io / _XInputStream.java
blob2f3161532ef45849bb8093af2609d4f741646e33
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package ifc.io;
30 import lib.MultiMethodTest;
31 import lib.Status;
33 import com.sun.star.io.XInputStream;
34 import com.sun.star.io.XOutputStream;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
38 /**
39 * Testing <code>com.sun.star.io.XInputStream</code>
40 * interface methods:
41 * <ul>
42 * <li><code>readBytes()</code></li>
43 * <li><code>readSomeBytes()</code></li>
44 * <li><code>skipBytes()</code></li>
45 * <li><code>available()</code></li>
46 * <li><code>closeInput()</code></li>
47 * </ul> <p>
48 * This test needs the following object relations :
49 * <ul>
50 * <li> <code>'StreamWriter'</code>:
51 * object that supports interface <code>XOutputStream</code>;
52 * a stream to write data to</li>
53 * <li> <code>'ByteData'</code> (of type <code>byte []</code>):
54 * data to write to the stream</li>
55 * <ul> <p>
57 * @see com.sun.star.io.XInputStream
59 public class _XInputStream extends MultiMethodTest {
61 public XInputStream oObj = null;
62 public XOutputStream oStream = null;
64 byte[] bytes = null;
66 int bytesReady = 0 ;
68 /**
69 * Before the test, the stream writer and the data are ecxtracted from
70 * the object relations and the data is written to the stream.
72 public void before() {
73 XInterface x = (XInterface)tEnv.getObjRelation("StreamWriter");
74 oStream = (XOutputStream)UnoRuntime.queryInterface(
75 XOutputStream.class, x) ;
76 bytes = (byte[])tEnv.getObjRelation("ByteData");
77 try {
78 oStream.writeBytes(bytes);
80 catch(com.sun.star.io.NotConnectedException e) {}
81 catch(com.sun.star.io.BufferSizeExceededException e) {}
82 catch(com.sun.star.io.IOException e) {}
85 /**
86 * After the test, the stream writer is closed and the
87 * environment is disposed.
89 public void after() {
90 try {
91 oStream.flush();
92 oStream.closeOutput();
94 catch(com.sun.star.io.NotConnectedException e) {}
95 catch(com.sun.star.io.BufferSizeExceededException e) {}
96 catch(com.sun.star.io.IOException e) {}
97 this.disposeEnvironment();
99 /**
100 * Test calls the method and stores number of available bytes. <p>
101 * Has <b> OK </b> status if the method successfully returns
102 * and no exceptions were thrown. <p>
104 public void _available() {
105 boolean result = true ;
106 try {
107 bytesReady = oObj.available() ;
108 log.println("Bytes available :" + bytesReady) ;
109 } catch (com.sun.star.io.IOException e){
110 e.printStackTrace(log) ;
111 result = false ;
114 tRes.tested("available()", result) ;
118 * Test reads one byte from stream. If no bytes available
119 * then test of method is skipped. <p>
120 * Has <b> OK </b> status if returned value equal to number of read bytes,
121 * no exceptions were thrown and read data is not null. <p>
122 * The following method tests are to be completed successfully before :
123 * <ul>
124 * <li> <code> available() </code> : to have available number
125 * of bytes in stream </li>
126 * </ul>
128 public void _readBytes() {
129 requiredMethod("available()") ;
130 boolean result ;
132 if (bytesReady-- > 0) {
133 try {
134 byte[][] data = new byte[1][1] ;
135 int read = oObj.readBytes(data, 1) ;
137 result = read == 1 &&
138 data != null &&
139 data.length == 1 ;
140 } catch (com.sun.star.io.IOException e){
141 e.printStackTrace(log) ;
142 result = false ;
145 tRes.tested("readBytes()", result) ;
146 } else {
147 log.println("No more bytes available in the stream");
148 tRes.tested("readBytes()", Status.skipped(false));
153 * Test reads one byte from stream. If no bytes available
154 * then test of method is skipped. <p>
155 * Has <b> OK </b> status if returned value equal to number of read bytes,
156 * no exceptions were thrown and read data is not null. <p>
157 * The following method tests are to be completed successfully before :
158 * <ul>
159 * <li> <code> available() </code> : to have available number
160 * of bytes in stream </li>
161 * </ul>
163 public void _readSomeBytes() {
164 requiredMethod("available()") ;
165 boolean result ;
167 if (bytesReady-- > 0) {
168 try {
169 byte[][] data = new byte [1][1] ;
170 int read = oObj.readSomeBytes(data, 1) ;
172 result = read == 1 &&
173 data != null &&
174 data.length == 1 ;
175 } catch (com.sun.star.io.IOException e){
176 e.printStackTrace(log) ;
177 result = false ;
179 tRes.tested("readSomeBytes()", result) ;
180 } else {
181 log.println("No more bytes available in the stream") ;
182 tRes.tested("readBytes()", Status.skipped(false));
187 * Test skips one byte from stream. If no bytes available
188 * then test of method is skipped. <p>
189 * Has <b> OK </b> status if the method successfully returns
190 * and no exceptions were thrown. <p>
191 * The following method tests are to be completed successfully before :
192 * <ul>
193 * <li> <code> available() </code> : to have available number
194 * of bytes in stream </li>
195 * </ul>
197 public void _skipBytes() {
198 requiredMethod("available()") ;
199 boolean result ;
201 if (bytesReady-- > 0) {
202 try {
203 oObj.skipBytes(1) ;
205 result = true ;
206 } catch (com.sun.star.io.IOException e){
207 e.printStackTrace(log) ;
208 result = false ;
210 tRes.tested("skipBytes()", result) ;
211 } else {
212 log.println("No more bytes available in the stream") ;
213 tRes.tested("readBytes()", Status.skipped(false));
218 * Test calls the method and forces object environment recreation. <p>
219 * Has <b> OK </b> status if the method successfully returns
220 * and no exceptions were thrown. <p>
221 * The following method tests are to be executed before :
222 * <ul>
223 * <li> <code> available() </code> </li>
224 * <li> <code> readBytes() </code> </li>
225 * <li> <code> readSomeBytes() </code> </li>
226 * <li> <code> skipBytes() </code> </li>
227 * </ul>
229 public void _closeInput() {
230 executeMethod("available()") ;
231 executeMethod("readBytes()") ;
232 executeMethod("readSomeBytes()") ;
233 executeMethod("skipBytes()") ;
235 boolean result = true ;
236 try {
237 oObj.closeInput() ;
238 } catch (com.sun.star.io.IOException e){
239 e.printStackTrace(log) ;
240 result = false ;
243 tRes.tested("closeInput()", result) ;
244 this.disposeEnvironment() ;