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 .
21 import lib
.MultiMethodTest
;
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
;
30 * Testing <code>com.sun.star.io.XInputStream</code>
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>
39 * This test needs the following object relations :
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>
48 * @see com.sun.star.io.XInputStream
50 public class _XInputStream
extends MultiMethodTest
{
52 public XInputStream oObj
= null;
53 public XOutputStream oStream
= null;
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.
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");
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
) {}
78 * After the test, the stream writer is closed and the
79 * environment is disposed.
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();
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 ;
100 bytesReady
= oObj
.available() ;
101 log
.println("Bytes available :" + bytesReady
) ;
102 } catch (com
.sun
.star
.io
.IOException e
){
103 e
.printStackTrace(log
) ;
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 :
117 * <li> <code> available() </code> : to have available number
118 * of bytes in stream </li>
121 public void _readBytes() {
122 requiredMethod("available()") ;
125 if (bytesReady
-- > 0) {
127 byte[][] data
= new byte[1][1] ;
128 int read
= oObj
.readBytes(data
, 1) ;
130 result
= read
== 1 &&
132 } catch (com
.sun
.star
.io
.IOException e
){
133 e
.printStackTrace(log
) ;
137 tRes
.tested("readBytes()", result
) ;
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 :
151 * <li> <code> available() </code> : to have available number
152 * of bytes in stream </li>
155 public void _readSomeBytes() {
156 requiredMethod("available()") ;
159 if (bytesReady
-- > 0) {
161 byte[][] data
= new byte [1][1] ;
162 int read
= oObj
.readSomeBytes(data
, 1) ;
164 result
= read
== 1 &&
166 } catch (com
.sun
.star
.io
.IOException e
){
167 e
.printStackTrace(log
) ;
170 tRes
.tested("readSomeBytes()", result
) ;
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 :
184 * <li> <code> available() </code> : to have available number
185 * of bytes in stream </li>
188 public void _skipBytes() {
189 requiredMethod("available()") ;
192 if (bytesReady
-- > 0) {
197 } catch (com
.sun
.star
.io
.IOException e
){
198 e
.printStackTrace(log
) ;
201 tRes
.tested("skipBytes()", result
) ;
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 :
214 * <li> <code> available() </code> </li>
215 * <li> <code> readBytes() </code> </li>
216 * <li> <code> readSomeBytes() </code> </li>
217 * <li> <code> skipBytes() </code> </li>
220 public void _closeInput() {
221 executeMethod("available()") ;
222 executeMethod("readBytes()") ;
223 executeMethod("readSomeBytes()") ;
224 executeMethod("skipBytes()") ;
226 boolean result
= true ;
229 } catch (com
.sun
.star
.io
.IOException e
){
230 e
.printStackTrace(log
) ;
234 tRes
.tested("closeInput()", result
) ;
235 this.disposeEnvironment() ;