1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.io;
25 
26 import java.util.Vector;
27 
28 import lib.MultiMethodTest;
29 
30 import com.sun.star.io.XDataOutputStream;
31 
32 /**
33 * Testing <code>com.sun.star.io.XDataOutputStream</code>
34 * interface methods:
35 * <ul>
36 *   <li><code>writeBoolean()</code></li>
37 *   <li><code>writeByte()</code></li>
38 *   <li><code>writeChar()</code></li>
39 *   <li><code>writeShort()</code></li>
40 *   <li><code>writeLong()</code></li>
41 *   <li><code>writeHyper()</code></li>
42 *   <li><code>writeFloat()</code></li>
43 *   <li><code>writeDouble()</code></li>
44 *   <li><code>writeUTF()</code></li>
45 * </ul> <p>
46 * This test needs the following object relations :
47 * <ul>
48 *  <li> <code>'StreamData'</code> (of type <code>Vector</code>):
49 *   vector of data for writing to the stream </li>
50 * <ul> <p>
51 * After test completion object environment has to be recreated.
52 * @see com.sun.star.io.XDataOutputStream
53 */
54 public class _XDataOutputStream extends MultiMethodTest {
55 
56     public XDataOutputStream oObj = null;
57 
58     // values that are written
59     private boolean writeBoolean;
60     private byte writeByte;
61     private char writeChar;
62     private double writeDouble;
63     private float writeFloat;
64     private long writeHyper;
65     private int writeLong;
66     private short writeShort;
67     private String writeUTF;
68 
69 
70     /**
71     * Retrieves object relation <code>'StreamData'</code>
72     * and executes methods of interface depending of data in stream.
73     * If relation or data of some type in stream not found then
74     * tests of corresponding methods are skipped.
75     */
before()76     public void before() throws RuntimeException {
77 
78         Vector data = (Vector) tEnv.getObjRelation("StreamData") ;
79         if (data == null) {
80             throw new RuntimeException("Object relation 'StreamData' not found.");
81         }
82 
83         // extract data from vector
84         Object dataElem = null ;
85         for (int i = 0; i < data.size(); i++) {
86             dataElem = data.get(i) ;
87 
88             if (dataElem instanceof Boolean) {
89                 writeBoolean = ((Boolean)dataElem).booleanValue();
90             } else
91             if (dataElem instanceof Byte) {
92                 writeByte = ((Byte)dataElem).byteValue();
93             } else
94             if (dataElem instanceof Character) {
95                 writeChar = ((Character)dataElem).charValue();
96             } else
97             if (dataElem instanceof Short) {
98                 writeShort = ((Short)dataElem).shortValue();
99             } else
100             if (dataElem instanceof Integer) {
101                 writeLong = ((Integer)dataElem).intValue();
102             } else
103             if (dataElem instanceof Long) {
104                 writeHyper = ((Long)dataElem).longValue();
105             } else
106             if (dataElem instanceof Float) {
107                 writeFloat = ((Float)dataElem).floatValue();
108             } else
109             if (dataElem instanceof Double) {
110                 writeDouble = ((Double)dataElem).doubleValue();
111             } else
112             if (dataElem instanceof String) {
113                 writeUTF = (String)dataElem;
114             }
115         }
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     */
_writeBoolean()123     public void _writeBoolean() {
124         boolean res = true;
125         try {
126             oObj.writeBoolean(true) ;
127         } catch(com.sun.star.io.IOException e) {
128             log.println("Couldn't write Boolean to stream");
129             e.printStackTrace(log);
130             res = false;
131         }
132         tRes.tested("writeBoolean()", 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     */
_writeByte()140     public void _writeByte() {
141         boolean res = true;
142         try {
143             oObj.writeByte((byte) 123);
144         } catch(com.sun.star.io.IOException e) {
145             log.println("Couldn't write Byte to stream");
146             e.printStackTrace(log);
147             res = false;
148         }
149         tRes.tested("writeByte()", 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     */
_writeChar()157     public void _writeChar() {
158         boolean res = true;
159         try {
160             oObj.writeChar((char)12345);
161         } catch(com.sun.star.io.IOException e) {
162             log.println("Couldn't write Char to stream");
163             e.printStackTrace(log);
164             res = false;
165         }
166         tRes.tested("writeChar()", 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     */
_writeShort()174     public void _writeShort() {
175         boolean res = true;
176         try {
177             oObj.writeShort((short)12345) ;
178         } catch(com.sun.star.io.IOException e) {
179             log.println("Couldn't write Short to stream");
180             e.printStackTrace(log);
181             res = false;
182         }
183         tRes.tested("writeShort()", 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     */
_writeLong()191     public void _writeLong() {
192         boolean res = true;
193         try {
194             oObj.writeLong(123456);
195         } catch(com.sun.star.io.IOException e) {
196             log.println("Couldn't write Long to stream");
197             e.printStackTrace(log);
198             res = false;
199         }
200         tRes.tested("writeLong()", 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     */
_writeHyper()208     public void _writeHyper() {
209         boolean res = true;
210         try {
211             oObj.writeHyper(123456789);
212         } catch(com.sun.star.io.IOException e) {
213             log.println("Couldn't write Hyper to stream");
214             e.printStackTrace(log);
215             res = false;
216         }
217         tRes.tested("writeHyper()", 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     */
_writeFloat()225     public void _writeFloat() {
226         boolean res = true;
227         try {
228             oObj.writeFloat((float)1.2345);
229         } catch(com.sun.star.io.IOException e) {
230             log.println("Couldn't write Float to stream");
231             e.printStackTrace(log);
232             res = false;
233         }
234         tRes.tested("writeFloat()", res);
235     }
236 
237     /**
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>
241     */
_writeDouble()242     public void _writeDouble() {
243         boolean res = true;
244         try {
245             oObj.writeDouble(1.2345);
246         } catch(com.sun.star.io.IOException e) {
247             log.println("Couldn't write Double to stream");
248             e.printStackTrace(log);
249             res = false;
250         }
251         tRes.tested("writeDouble()", res);
252     }
253 
254     /**
255     * Test writes some data to stream. <p>
256     * Has <b> OK </b> status if the method successfully returns
257     * and no exceptions were thrown. <p>
258     */
_writeUTF()259     public void _writeUTF() {
260         boolean res = true;
261         try {
262             oObj.writeUTF("XDataOutputStream") ;
263         } catch(com.sun.star.io.IOException e) {
264             log.println("Couldn't write String to stream");
265             e.printStackTrace(log);
266             res = false;
267         }
268         tRes.tested("writeUTF()", res);
269     }
270 
271     /**
272     * Forces object environment recreation.
273     */
after()274     public void after() {
275         this.disposeEnvironment() ;
276     }
277 }
278 
279