use of java.io.PushbackReader in project robovm by robovm.
the class OldAndroidPushbackReaderTest method testPushbackReader.
public void testPushbackReader() throws Exception {
String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
StringReader aa = new StringReader(str);
StringReader ba = new StringReader(str);
StringReader ca = new StringReader(str);
PushbackReader a = new PushbackReader(aa, 5);
try {
a.unread("PUSH".toCharArray());
Assert.assertEquals("PUSHAbCdEfGhIjKlMnOpQrStUvWxYz", read(a));
} finally {
a.close();
}
PushbackReader b = new PushbackReader(ba, 15);
try {
b.unread('X');
Assert.assertEquals("XAbCdEfGhI", read(b, 10));
} finally {
b.close();
}
PushbackReader c = new PushbackReader(ca);
try {
Assert.assertEquals("bdfhjlnprtvxz", skipRead(c));
} finally {
c.close();
}
}
use of java.io.PushbackReader in project robovm by robovm.
the class OldPushbackReaderTest method test_close.
/**
* java.io.PushbackReader#close()
*/
public void test_close() throws IOException {
PushbackReader tobj;
tobj = new PushbackReader(underlying);
tobj.close();
tobj.close();
tobj = new PushbackReader(underlying);
underlying.throwExceptionOnNextUse = true;
try {
tobj.close();
fail("IOException not thrown.");
} catch (IOException e) {
// expected
}
}
use of java.io.PushbackReader in project robovm by robovm.
the class OldPushbackReaderTest method test_unreadI.
/**
* java.io.PushbackReader#unread(int)
*/
public void test_unreadI() throws IOException {
PushbackReader tobj;
tobj = new PushbackReader(underlying);
// Why does this work?!?
tobj.unread(23);
tobj.skip(2);
tobj.unread(23);
assertEquals("Wrong value read!", 23, tobj.read());
tobj.unread(13);
try {
tobj.unread(13);
fail("IOException not thrown (ACTUALLY NOT SURE WHETHER IT REALLY MUST BE THROWN!).");
} catch (IOException e) {
// expected
}
}
use of java.io.PushbackReader in project robovm by robovm.
the class OldPushbackReaderTest method test_read_$CII_Exception.
/**
* java.io.PushbackReader#read(char[], int, int)
*/
public void test_read_$CII_Exception() throws IOException {
pbr = new PushbackReader(new StringReader(pbString), 10);
char[] nullCharArray = null;
char[] charArray = new char[10];
try {
pbr.read(nullCharArray, 0, 1);
fail("should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
try {
pbr.read(charArray, 0, -1);
fail("should throw IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
pbr.read(charArray, -1, 0);
fail("should throw IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
pbr.read(charArray, charArray.length + 1, 0);
fail("should throw IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
pbr.read(charArray, charArray.length, 1);
fail("should throw IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
pbr.read(charArray, 1, charArray.length);
fail("should throw IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException e) {
// expected
}
try {
pbr.read(charArray, 0, charArray.length + 1);
fail("should throw IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException e) {
// expected
}
pbr.close();
try {
pbr.read(charArray, 0, 1);
fail("should throw IOException");
} catch (IOException e) {
// expected
}
}
use of java.io.PushbackReader in project robovm by robovm.
the class OldPushbackReaderTest method test_unread$C.
/**
* java.io.PushbackReader#unread(char[])
*/
public void test_unread$C() throws IOException {
PushbackReader tobj;
String str2 = "0123456789";
char[] buf2 = str2.toCharArray();
char[] readBuf = new char[10];
tobj = new PushbackReader(underlying, 10);
tobj.unread(buf2);
try {
tobj.unread(buf2);
fail("IOException not thrown.");
} catch (IOException e) {
// expected
}
tobj.read(readBuf);
assertEquals("Incorrect bytes read", str2, new String(readBuf));
underlying.throwExceptionOnNextUse = true;
try {
tobj.read(buf2);
fail("IOException not thrown.");
} catch (IOException e) {
// expected
}
// Test for method void java.io.PushbackReader.unread(char [])
try {
char[] c = new char[5];
pbr.read(c, 0, 5);
pbr.unread(c);
pbr.read(c, 0, 5);
assertTrue("Failed to unread chars", new String(c).equals(pbString.substring(0, 5)));
} catch (IOException e) {
fail("IOException during read test : " + e.getMessage());
}
}
Aggregations