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.
59 @SuppressWarnings("unchecked")
61 public void before() throws RuntimeException
{
63 List
<Object
> data
= (List
<Object
>) tEnv
.getObjRelation("StreamData") ;
65 throw new RuntimeException("Object relation 'StreamData' not found.");
68 // extract data from vector
69 Object dataElem
= null ;
70 for (int i
= 0; i
< data
.size(); i
++) {
71 dataElem
= data
.get(i
) ;
73 if (!(dataElem
instanceof Boolean
||
74 dataElem
instanceof Byte
) ||
75 dataElem
instanceof Character
||
76 dataElem
instanceof Short
||
77 dataElem
instanceof Integer
||
78 dataElem
instanceof Float
||
79 dataElem
instanceof Double
) {
80 throw new RuntimeException("Object dataElem type not found.");
86 * Test writes some data to stream. <p>
87 * Has <b> OK </b> status if the method successfully returns
88 * and no exceptions were thrown. <p>
90 public void _writeBoolean() {
93 oObj
.writeBoolean(true) ;
94 } catch(com
.sun
.star
.io
.IOException e
) {
95 log
.println("Couldn't write Boolean to stream");
96 e
.printStackTrace(log
);
99 tRes
.tested("writeBoolean()", res
) ;
103 * Test writes some data to stream. <p>
104 * Has <b> OK </b> status if the method successfully returns
105 * and no exceptions were thrown. <p>
107 public void _writeByte() {
110 oObj
.writeByte((byte) 123);
111 } catch(com
.sun
.star
.io
.IOException e
) {
112 log
.println("Couldn't write Byte to stream");
113 e
.printStackTrace(log
);
116 tRes
.tested("writeByte()", res
);
120 * Test writes some data to stream. <p>
121 * Has <b> OK </b> status if the method successfully returns
122 * and no exceptions were thrown. <p>
124 public void _writeChar() {
127 oObj
.writeChar((char)12345);
128 } catch(com
.sun
.star
.io
.IOException e
) {
129 log
.println("Couldn't write Char to stream");
130 e
.printStackTrace(log
);
133 tRes
.tested("writeChar()", res
);
137 * Test writes some data to stream. <p>
138 * Has <b> OK </b> status if the method successfully returns
139 * and no exceptions were thrown. <p>
141 public void _writeShort() {
144 oObj
.writeShort((short)12345) ;
145 } catch(com
.sun
.star
.io
.IOException e
) {
146 log
.println("Couldn't write Short to stream");
147 e
.printStackTrace(log
);
150 tRes
.tested("writeShort()", res
);
154 * Test writes some data to stream. <p>
155 * Has <b> OK </b> status if the method successfully returns
156 * and no exceptions were thrown. <p>
158 public void _writeLong() {
161 oObj
.writeLong(123456);
162 } catch(com
.sun
.star
.io
.IOException e
) {
163 log
.println("Couldn't write Long to stream");
164 e
.printStackTrace(log
);
167 tRes
.tested("writeLong()", res
);
171 * Test writes some data to stream. <p>
172 * Has <b> OK </b> status if the method successfully returns
173 * and no exceptions were thrown. <p>
175 public void _writeHyper() {
178 oObj
.writeHyper(123456789);
179 } catch(com
.sun
.star
.io
.IOException e
) {
180 log
.println("Couldn't write Hyper to stream");
181 e
.printStackTrace(log
);
184 tRes
.tested("writeHyper()", res
);
188 * Test writes some data to stream. <p>
189 * Has <b> OK </b> status if the method successfully returns
190 * and no exceptions were thrown. <p>
192 public void _writeFloat() {
195 oObj
.writeFloat((float)1.2345);
196 } catch(com
.sun
.star
.io
.IOException e
) {
197 log
.println("Couldn't write Float to stream");
198 e
.printStackTrace(log
);
201 tRes
.tested("writeFloat()", res
);
205 * Test writes some data to stream. <p>
206 * Has <b> OK </b> status if the method successfully returns
207 * and no exceptions were thrown. <p>
209 public void _writeDouble() {
212 oObj
.writeDouble(1.2345);
213 } catch(com
.sun
.star
.io
.IOException e
) {
214 log
.println("Couldn't write Double to stream");
215 e
.printStackTrace(log
);
218 tRes
.tested("writeDouble()", res
);
222 * Test writes some data to stream. <p>
223 * Has <b> OK </b> status if the method successfully returns
224 * and no exceptions were thrown. <p>
226 public void _writeUTF() {
229 oObj
.writeUTF("XDataOutputStream") ;
230 } catch(com
.sun
.star
.io
.IOException e
) {
231 log
.println("Couldn't write String to stream");
232 e
.printStackTrace(log
);
235 tRes
.tested("writeUTF()", res
);
239 * Forces object environment recreation.
242 public void after() {
243 this.disposeEnvironment() ;