Author: gert
Date: 2007-07-21 05:03:40 -0400 (Sat, 21 Jul 2007)
New Revision: 82410

Modified:
   trunk/mcs/class/corlib/System/BitConverter.cs
   trunk/mcs/class/corlib/System/ChangeLog
   trunk/mcs/class/corlib/Test/System/BitConverterTest.cs
   trunk/mcs/class/corlib/Test/System/ChangeLog
Log:
* BitConverter.cs: Fixed exceptions to match MS. Fixed invalid use
of ArgumentOutOfRangeException and ArgumentException ctors that take
both parameter name and message. In ToString throws ArgumentException
instead of ArgumentOutOfRangeException when length is negative, and
return zero-length string when length is 0.
* BitConverterTest.cs: Remove use of deprecated Assertion class. 
Improved existing tests to verify throws exception. Create separate 
tests for null argument checking. Added tests for empty byte array.


Modified: trunk/mcs/class/corlib/System/BitConverter.cs
===================================================================
--- trunk/mcs/class/corlib/System/BitConverter.cs       2007-07-21 08:28:19 UTC 
(rev 82409)
+++ trunk/mcs/class/corlib/System/BitConverter.cs       2007-07-21 09:03:40 UTC 
(rev 82410)
@@ -4,7 +4,6 @@
 // Author:
 //   Matt Kimball ([EMAIL PROTECTED])
 //
-
 //
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
@@ -30,15 +29,16 @@
 
 using System.Text;
 
-namespace System {
+namespace System
+{
        public
 #if NET_2_0
-               static
+       static
 #else
-               sealed
+       sealed
 #endif
-       class BitConverter {
-
+       class BitConverter
+       {
 #if !NET_2_0
                private BitConverter ()
                {
@@ -48,7 +48,6 @@
                static readonly bool SwappedWordsInDouble = 
DoubleWordsAreSwapped ();
                public static readonly bool IsLittleEndian = AmILittleEndian ();
 
-
                static unsafe bool AmILittleEndian ()
                {
                        // binary representations of 1.0:
@@ -166,22 +165,26 @@
 
                unsafe static void PutBytes (byte *dst, byte[] src, int 
start_index, int count)
                {
-                       if (src == null) {
-                               throw new ArgumentNullException ("value"); // 
gets called from methods with value params
-                       }
+                       if (src == null)
+#if NET_2_0
+                               throw new ArgumentNullException ("value");
+#else
+                               throw new ArgumentNullException ("byteArray");
+#endif
 
-                       if (start_index < 0)
-                               throw new ArgumentOutOfRangeException 
("startIndex < 0");
+                       if (start_index < 0 || (start_index > src.Length - 1))
+                               throw new ArgumentOutOfRangeException 
("startIndex", "Index was"
+                                       + " out of range. Must be non-negative 
and less than the"
+                                       + " size of the collection.");
 
                        // avoid integer overflow (with large pos/neg 
start_index values)
-                       if (src.Length - count < start_index) {
-                               throw new ArgumentOutOfRangeException 
(Locale.GetText (
-                                       "Value is too big to return the 
requested type."), "startIndex");
-                       }
+                       if (src.Length - count < start_index)
+                               throw new ArgumentException ("Destination array 
is not long"
+                                       + " enough to copy all the items in the 
collection."
+                                       + " Check array index and length.");
 
-                       for (int i = 0; i < count; i++) {
+                       for (int i = 0; i < count; i++)
                                dst[i] = src[i + start_index];
-                       }
                }
 
                unsafe public static bool ToBoolean (byte[] value, int 
startIndex)
@@ -189,14 +192,11 @@
                        if (value == null) 
                                throw new ArgumentNullException ("value");
 
-                       if (startIndex < 0)
-                               throw new ArgumentOutOfRangeException 
("startIndex < 0");
+                       if (startIndex < 0 || (startIndex > value.Length - 1))
+                               throw new ArgumentOutOfRangeException 
("startIndex", "Index was"
+                                       + " out of range. Must be non-negative 
and less than the"
+                                       + " size of the collection.");
 
-                       // avoid integer overflow (with large pos/neg 
start_index values)
-                       if (value.Length - 1 < startIndex) 
-                               throw new ArgumentOutOfRangeException 
(Locale.GetText (
-                                       "Value is too big to return the 
requested type."), "startIndex");
-
                        if (value [startIndex] != 0)
                                return true;
                        
@@ -287,14 +287,17 @@
                                if (value == null)
                                        throw new ArgumentNullException 
("value");
 
-                               if (startIndex < 0)
-                                       throw new ArgumentOutOfRangeException 
("startIndex < 0");
+                               if (startIndex < 0 || (startIndex > 
value.Length - 1))
+                                       throw new ArgumentOutOfRangeException 
("startIndex", "Index was"
+                                               + " out of range. Must be 
non-negative and less than the"
+                                               + " size of the collection.");
 
                                // avoid integer overflow (with large pos/neg 
start_index values)
-                               if (value.Length - 8 < startIndex) {
-                                       throw new ArgumentOutOfRangeException 
(Locale.GetText (
-                                               "Value is too big to return the 
requested type."), "startIndex");
-                               }
+                               if (value.Length - 8 < startIndex)
+                                       throw new ArgumentException 
("Destination array is not long"
+                                               + " enough to copy all the 
items in the collection."
+                                               + " Check array index and 
length.");
+
                                p [0] = value [startIndex + 4];
                                p [1] = value [startIndex + 5];
                                p [2] = value [startIndex + 6];
@@ -321,14 +324,17 @@
                                if (value == null)
                                        throw new ArgumentNullException 
("value");
 
-                               if (startIndex < 0)
-                                       throw new ArgumentOutOfRangeException 
("startIndex < 0");
+                               if (startIndex < 0 || (startIndex > 
value.Length - 1))
+                                       throw new ArgumentOutOfRangeException 
("startIndex", "Index was"
+                                               + " out of range. Must be 
non-negative and less than the"
+                                               + " size of the collection.");
 
                                // avoid integer overflow (with large pos/neg 
start_index values)
-                               if (value.Length - 8 < startIndex) {
-                                       throw new ArgumentOutOfRangeException 
(Locale.GetText (
-                                               "Value is too big to return the 
requested type."), "startIndex");
-                               }
+                               if (value.Length - 8 < startIndex)
+                                       throw new ArgumentException 
("Destination array is not long"
+                                               + " enough to copy all the 
items in the collection."
+                                               + " Check array index and 
length.");
+
                                p [0] = value [startIndex + 4];
                                p [1] = value [startIndex + 5];
                                p [2] = value [startIndex + 6];
@@ -339,20 +345,22 @@
                                p [7] = value [startIndex + 3];
 
                                return ret;
-                       }
-                       else if (!IsLittleEndian) {
+                       } else if (!IsLittleEndian) {
                                byte* p = (byte*)&ret;
                                if (value == null)
                                        throw new ArgumentNullException 
("value");
 
-                               if (startIndex < 0)
-                                       throw new ArgumentOutOfRangeException 
("startIndex < 0");
+                               if (startIndex < 0 || (startIndex > 
value.Length - 1))
+                                       throw new ArgumentOutOfRangeException 
("startIndex", "Index was"
+                                               + " out of range. Must be 
non-negative and less than the"
+                                               + " size of the collection.");
 
                                // avoid integer overflow (with large pos/neg 
start_index values)
-                               if (value.Length - 8 < startIndex) {
-                                       throw new ArgumentOutOfRangeException 
(Locale.GetText (
-                                               "Value is too big to return the 
requested type."), "startIndex");
-                               }
+                               if (value.Length - 8 < startIndex)
+                                       throw new ArgumentException 
("Destination array is not long"
+                                               + " enough to copy all the 
items in the collection."
+                                               + " Check array index and 
length.");
+
                                p [0] = value [startIndex + 7];
                                p [1] = value [startIndex + 6];
                                p [2] = value [startIndex + 5];
@@ -363,7 +371,7 @@
                                p [7] = value [startIndex + 0];
 
                                return ret;
-                       }                               
+                       }
 
                        PutBytes ((byte *) &ret, value, startIndex, 8);
 
@@ -372,9 +380,8 @@
                
                public static string ToString (byte[] value)
                {
-                       if (value == null) {
+                       if (value == null)
                                throw new ArgumentNullException ("value");
-                       }
 
                        return ToString (value, 0, value.Length);
                }
@@ -383,34 +390,41 @@
                {
                        if (value == null)
                                throw new ArgumentNullException ("value");
-                       if (startIndex < 0 || startIndex > value.Length - 1) 
-                               throw new ArgumentOutOfRangeException 
("startIndex");
 
                        return ToString (value, startIndex, value.Length - 
startIndex);
                }
 
                public static string ToString (byte[] value, int startIndex, 
int length)
                {
-                       if (value == null) {
-                               throw new ArgumentNullException ("value");
-                       }
+                       if (value == null)
+                               throw new ArgumentNullException ("byteArray");
 
                        // The 4th and last clause (start_index >= value.Length)
                        // was added as a small fix to a very obscure bug.
                        // It makes a small difference when start_index is
                        // outside the range and length==0. 
-                       if (startIndex < 0 || length < 0 || startIndex >= 
value.Length) {
+                       if (startIndex < 0 || startIndex >= value.Length) {
 #if NET_2_0
                                // special (but valid) case (e.g. new byte [0])
                                if ((startIndex == 0) && (value.Length == 0))
                                        return String.Empty;
 #endif
-                               throw new ArgumentOutOfRangeException 
("startIndex");
+                               throw new ArgumentOutOfRangeException 
("startIndex", "Index was"
+                                       + " out of range. Must be non-negative 
and less than the"
+                                       + " size of the collection.");
                        }
+
+                       if (length < 0)
+                               throw new ArgumentOutOfRangeException ("length",
+                                       "Value must be positive.");
+
                        // note: re-ordered to avoid possible integer overflow
                        if (startIndex > value.Length - length)
                                throw new ArgumentException ("startIndex + 
length > value.Length");
 
+                       if (length == 0)
+                               return string.Empty;
+
                        StringBuilder builder = new StringBuilder(length * 3 - 
1);
                        int end = startIndex + length;
 

Modified: trunk/mcs/class/corlib/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System/ChangeLog     2007-07-21 08:28:19 UTC (rev 
82409)
+++ trunk/mcs/class/corlib/System/ChangeLog     2007-07-21 09:03:40 UTC (rev 
82410)
@@ -1,3 +1,11 @@
+2007-07-21  Gert Driesen  <[EMAIL PROTECTED]>
+
+       * BitConverter.cs: Fixed exceptions to match MS. Fixed invalid use
+       of ArgumentOutOfRangeException and ArgumentException ctors that take
+       both parameter name and message. In ToString throws ArgumentException
+       instead of ArgumentOutOfRangeException when length is negative, and
+       return zero-length string when length is 0.
+
 2007-07-20  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * AppDomainSetup.cs : fix serialization regression.

Modified: trunk/mcs/class/corlib/Test/System/BitConverterTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System/BitConverterTest.cs      2007-07-21 
08:28:19 UTC (rev 82409)
+++ trunk/mcs/class/corlib/Test/System/BitConverterTest.cs      2007-07-21 
09:03:40 UTC (rev 82410)
@@ -13,570 +13,987 @@
 
 namespace MonoTests.System
 {
-
-[TestFixture]
-public class BitConverterTest : Assertion {
-       
-       public void TestIsLittleEndian ()
+       [TestFixture]
+       public class BitConverterTest
        {
-               byte[] b;
+               public void TestIsLittleEndian ()
+               {
+                       byte [] b = BitConverter.GetBytes (1);
+                       Assert.AreEqual (b [0] == 1, 
BitConverter.IsLittleEndian, "#1");
+               }
 
-               b = BitConverter.GetBytes (1);
-               AssertEquals ("A1", b[0] == 1, BitConverter.IsLittleEndian );
-       }
+               private void PrivateTestSingle (float v1)
+               {
+                       float v2;
+                       byte [] b;
+                       byte [] larger = new byte [] { 0x00, 0x01, 0x02, 0x03, 
0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
 
-       private void PrivateTestSingle (float v1)
-       {
-               float v2;
-               byte[] b;
-               byte[] larger = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 
0x05, 0x06, 0x07, 0x08, 0x09 }; 
-               bool exception;
-               
-               b = BitConverter.GetBytes (v1);
-               AssertEquals("A1", 4, b.Length);
+                       b = BitConverter.GetBytes (v1);
+                       Assert.AreEqual (4, b.Length, "#A1");
 
-               v2 = BitConverter.ToSingle (b, 0);
-               AssertEquals("A2", v1, v2);     
+                       v2 = BitConverter.ToSingle (b, 0);
+                       Assert.AreEqual (v1, v2, "#A2");
 
-               b.CopyTo (larger, 1);
-               v2 = BitConverter.ToSingle (larger, 1);
-               AssertEquals("A3", v1, v2);
+                       b.CopyTo (larger, 1);
+                       v2 = BitConverter.ToSingle (larger, 1);
+                       Assert.AreEqual (v1, v2, "#A3");
 
-               try {
-                       v2 = BitConverter.ToSingle (larger, 8);
-                       exception = false;
+                       try {
+                               BitConverter.ToSingle (larger, 8);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // Destination array is not long enough to copy 
all the items
+                               // in the collection. Check array index and 
length
+                               Assert.AreEqual (typeof (ArgumentException), 
ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       try {
+                               BitConverter.ToSingle (larger, 10);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // Index was out of range. Must be non-negative 
and less than
+                               // the size of the collection
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNotNull (ex.ParamName, "#C5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#C6");
+                       }
                }
-               catch (ArgumentException) {
-                       exception = true;
-               } 
-               Assert ("A4", exception);
 
-               try {
-                       v2 = BitConverter.ToSingle ((byte[]) null, 77);
-                       exception = false;
+               [Test]
+               public void TestSingle ()
+               {
+                       PrivateTestSingle (0.1f);
+                       PrivateTestSingle (24.1e30f);
                }
-               catch (ArgumentNullException) {
-                       exception = true;
+
+               [Test]
+               public void ToSingle_Value_Null ()
+               {
+                       try {
+                               BitConverter.ToSingle ((byte []) null, 77);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof 
(ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+#if NET_2_0
+                               Assert.AreEqual ("value", ex.ParamName, "#6");
+#else
+                               Assert.AreEqual ("byteArray", ex.ParamName, 
"#6");
+#endif
+                       }
                }
-               Assert ("A5", exception);
-       }
 
-       public void TestSingle()
-       {
-               PrivateTestSingle (0.1f);
-               PrivateTestSingle (24.1e30f);
-       }
+               private void PrivateTestDouble (double v1)
+               {
+                       double v2;
+                       byte [] b;
+                       byte [] larger = new byte [] { 0x00, 0x01, 0x02, 0x03, 
0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
 
-       private void PrivateTestDouble (double v1)
-       {
-               double v2;
-               byte[] b;
-               byte[] larger = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 
0x05, 0x06, 0x07, 0x08, 0x09 }; 
-               bool exception;
-               
-               b = BitConverter.GetBytes (v1);
-               AssertEquals("A1", 8, b.Length);
+                       b = BitConverter.GetBytes (v1);
+                       Assert.AreEqual (8, b.Length, "#A1");
 
-               v2 = BitConverter.ToDouble (b, 0);
-               AssertEquals("A2", v1, v2);     
+                       v2 = BitConverter.ToDouble (b, 0);
+                       Assert.AreEqual (v1, v2, "#A2");
 
-               b.CopyTo (larger, 1);
-               v2 = BitConverter.ToDouble (larger, 1);
-               AssertEquals("A3", v1, v2);
+                       b.CopyTo (larger, 1);
+                       v2 = BitConverter.ToDouble (larger, 1);
+                       Assert.AreEqual (v1, v2, "#A3");
 
-               try {
-                       v2 = BitConverter.ToDouble (larger, 3);
-                       exception = false;
+                       try {
+                               BitConverter.ToDouble (larger, 3);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // Destination array is not long enough to copy 
all the items
+                               // in the collection. Check array index and 
length
+                               Assert.AreEqual (typeof (ArgumentException), 
ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       try {
+                               BitConverter.ToDouble (larger, 10);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // Index was out of range. Must be non-negative 
and less than
+                               // the size of the collection
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNotNull (ex.ParamName, "#C5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#C6");
+                       }
                }
-               catch (ArgumentException) {
-                       exception = true;
-               } 
-               Assert ("A4", exception);
 
-               try {
-                       v2 = BitConverter.ToDouble ((byte[]) null, 77);
-                       exception = false;
+               [Test]
+               public void TestDouble ()
+               {
+                       double d = 123.321;
+
+                       Assert.AreEqual (d, BitConverter.Int64BitsToDouble 
(BitConverter.DoubleToInt64Bits (d)), "#1");
+
+                       PrivateTestDouble (0.1);
+                       PrivateTestDouble (24.1e77);
                }
-               catch (ArgumentNullException) {
-                       exception = true;
+
+               [Test]
+               public void ToDouble_Value_Null ()
+               {
+                       try {
+                               BitConverter.ToDouble ((byte []) null, 77);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof 
(ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+#if NET_2_0
+                               Assert.AreEqual ("value", ex.ParamName, "#6");
+#else
+                               Assert.AreEqual ("byteArray", ex.ParamName, 
"#6");
+#endif
+                       }
                }
-               Assert ("A5", exception);
-       }
 
-       public void TestDouble ()
-       {
-               double d = 123.321;
+               private void PrivateTestBool (bool v1)
+               {
+                       bool v2;
+                       byte [] b;
+                       byte [] larger = new byte [] { 0x00, 0x01, 0x02, 0x03 };
 
-               AssertEquals("A1", d, BitConverter.Int64BitsToDouble 
(BitConverter.DoubleToInt64Bits (d)));
+                       b = BitConverter.GetBytes (v1);
+                       Assert.AreEqual (1, b.Length, "#A1");
 
-               PrivateTestDouble (0.1);
-               PrivateTestDouble (24.1e77);
-       }
+                       v2 = BitConverter.ToBoolean (b, 0);
+                       Assert.AreEqual (v1, v2, "#A2");
 
-       private void PrivateTestBool (bool v1)
-       {
-               bool v2;
-               byte[] b;
-               byte[] larger = new byte[] { 0x00, 0x01, 0x02, 0x03 }; 
-               bool exception;
-               
-               b = BitConverter.GetBytes (v1);
-               AssertEquals("A1", 1, b.Length);
+                       b.CopyTo (larger, 1);
+                       v2 = BitConverter.ToBoolean (larger, 1);
+                       Assert.AreEqual (v1, v2, "#A3");
 
-               v2 = BitConverter.ToBoolean (b, 0);
-               AssertEquals("A2", v1, v2);     
+                       try {
+                               BitConverter.ToBoolean (larger, 4);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // Index was out of range. Must be non-negative 
and less than
+                               // the size of the collection
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNotNull (ex.ParamName, "#B5");
+#if NET_2_0
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#B6");
+#endif
+                       }
+               }
 
-               b.CopyTo (larger, 1);
-               v2 = BitConverter.ToBoolean (larger, 1);
-               AssertEquals("A3", v1, v2);
-
-               try {
-                       v2 = BitConverter.ToBoolean (larger, 4);
-                       exception = false;
+               [Test]
+               public void TestBool ()
+               {
+                       PrivateTestBool (true);
+                       PrivateTestBool (false);
                }
-               catch (ArgumentException) {
-                       exception = true;
-               } 
-               Assert ("A4", exception);
 
-               try {
-                       v2 = BitConverter.ToBoolean ((byte[]) null, 77);
-                       exception = false;
+               [Test]
+               public void ToBoolean_Value_Null ()
+               {
+                       try {
+                               BitConverter.ToBoolean ((byte []) null, 77);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof 
(ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+                               Assert.AreEqual ("value", ex.ParamName, "#6");
+                       }
                }
-               catch (ArgumentNullException) {
-                       exception = true;
-               }
-               Assert ("A5", exception);
-       }
 
-       public void TestBool () {
-               PrivateTestBool(true);
-               PrivateTestBool(false);
-       }
+               private void PrivateTestChar (char v1)
+               {
+                       char v2;
+                       byte [] b;
+                       byte [] larger = new byte [] { 0x00, 0x01, 0x02, 0x03 };
 
-       private void PrivateTestChar (char v1)
-       {
-               char v2;
-               byte[] b;
-               byte[] larger = new byte[] { 0x00, 0x01, 0x02, 0x03 }; 
-               bool exception;
-               
-               b = BitConverter.GetBytes (v1);
-               AssertEquals("A1", 2, b.Length);
+                       b = BitConverter.GetBytes (v1);
+                       Assert.AreEqual (2, b.Length, "#A1");
 
-               v2 = BitConverter.ToChar (b, 0);
-               AssertEquals("A2", v1, v2);     
+                       v2 = BitConverter.ToChar (b, 0);
+                       Assert.AreEqual (v1, v2, "#A2");
 
-               b.CopyTo (larger, 1);
-               v2 = BitConverter.ToChar (larger, 1);
-               AssertEquals("A3", v1, v2);
+                       b.CopyTo (larger, 1);
+                       v2 = BitConverter.ToChar (larger, 1);
+                       Assert.AreEqual (v1, v2, "#A3");
 
-               try {
-                       v2 = BitConverter.ToChar (larger, 3);
-                       exception = false;
+                       try {
+                               BitConverter.ToChar (larger, 3);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // Destination array is not long enough to copy 
all the items
+                               // in the collection. Check array index and 
length
+                               Assert.AreEqual (typeof (ArgumentException), 
ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       try {
+                               BitConverter.ToChar (larger, 4);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // Index was out of range. Must be non-negative 
and less than
+                               // the size of the collection
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNotNull (ex.ParamName, "#C5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#C6");
+                       }
                }
-               // LAMESPEC:
-               // the docs say it should be ArgumentOutOfRangeException, but
-               // the mscorlib throws an ArgumentException.
-               catch (ArgumentException) {
-                       exception = true;
-               } 
-               Assert ("A4", exception);
 
-               try {
-                       v2 = BitConverter.ToChar ((byte[]) null, 77);
-                       exception = false;
+               [Test]
+               public void TestChar ()
+               {
+                       PrivateTestChar ('A');
+                       PrivateTestChar ('\x01ff');
                }
-               catch (ArgumentNullException) {
-                       exception = true;
+
+               [Test]
+               public void ToChar_Value_Null ()
+               {
+                       try {
+                               BitConverter.ToChar ((byte []) null, 77);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof 
(ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+#if NET_2_0
+                               Assert.AreEqual ("value", ex.ParamName, "#6");
+#else
+                               Assert.AreEqual ("byteArray", ex.ParamName, 
"#6");
+#endif
+                       }
                }
-               Assert ("A5", exception);
-       }
 
-       public void TestChar ()
-       {
-               PrivateTestChar('A');
-               PrivateTestChar('\x01ff');
-       }
+               private void PrivateTestInt16 (short v1)
+               {
+                       short v2;
+                       byte [] b;
+                       byte [] larger = new byte [] { 0x00, 0x01, 0x02, 0x03 };
 
-       private void PrivateTestInt16 (short v1)
-       {
-               short v2;
-               byte[] b;
-               byte[] larger = new byte[] { 0x00, 0x01, 0x02, 0x03 }; 
-               bool exception;
-               
-               b = BitConverter.GetBytes (v1);
-               AssertEquals("A1", 2, b.Length);
+                       b = BitConverter.GetBytes (v1);
+                       Assert.AreEqual (2, b.Length, "#A1");
 
-               v2 = BitConverter.ToInt16 (b, 0);
-               AssertEquals("A2", v1, v2);     
+                       v2 = BitConverter.ToInt16 (b, 0);
+                       Assert.AreEqual (v1, v2, "#A2");
 
-               b.CopyTo (larger, 1);
-               v2 = BitConverter.ToInt16 (larger, 1);
-               AssertEquals("A3", v1, v2);
+                       b.CopyTo (larger, 1);
+                       v2 = BitConverter.ToInt16 (larger, 1);
+                       Assert.AreEqual (v1, v2, "#A3");
 
-               try {
-                       v2 = BitConverter.ToInt16 (larger, 3);
-                       exception = false;
+                       try {
+                               BitConverter.ToInt16 (larger, 3);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // Destination array is not long enough to copy 
all the items
+                               // in the collection. Check array index and 
length
+                               Assert.AreEqual (typeof (ArgumentException), 
ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       try {
+                               BitConverter.ToInt16 (larger, 4);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // Index was out of range. Must be non-negative 
and less than
+                               // the size of the collection
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNotNull (ex.ParamName, "#C5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#C6");
+                       }
                }
-               catch (ArgumentException) {
-                       exception = true;
-               } 
-               Assert ("A4", exception);
 
-               try {
-                       v2 = BitConverter.ToInt16 ((byte[]) null, 77);
-                       exception = false;
+               [Test]
+               public void TestInt16 ()
+               {
+                       PrivateTestInt16 (0);
+                       PrivateTestInt16 (1000);
+                       PrivateTestInt16 (-32768);
+                       PrivateTestInt16 (32767);
                }
-               catch (ArgumentNullException) {
-                       exception = true;
+
+               [Test]
+               public void ToInt16_Value_Null ()
+               {
+                       try {
+                               BitConverter.ToInt16 ((byte []) null, 77);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof 
(ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+#if NET_2_0
+                               Assert.AreEqual ("value", ex.ParamName, "#6");
+#else
+                               Assert.AreEqual ("byteArray", ex.ParamName, 
"#6");
+#endif
+                       }
                }
-               Assert ("A5", exception);
-       }
 
-       public void TestInt16 ()
-       {
-               PrivateTestInt16 (0);
-               PrivateTestInt16 (1000);
-               PrivateTestInt16 (-32768);
-               PrivateTestInt16 (32767);
-       }
+               private void PrivateTestUInt16 (ushort v1)
+               {
+                       ushort v2;
+                       byte [] b;
+                       byte [] larger = new byte [] { 0x00, 0x01, 0x02, 0x03 };
 
-       private void PrivateTestUInt16 (ushort v1)
-       {
-               ushort v2;
-               byte[] b;
-               byte[] larger = new byte[] { 0x00, 0x01, 0x02, 0x03 }; 
-               bool exception;
-               
-               b = BitConverter.GetBytes (v1);
-               AssertEquals("A1", 2, b.Length);
+                       b = BitConverter.GetBytes (v1);
+                       Assert.AreEqual (2, b.Length, "#A1");
 
-               v2 = BitConverter.ToUInt16 (b, 0);
-               AssertEquals("A2", v1, v2);     
+                       v2 = BitConverter.ToUInt16 (b, 0);
+                       Assert.AreEqual (v1, v2, "#A2");
 
-               b.CopyTo (larger, 1);
-               v2 = BitConverter.ToUInt16 (larger, 1);
-               AssertEquals("A3", v1, v2);
+                       b.CopyTo (larger, 1);
+                       v2 = BitConverter.ToUInt16 (larger, 1);
+                       Assert.AreEqual (v1, v2, "#A3");
 
-               try {
-                       v2 = BitConverter.ToUInt16 (larger, 3);
-                       exception = false;
+                       try {
+                               BitConverter.ToUInt16 (larger, 3);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // Destination array is not long enough to copy 
all the items
+                               // in the collection. Check array index and 
length
+                               Assert.AreEqual (typeof (ArgumentException), 
ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       try {
+                               BitConverter.ToUInt16 (larger, 4);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // Index was out of range. Must be non-negative 
and less than
+                               // the size of the collection
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNotNull (ex.ParamName, "#C5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#C6");
+                       }
                }
-               catch (ArgumentException) {
-                       exception = true;
-               } 
-               Assert ("A4", exception);
 
-               try {
-                       v2 = BitConverter.ToUInt16 ((byte[]) null, 77);
-                       exception = false;
+               [Test]
+               public void TestUInt16 ()
+               {
+                       PrivateTestUInt16 (0);
+                       PrivateTestUInt16 (1000);
+                       PrivateTestUInt16 (65535);
                }
-               catch (ArgumentNullException) {
-                       exception = true;
+
+               [Test]
+               public void ToUInt16_Value_Null ()
+               {
+                       try {
+                               BitConverter.ToUInt16 ((byte []) null, 77);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof 
(ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+#if NET_2_0
+                               Assert.AreEqual ("value", ex.ParamName, "#6");
+#else
+                               Assert.AreEqual ("byteArray", ex.ParamName, 
"#6");
+#endif
+                       }
                }
-               Assert ("A5", exception);
-       }
 
-       public void TestUInt16 ()
-       {
-               PrivateTestUInt16 (0);
-               PrivateTestUInt16 (1000);
-               PrivateTestUInt16 (65535);
-       }
+               private void PrivateTestInt32 (int v1)
+               {
+                       int v2;
+                       byte [] b;
+                       byte [] larger = new byte [] { 0x00, 0x01, 0x02, 0x03, 
0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
 
-       private void PrivateTestInt32 (int v1)
-       {
-               int v2;
-               byte[] b;
-               byte[] larger = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 
0x05, 0x06, 0x07, 0x08, 0x09 }; 
-               bool exception;
-               
-               b = BitConverter.GetBytes (v1);
-               AssertEquals("A1", 4, b.Length);
+                       b = BitConverter.GetBytes (v1);
+                       Assert.AreEqual (4, b.Length, "#A1");
 
-               v2 = BitConverter.ToInt32 (b, 0);
-               AssertEquals("A2", v1, v2);     
+                       v2 = BitConverter.ToInt32 (b, 0);
+                       Assert.AreEqual (v1, v2, "#A2");
 
-               b.CopyTo (larger, 1);
-               v2 = BitConverter.ToInt32 (larger, 1);
-               AssertEquals("A3", v1, v2);
+                       b.CopyTo (larger, 1);
+                       v2 = BitConverter.ToInt32 (larger, 1);
+                       Assert.AreEqual (v1, v2, "#A3");
 
-               try {
-                       v2 = BitConverter.ToInt32 (larger, 8);
-                       exception = false;
+                       try {
+                               BitConverter.ToInt32 (larger, 8);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // Destination array is not long enough to copy 
all the items
+                               // in the collection. Check array index and 
length
+                               Assert.AreEqual (typeof (ArgumentException), 
ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       try {
+                               BitConverter.ToInt32 (larger, 10);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // Index was out of range. Must be non-negative 
and less than
+                               // the size of the collection
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNotNull (ex.ParamName, "#C5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#C6");
+                       }
                }
-               catch (ArgumentException) {
-                       exception = true;
-               } 
-               Assert ("A4", exception);
 
-               try {
-                       v2 = BitConverter.ToInt32 ((byte[]) null, 77);
-                       exception = false;
+               [Test]
+               public void TestInt32 ()
+               {
+                       PrivateTestInt32 (0);
+                       PrivateTestInt32 (1000);
+                       PrivateTestInt32 (-2147483648);
+                       PrivateTestInt32 (2147483647);
                }
-               catch (ArgumentNullException) {
-                       exception = true;
+
+               [Test]
+               public void ToInt32_Value_Null ()
+               {
+                       try {
+                               BitConverter.ToInt32 ((byte []) null, 77);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof 
(ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+#if NET_2_0
+                               Assert.AreEqual ("value", ex.ParamName, "#6");
+#else
+                               Assert.AreEqual ("byteArray", ex.ParamName, 
"#6");
+#endif
+                       }
                }
-               Assert ("A5", exception);
-       }
 
-       public void TestInt32 ()
-       {
-               PrivateTestInt32 (0);
-               PrivateTestInt32 (1000);
-               PrivateTestInt32 (-2147483648);
-               PrivateTestInt32 (2147483647);
-       }
+               private void PrivateTestUInt32 (uint v1)
+               {
+                       uint v2;
+                       byte [] b;
+                       byte [] larger = new byte [] { 0x00, 0x01, 0x02, 0x03, 
0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
 
-       private void PrivateTestUInt32 (uint v1)
-       {
-               uint v2;
-               byte[] b;
-               byte[] larger = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 
0x05, 0x06, 0x07, 0x08, 0x09 }; 
-               bool exception;
-               
-               b = BitConverter.GetBytes (v1);
-               AssertEquals ("A1", 4, b.Length);
+                       b = BitConverter.GetBytes (v1);
+                       Assert.AreEqual (4, b.Length, "#A1");
 
-               v2 = BitConverter.ToUInt32 (b, 0);
-               AssertEquals ("A2", v1, v2);    
+                       v2 = BitConverter.ToUInt32 (b, 0);
+                       Assert.AreEqual (v1, v2, "#A2");
 
-               b.CopyTo (larger, 1);
-               v2 = BitConverter.ToUInt32 (larger, 1);
-               AssertEquals ("A3", v1, v2);
+                       b.CopyTo (larger, 1);
+                       v2 = BitConverter.ToUInt32 (larger, 1);
+                       Assert.AreEqual (v1, v2, "#A3");
 
-               try {
-                       v2 = BitConverter.ToUInt32 (larger, 8);
-                       exception = false;
+                       try {
+                               BitConverter.ToUInt32 (larger, 8);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // Destination array is not long enough to copy 
all the items
+                               // in the collection. Check array index and 
length
+                               Assert.AreEqual (typeof (ArgumentException), 
ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       try {
+                               BitConverter.ToUInt32 (larger, 10);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // Index was out of range. Must be non-negative 
and less than
+                               // the size of the collection
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNotNull (ex.ParamName, "#C5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#C6");
+                       }
                }
-               catch (ArgumentException) {
-                       exception = true;
-               } 
-               Assert ("A4", exception);
 
-               try {
-                       v2 = BitConverter.ToUInt32 ((byte[]) null, 77);
-                       exception = false;
+               [Test]
+               public void TestUInt32 ()
+               {
+                       PrivateTestUInt32 (0u);
+                       PrivateTestUInt32 (1000u);
+                       PrivateTestUInt32 (4294967295u);
                }
-               catch (ArgumentNullException) {
-                       exception = true;
+
+               [Test]
+               public void ToUInt32_Value_Null ()
+               {
+                       try {
+                               BitConverter.ToUInt32 ((byte []) null, 77);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof 
(ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+#if NET_2_0
+                               Assert.AreEqual ("value", ex.ParamName, "#6");
+#else
+                               Assert.AreEqual ("byteArray", ex.ParamName, 
"#6");
+#endif
+                       }
                }
-               Assert ("A5", exception);
-       }
 
-       public void TestUInt32 ()
-       {
-               PrivateTestUInt32 (0u);
-               PrivateTestUInt32 (1000u);
-               PrivateTestUInt32 (4294967295u);
-       }
+               private void PrivateTestInt64 (long v1)
+               {
+                       long v2;
+                       byte [] b;
+                       byte [] larger = new byte [] { 0x00, 0x01, 0x02, 0x03, 
0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
 
-       private void PrivateTestInt64 (long v1)
-       {
-               long v2;
-               byte[] b;
-               byte[] larger = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 
0x05, 0x06, 0x07, 0x08, 0x09 }; 
-               bool exception;
-               
-               b = BitConverter.GetBytes (v1);
-               AssertEquals ("A1", 8, b.Length);
+                       b = BitConverter.GetBytes (v1);
+                       Assert.AreEqual (8, b.Length, "#A1");
 
-               v2 = BitConverter.ToInt64 (b, 0);
-               AssertEquals ("A2", v1, v2);    
+                       v2 = BitConverter.ToInt64 (b, 0);
+                       Assert.AreEqual (v1, v2, "#A2");
 
-               b.CopyTo (larger, 1);
-               v2 = BitConverter.ToInt64 (larger, 1);
-               AssertEquals ("A3", v1, v2);
+                       b.CopyTo (larger, 1);
+                       v2 = BitConverter.ToInt64 (larger, 1);
+                       Assert.AreEqual (v1, v2, "#A3");
 
-               try {
-                       v2 = BitConverter.ToInt64 (larger, 8);
-                       exception = false;
+                       try {
+                               BitConverter.ToInt64 (larger, 8);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // Destination array is not long enough to copy 
all the items
+                               // in the collection. Check array index and 
length
+                               Assert.AreEqual (typeof (ArgumentException), 
ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       try {
+                               BitConverter.ToInt64 (larger, 10);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // Index was out of range. Must be non-negative 
and less than
+                               // the size of the collection
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNotNull (ex.ParamName, "#C5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#C6");
+                       }
                }
-               catch (ArgumentException) {
-                       exception = true;
-               } 
-               Assert ("A4", exception);
 
-               try {
-                       v2 = BitConverter.ToInt64 ((byte[]) null, 77);
-                       exception = false;
+               [Test]
+               public void TestInt64 ()
+               {
+                       PrivateTestInt64 (0);
+                       PrivateTestInt64 (1000);
+                       PrivateTestInt64 (-9223372036854775808);
+                       PrivateTestInt64 (9223372036854775807);
                }
-               catch (ArgumentNullException) {
-                       exception = true;
+
+               [Test]
+               public void ToInt64_Value_Null ()
+               {
+                       try {
+                               BitConverter.ToInt64 ((byte []) null, 77);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof 
(ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+#if NET_2_0
+                               Assert.AreEqual ("value", ex.ParamName, "#6");
+#else
+                               Assert.AreEqual ("byteArray", ex.ParamName, 
"#6");
+#endif
+                       }
                }
-               Assert ("A5", exception);
-       }
 
-       public void TestInt64 ()
-       {
-               PrivateTestInt64 (0);
-               PrivateTestInt64 (1000);
-               PrivateTestInt64 (-9223372036854775808);
-               PrivateTestInt64 (9223372036854775807);
-       }
+               private void PrivateTestUInt64 (ulong v1)
+               {
+                       ulong v2;
+                       byte [] b;
+                       byte [] larger = new byte [] { 0x00, 0x01, 0x02, 0x03, 
0x04, 0x05, 0x06, 0x07, 0x08, 0x09 };
 
-       private void PrivateTestUInt64 (ulong v1)
-       {
-               ulong v2;
-               byte[] b;
-               byte[] larger = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 
0x05, 0x06, 0x07, 0x08, 0x09 }; 
-               bool exception;
-               
-               b = BitConverter.GetBytes (v1);
-               AssertEquals("A1", 8, b.Length);
+                       b = BitConverter.GetBytes (v1);
+                       Assert.AreEqual (8, b.Length, "#A1");
 
-               v2 = BitConverter.ToUInt64 (b, 0);
-               AssertEquals("A2", v1, v2);     
+                       v2 = BitConverter.ToUInt64 (b, 0);
+                       Assert.AreEqual (v1, v2, "#A2");
 
-               b.CopyTo (larger, 1);
-               v2 = BitConverter.ToUInt64 (larger, 1);
-               AssertEquals("A3", v1, v2);
+                       b.CopyTo (larger, 1);
+                       v2 = BitConverter.ToUInt64 (larger, 1);
+                       Assert.AreEqual (v1, v2, "#A3");
 
-               try {
-                       v2 = BitConverter.ToUInt64 (larger, 8);
-                       exception = false;
+                       try {
+                               BitConverter.ToUInt64 (larger, 8);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // Destination array is not long enough to copy 
all the items
+                               // in the collection. Check array index and 
length
+                               Assert.AreEqual (typeof (ArgumentException), 
ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       try {
+                               BitConverter.ToUInt64 (larger, 10);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // Index was out of range. Must be non-negative 
and less than
+                               // the size of the collection
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNotNull (ex.ParamName, "#C5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#C6");
+                       }
                }
-               catch (ArgumentException) {
-                       exception = true;
-               } 
-               Assert ("A4", exception);
 
-               try {
-                       v2 = BitConverter.ToUInt64 ((byte[]) null, 77);
-                       exception = false;
+               [Test]
+               public void TestUInt64 ()
+               {
+                       PrivateTestUInt64 (0);
+                       PrivateTestUInt64 (1000);
+                       PrivateTestUInt64 (18446744073709551615);
                }
-               catch (ArgumentNullException) {
-                       exception = true;
+
+               [Test]
+               public void ToUInt64_Value_Null ()
+               {
+                       try {
+                               BitConverter.ToUInt64 ((byte []) null, 77);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof 
(ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+#if NET_2_0
+                               Assert.AreEqual ("value", ex.ParamName, "#6");
+#else
+                               Assert.AreEqual ("byteArray", ex.ParamName, 
"#6");
+#endif
+                       }
                }
-               Assert ("A5", exception);
-       }
 
-       public void TestUInt64 ()
-       {
-               PrivateTestUInt64 (0);
-               PrivateTestUInt64 (1000);
-               PrivateTestUInt64 (18446744073709551615);
-       }
+               [Test]
+               public void TestToString ()
+               {
+                       byte [] b = new byte [] { 0x00, 0x11, 0x22, 0x33, 0x44, 
0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
 
-       public void TestToString ()
-       {
-               string s;
-               bool exception;
+                       Assert.AreEqual 
("00-11-22-33-44-55-66-77-88-99-AA-BB-CC-DD-EE-FF", BitConverter.ToString (b), 
"#A1");
+                       Assert.AreEqual ("66-77-88-99-AA-BB-CC-DD-EE-FF", 
BitConverter.ToString (b, 6), "#A2");
+                       Assert.AreEqual ("66-77-88", BitConverter.ToString (b, 
6, 3), "#A3");
+                       Assert.AreEqual (string.Empty, BitConverter.ToString 
(b, 6, 0), "#A4");
 
-               byte[] b = new byte[] {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 
0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
+                       try {
+                               BitConverter.ToString (b, 20);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // StartIndex cannot be less than zero
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNotNull (ex.ParamName, "#B5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#B6");
+                       }
 
-               AssertEquals ("A1", 
"00-11-22-33-44-55-66-77-88-99-AA-BB-CC-DD-EE-FF", BitConverter.ToString (b));
-               AssertEquals ("A2", "66-77-88-99-AA-BB-CC-DD-EE-FF", 
BitConverter.ToString (b, 6));
-               AssertEquals ("A3", "66-77-88", BitConverter.ToString (b, 6, 
3));
+                       try {
+                               BitConverter.ToString (b, 20, 3);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // StartIndex cannot be less than zero
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNotNull (ex.ParamName, "#C5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#C6");
+                       }
 
-               try {
-                       s = BitConverter.ToString ((byte[]) null);
-                       exception = false;
+                       try {
+                               BitConverter.ToString (b, 16, 0);
+                               Assert.Fail ("#D1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // StartIndex cannot be less than zero
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#D2");
+                               Assert.IsNull (ex.InnerException, "#D3");
+                               Assert.IsNotNull (ex.Message, "#D4");
+                               Assert.IsNotNull (ex.ParamName, "#D5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#D6");
+                       }
                }
-               catch (ArgumentNullException) {
-                       exception = true;
-               }
-               Assert ("A4", exception);
 
-               try {
-                       s = BitConverter.ToString (b, 20);
-                       exception = false;
-               }
-               catch (ArgumentException) {
-                       exception = true;
-               } 
-               Assert ("A5", exception);
+               [Test]
+               public void ToString_Value_Empty ()
+               {
+                       byte [] empty = new byte [0];
+#if NET_2_0
+                       Assert.AreEqual (String.Empty, BitConverter.ToString 
(empty), "#A1");
+#else
+                       try {
+                               BitConverter.ToString (empty);
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // StartIndex cannot be less than zero
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsNotNull (ex.ParamName, "#A5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#A6");
+                       }
+#endif
 
-               try {
-                       s = BitConverter.ToString ((byte[]) null, 20);
-                       exception = false;
+                       try {
+                               BitConverter.ToString (empty, 3);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // StartIndex cannot be less than zero
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNotNull (ex.ParamName, "#B5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#B6");
+                       }
+
+#if NET_2_0
+                       Assert.AreEqual (String.Empty, BitConverter.ToString 
(empty, 0), "#C1");
+#else
+                       try {
+                               BitConverter.ToString (empty, 0);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // StartIndex cannot be less than zero
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNotNull (ex.ParamName, "#C5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#C6");
+                       }
+#endif
+
+                       try {
+                               BitConverter.ToString (empty, 3, 0);
+                               Assert.Fail ("#D1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // StartIndex cannot be less than zero
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#D2");
+                               Assert.IsNull (ex.InnerException, "#D3");
+                               Assert.IsNotNull (ex.Message, "#D4");
+                               Assert.IsNotNull (ex.ParamName, "#D5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#D6");
+                       }
+
+#if NET_2_0
+                       Assert.AreEqual (string.Empty, BitConverter.ToString 
(empty, 0, 0), "#E1");
+#else
+                       try {
+                               BitConverter.ToString (empty, 0, 0);
+                               Assert.Fail ("#E1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // StartIndex cannot be less than zero
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#E2");
+                               Assert.IsNull (ex.InnerException, "#E3");
+                               Assert.IsNotNull (ex.Message, "#E4");
+                               Assert.IsNotNull (ex.ParamName, "#E5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#E6");
+                       }
+#endif
+
+                       try {
+                               BitConverter.ToString (empty, 3, -1);
+                               Assert.Fail ("#F1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // StartIndex cannot be less than zero
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#F2");
+                               Assert.IsNull (ex.InnerException, "#F3");
+                               Assert.IsNotNull (ex.Message, "#F4");
+                               Assert.IsNotNull (ex.ParamName, "#F5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#F6");
+                       }
                }
-               catch (ArgumentNullException) {
-                       exception = true;
-               }
-               Assert ("A6", exception);
 
-                try {
-                        s = BitConverter.ToString (b, 20, 3);
-                        exception = false;
-                }
-                catch (ArgumentOutOfRangeException) {
-                        exception = true;
-                }
-                Assert ("A7", exception);
+               [Test]
+               public void ToString_Value_Null ()
+               {
+                       try {
+                               BitConverter.ToString ((byte []) null);
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof 
(ArgumentNullException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsNotNull (ex.ParamName, "#A5");
+                               Assert.AreEqual ("value", ex.ParamName, "#A6");
+                       }
 
-                try {
-                       s = BitConverter.ToString ((byte[]) null, 20, 3);
-                        exception = false;
-                }
-                catch (ArgumentNullException) {
-                        exception = true;
-                }
-                Assert ("A8", exception);
+                       try {
+                               BitConverter.ToString ((byte []) null, 20);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof 
(ArgumentNullException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNotNull (ex.ParamName, "#B5");
+                               Assert.AreEqual ("value", ex.ParamName, "#B6");
+                       }
 
-                try {
-                        s = BitConverter.ToString (b, 16, 0);
-                        exception = false;
-                }
-                catch (ArgumentOutOfRangeException) {
-                        exception = true;
-                }
-                Assert ("A9", exception);
+                       try {
+                               BitConverter.ToString ((byte []) null, 20, 3);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof 
(ArgumentNullException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNotNull (ex.ParamName, "#C5");
+                               Assert.AreEqual ("byteArray", ex.ParamName, 
"#C6");
+                       }
+               }
 
+               [Test]
+               public void ToString_StartIndex_Negative ()
+               {
+                       try {
+                               BitConverter.ToString (new byte [0], -1);
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // StartIndex cannot be less than zero
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsNotNull (ex.ParamName, "#A5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#A6");
+                       }
 
-       }
+                       try {
+                               BitConverter.ToString (new byte [4], -1, 1);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // StartIndex cannot be less than zero
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNotNull (ex.ParamName, "#B5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#B6");
+                       }
+               }
 
-       [Test]
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]
-       public void ToString_StartIndexOverflow () 
-       {
-               byte[] array = new byte [4];
-               BitConverter.ToString (array, Int32.MaxValue, 1);
-       }
+               [Test]
+               public void ToString_StartIndex_Overflow ()
+               {
+                       byte [] array = new byte [4];
+                       try {
+                               BitConverter.ToString (array, Int32.MaxValue, 
1);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#6");
+                       }
+               }
 
-       [Test]
-       [ExpectedException (typeof (ArgumentException))]
-       public void ToString_LengthOverflow () 
-       {
-               byte[] array = new byte [4];
-               BitConverter.ToString (array, 1, Int32.MaxValue);
-       }
+               [Test]
+               public void ToString_Length_Negative ()
+               {
+                       byte [] array = new byte [4];
+                       try {
+                               BitConverter.ToString (array, 1, -1);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // Value must be positive
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+                               Assert.AreEqual ("length", ex.ParamName, "#6");
+                       }
+               }
 
-       [Test]
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]
-       public void ToUpperLimit () 
-       {
-               byte[] array = new byte [4];
-               BitConverter.ToInt32 (array, Int32.MaxValue);
-       }
+               [Test]
+               public void ToString_Length_Overflow ()
+               {
+                       byte [] array = new byte [4];
+                       try {
+                               BitConverter.ToString (array, 1, 
Int32.MaxValue);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               // Destination array is not long enough to copy 
all the items
+                               // in the collection. Check array index and 
length
+                               Assert.AreEqual (typeof (ArgumentException), 
ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNull (ex.ParamName, "#5");
+                       }
+               }
 
-       [Test]
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]
-       public void ToLowerLimit () 
-       {
-               byte[] array = new byte [4];
-               BitConverter.ToInt32 (array, Int32.MinValue);
-       }
+               [Test]
+               public void ToInt32_UpperLimit ()
+               {
+                       byte [] array = new byte [4];
+                       try {
+                               BitConverter.ToInt32 (array, Int32.MaxValue);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // Index was out of range. Must be non-negative 
and less than
+                               // the size of the collection
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#6");
+                       }
+               }
 
-       [Test]
-#if !NET_2_0
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]
-#endif
-       public void ToString_Empty ()
-       {
-               byte[] empty = new byte [0];
-               AssertEquals ("Empty", String.Empty, BitConverter.ToString 
(empty));
-       }
+               [Test]
+               public void ToInt32_LowerLimit ()
+               {
+                       byte [] array = new byte [4];
+                       try {
+                               BitConverter.ToInt32 (array, Int32.MinValue);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               // Index was out of range. Must be non-negative 
and less than
+                               // the size of the collection
+                               Assert.AreEqual (typeof 
(ArgumentOutOfRangeException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+                               Assert.AreEqual ("startIndex", ex.ParamName, 
"#6");
+                       }
+               }
 
-       [Test]
-       public void ToBoolean () 
-       {
-               byte[] array = new byte [2] { 0x02, 0x00 };
-               Assert ("True", BitConverter.ToBoolean (array, 0));
-               AssertEquals ("True==True", true, BitConverter.ToBoolean 
(array, 0));
-               Assert ("False", !BitConverter.ToBoolean (array, 1));
+               [Test]
+               public void ToBoolean ()
+               {
+                       byte [] array = new byte [2] { 0x02, 0x00 };
+                       Assert.IsTrue (BitConverter.ToBoolean (array, 0), "#1");
+                       Assert.IsFalse (BitConverter.ToBoolean (array, 1), 
"#2");
+               }
        }
 }
-}

Modified: trunk/mcs/class/corlib/Test/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System/ChangeLog        2007-07-21 08:28:19 UTC 
(rev 82409)
+++ trunk/mcs/class/corlib/Test/System/ChangeLog        2007-07-21 09:03:40 UTC 
(rev 82410)
@@ -1,3 +1,13 @@
+2007-07-21  Gert Driesen  <[EMAIL PROTECTED]>
+
+       * BitConverterTest.cs: Remove use of deprecated Assertion class. 
+       Improved existing tests to verify throws exception. Create separate
+       tests for null argument checking. Added tests for empty byte array.
+
+2007-07-20  Gert Driesen  <[EMAIL PROTECTED]>
+
+       * RuntimeMethodHandleTest.cs: Added operator and Equals tests.
+
 2007-07-20  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * AppDomainSetupTest.cs : added test for AppDomainInitializer.

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

Reply via email to