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