1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
using System;
using NUnit.Framework;
using Org.BouncyCastle.Asn1.IsisMtt.X509;
using Org.BouncyCastle.Asn1.X500;
namespace Org.BouncyCastle.Asn1.Tests
{
[TestFixture]
public class NamingAuthorityUnitTest
: Asn1UnitTest
{
public override string Name
{
get { return "NamingAuthority"; }
}
public override void PerformTest()
{
DerObjectIdentifier namingAuthorityID = new DerObjectIdentifier("1.2.3");
string namingAuthorityURL = "url";
DirectoryString namingAuthorityText = new DirectoryString("text");
NamingAuthority auth = new NamingAuthority(namingAuthorityID, namingAuthorityURL, namingAuthorityText);
checkConstruction(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText);
auth = new NamingAuthority(null, namingAuthorityURL, namingAuthorityText);
checkConstruction(auth, null, namingAuthorityURL, namingAuthorityText);
auth = new NamingAuthority(namingAuthorityID, null, namingAuthorityText);
checkConstruction(auth, namingAuthorityID, null, namingAuthorityText);
auth = new NamingAuthority(namingAuthorityID, namingAuthorityURL, null);
checkConstruction(auth, namingAuthorityID, namingAuthorityURL, null);
auth = NamingAuthority.GetInstance(null);
if (auth != null)
{
Fail("null GetInstance() failed.");
}
try
{
NamingAuthority.GetInstance(new Object());
Fail("GetInstance() failed to detect bad object.");
}
catch (ArgumentException)
{
// expected
}
}
private void checkConstruction(
NamingAuthority auth,
DerObjectIdentifier namingAuthorityID,
string namingAuthorityURL,
DirectoryString namingAuthorityText)
{
checkValues(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText);
auth = NamingAuthority.GetInstance(auth);
checkValues(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText);
Asn1InputStream aIn = new Asn1InputStream(auth.ToAsn1Object().GetEncoded());
Asn1Sequence seq = (Asn1Sequence) aIn.ReadObject();
auth = NamingAuthority.GetInstance(seq);
checkValues(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText);
}
private void checkValues(
NamingAuthority auth,
DerObjectIdentifier namingAuthorityId,
string namingAuthorityURL,
DirectoryString namingAuthorityText)
{
checkOptionalField("namingAuthorityId", namingAuthorityId, auth.NamingAuthorityID);
checkOptionalField("namingAuthorityURL", namingAuthorityURL, auth.NamingAuthorityUrl);
checkOptionalField("namingAuthorityText", namingAuthorityText, auth.NamingAuthorityText);
}
public static void MainOld(
string[] args)
{
RunTest(new NamingAuthorityUnitTest());
}
[Test]
public void TestFunction()
{
string resultText = Perform().ToString();
Assert.AreEqual(Name + ": Okay", resultText);
}
}
}
|