org.bouncycastle.asn1.test.BodyPartReferenceTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-jdk15to18 Show documentation
Show all versions of bcprov-jdk15to18 Show documentation
The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8.
package org.bouncycastle.asn1.test;
import java.util.Random;
import org.bouncycastle.asn1.cmc.BodyPartID;
import org.bouncycastle.asn1.cmc.BodyPartPath;
import org.bouncycastle.asn1.cmc.BodyPartReference;
import org.bouncycastle.util.test.SimpleTest;
public class BodyPartReferenceTest
extends SimpleTest
{
public String getName()
{
return "BodyPartReferenceTest";
}
public void performTest()
throws Exception
{
Random rand = new Random();
BodyPartReference ch0 = null;
BodyPartReference ch1 = null;
{
// Choice 1
BodyPartID id = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L));
ch0 = new BodyPartReference(id);
byte[] b = ch0.getEncoded();
BodyPartReference brRes = BodyPartReference.getInstance(b);
isEquals(brRes, ch0);
}
{
// Choice 2
BodyPartID[] bpid = new BodyPartID[Math.abs(rand.nextInt()) % 20];
for (int t = 0; t < bpid.length; t++)
{
bpid[t] = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L));
}
ch1 = new BodyPartReference(new BodyPartPath(bpid));
byte[] b = ch1.getEncoded();
BodyPartReference brRes = BodyPartReference.getInstance(b);
isEquals(brRes, ch1);
}
{
// Test choice alternatives are not equal.
BodyPartID id = new BodyPartID(Math.abs(rand.nextLong() % 4294967295L));
ch0 = new BodyPartReference(id);
ch1 = new BodyPartReference(new BodyPartPath(id));
try
{
isEquals(ch0, ch1);
fail("Must not be equal.");
}
catch (Throwable t)
{
// Ignored
}
}
}
public static void main(String[] args)
{
runTest(new BodyPartReferenceTest());
}
}