Search in sources :

Example 21 with Support_ASimpleInputStream

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

the class DigestInputStream2Test method test_read$BII_Exception.

/**
     * java.security.DigestInputStream#read(byte[], int, int)
     */
public void test_read$BII_Exception() throws IOException {
    DigestInputStream is = new DigestInputStream(inStream, digest);
    byte[] buf = null;
    try {
        is.read(buf, -1, 0);
        fail("Test 1: NullPointerException expected.");
    } catch (NullPointerException e) {
    // Expected.
    }
    buf = new byte[1000];
    try {
        is.read(buf, -1, 0);
        fail("Test 2: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        is.read(buf, 0, -1);
        fail("Test 3: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        is.read(buf, -1, -1);
        fail("Test 4: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        is.read(buf, 0, 1001);
        fail("Test 5: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        is.read(buf, 1001, 0);
        fail("Test 6: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        is.read(buf, 500, 501);
        fail("Test 7: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    is.close();
    Support_ASimpleInputStream sis = new Support_ASimpleInputStream(true);
    is = new DigestInputStream(sis, digest);
    try {
        is.read(buf, 0, 100);
        fail("Test 9: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    sis.throwExceptionOnNextUse = false;
    is.close();
}
Also used : DigestInputStream(java.security.DigestInputStream) Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) IOException(java.io.IOException)

Example 22 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 23 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)

Example 24 with Support_ASimpleInputStream

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

the class Test method test_read_IOException.

public void test_read_IOException() throws IOException {
    oos.writeObject(testString);
    oos.close();
    Support_ASimpleInputStream sis = new Support_ASimpleInputStream(bao.toByteArray());
    ois = new ObjectInputStream(sis);
    sis.throwExceptionOnNextUse = true;
    try {
        ois.read();
        fail("Test 1: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    sis.throwExceptionOnNextUse = false;
    ois.close();
}
Also used : Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 25 with Support_ASimpleInputStream

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

the class Test method test_close.

public void test_close() throws Exception {
    // Test for method void java.io.ObjectInputStream.close()
    oos.writeObject(testString);
    oos.close();
    Support_ASimpleInputStream sis = new Support_ASimpleInputStream(bao.toByteArray());
    ois = new ObjectInputStream(sis);
    sis.throwExceptionOnNextUse = true;
    try {
        ois.close();
        fail("Test 1: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    sis.throwExceptionOnNextUse = false;
    ois.close();
}
Also used : 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