2003-11-06 Sebastien Pouliot <spouliot@videotron.ca>
authorSebastien Pouliot <sebastien@ximian.com>
Fri, 7 Nov 2003 02:04:00 +0000 (02:04 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Fri, 7 Nov 2003 02:04:00 +0000 (02:04 -0000)
* AsnEncodedDataTest.cs: New. Unit tests for AsnEncodedData (.NET 1.2).
* OidTest.cs: New. Unit tests for Oid (.NET 1.2).
* OidCollectionTest.cs: New. Unit tests for OidCollection (.NET 1.2).
* OidEnumeratorTest.cs: New. Unit tests for OidEnumerator (.NET 1.2).

svn path=/trunk/mcs/; revision=19702

mcs/class/System.Security/Test/System.Security.Cryptography/AsnEncodedDataTest.cs [new file with mode: 0755]
mcs/class/System.Security/Test/System.Security.Cryptography/ChangeLog [new file with mode: 0755]
mcs/class/System.Security/Test/System.Security.Cryptography/OidCollectionTest.cs [new file with mode: 0755]
mcs/class/System.Security/Test/System.Security.Cryptography/OidEnumeratorTest.cs [new file with mode: 0755]
mcs/class/System.Security/Test/System.Security.Cryptography/OidTest.cs [new file with mode: 0755]

diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography/AsnEncodedDataTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography/AsnEncodedDataTest.cs
new file mode 100755 (executable)
index 0000000..08ea1fc
--- /dev/null
@@ -0,0 +1,120 @@
+//
+// AsnEncodedDataTest.cs - NUnit tests for AsnEncodedData
+//
+// Author:
+//     Sebastien Pouliot (spouliot@motus.com)
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+
+#if NET_1_2
+
+using NUnit.Framework;
+
+using System;
+using System.Security.Cryptography;
+
+namespace MonoTests.System.Security.Cryptography {
+
+       [TestFixture]
+       public class AsnEncodedDataTest : Assertion {
+
+               static byte[] asnNullBytes = { 0x05, 0x00 };
+               static string asnNullString = "05 00";
+               static byte[] asnLongBytes = { 0x30,0x5C,0x02,0x55,0x2D,0x58,0xE9,0xBF,0xF0,0x31,0xCD,0x79,0x06,0x50,0x5A,0xD5,0x9E,0x0E,0x2C,0xE6,0xC2,0xF7,0xF9,0xD2,0xCE,0x55,0x64,0x85,0xB1,0x90,0x9A,0x92,0xB3,0x36,0xC1,0xBC,0xEA,0xC8,0x23,0xB7,0xAB,0x3A,0xA7,0x64,0x63,0x77,0x5F,0x84,0x22,0x8E,0xE5,0xB6,0x45,0xDD,0x46,0xAE,0x0A,0xDD,0x00,0xC2,0x1F,0xBA,0xD9,0xAD,0xC0,0x75,0x62,0xF8,0x95,0x82,0xA2,0x80,0xB1,0x82,0x69,0xFA,0xE1,0xAF,0x7F,0xBC,0x7D,0xE2,0x7C,0x76,0xD5,0xBC,0x2A,0x80,0xFB,0x02,0x03,0x01,0x00,0x01 };
+               static string asnLongString = "30 5c 02 55 2d 58 e9 bf f0 31 cd 79 06 50 5a d5 9e 0e 2c e6 c2 f7 f9 d2 ce 55 64 85 b1 90 9a 92 b3 36 c1 bc ea c8 23 b7 ab 3a a7 64 63 77 5f 84 22 8e e5 b6 45 dd 46 ae 0a dd 00 c2 1f ba d9 ad c0 75 62 f8 95 82 a2 80 b1 82 69 fa e1 af 7f bc 7d e2 7c 76 d5 bc 2a 80 fb 02 03 01 00 01";
+
+               private void AssertEquals (string message, byte[] expected, byte[] actual) 
+               {
+                       AssertEquals (message, BitConverter.ToString (expected), BitConverter.ToString (actual));
+               }
+
+               [Test]
+               public void ConstructorStringData ()
+               {
+                       AsnEncodedData aed = new AsnEncodedData ("oid", asnNullBytes);
+                       AssertEquals ("Format", asnNullString, aed.Format (true));
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void ConstructorStringNullData () 
+               {
+                       string oid = null; // do not confuse compiler
+                       AsnEncodedData aed = new AsnEncodedData (oid, asnNullBytes);
+                       AssertEquals ("Format", asnNullString, aed.Format (true));
+               }
+
+               [Test]
+               //BUG [ExpectedException (typeof (ArgumentNullException))]
+               [ExpectedException (typeof (NullReferenceException))]
+               public void ConstructorStringDataNull () 
+               {
+                       AsnEncodedData aed = new AsnEncodedData ("oid", null);
+                       AssertEquals ("Format", asnNullString, aed.Format (true));
+               }
+
+               [Test]
+               public void ConstructorOidData () 
+               {
+                       Oid o = new Oid ("1.0");
+                       AsnEncodedData aed = new AsnEncodedData (o, asnNullBytes);
+                       AssertEquals ("Format", asnNullString, aed.Format (true));
+               }
+
+               [Test]
+               //BUG [ExpectedException (typeof (ArgumentNullException))]
+               [ExpectedException (typeof (NullReferenceException))]
+               public void ConstructorOidNullData () 
+               {
+                       Oid o = null;
+                       AsnEncodedData aed = new AsnEncodedData (o, asnNullBytes);
+               }
+
+               [Test]
+               //BUG [ExpectedException (typeof (ArgumentNullException))]
+               [ExpectedException (typeof (NullReferenceException))]
+               public void ConstructorOidDataNull () 
+               {
+                       Oid o = new Oid ("1.0");
+                       AsnEncodedData aed = new AsnEncodedData (o, null);
+               }
+
+               [Test]
+               public void ConstructorAsn () 
+               {
+                       AsnEncodedData aed = new AsnEncodedData ("oid", asnNullBytes);
+                       AsnEncodedData aed2 = new AsnEncodedData (aed);
+                       AssertEquals ("FriendlyName", aed.RawData, aed2.RawData);
+                       string s1 = aed.Format (false); 
+                       string s2 = aed.Format (true);
+                       AssertEquals ("Format", s1, s2);
+               }
+
+               [Test]
+               //BUG [ExpectedException (typeof (ArgumentNullException))]
+               [ExpectedException (typeof (NullReferenceException))]
+               public void ConstructorAsnNull ()
+               {
+                       AsnEncodedData aed = new AsnEncodedData (null);
+               }
+
+               [Test]
+               public void Format () 
+               {
+                       AsnEncodedData aed = new AsnEncodedData ("1.2.840.113549.1.1.1", asnLongBytes);
+                       string result = aed.Format (false);
+                       AssertEquals ("Format(false)", asnLongString, result);
+               }
+
+               [Test]
+               public void FormatMultiline ()
+               {
+                       AsnEncodedData aed = new AsnEncodedData ("1.2.840.113549.1.1.1", asnLongBytes);
+                       string result = aed.Format (true);
+                       AssertEquals ("Format(true)", asnLongString, result);
+               }
+       }
+}
+
+#endif
diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography/ChangeLog b/mcs/class/System.Security/Test/System.Security.Cryptography/ChangeLog
new file mode 100755 (executable)
index 0000000..44805ec
--- /dev/null
@@ -0,0 +1,7 @@
+2003-11-06  Sebastien Pouliot  <spouliot@videotron.ca>
+
+       * AsnEncodedDataTest.cs: New. Unit tests for AsnEncodedData (.NET 1.2).
+       * OidTest.cs: New. Unit tests for Oid (.NET 1.2).
+       * OidCollectionTest.cs: New. Unit tests for OidCollection (.NET 1.2).
+       * OidEnumeratorTest.cs: New. Unit tests for OidEnumerator (.NET 1.2).
+
diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography/OidCollectionTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography/OidCollectionTest.cs
new file mode 100755 (executable)
index 0000000..bc0f8b0
--- /dev/null
@@ -0,0 +1,75 @@
+//
+// OidCollectionTest.cs - NUnit tests for OidCollection
+//
+// Author:
+//     Sebastien Pouliot (spouliot@motus.com)
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+
+#if NET_1_2
+
+using NUnit.Framework;
+
+using System;
+using System.Security.Cryptography;
+
+namespace MonoTests.System.Security.Cryptography {
+
+       [TestFixture]
+       public class OidCollectionTest : Assertion {
+
+               [Test]
+               public void Constructor () 
+               {
+                       OidCollection oc = new OidCollection ();
+                       // default properties
+                       AssertEquals ("Count", 0, oc.Count);
+                       Assert ("IsSynchronized", !oc.IsSynchronized);
+                       AssertNotNull ("SyncRoot", oc.SyncRoot);
+                       AssertNotNull ("GetEnumerator", oc.GetEnumerator ());
+               }
+
+               [Test]
+               public void Add ()
+               {
+                       OidCollection oc = new OidCollection ();
+                       oc.Add (new Oid ("1.0"));
+                       AssertEquals ("Count", 1, oc.Count);
+                       AssertEquals ("[0]", "1.0", oc [0].Value);
+                       AssertEquals ("['1.0']", "1.0", oc ["1.0"].Value);
+               }
+
+               [Test]
+               //BUG [ExpectedException (typeof (ArgumentNullException))]
+               public void AddNull () 
+               {
+                       OidCollection oc = new OidCollection ();
+                       oc.Add (null);
+                       AssertEquals ("Count", 1, oc.Count);
+                       // AssertNull ("[0]", oc); throw NullReferenceException
+               }
+
+               [Test]
+               public void CopyToOid () 
+               {
+                       OidCollection oc = new OidCollection ();
+                       oc.Add (new Oid ("1.0"));
+                       Oid[] array = new Oid [1];
+                       oc.CopyTo (array, 0);
+                       AssertEquals ("CopyTo(Oid)", "1.0", array [0].Value);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void CopyToOidNull ()
+               {
+                       OidCollection oc = new OidCollection ();
+                       oc.Add (new Oid ("1.0"));
+                       Oid[] array = null;
+                       oc.CopyTo (array, 0);
+               }
+       }
+}
+
+#endif
diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography/OidEnumeratorTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography/OidEnumeratorTest.cs
new file mode 100755 (executable)
index 0000000..4257494
--- /dev/null
@@ -0,0 +1,82 @@
+//
+// OidEnumeratorTest.cs - NUnit tests for OidEnumerator
+//
+// Author:
+//     Sebastien Pouliot (spouliot@motus.com)
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+
+#if NET_1_2
+
+using NUnit.Framework;
+
+using System;
+using System.Security.Cryptography;
+
+namespace MonoTests.System.Security.Cryptography {
+
+       [TestFixture]
+       public class OidEnumeratorTest : Assertion {
+
+               private OidEnumerator GetEnumerator () 
+               {
+                       OidCollection oc = new OidCollection ();
+                       oc.Add (new Oid ("1.0"));
+                       oc.Add (new Oid ("1.1"));
+                       oc.Add (new Oid ("1.2"));
+                       return oc.GetEnumerator ();
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentOutOfRangeException))]
+               public void Current_BeforeFirstElement ()
+               {
+                       OidEnumerator enumerator = GetEnumerator ();
+                       Oid oid = enumerator.Current;
+               }
+
+               [Test]
+               public void Current () 
+               {
+                       OidEnumerator enumerator = GetEnumerator ();
+                       enumerator.MoveNext ();
+                       Oid oid = enumerator.Current;
+                       AssertNotNull ("Current", oid);
+               }
+
+               [Test]
+               public void Current_AfterLastElement ()
+               {
+                       OidEnumerator enumerator = GetEnumerator ();
+                       while (enumerator.MoveNext ());
+                       Oid oid = enumerator.Current;
+                       AssertNotNull ("Current_AfterLastElement", oid);
+                       AssertEquals ("Current==last", "1.2", oid.Value);
+               }
+
+               [Test]
+               public void MoveNext () 
+               {
+                       OidEnumerator enumerator = GetEnumerator ();
+                       int n = 0;
+                       while (enumerator.MoveNext ()) {
+                               n++;
+                       }
+                       AssertEquals ("MoveNext", 3, n);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentOutOfRangeException))]
+               public void Reset () 
+               {
+                       OidEnumerator enumerator = GetEnumerator ();
+                       enumerator.MoveNext ();
+                       AssertNotNull ("Current before reset", enumerator.Current);
+                       enumerator.Reset ();
+                       AssertNotNull ("Current after reset", enumerator.Current);
+               }
+       }
+}
+
+#endif
\ No newline at end of file
diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography/OidTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography/OidTest.cs
new file mode 100755 (executable)
index 0000000..a021c76
--- /dev/null
@@ -0,0 +1,145 @@
+//
+// OidTest.cs - NUnit tests for Oid
+//
+// Author:
+//     Sebastien Pouliot (spouliot@motus.com)
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+
+#if NET_1_2
+
+using NUnit.Framework;
+
+using System;
+using System.Security.Cryptography;
+
+namespace MonoTests.System.Security.Cryptography {
+
+       [TestFixture]
+       public class OidTest : Assertion {
+
+               static string invalidOid = "1.0";
+               static string invalidName = "friendlyName";
+               static string validOid = "1.2.840.113549.1.1.1";
+               static string validName = "RSA";
+
+               [Test]
+               public void ConstructorEmpty () 
+               {
+                       Oid o = new Oid ();
+                       AssertNull ("FriendlyName", o.FriendlyName);
+                       AssertNull ("Value", o.Value);
+               }
+
+               [Test]
+               public void ConstructorValidValue () 
+               {
+                       Oid o = new Oid (validOid);
+                       AssertEquals ("FriendlyName", validName, o.FriendlyName);
+                       AssertEquals ("Value", validOid, o.Value);
+               }
+
+               [Test]
+               public void ConstructorInvalidValue () 
+               {
+                       Oid o = new Oid (invalidOid);
+                       AssertNull ("FriendlyName", o.FriendlyName);
+                       AssertEquals ("Value", invalidOid, o.Value);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void ConstructorValueNull () 
+               {
+                       string oid = null; // do not confuse compiler
+                       Oid o = new Oid (oid);
+               }
+
+               [Test]
+               public void ConstructorValueName ()
+               {
+                       Oid o = new Oid (validOid, invalidName);
+                       AssertEquals ("FriendlyName", invalidName, o.FriendlyName);
+                       AssertEquals ("Value", validOid, o.Value);
+               }
+
+               [Test]
+               //BUG [ExpectedException (typeof (ArgumentNullException))]
+               public void ConstructorValueNullName () 
+               {
+                       Oid o = new Oid (null, validName);
+                       AssertEquals ("FriendlyName", validName, o.FriendlyName);
+                       AssertNull ("Value", o.Value);
+               }
+
+               [Test]
+               //BUG [ExpectedException (typeof (ArgumentNullException))]
+               public void ConstructorValueNameNull () 
+               {
+                       Oid o = new Oid (validOid, null);
+                       AssertNull ("FriendlyName", o.FriendlyName);
+                       AssertEquals ("Value", validOid, o.Value);
+               }
+
+               [Test]
+               public void ConstructorOid ()
+               {
+                       Oid o = new Oid (validOid, invalidName);
+                       Oid o2 = new Oid (o);
+                       AssertEquals ("FriendlyName==invalid", invalidName, o.FriendlyName);
+                       AssertEquals ("FriendlyName", o.FriendlyName, o2.FriendlyName);
+                       AssertEquals ("Value", o.Value, o2.Value);
+               }
+
+               [Test]
+               //BUG [ExpectedException (typeof (ArgumentNullException))]
+               [ExpectedException (typeof (NullReferenceException))]
+               public void ConstructorOidNull () 
+               {
+                       Oid onull = null; // do not confuse compiler
+                       Oid o = new Oid (onull);
+               }
+
+               [Test]
+               public void FriendlyName () 
+               {
+                       Oid o = new Oid (invalidOid, invalidName);
+                       AssertEquals ("FriendlyName", invalidName, o.FriendlyName);
+                       AssertEquals ("Value", invalidOid, o.Value);
+                       o.FriendlyName = validName;
+                       AssertEquals ("FriendlyName", validName, o.FriendlyName);
+                       AssertEquals ("Value", validOid, o.Value); // surprise!
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void FriendlyNameNull ()
+               {
+                       Oid o = new Oid (validOid, invalidName);
+                       AssertEquals ("FriendlyName", invalidName, o.FriendlyName);
+                       o.FriendlyName = null;
+               }
+
+               [Test]
+               public void Value () 
+               {
+                       Oid o = new Oid (validOid, invalidName);
+                       AssertEquals ("Value", validOid, o.Value);
+                       o.Value = invalidName;
+                       AssertEquals ("Value", invalidName, o.Value);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void ValueNull () 
+               {
+                       Oid o = new Oid (validOid, invalidName);
+                       AssertEquals ("Value", validOid, o.Value);
+                       o.Value = null;
+                       AssertNull ("Value==null", o.Value);
+               }
+       }
+}
+
+#endif