Search in sources :

Example 1 with Support_ASimpleInputStream

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

the class OldInputStreamReaderTest method test_close.

public void test_close() {
    // Test for method void java.io.InputStreamReader.close()
    try {
        is.close();
    } catch (IOException e) {
        fail("Failed to close reader : " + e.getMessage());
    }
    try {
        is.read();
        fail("Test 1: IOException expected.");
    } catch (IOException e) {
    // Exception means read failed due to close
    }
    is = new InputStreamReader(new Support_ASimpleInputStream(true));
    try {
        is.read();
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) IOException(java.io.IOException)

Example 2 with Support_ASimpleInputStream

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

the class OldFilterInputStreamTest method test_close.

public void test_close() throws IOException {
    is.close();
    try {
        is.read();
        fail("Test 1: Read from closed stream succeeded.");
    } catch (IOException e) {
    // Expected.
    }
    Support_ASimpleInputStream sis = new Support_ASimpleInputStream(true);
    is = new MyFilterInputStream(sis);
    try {
        is.close();
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    sis.throwExceptionOnNextUse = false;
}
Also used : Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) IOException(java.io.IOException)

Example 3 with Support_ASimpleInputStream

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

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

Example 4 with Support_ASimpleInputStream

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

the class OldDataInputStreamTest method test_read$B.

public void test_read$B() throws IOException {
    byte[] rbytes = new byte[testLength - 5];
    Support_ASimpleInputStream sis = new Support_ASimpleInputStream();
    int r;
    os.write(fileString.getBytes());
    os.close();
    openDataInputStream();
    r = dis.read(rbytes);
    assertEquals("Test 1: Incorrect number of bytes read;", testLength - 5, r);
    assertTrue("Test 2: Incorrect data written or read.", new String(rbytes).equals(fileString.substring(0, testLength - 5)));
    r = dis.read(rbytes);
    assertEquals("Test 3: Incorrect number of bytes read;", 5, r);
    assertTrue("Test 4: Incorrect data written or read.", new String(rbytes, 0, 5).equals(fileString.substring(testLength - 5)));
    dis.close();
    sis.throwExceptionOnNextUse = true;
    dis = new DataInputStream(sis);
    try {
        dis.read(rbytes);
        fail("Test 5: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 5 with Support_ASimpleInputStream

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

the class OldDataInputStreamTest method test_read$BII.

public void test_read$BII() throws IOException {
    byte[] rbytes = new byte[testLength - 5];
    Support_ASimpleInputStream sis = new Support_ASimpleInputStream();
    int r;
    os.write(fileString.getBytes());
    os.close();
    openDataInputStream();
    r = dis.read(rbytes, 1, testLength - 10);
    assertEquals("Test 1: Incorrect number of bytes read;", testLength - 10, r);
    assertEquals("Test 2: Incorrect data read.", 0, rbytes[0]);
    assertTrue("Test 3: Incorrect data written or read.", new String(rbytes, 1, r).equals(fileString.substring(0, r)));
    r = dis.read(rbytes, 0, 15);
    assertEquals("Test 3: Incorrect number of bytes read;", 10, r);
    assertTrue("Test 4: Incorrect data written or read.", new String(rbytes, 0, r).equals(fileString.substring(testLength - 10)));
    dis.close();
    sis.throwExceptionOnNextUse = true;
    dis = new DataInputStream(sis);
    try {
        dis.read(rbytes, 1, 5);
        fail("Test 5: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Aggregations

Support_ASimpleInputStream (tests.support.Support_ASimpleInputStream)27 IOException (java.io.IOException)24 ObjectInputStream (java.io.ObjectInputStream)10 DataInputStream (java.io.DataInputStream)4 SequenceInputStream (java.io.SequenceInputStream)4 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStreamReader (java.io.InputStreamReader)2 StreamTokenizer (java.io.StreamTokenizer)2 Support_StringReader (tests.support.Support_StringReader)2 DigestInputStream (java.security.DigestInputStream)1