use of tests.support.Support_OutputStream in project robovm by robovm.
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 robovm by robovm.
the class OldOutputStreamWriterTest method test_writeI.
public void test_writeI() throws IOException {
Support_OutputStream out = new Support_OutputStream(500);
OutputStreamWriter writer;
out.setThrowsException(true);
writer = new OutputStreamWriter(out, "utf-8");
try {
// one character needs to be written.
for (int i = 0; i < 200; i++) {
for (int j = 0; j < testString.length(); j++) {
writer.write(testString.charAt(j));
}
}
fail("Test 1: IOException expected.");
} catch (IOException e) {
// Expected
}
out.setThrowsException(false);
writer.close();
writer = new OutputStreamWriter(out, "utf-8");
writer.write(1);
writer.flush();
String str = new String(out.toByteArray(), "utf-8");
assertEquals("Test 2: ", "", str);
writer.write(2);
writer.flush();
str = new String(out.toByteArray(), "utf-8");
assertEquals("Test 3: ", "", str);
writer.write(-1);
writer.flush();
str = new String(out.toByteArray(), "utf-8");
assertEquals("Test 4: ", "", str);
writer.write(0xfedcb);
writer.flush();
str = new String(out.toByteArray(), "utf-8");
assertEquals("Test 5: ", "", str);
writer.close();
try {
writer.write(1);
fail("Test 6: IOException expected.");
} catch (IOException e) {
// Expected
}
}
use of tests.support.Support_OutputStream in project j2objc by google.
the class OldOutputStreamWriterTest method test_write$CII.
public void test_write$CII() throws IOException {
char[] chars = testString.toCharArray();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Support_OutputStream out = new Support_OutputStream(500);
OutputStreamWriter writer;
writer = new OutputStreamWriter(out, "utf-8");
try {
writer.write(chars, -1, 1);
fail("Test 1: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
writer.write(chars, 0, -1);
fail("Test 2: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
writer.write(new char[0], 0, 1);
fail("Test 3: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
writer.write((char[]) null, 0, 1);
fail("Test 4: NullPointerException expected.");
} catch (NullPointerException e) {
// Expected
}
try {
writer.write(chars, 1, chars.length);
fail("Test 5a: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
writer.write(chars, 0, chars.length + 1);
fail("Test 5b: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
writer.write(chars, chars.length, 1);
fail("Test 5c: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
writer.write(chars, chars.length + 1, 0);
fail("Test 5d: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected
}
out.setThrowsException(true);
try {
for (int i = 0; i < 200; i++) {
writer.write(chars, 0, chars.length);
}
fail("Test 6: IOException expected.");
} catch (IOException e) {
// Expected
}
out.setThrowsException(false);
writer.close();
writer = new OutputStreamWriter(baos, "utf-8");
writer.write(chars, 1, 2);
writer.flush();
assertEquals("Test 7: write(char[], int, int) has not produced the " + "expected content in the output stream.", "hi", baos.toString("utf-8"));
writer.write(chars, 0, chars.length);
writer.flush();
assertEquals("Test 8: write(char[], int, int) has not produced the " + "expected content in the output stream.", "hi" + testString, baos.toString("utf-8"));
writer.close();
try {
writer.write((char[]) null, -1, -1);
fail("Test 9: IOException expected.");
} catch (IOException e) {
// Expected
}
}
use of tests.support.Support_OutputStream in project j2objc by google.
the class OldOutputStreamWriterTest method test_ConstructorLjava_io_OutputStream.
public void test_ConstructorLjava_io_OutputStream() throws IOException {
OutputStreamWriter writer = null;
try {
writer = new OutputStreamWriter(null);
fail("Test 1: NullPointerException expected.");
} catch (NullPointerException e) {
// Expected
}
try {
writer = new OutputStreamWriter(new Support_OutputStream());
} catch (Exception e) {
fail("Test 2: Unexpected exception: " + e.getMessage());
}
// Test that the default encoding has been used.
assertEquals("Test 3: Incorrect default encoding used.", Charset.defaultCharset(), Charset.forName(writer.getEncoding()));
if (writer != null)
writer.close();
}
use of tests.support.Support_OutputStream in project j2objc by google.
the class OldOutputStreamWriterTest method test_writeLjava_lang_StringII.
public void test_writeLjava_lang_StringII() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Support_OutputStream out = new Support_OutputStream(500);
OutputStreamWriter writer;
writer = new OutputStreamWriter(out, "utf-8");
try {
writer.write("Lorem", -1, 0);
fail("Test 1: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
writer.write("Lorem", 0, -1);
fail("Test 2: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
writer.write("", 0, 1);
fail("Test 3: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
writer.write(testString, 1, testString.length());
fail("Test 4a: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
writer.write(testString, 0, testString.length() + 1);
fail("Test 4b: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
writer.write(testString, testString.length(), 1);
fail("Test 4c: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
writer.write(testString, testString.length() + 1, 0);
fail("Test 4d: IndexOutOfBoundsException expected.");
} catch (IndexOutOfBoundsException e) {
// Expected
}
try {
writer.write((String) null, 0, 1);
fail("Test 5: NullPointerException expected.");
} catch (NullPointerException e) {
// Expected
}
out.setThrowsException(true);
try {
for (int i = 0; i < 200; i++) {
writer.write(testString, 0, testString.length());
}
fail("Test 6: IOException expected.");
} catch (IOException e) {
// Expected
}
out.setThrowsException(false);
writer.close();
writer = new OutputStreamWriter(baos, "utf-8");
writer.write("abc", 1, 2);
writer.flush();
assertEquals("Test 7: write(String, int, int) has not produced the " + "expected content in the output stream.", "bc", baos.toString("utf-8"));
writer.write(testString, 0, testString.length());
writer.flush();
assertEquals("Test 7: write(String, int, int) has not produced the " + "expected content in the output stream.", "bc" + testString, baos.toString("utf-8"));
writer.close();
try {
writer.write("abc", 0, 1);
fail("Test 8: IOException expected.");
} catch (IOException e) {
// Expected
}
}
Aggregations