1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.io;
29 
30 import java.util.Vector;
31 
32 import lib.MultiMethodTest;
33 
34 import com.sun.star.io.XDataOutputStream;
35 
36 /**
37 * Testing <code>com.sun.star.io.XDataOutputStream</code>
38 * interface methods:
39 * <ul>
40 *   <li><code>writeBoolean()</code></li>
41 *   <li><code>writeByte()</code></li>
42 *   <li><code>writeChar()</code></li>
43 *   <li><code>writeShort()</code></li>
44 *   <li><code>writeLong()</code></li>
45 *   <li><code>writeHyper()</code></li>
46 *   <li><code>writeFloat()</code></li>
47 *   <li><code>writeDouble()</code></li>
48 *   <li><code>writeUTF()</code></li>
49 * </ul> <p>
50 * This test needs the following object relations :
51 * <ul>
52 *  <li> <code>'StreamData'</code> (of type <code>Vector</code>):
53 *   vector of data for writing to the stream </li>
54 * <ul> <p>
55 * After test completion object environment has to be recreated.
56 * @see com.sun.star.io.XDataOutputStream
57 */
58 public class _XDataOutputStream extends MultiMethodTest {
59 
60     public XDataOutputStream oObj = null;
61 
62     // values that are written
63     private boolean writeBoolean;
64     private byte writeByte;
65     private char writeChar;
66     private double writeDouble;
67     private float writeFloat;
68     private long writeHyper;
69     private int writeLong;
70     private short writeShort;
71     private String writeUTF;
72 
73 
74     /**
75     * Retrieves object relation <code>'StreamData'</code>
76     * and executes methods of interface depending of data in stream.
77     * If relation or data of some type in stream not found then
78     * tests of corresponding methods are skipped.
79     */
80     public void before() throws RuntimeException {
81 
82         Vector data = (Vector) tEnv.getObjRelation("StreamData") ;
83         if (data == null) {
84             throw new RuntimeException("Object relation 'StreamData' not found.");
85         }
86 
87         // extract data from vector
88         Object dataElem = null ;
89         for (int i = 0; i < data.size(); i++) {
90             dataElem = data.get(i) ;
91 
92             if (dataElem instanceof Boolean) {
93                 writeBoolean = ((Boolean)dataElem).booleanValue();
94             } else
95             if (dataElem instanceof Byte) {
96                 writeByte = ((Byte)dataElem).byteValue();
97             } else
98             if (dataElem instanceof Character) {
99                 writeChar = ((Character)dataElem).charValue();
100             } else
101             if (dataElem instanceof Short) {
102                 writeShort = ((Short)dataElem).shortValue();
103             } else
104             if (dataElem instanceof Integer) {
105                 writeLong = ((Integer)dataElem).intValue();
106             } else
107             if (dataElem instanceof Long) {
108                 writeHyper = ((Long)dataElem).longValue();
109             } else
110             if (dataElem instanceof Float) {
111                 writeFloat = ((Float)dataElem).floatValue();
112             } else
113             if (dataElem instanceof Double) {
114                 writeDouble = ((Double)dataElem).doubleValue();
115             } else
116             if (dataElem instanceof String) {
117                 writeUTF = (String)dataElem;
118             }
119         }
120     }
121 
122     /**
123     * Test writes some data to stream. <p>
124     * Has <b> OK </b> status if the method successfully returns
125     * and no exceptions were thrown. <p>
126     */
127     public void _writeBoolean() {
128         boolean res = true;
129         try {
130             oObj.writeBoolean(true) ;
131         } catch(com.sun.star.io.IOException e) {
132             log.println("Couldn't write Boolean to stream");
133             e.printStackTrace(log);
134             res = false;
135         }
136         tRes.tested("writeBoolean()", res) ;
137     }
138 
139     /**
140     * Test writes some data to stream. <p>
141     * Has <b> OK </b> status if the method successfully returns
142     * and no exceptions were thrown. <p>
143     */
144     public void _writeByte() {
145         boolean res = true;
146         try {
147             oObj.writeByte((byte) 123);
148         } catch(com.sun.star.io.IOException e) {
149             log.println("Couldn't write Byte to stream");
150             e.printStackTrace(log);
151             res = false;
152         }
153         tRes.tested("writeByte()", res);
154     }
155 
156     /**
157     * Test writes some data to stream. <p>
158     * Has <b> OK </b> status if the method successfully returns
159     * and no exceptions were thrown. <p>
160     */
161     public void _writeChar() {
162         boolean res = true;
163         try {
164             oObj.writeChar((char)12345);
165         } catch(com.sun.star.io.IOException e) {
166             log.println("Couldn't write Char to stream");
167             e.printStackTrace(log);
168             res = false;
169         }
170         tRes.tested("writeChar()", res);
171     }
172 
173     /**
174     * Test writes some data to stream. <p>
175     * Has <b> OK </b> status if the method successfully returns
176     * and no exceptions were thrown. <p>
177     */
178     public void _writeShort() {
179         boolean res = true;
180         try {
181             oObj.writeShort((short)12345) ;
182         } catch(com.sun.star.io.IOException e) {
183             log.println("Couldn't write Short to stream");
184             e.printStackTrace(log);
185             res = false;
186         }
187         tRes.tested("writeShort()", res);
188     }
189 
190     /**
191     * Test writes some data to stream. <p>
192     * Has <b> OK </b> status if the method successfully returns
193     * and no exceptions were thrown. <p>
194     */
195     public void _writeLong() {
196         boolean res = true;
197         try {
198             oObj.writeLong(123456);
199         } catch(com.sun.star.io.IOException e) {
200             log.println("Couldn't write Long to stream");
201             e.printStackTrace(log);
202             res = false;
203         }
204         tRes.tested("writeLong()", res);
205     }
206 
207     /**
208     * Test writes some data to stream. <p>
209     * Has <b> OK </b> status if the method successfully returns
210     * and no exceptions were thrown. <p>
211     */
212     public void _writeHyper() {
213         boolean res = true;
214         try {
215             oObj.writeHyper(123456789);
216         } catch(com.sun.star.io.IOException e) {
217             log.println("Couldn't write Hyper to stream");
218             e.printStackTrace(log);
219             res = false;
220         }
221         tRes.tested("writeHyper()", res);
222     }
223 
224     /**
225     * Test writes some data to stream. <p>
226     * Has <b> OK </b> status if the method successfully returns
227     * and no exceptions were thrown. <p>
228     */
229     public void _writeFloat() {
230         boolean res = true;
231         try {
232             oObj.writeFloat((float)1.2345);
233         } catch(com.sun.star.io.IOException e) {
234             log.println("Couldn't write Float to stream");
235             e.printStackTrace(log);
236             res = false;
237         }
238         tRes.tested("writeFloat()", res);
239     }
240 
241     /**
242     * Test writes some data to stream. <p>
243     * Has <b> OK </b> status if the method successfully returns
244     * and no exceptions were thrown. <p>
245     */
246     public void _writeDouble() {
247         boolean res = true;
248         try {
249             oObj.writeDouble(1.2345);
250         } catch(com.sun.star.io.IOException e) {
251             log.println("Couldn't write Double to stream");
252             e.printStackTrace(log);
253             res = false;
254         }
255         tRes.tested("writeDouble()", res);
256     }
257 
258     /**
259     * Test writes some data to stream. <p>
260     * Has <b> OK </b> status if the method successfully returns
261     * and no exceptions were thrown. <p>
262     */
263     public void _writeUTF() {
264         boolean res = true;
265         try {
266             oObj.writeUTF("XDataOutputStream") ;
267         } catch(com.sun.star.io.IOException e) {
268             log.println("Couldn't write String to stream");
269             e.printStackTrace(log);
270             res = false;
271         }
272         tRes.tested("writeUTF()", res);
273     }
274 
275     /**
276     * Forces object environment recreation.
277     */
278     public void after() {
279         this.disposeEnvironment() ;
280     }
281 }
282 
283