use of tests.support.Support_OutputStream in project j2objc by google.
the class OldObjectOutputStreamTest method test_reset.
public void test_reset() throws Exception {
String o = "HelloWorld";
sos = new Support_OutputStream(200);
oos.close();
oos = new ObjectOutputStream(sos);
oos.writeObject(o);
oos.writeObject(o);
oos.reset();
oos.writeObject(o);
sos.setThrowsException(true);
try {
oos.reset();
fail("Test 1: IOException expected.");
} catch (IOException e) {
// Expected.
}
sos.setThrowsException(false);
ois = new ObjectInputStream(new ByteArrayInputStream(sos.toByteArray()));
assertEquals("Test 2: Incorrect object read.", o, ois.readObject());
assertEquals("Test 3: Incorrect object read.", o, ois.readObject());
assertEquals("Test 4: Incorrect object read.", o, ois.readObject());
ois.close();
}
use of tests.support.Support_OutputStream in project j2objc by google.
the class OldBufferedOutputStreamTest method test_writeI.
public void test_writeI() throws IOException {
baos = new java.io.ByteArrayOutputStream();
os = new java.io.BufferedOutputStream(baos);
os.write('t');
bais = new java.io.ByteArrayInputStream(baos.toByteArray());
assertEquals("Test 1: Byte written, not buffered;", 0, bais.available());
os.flush();
bais = new java.io.ByteArrayInputStream(baos.toByteArray());
assertEquals("Test 2: Byte not written after flush;", 1, bais.available());
byte[] wbytes = new byte[1];
bais.read(wbytes, 0, 1);
assertEquals("Test 3: Incorrect byte written or read;", 't', wbytes[0]);
os.close();
sos = new Support_OutputStream(true);
os = new BufferedOutputStream(sos, 1);
os.write('t');
try {
// Exception is only thrown when the buffer is flushed.
os.write('e');
fail("Test 4: IOException expected.");
} catch (IOException e) {
// Expected.
}
// To avoid exception during tearDown().
sos.setThrowsException(false);
}
use of tests.support.Support_OutputStream in project j2objc by google.
the class OldBufferedOutputStreamTest method test_write$BII.
public void test_write$BII() throws IOException {
os = new java.io.BufferedOutputStream(baos = new java.io.ByteArrayOutputStream(), 512);
os.write(fileString.getBytes(), 0, 500);
bais = new java.io.ByteArrayInputStream(baos.toByteArray());
assertEquals("Test 1: Bytes written, not buffered;", 0, bais.available());
os.flush();
bais = new java.io.ByteArrayInputStream(baos.toByteArray());
assertEquals("Test 2: Bytes not written after flush;", 500, bais.available());
os.write(fileString.getBytes(), 500, 513);
bais = new java.io.ByteArrayInputStream(baos.toByteArray());
assertTrue("Test 3: Bytes not written when buffer full.", bais.available() >= 1000);
byte[] wbytes = new byte[1013];
bais.read(wbytes, 0, 1013);
assertTrue("Test 4: Incorrect bytes written or read.", fileString.substring(0, 1013).equals(new String(wbytes, 0, wbytes.length)));
os.close();
sos = new Support_OutputStream(true);
os = new BufferedOutputStream(sos, 10);
try {
os.write(fileString.getBytes(), 0, 500);
fail("Test 5: IOException expected.");
} catch (IOException e) {
// Expected.
}
// To avoid exception during tearDown().
sos.setThrowsException(false);
}
use of tests.support.Support_OutputStream in project j2objc by google.
the class OldBufferedOutputStreamTest method test_flush.
public void test_flush() throws IOException {
baos = new ByteArrayOutputStream();
os = new java.io.BufferedOutputStream(baos, 600);
os.write(fileString.getBytes(), 0, 500);
os.flush();
assertEquals("Test 1: Bytes not written after flush;", 500, ((ByteArrayOutputStream) baos).size());
os.close();
sos = new Support_OutputStream(true);
os = new BufferedOutputStream(sos, 10);
try {
os.flush();
fail("Test 2: IOException expected.");
} catch (IOException e) {
// Expected.
}
// To avoid exception during tearDown().
sos.setThrowsException(false);
}
use of tests.support.Support_OutputStream in project j2objc by google.
the class OldByteArrayOutputStreamTest method test_writeToLjava_io_OutputStream.
public void test_writeToLjava_io_OutputStream() throws Exception {
Support_OutputStream sos = new Support_OutputStream();
bos = new java.io.ByteArrayOutputStream();
bos.write(fileString.getBytes(), 0, 10);
bos.writeTo(sos);
assertTrue("Test 1: Incorrect string written.", sos.toString().equals(fileString.substring(0, 10)));
sos.setThrowsException(true);
try {
bos.writeTo(sos);
fail("Test 2: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
Aggregations