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 ************************************************************************/
30 import lib
.MultiMethodTest
;
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
;
39 * Testing <code>com.sun.star.io.XInputStream</code>
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>
48 * This test needs the following object relations :
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>
57 * @see com.sun.star.io.XInputStream
59 public class _XInputStream
extends MultiMethodTest
{
61 public XInputStream oObj
= null;
62 public XOutputStream oStream
= null;
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");
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
) {}
86 * After the test, the stream writer is closed and the
87 * environment is disposed.
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();
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 ;
107 bytesReady
= oObj
.available() ;
108 log
.println("Bytes available :" + bytesReady
) ;
109 } catch (com
.sun
.star
.io
.IOException e
){
110 e
.printStackTrace(log
) ;
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 :
124 * <li> <code> available() </code> : to have available number
125 * of bytes in stream </li>
128 public void _readBytes() {
129 requiredMethod("available()") ;
132 if (bytesReady
-- > 0) {
134 byte[][] data
= new byte[1][1] ;
135 int read
= oObj
.readBytes(data
, 1) ;
137 result
= read
== 1 &&
140 } catch (com
.sun
.star
.io
.IOException e
){
141 e
.printStackTrace(log
) ;
145 tRes
.tested("readBytes()", result
) ;
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 :
159 * <li> <code> available() </code> : to have available number
160 * of bytes in stream </li>
163 public void _readSomeBytes() {
164 requiredMethod("available()") ;
167 if (bytesReady
-- > 0) {
169 byte[][] data
= new byte [1][1] ;
170 int read
= oObj
.readSomeBytes(data
, 1) ;
172 result
= read
== 1 &&
175 } catch (com
.sun
.star
.io
.IOException e
){
176 e
.printStackTrace(log
) ;
179 tRes
.tested("readSomeBytes()", result
) ;
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 :
193 * <li> <code> available() </code> : to have available number
194 * of bytes in stream </li>
197 public void _skipBytes() {
198 requiredMethod("available()") ;
201 if (bytesReady
-- > 0) {
206 } catch (com
.sun
.star
.io
.IOException e
){
207 e
.printStackTrace(log
) ;
210 tRes
.tested("skipBytes()", result
) ;
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 :
223 * <li> <code> available() </code> </li>
224 * <li> <code> readBytes() </code> </li>
225 * <li> <code> readSomeBytes() </code> </li>
226 * <li> <code> skipBytes() </code> </li>
229 public void _closeInput() {
230 executeMethod("available()") ;
231 executeMethod("readBytes()") ;
232 executeMethod("readSomeBytes()") ;
233 executeMethod("skipBytes()") ;
235 boolean result
= true ;
238 } catch (com
.sun
.star
.io
.IOException e
){
239 e
.printStackTrace(log
) ;
243 tRes
.tested("closeInput()", result
) ;
244 this.disposeEnvironment() ;