1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XOutputStream.java,v $
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 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import lib
.StatusException
;
37 import com
.sun
.star
.io
.XInputStream
;
38 import com
.sun
.star
.io
.XOutputStream
;
41 * Testing <code>com.sun.star.io.XOutputStream</code>
44 * <li><code>writeBytes()</code></li>
45 * <li><code>flush()</code></li>
46 * <li><code>closeOutput()</code></li>
48 * This test needs the following object relations :
50 * <li> <code>'ByteData'</code> : Data that is written on the stream.
52 * <li> <code>'XOutputStream.StreamChecker'</code> : <code>
53 * _XOutputStream.StreamChecker</code> interface implementation
54 * which can reset streams and return input stream for check if the
55 * data was successfully written.</li>
57 * After test completion object environment has to be recreated.
58 * @see com.sun.star.io.XOutputStream
60 public class _XOutputStream
extends MultiMethodTest
{
62 public XOutputStream oObj
= null;
63 StreamChecker checker
= null;
66 public static interface StreamChecker
{
67 public XInputStream
getInStream();
68 public void resetStreams();
71 protected void before() {
72 checker
= (StreamChecker
)
73 tEnv
.getObjRelation("XOutputStream.StreamChecker");
74 if (checker
== null) throw
75 new StatusException(Status
.failed(
76 "Couldn't get relation 'XOutputStream.StreamChecker'"));
78 data
= (byte[])tEnv
.getObjRelation("ByteData");
79 if (data
== null) throw
80 new StatusException(Status
.failed(
81 "Couldn't get relation 'ByteData'"));
84 * Test writes data to stream. <p>
85 * Has <b> OK </b> status if the method successfully returns
86 * and no exceptions were thrown. <p>
88 public void _writeBytes() {
91 oObj
.writeBytes(data
);
92 } catch (com
.sun
.star
.io
.IOException e
) {
93 e
.printStackTrace(log
) ;
97 XInputStream xInStream
= checker
.getInStream();
98 byte[][] readData
= new byte[1][data
.length
];
101 iReadBytes
= xInStream
.readBytes(readData
, data
.length
);
102 } catch(com
.sun
.star
.io
.IOException e
) {
103 log
.println("Couldn't read data:" + e
);
107 for(int i
= 0; i
< readData
[0].length
; i
++) {
108 log
.println("Expected: "+data
[i
]+", actual is "+readData
[0][i
]);
109 res
&= readData
[0][i
] == data
[i
];
112 tRes
.tested("writeBytes()", res
);
116 * Test flushes out data from stream. <p>
117 * Has <b> OK </b> status if the method successfully returns
118 * and no exceptions were thrown. <p>
119 * The following method tests are to be completed successfully before :
121 * <li> <code> writeBytes() </code></li>
124 public void _flush() {
125 requiredMethod("writeBytes()");
131 } catch (com
.sun
.star
.io
.IOException e
) {
132 e
.printStackTrace(log
) ;
136 tRes
.tested("flush()", res
);
140 * Test calls the method. <p>
141 * Has <b> OK </b> status if the method successfully returns
142 * and no exceptions were thrown. <p>
143 * The following method tests are to be completed successfully before :
145 * <li> <code> writeBytes() </code></li>
147 * The following method tests are to be executed before :
149 * <li><code> flush() </code></li>
152 public void _closeOutput() {
153 requiredMethod("writeBytes()");
154 executeMethod("flush()");
160 } catch (com
.sun
.star
.io
.IOException e
) {
161 e
.printStackTrace(log
);
165 log
.println("This method is called in main module");
167 tRes
.tested("closeOutput()", res
);
171 * Forces object environment recreation.
173 public void after() {
174 this.disposeEnvironment() ;