X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FTest%2FSystem%2FConvertTest.cs;h=7ba22472e9db4e3ff7868e1bfc03a4bebbfa1164;hb=2d23bfcbce7a3f7e54dcd5911adb88b244baca35;hp=c3e7e0ca0bdb1ebb62ca827a3a660f6b7659ab6f;hpb=a3ea7ceb4d4f5e2cb8ea421313e8939640fb898c;p=mono.git diff --git a/mcs/class/corlib/Test/System/ConvertTest.cs b/mcs/class/corlib/Test/System/ConvertTest.cs index c3e7e0ca0bd..7ba22472e9d 100644 --- a/mcs/class/corlib/Test/System/ConvertTest.cs +++ b/mcs/class/corlib/Test/System/ConvertTest.cs @@ -13,7 +13,7 @@ using System.Globalization; namespace MonoTests.System { [TestFixture] - public class ConvertTest : Assertion { + public class ConvertTest { bool boolTrue; bool boolFalse; @@ -67,137 +67,137 @@ namespace MonoTests.System { public void TestChangeType() { int iTest = 1; try { - AssertEquals("#A01", (short)12345, Convert.ChangeType(tryInt32, typeof(short))); + Assert.AreEqual ((short)12345, Convert.ChangeType(tryInt32, typeof(short)), "#A01"); iTest++; - AssertEquals("#A02", 'A', Convert.ChangeType(65, typeof(char))); + Assert.AreEqual ('A', Convert.ChangeType(65, typeof(char)), "#A02"); iTest++; - AssertEquals("#A03", 66, Convert.ChangeType('B', typeof(int))); + Assert.AreEqual (66, Convert.ChangeType('B', typeof(int)), "#A03"); iTest++; - AssertEquals("#A04", ((ulong)12345), Convert.ChangeType(tryInt32, typeof(ulong))); + Assert.AreEqual (((ulong)12345), Convert.ChangeType(tryInt32, typeof(ulong)), "#A04"); iTest++; - AssertEquals("#A05", true, Convert.ChangeType(tryDec, TypeCode.Boolean)); + Assert.AreEqual (true, Convert.ChangeType(tryDec, TypeCode.Boolean), "#A05"); iTest++; - AssertEquals("#A06", 'f', Convert.ChangeType("f", TypeCode.Char)); + Assert.AreEqual ('f', Convert.ChangeType("f", TypeCode.Char), "#A06"); iTest++; - AssertEquals("#A07", (decimal)123456789012, Convert.ChangeType(tryInt64, TypeCode.Decimal)); + Assert.AreEqual ((decimal)123456789012, Convert.ChangeType(tryInt64, TypeCode.Decimal), "#A07"); iTest++; - AssertEquals("#A08", (int)34567, Convert.ChangeType(tryUI16, TypeCode.Int32)); + Assert.AreEqual ((int)34567, Convert.ChangeType(tryUI16, TypeCode.Int32), "#A08"); iTest++; - AssertEquals("#A09", (double)567891234, Convert.ChangeType(tryUI32, typeof(double), ci)); + Assert.AreEqual ((double)567891234, Convert.ChangeType(tryUI32, typeof(double), ci), "#A09"); iTest++; - AssertEquals("#A10", (ushort)0, Convert.ChangeType(tryByte, typeof(ushort), ci)); + Assert.AreEqual ((ushort)0, Convert.ChangeType(tryByte, typeof(ushort), ci), "#A10"); iTest++; - AssertEquals("#A11", (decimal)567891234, Convert.ChangeType(tryUI32, typeof(decimal), ci)); + Assert.AreEqual ((decimal)567891234, Convert.ChangeType(tryUI32, typeof(decimal), ci), "#A11"); iTest++; - AssertEquals("#A12", (float)1234, Convert.ChangeType(tryInt16, typeof(float), ci)); + Assert.AreEqual ((float)1234, Convert.ChangeType(tryInt16, typeof(float), ci), "#A12"); iTest++; - AssertEquals("#A13", null, Convert.ChangeType(null, null, ci)); + Assert.AreEqual (null, Convert.ChangeType(null, null, ci), "#A13"); iTest++; - AssertEquals("#A14", (decimal)0, Convert.ChangeType(tryByte, TypeCode.Decimal, ci)); + Assert.AreEqual ((decimal)0, Convert.ChangeType(tryByte, TypeCode.Decimal, ci), "#A14"); iTest++; - AssertEquals("#A15", "f", Convert.ChangeType('f', TypeCode.String, ci)); + Assert.AreEqual ("f", Convert.ChangeType('f', TypeCode.String, ci), "#A15"); iTest++; - AssertEquals("#A16", 'D', Convert.ChangeType(68, TypeCode.Char, ci)); + Assert.AreEqual ('D', Convert.ChangeType(68, TypeCode.Char, ci), "#A16"); iTest++; - AssertEquals("#A17", (long)34567, Convert.ChangeType(tryUI16, TypeCode.Int64, ci)); + Assert.AreEqual ((long)34567, Convert.ChangeType(tryUI16, TypeCode.Int64, ci), "#A17"); iTest++; - AssertEquals("#A18", null, Convert.ChangeType(null, TypeCode.Empty, ci)); + Assert.AreEqual (null, Convert.ChangeType(null, TypeCode.Empty, ci), "#A18"); } catch (Exception e) { - Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e); + Assert.Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e); } try { Convert.ChangeType(boolTrue, typeof(char)); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#A25", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#A25"); } try { Convert.ChangeType(tryChar, typeof(DateTime)); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#A26", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#A26"); } try { Convert.ChangeType(ci, TypeCode.String); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#A27", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#A27"); } try { Convert.ChangeType(tryInt32, null); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#A28", typeof(ArgumentNullException), e.GetType()); + Assert.AreEqual (typeof(ArgumentNullException), e.GetType(), "#A28"); } try { Convert.ChangeType(boolTrue, typeof(DateTime), ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#A29", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#A29"); } try { Convert.ChangeType(ci, typeof(DateTime), ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#A30", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#A30"); } /* Should throw ArgumentException but throws InvalidCastException try { Convert.ChangeType(tryUI32, typeof(FormatException), ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#A??", typeof(ArgumentException), e.GetType()); + Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#A??"); }*/ try { Convert.ChangeType(tryUI32, TypeCode.Byte, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#A31", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#A31"); } try { Convert.ChangeType(boolTrue, TypeCode.Char, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#A32", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#A32"); } try { Convert.ChangeType(boolTrue, null, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#A33", typeof(ArgumentNullException), e.GetType()); + Assert.AreEqual (typeof(ArgumentNullException), e.GetType(), "#A33"); } try { /* should fail to convert string to any enumeration type. */ Convert.ChangeType("random string", typeof(DayOfWeek)); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#A34", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#A34"); } } @@ -205,422 +205,422 @@ namespace MonoTests.System { public void TestGetTypeCode() { int marker = 1; try { - AssertEquals("#B01", TypeCode.String, Convert.GetTypeCode(tryStr)); + Assert.AreEqual (TypeCode.String, Convert.GetTypeCode(tryStr), "#B01"); marker++; - AssertEquals("#B02", TypeCode.UInt16, Convert.GetTypeCode(tryUI16)); + Assert.AreEqual (TypeCode.UInt16, Convert.GetTypeCode(tryUI16), "#B02"); marker++; - AssertEquals("#B03", TypeCode.UInt32, Convert.GetTypeCode(tryUI32)); + Assert.AreEqual (TypeCode.UInt32, Convert.GetTypeCode(tryUI32), "#B03"); marker++; - AssertEquals("#B04", TypeCode.UInt64, Convert.GetTypeCode(tryUI64)); + Assert.AreEqual (TypeCode.UInt64, Convert.GetTypeCode(tryUI64), "#B04"); marker++; - AssertEquals("#B05", TypeCode.Double, Convert.GetTypeCode(tryDbl)); + Assert.AreEqual (TypeCode.Double, Convert.GetTypeCode(tryDbl), "#B05"); marker++; - AssertEquals("#B06", TypeCode.Int16, Convert.GetTypeCode(tryInt16)); + Assert.AreEqual (TypeCode.Int16, Convert.GetTypeCode(tryInt16), "#B06"); marker++; - AssertEquals("#B07", TypeCode.Int64, Convert.GetTypeCode(tryInt64)); + Assert.AreEqual (TypeCode.Int64, Convert.GetTypeCode(tryInt64), "#B07"); marker++; - AssertEquals("#B08", TypeCode.Object, Convert.GetTypeCode(tryObj)); + Assert.AreEqual (TypeCode.Object, Convert.GetTypeCode(tryObj), "#B08"); marker++; - AssertEquals("#B09", TypeCode.SByte, Convert.GetTypeCode(trySByte)); + Assert.AreEqual (TypeCode.SByte, Convert.GetTypeCode(trySByte), "#B09"); marker++; - AssertEquals("#B10", TypeCode.Single, Convert.GetTypeCode(tryFloat)); + Assert.AreEqual (TypeCode.Single, Convert.GetTypeCode(tryFloat), "#B10"); marker++; - AssertEquals("#B11", TypeCode.Byte, Convert.GetTypeCode(tryByte)); + Assert.AreEqual (TypeCode.Byte, Convert.GetTypeCode(tryByte), "#B11"); marker++; - AssertEquals("#B12", TypeCode.Char, Convert.GetTypeCode(tryChar)); + Assert.AreEqual (TypeCode.Char, Convert.GetTypeCode(tryChar), "#B12"); marker++; -// AssertEquals("#B13", TypeCode.DateTime, Convert.GetTypeCode(tryDT)); +// Assert.AreEqual (TypeCode.DateTime, Convert.GetTypeCode(tryDT), "#B13"); marker++; - AssertEquals("#B14", TypeCode.Decimal, Convert.GetTypeCode(tryDec)); + Assert.AreEqual (TypeCode.Decimal, Convert.GetTypeCode(tryDec), "#B14"); marker++; - AssertEquals("#B15", TypeCode.Int32, Convert.GetTypeCode(tryInt32)); + Assert.AreEqual (TypeCode.Int32, Convert.GetTypeCode(tryInt32), "#B15"); marker++; - AssertEquals("#B16", TypeCode.Boolean, Convert.GetTypeCode(boolTrue)); + Assert.AreEqual (TypeCode.Boolean, Convert.GetTypeCode(boolTrue), "#B16"); } catch (Exception e) { - Fail ("Unexpected exception at " + marker + ": " + e); + Assert.Fail ("Unexpected exception at " + marker + ": " + e); } } public void TestIsDBNull() { - AssertEquals("#C01", false, Convert.IsDBNull(tryInt32)); - AssertEquals("#C02", true, Convert.IsDBNull(Convert.DBNull)); - AssertEquals("#C03", false, Convert.IsDBNull(boolTrue)); - AssertEquals("#C04", false, Convert.IsDBNull(tryChar)); - AssertEquals("#C05", false, Convert.IsDBNull(tryFloat)); + Assert.AreEqual (false, Convert.IsDBNull(tryInt32), "#C01"); + Assert.AreEqual (true, Convert.IsDBNull(Convert.DBNull), "#C02"); + Assert.AreEqual (false, Convert.IsDBNull(boolTrue), "#C03"); + Assert.AreEqual (false, Convert.IsDBNull(tryChar), "#C04"); + Assert.AreEqual (false, Convert.IsDBNull(tryFloat), "#C05"); } public void TestToBoolean() { tryObj = (object)tryDbl; - AssertEquals("#D01", true, Convert.ToBoolean(boolTrue)); - AssertEquals("#D02", false, Convert.ToBoolean(tryByte)); - AssertEquals("#D03", true, Convert.ToBoolean(tryDec)); - AssertEquals("#D04", false, Convert.ToBoolean(tryDbl)); - AssertEquals("#D05", true, Convert.ToBoolean(tryInt16)); - AssertEquals("#D06", true, Convert.ToBoolean(tryInt32)); - AssertEquals("#D07", true, Convert.ToBoolean(tryInt64)); - AssertEquals("#D08", false, Convert.ToBoolean(tryObj)); - AssertEquals("#D09", true, Convert.ToBoolean(trySByte)); - AssertEquals("#D10", true, Convert.ToBoolean(tryFloat)); - AssertEquals("#D11", true, Convert.ToBoolean(trueString)); - AssertEquals("#D12", false, Convert.ToBoolean(falseString)); - AssertEquals("#D13", true, Convert.ToBoolean(tryUI16)); - AssertEquals("#D14", true, Convert.ToBoolean(tryUI32)); - AssertEquals("#D15", false, Convert.ToBoolean(tryUI64)); - AssertEquals("#D16", false, Convert.ToBoolean(tryObj,ci)); - AssertEquals("#D17", true, Convert.ToBoolean(trueString, ci)); - AssertEquals("#D18", false, Convert.ToBoolean(falseString, ci)); + Assert.AreEqual (true, Convert.ToBoolean(boolTrue), "#D01"); + Assert.AreEqual (false, Convert.ToBoolean(tryByte), "#D02"); + Assert.AreEqual (true, Convert.ToBoolean(tryDec), "#D03"); + Assert.AreEqual (false, Convert.ToBoolean(tryDbl), "#D04"); + Assert.AreEqual (true, Convert.ToBoolean(tryInt16), "#D05"); + Assert.AreEqual (true, Convert.ToBoolean(tryInt32), "#D06"); + Assert.AreEqual (true, Convert.ToBoolean(tryInt64), "#D07"); + Assert.AreEqual (false, Convert.ToBoolean(tryObj), "#D08"); + Assert.AreEqual (true, Convert.ToBoolean(trySByte), "#D09"); + Assert.AreEqual (true, Convert.ToBoolean(tryFloat), "#D10"); + Assert.AreEqual (true, Convert.ToBoolean(trueString), "#D11"); + Assert.AreEqual (false, Convert.ToBoolean(falseString), "#D12"); + Assert.AreEqual (true, Convert.ToBoolean(tryUI16), "#D13"); + Assert.AreEqual (true, Convert.ToBoolean(tryUI32), "#D14"); + Assert.AreEqual (false, Convert.ToBoolean(tryUI64), "#D15"); + Assert.AreEqual (false, Convert.ToBoolean(tryObj, ci), "#D16"); + Assert.AreEqual (true, Convert.ToBoolean(trueString, ci), "#D17"); + Assert.AreEqual (false, Convert.ToBoolean(falseString, ci), "#D18"); try { Convert.ToBoolean(tryChar); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#D20", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#D20"); } try { Convert.ToBoolean(tryDT); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#D21", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#D21"); } try { Convert.ToBoolean(tryStr); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#D22", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#D22"); } try { Convert.ToBoolean(nullString); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#D23", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#D23"); } } public void TestToByte() { - AssertEquals("#E01", (byte)1, Convert.ToByte(boolTrue)); - AssertEquals("#E02", (byte)0, Convert.ToByte(boolFalse)); - AssertEquals("#E03", tryByte, Convert.ToByte(tryByte)); - AssertEquals("#E04", (byte)114, Convert.ToByte('r')); - AssertEquals("#E05", (byte)201, Convert.ToByte((decimal)200.6)); - AssertEquals("#E06", (byte)125, Convert.ToByte((double)125.4)); - AssertEquals("#E07", (byte)255, Convert.ToByte((short)255)); - AssertEquals("#E08", (byte)254, Convert.ToByte((int)254)); - AssertEquals("#E09", (byte)34, Convert.ToByte((long)34)); - AssertEquals("#E10", (byte)1, Convert.ToByte((object)boolTrue)); - AssertEquals("#E11", (byte)123, Convert.ToByte((float)123.49f)); - AssertEquals("#E12", (byte)57, Convert.ToByte("57")); - AssertEquals("#E13", (byte)75, Convert.ToByte((ushort)75)); - AssertEquals("#E14", (byte)184, Convert.ToByte((uint)184)); - AssertEquals("#E15", (byte)241, Convert.ToByte((ulong)241)); - AssertEquals("#E16", (byte)123, Convert.ToByte(trySByte, ci)); - AssertEquals("#E17", (byte)27, Convert.ToByte("011011", 2)); - AssertEquals("#E18", (byte)13, Convert.ToByte("15", 8)); - AssertEquals("#E19", (byte)27, Convert.ToByte("27", 10)); - AssertEquals("#E20", (byte)250, Convert.ToByte("FA", 16)); + Assert.AreEqual ((byte)1, Convert.ToByte(boolTrue), "#E01"); + Assert.AreEqual ((byte)0, Convert.ToByte(boolFalse), "#E02"); + Assert.AreEqual (tryByte, Convert.ToByte(tryByte), "#E03"); + Assert.AreEqual ((byte)114, Convert.ToByte('r'), "#E04"); + Assert.AreEqual ((byte)201, Convert.ToByte((decimal)200.6), "#E05"); + Assert.AreEqual ((byte)125, Convert.ToByte((double)125.4), "#E06"); + Assert.AreEqual ((byte)255, Convert.ToByte((short)255), "#E07"); + Assert.AreEqual ((byte)254, Convert.ToByte((int)254), "#E08"); + Assert.AreEqual ((byte)34, Convert.ToByte((long)34), "#E09"); + Assert.AreEqual ((byte)1, Convert.ToByte((object)boolTrue), "#E10"); + Assert.AreEqual ((byte)123, Convert.ToByte((float)123.49f), "#E11"); + Assert.AreEqual ((byte)57, Convert.ToByte("57"), "#E12"); + Assert.AreEqual ((byte)75, Convert.ToByte((ushort)75), "#E13"); + Assert.AreEqual ((byte)184, Convert.ToByte((uint)184), "#E14"); + Assert.AreEqual ((byte)241, Convert.ToByte((ulong)241), "#E15"); + Assert.AreEqual ((byte)123, Convert.ToByte(trySByte, ci), "#E16"); + Assert.AreEqual ((byte)27, Convert.ToByte("011011", 2), "#E17"); + Assert.AreEqual ((byte)13, Convert.ToByte("15", 8), "#E18"); + Assert.AreEqual ((byte)27, Convert.ToByte("27", 10), "#E19"); + Assert.AreEqual ((byte)250, Convert.ToByte("FA", 16), "#E20"); try { Convert.ToByte('\u03A9'); // sign of Omega on Win2k - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#E25", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E25"); } try { Convert.ToByte(tryDT); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#D26", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#D26"); } try { Convert.ToByte((decimal)22000); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#E27", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E27"); } try { Convert.ToByte((double)255.5); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#E28", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E28"); } try { Convert.ToByte(-tryInt16); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#E29", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E29"); } try { Convert.ToByte((int)-256); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#E30", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E30"); } try { Convert.ToByte(tryInt64); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#E31", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E31"); } try { Convert.ToByte((object)ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#E32", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#E32"); } try { Convert.ToByte((sbyte)-1); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#E33", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E33"); } try { Convert.ToByte((float)-0.6f); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#E34", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E34"); } try { Convert.ToByte("1a1"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#E35", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#E35"); } try { Convert.ToByte("457"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#E36", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E36"); } try { Convert.ToByte((ushort)30000); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#E37", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E37"); } try { Convert.ToByte((uint)300); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#E38", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E38"); } try { Convert.ToByte((ulong)987654321321); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#E39", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E39"); } try { Convert.ToByte("10010111", 3); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#E40", typeof(ArgumentException), e.GetType()); + Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#E40"); } try { Convert.ToByte("3F3", 16); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#E41", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E41"); } } public void TestToChar(){ tryByte = 58; - AssertEquals("#F01", ':', Convert.ToChar(tryByte)); - AssertEquals("#F02", 'a', Convert.ToChar(tryChar)); - AssertEquals("#F03", 'A', Convert.ToChar((short)65)); - AssertEquals("#F04", 'x', Convert.ToChar((int)120)); - AssertEquals("#F05", '"', Convert.ToChar((long)34)); - AssertEquals("#F06", '-', Convert.ToChar((sbyte)45)); - AssertEquals("#F07", '@', Convert.ToChar("@")); - AssertEquals("#F08", 'K', Convert.ToChar((ushort)75)); - AssertEquals("#F09", '=', Convert.ToChar((uint)61)); - // AssertEquals("#F10", 'E', Convert.ToChar((ulong)200)); - AssertEquals("#F11", '{', Convert.ToChar((object)trySByte, ci)); - AssertEquals("#F12", 'o', Convert.ToChar(tryStr.Substring(1,1), ci)); + Assert.AreEqual (':', Convert.ToChar(tryByte), "#F01"); + Assert.AreEqual ('a', Convert.ToChar(tryChar), "#F02"); + Assert.AreEqual ('A', Convert.ToChar((short)65), "#F03"); + Assert.AreEqual ('x', Convert.ToChar((int)120), "#F04"); + Assert.AreEqual ('"', Convert.ToChar((long)34), "#F05"); + Assert.AreEqual ('-', Convert.ToChar((sbyte)45), "#F06"); + Assert.AreEqual ('@', Convert.ToChar("@"), "#F07"); + Assert.AreEqual ('K', Convert.ToChar((ushort)75), "#F08"); + Assert.AreEqual ('=', Convert.ToChar((uint)61), "#F09"); + // Assert.AreEqual ('E', Convert.ToChar((ulong)200), "#F10"); + Assert.AreEqual ('{', Convert.ToChar((object)trySByte, ci), "#F11"); + Assert.AreEqual ('o', Convert.ToChar(tryStr.Substring(1, 1), ci), "#F12"); try { Convert.ToChar(boolTrue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F20", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#F20"); } try { Convert.ToChar(tryDT); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F21", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#F21"); } try { Convert.ToChar(tryDec); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F22", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#F22"); } try { Convert.ToChar(tryDbl); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F23", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#F23"); } try { Convert.ToChar((short)-1); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F24", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#F24"); } try { Convert.ToChar(Int32.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F25", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#F25"); } try { Convert.ToChar(Int32.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F26", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#F26"); } try { Convert.ToChar(tryInt64); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F27", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#F27"); } try { Convert.ToChar((long)-123); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F28", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#F28"); } try { Convert.ToChar(ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F29", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#F29"); } try { Convert.ToChar(-trySByte); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F30", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#F30"); } try { Convert.ToChar(tryFloat); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F31", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#F31"); } try { Convert.ToChar("foo"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F32", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#F32"); } try { Convert.ToChar(null); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F33", typeof(ArgumentNullException), e.GetType()); + Assert.AreEqual (typeof(ArgumentNullException), e.GetType(), "#F33"); } try { Convert.ToChar(new Exception(), ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F34", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#F34"); } try { Convert.ToChar(null, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F35", typeof(ArgumentNullException), e.GetType()); + Assert.AreEqual (typeof(ArgumentNullException), e.GetType(), "#F35"); } try { Convert.ToChar("", ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F36", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#F36"); } try { Convert.ToChar(tryStr, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#F37", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#F37"); } } @@ -635,825 +635,829 @@ namespace MonoTests.System { string dateString = "01/01/2002"; int iTest = 1; try { - AssertEquals("#G01", tryDT, Convert.ToDateTime(tryDT)); + Assert.AreEqual (tryDT, Convert.ToDateTime(tryDT), "#G01"); iTest++; - AssertEquals("#G02", tryDT, Convert.ToDateTime(dateString)); + Assert.AreEqual (tryDT, Convert.ToDateTime(dateString), "#G02"); iTest++; - AssertEquals("#G03", tryDT, Convert.ToDateTime(dateString, ci)); + Assert.AreEqual (tryDT, Convert.ToDateTime(dateString, ci), "#G03"); } catch (Exception e) { - Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e); + Assert.Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e); } try { Convert.ToDateTime(boolTrue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G10", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G10"); } try { Convert.ToDateTime(tryByte); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G11", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G11"); } try { Convert.ToDateTime(tryChar); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G12", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G12"); } try { Convert.ToDateTime(tryDec); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G13", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G13"); } try { Convert.ToDateTime(tryDbl); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G14", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G14"); } try { Convert.ToDateTime(tryInt16); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G15", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G15"); } try { Convert.ToDateTime(tryInt32); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G16", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G16"); } try { Convert.ToDateTime(tryInt64); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G17", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G17"); } try { Convert.ToDateTime(ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G18", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G18"); } try { Convert.ToDateTime(trySByte); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G19", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G19"); } try { Convert.ToDateTime(tryFloat); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G20", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G20"); } try { Convert.ToDateTime("20a2-01-01"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G21", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#G21"); } try { Convert.ToDateTime(tryUI16); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G23", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G23"); } try { Convert.ToDateTime(tryUI32); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G24", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G24"); } try { Convert.ToDateTime(tryUI64); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G25", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G25"); } try { Convert.ToDateTime(ci, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G26", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G26"); } try { Convert.ToDateTime("20a2-01-01", ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G27", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#G27"); } // this is supported by .net 1.1 (defect 41845) try { Convert.ToDateTime("20022-01-01"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G28", typeof(ArgumentOutOfRangeException), e.GetType()); +#if NET_2_0 + Assert.AreEqual (typeof(FormatException), e.GetType(), "#G28"); +#else + Assert.AreEqual (typeof(ArgumentOutOfRangeException), e.GetType(), "#G28"); +#endif } try { Convert.ToDateTime("2002-21-01"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G29", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#G29"); } try { Convert.ToDateTime("2002-111-01"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G30", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#G30"); } try { Convert.ToDateTime("2002-01-41"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G31", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#G31"); } try { Convert.ToDateTime("2002-01-111"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G32", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#G32"); } try { - AssertEquals("#G33", tryDT, Convert.ToDateTime("2002-01-01")); + Assert.AreEqual (tryDT, Convert.ToDateTime("2002-01-01"), "#G33"); } catch (Exception e) { - Fail ("Unexpected exception at #G33 " + e); + Assert.Fail ("Unexpected exception at #G33 " + e); } try { Convert.ToDateTime("2002-01-11 34:11:11"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G34", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#G34"); } try { Convert.ToDateTime("2002-01-11 11:70:11"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G35", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#G35"); } try { Convert.ToDateTime("2002-01-11 11:11:70"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#G36", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#G36"); } } public void TestToDecimal() { - AssertEquals("#H01", (decimal)1, Convert.ToDecimal(boolTrue)); - AssertEquals("#H02", (decimal)0, Convert.ToDecimal(boolFalse)); - AssertEquals("#H03", (decimal)tryByte, Convert.ToDecimal(tryByte)); - AssertEquals("#H04", tryDec, Convert.ToDecimal(tryDec)); - AssertEquals("#H05", (decimal)tryDbl, Convert.ToDecimal(tryDbl)); - AssertEquals("#H06", (decimal)tryInt16, Convert.ToDecimal(tryInt16)); - AssertEquals("#H07", (decimal)tryInt32, Convert.ToDecimal(tryInt32)); - AssertEquals("#H08", (decimal)tryInt64, Convert.ToDecimal(tryInt64)); - AssertEquals("#H09", (decimal)trySByte, Convert.ToDecimal(trySByte)); - AssertEquals("#H10", (decimal)tryFloat, Convert.ToDecimal(tryFloat)); + Assert.AreEqual ((decimal)1, Convert.ToDecimal(boolTrue), "#H01"); + Assert.AreEqual ((decimal)0, Convert.ToDecimal(boolFalse), "#H02"); + Assert.AreEqual ((decimal)tryByte, Convert.ToDecimal(tryByte), "#H03"); + Assert.AreEqual (tryDec, Convert.ToDecimal(tryDec), "#H04"); + Assert.AreEqual ((decimal)tryDbl, Convert.ToDecimal(tryDbl), "#H05"); + Assert.AreEqual ((decimal)tryInt16, Convert.ToDecimal(tryInt16), "#H06"); + Assert.AreEqual ((decimal)tryInt32, Convert.ToDecimal(tryInt32), "#H07"); + Assert.AreEqual ((decimal)tryInt64, Convert.ToDecimal(tryInt64), "#H08"); + Assert.AreEqual ((decimal)trySByte, Convert.ToDecimal(trySByte), "#H09"); + Assert.AreEqual ((decimal)tryFloat, Convert.ToDecimal(tryFloat), "#H10"); string sep = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator; -// AssertEquals("#H11", (decimal)23456.432, Convert.ToDecimal("23456" + sep + "432")); +// Assert.AreEqual ((decimal)23456.432, Convert.ToDecimal("23456" + sep + "432"), "#H11"); // Note: changed because the number were the same but with a different base // and this isn't a Convert bug (but a Decimal bug). See #60227 for more details. // http://bugzilla.ximian.com/show_bug.cgi?id=60227 - Assert ("#H11", Decimal.Equals (23456.432m, Convert.ToDecimal ("23456" + sep + "432"))); - AssertEquals("#H12", (decimal)tryUI16, Convert.ToDecimal(tryUI16)); - AssertEquals("#H13", (decimal)tryUI32, Convert.ToDecimal(tryUI32)); - AssertEquals("#H14", (decimal)tryUI64, Convert.ToDecimal(tryUI64)); - AssertEquals("#H15", (decimal)63784, Convert.ToDecimal("63784", ci)); + Assert.IsTrue (Decimal.Equals (23456.432m, Convert.ToDecimal ("23456" + sep + "432")), "#H11"); + Assert.AreEqual ((decimal)tryUI16, Convert.ToDecimal(tryUI16), "#H12"); + Assert.AreEqual ((decimal)tryUI32, Convert.ToDecimal(tryUI32), "#H13"); + Assert.AreEqual ((decimal)tryUI64, Convert.ToDecimal(tryUI64), "#H14"); + Assert.AreEqual ((decimal)63784, Convert.ToDecimal("63784", ci), "#H15"); try { Convert.ToDecimal(tryChar); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#H20", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#H20"); } try { Convert.ToDecimal(tryDT); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#H21", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#H21"); } try { Convert.ToDecimal(double.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#H22", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#H22"); } try { Convert.ToDecimal(double.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#H23", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#H23"); } try { Convert.ToDecimal(ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#H24", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#H24"); } try { Convert.ToDecimal(tryStr); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#H25", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#H25"); } try { string maxDec = decimal.MaxValue.ToString(); maxDec = maxDec + "1"; Convert.ToDecimal(maxDec); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#H26", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#H26"); } try { Convert.ToDecimal(ci, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#H27", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#H27"); } try { Convert.ToDecimal(tryStr, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#H28", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#H28"); } try { string maxDec = decimal.MaxValue.ToString(); maxDec = maxDec + "1"; Convert.ToDecimal(maxDec, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#H29", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#H29"); } } public void TestToDouble() { int iTest = 1; try { - AssertEquals("#I01", (double)1, Convert.ToDouble(boolTrue)); + Assert.AreEqual ((double)1, Convert.ToDouble(boolTrue), "#I01"); iTest++; - AssertEquals("#I02", (double)0, Convert.ToDouble(boolFalse)); + Assert.AreEqual ((double)0, Convert.ToDouble(boolFalse), "#I02"); iTest++; - AssertEquals("#I03", (double)tryByte, Convert.ToDouble(tryByte)); + Assert.AreEqual ((double)tryByte, Convert.ToDouble(tryByte), "#I03"); iTest++; - AssertEquals("#I04", tryDbl, Convert.ToDouble(tryDbl)); + Assert.AreEqual (tryDbl, Convert.ToDouble(tryDbl), "#I04"); iTest++; - AssertEquals("#I05", (double)tryDec, Convert.ToDouble(tryDec)); + Assert.AreEqual ((double)tryDec, Convert.ToDouble(tryDec), "#I05"); iTest++; - AssertEquals("#I06", (double)tryInt16, Convert.ToDouble(tryInt16)); + Assert.AreEqual ((double)tryInt16, Convert.ToDouble(tryInt16), "#I06"); iTest++; - AssertEquals("#I07", (double)tryInt32, Convert.ToDouble(tryInt32)); + Assert.AreEqual ((double)tryInt32, Convert.ToDouble(tryInt32), "#I07"); iTest++; - AssertEquals("#I08", (double)tryInt64, Convert.ToDouble(tryInt64)); + Assert.AreEqual ((double)tryInt64, Convert.ToDouble(tryInt64), "#I08"); iTest++; - AssertEquals("#I09", (double)trySByte, Convert.ToDouble(trySByte)); + Assert.AreEqual ((double)trySByte, Convert.ToDouble(trySByte), "#I09"); iTest++; - AssertEquals("#I10", (double)tryFloat, Convert.ToDouble(tryFloat)); + Assert.AreEqual ((double)tryFloat, Convert.ToDouble(tryFloat), "#I10"); iTest++; string sep = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator; - AssertEquals("#I11", (double)23456.432, Convert.ToDouble("23456" + sep + "432")); + Assert.AreEqual ((double)23456.432, Convert.ToDouble("23456" + sep + "432"), "#I11"); iTest++; - AssertEquals("#I12", (double)tryUI16, Convert.ToDouble(tryUI16)); + Assert.AreEqual ((double)tryUI16, Convert.ToDouble(tryUI16), "#I12"); iTest++; - AssertEquals("#I13", (double)tryUI32, Convert.ToDouble(tryUI32)); + Assert.AreEqual ((double)tryUI32, Convert.ToDouble(tryUI32), "#I13"); iTest++; - AssertEquals("#I14", (double)tryUI64, Convert.ToDouble(tryUI64)); + Assert.AreEqual ((double)tryUI64, Convert.ToDouble(tryUI64), "#I14"); iTest++; - AssertEquals("#H15", (double)63784, Convert.ToDouble("63784", ci)); + Assert.AreEqual ((double)63784, Convert.ToDouble("63784", ci), "#H15"); } catch (Exception e) { - Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e); + Assert.Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e); } try { Convert.ToDouble(tryChar); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#I20", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#I20"); } try { Convert.ToDouble(tryDT); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#I21", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#I21"); } try { Convert.ToDouble(ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#I22", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#I22"); } try { Convert.ToDouble(tryStr); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#I23", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#I23"); } try { string maxDec = double.MaxValue.ToString(); maxDec = maxDec + "1"; Convert.ToDouble(maxDec); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#I24", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#I24"); } try { Convert.ToDouble(ci, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#I25", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#I25"); } try { Convert.ToDouble(tryStr, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#I26", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#I26"); } try { string maxDec = double.MaxValue.ToString(); maxDec = maxDec + "1"; Convert.ToDouble(maxDec, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#I27", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#I27"); } try { Convert.ToDouble(tryObj, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#I28", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#I28"); } } public void TestToInt16() { - AssertEquals("#J01", (short)0, Convert.ToInt16(boolFalse)); - AssertEquals("#J02", (short)1, Convert.ToInt16(boolTrue)); - AssertEquals("#J03", (short)97, Convert.ToInt16(tryChar)); - AssertEquals("#J04", (short)1234, Convert.ToInt16(tryDec)); - AssertEquals("#J05", (short)0, Convert.ToInt16(tryDbl)); - AssertEquals("#J06", (short)1234, Convert.ToInt16(tryInt16)); - AssertEquals("#J07", (short)12345, Convert.ToInt16(tryInt32)); - AssertEquals("#J08", (short)30000, Convert.ToInt16((long)30000)); - AssertEquals("#J09", (short)123, Convert.ToInt16(trySByte)); - AssertEquals("#J10", (short)1234, Convert.ToInt16(tryFloat)); - AssertEquals("#J11", (short)578, Convert.ToInt16("578")); - AssertEquals("#J12", (short)15500, Convert.ToInt16((ushort)15500)); - AssertEquals("#J13", (short)5489, Convert.ToInt16((uint)5489)); - AssertEquals("#J14", (short)9876, Convert.ToInt16((ulong)9876)); - AssertEquals("#J15", (short)14, Convert.ToInt16("14", ci)); - AssertEquals("#J16", (short)11, Convert.ToInt16("01011", 2)); - AssertEquals("#J17", (short)1540, Convert.ToInt16("3004", 8)); - AssertEquals("#J18", (short)321, Convert.ToInt16("321", 10)); - AssertEquals("#J19", (short)2748, Convert.ToInt16("ABC", 16)); + Assert.AreEqual ((short)0, Convert.ToInt16(boolFalse), "#J01"); + Assert.AreEqual ((short)1, Convert.ToInt16(boolTrue), "#J02"); + Assert.AreEqual ((short)97, Convert.ToInt16(tryChar), "#J03"); + Assert.AreEqual ((short)1234, Convert.ToInt16(tryDec), "#J04"); + Assert.AreEqual ((short)0, Convert.ToInt16(tryDbl), "#J05"); + Assert.AreEqual ((short)1234, Convert.ToInt16(tryInt16), "#J06"); + Assert.AreEqual ((short)12345, Convert.ToInt16(tryInt32), "#J07"); + Assert.AreEqual ((short)30000, Convert.ToInt16((long)30000), "#J08"); + Assert.AreEqual ((short)123, Convert.ToInt16(trySByte), "#J09"); + Assert.AreEqual ((short)1234, Convert.ToInt16(tryFloat), "#J10"); + Assert.AreEqual ((short)578, Convert.ToInt16("578"), "#J11"); + Assert.AreEqual ((short)15500, Convert.ToInt16((ushort)15500), "#J12"); + Assert.AreEqual ((short)5489, Convert.ToInt16((uint)5489), "#J13"); + Assert.AreEqual ((short)9876, Convert.ToInt16((ulong)9876), "#J14"); + Assert.AreEqual ((short)14, Convert.ToInt16("14", ci), "#J15"); + Assert.AreEqual ((short)11, Convert.ToInt16("01011", 2), "#J16"); + Assert.AreEqual ((short)1540, Convert.ToInt16("3004", 8), "#J17"); + Assert.AreEqual ((short)321, Convert.ToInt16("321", 10), "#J18"); + Assert.AreEqual ((short)2748, Convert.ToInt16("ABC", 16), "#J19"); try { Convert.ToInt16(char.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J25", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J25"); } try { Convert.ToInt16(tryDT); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J26", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#J26"); } try { Convert.ToInt16((decimal)(short.MaxValue + 1)); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J27", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J27"); } try { Convert.ToInt16((decimal)(short.MinValue - 1)); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J28", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J28"); } try { Convert.ToInt16((double)(short.MaxValue + 1)); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J29", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J29"); } try { Convert.ToInt16((double)(short.MinValue - 1)); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J30", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J30"); } try { Convert.ToInt16(50000); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J31", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J31"); } try { Convert.ToInt16(-50000); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J32", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J32"); } try { Convert.ToInt16(tryInt64); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J33", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J33"); } try { Convert.ToInt16(-tryInt64); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J34", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J34"); } try { Convert.ToInt16(tryObj); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J35", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#J35"); } try { Convert.ToInt16((float)32767.5); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J36", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J36"); } try { Convert.ToInt16((float)-33000.54); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J37", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J37"); } try { Convert.ToInt16(tryStr); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J38", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#J38"); } try { Convert.ToInt16("-33000"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J39", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J39"); } try { Convert.ToInt16(ushort.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J40", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J40"); } try { Convert.ToInt16(uint.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J41", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J41"); } try { Convert.ToInt16(ulong.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J42", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J42"); } try { Convert.ToInt16(tryObj, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J43", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#J43"); } try { Convert.ToInt16(tryStr, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J44", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#J44"); } try { Convert.ToInt16("-33000", ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J45", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J45"); } try { Convert.ToInt16("321", 11); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J46", typeof(ArgumentException), e.GetType()); + Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#J46"); } try { Convert.ToInt16("D8BF1", 16); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#J47", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J47"); } } public void TestToInt32() { long tryMax = long.MaxValue; long tryMin = long.MinValue; - AssertEquals("#K01", (int)0, Convert.ToInt32(boolFalse)); - AssertEquals("#K02", (int)1, Convert.ToInt32(boolTrue)); - AssertEquals("#K03", (int)0, Convert.ToInt32(tryByte)); - AssertEquals("#K04", (int)97, Convert.ToInt32(tryChar)); - AssertEquals("#K05", (int)1234, Convert.ToInt32(tryDec)); - AssertEquals("#K06", (int)0, Convert.ToInt32(tryDbl)); - AssertEquals("#K07", (int)1234, Convert.ToInt32(tryInt16)); - AssertEquals("#K08", (int)12345, Convert.ToInt32(tryInt32)); - AssertEquals("#K09", (int)60000, Convert.ToInt32((long)60000)); - AssertEquals("#K10", (int)123, Convert.ToInt32(trySByte)); - AssertEquals("#K11", (int)1234, Convert.ToInt32(tryFloat)); - AssertEquals("#K12", (int)9876, Convert.ToInt32((string)"9876")); - AssertEquals("#K13", (int)34567, Convert.ToInt32(tryUI16)); - AssertEquals("#K14", (int)567891234, Convert.ToInt32(tryUI32)); - AssertEquals("#K15", (int)0, Convert.ToInt32(tryUI64)); - AssertEquals("#K16", (int)123, Convert.ToInt32("123", ci)); - AssertEquals("#K17", (int)128, Convert.ToInt32("10000000", 2)); - AssertEquals("#K18", (int)302, Convert.ToInt32("456", 8)); - AssertEquals("#K19", (int)456, Convert.ToInt32("456", 10)); - AssertEquals("#K20", (int)1110, Convert.ToInt32("456", 16)); + Assert.AreEqual ((int)0, Convert.ToInt32(boolFalse), "#K01"); + Assert.AreEqual ((int)1, Convert.ToInt32(boolTrue), "#K02"); + Assert.AreEqual ((int)0, Convert.ToInt32(tryByte), "#K03"); + Assert.AreEqual ((int)97, Convert.ToInt32(tryChar), "#K04"); + Assert.AreEqual ((int)1234, Convert.ToInt32(tryDec), "#K05"); + Assert.AreEqual ((int)0, Convert.ToInt32(tryDbl), "#K06"); + Assert.AreEqual ((int)1234, Convert.ToInt32(tryInt16), "#K07"); + Assert.AreEqual ((int)12345, Convert.ToInt32(tryInt32), "#K08"); + Assert.AreEqual ((int)60000, Convert.ToInt32((long)60000), "#K09"); + Assert.AreEqual ((int)123, Convert.ToInt32(trySByte), "#K10"); + Assert.AreEqual ((int)1234, Convert.ToInt32(tryFloat), "#K11"); + Assert.AreEqual ((int)9876, Convert.ToInt32((string)"9876"), "#K12"); + Assert.AreEqual ((int)34567, Convert.ToInt32(tryUI16), "#K13"); + Assert.AreEqual ((int)567891234, Convert.ToInt32(tryUI32), "#K14"); + Assert.AreEqual ((int)0, Convert.ToInt32(tryUI64), "#K15"); + Assert.AreEqual ((int)123, Convert.ToInt32("123", ci), "#K16"); + Assert.AreEqual ((int)128, Convert.ToInt32("10000000", 2), "#K17"); + Assert.AreEqual ((int)302, Convert.ToInt32("456", 8), "#K18"); + Assert.AreEqual ((int)456, Convert.ToInt32("456", 10), "#K19"); + Assert.AreEqual ((int)1110, Convert.ToInt32("456", 16), "#K20"); try { Convert.ToInt32(tryDT); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K25", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#K25"); } try { Convert.ToInt32((decimal)tryMax); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K26", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K26"); } try { Convert.ToInt32((decimal)tryMin); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K27", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K27"); } try { Convert.ToInt32((double)tryMax); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K28", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K28"); } try { Convert.ToInt32((double)tryMin); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K29", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K29"); } try { Convert.ToInt32(tryInt64); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K30", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K30"); } try { Convert.ToInt32(-tryInt64); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K31", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K31"); } try { Convert.ToInt32(tryObj); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K32", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#K32"); } try { Convert.ToInt32((float)tryMax); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K33", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K33"); } try { Convert.ToInt32((float)tryMin); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K34", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K34"); } try { Convert.ToInt32(tryStr, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K35", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#K35"); } try { Convert.ToInt32("-46565465123"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K36", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K36"); } try { Convert.ToInt32("46565465123"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K37", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K37"); } try { Convert.ToInt32((uint)tryMax); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K38", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K38"); } try { Convert.ToInt32((ulong)tryMax); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K39", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K39"); } try { Convert.ToInt32(tryObj, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K40", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#K40"); } try { Convert.ToInt32(tryStr, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K41", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#K41"); } try { Convert.ToInt32("-46565465123", ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K42", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K42"); } try { Convert.ToInt32("654", 9); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#K43", typeof(ArgumentException), e.GetType()); + Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#K43"); } } @@ -1463,803 +1467,802 @@ namespace MonoTests.System { decimal longMin = long.MinValue; longMin -= 1000000; - AssertEquals("#L01", (long)0, Convert.ToInt64(boolFalse)); - AssertEquals("#L02", (long)1, Convert.ToInt64(boolTrue)); - AssertEquals("#L03", (long)97, Convert.ToInt64(tryChar)); - AssertEquals("#L04", (long)1234, Convert.ToInt64(tryDec)); - AssertEquals("#L05", (long)0, Convert.ToInt64(tryDbl)); - AssertEquals("#L06", (long)1234, Convert.ToInt64(tryInt16)); - AssertEquals("#L07", (long)12345, Convert.ToInt64(tryInt32)); - AssertEquals("#L08", (long)123456789012, Convert.ToInt64(tryInt64)); - AssertEquals("#L09", (long)123, Convert.ToInt64(trySByte)); - AssertEquals("#L10", (long)1234, Convert.ToInt64(tryFloat)); - AssertEquals("#L11", (long)564897, Convert.ToInt64("564897")); - AssertEquals("#L12", (long)34567, Convert.ToInt64(tryUI16)); - AssertEquals("#L13", (long)567891234, Convert.ToInt64(tryUI32)); - AssertEquals("#L14", (long)0, Convert.ToInt64(tryUI64)); - AssertEquals("#L15", (long)-2548751, Convert.ToInt64("-2548751", ci)); - AssertEquals("#L16", (long)24987562, Convert.ToInt64("1011111010100011110101010", 2)); - AssertEquals("#L17", (long)-24578965, Convert.ToInt64("1777777777777642172153", 8)); - AssertEquals("#L18", (long)248759757, Convert.ToInt64("248759757", 10)); - AssertEquals("#L19", (long)256, Convert.ToInt64("100", 16)); + Assert.AreEqual ((long)0, Convert.ToInt64(boolFalse), "#L01"); + Assert.AreEqual ((long)1, Convert.ToInt64(boolTrue), "#L02"); + Assert.AreEqual ((long)97, Convert.ToInt64(tryChar), "#L03"); + Assert.AreEqual ((long)1234, Convert.ToInt64(tryDec), "#L04"); + Assert.AreEqual ((long)0, Convert.ToInt64(tryDbl), "#L05"); + Assert.AreEqual ((long)1234, Convert.ToInt64(tryInt16), "#L06"); + Assert.AreEqual ((long)12345, Convert.ToInt64(tryInt32), "#L07"); + Assert.AreEqual ((long)123456789012, Convert.ToInt64(tryInt64), "#L08"); + Assert.AreEqual ((long)123, Convert.ToInt64(trySByte), "#L09"); + Assert.AreEqual ((long)1234, Convert.ToInt64(tryFloat), "#L10"); + Assert.AreEqual ((long)564897, Convert.ToInt64("564897"), "#L11"); + Assert.AreEqual ((long)34567, Convert.ToInt64(tryUI16), "#L12"); + Assert.AreEqual ((long)567891234, Convert.ToInt64(tryUI32), "#L13"); + Assert.AreEqual ((long)0, Convert.ToInt64(tryUI64), "#L14"); + Assert.AreEqual ((long)-2548751, Convert.ToInt64("-2548751", ci), "#L15"); + Assert.AreEqual ((long)24987562, Convert.ToInt64("1011111010100011110101010", 2), "#L16"); + Assert.AreEqual ((long)-24578965, Convert.ToInt64("1777777777777642172153", 8), "#L17"); + Assert.AreEqual ((long)248759757, Convert.ToInt64("248759757", 10), "#L18"); + Assert.AreEqual ((long)256, Convert.ToInt64("100", 16), "#L19"); try { Convert.ToInt64(tryDT); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#L20", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#L20"); } try { Convert.ToInt64((decimal)longMax + 1); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#L21", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L21"); } try { Convert.ToInt64((decimal)longMin); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#L24", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L24"); } try { Convert.ToInt64((double)longMax); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#L25:"+longMax, typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L25:"+longMax); } try { Convert.ToInt64((double)longMin); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#L26", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L26"); } try { Convert.ToInt64(new Exception()); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#L27", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#L27"); } try { Convert.ToInt64(((float)longMax)*100); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#L28:"+longMax, typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L28:"+longMax); } try { Convert.ToInt64(((float)longMin)*100); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#L29", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L29"); } try { Convert.ToInt64("-567b3"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#L30", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#L30"); } try { Convert.ToInt64(longMax.ToString()); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#L31:", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L31:"); } try { Convert.ToInt64(ulong.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#L32", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L32"); } try { Convert.ToInt64(tryStr, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#L32b", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#L32b"); } try { Convert.ToInt64(longMin.ToString(), ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#L33", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L33"); } try { Convert.ToInt64("321", 11); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#L34", typeof(ArgumentException), e.GetType()); + Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#L34"); } } public void TestToSByte() { int iTest = 1; try { - AssertEquals("#M01", (sbyte)0, Convert.ToSByte(boolFalse)); + Assert.AreEqual ((sbyte)0, Convert.ToSByte(boolFalse), "#M01"); iTest++; - AssertEquals("#M02", (sbyte)1, Convert.ToSByte(boolTrue)); + Assert.AreEqual ((sbyte)1, Convert.ToSByte(boolTrue), "#M02"); iTest++; - AssertEquals("#M03", (sbyte)97, Convert.ToSByte(tryChar)); + Assert.AreEqual ((sbyte)97, Convert.ToSByte(tryChar), "#M03"); iTest++; - AssertEquals("#M04", (sbyte)15, Convert.ToSByte((decimal)15)); + Assert.AreEqual ((sbyte)15, Convert.ToSByte((decimal)15), "#M04"); iTest++; - AssertEquals("#M05", (sbyte)0, Convert.ToSByte(tryDbl)); + Assert.AreEqual ((sbyte)0, Convert.ToSByte(tryDbl), "#M05"); iTest++; - AssertEquals("#M06", (sbyte)127, Convert.ToSByte((short)127)); + Assert.AreEqual ((sbyte)127, Convert.ToSByte((short)127), "#M06"); iTest++; - AssertEquals("#M07", (sbyte)-128, Convert.ToSByte((int)-128)); + Assert.AreEqual ((sbyte)-128, Convert.ToSByte((int)-128), "#M07"); iTest++; - AssertEquals("#M08", (sbyte)30, Convert.ToSByte((long)30)); + Assert.AreEqual ((sbyte)30, Convert.ToSByte((long)30), "#M08"); iTest++; - AssertEquals("#M09", (sbyte)123, Convert.ToSByte(trySByte)); + Assert.AreEqual ((sbyte)123, Convert.ToSByte(trySByte), "#M09"); iTest++; - AssertEquals("#M10", (sbyte)12, Convert.ToSByte((float)12.46987f)); + Assert.AreEqual ((sbyte)12, Convert.ToSByte((float)12.46987f), "#M10"); iTest++; - AssertEquals("#M11", (sbyte)1, Convert.ToSByte("1")); + Assert.AreEqual ((sbyte)1, Convert.ToSByte("1"), "#M11"); iTest++; - AssertEquals("#M12", (sbyte)99, Convert.ToSByte((ushort)99)); + Assert.AreEqual ((sbyte)99, Convert.ToSByte((ushort)99), "#M12"); iTest++; - AssertEquals("#M13", (sbyte)54, Convert.ToSByte((uint)54)); + Assert.AreEqual ((sbyte)54, Convert.ToSByte((uint)54), "#M13"); iTest++; - AssertEquals("#M14", (sbyte)127, Convert.ToSByte((ulong)127)); + Assert.AreEqual ((sbyte)127, Convert.ToSByte((ulong)127), "#M14"); iTest++; - AssertEquals("#M15", (sbyte)14, Convert.ToSByte("14", ci)); + Assert.AreEqual ((sbyte)14, Convert.ToSByte("14", ci), "#M15"); iTest++; - AssertEquals("#M16", (sbyte)11, Convert.ToSByte("01011", 2)); + Assert.AreEqual ((sbyte)11, Convert.ToSByte("01011", 2), "#M16"); iTest++; - AssertEquals("#M17", (sbyte)5, Convert.ToSByte("5", 8)); + Assert.AreEqual ((sbyte)5, Convert.ToSByte("5", 8), "#M17"); iTest++; - AssertEquals("#M18", (sbyte)100, Convert.ToSByte("100", 10)); + Assert.AreEqual ((sbyte)100, Convert.ToSByte("100", 10), "#M18"); iTest++; - AssertEquals("#M19", (sbyte)-1, Convert.ToSByte("FF", 16)); + Assert.AreEqual ((sbyte)-1, Convert.ToSByte("FF", 16), "#M19"); } catch (Exception e) { - Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e); + Assert.Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e); } try { Convert.ToSByte((byte)200); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M25", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M25"); } try { Convert.ToSByte((char)130); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M26", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M26"); } try { Convert.ToSByte(tryDT); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M27", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#M27"); } try { Convert.ToSByte((decimal)127.5m); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M28", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M28"); } try { Convert.ToSByte((decimal)-200m); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M29", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M29"); } try { Convert.ToSByte((double)150); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M30", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M30"); } try { Convert.ToSByte((double)-128.6); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M31", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M31"); } try { Convert.ToSByte((short)150); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M32", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M32"); } try { Convert.ToSByte((short)-300); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M33", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M33"); } try { Convert.ToSByte((int)1500); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M34", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M34"); } try { Convert.ToSByte((int)-1286); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M35", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M35"); } try { Convert.ToSByte((long)128); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M36", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M36"); } try { Convert.ToSByte((long)-129); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M37", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M37"); } try { Convert.ToSByte(new NumberFormatInfo()); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M38", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#M38"); } try { Convert.ToSByte((float)333); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M39", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M39"); } try { Convert.ToSByte((float)-666); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M40", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M40"); } try { Convert.ToSByte("B3"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M41", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#M41"); } try { Convert.ToSByte("251"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M42", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M42"); } try { Convert.ToSByte(ushort.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M43", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M43"); } try { Convert.ToSByte((uint)600); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M44", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M44"); } try { Convert.ToSByte(ulong.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M45", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M45"); } try { Convert.ToSByte(ci, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M46", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#M46"); } try { Convert.ToSByte(tryStr, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M47", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#M47"); } try { Convert.ToSByte("325", ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M48", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M48"); } try { Convert.ToSByte("5D", 15); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M49", typeof(ArgumentException), e.GetType()); + Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#M49"); } try { Convert.ToSByte("111111111", 2); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#M50", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M50"); } } public void TestToSingle() { int iTest = 1; try { - AssertEquals("#N01", (float)0, Convert.ToSingle(boolFalse)); + Assert.AreEqual ((float)0, Convert.ToSingle(boolFalse), "#N01"); iTest++; - AssertEquals("#N02", (float)1, Convert.ToSingle(boolTrue)); + Assert.AreEqual ((float)1, Convert.ToSingle(boolTrue), "#N02"); iTest++; - AssertEquals("#N03", (float)0, Convert.ToSingle(tryByte)); + Assert.AreEqual ((float)0, Convert.ToSingle(tryByte), "#N03"); iTest++; - AssertEquals("#N04", (float)1234,234, Convert.ToSingle(tryDec)); + Assert.AreEqual ((float)1234, 234, Convert.ToSingle(tryDec), "#N04"); iTest++; - AssertEquals("#N05", (float)0, Convert.ToSingle(tryDbl)); + Assert.AreEqual ((float)0, Convert.ToSingle(tryDbl), "#N05"); iTest++; - AssertEquals("#N06", (float)1234, Convert.ToSingle(tryInt16)); + Assert.AreEqual ((float)1234, Convert.ToSingle(tryInt16), "#N06"); iTest++; - AssertEquals("#N07", (float)12345, Convert.ToSingle(tryInt32)); + Assert.AreEqual ((float)12345, Convert.ToSingle(tryInt32), "#N07"); iTest++; - AssertEquals("#N08", (float)123456789012, Convert.ToSingle(tryInt64)); + Assert.AreEqual ((float)123456789012, Convert.ToSingle(tryInt64), "#N08"); iTest++; - AssertEquals("#N09", (float)123, Convert.ToSingle(trySByte)); + Assert.AreEqual ((float)123, Convert.ToSingle(trySByte), "#N09"); iTest++; - AssertEquals("#N10", (float)1234,2345, Convert.ToSingle(tryFloat)); + Assert.AreEqual ((float)1234, 2345, Convert.ToSingle(tryFloat), "#N10"); iTest++; - AssertEquals("#N11", (float)987, Convert.ToSingle("987")); + Assert.AreEqual ((float)987, Convert.ToSingle("987"), "#N11"); iTest++; - AssertEquals("#N12", (float)34567, Convert.ToSingle(tryUI16)); + Assert.AreEqual ((float)34567, Convert.ToSingle(tryUI16), "#N12"); iTest++; - AssertEquals("#N13", (float)567891234, Convert.ToSingle(tryUI32)); + Assert.AreEqual ((float)567891234, Convert.ToSingle(tryUI32), "#N13"); iTest++; - AssertEquals("#N14", (float)0, Convert.ToSingle(tryUI64)); + Assert.AreEqual ((float)0, Convert.ToSingle(tryUI64), "#N14"); iTest++; - AssertEquals("#N15", (float)654.234, Convert.ToSingle("654.234", ci)); + Assert.AreEqual ((float)654.234, Convert.ToSingle("654.234", ci), "#N15"); } catch (Exception e) { - Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e); + Assert.Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e); } try { Convert.ToSingle(tryChar); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#N25", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#N25"); } try { Convert.ToSingle(tryDT); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#N26", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#N26"); } try { Convert.ToSingle(tryObj); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#N27", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#N27"); } try { Convert.ToSingle("A345H"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#N28", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#N28"); } try { Convert.ToSingle(double.MaxValue.ToString()); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#N29", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#N29"); } try { Convert.ToSingle(tryObj, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#N30", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#N30"); } try { Convert.ToSingle("J345K", ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#N31", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#N31"); } try { Convert.ToSingle("11000000000000000000000000000000000000000000000", ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#N32", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#N32"); } } public void TestToString() { tryByte = 123; - AssertEquals("#O01", "False", Convert.ToString(boolFalse)); - AssertEquals("#O02", "True", Convert.ToString(boolTrue)); - AssertEquals("#O03", "123", Convert.ToString(tryByte)); - AssertEquals("#O04", "a", Convert.ToString(tryChar)); - AssertEquals("#O05", tryDT.ToString(), Convert.ToString(tryDT)); - AssertEquals("#O06", tryDec.ToString(), Convert.ToString(tryDec)); - AssertEquals("#O07", tryDbl.ToString(), Convert.ToString(tryDbl)); - AssertEquals("#O08", "1234", Convert.ToString(tryInt16)); - AssertEquals("#O09", "12345", Convert.ToString(tryInt32)); - AssertEquals("#O10", "123456789012", Convert.ToString(tryInt64)); - AssertEquals("#O11", "123", Convert.ToString(trySByte)); - AssertEquals("#O12", tryFloat.ToString(), Convert.ToString(tryFloat)); - AssertEquals("#O13", "foobar", Convert.ToString(tryStr)); - AssertEquals("#O14", "34567", Convert.ToString(tryUI16)); - AssertEquals("#O15", "567891234", Convert.ToString(tryUI32)); - AssertEquals("#O16", "True", Convert.ToString(boolTrue, ci)); - AssertEquals("#O17", "False", Convert.ToString(boolFalse, ci)); - AssertEquals("#O18", "123", Convert.ToString(tryByte, ci)); - AssertEquals("#O19", "1111011", Convert.ToString(tryByte, 2)); - AssertEquals("#O20", "173", Convert.ToString(tryByte, 8)); - AssertEquals("#O21", "123", Convert.ToString(tryByte, 10)); - AssertEquals("#O22", "7b", Convert.ToString(tryByte, 16)); - AssertEquals("#O23", "a", Convert.ToString(tryChar, ci)); - AssertEquals("#O24", tryDT.ToString(ci), Convert.ToString(tryDT, ci)); - AssertEquals("#O25", tryDec.ToString(ci), Convert.ToString(tryDec,ci)); - AssertEquals("#O26", tryDbl.ToString(ci), Convert.ToString(tryDbl, ci)); - AssertEquals("#O27", "1234", Convert.ToString(tryInt16, ci)); - AssertEquals("#O28", "10011010010", Convert.ToString(tryInt16, 2)); - AssertEquals("#O29", "2322", Convert.ToString(tryInt16, 8)); - AssertEquals("#O30", "1234", Convert.ToString(tryInt16, 10)); - AssertEquals("#O31", "4d2", Convert.ToString(tryInt16, 16)); - AssertEquals("#O32", "12345", Convert.ToString(tryInt32, ci)); - AssertEquals("#O33", "11000000111001", Convert.ToString(tryInt32, 2)); - AssertEquals("#O34", "30071", Convert.ToString(tryInt32, 8)); - AssertEquals("#O35", "12345", Convert.ToString(tryInt32, 10)); - AssertEquals("#O36", "3039", Convert.ToString(tryInt32, 16)); - AssertEquals("#O37", "123456789012", Convert.ToString(tryInt64, ci)); - AssertEquals("#O38", "1110010111110100110010001101000010100", - Convert.ToString(tryInt64, 2)); - AssertEquals("#O39", "1627646215024", Convert.ToString(tryInt64, 8)); - AssertEquals("#O40", "123456789012", Convert.ToString(tryInt64, 10)); - AssertEquals("#O41", "1cbe991a14", Convert.ToString(tryInt64, 16)); - AssertEquals("#O42", "123", Convert.ToString((trySByte), ci)); - AssertEquals("#O43", tryFloat.ToString(ci), Convert.ToString((tryFloat), ci)); - AssertEquals("#O44", "foobar", Convert.ToString((tryStr), ci)); - AssertEquals("#O45", "34567", Convert.ToString((tryUI16), ci)); - AssertEquals("#O46", "567891234", Convert.ToString((tryUI32), ci)); - AssertEquals("#O47", "0", Convert.ToString(tryUI64)); - AssertEquals("#O48", "0", Convert.ToString((tryUI64), ci)); + Assert.AreEqual ("False", Convert.ToString(boolFalse), "#O01"); + Assert.AreEqual ("True", Convert.ToString(boolTrue), "#O02"); + Assert.AreEqual ("123", Convert.ToString(tryByte), "#O03"); + Assert.AreEqual ("a", Convert.ToString(tryChar), "#O04"); + Assert.AreEqual (tryDT.ToString(), Convert.ToString(tryDT), "#O05"); + Assert.AreEqual (tryDec.ToString(), Convert.ToString(tryDec), "#O06"); + Assert.AreEqual (tryDbl.ToString(), Convert.ToString(tryDbl), "#O07"); + Assert.AreEqual ("1234", Convert.ToString(tryInt16), "#O08"); + Assert.AreEqual ("12345", Convert.ToString(tryInt32), "#O09"); + Assert.AreEqual ("123456789012", Convert.ToString(tryInt64), "#O10"); + Assert.AreEqual ("123", Convert.ToString(trySByte), "#O11"); + Assert.AreEqual (tryFloat.ToString(), Convert.ToString(tryFloat), "#O12"); + Assert.AreEqual ("foobar", Convert.ToString(tryStr), "#O13"); + Assert.AreEqual ("34567", Convert.ToString(tryUI16), "#O14"); + Assert.AreEqual ("567891234", Convert.ToString(tryUI32), "#O15"); + Assert.AreEqual ("True", Convert.ToString(boolTrue, ci), "#O16"); + Assert.AreEqual ("False", Convert.ToString(boolFalse, ci), "#O17"); + Assert.AreEqual ("123", Convert.ToString(tryByte, ci), "#O18"); + Assert.AreEqual ("1111011", Convert.ToString(tryByte, 2), "#O19"); + Assert.AreEqual ("173", Convert.ToString(tryByte, 8), "#O20"); + Assert.AreEqual ("123", Convert.ToString(tryByte, 10), "#O21"); + Assert.AreEqual ("7b", Convert.ToString(tryByte, 16), "#O22"); + Assert.AreEqual ("a", Convert.ToString(tryChar, ci), "#O23"); + Assert.AreEqual (tryDT.ToString(ci), Convert.ToString(tryDT, ci), "#O24"); + Assert.AreEqual (tryDec.ToString(ci), Convert.ToString(tryDec, ci), "#O25"); + Assert.AreEqual (tryDbl.ToString(ci), Convert.ToString(tryDbl, ci), "#O26"); + Assert.AreEqual ("1234", Convert.ToString(tryInt16, ci), "#O27"); + Assert.AreEqual ("10011010010", Convert.ToString(tryInt16, 2), "#O28"); + Assert.AreEqual ("2322", Convert.ToString(tryInt16, 8), "#O29"); + Assert.AreEqual ("1234", Convert.ToString(tryInt16, 10), "#O30"); + Assert.AreEqual ("4d2", Convert.ToString(tryInt16, 16), "#O31"); + Assert.AreEqual ("12345", Convert.ToString(tryInt32, ci), "#O32"); + Assert.AreEqual ("11000000111001", Convert.ToString(tryInt32, 2), "#O33"); + Assert.AreEqual ("30071", Convert.ToString(tryInt32, 8), "#O34"); + Assert.AreEqual ("12345", Convert.ToString(tryInt32, 10), "#O35"); + Assert.AreEqual ("3039", Convert.ToString(tryInt32, 16), "#O36"); + Assert.AreEqual ("123456789012", Convert.ToString(tryInt64, ci), "#O37"); + Assert.AreEqual ("1110010111110100110010001101000010100", Convert.ToString(tryInt64, 2), "#O38"); + Assert.AreEqual ("1627646215024", Convert.ToString(tryInt64, 8), "#O39"); + Assert.AreEqual ("123456789012", Convert.ToString(tryInt64, 10), "#O40"); + Assert.AreEqual ("1cbe991a14", Convert.ToString(tryInt64, 16), "#O41"); + Assert.AreEqual ("123", Convert.ToString((trySByte), ci), "#O42"); + Assert.AreEqual (tryFloat.ToString(ci), Convert.ToString((tryFloat), ci), "#O43"); + Assert.AreEqual ("foobar", Convert.ToString((tryStr), ci), "#O44"); + Assert.AreEqual ("34567", Convert.ToString((tryUI16), ci), "#O45"); + Assert.AreEqual ("567891234", Convert.ToString((tryUI32), ci), "#O46"); + Assert.AreEqual ("0", Convert.ToString(tryUI64), "#O47"); + Assert.AreEqual ("0", Convert.ToString((tryUI64), ci), "#O48"); try { Convert.ToString(tryInt16, 5); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#O55", typeof(ArgumentException), e.GetType()); + Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#O55"); } try { Convert.ToString(tryInt32, 17); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#O56", typeof(ArgumentException), e.GetType()); + Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#O56"); } try { Convert.ToString(tryInt64, 1); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#O57", typeof(ArgumentException), e.GetType()); + Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#O57"); } } public void TestToUInt16() { - AssertEquals("#P01", (ushort)0, Convert.ToUInt16(boolFalse)); - AssertEquals("#P02", (ushort)1, Convert.ToUInt16(boolTrue)); - AssertEquals("#P03", (ushort)0, Convert.ToUInt16(tryByte)); - AssertEquals("#P04", (ushort)97, Convert.ToUInt16(tryChar)); - AssertEquals("#P05", (ushort)1234, Convert.ToUInt16(tryDec)); - AssertEquals("#P06", (ushort)0, Convert.ToUInt16(tryDbl)); - AssertEquals("#P07", (ushort)1234, Convert.ToUInt16(tryInt16)); - AssertEquals("#P08", (ushort)12345, Convert.ToUInt16(tryInt32)); - AssertEquals("#P09", (ushort)43752, Convert.ToUInt16((long)43752)); - AssertEquals("#P10", (ushort)123, Convert.ToUInt16(trySByte)); - AssertEquals("#P11", (ushort)1234, Convert.ToUInt16(tryFloat)); - AssertEquals("#P12", (ushort)123, Convert.ToUInt16((string)"123")); - AssertEquals("#P13", (ushort)34567, Convert.ToUInt16(tryUI16)); - AssertEquals("#P14", (ushort)56789, Convert.ToUInt16((uint)56789)); - AssertEquals("#P15", (ushort)0, Convert.ToUInt16(tryUI64)); - AssertEquals("#P16", (ushort)31, Convert.ToUInt16("31", ci)); - AssertEquals("#P17", (ushort)14, Convert.ToUInt16("1110", 2)); - AssertEquals("#P18", (ushort)32, Convert.ToUInt16("40", 8)); - AssertEquals("#P19", (ushort)40, Convert.ToUInt16("40", 10)); - AssertEquals("#P20", (ushort)64, Convert.ToUInt16("40", 16)); + Assert.AreEqual ((ushort)0, Convert.ToUInt16(boolFalse), "#P01"); + Assert.AreEqual ((ushort)1, Convert.ToUInt16(boolTrue), "#P02"); + Assert.AreEqual ((ushort)0, Convert.ToUInt16(tryByte), "#P03"); + Assert.AreEqual ((ushort)97, Convert.ToUInt16(tryChar), "#P04"); + Assert.AreEqual ((ushort)1234, Convert.ToUInt16(tryDec), "#P05"); + Assert.AreEqual ((ushort)0, Convert.ToUInt16(tryDbl), "#P06"); + Assert.AreEqual ((ushort)1234, Convert.ToUInt16(tryInt16), "#P07"); + Assert.AreEqual ((ushort)12345, Convert.ToUInt16(tryInt32), "#P08"); + Assert.AreEqual ((ushort)43752, Convert.ToUInt16((long)43752), "#P09"); + Assert.AreEqual ((ushort)123, Convert.ToUInt16(trySByte), "#P10"); + Assert.AreEqual ((ushort)1234, Convert.ToUInt16(tryFloat), "#P11"); + Assert.AreEqual ((ushort)123, Convert.ToUInt16((string)"123"), "#P12"); + Assert.AreEqual ((ushort)34567, Convert.ToUInt16(tryUI16), "#P13"); + Assert.AreEqual ((ushort)56789, Convert.ToUInt16((uint)56789), "#P14"); + Assert.AreEqual ((ushort)0, Convert.ToUInt16(tryUI64), "#P15"); + Assert.AreEqual ((ushort)31, Convert.ToUInt16("31", ci), "#P16"); + Assert.AreEqual ((ushort)14, Convert.ToUInt16("1110", 2), "#P17"); + Assert.AreEqual ((ushort)32, Convert.ToUInt16("40", 8), "#P18"); + Assert.AreEqual ((ushort)40, Convert.ToUInt16("40", 10), "#P19"); + Assert.AreEqual ((ushort)64, Convert.ToUInt16("40", 16), "#P20"); try { Convert.ToUInt16(tryDT); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P25", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#P25"); } try { Convert.ToUInt16(decimal.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P26", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P26"); } try { Convert.ToUInt16(decimal.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P27", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P27"); } try { Convert.ToUInt16(double.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P28", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P28"); } try { Convert.ToUInt16(double.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P29", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P29"); } try { Convert.ToUInt16(short.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P30", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P30"); } try { Convert.ToUInt16(int.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P31", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P31"); } try { Convert.ToUInt16(int.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P32", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P32"); } try { Convert.ToUInt16(long.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P33", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P33"); } try { Convert.ToUInt16(long.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P34", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P34"); } try { Convert.ToUInt16(tryObj); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P35", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#P35"); } try { Convert.ToUInt16(sbyte.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P36", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P36"); } try { Convert.ToUInt16(float.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P37", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P37"); } try { Convert.ToUInt16(float.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P38", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P38"); } try { Convert.ToUInt16("1A2"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P39", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#P39"); } try { Convert.ToUInt16("-32800"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P40", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P40"); } try { Convert.ToUInt16(int.MaxValue.ToString()); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P41", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P41"); } try { Convert.ToUInt16(ulong.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P42", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P42"); } try { Convert.ToUInt16("1A2", ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P43", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#P43"); } try { Convert.ToUInt16("-32800", ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P44", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P44"); } try { Convert.ToUInt16("456987", ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P45", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P45"); } try { Convert.ToUInt16("40", 9); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#P46", typeof(ArgumentException), e.GetType()); + Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#P46"); } try { Convert.ToUInt16 ("abcde", 16); - Fail (); + Assert.Fail (); } catch (Exception e) { - AssertEquals ("#P47", typeof (OverflowException), e.GetType ()); + Assert.AreEqual (typeof (OverflowException), e.GetType (), "#P47"); } } public void TestSignedToInt() { // String cannot contain a minus sign if the base is not 10. // But can if it is ten, and + is allowed everywhere. - AssertEquals("Signed0", -1, Convert.ToInt32 ("-1", 10)); - AssertEquals("Signed1", 1, Convert.ToInt32 ("+1", 10)); - AssertEquals("Signed2", 1, Convert.ToInt32 ("+1", 2)); - AssertEquals("Signed3", 1, Convert.ToInt32 ("+1", 8)); - AssertEquals("Signed4", 1, Convert.ToInt32 ("+1", 16)); + Assert.AreEqual (-1, Convert.ToInt32 ("-1", 10), "Signed0"); + Assert.AreEqual (1, Convert.ToInt32 ("+1", 10), "Signed1"); + Assert.AreEqual (1, Convert.ToInt32 ("+1", 2), "Signed2"); + Assert.AreEqual (1, Convert.ToInt32 ("+1", 8), "Signed3"); + Assert.AreEqual (1, Convert.ToInt32 ("+1", 16), "Signed4"); try { Convert.ToInt32("-1", 2); - Fail(); + Assert.Fail (); } catch (Exception) { } try { Convert.ToInt32("-1", 8); - Fail(); + Assert.Fail (); } catch (Exception) { } try { Convert.ToInt32("-1", 16); - Fail(); + Assert.Fail (); } catch (Exception) { } @@ -2268,193 +2271,193 @@ namespace MonoTests.System { } public void TestToUInt32() { - AssertEquals("#Q01", (uint)1, Convert.ToUInt32(boolTrue)); - AssertEquals("#Q02", (uint)0, Convert.ToUInt32(boolFalse)); - AssertEquals("#Q03", (uint)0, Convert.ToUInt32(tryByte)); - AssertEquals("#Q04", (uint)97, Convert.ToUInt32(tryChar)); - AssertEquals("#Q05", (uint)1234, Convert.ToUInt32(tryDec)); - AssertEquals("#Q06", (uint)0, Convert.ToUInt32(tryDbl)); - AssertEquals("#Q07", (uint)1234, Convert.ToUInt32(tryInt16)); - AssertEquals("#Q08", (uint)12345, Convert.ToUInt32(tryInt32)); - AssertEquals("#Q09", (uint)1234567890, Convert.ToUInt32((long)1234567890)); - AssertEquals("#Q10", (uint)123, Convert.ToUInt32(trySByte)); - AssertEquals("#Q11", (uint)1234, Convert.ToUInt32(tryFloat)); - AssertEquals("#Q12", (uint)3456789, Convert.ToUInt32("3456789")); - AssertEquals("#Q13", (uint)34567, Convert.ToUInt32(tryUI16)); - AssertEquals("#Q14", (uint)567891234, Convert.ToUInt32(tryUI32)); - AssertEquals("#Q15", (uint)0, Convert.ToUInt32(tryUI64)); - AssertEquals("#Q16", (uint)415, Convert.ToUInt32("110011111", 2)); - AssertEquals("#Q17", (uint)156, Convert.ToUInt32("234" ,8)); - AssertEquals("#Q18", (uint)234, Convert.ToUInt32("234" ,10)); - AssertEquals("#Q19", (uint)564, Convert.ToUInt32("234" ,16)); + Assert.AreEqual ((uint)1, Convert.ToUInt32(boolTrue), "#Q01"); + Assert.AreEqual ((uint)0, Convert.ToUInt32(boolFalse), "#Q02"); + Assert.AreEqual ((uint)0, Convert.ToUInt32(tryByte), "#Q03"); + Assert.AreEqual ((uint)97, Convert.ToUInt32(tryChar), "#Q04"); + Assert.AreEqual ((uint)1234, Convert.ToUInt32(tryDec), "#Q05"); + Assert.AreEqual ((uint)0, Convert.ToUInt32(tryDbl), "#Q06"); + Assert.AreEqual ((uint)1234, Convert.ToUInt32(tryInt16), "#Q07"); + Assert.AreEqual ((uint)12345, Convert.ToUInt32(tryInt32), "#Q08"); + Assert.AreEqual ((uint)1234567890, Convert.ToUInt32((long)1234567890), "#Q09"); + Assert.AreEqual ((uint)123, Convert.ToUInt32(trySByte), "#Q10"); + Assert.AreEqual ((uint)1234, Convert.ToUInt32(tryFloat), "#Q11"); + Assert.AreEqual ((uint)3456789, Convert.ToUInt32("3456789"), "#Q12"); + Assert.AreEqual ((uint)34567, Convert.ToUInt32(tryUI16), "#Q13"); + Assert.AreEqual ((uint)567891234, Convert.ToUInt32(tryUI32), "#Q14"); + Assert.AreEqual ((uint)0, Convert.ToUInt32(tryUI64), "#Q15"); + Assert.AreEqual ((uint)415, Convert.ToUInt32("110011111", 2), "#Q16"); + Assert.AreEqual ((uint)156, Convert.ToUInt32("234", 8), "#Q17"); + Assert.AreEqual ((uint)234, Convert.ToUInt32("234", 10), "#Q18"); + Assert.AreEqual ((uint)564, Convert.ToUInt32("234", 16), "#Q19"); try { Convert.ToUInt32(tryDT); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q25", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#Q25"); } try { Convert.ToUInt32(decimal.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q26", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q26"); } try { Convert.ToUInt32((decimal)-150); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q27", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q27"); } try { Convert.ToUInt32(double.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q28", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q28"); } try { Convert.ToUInt32((double)-1); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q29", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q29"); } try { Convert.ToUInt32(short.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q30", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q30"); } try { Convert.ToUInt32(int.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q31", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q31"); } try { Convert.ToUInt32(long.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q32", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q32"); } try { Convert.ToUInt32((long)-50000); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q33", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q33"); } try { Convert.ToUInt32(new Exception()); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q34", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#Q34"); } try { Convert.ToUInt32(sbyte.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q35", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q35"); } try { Convert.ToUInt32(float.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q36", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q36"); } try { Convert.ToUInt32(float.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q37", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q37"); } try { Convert.ToUInt32("45t54"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q38", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#Q38"); } try { Convert.ToUInt32("-55"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q39", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q39"); } try { Convert.ToUInt32(ulong.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q40", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q40"); } try { Convert.ToUInt32(new Exception(), ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q41", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#Q41"); } try { Convert.ToUInt32(tryStr, ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q42", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#Q42"); } try { Convert.ToUInt32("-50", ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q43", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q43"); } try { Convert.ToUInt32(decimal.MaxValue.ToString(), ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q44", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q44"); } try { Convert.ToUInt32("1001110", 1); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#Q45", typeof(ArgumentException), e.GetType()); + Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#Q45"); } } @@ -2462,205 +2465,205 @@ namespace MonoTests.System { { int iTest = 1; try { - AssertEquals("#R01", (ulong)1, Convert.ToUInt64(boolTrue)); + Assert.AreEqual ((ulong)1, Convert.ToUInt64(boolTrue), "#R01"); iTest++; - AssertEquals("#R02", (ulong)0, Convert.ToUInt64(boolFalse)); + Assert.AreEqual ((ulong)0, Convert.ToUInt64(boolFalse), "#R02"); iTest++; - AssertEquals("#R03", (ulong)0, Convert.ToUInt64(tryByte)); + Assert.AreEqual ((ulong)0, Convert.ToUInt64(tryByte), "#R03"); iTest++; - AssertEquals("#R04", (ulong)97, Convert.ToUInt64(tryChar)); + Assert.AreEqual ((ulong)97, Convert.ToUInt64(tryChar), "#R04"); iTest++; - AssertEquals("#R05", (ulong)1234, Convert.ToUInt64(tryDec)); + Assert.AreEqual ((ulong)1234, Convert.ToUInt64(tryDec), "#R05"); iTest++; - AssertEquals("#R06", (ulong)0, Convert.ToUInt64(tryDbl)); + Assert.AreEqual ((ulong)0, Convert.ToUInt64(tryDbl), "#R06"); iTest++; - AssertEquals("#R07", (ulong)1234, Convert.ToUInt64(tryInt16)); + Assert.AreEqual ((ulong)1234, Convert.ToUInt64(tryInt16), "#R07"); iTest++; - AssertEquals("#R08", (ulong)12345, Convert.ToUInt64(tryInt32)); + Assert.AreEqual ((ulong)12345, Convert.ToUInt64(tryInt32), "#R08"); iTest++; - AssertEquals("#R09", (ulong)123456789012, Convert.ToUInt64(tryInt64)); + Assert.AreEqual ((ulong)123456789012, Convert.ToUInt64(tryInt64), "#R09"); iTest++; - AssertEquals("#R10", (ulong)123, Convert.ToUInt64(trySByte)); + Assert.AreEqual ((ulong)123, Convert.ToUInt64(trySByte), "#R10"); iTest++; - AssertEquals("#R11", (ulong)1234, Convert.ToUInt64(tryFloat)); + Assert.AreEqual ((ulong)1234, Convert.ToUInt64(tryFloat), "#R11"); iTest++; - AssertEquals("#R12", (ulong)345678, Convert.ToUInt64("345678")); + Assert.AreEqual ((ulong)345678, Convert.ToUInt64("345678"), "#R12"); iTest++; - AssertEquals("#R13", (ulong)34567, Convert.ToUInt64(tryUI16)); + Assert.AreEqual ((ulong)34567, Convert.ToUInt64(tryUI16), "#R13"); iTest++; - AssertEquals("#R14", (ulong)567891234, Convert.ToUInt64(tryUI32)); + Assert.AreEqual ((ulong)567891234, Convert.ToUInt64(tryUI32), "#R14"); iTest++; - AssertEquals("#R15", (ulong)0, Convert.ToUInt64(tryUI64)); + Assert.AreEqual ((ulong)0, Convert.ToUInt64(tryUI64), "#R15"); iTest++; - AssertEquals("#R16", (ulong)123, Convert.ToUInt64("123", ci)); + Assert.AreEqual ((ulong)123, Convert.ToUInt64("123", ci), "#R16"); iTest++; - AssertEquals("#R17", (ulong)4, Convert.ToUInt64("100", 2)); + Assert.AreEqual ((ulong)4, Convert.ToUInt64("100", 2), "#R17"); iTest++; - AssertEquals("#R18", (ulong)64, Convert.ToUInt64("100", 8)); + Assert.AreEqual ((ulong)64, Convert.ToUInt64("100", 8), "#R18"); iTest++; - AssertEquals("#R19", (ulong)100, Convert.ToUInt64("100", 10)); + Assert.AreEqual ((ulong)100, Convert.ToUInt64("100", 10), "#R19"); iTest++; - AssertEquals("#R20", (ulong)256, Convert.ToUInt64("100", 16)); + Assert.AreEqual ((ulong)256, Convert.ToUInt64("100", 16), "#R20"); } catch (Exception e) { - Fail ("Unexpected exception caught when iTest = " + iTest + ": e = " + e); + Assert.Fail ("Unexpected exception caught when iTest = " + iTest + ": e = " + e); } try { Convert.ToUInt64(tryDT); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R25", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#R25"); } try { Convert.ToUInt64(decimal.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R26", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R26"); } try { Convert.ToUInt64((decimal)-140); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R27", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R27"); } try { Convert.ToUInt64(double.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R28", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R28"); } try { Convert.ToUInt64((double)-1); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R29", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R29"); } try { Convert.ToUInt64(short.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R30", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R30"); } try { Convert.ToUInt64(int.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R31", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R31"); } try { Convert.ToUInt64(long.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R32", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R32"); } try { Convert.ToUInt64(tryObj); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R33", typeof(InvalidCastException), e.GetType()); + Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#R33"); } try { Convert.ToUInt64(sbyte.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R34", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R34"); } try { Convert.ToUInt64(float.MinValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R35", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R35"); } try { Convert.ToUInt64(float.MaxValue); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R36", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R36"); } try { Convert.ToUInt64("234rt78"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R37", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#R37"); } try { Convert.ToUInt64("-68"); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R38", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R38"); } try { Convert.ToUInt64(decimal.MaxValue.ToString()); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R39", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R39"); } try { Convert.ToUInt64("23rd2", ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R40", typeof(FormatException), e.GetType()); + Assert.AreEqual (typeof(FormatException), e.GetType(), "#R40"); } try { Convert.ToUInt64(decimal.MinValue.ToString(), ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R41", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R41"); } try { Convert.ToUInt64(decimal.MaxValue.ToString(), ci); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R42", typeof(OverflowException), e.GetType()); + Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R42"); } try { Convert.ToUInt64("132", 9); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#R43", typeof(ArgumentException), e.GetType()); + Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#R43"); } - AssertEquals ("#L35", (ulong) 256, Convert.ToUInt64 ("0x100", 16)); - AssertEquals ("#L36", (ulong) 256, Convert.ToUInt64 ("0X100", 16)); - AssertEquals ("#L37", ulong.MaxValue, Convert.ToUInt64 ("0xFFFFFFFFFFFFFFFF", 16)); + Assert.AreEqual ((ulong) 256, Convert.ToUInt64 ("0x100", 16), "#L35"); + Assert.AreEqual ((ulong) 256, Convert.ToUInt64 ("0X100", 16), "#L36"); + Assert.AreEqual (ulong.MaxValue, Convert.ToUInt64 ("0xFFFFFFFFFFFFFFFF", 16), "#L37"); } [Test] @@ -2681,9 +2684,9 @@ namespace MonoTests.System { byte[] bb = new byte[] { 1, 2, 3}; string s = Convert.ToBase64String (bb); byte [] b2 = Convert.FromBase64String (" " + s); - Assertion.AssertEquals ("#01", 3, b2.Length); + Assert.AreEqual (3, b2.Length, "#01"); for (int i = 0; i < 3; i++) - Assertion.AssertEquals ("#0" + (i + 2), bb [i], b2 [i]); + Assert.AreEqual (bb [i], b2 [i], "#0" + (i + 2)); } public void TestToBase64CharArray () @@ -2696,7 +2699,7 @@ namespace MonoTests.System { Convert.ToBase64CharArray(byteArr, 0, byteArr.Length, result, 0); for (int i = 0; i < expectedCharArr.Length; i++) { - AssertEquals("#S0" + i, expectedCharArr[i], result[i]); + Assert.AreEqual (expectedCharArr[i], result[i], "#S0" + i); } } @@ -2789,39 +2792,39 @@ namespace MonoTests.System { result1 = Convert.ToBase64String(byteArr); result2 = Convert.ToBase64String(byteArr, 0, byteArr.Length); - AssertEquals("#T01", expectedStr, result1); - AssertEquals("#T02", expectedStr, result2); + Assert.AreEqual (expectedStr, result1, "#T01"); + Assert.AreEqual (expectedStr, result2, "#T02"); try { Convert.ToBase64String(null); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#T05", typeof(ArgumentNullException), e.GetType()); + Assert.AreEqual (typeof(ArgumentNullException), e.GetType(), "#T05"); } try { Convert.ToBase64String(byteArr, -1, byteArr.Length); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#T06", typeof(ArgumentOutOfRangeException), e.GetType()); + Assert.AreEqual (typeof(ArgumentOutOfRangeException), e.GetType(), "#T06"); } try { Convert.ToBase64String(byteArr, 0, -10); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#T07", typeof(ArgumentOutOfRangeException), e.GetType()); + Assert.AreEqual (typeof(ArgumentOutOfRangeException), e.GetType(), "#T07"); } try { Convert.ToBase64String(byteArr, 4, byteArr.Length); - Fail(); + Assert.Fail (); } catch (Exception e) { - AssertEquals("#T08", typeof(ArgumentOutOfRangeException), e.GetType()); + Assert.AreEqual (typeof(ArgumentOutOfRangeException), e.GetType(), "#T08"); } } #if NET_2_0 @@ -2830,7 +2833,54 @@ namespace MonoTests.System { { byte[] bs = Convert.FromBase64String ("ZuBZ7PESb3VRXgrl/KSRJd/hTGBvaEvEplqH3izPomDv5nBjS9MzcD1h8tOWzS7/wYGnaip8\nbhBfCrpWxivi8G7R08oBcADIiclpZeqRxai9kG4WoBUzJ6MCbxuvb1k757q+D9nqoL0p9Rer\n+5+vNodYkHYwqnKKyMBSQ11sspw=\n"); string s = Convert.ToBase64String (bs, Base64FormattingOptions.None); - Assert ("no new line", !s.Contains ("\n")); + Assert.IsTrue (!s.Contains ("\n"), "no new line"); + } + + static string ToBase64 (int len, Base64FormattingOptions options) + { + return Convert.ToBase64String (new byte [len], options); + } + + [Test] + public void Base64String_LineEnds_InsertLineBreaks () + { + string base64 = ToBase64 (0, Base64FormattingOptions.InsertLineBreaks); + Assert.IsFalse (base64.EndsWith (Environment.NewLine), "0-le"); + Assert.AreEqual (String.Empty, base64, "0"); + + base64 = ToBase64 (1, Base64FormattingOptions.InsertLineBreaks); + Assert.IsFalse (base64.EndsWith (Environment.NewLine), "1-le"); + Assert.AreEqual ("AA==", base64, "1"); + + base64 = ToBase64 (57, Base64FormattingOptions.InsertLineBreaks); + Assert.IsFalse (base64.Contains (Environment.NewLine), "57-nl"); // one lines + Assert.IsFalse (base64.EndsWith (Environment.NewLine), "57-le"); + Assert.AreEqual ("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", base64, "55"); + + base64 = ToBase64 (58, Base64FormattingOptions.InsertLineBreaks); + Assert.IsTrue (base64.Contains (Environment.NewLine), "58-nl"); // two lines + Assert.IsTrue (base64.EndsWith ("AA=="), "58-le"); // no NewLine + } + + [Test] + public void Base64String_LineEnds_None () + { + string base64 = ToBase64 (0, Base64FormattingOptions.None); + Assert.IsFalse (base64.EndsWith (Environment.NewLine), "0-le"); + Assert.AreEqual (String.Empty, base64, "0"); + + base64 = ToBase64 (1, Base64FormattingOptions.None); + Assert.IsFalse (base64.EndsWith (Environment.NewLine), "1-le"); + Assert.AreEqual ("AA==", base64, "1"); + + base64 = ToBase64 (57, Base64FormattingOptions.None); + Assert.IsFalse (base64.Contains (Environment.NewLine), "57-nl"); // one lines + Assert.IsFalse (base64.EndsWith (Environment.NewLine), "57-le"); + Assert.AreEqual ("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", base64, "55"); + + base64 = ToBase64 (58, Base64FormattingOptions.None); + Assert.IsFalse (base64.Contains (Environment.NewLine), "58-nl"); // one lines + Assert.IsTrue (base64.EndsWith ("AA=="), "58-le"); // no NewLine } #endif /* Have experienced some problems with FromBase64CharArray using mono. Something @@ -2848,6 +2898,7 @@ namespace MonoTests.System { [Test] [ExpectedException (typeof (FormatException))] + [Category ("TargetJvmNotWorking")] public void FromBase64CharArray_Empty () { Convert.FromBase64CharArray (new char[0], 0, 0); @@ -2855,6 +2906,7 @@ namespace MonoTests.System { [Test] [ExpectedException (typeof (FormatException))] + [Category ("TargetJvmNotWorking")] public void FormatBase64CharArray_OnlyWhitespace () { Convert.FromBase64CharArray (new char[3] {' ', @@ -2906,7 +2958,7 @@ namespace MonoTests.System { byte[] fromCharArr = Convert.FromBase64CharArray(charArr, 0, 8); for (int i = 0; i < fromCharArr.Length; i++){ - AssertEquals("#U0" + i, expectedByteArr[i], fromCharArr[i]); + Assert.AreEqual (expectedByteArr[i], fromCharArr[i], "#U0" + i); } } @@ -2941,7 +2993,7 @@ namespace MonoTests.System { public void FromBase64String_InvalidLengthBecauseOfIgnoredChars () { byte[] result = Convert.FromBase64String ("AAAA\t"); - AssertEquals ("InvalidLengthBecauseOfIgnoredChars", 3, result.Length); + Assert.AreEqual (3, result.Length, "InvalidLengthBecauseOfIgnoredChars"); } private const string ignored = "\t\r\n "; @@ -2952,11 +3004,11 @@ namespace MonoTests.System { { string s = ignored + base64data; byte[] data = Convert.FromBase64String (s); - AssertEquals ("String-IgnoreCharsBefore-Ignored", 15, data.Length); + Assert.AreEqual (15, data.Length, "String-IgnoreCharsBefore-Ignored"); char[] c = s.ToCharArray (); data = Convert.FromBase64CharArray (c, 0, c.Length); - AssertEquals ("CharArray-IgnoreCharsBefore-Ignored", 15, data.Length); + Assert.AreEqual (15, data.Length, "CharArray-IgnoreCharsBefore-Ignored"); } [Test] @@ -2964,11 +3016,11 @@ namespace MonoTests.System { { string s = base64data + ignored + base64data; byte[] data = Convert.FromBase64String (s); - AssertEquals ("String-IgnoreCharsInside-Ignored", 30, data.Length); + Assert.AreEqual (30, data.Length, "String-IgnoreCharsInside-Ignored"); char[] c = s.ToCharArray (); data = Convert.FromBase64CharArray (c, 0, c.Length); - AssertEquals ("CharArray-IgnoreCharsInside-Ignored", 30, data.Length); + Assert.AreEqual (30, data.Length, "CharArray-IgnoreCharsInside-Ignored"); } [Test] @@ -2976,17 +3028,18 @@ namespace MonoTests.System { { string s = base64data + ignored; byte[] data = Convert.FromBase64String (s); - AssertEquals ("String-IgnoreCharsAfter-Ignored", 15, data.Length); + Assert.AreEqual (15, data.Length, "String-IgnoreCharsAfter-Ignored"); char[] c = s.ToCharArray (); data = Convert.FromBase64CharArray (c, 0, c.Length); - AssertEquals ("CharArray-IgnoreCharsAfter-Ignored", 15, data.Length); + Assert.AreEqual (15, data.Length, "CharArray-IgnoreCharsAfter-Ignored"); } [Test] + [Category ("TargetJvmNotWorking")] public void FromBase64_Empty () { - AssertEquals (new byte[0], Convert.FromBase64String (string.Empty)); + Assert.AreEqual (new byte[0], Convert.FromBase64String (string.Empty)); } [Test] @@ -2996,7 +3049,7 @@ namespace MonoTests.System { public void FromBase64_OnlyWhiteSpace () { #if NET_2_0 - AssertEquals (new byte[0], Convert.FromBase64String (" \r\t")); + Assert.AreEqual (new byte[0], Convert.FromBase64String (" \r\t")); #else Convert.FromBase64String (" \r\t"); #endif @@ -3021,71 +3074,85 @@ namespace MonoTests.System { { string base64 = "\n fdy6S2NLpnT4fMdokUHSHsmpcvo= "; byte [] bytes = Convert.FromBase64String (base64); - AssertEquals ("#01", 20, bytes.Length); + Assert.AreEqual (20, bytes.Length, "#01"); byte [] target = new byte [] { 0x7D, 0xDC, 0xBA, 0x4B, 0x63, 0x4B, 0xA6, 0x74, 0xF8, 0x7C, 0xC7, 0x68, 0x91, 0x41, 0xD2, 0x1E, 0xC9, 0xA9, 0x72, 0xFA }; for (int i = 0; i < 20; i++) { if (bytes [i] != target [i]) - Fail ("Item #" + i); + Assert.Fail ("Item #" + i); } } public void TestConvertFromNull() { - AssertEquals ("#W1", false, Convert.ToBoolean (null as object)); - AssertEquals ("#W2", 0, Convert.ToByte (null as object)); - AssertEquals ("#W3", 0, Convert.ToChar (null as object)); - AssertEquals ("#W4", new DateTime (1,1,1,0,0,0), Convert.ToDateTime (null as object)); - AssertEquals ("#W5", 0, Convert.ToDecimal (null as object)); - AssertEquals ("#W6", 0, Convert.ToDouble (null as object)); - AssertEquals ("#W7", 0, Convert.ToInt16 (null as object)); - AssertEquals ("#W8", 0, Convert.ToInt32 (null as object)); - AssertEquals ("#W9", 0, Convert.ToInt64 (null as object)); - AssertEquals ("#W10", 0, Convert.ToSByte (null as object)); - AssertEquals ("#W11", 0, Convert.ToSingle (null as object)); - AssertEquals ("#W12", "", Convert.ToString (null as object)); - AssertEquals ("#W13", 0, Convert.ToUInt16 (null as object)); - AssertEquals ("#W14", 0, Convert.ToUInt32 (null as object)); - AssertEquals ("#W15", 0, Convert.ToUInt64 (null as object)); - AssertEquals ("#W16", false, Convert.ToBoolean (null as string)); - AssertEquals ("#W17", 0, Convert.ToByte (null as string)); + Assert.AreEqual (false, Convert.ToBoolean (null as object), "#W1"); + Assert.AreEqual (0, Convert.ToByte (null as object), "#W2"); + Assert.AreEqual (0, Convert.ToChar (null as object), "#W3"); + Assert.AreEqual (new DateTime (1, 1, 1, 0, 0, 0), Convert.ToDateTime (null as object), "#W4"); + Assert.AreEqual (0, Convert.ToDecimal (null as object), "#W5"); + Assert.AreEqual (0, Convert.ToDouble (null as object), "#W6"); + Assert.AreEqual (0, Convert.ToInt16 (null as object), "#W7"); + Assert.AreEqual (0, Convert.ToInt32 (null as object), "#W8"); + Assert.AreEqual (0, Convert.ToInt64 (null as object), "#W9"); + Assert.AreEqual (0, Convert.ToSByte (null as object), "#W10"); + Assert.AreEqual (0, Convert.ToSingle (null as object), "#W11"); + Assert.AreEqual ("", Convert.ToString (null as object), "#W12"); + Assert.AreEqual (0, Convert.ToUInt16 (null as object), "#W13"); + Assert.AreEqual (0, Convert.ToUInt32 (null as object), "#W14"); + Assert.AreEqual (0, Convert.ToUInt64 (null as object), "#W15"); + Assert.AreEqual (false, Convert.ToBoolean (null as string), "#W16"); + Assert.AreEqual (0, Convert.ToByte (null as string), "#W17"); try { Convert.ToChar (null as string); - Fail (); + Assert.Fail (); } catch (Exception e) { - AssertEquals ("#W18", typeof (ArgumentNullException), e.GetType ()); + Assert.AreEqual (typeof (ArgumentNullException), e.GetType (), "#W18"); } - AssertEquals ("#W19", new DateTime (1,1,1,0,0,0), Convert.ToDateTime (null as string)); - AssertEquals ("#W20", 0, Convert.ToDecimal (null as string)); - AssertEquals ("#W21", 0, Convert.ToDouble (null as string)); - AssertEquals ("#W22", 0, Convert.ToInt16 (null as string)); - AssertEquals ("#W23", 0, Convert.ToInt32 (null as string)); - AssertEquals ("#W24", 0, Convert.ToInt64 (null as string)); - AssertEquals ("#W25", 0, Convert.ToSByte (null as string)); - AssertEquals ("#W26", 0, Convert.ToSingle (null as string)); - AssertEquals ("#W27", null, Convert.ToString (null as string)); - AssertEquals ("#W28", 0, Convert.ToUInt16 (null as string)); - AssertEquals ("#W29", 0, Convert.ToUInt32 (null as string)); - AssertEquals ("#W30", 0, Convert.ToUInt64 (null as string)); + Assert.AreEqual (new DateTime (1, 1, 1, 0, 0, 0), Convert.ToDateTime (null as string), "#W19"); + Assert.AreEqual (0, Convert.ToDecimal (null as string), "#W20"); + Assert.AreEqual (0, Convert.ToDouble (null as string), "#W21"); + Assert.AreEqual (0, Convert.ToInt16 (null as string), "#W22"); + Assert.AreEqual (0, Convert.ToInt32 (null as string), "#W23"); + Assert.AreEqual (0, Convert.ToInt64 (null as string), "#W24"); + Assert.AreEqual (0, Convert.ToSByte (null as string), "#W25"); + Assert.AreEqual (0, Convert.ToSingle (null as string), "#W26"); + Assert.AreEqual (null, Convert.ToString (null as string), "#W27"); + Assert.AreEqual (0, Convert.ToUInt16 (null as string), "#W28"); + Assert.AreEqual (0, Convert.ToUInt32 (null as string), "#W29"); + Assert.AreEqual (0, Convert.ToUInt64 (null as string), "#W30"); + } + + [Test] + [ExpectedException (typeof (FormatException))] + public void FromBase64StringInvalidFormat () + { + Convert.FromBase64String ("Tgtm+DBN===="); + } + + [Test] + [ExpectedException (typeof (FormatException))] + public void FromBase64StringInvalidFormat2 () + { + Convert.FromBase64String ("Tgtm+DBN========"); } [Test] public void ToByte_PrefixedHexStringInBase16 () { - AssertEquals ("0xff", 255, Convert.ToByte ("0xff", 16)); - AssertEquals ("0xfF", 255, Convert.ToByte ("0xfF", 16)); - AssertEquals ("0xFf", 255, Convert.ToByte ("0xFf", 16)); - AssertEquals ("0xFF", 255, Convert.ToByte ("0xFF", 16)); + Assert.AreEqual (255, Convert.ToByte ("0xff", 16), "0xff"); + Assert.AreEqual (255, Convert.ToByte ("0xfF", 16), "0xfF"); + Assert.AreEqual (255, Convert.ToByte ("0xFf", 16), "0xFf"); + Assert.AreEqual (255, Convert.ToByte ("0xFF", 16), "0xFF"); - AssertEquals ("0Xff", 255, Convert.ToByte ("0Xff", 16)); - AssertEquals ("0XfF", 255, Convert.ToByte ("0XfF", 16)); - AssertEquals ("0XFf", 255, Convert.ToByte ("0XFf", 16)); - AssertEquals ("0XFF", 255, Convert.ToByte ("0XFF", 16)); + Assert.AreEqual (255, Convert.ToByte ("0Xff", 16), "0Xff"); + Assert.AreEqual (255, Convert.ToByte ("0XfF", 16), "0XfF"); + Assert.AreEqual (255, Convert.ToByte ("0XFf", 16), "0XFf"); + Assert.AreEqual (255, Convert.ToByte ("0XFF", 16), "0XFF"); - AssertEquals ("0x0", Byte.MinValue, Convert.ToByte ("0x0", 16)); + Assert.AreEqual (Byte.MinValue, Convert.ToByte ("0x0", 16), "0x0"); } [Test] @@ -3205,81 +3272,81 @@ namespace MonoTests.System { [Test] public void ToByte_MaxValue () { - AssertEquals ("ff,16", Byte.MaxValue, Convert.ToByte ("ff", 16)); - AssertEquals ("0xFF,16", Byte.MaxValue, Convert.ToByte ("0XFF", 16)); - AssertEquals ("255,10", Byte.MaxValue, Convert.ToByte ("255", 10)); - AssertEquals ("377,8", Byte.MaxValue, Convert.ToByte ("377", 8)); - AssertEquals ("11111111,2", Byte.MaxValue, Convert.ToByte ("11111111", 2)); + Assert.AreEqual (Byte.MaxValue, Convert.ToByte ("ff", 16), "ff,16"); + Assert.AreEqual (Byte.MaxValue, Convert.ToByte ("0XFF", 16), "0xFF,16"); + Assert.AreEqual (Byte.MaxValue, Convert.ToByte ("255", 10), "255,10"); + Assert.AreEqual (Byte.MaxValue, Convert.ToByte ("377", 8), "377,8"); + Assert.AreEqual (Byte.MaxValue, Convert.ToByte ("11111111", 2), "11111111,2"); } [Test] public void ToByte_MinValue () { - AssertEquals ("0,16", Byte.MinValue, Convert.ToByte ("0", 16)); - AssertEquals ("0x0,16", Byte.MinValue, Convert.ToByte ("0x0", 16)); - AssertEquals ("0,10", Byte.MinValue, Convert.ToByte ("0", 10)); - AssertEquals ("0,8", Byte.MinValue, Convert.ToByte ("0", 8)); - AssertEquals ("0,2", Byte.MinValue, Convert.ToByte ("0", 2)); + Assert.AreEqual (Byte.MinValue, Convert.ToByte ("0", 16), "0,16"); + Assert.AreEqual (Byte.MinValue, Convert.ToByte ("0x0", 16), "0x0,16"); + Assert.AreEqual (Byte.MinValue, Convert.ToByte ("0", 10), "0,10"); + Assert.AreEqual (Byte.MinValue, Convert.ToByte ("0", 8), "0,8"); + Assert.AreEqual (Byte.MinValue, Convert.ToByte ("0", 2), "0,2"); } [Test] public void ToUInt16_MaxValue () { - AssertEquals ("ffff,16", UInt16.MaxValue, Convert.ToUInt16 ("ffff", 16)); - AssertEquals ("0XFFFF,16", UInt16.MaxValue, Convert.ToUInt16 ("0XFFFF", 16)); - AssertEquals ("65535,10", UInt16.MaxValue, Convert.ToUInt16 ("65535", 10)); - AssertEquals ("177777,8", UInt16.MaxValue, Convert.ToUInt16 ("177777", 8)); - AssertEquals ("1111111111111111,2", UInt16.MaxValue, Convert.ToUInt16 ("1111111111111111", 2)); + Assert.AreEqual (UInt16.MaxValue, Convert.ToUInt16 ("ffff", 16), "ffff,16"); + Assert.AreEqual (UInt16.MaxValue, Convert.ToUInt16 ("0XFFFF", 16), "0XFFFF,16"); + Assert.AreEqual (UInt16.MaxValue, Convert.ToUInt16 ("65535", 10), "65535,10"); + Assert.AreEqual (UInt16.MaxValue, Convert.ToUInt16 ("177777", 8), "177777,8"); + Assert.AreEqual (UInt16.MaxValue, Convert.ToUInt16 ("1111111111111111", 2), "1111111111111111,2"); } [Test] public void ToUInt16_MinValue () { - AssertEquals ("0,16", UInt16.MinValue, Convert.ToUInt16 ("0", 16)); - AssertEquals ("0x0,16", UInt16.MinValue, Convert.ToUInt16 ("0x0", 16)); - AssertEquals ("0,10", UInt16.MinValue, Convert.ToUInt16 ("0", 10)); - AssertEquals ("0,8", UInt16.MinValue, Convert.ToUInt16 ("0", 8)); - AssertEquals ("0,2", UInt16.MinValue, Convert.ToUInt16 ("0", 2)); + Assert.AreEqual (UInt16.MinValue, Convert.ToUInt16 ("0", 16), "0,16"); + Assert.AreEqual (UInt16.MinValue, Convert.ToUInt16 ("0x0", 16), "0x0,16"); + Assert.AreEqual (UInt16.MinValue, Convert.ToUInt16 ("0", 10), "0,10"); + Assert.AreEqual (UInt16.MinValue, Convert.ToUInt16 ("0", 8), "0,8"); + Assert.AreEqual (UInt16.MinValue, Convert.ToUInt16 ("0", 2), "0,2"); } [Test] public void ToUInt32_MaxValue () { - AssertEquals ("ffffffff,16", UInt32.MaxValue, Convert.ToUInt32 ("ffffffff", 16)); - AssertEquals ("0XFFFFFFFF,16", UInt32.MaxValue, Convert.ToUInt32 ("0XFFFFFFFF", 16)); - AssertEquals ("4294967295,10", UInt32.MaxValue, Convert.ToUInt32 ("4294967295", 10)); - AssertEquals ("37777777777,8", UInt32.MaxValue, Convert.ToUInt32 ("37777777777", 8)); - AssertEquals ("11111111111111111111111111111111,2", UInt32.MaxValue, Convert.ToUInt32 ("11111111111111111111111111111111", 2)); + Assert.AreEqual (UInt32.MaxValue, Convert.ToUInt32 ("ffffffff", 16), "ffffffff,16"); + Assert.AreEqual (UInt32.MaxValue, Convert.ToUInt32 ("0XFFFFFFFF", 16), "0XFFFFFFFF,16"); + Assert.AreEqual (UInt32.MaxValue, Convert.ToUInt32 ("4294967295", 10), "4294967295,10"); + Assert.AreEqual (UInt32.MaxValue, Convert.ToUInt32 ("37777777777", 8), "37777777777,8"); + Assert.AreEqual (UInt32.MaxValue, Convert.ToUInt32 ("11111111111111111111111111111111", 2), "11111111111111111111111111111111,2"); } [Test] public void ToUInt32_MinValue () { - AssertEquals ("0,16", UInt32.MinValue, Convert.ToUInt32 ("0", 16)); - AssertEquals ("0x0,16", UInt32.MinValue, Convert.ToUInt32 ("0x0", 16)); - AssertEquals ("0,10", UInt32.MinValue, Convert.ToUInt32 ("0", 10)); - AssertEquals ("0,8", UInt32.MinValue, Convert.ToUInt32 ("0", 8)); - AssertEquals ("0,2", UInt32.MinValue, Convert.ToUInt32 ("0", 2)); + Assert.AreEqual (UInt32.MinValue, Convert.ToUInt32 ("0", 16), "0,16"); + Assert.AreEqual (UInt32.MinValue, Convert.ToUInt32 ("0x0", 16), "0x0,16"); + Assert.AreEqual (UInt32.MinValue, Convert.ToUInt32 ("0", 10), "0,10"); + Assert.AreEqual (UInt32.MinValue, Convert.ToUInt32 ("0", 8), "0,8"); + Assert.AreEqual (UInt32.MinValue, Convert.ToUInt32 ("0", 2), "0,2"); } [Test] public void ToUInt64_MaxValue () { - AssertEquals ("ffffffffffffffff,16", UInt64.MaxValue, Convert.ToUInt64 ("ffffffffffffffff", 16)); - AssertEquals ("0XFFFFFFFFFFFFFFFF,16", UInt64.MaxValue, Convert.ToUInt64 ("0XFFFFFFFFFFFFFFFF", 16)); - AssertEquals ("18446744073709551615,10", UInt64.MaxValue, Convert.ToUInt64 ("18446744073709551615", 10)); - AssertEquals ("1777777777777777777777,8", UInt64.MaxValue, Convert.ToUInt64 ("1777777777777777777777", 8)); - AssertEquals ("1111111111111111111111111111111111111111111111111111111111111111,2", UInt64.MaxValue, Convert.ToUInt64 ("1111111111111111111111111111111111111111111111111111111111111111", 2)); + Assert.AreEqual (UInt64.MaxValue, Convert.ToUInt64 ("ffffffffffffffff", 16), "ffffffffffffffff,16"); + Assert.AreEqual (UInt64.MaxValue, Convert.ToUInt64 ("0XFFFFFFFFFFFFFFFF", 16), "0XFFFFFFFFFFFFFFFF,16"); + Assert.AreEqual (UInt64.MaxValue, Convert.ToUInt64 ("18446744073709551615", 10), "18446744073709551615,10"); + Assert.AreEqual (UInt64.MaxValue, Convert.ToUInt64 ("1777777777777777777777", 8), "1777777777777777777777,8"); + Assert.AreEqual (UInt64.MaxValue, Convert.ToUInt64 ("1111111111111111111111111111111111111111111111111111111111111111", 2), "1111111111111111111111111111111111111111111111111111111111111111,2"); } [Test] public void ToUInt64_MinValue () { - AssertEquals ("0,16", UInt64.MinValue, Convert.ToUInt64 ("0", 16)); - AssertEquals ("0x0,16", UInt64.MinValue, Convert.ToUInt64 ("0x0", 16)); - AssertEquals ("0,10", UInt64.MinValue, Convert.ToUInt64 ("0", 10)); - AssertEquals ("0,8", UInt64.MinValue, Convert.ToUInt64 ("0", 8)); - AssertEquals ("0,2", UInt64.MinValue, Convert.ToUInt64 ("0", 2)); + Assert.AreEqual (UInt64.MinValue, Convert.ToUInt64 ("0", 16), "0,16"); + Assert.AreEqual (UInt64.MinValue, Convert.ToUInt64 ("0x0", 16), "0x0,16"); + Assert.AreEqual (UInt64.MinValue, Convert.ToUInt64 ("0", 10), "0,10"); + Assert.AreEqual (UInt64.MinValue, Convert.ToUInt64 ("0", 8), "0,8"); + Assert.AreEqual (UInt64.MinValue, Convert.ToUInt64 ("0", 2), "0,2"); } // min/max signed @@ -3287,78 +3354,78 @@ namespace MonoTests.System { [Test] public void ToSByte_MaxValue () { - AssertEquals ("7F,16", SByte.MaxValue, Convert.ToSByte ("7f", 16)); - AssertEquals ("0X7F,16", SByte.MaxValue, Convert.ToSByte ("0X7F", 16)); - AssertEquals ("127,10", SByte.MaxValue, Convert.ToSByte ("127", 10)); - AssertEquals ("177,8", SByte.MaxValue, Convert.ToSByte ("177", 8)); - AssertEquals ("1111111,2", SByte.MaxValue, Convert.ToSByte ("1111111", 2)); + Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("7f", 16), "7F,16"); + Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("0X7F", 16), "0X7F,16"); + Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("127", 10), "127,10"); + Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("177", 8), "177,8"); + Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("1111111", 2), "1111111,2"); } [Test] public void ToSByte_MinValue () { - AssertEquals ("80,16", SByte.MinValue, Convert.ToSByte ("80", 16)); - AssertEquals ("-128,10", SByte.MinValue, Convert.ToSByte ("-128", 10)); - AssertEquals ("200,8", SByte.MinValue, Convert.ToSByte ("200", 8)); - AssertEquals ("10000000,2", SByte.MinValue, Convert.ToSByte ("10000000", 2)); + Assert.AreEqual (SByte.MinValue, Convert.ToSByte ("80", 16), "80,16"); + Assert.AreEqual (SByte.MinValue, Convert.ToSByte ("-128", 10), "-128,10"); + Assert.AreEqual (SByte.MinValue, Convert.ToSByte ("200", 8), "200,8"); + Assert.AreEqual (SByte.MinValue, Convert.ToSByte ("10000000", 2), "10000000,2"); } [Test] public void ToInt16_MaxValue () { - AssertEquals ("7FFF,16", Int16.MaxValue, Convert.ToInt16 ("7fff", 16)); - AssertEquals ("0X7FFF,16", Int16.MaxValue, Convert.ToInt16 ("0X7FFF", 16)); - AssertEquals ("32767,10", Int16.MaxValue, Convert.ToInt16 ("32767", 10)); - AssertEquals ("77777,8", Int16.MaxValue, Convert.ToInt16 ("77777", 8)); - AssertEquals ("111111111111111,2", Int16.MaxValue, Convert.ToInt16 ("111111111111111", 2)); + Assert.AreEqual (Int16.MaxValue, Convert.ToInt16 ("7fff", 16), "7FFF,16"); + Assert.AreEqual (Int16.MaxValue, Convert.ToInt16 ("0X7FFF", 16), "0X7FFF,16"); + Assert.AreEqual (Int16.MaxValue, Convert.ToInt16 ("32767", 10), "32767,10"); + Assert.AreEqual (Int16.MaxValue, Convert.ToInt16 ("77777", 8), "77777,8"); + Assert.AreEqual (Int16.MaxValue, Convert.ToInt16 ("111111111111111", 2), "111111111111111,2"); } [Test] public void ToInt16_MinValue () { - AssertEquals ("8000,16", Int16.MinValue, Convert.ToInt16 ("8000", 16)); - AssertEquals ("-32768,10", Int16.MinValue, Convert.ToInt16 ("-32768", 10)); - AssertEquals ("100000,8", Int16.MinValue, Convert.ToInt16 ("100000", 8)); - AssertEquals ("1000000000000000,2", Int16.MinValue, Convert.ToInt16 ("1000000000000000", 2)); + Assert.AreEqual (Int16.MinValue, Convert.ToInt16 ("8000", 16), "8000,16"); + Assert.AreEqual (Int16.MinValue, Convert.ToInt16 ("-32768", 10), "-32768,10"); + Assert.AreEqual (Int16.MinValue, Convert.ToInt16 ("100000", 8), "100000,8"); + Assert.AreEqual (Int16.MinValue, Convert.ToInt16 ("1000000000000000", 2), "1000000000000000,2"); } [Test] public void ToInt32_MaxValue () { - AssertEquals ("7fffffff,16", Int32.MaxValue, Convert.ToInt32 ("7fffffff", 16)); - AssertEquals ("0X7FFFFFFF,16", Int32.MaxValue, Convert.ToInt32 ("0X7FFFFFFF", 16)); - AssertEquals ("2147483647,10", Int32.MaxValue, Convert.ToInt32 ("2147483647", 10)); - AssertEquals ("17777777777,8", Int32.MaxValue, Convert.ToInt32 ("17777777777", 8)); - AssertEquals ("1111111111111111111111111111111,2", Int32.MaxValue, Convert.ToInt32 ("1111111111111111111111111111111", 2)); + Assert.AreEqual (Int32.MaxValue, Convert.ToInt32 ("7fffffff", 16), "7fffffff,16"); + Assert.AreEqual (Int32.MaxValue, Convert.ToInt32 ("0X7FFFFFFF", 16), "0X7FFFFFFF,16"); + Assert.AreEqual (Int32.MaxValue, Convert.ToInt32 ("2147483647", 10), "2147483647,10"); + Assert.AreEqual (Int32.MaxValue, Convert.ToInt32 ("17777777777", 8), "17777777777,8"); + Assert.AreEqual (Int32.MaxValue, Convert.ToInt32 ("1111111111111111111111111111111", 2), "1111111111111111111111111111111,2"); } [Test] public void ToInt32_MinValue () { - AssertEquals ("80000000,16", Int32.MinValue, Convert.ToInt32 ("80000000", 16)); - AssertEquals ("-2147483648,10", Int32.MinValue, Convert.ToInt32 ("-2147483648", 10)); - AssertEquals ("20000000000,8", Int32.MinValue, Convert.ToInt32 ("20000000000", 8)); - AssertEquals ("10000000000000000000000000000000,2", Int32.MinValue, Convert.ToInt32 ("10000000000000000000000000000000", 2)); + Assert.AreEqual (Int32.MinValue, Convert.ToInt32 ("80000000", 16), "80000000,16"); + Assert.AreEqual (Int32.MinValue, Convert.ToInt32 ("-2147483648", 10), "-2147483648,10"); + Assert.AreEqual (Int32.MinValue, Convert.ToInt32 ("20000000000", 8), "20000000000,8"); + Assert.AreEqual (Int32.MinValue, Convert.ToInt32 ("10000000000000000000000000000000", 2), "10000000000000000000000000000000,2"); } [Test] public void ToInt64_MaxValue () { - AssertEquals ("7fffffffffffffff,16", Int64.MaxValue, Convert.ToInt64 ("7fffffffffffffff", 16)); - AssertEquals ("0X7FFFFFFFFFFFFFFF,16", Int64.MaxValue, Convert.ToInt64 ("0X7FFFFFFFFFFFFFFF", 16)); - AssertEquals ("9223372036854775807,10", Int64.MaxValue, Convert.ToInt64 ("9223372036854775807", 10)); - AssertEquals ("777777777777777777777,8", Int64.MaxValue, Convert.ToInt64 ("777777777777777777777", 8)); - AssertEquals ("111111111111111111111111111111111111111111111111111111111111111,2", Int64.MaxValue, Convert.ToInt64 ("111111111111111111111111111111111111111111111111111111111111111", 2)); + Assert.AreEqual (Int64.MaxValue, Convert.ToInt64 ("7fffffffffffffff", 16), "7fffffffffffffff,16"); + Assert.AreEqual (Int64.MaxValue, Convert.ToInt64 ("0X7FFFFFFFFFFFFFFF", 16), "0X7FFFFFFFFFFFFFFF,16"); + Assert.AreEqual (Int64.MaxValue, Convert.ToInt64 ("9223372036854775807", 10), "9223372036854775807,10"); + Assert.AreEqual (Int64.MaxValue, Convert.ToInt64 ("777777777777777777777", 8), "777777777777777777777,8"); + Assert.AreEqual (Int64.MaxValue, Convert.ToInt64 ("111111111111111111111111111111111111111111111111111111111111111", 2), "111111111111111111111111111111111111111111111111111111111111111,2"); } [Test] public void ToInt64_MinValue () { - AssertEquals ("8000000000000000,16", Int64.MinValue, Convert.ToInt64 ("8000000000000000", 16)); - AssertEquals ("0x8000000000000000,16", Int64.MinValue, Convert.ToInt64 ("0x8000000000000000", 16)); - AssertEquals ("-9223372036854775808,10", Int64.MinValue, Convert.ToInt64 ("-9223372036854775808", 10)); - AssertEquals ("1000000000000000000000,8", Int64.MinValue, Convert.ToInt64 ("1000000000000000000000", 8)); - AssertEquals ("1000000000000000000000000000000000000000000000000000000000000000,2", Int64.MinValue, Convert.ToInt64 ("1000000000000000000000000000000000000000000000000000000000000000", 2)); + Assert.AreEqual (Int64.MinValue, Convert.ToInt64 ("8000000000000000", 16), "8000000000000000,16"); + Assert.AreEqual (Int64.MinValue, Convert.ToInt64 ("0x8000000000000000", 16), "0x8000000000000000,16"); + Assert.AreEqual (Int64.MinValue, Convert.ToInt64 ("-9223372036854775808", 10), "-9223372036854775808,10"); + Assert.AreEqual (Int64.MinValue, Convert.ToInt64 ("1000000000000000000000", 8), "1000000000000000000000,8"); + Assert.AreEqual (Int64.MinValue, Convert.ToInt64 ("1000000000000000000000000000000000000000000000000000000000000000", 2), "1000000000000000000000000000000000000000000000000000000000000000,2"); } // signed types @@ -3498,23 +3565,23 @@ namespace MonoTests.System { { string s = null; // signed - AssertEquals ("ToSByte", 0, Convert.ToSByte (s)); - AssertEquals ("ToSByte+base", 0, Convert.ToSByte (s, 10)); - AssertEquals ("ToInt16", 0, Convert.ToInt16 (s)); - AssertEquals ("ToInt16+base", 0, Convert.ToInt16 (s, 10)); - AssertEquals ("ToInt32", 0, Convert.ToInt32 (s)); - AssertEquals ("ToInt32+base", 0, Convert.ToInt32 (s, 10)); - AssertEquals ("ToInt64", 0, Convert.ToInt64 (s)); - AssertEquals ("ToInt64+base", 0, Convert.ToInt64 (s, 10)); + Assert.AreEqual (0, Convert.ToSByte (s), "ToSByte"); + Assert.AreEqual (0, Convert.ToSByte (s, 10), "ToSByte+base"); + Assert.AreEqual (0, Convert.ToInt16 (s), "ToInt16"); + Assert.AreEqual (0, Convert.ToInt16 (s, 10), "ToInt16+base"); + Assert.AreEqual (0, Convert.ToInt32 (s), "ToInt32"); + Assert.AreEqual (0, Convert.ToInt32 (s, 10), "ToInt32+base"); + Assert.AreEqual (0, Convert.ToInt64 (s), "ToInt64"); + Assert.AreEqual (0, Convert.ToInt64 (s, 10), "ToInt64+base"); // unsigned - AssertEquals ("ToByte", 0, Convert.ToByte (s)); - AssertEquals ("ToByte+base", 0, Convert.ToByte (s, 10)); - AssertEquals ("ToUInt16", 0, Convert.ToUInt16 (s)); - AssertEquals ("ToUInt16+base", 0, Convert.ToUInt16 (s, 10)); - AssertEquals ("ToUInt32", 0, Convert.ToUInt32 (s)); - AssertEquals ("ToUInt32+base", 0, Convert.ToUInt32 (s, 10)); - AssertEquals ("ToUInt64", 0, Convert.ToUInt64 (s)); - AssertEquals ("ToUInt64+base", 0, Convert.ToUInt64 (s, 10)); + Assert.AreEqual (0, Convert.ToByte (s), "ToByte"); + Assert.AreEqual (0, Convert.ToByte (s, 10), "ToByte+base"); + Assert.AreEqual (0, Convert.ToUInt16 (s), "ToUInt16"); + Assert.AreEqual (0, Convert.ToUInt16 (s, 10), "ToUInt16+base"); + Assert.AreEqual (0, Convert.ToUInt32 (s), "ToUInt32"); + Assert.AreEqual (0, Convert.ToUInt32 (s, 10), "ToUInt32+base"); + Assert.AreEqual (0, Convert.ToUInt64 (s), "ToUInt64"); + Assert.AreEqual (0, Convert.ToUInt64 (s, 10), "ToUInt64+base"); } [Test] @@ -3522,15 +3589,15 @@ namespace MonoTests.System { { object o = null; // signed - AssertEquals ("ToSByte", 0, Convert.ToSByte (o)); - AssertEquals ("ToInt16", 0, Convert.ToInt16 (o)); - AssertEquals ("ToInt32", 0, Convert.ToInt32 (o)); - AssertEquals ("ToInt64", 0, Convert.ToInt64 (o)); + Assert.AreEqual (0, Convert.ToSByte (o), "ToSByte"); + Assert.AreEqual (0, Convert.ToInt16 (o), "ToInt16"); + Assert.AreEqual (0, Convert.ToInt32 (o), "ToInt32"); + Assert.AreEqual (0, Convert.ToInt64 (o), "ToInt64"); // unsigned - AssertEquals ("ToByte", 0, Convert.ToByte (o)); - AssertEquals ("ToUInt16", 0, Convert.ToUInt16 (o)); - AssertEquals ("ToUInt32", 0, Convert.ToUInt32 (o)); - AssertEquals ("ToUInt64", 0, Convert.ToUInt64 (o)); + Assert.AreEqual (0, Convert.ToByte (o), "ToByte"); + Assert.AreEqual (0, Convert.ToUInt16 (o), "ToUInt16"); + Assert.AreEqual (0, Convert.ToUInt32 (o), "ToUInt32"); + Assert.AreEqual (0, Convert.ToUInt64 (o), "ToUInt64"); } [Test] @@ -3539,15 +3606,15 @@ namespace MonoTests.System { object o = null; IFormatProvider fp = (IFormatProvider) new NumberFormatInfo (); // signed - AssertEquals ("ToSByte", 0, Convert.ToSByte (o, fp)); - AssertEquals ("ToInt16", 0, Convert.ToInt16 (o, fp)); - AssertEquals ("ToInt32", 0, Convert.ToInt32 (o, fp)); - AssertEquals ("ToInt64", 0, Convert.ToInt64 (o, fp)); + Assert.AreEqual (0, Convert.ToSByte (o, fp), "ToSByte"); + Assert.AreEqual (0, Convert.ToInt16 (o, fp), "ToInt16"); + Assert.AreEqual (0, Convert.ToInt32 (o, fp), "ToInt32"); + Assert.AreEqual (0, Convert.ToInt64 (o, fp), "ToInt64"); // unsigned - AssertEquals ("ToByte", 0, Convert.ToByte (o, fp)); - AssertEquals ("ToUInt16", 0, Convert.ToUInt16 (o, fp)); - AssertEquals ("ToUInt32", 0, Convert.ToUInt32 (o, fp)); - AssertEquals ("ToUInt64", 0, Convert.ToUInt64 (o, fp)); + Assert.AreEqual (0, Convert.ToByte (o, fp), "ToByte"); + Assert.AreEqual (0, Convert.ToUInt16 (o, fp), "ToUInt16"); + Assert.AreEqual (0, Convert.ToUInt32 (o, fp), "ToUInt32"); + Assert.AreEqual (0, Convert.ToUInt64 (o, fp), "ToUInt64"); } [Test] @@ -3566,14 +3633,14 @@ namespace MonoTests.System { IFormatProvider fp = (IFormatProvider) new NumberFormatInfo (); // signed // No SByte here - AssertEquals ("ToInt16", 0, Convert.ToInt16 (s, fp)); - AssertEquals ("ToInt32", 0, Convert.ToInt32 (s, fp)); - AssertEquals ("ToInt64", 0, Convert.ToInt64 (s, fp)); + Assert.AreEqual (0, Convert.ToInt16 (s, fp), "ToInt16"); + Assert.AreEqual (0, Convert.ToInt32 (s, fp), "ToInt32"); + Assert.AreEqual (0, Convert.ToInt64 (s, fp), "ToInt64"); // unsigned - AssertEquals ("ToByte", 0, Convert.ToByte (s, fp)); - AssertEquals ("ToUInt16", 0, Convert.ToUInt16 (s, fp)); - AssertEquals ("ToUInt32", 0, Convert.ToUInt32 (s, fp)); - AssertEquals ("ToUInt64", 0, Convert.ToUInt64 (s, fp)); + Assert.AreEqual (0, Convert.ToByte (s, fp), "ToByte"); + Assert.AreEqual (0, Convert.ToUInt16 (s, fp), "ToUInt16"); + Assert.AreEqual (0, Convert.ToUInt32 (s, fp), "ToUInt32"); + Assert.AreEqual (0, Convert.ToUInt64 (s, fp), "ToUInt64"); } [Test] @@ -3583,6 +3650,24 @@ namespace MonoTests.System { Convert.ChangeType (true, TypeCode.Empty); } + [Test] + [ExpectedException (typeof (ArgumentNullException))] + public void CharChangeTypeNullNull () + { + char a = 'a'; + IConvertible convert = a; + convert.ToType (null, null); + } + + [Test] + [ExpectedException (typeof (ArgumentNullException))] + public void StringChangeTypeNullNull () + { + string a = "a"; + IConvertible convert = a; + convert.ToType (null, null); + } + [Test] // 2005/01/10: The docs say this should throw an InvalidCastException, // however, MS.NET 1.1 throws a NullReferenceException. Assuming docs @@ -3600,45 +3685,45 @@ namespace MonoTests.System { [Test] public void ToString_MinMax_WithBase () { - AssertEquals ("Byte.MinValue base 2", "0", Convert.ToString (Byte.MinValue, 2)); - AssertEquals ("Byte.MinValue base 8", "0", Convert.ToString (Byte.MinValue, 8)); - AssertEquals ("Byte.MinValue base 10", "0", Convert.ToString (Byte.MinValue, 10)); - AssertEquals ("Byte.MinValue base 16", "0", Convert.ToString (Byte.MinValue, 16)); + Assert.AreEqual ("0", Convert.ToString (Byte.MinValue, 2), "Byte.MinValue base 2"); + Assert.AreEqual ("0", Convert.ToString (Byte.MinValue, 8), "Byte.MinValue base 8"); + Assert.AreEqual ("0", Convert.ToString (Byte.MinValue, 10), "Byte.MinValue base 10"); + Assert.AreEqual ("0", Convert.ToString (Byte.MinValue, 16), "Byte.MinValue base 16"); - AssertEquals ("Byte.MaxValue base 2", "11111111", Convert.ToString (Byte.MaxValue, 2)); - AssertEquals ("Byte.MaxValue base 8", "377", Convert.ToString (Byte.MaxValue, 8)); - AssertEquals ("Byte.MaxValue base 10", "255", Convert.ToString (Byte.MaxValue, 10)); - AssertEquals ("Byte.MaxValue base 16", "ff", Convert.ToString (Byte.MaxValue, 16)); + Assert.AreEqual ("11111111", Convert.ToString (Byte.MaxValue, 2), "Byte.MaxValue base 2"); + Assert.AreEqual ("377", Convert.ToString (Byte.MaxValue, 8), "Byte.MaxValue base 8"); + Assert.AreEqual ("255", Convert.ToString (Byte.MaxValue, 10), "Byte.MaxValue base 10"); + Assert.AreEqual ("ff", Convert.ToString (Byte.MaxValue, 16), "Byte.MaxValue base 16"); - AssertEquals ("Int16.MinValue base 2", "1000000000000000", Convert.ToString (Int16.MinValue, 2)); - AssertEquals ("Int16.MinValue base 8", "100000", Convert.ToString (Int16.MinValue, 8)); - AssertEquals ("Int16.MinValue base 10", "-32768", Convert.ToString (Int16.MinValue, 10)); - AssertEquals ("Int16.MinValue base 16", "8000", Convert.ToString (Int16.MinValue, 16)); + Assert.AreEqual ("1000000000000000", Convert.ToString (Int16.MinValue, 2), "Int16.MinValue base 2"); + Assert.AreEqual ("100000", Convert.ToString (Int16.MinValue, 8), "Int16.MinValue base 8"); + Assert.AreEqual ("-32768", Convert.ToString (Int16.MinValue, 10), "Int16.MinValue base 10"); + Assert.AreEqual ("8000", Convert.ToString (Int16.MinValue, 16), "Int16.MinValue base 16"); - AssertEquals ("Int16.MaxValue base 2", "111111111111111", Convert.ToString (Int16.MaxValue, 2)); - AssertEquals ("Int16.MaxValue base 8", "77777", Convert.ToString (Int16.MaxValue, 8)); - AssertEquals ("Int16.MaxValue base 10", "32767", Convert.ToString (Int16.MaxValue, 10)); - AssertEquals ("Int16.MaxValue base 16", "7fff", Convert.ToString (Int16.MaxValue, 16)); + Assert.AreEqual ("111111111111111", Convert.ToString (Int16.MaxValue, 2), "Int16.MaxValue base 2"); + Assert.AreEqual ("77777", Convert.ToString (Int16.MaxValue, 8), "Int16.MaxValue base 8"); + Assert.AreEqual ("32767", Convert.ToString (Int16.MaxValue, 10), "Int16.MaxValue base 10"); + Assert.AreEqual ("7fff", Convert.ToString (Int16.MaxValue, 16), "Int16.MaxValue base 16"); - AssertEquals ("Int32.MinValue base 2", "10000000000000000000000000000000", Convert.ToString (Int32.MinValue, 2)); - AssertEquals ("Int32.MinValue base 8", "20000000000", Convert.ToString (Int32.MinValue, 8)); - AssertEquals ("Int32.MinValue base 10", "-2147483648", Convert.ToString (Int32.MinValue, 10)); - AssertEquals ("Int32.MinValue base 16", "80000000", Convert.ToString (Int32.MinValue, 16)); + Assert.AreEqual ("10000000000000000000000000000000", Convert.ToString (Int32.MinValue, 2), "Int32.MinValue base 2"); + Assert.AreEqual ("20000000000", Convert.ToString (Int32.MinValue, 8), "Int32.MinValue base 8"); + Assert.AreEqual ("-2147483648", Convert.ToString (Int32.MinValue, 10), "Int32.MinValue base 10"); + Assert.AreEqual ("80000000", Convert.ToString (Int32.MinValue, 16), "Int32.MinValue base 16"); - AssertEquals ("Int32.MaxValue base 2", "1111111111111111111111111111111", Convert.ToString (Int32.MaxValue, 2)); - AssertEquals ("Int32.MaxValue base 8", "17777777777", Convert.ToString (Int32.MaxValue, 8)); - AssertEquals ("Int32.MaxValue base 10", "2147483647", Convert.ToString (Int32.MaxValue, 10)); - AssertEquals ("Int32.MaxValue base 16", "7fffffff", Convert.ToString (Int32.MaxValue, 16)); + Assert.AreEqual ("1111111111111111111111111111111", Convert.ToString (Int32.MaxValue, 2), "Int32.MaxValue base 2"); + Assert.AreEqual ("17777777777", Convert.ToString (Int32.MaxValue, 8), "Int32.MaxValue base 8"); + Assert.AreEqual ("2147483647", Convert.ToString (Int32.MaxValue, 10), "Int32.MaxValue base 10"); + Assert.AreEqual ("7fffffff", Convert.ToString (Int32.MaxValue, 16), "Int32.MaxValue base 16"); - AssertEquals ("Int64.MinValue base 2", "1000000000000000000000000000000000000000000000000000000000000000", Convert.ToString (Int64.MinValue, 2)); - AssertEquals ("Int64.MinValue base 8", "1000000000000000000000", Convert.ToString (Int64.MinValue, 8)); - AssertEquals ("Int64.MinValue base 10", "-9223372036854775808", Convert.ToString (Int64.MinValue, 10)); - AssertEquals ("Int64.MinValue base 16", "8000000000000000", Convert.ToString (Int64.MinValue, 16)); + Assert.AreEqual ("1000000000000000000000000000000000000000000000000000000000000000", Convert.ToString (Int64.MinValue, 2), "Int64.MinValue base 2"); + Assert.AreEqual ("1000000000000000000000", Convert.ToString (Int64.MinValue, 8), "Int64.MinValue base 8"); + Assert.AreEqual ("-9223372036854775808", Convert.ToString (Int64.MinValue, 10), "Int64.MinValue base 10"); + Assert.AreEqual ("8000000000000000", Convert.ToString (Int64.MinValue, 16), "Int64.MinValue base 16"); - AssertEquals ("Int64.MaxValue base 2", "111111111111111111111111111111111111111111111111111111111111111", Convert.ToString (Int64.MaxValue, 2)); - AssertEquals ("Int64.MaxValue base 8", "777777777777777777777", Convert.ToString (Int64.MaxValue, 8)); - AssertEquals ("Int64.MaxValue base 10", "9223372036854775807", Convert.ToString (Int64.MaxValue, 10)); - AssertEquals ("Int64.MaxValue base 16", "7fffffffffffffff", Convert.ToString (Int64.MaxValue, 16)); + Assert.AreEqual ("111111111111111111111111111111111111111111111111111111111111111", Convert.ToString (Int64.MaxValue, 2), "Int64.MaxValue base 2"); + Assert.AreEqual ("777777777777777777777", Convert.ToString (Int64.MaxValue, 8), "Int64.MaxValue base 8"); + Assert.AreEqual ("9223372036854775807", Convert.ToString (Int64.MaxValue, 10), "Int64.MaxValue base 10"); + Assert.AreEqual ("7fffffffffffffff", Convert.ToString (Int64.MaxValue, 16), "Int64.MaxValue base 16"); } [Test] @@ -3812,40 +3897,40 @@ namespace MonoTests.System { [Test] public void ToSByte_Base16_MinMax () { - AssertEquals ("80,16", SByte.MinValue, Convert.ToSByte ("80", 16)); - AssertEquals ("0x80,16", SByte.MinValue, Convert.ToSByte ("0x80", 16)); - AssertEquals ("0X80,16", SByte.MinValue, Convert.ToSByte ("0X80", 16)); + Assert.AreEqual (SByte.MinValue, Convert.ToSByte ("80", 16), "80,16"); + Assert.AreEqual (SByte.MinValue, Convert.ToSByte ("0x80", 16), "0x80,16"); + Assert.AreEqual (SByte.MinValue, Convert.ToSByte ("0X80", 16), "0X80,16"); - AssertEquals ("7f,16", SByte.MaxValue, Convert.ToSByte ("7f", 16)); - AssertEquals ("7F,16", SByte.MaxValue, Convert.ToSByte ("7F", 16)); - AssertEquals ("0x7f,16", SByte.MaxValue, Convert.ToSByte ("0x7f", 16)); - AssertEquals ("0X7F,16", SByte.MaxValue, Convert.ToSByte ("0X7F", 16)); + Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("7f", 16), "7f,16"); + Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("7F", 16), "7F,16"); + Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("0x7f", 16), "0x7f,16"); + Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("0X7F", 16), "0X7F,16"); } [Test] public void ToInt16_Base16_MinMax () { - AssertEquals ("8000,16", short.MinValue, Convert.ToInt16 ("8000", 16)); - AssertEquals ("0x8000,16", short.MinValue, Convert.ToInt16 ("0x8000", 16)); - AssertEquals ("0X8000,16", short.MinValue, Convert.ToInt16 ("0X8000", 16)); + Assert.AreEqual (short.MinValue, Convert.ToInt16 ("8000", 16), "8000,16"); + Assert.AreEqual (short.MinValue, Convert.ToInt16 ("0x8000", 16), "0x8000,16"); + Assert.AreEqual (short.MinValue, Convert.ToInt16 ("0X8000", 16), "0X8000,16"); - AssertEquals ("7fff,16", short.MaxValue, Convert.ToInt16 ("7fff", 16)); - AssertEquals ("7FFF,16", short.MaxValue, Convert.ToInt16 ("7FFF", 16)); - AssertEquals ("0x7fff,16", short.MaxValue, Convert.ToInt16 ("0x7fff", 16)); - AssertEquals ("0X7FFF,16", short.MaxValue, Convert.ToInt16 ("0X7FFF", 16)); + Assert.AreEqual (short.MaxValue, Convert.ToInt16 ("7fff", 16), "7fff,16"); + Assert.AreEqual (short.MaxValue, Convert.ToInt16 ("7FFF", 16), "7FFF,16"); + Assert.AreEqual (short.MaxValue, Convert.ToInt16 ("0x7fff", 16), "0x7fff,16"); + Assert.AreEqual (short.MaxValue, Convert.ToInt16 ("0X7FFF", 16), "0X7FFF,16"); } [Test] public void ToInt32_Base16_MinMax () { - AssertEquals ("80000000,16", int.MinValue, Convert.ToInt32 ("80000000", 16)); - AssertEquals ("0x80000000,16", int.MinValue, Convert.ToInt32 ("0x80000000", 16)); - AssertEquals ("0X80000000,16", int.MinValue, Convert.ToInt32 ("0X80000000", 16)); + Assert.AreEqual (int.MinValue, Convert.ToInt32 ("80000000", 16), "80000000,16"); + Assert.AreEqual (int.MinValue, Convert.ToInt32 ("0x80000000", 16), "0x80000000,16"); + Assert.AreEqual (int.MinValue, Convert.ToInt32 ("0X80000000", 16), "0X80000000,16"); - AssertEquals ("7fffffff,16", int.MaxValue, Convert.ToInt32 ("7fffffff", 16)); - AssertEquals ("7FFFFFFF,16", int.MaxValue, Convert.ToInt32 ("7FFFFFFF", 16)); - AssertEquals ("0x7fffffff,16", int.MaxValue, Convert.ToInt32 ("0x7fffffff", 16)); - AssertEquals ("0X7FFFFFFF,16", int.MaxValue, Convert.ToInt32 ("0X7FFFFFFF", 16)); + Assert.AreEqual (int.MaxValue, Convert.ToInt32 ("7fffffff", 16), "7fffffff,16"); + Assert.AreEqual (int.MaxValue, Convert.ToInt32 ("7FFFFFFF", 16), "7FFFFFFF,16"); + Assert.AreEqual (int.MaxValue, Convert.ToInt32 ("0x7fffffff", 16), "0x7fffffff,16"); + Assert.AreEqual (int.MaxValue, Convert.ToInt32 ("0X7FFFFFFF", 16), "0X7FFFFFFF,16"); } [Test] @@ -4575,5 +4660,165 @@ namespace MonoTests.System { { Convert.ToUInt64 ("-", 16); } + + [Test] // bug #481687 + public void ChangeType_Value_IConvertible () + { + BitmapStatus bitmapStatus = new BitmapStatus (3); + Image c1 = Convert.ChangeType (bitmapStatus, typeof (Image)) as Image; + Assert.IsNotNull (c1, "#A1"); + Assert.AreEqual (32, c1.ColorDepth, "#A2"); + + bitmapStatus.ConvertToImage = false; + object c2 = Convert.ChangeType (bitmapStatus, typeof (Image)); + Assert.IsNull (c2, "#B"); + + object c3 = Convert.ChangeType (bitmapStatus, typeof (int)); + Assert.IsNotNull (c3, "#C1"); + Assert.AreEqual (3, c3, "#C2"); + } + + // This is a simple and happy struct. + struct Foo { + } + + [Test] + [ExpectedException (typeof (InvalidCastException))] + public void ChangeType_ShouldThrowOnString () + { + Convert.ChangeType ("this-is-a-string", typeof (Foo)); + } + + [Test] + [ExpectedException (typeof (OverflowException))] + public void ToInt32_NaN () + { + Convert.ToInt32 (Double.NaN); + } + } + + public class Image + { + private int colorDepth; + + public Image () + { + colorDepth = 8; + } + + public Image (int colorDepth) + { + this.colorDepth = colorDepth; + } + + public int ColorDepth { + get { return colorDepth; } + } + } + + public class BitmapStatus : IConvertible + { + protected int m_Status; + private bool convertToImage; + + public BitmapStatus (int status) + { + m_Status = status; + convertToImage = true; + } + + public bool ConvertToImage { + get { return convertToImage; } + set { convertToImage = value; } + } + + TypeCode IConvertible.GetTypeCode () + { + return TypeCode.Int32; + } + + bool IConvertible.ToBoolean (IFormatProvider provider) + { + return (bool)((IConvertible)this).ToType (typeof (bool), provider); + } + + byte IConvertible.ToByte (IFormatProvider provider) + { + return (byte)((IConvertible)this).ToType (typeof (byte), provider); + } + + char IConvertible.ToChar (IFormatProvider provider) + { + return (char)((IConvertible)this).ToType (typeof (char), provider); + } + + DateTime IConvertible.ToDateTime (IFormatProvider provider) + { + return (DateTime)((IConvertible)this).ToType (typeof (DateTime), provider); + } + + decimal IConvertible.ToDecimal (IFormatProvider provider) + { + return (decimal)((IConvertible)this).ToType (typeof (decimal), provider); + } + + double IConvertible.ToDouble (IFormatProvider provider) + { + return (double)((IConvertible)this).ToType (typeof (double), provider); + } + + short IConvertible.ToInt16 (IFormatProvider provider) + { + return (short)((IConvertible)this).ToType (typeof (short), provider); + } + + int IConvertible.ToInt32 (IFormatProvider provider) + { + return (int)m_Status; + } + + long IConvertible.ToInt64 (IFormatProvider provider) + { + return (long)((IConvertible)this).ToType (typeof (long), provider); + } + + sbyte IConvertible.ToSByte (IFormatProvider provider) + { + return (sbyte)((IConvertible)this).ToType (typeof (sbyte), provider); + } + + float IConvertible.ToSingle (IFormatProvider provider) + { + return (float)((IConvertible)this).ToType (typeof (float), provider); + } + + string IConvertible.ToString (IFormatProvider provider) + { + return (string)((IConvertible)this).ToType (typeof (string), provider); + } + + object IConvertible.ToType (Type conversionType, IFormatProvider provider) + { + if (ConvertToImage && conversionType == typeof (Image)) + return new Image (32); + else if (conversionType.IsAssignableFrom (typeof (int))) + return Convert.ChangeType (1, conversionType, provider); + return null; + } + + ushort IConvertible.ToUInt16 (IFormatProvider provider) + { + return (ushort)((IConvertible)this).ToType (typeof (ushort), provider); + } + + uint IConvertible.ToUInt32 (IFormatProvider provider) + { + return (uint)((IConvertible)this).ToType (typeof (uint), provider); + } + + ulong IConvertible.ToUInt64 (IFormatProvider provider) + { + return (ulong)((IConvertible)this).ToType (typeof (ulong), provider); + } } }