Search in sources :

Example 6 with Support_StringReader

use of tests.support.Support_StringReader in project robovm by robovm.

the class BufferedReaderTest method test_read_$CII_Exception.

/**
	 * @tests java.io.BufferedReader#read(char[], int, int)
	 */
public void test_read_$CII_Exception() throws IOException {
    br = new BufferedReader(new Support_StringReader(testString));
    char[] nullCharArray = null;
    char[] charArray = testString.toCharArray();
    try {
        br.read(nullCharArray, -1, -1);
        fail();
    } catch (NullPointerException expected) {
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        br.read(nullCharArray, -1, 0);
        fail();
    } catch (NullPointerException expected) {
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        br.read(nullCharArray, 0, -1);
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    try {
        br.read(nullCharArray, 0, 0);
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    try {
        br.read(nullCharArray, 0, 1);
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    try {
        br.read(charArray, -1, -1);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        br.read(charArray, -1, 0);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    br.read(charArray, 0, 0);
    br.read(charArray, 0, charArray.length);
    br.read(charArray, charArray.length, 0);
    try {
        br.read(charArray, charArray.length + 1, 0);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    //expected
    }
    try {
        br.read(charArray, charArray.length + 1, 1);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    //expected
    }
    br.close();
    try {
        br.read(nullCharArray, -1, -1);
        fail("should throw IOException");
    } catch (IOException e) {
    // expected
    }
    try {
        br.read(charArray, -1, 0);
        fail("should throw IOException");
    } catch (IOException e) {
    // expected
    }
    try {
        br.read(charArray, 0, -1);
        fail("should throw IOException");
    } catch (IOException e) {
    // expected
    }
}
Also used : BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Support_StringReader(tests.support.Support_StringReader)

Example 7 with Support_StringReader

use of tests.support.Support_StringReader in project robovm by robovm.

the class BufferedReaderTest method test_reset.

/**
	 * @tests java.io.BufferedReader#reset()
	 */
public void test_reset() {
    // Test for method void java.io.BufferedReader.reset()
    try {
        br = new BufferedReader(new Support_StringReader(testString));
        br.skip(500);
        br.mark(900);
        br.skip(500);
        br.reset();
        char[] buf = new char[testString.length()];
        br.read(buf, 0, 500);
        assertTrue("Failed to reset properly", testString.substring(500, 1000).equals(new String(buf, 0, 500)));
    } catch (java.io.IOException e) {
        fail("Exception during reset test");
    }
    try {
        br = new BufferedReader(new Support_StringReader(testString));
        br.skip(500);
        br.reset();
        fail("Reset succeeded on unmarked stream");
    } catch (IOException x) {
        return;
    }
}
Also used : BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) IOException(java.io.IOException) Support_StringReader(tests.support.Support_StringReader)

Example 8 with Support_StringReader

use of tests.support.Support_StringReader in project robovm by robovm.

the class BufferedReaderTest method test_readLine.

/**
	 * @tests java.io.BufferedReader#readLine()
	 */
public void test_readLine() {
    // Test for method java.lang.String java.io.BufferedReader.readLine()
    try {
        br = new BufferedReader(new Support_StringReader(testString));
        String r = br.readLine();
        assertEquals("readLine returned incorrect string", "Test_All_Tests", r);
    } catch (java.io.IOException e) {
        fail("Exception during readLine test");
    }
}
Also used : BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Support_StringReader(tests.support.Support_StringReader)

Example 9 with Support_StringReader

use of tests.support.Support_StringReader in project robovm by robovm.

the class BufferedReaderTest method test_ready.

/**
	 * @tests java.io.BufferedReader#ready()
	 */
public void test_ready() {
    // Test for method boolean java.io.BufferedReader.ready()
    try {
        br = new BufferedReader(new Support_StringReader(testString));
        assertTrue("ready returned false", br.ready());
    } catch (java.io.IOException e) {
        fail("Exception during ready test" + e.toString());
    }
}
Also used : BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Support_StringReader(tests.support.Support_StringReader)

Example 10 with Support_StringReader

use of tests.support.Support_StringReader in project robovm by robovm.

the class BufferedReaderTest method assertLines.

private void assertLines(String in, String... lines) throws IOException {
    BufferedReader bufferedReader = new BufferedReader(new Support_StringReader(in));
    for (String line : lines) {
        assertEquals(line, bufferedReader.readLine());
    }
    assertNull(bufferedReader.readLine());
}
Also used : BufferedReader(java.io.BufferedReader) Support_StringReader(tests.support.Support_StringReader)

Aggregations

Support_StringReader (tests.support.Support_StringReader)36 BufferedReader (java.io.BufferedReader)34 IOException (java.io.IOException)24 Support_ASimpleReader (tests.support.Support_ASimpleReader)10 PipedReader (java.io.PipedReader)9 CharArrayReader (java.io.CharArrayReader)7 InputStreamReader (java.io.InputStreamReader)7 Reader (java.io.Reader)7 StringReader (java.io.StringReader)7 ThrowingReader (tests.support.ThrowingReader)4 StreamTokenizer (java.io.StreamTokenizer)2 Support_ASimpleInputStream (tests.support.Support_ASimpleInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1