01: package org.bouncycastle.asn1.test;
02:
03: import org.bouncycastle.asn1.ASN1InputStream;
04: import org.bouncycastle.asn1.DERString;
05: import org.bouncycastle.asn1.isismtt.x509.AdditionalInformationSyntax;
06: import org.bouncycastle.asn1.x500.DirectoryString;
07:
08: import java.io.IOException;
09:
10: public class AdditionalInformationSyntaxUnitTest extends ASN1UnitTest {
11: public String getName() {
12: return "AdditionalInformationSyntax";
13: }
14:
15: public void performTest() throws Exception {
16: AdditionalInformationSyntax syntax = new AdditionalInformationSyntax(
17: "hello world");
18:
19: checkConstruction(syntax, new DirectoryString("hello world"));
20:
21: syntax = AdditionalInformationSyntax.getInstance(null);
22:
23: if (syntax != null) {
24: fail("null getInstance() failed.");
25: }
26:
27: try {
28: AdditionalInformationSyntax.getInstance(new Object());
29:
30: fail("getInstance() failed to detect bad object.");
31: } catch (IllegalArgumentException e) {
32: // expected
33: }
34: }
35:
36: private void checkConstruction(AdditionalInformationSyntax syntax,
37: DirectoryString information) throws IOException {
38: checkValues(syntax, information);
39:
40: syntax = AdditionalInformationSyntax.getInstance(syntax);
41:
42: checkValues(syntax, information);
43:
44: ASN1InputStream aIn = new ASN1InputStream(syntax.toASN1Object()
45: .getEncoded());
46:
47: DERString info = (DERString) aIn.readObject();
48:
49: syntax = AdditionalInformationSyntax.getInstance(info);
50:
51: checkValues(syntax, information);
52: }
53:
54: private void checkValues(AdditionalInformationSyntax syntax,
55: DirectoryString information) {
56: checkMandatoryField("information", information, syntax
57: .getInformation());
58: }
59:
60: public static void main(String[] args) {
61: runTest(new AdditionalInformationSyntaxUnitTest());
62: }
63: }
|