Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / io / _XOutputStream.java
blob01caa6f48d207156700a7ebd131c3d5a4e825c24
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 interface StreamChecker {
55 XInputStream getInStream();
56 void resetStreams();
59 @Override
60 protected void before() {
61 checker = (StreamChecker)
62 tEnv.getObjRelation("XOutputStream.StreamChecker");
63 if (checker == null) throw
64 new StatusException(Status.failed(
65 "Couldn't get relation 'XOutputStream.StreamChecker'"));
67 data = (byte[])tEnv.getObjRelation("ByteData");
68 if (data == null) throw
69 new StatusException(Status.failed(
70 "Couldn't get relation 'ByteData'"));
72 /**
73 * Test writes data to stream. <p>
74 * Has <b> OK </b> status if the method successfully returns
75 * and no exceptions were thrown. <p>
77 public void _writeBytes() {
78 boolean res = true;
79 try {
80 oObj.writeBytes(data);
81 } catch (com.sun.star.io.IOException e) {
82 e.printStackTrace(log) ;
83 res = false;
86 XInputStream xInStream = checker.getInStream();
87 byte[][] readData = new byte[1][data.length];
88 try {
89 xInStream.readBytes(readData, data.length);
90 } catch(com.sun.star.io.IOException e) {
91 log.println("Couldn't read data:" + e);
92 res = false;
95 for(int i = 0; i < readData[0].length; i++) {
96 log.println("Expected: "+data[i]+", actual is "+readData[0][i]);
97 res &= readData[0][i] == data[i];
100 tRes.tested("writeBytes()", res);
104 * Test flushes out data from stream. <p>
105 * Has <b> OK </b> status if the method successfully returns
106 * and no exceptions were thrown. <p>
107 * The following method tests are to be completed successfully before :
108 * <ul>
109 * <li> <code> writeBytes() </code></li>
110 * </ul>
112 public void _flush() {
113 requiredMethod("writeBytes()");
115 boolean res;
116 try {
117 oObj.flush();
118 res = true;
119 } catch (com.sun.star.io.IOException e) {
120 e.printStackTrace(log) ;
121 res = false;
124 tRes.tested("flush()", res);
128 * Test calls the method. <p>
129 * Has <b> OK </b> status if the method successfully returns
130 * and no exceptions were thrown. <p>
131 * The following method tests are to be completed successfully before :
132 * <ul>
133 * <li> <code> writeBytes() </code></li>
134 * </ul>
135 * The following method tests are to be executed before :
136 * <ul>
137 * <li><code> flush() </code></li>
138 * </ul>
140 public void _closeOutput() {
141 requiredMethod("writeBytes()");
142 executeMethod("flush()");
144 boolean res;
145 try {
146 oObj.closeOutput();
147 res = true;
148 } catch (com.sun.star.io.IOException e) {
149 e.printStackTrace(log);
150 res = false;
153 log.println("This method is called in main module");
155 tRes.tested("closeOutput()", res);
159 * Forces object environment recreation.
161 @Override
162 public void after() {
163 this.disposeEnvironment() ;