--- /dev/null
+// Testsuite.System.AllSystemTests.cs
+//
+// Mario Martinez (mariom925@home.om)
+//
+// (C) Ximian, Inc. http://www.ximian.com
+//
+
+using System;
+using NUnit.Framework;
+
+namespace Testsuite.System {
+ /// <summary>
+ /// Combines all available unit tests into one test suite.
+ /// </summary>
+ public class AllSystemTests : TestCase {
+ public AllSystemTests(string name) : base(name) {}
+
+ public static ITest Suite
+ {
+ get
+ {
+ TestSuite suite = new TestSuite();
+ suite.AddTest(ByteTest.Suite);
+ suite.AddTest(SByteTest.Suite);
+ suite.AddTest(Int16Test.Suite);
+ suite.AddTest(Int32Test.Suite);
+ suite.AddTest(Int64Test.Suite);
+ suite.AddTest(UInt16Test.Suite);
+ suite.AddTest(UInt32Test.Suite);
+ suite.AddTest(UInt64Test.Suite);
+ return suite;
+ }
+ }
+ }
+}
+
--- /dev/null
+// ByteTest.cs - NUnit Test Cases for the System.Byte struct
+//
+// Mario Martinez (mariom925@home.om)
+//
+// (C) Ximian, Inc. http://www.ximian.com
+//
+
+using NUnit.Framework;
+using System;
+using System.Globalization;
+
+public class ByteTest : TestCase
+{
+ private const Byte MyByte1 = 42;
+ private const Byte MyByte2 = 0;
+ private const Byte MyByte3 = 255;
+ private const string MyString1 = "42";
+ private const string MyString2 = "0";
+ private const string MyString3 = "255";
+ private string[] Formats1 = {"c", "d", "e", "f", "g", "n", "p", "x" };
+ private string[] Formats2 = {"c5", "d5", "e5", "f5", "g5", "n5", "p5", "x5" };
+ private string[] Results1 = {"$0.00", "0", "0.000000e+000", "0.00",
+ "0", "0.00", "0.00 %", "0"};
+ private string[] Results2 = {"$255.00000", "00255", "2.55000e+002", "255.00000",
+ "255", "255.00000", "25,500.00000 %", "000ff"};
+ private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
+
+ public ByteTest(string name) : base(name) {}
+
+ protected override void SetUp()
+ {
+ }
+
+ public static ITest Suite {
+ get {
+ return new TestSuite(typeof(ByteTest));
+ }
+ }
+
+ public void TestMinMax()
+ {
+ AssertEquals(Byte.MinValue, MyByte2);
+ AssertEquals(Byte.MaxValue, MyByte3);
+ }
+
+ public void TestCompareTo()
+ {
+ Assert(MyByte3.CompareTo(MyByte2) > 0);
+ Assert(MyByte2.CompareTo(MyByte2) == 0);
+ Assert(MyByte1.CompareTo((Byte)42) == 0);
+ Assert(MyByte2.CompareTo(MyByte3) < 0);
+ try {
+ MyByte2.CompareTo(100);
+ Fail("Should raise a System.ArgumentException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.ArgumentException) == e.GetType());
+ }
+ }
+
+ public void TestEquals()
+ {
+ Assert(MyByte1.Equals(MyByte1));
+ Assert(MyByte1.Equals((Byte)42));
+ Assert(MyByte1.Equals((Int16)42) == false);
+ Assert(MyByte1.Equals(MyByte2) == false);
+ }
+
+ public void TestGetHashCode()
+ {
+ try {
+ MyByte1.GetHashCode();
+ MyByte2.GetHashCode();
+ MyByte3.GetHashCode();
+ }
+ catch {
+ Fail("GetHashCode should not raise an exception here");
+ }
+ }
+
+ public void TestParse()
+ {
+ //test Parse(string s)
+ Assert(MyByte1 == Byte.Parse(MyString1));
+ Assert(MyByte2 == Byte.Parse(MyString2));
+ Assert(MyByte3 == Byte.Parse(MyString3));
+ try {
+ Byte.Parse(null);
+ Fail("Should raise a System.ArgumentNullException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.ArgumentNullException) == e.GetType());
+ }
+ try {
+ Byte.Parse("not-a-number");
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ try {
+ int OverInt = Byte.MaxValue + 1;
+ Byte.Parse(OverInt.ToString());
+ Fail("Should raise a System.OverflowException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.OverflowException) == e.GetType());
+ }
+ //test Parse(string s, NumberStyles style)
+ Assert(42 == Byte.Parse(" $42 ", NumberStyles.Currency));
+ try {
+ Byte.Parse("$42", NumberStyles.Integer);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, IFormatProvider provider)
+ Assert(42 == Byte.Parse(" 42 ", Nfi));
+ try {
+ Byte.Parse("%42", Nfi);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, NumberStyles style, IFormatProvider provider)
+ Assert(16 == Byte.Parse(" 10 ", NumberStyles.HexNumber, Nfi));
+ try {
+ Byte.Parse("$42", NumberStyles.Integer, Nfi);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ }
+
+ public void TestToString()
+ {
+ //test ToString()
+ Assert(String.Compare(MyString1, MyByte1.ToString()) == 0);
+ Assert(String.Compare(MyString2, MyByte2.ToString()) == 0);
+ Assert(String.Compare(MyString3, MyByte3.ToString()) == 0);
+ //test ToString(string format)
+ for (int i=0; i < Formats1.Length; i++) {
+ Assert(String.Compare(Results1[i], MyByte2.ToString(Formats1[i])) == 0);
+ Assert(String.Compare(Results2[i], MyByte3.ToString(Formats2[i])) == 0);
+ }
+ //test ToString(string format, IFormatProvider provider);
+ for (int i=0; i < Formats1.Length; i++) {
+ Assert(String.Compare(Results1[i], MyByte2.ToString(Formats1[i], Nfi)) == 0);
+ Assert(String.Compare(Results2[i], MyByte3.ToString(Formats2[i], Nfi)) == 0);
+ }
+ try {
+ MyByte1.ToString("z");
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+
+ }
+}
+
--- /dev/null
+// Int16Test.cs - NUnit Test Cases for the System.Int16 struct
+//
+// Mario Martinez (mariom925@home.om)
+//
+// (C) Ximian, Inc. http://www.ximian.com
+//
+
+using NUnit.Framework;
+using System;
+using System.Globalization;
+
+public class Int16Test : TestCase
+{
+ private const Int16 MyInt16_1 = -42;
+ private const Int16 MyInt16_2 = -32768;
+ private const Int16 MyInt16_3 = 32767;
+ private const string MyString1 = "-42";
+ private const string MyString2 = "-32768";
+ private const string MyString3 = "32767";
+ private string[] Formats1 = {"c", "d", "e", "f", "g", "n", "p", "x" };
+ private string[] Formats2 = {"c5", "d5", "e5", "f5", "g5", "n5", "p5", "x5" };
+ private string[] Results1 = {"($32,768.00)", "-32768", "-3.276800e+004", "-32768.00",
+ "-32768", "-32,768.00", "-3,276,800.00 %", "8000"};
+ private string[] Results2 = {"$32,767.00000", "32767", "3.27670e+004", "32767.00000",
+ "32767", "32,767.00000", "3,276,700.00000 %", "07fff"};
+ private string[] ResultsNfi1 = {"($32,768.00)", "-32768", "-3.276800e+004", "-32768.00",
+ "-32768", "(32,768.00)", "-3,276,800.00 %", "8000"};
+ private string[] ResultsNfi2 = {"$32,767.00000", "32767", "3.27670e+004", "32767.00000",
+ "32767", "32,767.00000", "3,276,700.00000 %", "07fff"};
+ private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
+
+ public Int16Test(string name) : base(name) {}
+
+ protected override void SetUp()
+ {
+ }
+
+ public static ITest Suite {
+ get {
+ return new TestSuite(typeof(Int16Test));
+ }
+ }
+
+ public void TestMinMax()
+ {
+
+ AssertEquals(Int16.MinValue, MyInt16_2);
+ AssertEquals(Int16.MaxValue, MyInt16_3);
+ }
+
+ public void TestCompareTo()
+ {
+ Assert(MyInt16_3.CompareTo(MyInt16_2) > 0);
+ Assert(MyInt16_2.CompareTo(MyInt16_2) == 0);
+ Assert(MyInt16_1.CompareTo((Int16)(-42)) == 0);
+ Assert(MyInt16_2.CompareTo(MyInt16_3) < 0);
+ try {
+ MyInt16_2.CompareTo(100);
+ Fail("Should raise a System.ArgumentException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.ArgumentException) == e.GetType());
+ }
+ }
+
+ public void TestEquals()
+ {
+ Assert(MyInt16_1.Equals(MyInt16_1));
+ Assert(MyInt16_1.Equals((Int16)(-42)));
+ Assert(MyInt16_1.Equals((SByte)(-42)) == false);
+ Assert(MyInt16_1.Equals(MyInt16_2) == false);
+ }
+
+ public void TestGetHashCode()
+ {
+ try {
+ MyInt16_1.GetHashCode();
+ MyInt16_2.GetHashCode();
+ MyInt16_3.GetHashCode();
+ }
+ catch {
+ Fail("GetHashCode should not raise an exception here");
+ }
+ }
+
+ public void TestParse()
+ {
+ //test Parse(string s)
+ Assert(MyInt16_1 == Int16.Parse(MyString1));
+ Assert(MyInt16_2 == Int16.Parse(MyString2));
+ Assert(MyInt16_3 == Int16.Parse(MyString3));
+ try {
+ Int16.Parse(null);
+ Fail("Should raise a System.ArgumentNullException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.ArgumentNullException) == e.GetType());
+ }
+ try {
+ Int16.Parse("not-a-number");
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ try {
+ int OverInt = Int16.MaxValue + 1;
+ Int16.Parse(OverInt.ToString());
+ Fail("Should raise a System.OverflowException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.OverflowException) == e.GetType());
+ }
+ //test Parse(string s, NumberStyles style)
+ Assert(42 == Int16.Parse(" $42 ", NumberStyles.Currency));
+ try {
+ Int16.Parse("$42", NumberStyles.Integer);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, IFormatProvider provider)
+ Assert(-42 == Int16.Parse(" -42 ", Nfi));
+ try {
+ Int16.Parse("%42", Nfi);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, NumberStyles style, IFormatProvider provider)
+ Assert(16 == Int16.Parse(" 10 ", NumberStyles.HexNumber, Nfi));
+ try {
+ Int16.Parse("$42", NumberStyles.Integer, Nfi);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ }
+
+ public void TestToString()
+ {
+ //test ToString()
+ Assert(String.Compare(MyString1, MyInt16_1.ToString()) == 0);
+ Assert(String.Compare(MyString2, MyInt16_2.ToString()) == 0);
+ Assert(String.Compare(MyString3, MyInt16_3.ToString()) == 0);
+ //test ToString(string format)
+ for (int i=0; i < Formats1.Length; i++) {
+ Assert(String.Compare(Results1[i], MyInt16_2.ToString(Formats1[i])) == 0);
+ Assert(String.Compare(Results2[i], MyInt16_3.ToString(Formats2[i])) == 0);
+ }
+ //test ToString(string format, IFormatProvider provider);
+ for (int i=0; i < Formats1.Length; i++) {
+ Assert(String.Compare(ResultsNfi1[i], MyInt16_2.ToString(Formats1[i], Nfi)) == 0);
+ Assert(String.Compare(ResultsNfi2[i], MyInt16_3.ToString(Formats2[i], Nfi)) == 0);
+ }
+ try {
+ MyInt16_1.ToString("z");
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ }
+}
+
--- /dev/null
+// Int32Test.cs - NUnit Test Cases for the System.Int32 struct
+//
+// Mario Martinez (mariom925@home.om)
+//
+// (C) Ximian, Inc. http://www.ximian.com
+//
+
+using NUnit.Framework;
+using System;
+using System.Globalization;
+
+public class Int32Test : TestCase
+{
+ private const Int32 MyInt32_1 = -42;
+ private const Int32 MyInt32_2 = -2147483648;
+ private const Int32 MyInt32_3 = 2147483647;
+ private const string MyString1 = "-42";
+ private const string MyString2 = "-2147483648";
+ private const string MyString3 = "2147483647";
+ private string[] Formats1 = {"c", "d", "e", "f", "g", "n", "p", "x" };
+ private string[] Formats2 = {"c5", "d5", "e5", "f5", "g5", "n5", "p5", "x5" };
+ private string[] Results1 = {"($2,147,483,648.00)", "-2147483648", "-2.147484e+009", "-2147483648.00",
+ "-2147483648", "-2,147,483,648.00", "-214,748,364,800.00 %", "80000000"};
+ private string[] Results2 = {"$2,147,483,647.00000", "2147483647", "2.14748e+009", "2147483647.00000",
+ "2.1475e+09", "2,147,483,647.00000", "214,748,364,700.00000 %", "7fffffff"};
+ private string[] ResultsNfi1 = {"($2,147,483,648.00)", "-2147483648", "-2.147484e+009", "-2147483648.00",
+ "-2147483648", "(2,147,483,648.00)", "-214,748,364,800.00 %", "80000000"};
+ private string[] ResultsNfi2 = {"$2,147,483,647.00000", "2147483647", "2.14748e+009", "2147483647.00000",
+ "2.1475e+09", "2,147,483,647.00000", "214,748,364,700.00000 %", "7fffffff"};
+ private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
+
+ public Int32Test(string name) : base(name) {}
+
+ protected override void SetUp()
+ {
+ }
+
+ public static ITest Suite {
+ get {
+ return new TestSuite(typeof(Int32Test));
+ }
+ }
+
+ public void TestMinMax()
+ {
+
+ AssertEquals(Int32.MinValue, MyInt32_2);
+ AssertEquals(Int32.MaxValue, MyInt32_3);
+ }
+
+ public void TestCompareTo()
+ {
+ Assert(MyInt32_3.CompareTo(MyInt32_2) > 0);
+ Assert(MyInt32_2.CompareTo(MyInt32_2) == 0);
+ Assert(MyInt32_1.CompareTo((Int32)(-42)) == 0);
+ Assert(MyInt32_2.CompareTo(MyInt32_3) < 0);
+ try {
+ MyInt32_2.CompareTo((Int16)100);
+ Fail("Should raise a System.ArgumentException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.ArgumentException) == e.GetType());
+ }
+ }
+
+ public void TestEquals()
+ {
+ Assert(MyInt32_1.Equals(MyInt32_1));
+ Assert(MyInt32_1.Equals((Int32)(-42)));
+ Assert(MyInt32_1.Equals((SByte)(-42)) == false);
+ Assert(MyInt32_1.Equals(MyInt32_2) == false);
+ }
+
+ public void TestGetHashCode()
+ {
+ try {
+ MyInt32_1.GetHashCode();
+ MyInt32_2.GetHashCode();
+ MyInt32_3.GetHashCode();
+ }
+ catch {
+ Fail("GetHashCode should not raise an exception here");
+ }
+ }
+
+ public void TestParse()
+ {
+ //test Parse(string s)
+ Assert(MyInt32_1 == Int32.Parse(MyString1));
+ Assert(MyInt32_2 == Int32.Parse(MyString2));
+ Assert(MyInt32_3 == Int32.Parse(MyString3));
+ try {
+ Int32.Parse(null);
+ Fail("Should raise a System.ArgumentNullException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.ArgumentNullException) == e.GetType());
+ }
+ try {
+ Int32.Parse("not-a-number");
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ try {
+ double OverInt = (double)Int32.MaxValue + 1;
+ Int32.Parse(OverInt.ToString());
+ Fail("Should raise a System.OverflowException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.OverflowException) == e.GetType());
+ }
+ //test Parse(string s, NumberStyles style)
+ Assert(42 == Int32.Parse(" $42 ", NumberStyles.Currency));
+ try {
+ Int32.Parse("$42", NumberStyles.Integer);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, IFormatProvider provider)
+ Assert(-42 == Int32.Parse(" -42 ", Nfi));
+ try {
+ Int32.Parse("%42", Nfi);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, NumberStyles style, IFormatProvider provider)
+ Assert(16 == Int32.Parse(" 10 ", NumberStyles.HexNumber, Nfi));
+ try {
+ Int32.Parse("$42", NumberStyles.Integer, Nfi);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ }
+
+ public void TestToString()
+ {
+ //test ToString()
+ Assert(String.Compare(MyString1, MyInt32_1.ToString()) == 0);
+ Assert(String.Compare(MyString2, MyInt32_2.ToString()) == 0);
+ Assert(String.Compare(MyString3, MyInt32_3.ToString()) == 0);
+ //test ToString(string format)
+ for (int i=0; i < Formats1.Length; i++) {
+ Assert(String.Compare(Results1[i], MyInt32_2.ToString(Formats1[i])) == 0);
+ Assert(String.Compare(Results2[i], MyInt32_3.ToString(Formats2[i])) == 0);
+ }
+ //test ToString(string format, IFormatProvider provider);
+ for (int i=0; i < Formats1.Length; i++) {
+ Assert(String.Compare(ResultsNfi1[i], MyInt32_2.ToString(Formats1[i], Nfi)) == 0);
+ Assert(String.Compare(ResultsNfi2[i], MyInt32_3.ToString(Formats2[i], Nfi)) == 0);
+ }
+ try {
+ MyInt32_1.ToString("z");
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ }
+}
+
-// Int64Test.cs - NUnit Test Cases for the System.Int64 struct\r
-//\r
-// Author: Martin Weindel (martin.weindel@t-online.de)\r
-//\r
-// (C) Martin Weindel, 2001\r
-// \r
-// tests ToString and Parse function with the culture independent \r
-// NumberFormatInfo.InvariantInfo\r
-\r
-using NUnit.Framework;\r
-using System;\r
-using System.Globalization;\r
-\r
- /// <summary>\r
- /// Tests for System.Int64\r
- /// </summary>\r
-public class Int64Test : TestCase\r
-{\r
- private static long[] vals\r
- = { 0, Int64.MaxValue, Int64.MinValue,\r
- 1L, 12L, 123L, 1234L, -123L, \r
- 1234567890123456L, 6543210987654321L };\r
- private const long val1 = -1234567L;\r
- private const long val2 = 1234567L;\r
- private const string sval1Test1 = " -1,234,567 ";\r
- private const string sval1Test2 = " -1234567 ";\r
- //private const string sval1Test3 = " -12345,,,,67 "; // interesting: this case works on SDK Beta2, but the specification says nothing about this case\r
- private const string sval1Test4 = " -12345 67 ";\r
- private const string sval1Test5 = " -$1,234567.00 ";\r
- private const string sval1Test6 = "($1,234,567.00)";\r
- private const string sval1Test7 = "(1,234,567.00)";\r
- private const string sval1UserCur1 = "1234_5_67,000 XYZ-";\r
- private const string sval2UserCur1 = "1234_5_67,000 XYZ";\r
- private const string sval1UserPercent1 = "-%%%1~2~3~4~5~6~7~0~0;0";\r
- private const string sval2UserPercent1 = "%%%1~2~3~4~5~6~7~0~0;0";\r
- private const NumberStyles style1 = NumberStyles.AllowLeadingWhite | NumberStyles.AllowLeadingSign\r
- | NumberStyles.AllowTrailingWhite | NumberStyles.AllowThousands;\r
- private NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;\r
- private NumberFormatInfo nfiUser;\r
-\r
- public Int64Test(string name) : base(name) {}\r
-\r
- public static ITest Suite \r
- {\r
- get { return new TestSuite(typeof(Int64Test)); }\r
- }\r
-\r
- protected override void SetUp() \r
- {\r
- nfiUser = new NumberFormatInfo();\r
- nfiUser.CurrencyDecimalDigits = 3;\r
- nfiUser.CurrencyDecimalSeparator = ",";\r
- nfiUser.CurrencyGroupSeparator = "_";\r
- nfiUser.CurrencyGroupSizes = new int[] { 2,1,0 };\r
- nfiUser.CurrencyNegativePattern = 10;\r
- nfiUser.CurrencyPositivePattern = 3;\r
- nfiUser.CurrencySymbol = "XYZ";\r
- nfiUser.PercentDecimalDigits = 1;\r
- nfiUser.PercentDecimalSeparator = ";";\r
- nfiUser.PercentGroupSeparator = "~";\r
- nfiUser.PercentGroupSizes = new int[] {1};\r
- nfiUser.PercentNegativePattern = 2;\r
- nfiUser.PercentPositivePattern = 2;\r
- nfiUser.PercentSymbol = "%%%";\r
- }\r
-\r
- public void TestRoundTripGeneral() \r
- {\r
- foreach(long lv in vals) \r
- {\r
- string s = lv.ToString(nfi);\r
- long lv2 = Int64.Parse(s);\r
- Assert(lv == lv2);\r
- long lv3 = Int64.Parse(s, NumberStyles.Integer, nfi);\r
- Assert(lv == lv3);\r
- }\r
- }\r
-\r
- public void TestRoundTripHex() \r
- {\r
- foreach(long lv in vals) \r
- {\r
- string s = lv.ToString("x", nfi);\r
- long lv2 = Int64.Parse(s, NumberStyles.HexNumber, nfi);\r
- Assert(lv == lv2);\r
- }\r
- }\r
-\r
- public void TestParseNull()\r
- {\r
- try \r
- {\r
- Int64.Parse(null);\r
- Fail("Should raise System.ArgumentNullException"); \r
- } \r
- catch (ArgumentNullException) \r
- {\r
- // ok\r
- }\r
- }\r
-\r
- public void TestParse()\r
- {\r
- long lv;\r
-\r
- lv = Int64.Parse(sval1Test1, style1, nfi);\r
- Assert(lv == val1);\r
-\r
- try\r
- {\r
- lv = Int64.Parse(sval1Test1, nfi);\r
- Fail("Should raise System.FormatException 1");\r
- }\r
- catch (System.FormatException)\r
- {\r
- // ok\r
- }\r
-\r
- lv = Int64.Parse(sval1Test2, style1, nfi);\r
- Assert(lv == val1);\r
- lv = Int64.Parse(sval1Test2, nfi);\r
- Assert(lv == val1);\r
-\r
- try\r
- {\r
- lv = Int64.Parse(sval1Test4, style1, nfi);\r
- Fail("Should raise System.FormatException 3");\r
- }\r
- catch (System.FormatException)\r
- {\r
- // ok\r
- }\r
-\r
- lv = Int64.Parse(sval1Test5, NumberStyles.Currency, nfi);\r
- Assert(lv == val1);\r
- }\r
-\r
- public void TestToString() \r
- {\r
- string s;\r
-\r
- s = val1.ToString("c", nfi);\r
- Assert(s.Equals(sval1Test6));\r
-\r
- s = val1.ToString("n", nfi);\r
- Assert(s.Equals(sval1Test7));\r
- }\r
-\r
- public void TestUserCurrency()\r
- {\r
- string s;\r
- long v;\r
-\r
- s = val1.ToString("c", nfiUser);\r
- Assert(s.Equals(sval1UserCur1));\r
- v = Int64.Parse(s, NumberStyles.Currency, nfiUser);\r
- Assert(v == val1);\r
- \r
- s = val2.ToString("c", nfiUser);\r
- Assert(s.Equals(sval2UserCur1));\r
- v = Int64.Parse(s, NumberStyles.Currency, nfiUser);\r
- Assert(v == val2);\r
- }\r
-\r
- public void TestUserPercent()\r
- {\r
- string s;\r
-\r
- s = val1.ToString("p", nfiUser);\r
- Assert(s.Equals(sval1UserPercent1));\r
-\r
- s = val2.ToString("p", nfiUser);\r
- Assert(s.Equals(sval2UserPercent1));\r
- }\r
-}\r
-\r
+// Int64Test.cs - NUnit Test Cases for the System.Int64 struct
+//
+// Author: Martin Weindel (martin.weindel@t-online.de)
+//
+// (C) Martin Weindel, 2001
+//
+// tests ToString and Parse function with the culture independent
+// NumberFormatInfo.InvariantInfo
+
+using NUnit.Framework;
+using System;
+using System.Globalization;
+
+ /// <summary>
+ /// Tests for System.Int64
+ /// </summary>
+public class Int64Test : TestCase
+{
+ private const Int64 MyInt64_1 = -42;
+ private const Int64 MyInt64_2 = -9223372036854775808;
+ private const Int64 MyInt64_3 = 9223372036854775807;
+ private const string MyString1 = "-42";
+ private const string MyString2 = "-9223372036854775808";
+ private const string MyString3 = "9223372036854775807";
+ private string[] Formats1 = {"c", "d", "e", "f", "g", "n", "p", "x" };
+ private string[] Formats2 = {"c5", "d5", "e5", "f5", "g5", "n5", "p5", "x5" };
+ private string[] Results1 = {"($9,223,372,036,854,775,808.00)", "-9223372036854775808", "-9.223372e+018", "-9223372036854775808.00",
+ "-9223372036854775808", "-9,223,372,036,854,775,808.00", "-922,337,203,685,477,580,800.00 %", "8000000000000000"};
+ private string[] Results2 = {"$9,223,372,036,854,775,807.00000", "9223372036854775807", "9.22337e+018", "9223372036854775807.00000",
+ "9.2234e+18", "9,223,372,036,854,775,807.00000", "922,337,203,685,477,580,700.00000 %", "7fffffffffffffff"};
+ private string[] ResultsNfi1 = {"($9,223,372,036,854,775,808.00)", "-9223372036854775808", "-9.223372e+018", "-9223372036854775808.00",
+ "-9223372036854775808", "(9,223,372,036,854,775,808.00)", "-922,337,203,685,477,580,800.00 %", "8000000000000000"};
+ private string[] ResultsNfi2 = {"$9,223,372,036,854,775,807.00000", "9223372036854775807", "9.22337e+018", "9223372036854775807.00000",
+ "9.2234e+18", "9,223,372,036,854,775,807.00000", "922,337,203,685,477,580,700.00000 %", "7fffffffffffffff"};
+ private static long[] vals
+ = { 0, Int64.MaxValue, Int64.MinValue,
+ 1L, 12L, 123L, 1234L, -123L,
+ 1234567890123456L, 6543210987654321L };
+ private const long val1 = -1234567L;
+ private const long val2 = 1234567L;
+ private const string sval1Test1 = " -1,234,567 ";
+ private const string sval1Test2 = " -1234567 ";
+ //private const string sval1Test3 = " -12345,,,,67 "; // interesting: this case works on SDK Beta2, but the specification says nothing about this case
+ private const string sval1Test4 = " -12345 67 ";
+ private const string sval1Test5 = " -$1,234567.00 ";
+ private const string sval1Test6 = "($1,234,567.00)";
+ private const string sval1Test7 = "(1,234,567.00)";
+ private const string sval1UserCur1 = "1234_5_67,000 XYZ-";
+ private const string sval2UserCur1 = "1234_5_67,000 XYZ";
+ private const string sval1UserPercent1 = "-%%%1~2~3~4~5~6~7~0~0;0";
+ private const string sval2UserPercent1 = "%%%1~2~3~4~5~6~7~0~0;0";
+ private const NumberStyles style1 = NumberStyles.AllowLeadingWhite | NumberStyles.AllowLeadingSign
+ | NumberStyles.AllowTrailingWhite | NumberStyles.AllowThousands;
+ private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
+ private NumberFormatInfo NfiUser;
+
+ public Int64Test(string name) : base(name) {}
+
+ public static ITest Suite
+ {
+ get { return new TestSuite(typeof(Int64Test)); }
+ }
+
+ protected override void SetUp()
+ {
+ NfiUser = new NumberFormatInfo();
+ NfiUser.CurrencyDecimalDigits = 3;
+ NfiUser.CurrencyDecimalSeparator = ",";
+ NfiUser.CurrencyGroupSeparator = "_";
+ NfiUser.CurrencyGroupSizes = new int[] { 2,1,0 };
+ NfiUser.CurrencyNegativePattern = 10;
+ NfiUser.CurrencyPositivePattern = 3;
+ NfiUser.CurrencySymbol = "XYZ";
+ NfiUser.PercentDecimalDigits = 1;
+ NfiUser.PercentDecimalSeparator = ";";
+ NfiUser.PercentGroupSeparator = "~";
+ NfiUser.PercentGroupSizes = new int[] {1};
+ NfiUser.PercentNegativePattern = 2;
+ NfiUser.PercentPositivePattern = 2;
+ NfiUser.PercentSymbol = "%%%";
+ }
+
+ public void TestMinMax()
+ {
+
+ AssertEquals(Int64.MinValue, MyInt64_2);
+ AssertEquals(Int64.MaxValue, MyInt64_3);
+ }
+
+ public void TestCompareTo()
+ {
+ Assert(MyInt64_3.CompareTo(MyInt64_2) > 0);
+ Assert(MyInt64_2.CompareTo(MyInt64_2) == 0);
+ Assert(MyInt64_1.CompareTo((Int64)(-42)) == 0);
+ Assert(MyInt64_2.CompareTo(MyInt64_3) < 0);
+ try {
+ MyInt64_2.CompareTo((Int16)100);
+ Fail("Should raise a System.ArgumentException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.ArgumentException) == e.GetType());
+ }
+ }
+
+ public void TestEquals()
+ {
+ Assert(MyInt64_1.Equals(MyInt64_1));
+ Assert(MyInt64_1.Equals((Int64)(-42)));
+ Assert(MyInt64_1.Equals((SByte)(-42)) == false);
+ Assert(MyInt64_1.Equals(MyInt64_2) == false);
+ }
+
+ public void TestGetHashCode()
+ {
+ try {
+ MyInt64_1.GetHashCode();
+ MyInt64_2.GetHashCode();
+ MyInt64_3.GetHashCode();
+ }
+ catch {
+ Fail("GetHashCode should not raise an exception here");
+ }
+ }
+
+ public void TestRoundTripGeneral()
+ {
+ foreach(long lv in vals)
+ {
+ string s = lv.ToString(Nfi);
+ long lv2 = Int64.Parse(s);
+ Assert(lv == lv2);
+ long lv3 = Int64.Parse(s, NumberStyles.Integer, Nfi);
+ Assert(lv == lv3);
+ }
+ }
+
+ public void TestRoundTripHex()
+ {
+ foreach(long lv in vals)
+ {
+ string s = lv.ToString("x", Nfi);
+ long lv2 = Int64.Parse(s, NumberStyles.HexNumber, Nfi);
+ Assert(lv == lv2);
+ }
+ }
+
+ public void TestParseNull()
+ {
+ try
+ {
+ Int64.Parse(null);
+ Fail("Should raise System.ArgumentNullException");
+ }
+ catch (ArgumentNullException)
+ {
+ // ok
+ }
+ }
+
+ public void TestParse()
+ {
+ long lv;
+
+ lv = Int64.Parse(sval1Test1, style1, Nfi);
+ Assert(lv == val1);
+
+ try
+ {
+ lv = Int64.Parse(sval1Test1, Nfi);
+ Fail("Should raise System.FormatException 1");
+ }
+ catch (System.FormatException)
+ {
+ // ok
+ }
+
+ lv = Int64.Parse(sval1Test2, style1, Nfi);
+ Assert(lv == val1);
+ lv = Int64.Parse(sval1Test2, Nfi);
+ Assert(lv == val1);
+
+ try
+ {
+ lv = Int64.Parse(sval1Test4, style1, Nfi);
+ Fail("Should raise System.FormatException 3");
+ }
+ catch (System.FormatException)
+ {
+ // ok
+ }
+
+ lv = Int64.Parse(sval1Test5, NumberStyles.Currency, Nfi);
+ Assert(lv == val1);
+
+ //test Parse(string s)
+ Assert(MyInt64_1 == Int64.Parse(MyString1));
+ Assert(MyInt64_2 == Int64.Parse(MyString2));
+ Assert(MyInt64_3 == Int64.Parse(MyString3));
+ try {
+ Int64.Parse(null);
+ Fail("Should raise a System.ArgumentNullException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.ArgumentNullException) == e.GetType());
+ }
+ try {
+ Int64.Parse("not-a-number");
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, NumberStyles style)
+ try {
+ double OverInt = (double)Int64.MaxValue + 1;
+ Int64.Parse(OverInt.ToString(), NumberStyles.Float);
+ Fail("Should raise a System.OverflowException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.OverflowException) == e.GetType());
+ }
+ try {
+ double OverInt = (double)Int64.MaxValue + 1;
+ Int64.Parse(OverInt.ToString(), NumberStyles.Integer);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ Assert(42 == Int64.Parse(" $42 ", NumberStyles.Currency));
+ try {
+ Int64.Parse("$42", NumberStyles.Integer);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, IFormatProvider provider)
+ Assert(-42 == Int64.Parse(" -42 ", Nfi));
+ try {
+ Int64.Parse("%42", Nfi);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, NumberStyles style, IFormatProvider provider)
+ Assert(16 == Int64.Parse(" 10 ", NumberStyles.HexNumber, Nfi));
+ try {
+ Int64.Parse("$42", NumberStyles.Integer, Nfi);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ }
+
+ public void TestToString()
+ {
+ string s;
+
+ s = val1.ToString("c", Nfi);
+ Assert(s.Equals(sval1Test6));
+
+ s = val1.ToString("n", Nfi);
+ Assert(s.Equals(sval1Test7));
+
+ //test ToString()
+ Assert(String.Compare(MyString1, MyInt64_1.ToString()) == 0);
+ Assert(String.Compare(MyString2, MyInt64_2.ToString()) == 0);
+ Assert(String.Compare(MyString3, MyInt64_3.ToString()) == 0);
+ //test ToString(string format)
+ for (int i=0; i < Formats1.Length; i++) {
+ Assert(String.Compare(Results1[i], MyInt64_2.ToString(Formats1[i])) == 0);
+ Assert(String.Compare(Results2[i], MyInt64_3.ToString(Formats2[i])) == 0);
+ }
+ //test ToString(string format, IFormatProvider provider);
+ for (int i=0; i < Formats1.Length; i++) {
+ Assert(String.Compare(ResultsNfi1[i], MyInt64_2.ToString(Formats1[i], Nfi)) == 0);
+ Assert(String.Compare(ResultsNfi2[i], MyInt64_3.ToString(Formats2[i], Nfi)) == 0);
+ }
+ try {
+ MyInt64_1.ToString("z");
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ }
+
+ public void TestUserCurrency()
+ {
+ string s;
+ long v;
+
+ s = val1.ToString("c", NfiUser);
+ Assert(s.Equals(sval1UserCur1));
+ v = Int64.Parse(s, NumberStyles.Currency, NfiUser);
+ Assert(v == val1);
+
+ s = val2.ToString("c", NfiUser);
+ Assert(s.Equals(sval2UserCur1));
+ v = Int64.Parse(s, NumberStyles.Currency, NfiUser);
+ Assert(v == val2);
+ }
+
+ public void TestUserPercent()
+ {
+ string s;
+
+ s = val1.ToString("p", NfiUser);
+ Assert(s.Equals(sval1UserPercent1));
+
+ s = val2.ToString("p", NfiUser);
+ Assert(s.Equals(sval2UserPercent1));
+ }
+}
+
+
--- /dev/null
+// SByteTest.cs - NUnit Test Cases for the System.SByte struct
+//
+// Mario Martinez (mariom925@home.om)
+//
+// (C) Ximian, Inc. http://www.ximian.com
+//
+
+using NUnit.Framework;
+using System;
+using System.Globalization;
+
+public class SByteTest : TestCase
+{
+ private const SByte MySByte1 = -42;
+ private const SByte MySByte2 = -128;
+ private const SByte MySByte3 = 127;
+ private const string MyString1 = "-42";
+ private const string MyString2 = "-128";
+ private const string MyString3 = "127";
+ private string[] Formats1 = {"c", "d", "e", "f", "g", "n", "p", "x" };
+ private string[] Formats2 = {"c5", "d5", "e5", "f5", "g5", "n5", "p5", "x5" };
+ private string[] Results1 = {"($128.00)", "-128", "-1.280000e+002", "-128.00",
+ "-128", "-128.00", "-12,800.00 %", "80"};
+ private string[] Results2 = {"$127.00000", "00127", "1.27000e+002", "127.00000",
+ "127", "127.00000", "12,700.00000 %", "0007f"};
+ private string[] ResultsNfi1 = {"($128.00)", "-128", "-1.280000e+002", "-128.00",
+ "-128", "(128.00)", "-12,800.00 %", "80"};
+ private string[] ResultsNfi2 = {"$127.00000", "00127", "1.27000e+002", "127.00000",
+ "127", "127.00000", "12,700.00000 %", "0007f"};
+ private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
+
+ public SByteTest(string name) : base(name) {}
+
+ protected override void SetUp()
+ {
+ }
+
+ public static ITest Suite {
+ get {
+ return new TestSuite(typeof(SByteTest));
+ }
+ }
+
+ public void TestMinMax()
+ {
+ AssertEquals(SByte.MinValue, MySByte2);
+ AssertEquals(SByte.MaxValue, MySByte3);
+ }
+
+ public void TestCompareTo()
+ {
+ Assert(MySByte3.CompareTo(MySByte2) > 0);
+ Assert(MySByte2.CompareTo(MySByte2) == 0);
+ Assert(MySByte1.CompareTo((SByte)(-42)) == 0);
+ Assert(MySByte2.CompareTo(MySByte3) < 0);
+ try {
+ MySByte2.CompareTo(100);
+ Fail("Should raise a System.ArgumentException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.ArgumentException) == e.GetType());
+ }
+ }
+
+ public void TestEquals()
+ {
+ Assert(MySByte1.Equals(MySByte1));
+ Assert(MySByte1.Equals((SByte)(-42)));
+ Assert(MySByte1.Equals((Int16)(-42)) == false);
+ Assert(MySByte1.Equals(MySByte2) == false);
+ }
+
+ public void TestGetHashCode()
+ {
+ try {
+ MySByte1.GetHashCode();
+ MySByte2.GetHashCode();
+ MySByte3.GetHashCode();
+ }
+ catch {
+ Fail("GetHashCode should not raise an exception here");
+ }
+ }
+
+ public void TestParse()
+ {
+ //test Parse(string s)
+ Assert(MySByte1 == SByte.Parse(MyString1));
+ Assert(MySByte2 == SByte.Parse(MyString2));
+ Assert(MySByte3 == SByte.Parse(MyString3));
+ try {
+ SByte.Parse(null);
+ Fail("Should raise a System.ArgumentNullException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.ArgumentNullException) == e.GetType());
+ }
+ try {
+ SByte.Parse("not-a-number");
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ try {
+ int OverInt = SByte.MaxValue + 1;
+ SByte.Parse(OverInt.ToString());
+ Fail("Should raise a System.OverflowException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.OverflowException) == e.GetType());
+ }
+ //test Parse(string s, NumberStyles style)
+ Assert(42 == SByte.Parse(" $42 ", NumberStyles.Currency));
+ try {
+ SByte.Parse("$42", NumberStyles.Integer);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, IFormatProvider provider)
+ Assert(-42 == SByte.Parse(" -42 ", Nfi));
+ try {
+ SByte.Parse("%42", Nfi);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, NumberStyles style, IFormatProvider provider)
+ Assert(16 == SByte.Parse(" 10 ", NumberStyles.HexNumber, Nfi));
+ try {
+ SByte.Parse("$42", NumberStyles.Integer, Nfi);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ }
+
+ public void TestToString()
+ {
+ //test ToString()
+ Assert(String.Compare(MyString1, MySByte1.ToString()) == 0);
+ Assert(String.Compare(MyString2, MySByte2.ToString()) == 0);
+ Assert(String.Compare(MyString3, MySByte3.ToString()) == 0);
+ //test ToString(string format)
+ for (int i=0; i < Formats1.Length; i++) {
+ Assert(String.Compare(Results1[i], MySByte2.ToString(Formats1[i])) == 0);
+ Assert(String.Compare(Results2[i], MySByte3.ToString(Formats2[i])) == 0);
+ }
+ //test ToString(string format, IFormatProvider provider);
+ for (int i=0; i < Formats1.Length; i++) {
+ Assert(String.Compare(ResultsNfi1[i], MySByte2.ToString(Formats1[i], Nfi)) == 0);
+ Assert(String.Compare(ResultsNfi2[i], MySByte3.ToString(Formats2[i], Nfi)) == 0);
+ }
+ try {
+ MySByte1.ToString("z");
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ }
+}
+
--- /dev/null
+// UInt16Test.cs - NUnit Test Cases for the System.UInt16 struct
+//
+// Mario Martinez (mariom925@home.om)
+//
+// (C) Ximian, Inc. http://www.ximian.com
+//
+
+using NUnit.Framework;
+using System;
+using System.Globalization;
+
+public class UInt16Test : TestCase
+{
+ private const UInt16 MyUInt16_1 = 42;
+ private const UInt16 MyUInt16_2 = 0;
+ private const UInt16 MyUInt16_3 = 65535;
+ private const string MyString1 = "42";
+ private const string MyString2 = "0";
+ private const string MyString3 = "65535";
+ private string[] Formats1 = {"c", "d", "e", "f", "g", "n", "p", "x" };
+ private string[] Formats2 = {"c5", "d5", "e5", "f5", "g5", "n5", "p5", "x5" };
+ private string[] Results1 = {"$0.00", "0", "0.000000e+000", "0.00",
+ "0", "0.00", "0.00 %", "0"};
+ private string[] Results2 = {"$65,535.00000", "65535", "6.55350e+004", "65535.00000",
+ "65535", "65,535.00000", "6,553,500.00000 %", "0ffff"};
+ private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
+
+ public UInt16Test(string name) : base(name) {}
+
+ protected override void SetUp()
+ {
+ }
+
+ public static ITest Suite {
+ get {
+ return new TestSuite(typeof(UInt16Test));
+ }
+ }
+
+ public void TestMinMax()
+ {
+
+ AssertEquals(UInt16.MinValue, MyUInt16_2);
+ AssertEquals(UInt16.MaxValue, MyUInt16_3);
+ }
+
+ public void TestCompareTo()
+ {
+ Assert(MyUInt16_3.CompareTo(MyUInt16_2) > 0);
+ Assert(MyUInt16_2.CompareTo(MyUInt16_2) == 0);
+ Assert(MyUInt16_1.CompareTo((UInt16)(42)) == 0);
+ Assert(MyUInt16_2.CompareTo(MyUInt16_3) < 0);
+ try {
+ MyUInt16_2.CompareTo(100);
+ Fail("Should raise a System.ArgumentException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.ArgumentException) == e.GetType());
+ }
+ }
+
+ public void TestEquals()
+ {
+ Assert(MyUInt16_1.Equals(MyUInt16_1));
+ Assert(MyUInt16_1.Equals((UInt16)(42)));
+ Assert(MyUInt16_1.Equals((SByte)(42)) == false);
+ Assert(MyUInt16_1.Equals(MyUInt16_2) == false);
+ }
+
+ public void TestGetHashCode()
+ {
+ try {
+ MyUInt16_1.GetHashCode();
+ MyUInt16_2.GetHashCode();
+ MyUInt16_3.GetHashCode();
+ }
+ catch {
+ Fail("GetHashCode should not raise an exception here");
+ }
+ }
+
+ public void TestParse()
+ {
+ //test Parse(string s)
+ Assert(MyUInt16_1 == UInt16.Parse(MyString1));
+ Assert(MyUInt16_2 == UInt16.Parse(MyString2));
+ Assert(MyUInt16_3 == UInt16.Parse(MyString3));
+ try {
+ UInt16.Parse(null);
+ Fail("Should raise a System.ArgumentNullException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.ArgumentNullException) == e.GetType());
+ }
+ try {
+ UInt16.Parse("not-a-number");
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ try {
+ int OverInt = UInt16.MaxValue + 1;
+ UInt16.Parse(OverInt.ToString());
+ Fail("Should raise a System.OverflowException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.OverflowException) == e.GetType());
+ }
+ //test Parse(string s, NumberStyles style)
+ Assert(42 == UInt16.Parse(" $42 ", NumberStyles.Currency));
+ try {
+ UInt16.Parse("$42", NumberStyles.Integer);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, IFormatProvider provider)
+ Assert(42 == UInt16.Parse(" 42 ", Nfi));
+ try {
+ UInt16.Parse("%42", Nfi);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, NumberStyles style, IFormatProvider provider)
+ Assert(16 == UInt16.Parse(" 10 ", NumberStyles.HexNumber, Nfi));
+ try {
+ UInt16.Parse("$42", NumberStyles.Integer, Nfi);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ }
+
+ public void TestToString()
+ {
+ //test ToString()
+ Assert(String.Compare(MyString1, MyUInt16_1.ToString()) == 0);
+ Assert(String.Compare(MyString2, MyUInt16_2.ToString()) == 0);
+ Assert(String.Compare(MyString3, MyUInt16_3.ToString()) == 0);
+ //test ToString(string format)
+ for (int i=0; i < Formats1.Length; i++) {
+ Assert(String.Compare(Results1[i], MyUInt16_2.ToString(Formats1[i])) == 0);
+ Assert(String.Compare(Results2[i], MyUInt16_3.ToString(Formats2[i])) == 0);
+ }
+ //test ToString(string format, IFormatProvider provider);
+ for (int i=0; i < Formats1.Length; i++) {
+ Assert(String.Compare(Results1[i], MyUInt16_2.ToString(Formats1[i], Nfi)) == 0);
+ Assert(String.Compare(Results2[i], MyUInt16_3.ToString(Formats2[i], Nfi)) == 0);
+ }
+ try {
+ MyUInt16_1.ToString("z");
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ }
+}
+
--- /dev/null
+// UInt32Test.cs - NUnit Test Cases for the System.UInt32 struct
+//
+// Mario Martinez (mariom925@home.om)
+//
+// (C) Ximian, Inc. http://www.ximian.com
+//
+
+using NUnit.Framework;
+using System;
+using System.Globalization;
+
+public class UInt32Test : TestCase
+{
+ private const UInt32 MyUInt32_1 = 42;
+ private const UInt32 MyUInt32_2 = 0;
+ private const UInt32 MyUInt32_3 = 4294967295;
+ private const string MyString1 = "42";
+ private const string MyString2 = "0";
+ private const string MyString3 = "4294967295";
+ private string[] Formats1 = {"c", "d", "e", "f", "g", "n", "p", "x" };
+ private string[] Formats2 = {"c5", "d5", "e5", "f5", "g5", "n5", "p5", "x5" };
+ private string[] Results1 = {"$0.00", "0", "0.000000e+000", "0.00",
+ "0", "0.00", "0.00 %", "0"};
+ private string[] Results2 = {"$4,294,967,295.00000", "4294967295", "4.29497e+009", "4294967295.00000",
+ "4.295e+09", "4,294,967,295.00000", "429,496,729,500.00000 %", "ffffffff"};
+ private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
+
+ public UInt32Test(string name) : base(name) {}
+
+ protected override void SetUp()
+ {
+ }
+
+ public static ITest Suite {
+ get {
+ return new TestSuite(typeof(UInt32Test));
+ }
+ }
+
+ public void TestMinMax()
+ {
+
+ AssertEquals(UInt32.MinValue, MyUInt32_2);
+ AssertEquals(UInt32.MaxValue, MyUInt32_3);
+ }
+
+ public void TestCompareTo()
+ {
+ Assert(MyUInt32_3.CompareTo(MyUInt32_2) > 0);
+ Assert(MyUInt32_2.CompareTo(MyUInt32_2) == 0);
+ Assert(MyUInt32_1.CompareTo((UInt32)(42)) == 0);
+ Assert(MyUInt32_2.CompareTo(MyUInt32_3) < 0);
+ try {
+ MyUInt32_2.CompareTo((Int16)100);
+ Fail("Should raise a System.ArgumentException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.ArgumentException) == e.GetType());
+ }
+ }
+
+ public void TestEquals()
+ {
+ Assert(MyUInt32_1.Equals(MyUInt32_1));
+ Assert(MyUInt32_1.Equals((UInt32)(42)));
+ Assert(MyUInt32_1.Equals((SByte)(42)) == false);
+ Assert(MyUInt32_1.Equals(MyUInt32_2) == false);
+ }
+
+ public void TestGetHashCode()
+ {
+ try {
+ MyUInt32_1.GetHashCode();
+ MyUInt32_2.GetHashCode();
+ MyUInt32_3.GetHashCode();
+ }
+ catch {
+ Fail("GetHashCode should not raise an exception here");
+ }
+ }
+
+ public void TestParse()
+ {
+ //test Parse(string s)
+ Assert(MyUInt32_1 == UInt32.Parse(MyString1));
+ Assert(MyUInt32_2 == UInt32.Parse(MyString2));
+ Assert(MyUInt32_3 == UInt32.Parse(MyString3));
+ try {
+ UInt32.Parse(null);
+ Fail("Should raise a System.ArgumentNullException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.ArgumentNullException) == e.GetType());
+ }
+ try {
+ UInt32.Parse("not-a-number");
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ try {
+ double OverInt = (double)UInt32.MaxValue + 1;
+ UInt32.Parse(OverInt.ToString());
+ Fail("Should raise a System.OverflowException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.OverflowException) == e.GetType());
+ }
+ //test Parse(string s, NumberStyles style)
+ Assert(42 == UInt32.Parse(" $42 ", NumberStyles.Currency));
+ try {
+ UInt32.Parse("$42", NumberStyles.Integer);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, IFormatProvider provider)
+ Assert(42 == UInt32.Parse(" 42 ", Nfi));
+ try {
+ UInt32.Parse("%42", Nfi);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, NumberStyles style, IFormatProvider provider)
+ Assert(16 == UInt32.Parse(" 10 ", NumberStyles.HexNumber, Nfi));
+ try {
+ UInt32.Parse("$42", NumberStyles.Integer, Nfi);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ }
+
+ public void TestToString()
+ {
+ //test ToString()
+ Assert(String.Compare(MyString1, MyUInt32_1.ToString()) == 0);
+ Assert(String.Compare(MyString2, MyUInt32_2.ToString()) == 0);
+ Assert(String.Compare(MyString3, MyUInt32_3.ToString()) == 0);
+ //test ToString(string format)
+ for (int i=0; i < Formats1.Length; i++) {
+ Assert(String.Compare(Results1[i], MyUInt32_2.ToString(Formats1[i])) == 0);
+ Assert(String.Compare(Results2[i], MyUInt32_3.ToString(Formats2[i])) == 0);
+ }
+ //test ToString(string format, IFormatProvider provider);
+ for (int i=0; i < Formats1.Length; i++) {
+ Assert(String.Compare(Results1[i], MyUInt32_2.ToString(Formats1[i], Nfi)) == 0);
+ Assert(String.Compare(Results2[i], MyUInt32_3.ToString(Formats2[i], Nfi)) == 0);
+ }
+ try {
+ MyUInt32_1.ToString("z");
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ }
+}
+
--- /dev/null
+// UInt64Test.cs - NUnit Test Cases for the System.UInt64 struct
+//
+// Mario Martinez (mariom925@home.om)
+//
+// (C) Ximian, Inc. http://www.ximian.com
+//
+
+using NUnit.Framework;
+using System;
+using System.Globalization;
+
+public class UInt64Test : TestCase
+{
+ private const UInt64 MyUInt64_1 = 42;
+ private const UInt64 MyUInt64_2 = 0;
+ private const UInt64 MyUInt64_3 = 18446744073709551615;
+ private const string MyString1 = "42";
+ private const string MyString2 = "0";
+ private const string MyString3 = "18446744073709551615";
+ private string[] Formats1 = {"c", "d", "e", "f", "g", "n", "p", "x" };
+ private string[] Formats2 = {"c5", "d5", "e5", "f5", "g5", "n5", "p5", "x5" };
+ private string[] Results1 = {"$0.00", "0", "0.000000e+000", "0.00",
+ "0", "0.00", "0.00 %", "0"};
+ private string[] Results2 = {"$18,446,744,073,709,551,615.00000", "18446744073709551615", "1.84467e+019", "18446744073709551615.00000",
+ "1.8447e+19", "18,446,744,073,709,551,615.00000", "1,844,674,407,370,955,161,500.00000 %", "ffffffffffffffff"};
+ private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
+
+ public UInt64Test(string name) : base(name) {}
+
+ protected override void SetUp()
+ {
+ }
+
+ public static ITest Suite {
+ get {
+ return new TestSuite(typeof(UInt64Test));
+ }
+ }
+
+ public void TestMinMax()
+ {
+
+ AssertEquals(UInt64.MinValue, MyUInt64_2);
+ AssertEquals(UInt64.MaxValue, MyUInt64_3);
+ }
+
+ public void TestCompareTo()
+ {
+ Assert(MyUInt64_3.CompareTo(MyUInt64_2) > 0);
+ Assert(MyUInt64_2.CompareTo(MyUInt64_2) == 0);
+ Assert(MyUInt64_1.CompareTo((UInt64)(42)) == 0);
+ Assert(MyUInt64_2.CompareTo(MyUInt64_3) < 0);
+ try {
+ MyUInt64_2.CompareTo((Int16)100);
+ Fail("Should raise a System.ArgumentException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.ArgumentException) == e.GetType());
+ }
+ }
+
+ public void TestEquals()
+ {
+ Assert(MyUInt64_1.Equals(MyUInt64_1));
+ Assert(MyUInt64_1.Equals((UInt64)(42)));
+ Assert(MyUInt64_1.Equals((SByte)(42)) == false);
+ Assert(MyUInt64_1.Equals(MyUInt64_2) == false);
+ }
+
+ public void TestGetHashCode()
+ {
+ try {
+ MyUInt64_1.GetHashCode();
+ MyUInt64_2.GetHashCode();
+ MyUInt64_3.GetHashCode();
+ }
+ catch {
+ Fail("GetHashCode should not raise an exception here");
+ }
+ }
+
+ public void TestParse()
+ {
+ //test Parse(string s)
+ Assert(MyUInt64_1 == UInt64.Parse(MyString1));
+ Assert(MyUInt64_2 == UInt64.Parse(MyString2));
+ Assert(MyUInt64_3 == UInt64.Parse(MyString3));
+ try {
+ UInt64.Parse(null);
+ Fail("Should raise a System.ArgumentNullException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.ArgumentNullException) == e.GetType());
+ }
+ try {
+ UInt64.Parse("not-a-number");
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, NumberStyles style)
+ try {
+ double OverInt = (double)UInt64.MaxValue + 1;
+ UInt64.Parse(OverInt.ToString(), NumberStyles.Float);
+ Fail("Should raise a System.OverflowException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.OverflowException) == e.GetType());
+ }
+ try {
+ double OverInt = (double)UInt64.MaxValue + 1;
+ UInt64.Parse(OverInt.ToString(), NumberStyles.Integer);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ Assert(42 == UInt64.Parse(" $42 ", NumberStyles.Currency));
+ try {
+ UInt64.Parse("$42", NumberStyles.Integer);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, IFormatProvider provider)
+ Assert(42 == UInt64.Parse(" 42 ", Nfi));
+ try {
+ UInt64.Parse("%42", Nfi);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ //test Parse(string s, NumberStyles style, IFormatProvider provider)
+ Assert(16 == UInt64.Parse(" 10 ", NumberStyles.HexNumber, Nfi));
+ try {
+ UInt64.Parse("$42", NumberStyles.Integer, Nfi);
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ }
+
+ public void TestToString()
+ {
+ //test ToString()
+ Assert(String.Compare(MyString1, MyUInt64_1.ToString()) == 0);
+ Assert(String.Compare(MyString2, MyUInt64_2.ToString()) == 0);
+ Assert(String.Compare(MyString3, MyUInt64_3.ToString()) == 0);
+ //test ToString(string format)
+ for (int i=0; i < Formats1.Length; i++) {
+ Assert(String.Compare(Results1[i], MyUInt64_2.ToString(Formats1[i])) == 0);
+ Assert(String.Compare(Results2[i], MyUInt64_3.ToString(Formats2[i])) == 0);
+ }
+ //test ToString(string format, IFormatProvider provider);
+ for (int i=0; i < Formats1.Length; i++) {
+ Assert(String.Compare(Results1[i], MyUInt64_2.ToString(Formats1[i], Nfi)) == 0);
+ Assert(String.Compare(Results2[i], MyUInt64_3.ToString(Formats2[i], Nfi)) == 0);
+ }
+ try {
+ MyUInt64_1.ToString("z");
+ Fail("Should raise a System.FormatException");
+ }
+ catch (Exception e) {
+ Assert(typeof(System.FormatException) == e.GetType());
+ }
+ }
+}
+
<includes name="**/*.cs"/>
<excludes name="temp/HashtableTest.cs"/>
<excludes name="temp/QueueTest.cs"/>
+ <excludes name="System/IntegerFormatterTest.cs"/>
</sources>
<references basedir="..\..\..\nunit">
<includes name="NUnitCore.dll"/>
suite.AddTest(new TestSuite(typeof(StringReaderTest)));\r
suite.AddTest(new TestSuite(typeof(StringWriterTest)));\r
\r
- suite.AddTest(Testsuite.System.Security.Cryptography.AllCryptoTests.Suite);\r
+ suite.AddTest(Testsuite.System.AllSystemTests.Suite);
+ suite.AddTest(Testsuite.System.Security.Cryptography.AllCryptoTests.Suite);\r
return suite;\r
}\r
}\r