Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / io / _XDataOutputStream.java
blob51dcff41c2f06dac914445ed834316d969e59c50
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 java.util.List;
23 import lib.MultiMethodTest;
25 import com.sun.star.io.XDataOutputStream;
27 /**
28 * Testing <code>com.sun.star.io.XDataOutputStream</code>
29 * interface methods:
30 * <ul>
31 * <li><code>writeBoolean()</code></li>
32 * <li><code>writeByte()</code></li>
33 * <li><code>writeChar()</code></li>
34 * <li><code>writeShort()</code></li>
35 * <li><code>writeLong()</code></li>
36 * <li><code>writeHyper()</code></li>
37 * <li><code>writeFloat()</code></li>
38 * <li><code>writeDouble()</code></li>
39 * <li><code>writeUTF()</code></li>
40 * </ul> <p>
41 * This test needs the following object relations :
42 * <ul>
43 * <li> <code>'StreamData'</code> (of type <code>Vector</code>):
44 * vector of data for writing to the stream </li>
45 * <ul> <p>
46 * After test completion object environment has to be recreated.
47 * @see com.sun.star.io.XDataOutputStream
49 public class _XDataOutputStream extends MultiMethodTest {
51 public XDataOutputStream oObj = null;
53 /**
54 * Retrieves object relation <code>'StreamData'</code>
55 * and executes methods of interface depending of data in stream.
56 * If relation or data of some type in stream not found then
57 * tests of corresponding methods are skipped.
59 @Override
60 public void before() throws RuntimeException {
62 List<Object> data = (List<Object>) tEnv.getObjRelation("StreamData") ;
63 if (data == null) {
64 throw new RuntimeException("Object relation 'StreamData' not found.");
67 // extract data from vector
68 Object dataElem = null ;
69 for (int i = 0; i < data.size(); i++) {
70 dataElem = data.get(i) ;
72 if (dataElem instanceof Boolean) {
73 ((Boolean)dataElem).booleanValue();
74 } else
75 if (dataElem instanceof Byte) {
76 ((Byte)dataElem).byteValue();
77 } else
78 if (dataElem instanceof Character) {
79 ((Character)dataElem).charValue();
80 } else
81 if (dataElem instanceof Short) {
82 ((Short)dataElem).shortValue();
83 } else
84 if (dataElem instanceof Integer) {
85 ((Integer)dataElem).intValue();
86 } else
87 if (dataElem instanceof Long) {
88 ((Long)dataElem).longValue();
89 } else
90 if (dataElem instanceof Float) {
91 ((Float)dataElem).floatValue();
92 } else
93 if (dataElem instanceof Double) {
94 ((Double)dataElem).doubleValue();
95 } else
96 if (dataElem instanceof String) {
102 * Test writes some data to stream. <p>
103 * Has <b> OK </b> status if the method successfully returns
104 * and no exceptions were thrown. <p>
106 public void _writeBoolean() {
107 boolean res = true;
108 try {
109 oObj.writeBoolean(true) ;
110 } catch(com.sun.star.io.IOException e) {
111 log.println("Couldn't write Boolean to stream");
112 e.printStackTrace(log);
113 res = false;
115 tRes.tested("writeBoolean()", res) ;
119 * Test writes some data to stream. <p>
120 * Has <b> OK </b> status if the method successfully returns
121 * and no exceptions were thrown. <p>
123 public void _writeByte() {
124 boolean res = true;
125 try {
126 oObj.writeByte((byte) 123);
127 } catch(com.sun.star.io.IOException e) {
128 log.println("Couldn't write Byte to stream");
129 e.printStackTrace(log);
130 res = false;
132 tRes.tested("writeByte()", res);
136 * Test writes some data to stream. <p>
137 * Has <b> OK </b> status if the method successfully returns
138 * and no exceptions were thrown. <p>
140 public void _writeChar() {
141 boolean res = true;
142 try {
143 oObj.writeChar((char)12345);
144 } catch(com.sun.star.io.IOException e) {
145 log.println("Couldn't write Char to stream");
146 e.printStackTrace(log);
147 res = false;
149 tRes.tested("writeChar()", res);
153 * Test writes some data to stream. <p>
154 * Has <b> OK </b> status if the method successfully returns
155 * and no exceptions were thrown. <p>
157 public void _writeShort() {
158 boolean res = true;
159 try {
160 oObj.writeShort((short)12345) ;
161 } catch(com.sun.star.io.IOException e) {
162 log.println("Couldn't write Short to stream");
163 e.printStackTrace(log);
164 res = false;
166 tRes.tested("writeShort()", res);
170 * Test writes some data to stream. <p>
171 * Has <b> OK </b> status if the method successfully returns
172 * and no exceptions were thrown. <p>
174 public void _writeLong() {
175 boolean res = true;
176 try {
177 oObj.writeLong(123456);
178 } catch(com.sun.star.io.IOException e) {
179 log.println("Couldn't write Long to stream");
180 e.printStackTrace(log);
181 res = false;
183 tRes.tested("writeLong()", res);
187 * Test writes some data to stream. <p>
188 * Has <b> OK </b> status if the method successfully returns
189 * and no exceptions were thrown. <p>
191 public void _writeHyper() {
192 boolean res = true;
193 try {
194 oObj.writeHyper(123456789);
195 } catch(com.sun.star.io.IOException e) {
196 log.println("Couldn't write Hyper to stream");
197 e.printStackTrace(log);
198 res = false;
200 tRes.tested("writeHyper()", res);
204 * Test writes some data to stream. <p>
205 * Has <b> OK </b> status if the method successfully returns
206 * and no exceptions were thrown. <p>
208 public void _writeFloat() {
209 boolean res = true;
210 try {
211 oObj.writeFloat((float)1.2345);
212 } catch(com.sun.star.io.IOException e) {
213 log.println("Couldn't write Float to stream");
214 e.printStackTrace(log);
215 res = false;
217 tRes.tested("writeFloat()", res);
221 * Test writes some data to stream. <p>
222 * Has <b> OK </b> status if the method successfully returns
223 * and no exceptions were thrown. <p>
225 public void _writeDouble() {
226 boolean res = true;
227 try {
228 oObj.writeDouble(1.2345);
229 } catch(com.sun.star.io.IOException e) {
230 log.println("Couldn't write Double to stream");
231 e.printStackTrace(log);
232 res = false;
234 tRes.tested("writeDouble()", res);
238 * Test writes some data to stream. <p>
239 * Has <b> OK </b> status if the method successfully returns
240 * and no exceptions were thrown. <p>
242 public void _writeUTF() {
243 boolean res = true;
244 try {
245 oObj.writeUTF("XDataOutputStream") ;
246 } catch(com.sun.star.io.IOException e) {
247 log.println("Couldn't write String to stream");
248 e.printStackTrace(log);
249 res = false;
251 tRes.tested("writeUTF()", res);
255 * Forces object environment recreation.
257 @Override
258 public void after() {
259 this.disposeEnvironment() ;