Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / io / _XOutputStream.java
blobbd4e04756681c06a678b9cbf1ee912499423406e
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: _XOutputStream.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;
35 import lib.StatusException;
37 import com.sun.star.io.XInputStream;
38 import com.sun.star.io.XOutputStream;
40 /**
41 * Testing <code>com.sun.star.io.XOutputStream</code>
42 * interface methods:
43 * <ul>
44 * <li><code>writeBytes()</code></li>
45 * <li><code>flush()</code></li>
46 * <li><code>closeOutput()</code></li>
47 * </ul> <p>
48 * This test needs the following object relations :
49 * <ul>
50 * <li> <code>'ByteData'</code> : Data that is written on the stream.
51 * </li>
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>
56 * <ul> <p>
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;
64 byte[] data = 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'"));
83 /**
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() {
89 boolean res = true;
90 try {
91 oObj.writeBytes(data);
92 } catch (com.sun.star.io.IOException e) {
93 e.printStackTrace(log) ;
94 res = false;
97 XInputStream xInStream = checker.getInStream();
98 byte[][] readData = new byte[1][data.length];
99 int iReadBytes = 0;
100 try {
101 iReadBytes = xInStream.readBytes(readData, data.length);
102 } catch(com.sun.star.io.IOException e) {
103 log.println("Couldn't read data:" + e);
104 res = false;
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 :
120 * <ul>
121 * <li> <code> writeBytes() </code></li>
122 * </ul>
124 public void _flush() {
125 requiredMethod("writeBytes()");
127 boolean res;
128 try {
129 oObj.flush();
130 res = true;
131 } catch (com.sun.star.io.IOException e) {
132 e.printStackTrace(log) ;
133 res = false;
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 :
144 * <ul>
145 * <li> <code> writeBytes() </code></li>
146 * </ul>
147 * The following method tests are to be executed before :
148 * <ul>
149 * <li><code> flush() </code></li>
150 * </ul>
152 public void _closeOutput() {
153 requiredMethod("writeBytes()");
154 executeMethod("flush()");
156 boolean res;
157 try {
158 oObj.closeOutput();
159 res = true;
160 } catch (com.sun.star.io.IOException e) {
161 e.printStackTrace(log);
162 res = false;
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() ;