merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / io / _XDataOutputStream.java
blob5608a01351e952b97f6a3d4318a6fd25fd9aa253
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: _XDataOutputStream.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 java.util.Vector;
35 import lib.MultiMethodTest;
37 import com.sun.star.io.XDataOutputStream;
39 /**
40 * Testing <code>com.sun.star.io.XDataOutputStream</code>
41 * interface methods:
42 * <ul>
43 * <li><code>writeBoolean()</code></li>
44 * <li><code>writeByte()</code></li>
45 * <li><code>writeChar()</code></li>
46 * <li><code>writeShort()</code></li>
47 * <li><code>writeLong()</code></li>
48 * <li><code>writeHyper()</code></li>
49 * <li><code>writeFloat()</code></li>
50 * <li><code>writeDouble()</code></li>
51 * <li><code>writeUTF()</code></li>
52 * </ul> <p>
53 * This test needs the following object relations :
54 * <ul>
55 * <li> <code>'StreamData'</code> (of type <code>Vector</code>):
56 * vector of data for writing to the stream </li>
57 * <ul> <p>
58 * After test completion object environment has to be recreated.
59 * @see com.sun.star.io.XDataOutputStream
61 public class _XDataOutputStream extends MultiMethodTest {
63 public XDataOutputStream oObj = null;
65 // values that are written
66 private boolean writeBoolean;
67 private byte writeByte;
68 private char writeChar;
69 private double writeDouble;
70 private float writeFloat;
71 private long writeHyper;
72 private int writeLong;
73 private short writeShort;
74 private String writeUTF;
77 /**
78 * Retrieves object relation <code>'StreamData'</code>
79 * and executes methods of interface depending of data in stream.
80 * If relation or data of some type in stream not found then
81 * tests of corresponding methods are skipped.
83 public void before() throws RuntimeException {
85 Vector data = (Vector) tEnv.getObjRelation("StreamData") ;
86 if (data == null) {
87 throw new RuntimeException("Object relation 'StreamData' not found.");
90 // extract data from vector
91 Object dataElem = null ;
92 for (int i = 0; i < data.size(); i++) {
93 dataElem = data.get(i) ;
95 if (dataElem instanceof Boolean) {
96 writeBoolean = ((Boolean)dataElem).booleanValue();
97 } else
98 if (dataElem instanceof Byte) {
99 writeByte = ((Byte)dataElem).byteValue();
100 } else
101 if (dataElem instanceof Character) {
102 writeChar = ((Character)dataElem).charValue();
103 } else
104 if (dataElem instanceof Short) {
105 writeShort = ((Short)dataElem).shortValue();
106 } else
107 if (dataElem instanceof Integer) {
108 writeLong = ((Integer)dataElem).intValue();
109 } else
110 if (dataElem instanceof Long) {
111 writeHyper = ((Long)dataElem).longValue();
112 } else
113 if (dataElem instanceof Float) {
114 writeFloat = ((Float)dataElem).floatValue();
115 } else
116 if (dataElem instanceof Double) {
117 writeDouble = ((Double)dataElem).doubleValue();
118 } else
119 if (dataElem instanceof String) {
120 writeUTF = (String)dataElem;
126 * Test writes some data to stream. <p>
127 * Has <b> OK </b> status if the method successfully returns
128 * and no exceptions were thrown. <p>
130 public void _writeBoolean() {
131 boolean res = true;
132 try {
133 oObj.writeBoolean(true) ;
134 } catch(com.sun.star.io.IOException e) {
135 log.println("Couldn't write Boolean to stream");
136 e.printStackTrace(log);
137 res = false;
139 tRes.tested("writeBoolean()", res) ;
143 * Test writes some data to stream. <p>
144 * Has <b> OK </b> status if the method successfully returns
145 * and no exceptions were thrown. <p>
147 public void _writeByte() {
148 boolean res = true;
149 try {
150 oObj.writeByte((byte) 123);
151 } catch(com.sun.star.io.IOException e) {
152 log.println("Couldn't write Byte to stream");
153 e.printStackTrace(log);
154 res = false;
156 tRes.tested("writeByte()", res);
160 * Test writes some data to stream. <p>
161 * Has <b> OK </b> status if the method successfully returns
162 * and no exceptions were thrown. <p>
164 public void _writeChar() {
165 boolean res = true;
166 try {
167 oObj.writeChar((char)12345);
168 } catch(com.sun.star.io.IOException e) {
169 log.println("Couldn't write Char to stream");
170 e.printStackTrace(log);
171 res = false;
173 tRes.tested("writeChar()", res);
177 * Test writes some data to stream. <p>
178 * Has <b> OK </b> status if the method successfully returns
179 * and no exceptions were thrown. <p>
181 public void _writeShort() {
182 boolean res = true;
183 try {
184 oObj.writeShort((short)12345) ;
185 } catch(com.sun.star.io.IOException e) {
186 log.println("Couldn't write Short to stream");
187 e.printStackTrace(log);
188 res = false;
190 tRes.tested("writeShort()", res);
194 * Test writes some data to stream. <p>
195 * Has <b> OK </b> status if the method successfully returns
196 * and no exceptions were thrown. <p>
198 public void _writeLong() {
199 boolean res = true;
200 try {
201 oObj.writeLong(123456);
202 } catch(com.sun.star.io.IOException e) {
203 log.println("Couldn't write Long to stream");
204 e.printStackTrace(log);
205 res = false;
207 tRes.tested("writeLong()", res);
211 * Test writes some data to stream. <p>
212 * Has <b> OK </b> status if the method successfully returns
213 * and no exceptions were thrown. <p>
215 public void _writeHyper() {
216 boolean res = true;
217 try {
218 oObj.writeHyper(123456789);
219 } catch(com.sun.star.io.IOException e) {
220 log.println("Couldn't write Hyper to stream");
221 e.printStackTrace(log);
222 res = false;
224 tRes.tested("writeHyper()", res);
228 * Test writes some data to stream. <p>
229 * Has <b> OK </b> status if the method successfully returns
230 * and no exceptions were thrown. <p>
232 public void _writeFloat() {
233 boolean res = true;
234 try {
235 oObj.writeFloat((float)1.2345);
236 } catch(com.sun.star.io.IOException e) {
237 log.println("Couldn't write Float to stream");
238 e.printStackTrace(log);
239 res = false;
241 tRes.tested("writeFloat()", res);
245 * Test writes some data to stream. <p>
246 * Has <b> OK </b> status if the method successfully returns
247 * and no exceptions were thrown. <p>
249 public void _writeDouble() {
250 boolean res = true;
251 try {
252 oObj.writeDouble(1.2345);
253 } catch(com.sun.star.io.IOException e) {
254 log.println("Couldn't write Double to stream");
255 e.printStackTrace(log);
256 res = false;
258 tRes.tested("writeDouble()", res);
262 * Test writes some data to stream. <p>
263 * Has <b> OK </b> status if the method successfully returns
264 * and no exceptions were thrown. <p>
266 public void _writeUTF() {
267 boolean res = true;
268 try {
269 oObj.writeUTF("XDataOutputStream") ;
270 } catch(com.sun.star.io.IOException e) {
271 log.println("Couldn't write String to stream");
272 e.printStackTrace(log);
273 res = false;
275 tRes.tested("writeUTF()", res);
279 * Forces object environment recreation.
281 public void after() {
282 this.disposeEnvironment() ;