Author: spouliot
Date: 2007-01-05 11:39:15 -0500 (Fri, 05 Jan 2007)
New Revision: 70538

Modified:
   trunk/mcs/class/Mono.Security/Test/Mono.Security/ASN1ConvertTest.cs
   trunk/mcs/class/Mono.Security/Test/Mono.Security/ChangeLog
Log:
2007-01-05  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * ASN1ConvertTest.cs: Update unit test syntax to NUnit 2.2. Change
        DateTime.UtcNow to Now as the API requires, under 1.x, a local date 
        time. Disregard buggy ConvertOID_LargeX under MS 2.0.



Modified: trunk/mcs/class/Mono.Security/Test/Mono.Security/ASN1ConvertTest.cs
===================================================================
--- trunk/mcs/class/Mono.Security/Test/Mono.Security/ASN1ConvertTest.cs 
2007-01-05 16:38:54 UTC (rev 70537)
+++ trunk/mcs/class/Mono.Security/Test/Mono.Security/ASN1ConvertTest.cs 
2007-01-05 16:39:15 UTC (rev 70538)
@@ -4,7 +4,7 @@
 // Author:
 //     Sebastien Pouliot ([EMAIL PROTECTED])
 //
-// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2007 Novell, Inc (http://www.novell.com)
 //
 
 using System;
@@ -17,37 +17,58 @@
 namespace MonoTests.Mono.Security {
 
        [TestFixture]
-       public class ASN1ConvertTest : Assertion {
+       public class ASN1ConvertTest {
 
+               // UtcNow has more precision than the ASN.1 encoded has
+               // we need to ignore the extra subseconds but using ToString
+               // won't work under 2.0 (Utc string compared to Local string)
+               private void AssertDate (DateTime expected, DateTime actual, 
string message)
+               {
+                       // expected is full precision, actual has second-level 
precision
+                       double seconds = new TimeSpan (expected.Ticks - 
actual.Ticks).TotalSeconds;
+                       if (seconds >= 1.0) {
+                               Assert.Fail ("Expected {0} has more than one 
second ({1}) difference with actual data {2}",
+                                       expected, seconds, actual);
+                       }
+               }
+
                [Test]
                public void ConvertDateTimeBefore2000 () 
                {
-                       DateTime expected = DateTime.UtcNow.AddYears (-50);
+                       DateTime expected = DateTime.Now.AddYears (-50);
                        ASN1 dt = ASN1Convert.FromDateTime (expected);
-                       AssertEquals ("UTCTIME", 0x17, dt.Tag);
+                       Assert.AreEqual (0x17, dt.Tag, "UTCTIME");
                        DateTime actual = ASN1Convert.ToDateTime (dt);
-                       AssertEquals ("DateTime", expected.ToString (), 
actual.ToString ());
+#if NET_2_0
+                       Assert.AreEqual (DateTimeKind.Utc, actual.Kind, "Kind");
+#endif
+                       AssertDate (expected, actual, "DateTime");
                }
 
                [Test]
-               [Ignore("We are sorting out the issues of the public API of 
FromDateTime")]
                public void ConvertDateTimeAfter2000 () 
                {
-                       DateTime expected = DateTime.UtcNow;
+                       DateTime expected = DateTime.Now;
                        ASN1 dt = ASN1Convert.FromDateTime (expected);
-                       AssertEquals ("UTCTIME", 0x17, dt.Tag);
+                       Assert.AreEqual (0x17, dt.Tag, "UTCTIME");
                        DateTime actual = ASN1Convert.ToDateTime (dt);
-                       AssertEquals ("DateTime", expected.ToString (), 
actual.ToString ());
+#if NET_2_0
+                       Assert.AreEqual (DateTimeKind.Utc, actual.Kind, "Kind");
+#endif
+                       AssertDate (expected, actual, "DateTime");
                }
 
                [Test]
                public void ConvertDateTimeAfter2050 () 
                {
-                       DateTime expected = DateTime.UtcNow.AddYears (50);
+                       DateTime expected = DateTime.Now.AddYears (50);
                        ASN1 dt = ASN1Convert.FromDateTime (expected);
-                       AssertEquals ("GENERALIZEDTIME", 0x18, dt.Tag);
+                       Assert.AreEqual (0x18, dt.Tag, "GENERALIZEDTIME");
                        DateTime actual = ASN1Convert.ToDateTime (dt);
-                       AssertEquals ("DateTime", expected.ToString (), 
actual.ToString ());
+#if NET_2_0
+                       Assert.AreEqual (DateTimeKind.Utc, actual.Kind, "Kind");
+#endif
+                       AssertDate (expected, actual, "DateTime");
                }
 
                [Test]
@@ -56,7 +77,10 @@
                        string nosecs = "9912312359Z"; 
                        ASN1 dt = new ASN1 (0x18, Encoding.ASCII.GetBytes 
(nosecs));
                        DateTime actual = ASN1Convert.ToDateTime (dt);
-                       AssertEquals ("DateTime", nosecs, 
actual.ToUniversalTime ().ToString ("yyMMddHHmm") + "Z");
+#if NET_2_0
+                       Assert.AreEqual (DateTimeKind.Utc, actual.Kind, "Kind");
+#endif
+                       Assert.AreEqual (nosecs, actual.ToUniversalTime 
().ToString ("yyMMddHHmm") + "Z", "DateTime");
                }
 
                [Test]
@@ -72,7 +96,7 @@
                        Int32 expected = -1;
                        ASN1 integer = ASN1Convert.FromInt32 (expected);
                        Int32 actual = ASN1Convert.ToInt32 (integer);
-                       AssertEquals ("Int32_Negative", expected, actual);
+                       Assert.AreEqual (expected, actual, "Int32_Negative");
                }
 
                [Test]
@@ -81,7 +105,7 @@
                        Int32 expected = 0;
                        ASN1 integer = ASN1Convert.FromInt32 (expected);
                        Int32 actual = ASN1Convert.ToInt32 (integer);
-                       AssertEquals ("Int32_Zero", expected, actual);
+                       Assert.AreEqual (expected, actual, "Int32_Zero");
                }
                [Test]
                public void ConvertInt32_One () 
@@ -89,7 +113,7 @@
                        Int32 expected = 1;
                        ASN1 integer = ASN1Convert.FromInt32 (expected);
                        Int32 actual = ASN1Convert.ToInt32 (integer);
-                       AssertEquals ("Int32_Zero", expected, actual);
+                       Assert.AreEqual (expected, actual, "Int32_Zero");
                }
 
                [Test]
@@ -98,7 +122,7 @@
                        Int32 expected = Int32.MaxValue;
                        ASN1 integer = ASN1Convert.FromInt32 (expected);
                        Int32 actual = ASN1Convert.ToInt32 (integer);
-                       AssertEquals ("Int32_Positive", expected, actual);
+                       Assert.AreEqual (expected, actual, "Int32_Positive");
                }
 
                [Test]
@@ -131,12 +155,12 @@
                        big [0] = 1;
                        ASN1 bigint = ASN1Convert.FromUnsignedBigInteger (big);
                        // no byte is required for the sign (100% positive it's 
positive ;-)
-                       AssertEquals ("BigInteger-NotExtended", 16, 
bigint.Value.Length);
+                       Assert.AreEqual (16, bigint.Value.Length, 
"BigInteger-NotExtended");
 
                        big [0] = 0x80;
                        bigint = ASN1Convert.FromUnsignedBigInteger (big);
                        // one byte added as 0x00 to be sure it's not 
interpreted as a negative
-                       AssertEquals ("BigInteger-SignExtended", 17, 
bigint.Value.Length);
+                       Assert.AreEqual (17, bigint.Value.Length, 
"BigInteger-SignExtended");
                }
 
                [Test]
@@ -145,18 +169,25 @@
                        string expected = "1.2.840.113549.1.7.6";
                        ASN1 oid = ASN1Convert.FromOid (expected);
                        string actual = ASN1Convert.ToOid (oid);
-                       AssertEquals ("OID", expected, actual);
+                       Assert.AreEqual (expected, actual, "OID");
                }
 
                [Test]
+#if NET_2_0
+               // the large X test tries to encode an invalid OID (second part 
being > 40).
+               // In 1.x CryptoConfig.EncodeOID just encoded the binary (so we 
copied the 
+               // *bad* behaviour) but 2.0 encode it differently (sigh)
+               [Category ("NotDotNet")]
+#endif
                public void ConvertOID_LargeX () 
                {
                        ASN1 asn = new ASN1 (0x06, new byte [] { 0xA8, 0x00, 
0x00 });
                        string oid = ASN1Convert.ToOid (asn);
-                       AssertEquals ("ToOID", "2.88.0.0", oid);
-                       AssertEquals ("FromOID", BitConverter.ToString 
(asn.GetBytes ()), 
-                               BitConverter.ToString (ASN1Convert.FromOid 
(oid).GetBytes ()));
+                       Assert.AreEqual ("2.88.0.0", oid, "ToOID");
+                       Assert.AreEqual (BitConverter.ToString (asn.GetBytes 
()),
+                               BitConverter.ToString (ASN1Convert.FromOid 
(oid).GetBytes ()), "FromOID");
                }
+
                [Test]
                [ExpectedException (typeof (ArgumentNullException))]
                public void ConvertFromOid_Null () 

Modified: trunk/mcs/class/Mono.Security/Test/Mono.Security/ChangeLog
===================================================================
--- trunk/mcs/class/Mono.Security/Test/Mono.Security/ChangeLog  2007-01-05 
16:38:54 UTC (rev 70537)
+++ trunk/mcs/class/Mono.Security/Test/Mono.Security/ChangeLog  2007-01-05 
16:39:15 UTC (rev 70538)
@@ -1,3 +1,9 @@
+2007-01-05  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * ASN1ConvertTest.cs: Update unit test syntax to NUnit 2.2. Change
+       DateTime.UtcNow to Now as the API requires, under 1.x, a local date 
+       time. Disregard buggy ConvertOID_LargeX under MS 2.0.
+
 2006-10-06  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * ASN1ConvertTest.cs: Adjusted big integer convertion test cases for

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to