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.
31 using NUnit.Framework;
34 using System.Security.Cryptography;
36 namespace MonoTests.System.Security.Cryptography {
40 public class OidTest {
42 static string invalidOid = "1.0";
43 static string invalidName = "friendlyName";
44 static string validOid = "1.2.840.113549.1.1.1";
45 static string validName = "RSA";
48 public void ConstructorEmpty ()
51 Assert.IsNull (o.FriendlyName, "FriendlyName");
52 Assert.IsNull (o.Value, "Value");
56 public void ConstructorValidString ()
58 Oid o = new Oid (validOid);
59 Assert.AreEqual (validName, o.FriendlyName, "FriendlyName");
60 Assert.AreEqual (validOid, o.Value, "Value");
64 public void ConstructorInvalidString ()
66 Oid o = new Oid (invalidOid);
67 Assert.IsNull (o.FriendlyName, "FriendlyName");
68 Assert.AreEqual (invalidOid, o.Value, "Value");
72 [ExpectedException (typeof (ArgumentNullException))]
73 public void ConstructorNullString ()
75 string oid = null; // do not confuse compiler
76 Oid o = new Oid (oid);
80 public void ConstructorStringString ()
82 Oid o = new Oid (validOid, invalidName);
83 Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName");
84 Assert.AreEqual (validOid, o.Value, "Value");
88 //BUG [ExpectedException (typeof (ArgumentNullException))]
89 public void ConstructorStringNullString ()
91 Oid o = new Oid (null, validName);
92 Assert.AreEqual (validName, o.FriendlyName, "FriendlyName");
93 Assert.IsNull (o.Value, "Value");
97 public void ConstructorStringStringNull ()
99 Oid o = new Oid (validOid, null);
100 Assert.IsNull (o.FriendlyName, "FriendlyName");
101 Assert.AreEqual (validOid, o.Value, "Value");
105 public void ConstructorOid ()
107 Oid o = new Oid (validOid, invalidName);
108 Oid o2 = new Oid (o);
109 Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName==invalid");
110 Assert.AreEqual (o.FriendlyName, o2.FriendlyName, "FriendlyName");
111 Assert.AreEqual (o.Value, o2.Value, "Value");
115 [ExpectedException (typeof (ArgumentNullException))]
116 public void ConstructorOidNull ()
118 Oid onull = null; // do not confuse compiler
119 Oid o = new Oid (onull);
123 public void FriendlyName ()
125 Oid o = new Oid (invalidOid, invalidName);
126 Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName-1");
127 Assert.AreEqual (invalidOid, o.Value, "Value-1");
128 o.FriendlyName = validName;
129 Assert.AreEqual (validName, o.FriendlyName, "FriendlyName-2");
130 Assert.AreEqual (validOid, o.Value, "Value-2"); // surprise!
134 public void FriendlyNameNull ()
136 Oid o = new Oid (validOid, invalidName);
137 Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName");
138 o.FriendlyName = null;
139 Assert.IsNull (o.FriendlyName, "FriendlyName-Null");
145 Oid o = new Oid (validOid, invalidName);
146 Assert.AreEqual (validOid, o.Value, "Value-1");
147 o.Value = invalidName;
148 Assert.AreEqual (invalidName, o.Value, "Value-2");
152 public void ValueNull ()
154 Oid o = new Oid (validOid, invalidName);
155 Assert.AreEqual (validOid, o.Value, "Value");
157 Assert.IsNull (o.Value, "Value-Null");
161 public void WellKnownOid ()
163 Oid o = new Oid ("1.2.840.113549.1.1.1");
164 Assert.AreEqual ("1.2.840.113549.1.1.1", o.Value, "RSA Value");
165 Assert.AreEqual ("RSA", o.FriendlyName, "RSA FriendlyName");
167 o = new Oid ("1.2.840.113549.1.7.1");
168 Assert.AreEqual ("1.2.840.113549.1.7.1", o.Value, "PKCS 7 Data Value");
169 // FIXME: Don't expect that FriendlyName is English. This test fails under non-English Windows.
170 //Assert.AreEqual ("PKCS 7 Data", o.FriendlyName, "PKCS 7 Data FriendlyName");
172 o = new Oid ("1.2.840.113549.1.9.5");
173 Assert.AreEqual ("1.2.840.113549.1.9.5", o.Value, "Signing Time Value");
174 // FIXME: Don't expect that FriendlyName is English. This test fails under non-English Windows.
175 //Assert.AreEqual ("Signing Time", o.FriendlyName, "Signing Time FriendlyName");
177 o = new Oid ("1.2.840.113549.3.7");
178 Assert.AreEqual ("1.2.840.113549.3.7", o.Value, "3des Value");
179 Assert.AreEqual ("3des", o.FriendlyName, "3des FriendlyName");
181 // TODO: add other well known oid as we find them