merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / io / _XInputStream.java
blob777f90400dc15621e3df97094f6b3ecce7ca09a6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XInputStream.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.io;
33 import lib.MultiMethodTest;
34 import lib.Status;
36 import com.sun.star.io.XInputStream;
37 import com.sun.star.io.XOutputStream;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
41 /**
42 * Testing <code>com.sun.star.io.XInputStream</code>
43 * interface methods:
44 * <ul>
45 * <li><code>readBytes()</code></li>
46 * <li><code>readSomeBytes()</code></li>
47 * <li><code>skipBytes()</code></li>
48 * <li><code>available()</code></li>
49 * <li><code>closeInput()</code></li>
50 * </ul> <p>
51 * This test needs the following object relations :
52 * <ul>
53 * <li> <code>'StreamWriter'</code>:
54 * object that supports interface <code>XOutputStream</code>;
55 * a stream to write data to</li>
56 * <li> <code>'ByteData'</code> (of type <code>byte []</code>):
57 * data to write to the stream</li>
58 * <ul> <p>
60 * @see com.sun.star.io.XInputStream
62 public class _XInputStream extends MultiMethodTest {
64 public XInputStream oObj = null;
65 public XOutputStream oStream = null;
67 byte[] bytes = null;
69 int bytesReady = 0 ;
71 /**
72 * Before the test, the stream writer and the data are ecxtracted from
73 * the object relations and the data is written to the stream.
75 public void before() {
76 XInterface x = (XInterface)tEnv.getObjRelation("StreamWriter");
77 oStream = (XOutputStream)UnoRuntime.queryInterface(
78 XOutputStream.class, x) ;
79 bytes = (byte[])tEnv.getObjRelation("ByteData");
80 try {
81 oStream.writeBytes(bytes);
83 catch(com.sun.star.io.NotConnectedException e) {}
84 catch(com.sun.star.io.BufferSizeExceededException e) {}
85 catch(com.sun.star.io.IOException e) {}
88 /**
89 * After the test, the stream writer is closed and the
90 * environment is disposed.
92 public void after() {
93 try {
94 oStream.flush();
95 oStream.closeOutput();
97 catch(com.sun.star.io.NotConnectedException e) {}
98 catch(com.sun.star.io.BufferSizeExceededException e) {}
99 catch(com.sun.star.io.IOException e) {}
100 this.disposeEnvironment();
103 * Test calls the method and stores number of available bytes. <p>
104 * Has <b> OK </b> status if the method successfully returns
105 * and no exceptions were thrown. <p>
107 public void _available() {
108 boolean result = true ;
109 try {
110 bytesReady = oObj.available() ;
111 log.println("Bytes available :" + bytesReady) ;
112 } catch (com.sun.star.io.IOException e){
113 e.printStackTrace(log) ;
114 result = false ;
117 tRes.tested("available()", result) ;
121 * Test reads one byte from stream. If no bytes available
122 * then test of method is skipped. <p>
123 * Has <b> OK </b> status if returned value equal to number of read bytes,
124 * no exceptions were thrown and read data is not null. <p>
125 * The following method tests are to be completed successfully before :
126 * <ul>
127 * <li> <code> available() </code> : to have available number
128 * of bytes in stream </li>
129 * </ul>
131 public void _readBytes() {
132 requiredMethod("available()") ;
133 boolean result ;
135 if (bytesReady-- > 0) {
136 try {
137 byte[][] data = new byte[1][1] ;
138 int read = oObj.readBytes(data, 1) ;
140 result = read == 1 &&
141 data != null &&
142 data.length == 1 ;
143 } catch (com.sun.star.io.IOException e){
144 e.printStackTrace(log) ;
145 result = false ;
148 tRes.tested("readBytes()", result) ;
149 } else {
150 log.println("No more bytes available in the stream");
151 tRes.tested("readBytes()", Status.skipped(false));
156 * Test reads one byte from stream. If no bytes available
157 * then test of method is skipped. <p>
158 * Has <b> OK </b> status if returned value equal to number of read bytes,
159 * no exceptions were thrown and read data is not null. <p>
160 * The following method tests are to be completed successfully before :
161 * <ul>
162 * <li> <code> available() </code> : to have available number
163 * of bytes in stream </li>
164 * </ul>
166 public void _readSomeBytes() {
167 requiredMethod("available()") ;
168 boolean result ;
170 if (bytesReady-- > 0) {
171 try {
172 byte[][] data = new byte [1][1] ;
173 int read = oObj.readSomeBytes(data, 1) ;
175 result = read == 1 &&
176 data != null &&
177 data.length == 1 ;
178 } catch (com.sun.star.io.IOException e){
179 e.printStackTrace(log) ;
180 result = false ;
182 tRes.tested("readSomeBytes()", result) ;
183 } else {
184 log.println("No more bytes available in the stream") ;
185 tRes.tested("readBytes()", Status.skipped(false));
190 * Test skips one byte from stream. If no bytes available
191 * then test of method is skipped. <p>
192 * Has <b> OK </b> status if the method successfully returns
193 * and no exceptions were thrown. <p>
194 * The following method tests are to be completed successfully before :
195 * <ul>
196 * <li> <code> available() </code> : to have available number
197 * of bytes in stream </li>
198 * </ul>
200 public void _skipBytes() {
201 requiredMethod("available()") ;
202 boolean result ;
204 if (bytesReady-- > 0) {
205 try {
206 oObj.skipBytes(1) ;
208 result = true ;
209 } catch (com.sun.star.io.IOException e){
210 e.printStackTrace(log) ;
211 result = false ;
213 tRes.tested("skipBytes()", result) ;
214 } else {
215 log.println("No more bytes available in the stream") ;
216 tRes.tested("readBytes()", Status.skipped(false));
221 * Test calls the method and forces object environment recreation. <p>
222 * Has <b> OK </b> status if the method successfully returns
223 * and no exceptions were thrown. <p>
224 * The following method tests are to be executed before :
225 * <ul>
226 * <li> <code> available() </code> </li>
227 * <li> <code> readBytes() </code> </li>
228 * <li> <code> readSomeBytes() </code> </li>
229 * <li> <code> skipBytes() </code> </li>
230 * </ul>
232 public void _closeInput() {
233 executeMethod("available()") ;
234 executeMethod("readBytes()") ;
235 executeMethod("readSomeBytes()") ;
236 executeMethod("skipBytes()") ;
238 boolean result = true ;
239 try {
240 oObj.closeInput() ;
241 } catch (com.sun.star.io.IOException e){
242 e.printStackTrace(log) ;
243 result = false ;
246 tRes.tested("closeInput()", result) ;
247 this.disposeEnvironment() ;