Search in sources :

Example 16 with Support_ASimpleInputStream

use of tests.support.Support_ASimpleInputStream in project j2objc by google.

the class OldSequenceInputStreamTest method test_read$BII_Excpetion.

public void test_read$BII_Excpetion() throws IOException {
    byte[] buf = new byte[4];
    si.read(buf, 0, 2);
    si.read(buf, 2, 1);
    simple2.throwExceptionOnNextUse = true;
    si.read(buf, 3, 1);
    assertEquals("Wrong stuff read!", "Hell", new String(buf));
    simple1.throwExceptionOnNextUse = true;
    try {
        si.read(buf, 3, 1);
        fail("IOException not thrown!");
    } catch (IOException e) {
    // expected
    }
    buf = new byte[10];
    simple1 = new Support_ASimpleInputStream(s1);
    simple2 = new Support_ASimpleInputStream(s2);
    si = new SequenceInputStream(simple1, simple2);
    try {
        si.read(buf, -1, 1);
        fail("IndexOutOfBoundsException was not thrown");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        si.read(buf, 0, -1);
        fail("IndexOutOfBoundsException was not thrown");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        si.read(buf, 1, 10);
        fail("IndexOutOfBoundsException was not thrown");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
}
Also used : SequenceInputStream(java.io.SequenceInputStream) Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) IOException(java.io.IOException)

Example 17 with Support_ASimpleInputStream

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

Example 18 with Support_ASimpleInputStream

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

the class OldBufferedInputStreamTest method test_close.

public void test_close() throws IOException {
    is.close();
    try {
        is.read();
        fail("Test 1: IOException expected when reading after closing " + "the stream.");
    } catch (IOException e) {
    // Expected.
    }
    Support_ASimpleInputStream sis = new Support_ASimpleInputStream(true);
    is = new BufferedInputStream(sis);
    try {
        is.close();
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    sis.throwExceptionOnNextUse = false;
}
Also used : Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException)

Example 19 with Support_ASimpleInputStream

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

the class Test method test_available.

public void test_available() throws IOException {
    // Test for method int java.io.ObjectInputStream.available()
    oos.writeBytes(testString);
    oos.close();
    Support_ASimpleInputStream sis = new Support_ASimpleInputStream(bao.toByteArray());
    ois = new ObjectInputStream(sis);
    assertEquals("Test 1: Incorrect number of bytes;", testLength, ois.available());
    ois.close();
}
Also used : Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 20 with Support_ASimpleInputStream

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

the class Test method test_readFully$BII_Exception.

public void test_readFully$BII_Exception() throws IOException {
    byte[] buf = new byte[testLength];
    oos.writeObject(testString);
    oos.close();
    ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
    try {
        ois.readFully(buf, 0, -1);
        fail("IndexOutOfBoundsException was not thrown.");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        ois.readFully(buf, -1, 1);
        fail("IndexOutOfBoundsException was not thrown.");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        ois.readFully(buf, testLength, 1);
        fail("IndexOutOfBoundsException was not thrown.");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    ois.close();
    Support_ASimpleInputStream sis = new Support_ASimpleInputStream(bao.toByteArray());
    ois = new ObjectInputStream(sis);
    sis.throwExceptionOnNextUse = true;
    try {
        ois.readFully(buf, 0, 1);
        fail("Test 1: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    sis.throwExceptionOnNextUse = false;
    ois.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

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