01: package org.bouncycastle.asn1.test;
02:
03: import java.io.IOException;
04:
05: import org.bouncycastle.asn1.ASN1Encodable;
06: import org.bouncycastle.asn1.ASN1InputStream;
07: import org.bouncycastle.asn1.ASN1Sequence;
08: import org.bouncycastle.asn1.DERObjectIdentifier;
09: import org.bouncycastle.asn1.x509.qualified.QCStatement;
10: import org.bouncycastle.asn1.x509.qualified.RFC3739QCObjectIdentifiers;
11: import org.bouncycastle.asn1.x509.qualified.SemanticsInformation;
12: import org.bouncycastle.util.test.SimpleTest;
13:
14: public class QCStatementUnitTest extends SimpleTest {
15: public String getName() {
16: return "QCStatement";
17: }
18:
19: public void performTest() throws Exception {
20: QCStatement mv = new QCStatement(
21: RFC3739QCObjectIdentifiers.id_qcs_pkixQCSyntax_v1);
22:
23: checkConstruction(mv,
24: RFC3739QCObjectIdentifiers.id_qcs_pkixQCSyntax_v1, null);
25:
26: ASN1Encodable info = new SemanticsInformation(
27: new DERObjectIdentifier("1.2"));
28:
29: mv = new QCStatement(
30: RFC3739QCObjectIdentifiers.id_qcs_pkixQCSyntax_v1, info);
31:
32: checkConstruction(mv,
33: RFC3739QCObjectIdentifiers.id_qcs_pkixQCSyntax_v1, info);
34:
35: mv = QCStatement.getInstance(null);
36:
37: if (mv != null) {
38: fail("null getInstance() failed.");
39: }
40:
41: try {
42: QCStatement.getInstance(new Object());
43:
44: fail("getInstance() failed to detect bad object.");
45: } catch (IllegalArgumentException e) {
46: // expected
47: }
48: }
49:
50: private void checkConstruction(QCStatement mv,
51: DERObjectIdentifier statementId, ASN1Encodable statementInfo)
52: throws IOException {
53: checkStatement(mv, statementId, statementInfo);
54:
55: mv = QCStatement.getInstance(mv);
56:
57: checkStatement(mv, statementId, statementInfo);
58:
59: ASN1InputStream aIn = new ASN1InputStream(mv.toASN1Object()
60: .getEncoded());
61:
62: ASN1Sequence seq = (ASN1Sequence) aIn.readObject();
63:
64: mv = QCStatement.getInstance(seq);
65:
66: checkStatement(mv, statementId, statementInfo);
67: }
68:
69: private void checkStatement(QCStatement qcs,
70: DERObjectIdentifier statementId, ASN1Encodable statementInfo)
71: throws IOException {
72: if (!qcs.getStatementId().equals(statementId)) {
73: fail("statementIds don't match.");
74: }
75:
76: if (statementInfo != null) {
77: if (!qcs.getStatementInfo().equals(statementInfo)) {
78: fail("statementInfos don't match.");
79: }
80: } else if (qcs.getStatementInfo() != null) {
81: fail("statementInfo found when none expected.");
82: }
83: }
84:
85: public static void main(String[] args) {
86: runTest(new QCStatementUnitTest());
87: }
88: }
|