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();
}
use of java.security.DigestInputStream in project robovm by robovm.
the class DigestInputStreamTest method testRead02.
/**
* Test #2 for <code>read()</code> method<br>
*
* Assertion: returns -1 if EOS had been
* reached but not read before method call<br>
*
* Assertion: must not update digest if EOS had been
* reached but not read before method call<br>
*/
public final void testRead02() throws IOException {
for (int ii = 0; ii < algorithmName.length; ii++) {
try {
MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
InputStream is = new ByteArrayInputStream(myMessage);
DigestInputStream dis = new DigestInputStream(is, md);
for (int i = 0; i < MY_MESSAGE_LEN; i++) {
dis.read();
}
// check that subsequent read() calls return -1 (eos)
assertEquals("retval1", -1, dis.read());
assertEquals("retval2", -1, dis.read());
assertEquals("retval3", -1, dis.read());
// check that 3 previous read() calls did not update digest
assertTrue("update", Arrays.equals(dis.getMessageDigest().digest(), MDGoldenData.getDigest(algorithmName[ii])));
return;
} catch (NoSuchAlgorithmException e) {
// allowed failure
}
}
fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
Aggregations