1 /*
2  * This file is part of the LibreOffice project.
3  *
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/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
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 .
17  */
18 
19 package ifc.io;
20 
21 import java.util.List;
22 
23 import lib.MultiMethodTest;
24 
25 import com.sun.star.io.XDataOutputStream;
26 
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
48 */
49 public class _XDataOutputStream extends MultiMethodTest {
50 
51     public XDataOutputStream oObj = null;
52 
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.
58     */
59     @Override
before()60     public void before() throws RuntimeException {
61 
62         List<Object> data = (List<Object>) tEnv.getObjRelation("StreamData") ;
63         if (data == null) {
64             throw new RuntimeException("Object relation 'StreamData' not found.");
65         }
66 
67         // extract data from vector
68         Object dataElem = null ;
69         for (int i = 0; i < data.size(); i++) {
70             dataElem = data.get(i) ;
71 
72             if (!(dataElem instanceof Boolean   ||
73                   dataElem instanceof Byte)     ||
74                   dataElem instanceof Character ||
75                   dataElem instanceof Short     ||
76                   dataElem instanceof Integer   ||
77                   dataElem instanceof Float     ||
78                   dataElem instanceof Double)   {
79                 throw new RuntimeException("Object dataElem type not found.");
80             }
81         }
82     }
83 
84     /**
85     * Test writes some data to stream. <p>
86     * Has <b> OK </b> status if the method successfully returns
87     * and no exceptions were thrown. <p>
88     */
_writeBoolean()89     public void _writeBoolean() {
90         boolean res = true;
91         try {
92             oObj.writeBoolean(true) ;
93         } catch(com.sun.star.io.IOException e) {
94             log.println("Couldn't write Boolean to stream");
95             e.printStackTrace(log);
96             res = false;
97         }
98         tRes.tested("writeBoolean()", res) ;
99     }
100 
101     /**
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>
105     */
_writeByte()106     public void _writeByte() {
107         boolean res = true;
108         try {
109             oObj.writeByte((byte) 123);
110         } catch(com.sun.star.io.IOException e) {
111             log.println("Couldn't write Byte to stream");
112             e.printStackTrace(log);
113             res = false;
114         }
115         tRes.tested("writeByte()", res);
116     }
117 
118     /**
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>
122     */
_writeChar()123     public void _writeChar() {
124         boolean res = true;
125         try {
126             oObj.writeChar((char)12345);
127         } catch(com.sun.star.io.IOException e) {
128             log.println("Couldn't write Char to stream");
129             e.printStackTrace(log);
130             res = false;
131         }
132         tRes.tested("writeChar()", res);
133     }
134 
135     /**
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>
139     */
_writeShort()140     public void _writeShort() {
141         boolean res = true;
142         try {
143             oObj.writeShort((short)12345) ;
144         } catch(com.sun.star.io.IOException e) {
145             log.println("Couldn't write Short to stream");
146             e.printStackTrace(log);
147             res = false;
148         }
149         tRes.tested("writeShort()", res);
150     }
151 
152     /**
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>
156     */
_writeLong()157     public void _writeLong() {
158         boolean res = true;
159         try {
160             oObj.writeLong(123456);
161         } catch(com.sun.star.io.IOException e) {
162             log.println("Couldn't write Long to stream");
163             e.printStackTrace(log);
164             res = false;
165         }
166         tRes.tested("writeLong()", res);
167     }
168 
169     /**
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>
173     */
_writeHyper()174     public void _writeHyper() {
175         boolean res = true;
176         try {
177             oObj.writeHyper(123456789);
178         } catch(com.sun.star.io.IOException e) {
179             log.println("Couldn't write Hyper to stream");
180             e.printStackTrace(log);
181             res = false;
182         }
183         tRes.tested("writeHyper()", res);
184     }
185 
186     /**
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>
190     */
_writeFloat()191     public void _writeFloat() {
192         boolean res = true;
193         try {
194             oObj.writeFloat((float)1.2345);
195         } catch(com.sun.star.io.IOException e) {
196             log.println("Couldn't write Float to stream");
197             e.printStackTrace(log);
198             res = false;
199         }
200         tRes.tested("writeFloat()", res);
201     }
202 
203     /**
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>
207     */
_writeDouble()208     public void _writeDouble() {
209         boolean res = true;
210         try {
211             oObj.writeDouble(1.2345);
212         } catch(com.sun.star.io.IOException e) {
213             log.println("Couldn't write Double to stream");
214             e.printStackTrace(log);
215             res = false;
216         }
217         tRes.tested("writeDouble()", res);
218     }
219 
220     /**
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>
224     */
_writeUTF()225     public void _writeUTF() {
226         boolean res = true;
227         try {
228             oObj.writeUTF("XDataOutputStream") ;
229         } catch(com.sun.star.io.IOException e) {
230             log.println("Couldn't write String to stream");
231             e.printStackTrace(log);
232             res = false;
233         }
234         tRes.tested("writeUTF()", res);
235     }
236 
237     /**
238     * Forces object environment recreation.
239     */
240     @Override
after()241     public void after() {
242         this.disposeEnvironment() ;
243     }
244 }
245 
246