2 // OidTest.cs - NUnit tests for Oid
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using NUnit.Framework;
35 using System.Security.Cryptography;
37 namespace MonoTests.System.Security.Cryptography {
41 public class OidTest {
43 static string invalidOid = "1.0";
44 static string invalidName = "friendlyName";
45 static string validOid = "1.2.840.113549.1.1.1";
46 static string validName = "RSA";
49 public void ConstructorEmpty ()
52 Assert.IsNull (o.FriendlyName, "FriendlyName");
53 Assert.IsNull (o.Value, "Value");
57 public void ConstructorValidString ()
59 Oid o = new Oid (validOid);
60 Assert.AreEqual (validName, o.FriendlyName, "FriendlyName");
61 Assert.AreEqual (validOid, o.Value, "Value");
65 public void ConstructorInvalidString ()
67 Oid o = new Oid (invalidOid);
68 Assert.IsNull (o.FriendlyName, "FriendlyName");
69 Assert.AreEqual (invalidOid, o.Value, "Value");
73 [ExpectedException (typeof (ArgumentNullException))]
74 public void ConstructorNullString ()
76 string oid = null; // do not confuse compiler
77 Oid o = new Oid (oid);
81 public void ConstructorStringString ()
83 Oid o = new Oid (validOid, invalidName);
84 Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName");
85 Assert.AreEqual (validOid, o.Value, "Value");
89 //BUG [ExpectedException (typeof (ArgumentNullException))]
90 public void ConstructorStringNullString ()
92 Oid o = new Oid (null, validName);
93 Assert.AreEqual (validName, o.FriendlyName, "FriendlyName");
94 Assert.IsNull (o.Value, "Value");
98 public void ConstructorStringStringNull ()
100 Oid o = new Oid (validOid, null);
101 Assert.IsNull (o.FriendlyName, "FriendlyName");
102 Assert.AreEqual (validOid, o.Value, "Value");
106 public void ConstructorOid ()
108 Oid o = new Oid (validOid, invalidName);
109 Oid o2 = new Oid (o);
110 Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName==invalid");
111 Assert.AreEqual (o.FriendlyName, o2.FriendlyName, "FriendlyName");
112 Assert.AreEqual (o.Value, o2.Value, "Value");
116 [ExpectedException (typeof (ArgumentNullException))]
117 public void ConstructorOidNull ()
119 Oid onull = null; // do not confuse compiler
120 Oid o = new Oid (onull);
124 public void FriendlyName ()
126 Oid o = new Oid (invalidOid, invalidName);
127 Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName-1");
128 Assert.AreEqual (invalidOid, o.Value, "Value-1");
129 o.FriendlyName = validName;
130 Assert.AreEqual (validName, o.FriendlyName, "FriendlyName-2");
131 Assert.AreEqual (validOid, o.Value, "Value-2"); // surprise!
135 public void FriendlyNameNull ()
137 Oid o = new Oid (validOid, invalidName);
138 Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName");
139 o.FriendlyName = null;
140 Assert.IsNull (o.FriendlyName, "FriendlyName-Null");
146 Oid o = new Oid (validOid, invalidName);
147 Assert.AreEqual (validOid, o.Value, "Value-1");
148 o.Value = invalidName;
149 Assert.AreEqual (invalidName, o.Value, "Value-2");
153 public void ValueNull ()
155 Oid o = new Oid (validOid, invalidName);
156 Assert.AreEqual (validOid, o.Value, "Value");
158 Assert.IsNull (o.Value, "Value-Null");
162 public void WellKnownOid ()
164 Oid o = new Oid ("1.2.840.113549.1.1.1");
165 Assert.AreEqual ("1.2.840.113549.1.1.1", o.Value, "RSA Value");
166 Assert.AreEqual ("RSA", o.FriendlyName, "RSA FriendlyName");
168 o = new Oid ("1.2.840.113549.1.7.1");
169 Assert.AreEqual ("1.2.840.113549.1.7.1", o.Value, "PKCS 7 Data Value");
170 // FIXME: Don't expect that FriendlyName is English. This test fails under non-English Windows.
171 //Assert.AreEqual ("PKCS 7 Data", o.FriendlyName, "PKCS 7 Data FriendlyName");
173 o = new Oid ("1.2.840.113549.1.9.5");
174 Assert.AreEqual ("1.2.840.113549.1.9.5", o.Value, "Signing Time Value");
175 // FIXME: Don't expect that FriendlyName is English. This test fails under non-English Windows.
176 //Assert.AreEqual ("Signing Time", o.FriendlyName, "Signing Time FriendlyName");
178 o = new Oid ("1.2.840.113549.3.7");
179 Assert.AreEqual ("1.2.840.113549.3.7", o.Value, "3des Value");
180 Assert.AreEqual ("3des", o.FriendlyName, "3des FriendlyName");
182 // TODO: add other well known oid as we find them