1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
package ifc.io;
import java.util.Vector;
import lib.MultiMethodTest;
import lib.Status;
import lib.StatusException;
import com.sun.star.io.XDataInputStream;
import com.sun.star.io.XDataOutputStream;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
/**
* Testing <code>com.sun.star.io.XDataInputStream</code>
* interface methods:
* <ul>
* <li><code>readBoolean()</code></li>
* <li><code>readByte()</code></li>
* <li><code>readChar()</code></li>
* <li><code>readShort()</code></li>
* <li><code>readLong()</code></li>
* <li><code>readHyper()</code></li>
* <li><code>readFloat()</code></li>
* <li><code>readDouble()</code></li>
* <li><code>readUTF()</code></li>
* </ul> <p>
* This test needs the following object relations :
* <ul>
* <li> <code>'StreamData'</code> (of type <code>Vector</code>):
* vector of data for comparing with data that obtained from stream </li>
* <li> <code>'StreamWriter'</code> (of type <code>XDataOutputStream</code>):
* a possiblitiy to write values to the stream. </li>
* <ul> <p>
* After test completion object environment has to be recreated.
* @see com.sun.star.io.XDataInputStream
* @see java.util.Vector
*/
public class _XDataInputStream extends MultiMethodTest {
public XDataInputStream oObj = null;
public XDataOutputStream oStream = null;
// values that are written
private boolean writeBoolean;
private byte writeByte;
private char writeChar;
private double writeDouble;
private float writeFloat;
private long writeHyper;
private int writeLong;
private short writeShort;
private String writeUTF;
/**
* Retrieves relations. From relation 'StreamData' extracts
* data of different types and fills the appropriate variables.
* @throws StatusException If one of relations not found.
*/
public void before(){
XInterface x = (XInterface)tEnv.getObjRelation("StreamWriter") ;
oStream = (XDataOutputStream)UnoRuntime.queryInterface(
XDataOutputStream.class, x);
Vector data = (Vector) tEnv.getObjRelation("StreamData") ;
if (data == null || oStream == null) {
throw new StatusException(Status.failed("Object relation not found."));
}
// extract data from vector
Object dataElem = null ;
for (int i = 0; i < data.size(); i++) {
dataElem = data.get(i) ;
if (dataElem instanceof Boolean) {
writeBoolean = ((Boolean)dataElem).booleanValue();
} else
if (dataElem instanceof Byte) {
writeByte = ((Byte)dataElem).byteValue();
} else
if (dataElem instanceof Character) {
writeChar = ((Character)dataElem).charValue();
} else
if (dataElem instanceof Short) {
writeShort = ((Short)dataElem).shortValue();
} else
if (dataElem instanceof Integer) {
writeLong = ((Integer)dataElem).intValue();
} else
if (dataElem instanceof Long) {
writeHyper = ((Long)dataElem).longValue();
} else
if (dataElem instanceof Float) {
writeFloat = ((Float)dataElem).floatValue();
} else
if (dataElem instanceof Double) {
writeDouble = ((Double)dataElem).doubleValue();
} else
if (dataElem instanceof String) {
writeUTF = (String)dataElem;
}
}
}
/**
* First writes a value to outStream then reads it from input. <p>
*
* Has <b> OK </b> status if read and written values are equal. <p>
*/
public void _readBoolean() {
boolean res = true ;
try {
oStream.writeBoolean(writeBoolean);
} catch (com.sun.star.io.IOException e) {
e.printStackTrace(log);
throw new StatusException("Can't write data to the stream", e);
}
byte readElem;
try {
readElem = oObj.readBoolean();
res = ((readElem != 0) == writeBoolean);
if (!res)
log.println("Must be read " +
writeBoolean +
" but was read " + (readElem != 0)) ;
} catch (com.sun.star.io.IOException e) {
log.println("Couldn't read Boolean from stream");
e.printStackTrace(log);
res = false;
}
tRes.tested("readBoolean()", res) ;
}
/**
* First writes a value to outStream then reads it from input. <p>
*
* Has <b> OK </b> status if read and written values are equal. <p>
*/
public void _readByte() {
boolean res = true ;
try {
oStream.writeByte(writeByte);
} catch (com.sun.star.io.IOException e) {
e.printStackTrace(log);
throw new StatusException("Can't write data to the stream", e);
}
byte readElem;
try {
readElem = oObj.readByte() ;
res = (readElem == writeByte);
if (!res)
log.println("Must be read " +
writeByte +
" but was read " + readElem);
} catch(com.sun.star.io.IOException e) {
log.println("Couldn't read Byte from stream");
e.printStackTrace(log);
res = false;
}
tRes.tested("readByte()", res) ;
}
/**
* First writes a value to outStream then reads it from input. <p>
*
* Has <b> OK </b> status if read and written values are equal. <p>
*/
public void _readChar() {
boolean res = true ;
try {
oStream.writeChar(writeChar);
} catch (com.sun.star.io.IOException e) {
e.printStackTrace(log);
throw new StatusException("Can't write data to the stream", e);
}
char readElem;
try {
readElem = oObj.readChar() ;
res = (readElem == writeChar);
if (!res)
log.println("Must be read " +
writeChar +
" but was read " + readElem) ;
} catch( com.sun.star.io.IOException e ) {
log.println("Couldn't read Char from stream");
e.printStackTrace(log);
res = false;
}
tRes.tested("readChar()", res);
}
/**
* First writes a value to outStream then reads it from input. <p>
*
* Has <b> OK </b> status if read and written values are equal. <p>
*/
public void _readShort() {
boolean res = true ;
try {
oStream.writeShort(writeShort);
} catch (com.sun.star.io.IOException e) {
e.printStackTrace(log);
throw new StatusException("Can't write data to the stream", e);
}
short readElem;
try {
readElem = oObj.readShort() ;
res = (readElem == writeShort);
if (!res)
log.println("Must be read " +
writeShort +
" but was read " + readElem) ;
} catch( com.sun.star.io.IOException e ) {
log.println("Couldn't read Short from stream");
e.printStackTrace(log);
res = false;
}
tRes.tested("readShort()", res);
}
/**
* First writes a value to outStream then reads it from input. <p>
*
* Has <b> OK </b> status if read and written values are equal. <p>
*/
public void _readLong() {
try {
oStream.writeLong(writeLong);
} catch (com.sun.star.io.IOException e) {
e.printStackTrace(log);
throw new StatusException("Can't write data to the stream", e);
}
boolean res = true ;
int readElem;
try {
readElem = oObj.readLong() ;
res = (readElem == writeLong);
if (!res)
log.println("Must be read " +
writeLong +
" but was read " + readElem) ;
} catch( com.sun.star.io.IOException e ) {
log.println("Couldn't read Long from stream");
e.printStackTrace(log);
res = false;
}
tRes.tested("readLong()", res);
}
/**
* First writes a value to outStream then reads it from input. <p>
*
* Has <b> OK </b> status if read and written values are equal. <p>
*/
public void _readHyper() {
boolean res = true ;
try {
oStream.writeHyper(writeHyper);
} catch (com.sun.star.io.IOException e) {
e.printStackTrace(log);
throw new StatusException("Can't write data to the stream", e);
}
long readElem;
try {
readElem = oObj.readHyper() ;
res = (readElem == writeHyper);
if (!res)
log.println("Must be read " +
writeHyper +
" but was read " + readElem) ;
} catch( com.sun.star.io.IOException e ) {
log.println("Couldn't read Hyper from stream");
e.printStackTrace(log);
res = false;
}
tRes.tested("readHyper()", res);
}
/**
* First writes a value to outStream then reads it from input. <p>
*
* Has <b> OK </b> status if read and written values are equal. <p>
*/
public void _readFloat() {
boolean res = true ;
try {
oStream.writeFloat(writeFloat);
} catch (com.sun.star.io.IOException e) {
e.printStackTrace(log);
throw new StatusException("Can't write data to the stream", e);
}
float readElem;
try {
readElem = oObj.readFloat() ;
res = (readElem == writeFloat);
if (!res)
log.println("Must be read " +
writeFloat +
" but was read " + readElem) ;
} catch( com.sun.star.io.IOException e ) {
log.println("Couldn't read Float from stream");
e.printStackTrace(log);
res = false;
}
tRes.tested("readFloat()", res);
}
/**
* First writes a value to outStream then reads it from input. <p>
*
* Has <b> OK </b> status if read and written values are equal. <p>
*/
public void _readDouble() {
boolean res = true ;
try {
oStream.writeDouble(writeDouble);
} catch (com.sun.star.io.IOException e) {
e.printStackTrace(log);
throw new StatusException("Can't write data to the stream", e);
}
double readElem;
try {
readElem = oObj.readDouble() ;
res = (readElem == writeDouble);
if (!res)
log.println("Must be read " +
writeDouble +
" but was read " + readElem) ;
} catch( com.sun.star.io.IOException e ) {
log.println("Couldn't read Double from stream");
e.printStackTrace(log);
res = false;
}
tRes.tested("readDouble()", res);
}
/**
* First writes a value to outStream then reads it from input. <p>
*
* Has <b> OK </b> status if read and written values are equal. <p>
*/
public void _readUTF() {
boolean res = true ;
try {
oStream.writeUTF(writeUTF);
} catch (com.sun.star.io.IOException e) {
e.printStackTrace(log);
throw new StatusException("Can't write data to the stream", e);
}
String readElem;
try {
readElem = oObj.readUTF() ;
res = writeUTF.equals(readElem) ;
if (!res)
log.println("Must be read '" +
writeUTF +
"' but was read '" + readElem + "'") ;
} catch( com.sun.star.io.IOException e ) {
log.println("Couldn't read String from stream");
e.printStackTrace(log);
res = false;
}
tRes.tested("readUTF()", res);
}
/**
* Forces object environment recreation.
*/
public void after() {
try {
oStream.flush();
} catch (com.sun.star.io.NotConnectedException e) {
e.printStackTrace(log);
} catch (com.sun.star.io.BufferSizeExceededException e) {
e.printStackTrace(log);
} catch (com.sun.star.io.IOException e) {
e.printStackTrace(log);
}
this.disposeEnvironment() ;
}
}
|