use of tests.support.Support_StringReader in project robovm by robovm.
the class BufferedReaderTest method test_markSupported.
/**
* @tests java.io.BufferedReader#markSupported()
*/
public void test_markSupported() {
// Test for method boolean java.io.BufferedReader.markSupported()
br = new BufferedReader(new Support_StringReader(testString));
assertTrue("markSupported returned false", br.markSupported());
}
use of tests.support.Support_StringReader in project robovm by robovm.
the class BufferedReaderTest method test_read.
/**
* @tests java.io.BufferedReader#read()
*/
public void test_read() throws IOException {
// Test for method int java.io.BufferedReader.read()
try {
br = new BufferedReader(new Support_StringReader(testString));
int r = br.read();
assertTrue("Char read improperly", testString.charAt(0) == r);
br = new BufferedReader(new Support_StringReader(new String(new char[] { '蝥' })));
assertTrue("Wrong double byte character", br.read() == '蝥');
} catch (java.io.IOException e) {
fail("Exception during read test");
}
char[] chars = new char[256];
for (int i = 0; i < 256; i++) chars[i] = (char) i;
Reader in = new BufferedReader(new Support_StringReader(new String(chars)), 12);
try {
// Fill the
assertEquals("Wrong initial char", 0, in.read());
// buffer
char[] buf = new char[14];
// Read greater than the buffer
in.read(buf, 0, 14);
assertTrue("Wrong block read data", new String(buf).equals(new String(chars, 1, 14)));
// Check next byte
assertEquals("Wrong chars", 15, in.read());
} catch (IOException e) {
fail("Exception during read test 2:" + e);
}
// regression test for HARMONY-841
assertTrue(new BufferedReader(new CharArrayReader(new char[5], 1, 0), 2).read() == -1);
}
use of tests.support.Support_StringReader in project robovm by robovm.
the class BufferedReaderTest method test_reset_IOException.
public void test_reset_IOException() throws Exception {
int[] expected = new int[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', -1 };
br = new BufferedReader(new Support_StringReader("1234567890"), 9);
br.mark(9);
for (int i = 0; i < 11; i++) {
assertEquals(expected[i], br.read());
}
try {
br.reset();
fail("should throw IOException");
} catch (IOException e) {
// Expected
}
for (int i = 0; i < 11; i++) {
assertEquals(-1, br.read());
}
br = new BufferedReader(new Support_StringReader("1234567890"));
br.mark(10);
for (int i = 0; i < 10; i++) {
assertEquals(expected[i], br.read());
}
br.reset();
for (int i = 0; i < 11; i++) {
assertEquals(expected[i], br.read());
}
}
use of tests.support.Support_StringReader in project robovm by robovm.
the class BufferedReaderTest method test_markI.
/**
* @tests java.io.BufferedReader#mark(int)
*/
public void test_markI() throws IOException {
// Test for method void java.io.BufferedReader.mark(int)
char[] buf = null;
br = new BufferedReader(new Support_StringReader(testString));
br.skip(500);
br.mark(1000);
br.skip(250);
br.reset();
buf = new char[testString.length()];
br.read(buf, 0, 500);
assertTrue("Failed to set mark properly", testString.substring(500, 1000).equals(new String(buf, 0, 500)));
try {
br = new BufferedReader(new Support_StringReader(testString), 800);
br.skip(500);
br.mark(250);
br.read(buf, 0, 1000);
br.reset();
fail("Failed to invalidate mark properly");
} catch (IOException x) {
// Expected
}
char[] chars = new char[256];
for (int i = 0; i < 256; i++) chars[i] = (char) i;
Reader in = new BufferedReader(new Support_StringReader(new String(chars)), 12);
in.skip(6);
in.mark(14);
in.read(new char[14], 0, 14);
in.reset();
assertTrue("Wrong chars", in.read() == (char) 6 && in.read() == (char) 7);
in = new BufferedReader(new Support_StringReader(new String(chars)), 12);
in.skip(6);
in.mark(8);
in.skip(7);
in.reset();
assertTrue("Wrong chars 2", in.read() == (char) 6 && in.read() == (char) 7);
BufferedReader br = new BufferedReader(new StringReader("01234"), 2);
br.mark(3);
char[] carray = new char[3];
int result = br.read(carray);
assertEquals(3, result);
assertEquals("Assert 0:", '0', carray[0]);
assertEquals("Assert 1:", '1', carray[1]);
assertEquals("Assert 2:", '2', carray[2]);
assertEquals("Assert 3:", '3', br.read());
br = new BufferedReader(new StringReader("01234"), 2);
br.mark(3);
carray = new char[4];
result = br.read(carray);
assertEquals("Assert 4:", 4, result);
assertEquals("Assert 5:", '0', carray[0]);
assertEquals("Assert 6:", '1', carray[1]);
assertEquals("Assert 7:", '2', carray[2]);
assertEquals("Assert 8:", '3', carray[3]);
assertEquals("Assert 9:", '4', br.read());
assertEquals("Assert 10:", -1, br.read());
BufferedReader reader = new BufferedReader(new StringReader("01234"));
reader.mark(Integer.MAX_VALUE);
reader.read();
reader.close();
}
use of tests.support.Support_StringReader in project robovm by robovm.
the class OldBufferedReaderTest method test_markI.
public void test_markI() throws IOException {
// Test for method void java.io.BufferedReader.mark(int)
char[] buf = null;
try {
br = new BufferedReader(new Support_StringReader(testString));
br.skip(500);
br.mark(1000);
br.skip(250);
br.reset();
buf = new char[testString.length()];
br.read(buf, 0, 500);
assertTrue("Failed to set mark properly", testString.substring(500, 1000).equals(new String(buf, 0, 500)));
} catch (java.io.IOException e) {
fail("Exception during mark test");
}
try {
br = new BufferedReader(new Support_StringReader(testString), 800);
br.skip(500);
br.mark(250);
br.read(buf, 0, 1000);
br.reset();
fail("Failed to invalidate mark properly");
} catch (IOException x) {
}
char[] chars = new char[256];
for (int i = 0; i < 256; i++) chars[i] = (char) i;
Reader in = new BufferedReader(new Support_StringReader(new String(chars)), 12);
try {
in.skip(6);
in.mark(14);
in.read(new char[14], 0, 14);
in.reset();
assertTrue("Wrong chars", in.read() == (char) 6 && in.read() == (char) 7);
} catch (IOException e) {
fail("Exception during mark test 2:" + e);
}
in = new BufferedReader(new Support_StringReader(new String(chars)), 12);
try {
in.skip(6);
in.mark(8);
in.skip(7);
in.reset();
assertTrue("Wrong chars 2", in.read() == (char) 6 && in.read() == (char) 7);
} catch (IOException e) {
fail("Exception during mark test 3:" + e);
}
}
Aggregations