use of java.security.DigestInputStream in project robovm by robovm.
the class DigestInputStreamTest method testDigestInputStream01.
//
// Tests
//
/**
* Test #1 for <code>DigestInputStream</code> constructor<br>
*
* Assertion: creates new <code>DigestInputStream</code> instance
* using valid parameters (both non <code>null</code>)
*
* @throws NoSuchAlgorithmException
*/
public final void testDigestInputStream01() {
for (int i = 0; i < algorithmName.length; i++) {
try {
MessageDigest md = MessageDigest.getInstance(algorithmName[i]);
InputStream is = new ByteArrayInputStream(myMessage);
InputStream dis = new DigestInputStream(is, md);
assertTrue(dis instanceof DigestInputStream);
return;
} 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 DigestInputStreamTest method testRead06.
/**
* Test #6 for <code>read()</code> method<br>
* Test #2 for <code>on(boolean)</code> method<br>
*
* Assertion: broken <code>DigestInputStream</code>instance:
* associated <code>MessageDigest</code> not set.
* <code>read()</code> must work when digest
* functionality is off
*/
public final void testRead06() throws IOException {
InputStream is = new ByteArrayInputStream(myMessage);
// construct object without digest
DigestInputStream dis = new DigestInputStream(is, null);
// set digest functionality to off
dis.on(false);
// the following must pass without any exception
for (int i = 0; i < MY_MESSAGE_LEN; i++) {
assertTrue((byte) dis.read() == myMessage[i]);
}
}
use of java.security.DigestInputStream in project robovm by robovm.
the class DigestInputStreamTest method testToString.
/**
* Test for <code>toString()</code> method<br>
* Assertion: returns <code>String</code> representation of this object
*/
public final void testToString() {
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);
assertNotNull(dis.toString());
return;
} 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 FilterInputStreamNullSourceTest method testDigestInputStream.
public void testDigestInputStream() throws IOException, NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
assertReadsFailWithNullPointerException(new DigestInputStream(null, md5));
}
use of java.security.DigestInputStream in project robovm by robovm.
the class DigestInputStream2Test method test_read$BII.
/**
* java.security.DigestInputStream#read(byte[], int, int)
*/
public void test_read$BII() throws IOException {
// Test for method int java.security.DigestInputStream.read(byte [],
// int, int)
DigestInputStream dis = new DigestInputStream(inStream, digest);
int bytesToRead = inStream.available();
byte[] buf1 = new byte[bytesToRead + 5];
byte[] buf2 = new byte[bytesToRead + 5];
// make sure we're actually reading some data
assertTrue("No data to read for this test", bytesToRead > 0);
// read and compare the data that the inStream has
int bytesRead1 = dis.read(buf1, 5, bytesToRead);
int bytesRead2 = inStream1.read(buf2, 5, bytesToRead);
assertEquals("Didn't read the same from each stream", bytesRead1, bytesRead2);
assertEquals("Didn't read the entire", bytesRead1, bytesToRead);
// compare the arrays
boolean same = true;
for (int i = 0; i < bytesToRead + 5; i++) {
if (buf1[i] != buf2[i]) {
same = false;
}
}
// end for
assertTrue("Didn't get the same data", same);
}
Aggregations