use of tests.support.Support_StringReader in project j2objc by google.
the class OldBufferedReaderTest method testReadZeroLengthArray.
public void testReadZeroLengthArray() throws IOException {
br = new BufferedReader(new Support_StringReader("ABCDEF"));
br.read();
br.read();
assertEquals(0, br.read(new char[6], 3, 0));
}
use of tests.support.Support_StringReader in project j2objc by google.
the class OldBufferedReaderTest method test_ConstructorLjava_io_ReaderI.
public void test_ConstructorLjava_io_ReaderI() {
// Illegal negative size argument test.
try {
br = new BufferedReader(new Support_StringReader(testString), 0);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
}
br = new BufferedReader(new Support_StringReader(testString), 1024);
assertNotNull(br);
}
use of tests.support.Support_StringReader in project j2objc by google.
the class OldStreamTokenizerTest method test_nextToken.
public void test_nextToken() throws IOException {
st = new StreamTokenizer(new Support_StringReader("\n \r\n#"));
// make \n ordinary
st.ordinaryChar('\n');
st.eolIsSignificant(true);
assertTrue("Wrong token 2,1", st.nextToken() == '\n');
assertTrue("Wrong token 2,2", st.nextToken() == '\n');
assertEquals("Wrong token 2,3", '#', st.nextToken());
Support_ASimpleInputStream sis = new Support_ASimpleInputStream();
sis.throwExceptionOnNextUse = true;
st = new StreamTokenizer(sis);
try {
st.nextToken();
fail("IOException expected.");
} catch (IOException e) {
// Expected.
}
}
use of tests.support.Support_StringReader in project robovm by robovm.
the class BufferedReaderTest method test_close.
/**
* @tests java.io.BufferedReader#close()
*/
public void test_close() {
// Test for method void java.io.BufferedReader.close()
try {
br = new BufferedReader(new Support_StringReader(testString));
br.close();
br.read();
fail("Read on closed stream");
} catch (IOException x) {
return;
}
}
use of tests.support.Support_StringReader in project robovm by robovm.
the class BufferedReaderTest method test_read$CII.
/**
* @tests java.io.BufferedReader#read(char[], int, int)
*/
public void test_read$CII() throws Exception {
char[] ca = new char[2];
BufferedReader toRet = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(new byte[0])));
/* Null buffer should throw NPE even when len == 0 */
try {
toRet.read(null, 1, 0);
fail("null buffer reading zero bytes should throw NPE");
} catch (NullPointerException e) {
//expected
}
try {
toRet.close();
} catch (IOException e) {
fail("unexpected 1: " + e);
}
try {
toRet.read(null, 1, 0);
fail("null buffer reading zero bytes on closed stream should throw IOException");
} catch (IOException e) {
//expected
}
/* Closed reader should throw IOException reading zero bytes */
try {
toRet.read(ca, 0, 0);
fail("Reading zero bytes on a closed reader should not work");
} catch (IOException e) {
// expected
}
/*
* Closed reader should throw IOException in preference to index out of
* bounds
*/
try {
// Read should throw IOException before
// ArrayIndexOutOfBoundException
toRet.read(ca, 1, 5);
fail("IOException should have been thrown");
} catch (IOException e) {
// expected
}
// Test to ensure that a drained stream returns 0 at EOF
toRet = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(new byte[2])));
try {
assertEquals("Emptying the reader should return two bytes", 2, toRet.read(ca, 0, 2));
assertEquals("EOF on a reader should be -1", -1, toRet.read(ca, 0, 2));
assertEquals("Reading zero bytes at EOF should work", 0, toRet.read(ca, 0, 0));
} catch (IOException ex) {
fail("Unexpected IOException : " + ex.getLocalizedMessage());
}
// Test for method int java.io.BufferedReader.read(char [], int, int)
try {
char[] buf = new char[testString.length()];
br = new BufferedReader(new Support_StringReader(testString));
br.read(buf, 50, 500);
assertTrue("Chars read improperly", new String(buf, 50, 500).equals(testString.substring(0, 500)));
} catch (java.io.IOException e) {
fail("Exception during read test");
}
BufferedReader bufin = new BufferedReader(new Reader() {
int size = 2, pos = 0;
char[] contents = new char[size];
public int read() throws IOException {
if (pos >= size)
throw new IOException("Read past end of data");
return contents[pos++];
}
public int read(char[] buf, int off, int len) throws IOException {
if (pos >= size)
throw new IOException("Read past end of data");
int toRead = len;
if (toRead > (size - pos))
toRead = size - pos;
System.arraycopy(contents, pos, buf, off, toRead);
pos += toRead;
return toRead;
}
public boolean ready() throws IOException {
return size - pos > 0;
}
public void close() throws IOException {
}
});
try {
bufin.read();
int result = bufin.read(new char[2], 0, 2);
assertTrue("Incorrect result: " + result, result == 1);
} catch (IOException e) {
fail("Unexpected: " + e);
}
//regression for HARMONY-831
try {
new BufferedReader(new PipedReader(), 9).read(new char[] {}, 7, 0);
fail("should throw IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException e) {
}
// Regression for HARMONY-54
char[] ch = {};
BufferedReader reader = new BufferedReader(new CharArrayReader(ch));
try {
// Check exception thrown when the reader is open.
reader.read(null, 1, 0);
fail("Assert 0: NullPointerException expected");
} catch (NullPointerException e) {
// Expected
}
// Now check IOException is thrown in preference to
// NullPointerexception when the reader is closed.
reader.close();
try {
reader.read(null, 1, 0);
fail("Assert 1: IOException expected");
} catch (IOException e) {
// Expected
}
try {
// And check that the IOException is thrown before
// ArrayIndexOutOfBoundException
reader.read(ch, 0, 42);
fail("Assert 2: IOException expected");
} catch (IOException e) {
// expected
}
}
Aggregations