bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / io / _XOutputStream.java
blob8e53c67def0bd9f95e3be7fe7cfed55de52854bc
1 /*
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 .
19 package ifc.io;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
25 import com.sun.star.io.XInputStream;
26 import com.sun.star.io.XOutputStream;
28 /**
29 * Testing <code>com.sun.star.io.XOutputStream</code>
30 * interface methods:
31 * <ul>
32 * <li><code>writeBytes()</code></li>
33 * <li><code>flush()</code></li>
34 * <li><code>closeOutput()</code></li>
35 * </ul> <p>
36 * This test needs the following object relations :
37 * <ul>
38 * <li> <code>'ByteData'</code> : Data that is written on the stream.
39 * </li>
40 * <li> <code>'XOutputStream.StreamChecker'</code> : <code>
41 * _XOutputStream.StreamChecker</code> interface implementation
42 * which can reset streams and return input stream for check if the
43 * data was successfully written.</li>
44 * <ul> <p>
45 * After test completion object environment has to be recreated.
46 * @see com.sun.star.io.XOutputStream
48 public class _XOutputStream extends MultiMethodTest {
50 public XOutputStream oObj = null;
51 StreamChecker checker = null;
52 byte[] data = null;
54 public static interface StreamChecker {
55 public XInputStream getInStream();
56 public void resetStreams();
59 protected void before() {
60 checker = (StreamChecker)
61 tEnv.getObjRelation("XOutputStream.StreamChecker");
62 if (checker == null) throw
63 new StatusException(Status.failed(
64 "Couldn't get relation 'XOutputStream.StreamChecker'"));
66 data = (byte[])tEnv.getObjRelation("ByteData");
67 if (data == null) throw
68 new StatusException(Status.failed(
69 "Couldn't get relation 'ByteData'"));
71 /**
72 * Test writes data to stream. <p>
73 * Has <b> OK </b> status if the method successfully returns
74 * and no exceptions were thrown. <p>
76 public void _writeBytes() {
77 boolean res = true;
78 try {
79 oObj.writeBytes(data);
80 } catch (com.sun.star.io.IOException e) {
81 e.printStackTrace(log) ;
82 res = false;
85 XInputStream xInStream = checker.getInStream();
86 byte[][] readData = new byte[1][data.length];
87 try {
88 xInStream.readBytes(readData, data.length);
89 } catch(com.sun.star.io.IOException e) {
90 log.println("Couldn't read data:" + e);
91 res = false;
94 for(int i = 0; i < readData[0].length; i++) {
95 log.println("Expected: "+data[i]+", actual is "+readData[0][i]);
96 res &= readData[0][i] == data[i];
99 tRes.tested("writeBytes()", res);
103 * Test flushes out data from stream. <p>
104 * Has <b> OK </b> status if the method successfully returns
105 * and no exceptions were thrown. <p>
106 * The following method tests are to be completed successfully before :
107 * <ul>
108 * <li> <code> writeBytes() </code></li>
109 * </ul>
111 public void _flush() {
112 requiredMethod("writeBytes()");
114 boolean res;
115 try {
116 oObj.flush();
117 res = true;
118 } catch (com.sun.star.io.IOException e) {
119 e.printStackTrace(log) ;
120 res = false;
123 tRes.tested("flush()", res);
127 * Test calls the method. <p>
128 * Has <b> OK </b> status if the method successfully returns
129 * and no exceptions were thrown. <p>
130 * The following method tests are to be completed successfully before :
131 * <ul>
132 * <li> <code> writeBytes() </code></li>
133 * </ul>
134 * The following method tests are to be executed before :
135 * <ul>
136 * <li><code> flush() </code></li>
137 * </ul>
139 public void _closeOutput() {
140 requiredMethod("writeBytes()");
141 executeMethod("flush()");
143 boolean res;
144 try {
145 oObj.closeOutput();
146 res = true;
147 } catch (com.sun.star.io.IOException e) {
148 e.printStackTrace(log);
149 res = false;
152 log.println("This method is called in main module");
154 tRes.tested("closeOutput()", res);
158 * Forces object environment recreation.
160 public void after() {
161 this.disposeEnvironment() ;