Search in sources :

Example 31 with Support_StringReader

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

the class OldBufferedReaderTest method test_read.

public void test_read() throws IOException {
    Support_ASimpleReader ssr = new Support_ASimpleReader(true);
    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);
    br.close();
    br = new BufferedReader(ssr);
    try {
        br.read();
        fail("IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    // Avoid IOException in tearDown().
    ssr.throwExceptionOnNextUse = false;
}
Also used : CharArrayReader(java.io.CharArrayReader) Support_ASimpleReader(tests.support.Support_ASimpleReader) BufferedReader(java.io.BufferedReader) PipedReader(java.io.PipedReader) Support_ASimpleReader(tests.support.Support_ASimpleReader) Support_StringReader(tests.support.Support_StringReader) CharArrayReader(java.io.CharArrayReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) ThrowingReader(tests.support.ThrowingReader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) IOException(java.io.IOException) Support_StringReader(tests.support.Support_StringReader)

Example 32 with Support_StringReader

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

the class OldBufferedReaderTest method test_skipJ.

public void test_skipJ() throws IOException {
    Support_ASimpleReader ssr = new Support_ASimpleReader(true);
    br = new BufferedReader(new Support_StringReader(testString));
    try {
        br.skip(-1);
        fail("Test 1: IllegalArgumentException expected.");
    } catch (IllegalArgumentException e) {
    // Expected.
    }
    br.skip(500);
    char[] buf = new char[testString.length()];
    br.read(buf, 0, 500);
    assertTrue("Test 2: Failed to set skip properly.", testString.substring(500, 1000).equals(new String(buf, 0, 500)));
    br.close();
    br = new BufferedReader(ssr);
    try {
        br.skip(1);
        fail("Test 3: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    // Avoid IOException in tearDown().
    ssr.throwExceptionOnNextUse = false;
}
Also used : Support_ASimpleReader(tests.support.Support_ASimpleReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Support_StringReader(tests.support.Support_StringReader)

Example 33 with Support_StringReader

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

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));
}
Also used : BufferedReader(java.io.BufferedReader) Support_StringReader(tests.support.Support_StringReader)

Example 34 with Support_StringReader

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

the class OldBufferedReaderTest method test_ready.

public void test_ready() throws IOException {
    Support_ASimpleReader ssr = new Support_ASimpleReader(true);
    try {
        br = new BufferedReader(new Support_StringReader(testString));
        assertTrue("Test 1: ready() returned false", br.ready());
    } catch (java.io.IOException e) {
        fail("Exception during ready test" + e.toString());
    }
    br.close();
    br = new BufferedReader(ssr);
    try {
        br.close();
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    // Avoid IOException in tearDown().
    ssr.throwExceptionOnNextUse = false;
}
Also used : Support_ASimpleReader(tests.support.Support_ASimpleReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) IOException(java.io.IOException) Support_StringReader(tests.support.Support_StringReader)

Example 35 with Support_StringReader

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

the class OldBufferedReaderTest method test_readLine.

public void test_readLine() throws IOException {
    String line;
    br = new BufferedReader(new Support_StringReader("Lorem\nipsum\rdolor sit amet..."));
    line = br.readLine();
    assertTrue("Test 1: Incorrect line written or read: " + line, line.equals("Lorem"));
    line = br.readLine();
    assertTrue("Test 2: Incorrect line written or read: " + line, line.equals("ipsum"));
    line = br.readLine();
    assertTrue("Test 3: Incorrect line written or read: " + line, line.equals("dolor sit amet..."));
    br.close();
    try {
        br.readLine();
        fail("Test 4: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) 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