use of java.security.DigestInputStream in project robovm by robovm.
the class DigestInputStreamTest method testRead04.
/**
* Test #4 for <code>read()</code> method<br>
*
* Assertion: broken <code>DigestInputStream</code>instance:
* <code>InputStream</code> not set. <code>read()</code> must
* not work
*/
public final void testRead04() throws IOException {
for (int ii = 0; ii < algorithmName.length; ii++) {
try {
MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
DigestInputStream dis = new DigestInputStream(null, md);
// must result in an exception
try {
for (int i = 0; i < MY_MESSAGE_LEN; i++) {
dis.read();
}
} catch (Exception e) {
// Expected.
return;
}
fail("InputStream not set. read() must not work");
} catch (NoSuchAlgorithmException e) {
// allowed failure
}
}
fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
use of java.security.DigestInputStream in project robovm by robovm.
the class DigestInputStream2Test method test_ConstructorLjava_io_InputStreamLjava_security_MessageDigest.
/**
* java.security.DigestInputStream#DigestInputStream(java.io.InputStream,
* java.security.MessageDigest)
*/
public void test_ConstructorLjava_io_InputStreamLjava_security_MessageDigest() {
// Test for method java.security.DigestInputStream(java.io.InputStream,
// java.security.MessageDigest)
DigestInputStream dis = new DigestInputStream(inStream, digest);
assertNotNull("Constructor returned null instance", dis);
}
use of java.security.DigestInputStream in project robovm by robovm.
the class DigestInputStream2Test method test_read.
/**
* java.security.DigestInputStream#read()
*/
public void test_read() throws IOException {
// Test for method int java.security.DigestInputStream.read()
DigestInputStream dis = new DigestInputStream(inStream, digest);
// read and compare the data that the inStream has
int c;
while ((c = dis.read()) > -1) {
int d = inStream1.read();
assertEquals(d, c);
}
// end while
}
use of java.security.DigestInputStream in project robovm by robovm.
the class DigestInputStream2Test method test_getMessageDigest.
/**
* java.security.DigestInputStream#getMessageDigest()
*/
public void test_getMessageDigest() {
// Test for method java.security.MessageDigest
// java.security.DigestInputStream.getMessageDigest()
DigestInputStream dis = new DigestInputStream(inStream, digest);
assertEquals("getMessageDigest returned a bogus result", digest, dis.getMessageDigest());
}
use of java.security.DigestInputStream 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();
}
Aggregations