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 .
21 import java
.util
.List
;
23 import lib
.MultiMethodTest
;
25 import com
.sun
.star
.io
.XDataOutputStream
;
28 * Testing <code>com.sun.star.io.XDataOutputStream</code>
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>
41 * This test needs the following object relations :
43 * <li> <code>'StreamData'</code> (of type <code>Vector</code>):
44 * vector of data for writing to the stream </li>
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;
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.
60 public void before() throws RuntimeException
{
62 List
<Object
> data
= (List
<Object
>) tEnv
.getObjRelation("StreamData") ;
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();
75 if (dataElem
instanceof Byte
) {
76 ((Byte
)dataElem
).byteValue();
78 if (dataElem
instanceof Character
) {
79 ((Character
)dataElem
).charValue();
81 if (dataElem
instanceof Short
) {
82 ((Short
)dataElem
).shortValue();
84 if (dataElem
instanceof Integer
) {
85 ((Integer
)dataElem
).intValue();
87 if (dataElem
instanceof Long
) {
88 ((Long
)dataElem
).longValue();
90 if (dataElem
instanceof Float
) {
91 ((Float
)dataElem
).floatValue();
93 if (dataElem
instanceof Double
) {
94 ((Double
)dataElem
).doubleValue();
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() {
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
);
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() {
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
);
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() {
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
);
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() {
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
);
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() {
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
);
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() {
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
);
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() {
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
);
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() {
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
);
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() {
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
);
251 tRes
.tested("writeUTF()", res
);
255 * Forces object environment recreation.
258 public void after() {
259 this.disposeEnvironment() ;