Răsfoiți Sursa

2002-10-24 Ville Palo <[email protected]>

	* System.Data.SqlTypes/AllTests.cs:
	* System.Data.SqlTypes/SqlStringTest.cs:
	* System.Data.SqlTypes/SqlDecimalTest.cs: new test suites for
	SqlDecimal and SqlString

svn path=/trunk/mcs/; revision=8512
Ville Palo 23 ani în urmă
părinte
comite
b6c4affae9

+ 7 - 0
mcs/class/System.Data/Test/ChangeLog

@@ -1,3 +1,10 @@
+2002-10-24  Ville Palo <[email protected]>
+
+	* System.Data.SqlTypes/AllTests.cs:
+	* System.Data.SqlTypes/SqlStringTest.cs:
+	* System.Data.SqlTypes/SqlDecimalTest.cs: new test suites for 
+	SqlDecimal and SqlString
+		
 2002-10-19  Ville Palo <[email protected]>
 
 	* System.Data.SqlTypes/AllTests.cs:

+ 2 - 0
mcs/class/System.Data/Test/System.Data.SqlTypes/AllTests.cs

@@ -30,6 +30,8 @@ namespace MonoTests.System.Data.SqlTypes
 				suite.AddTest (new TestSuite (typeof (SqlMoneyTest)));
 				suite.AddTest (new TestSuite (typeof (SqlDateTimeTest)));
 				suite.AddTest (new TestSuite (typeof (SqlGuidTest)));
+				suite.AddTest (new TestSuite (typeof (SqlDecimalTest)));
+				suite.AddTest (new TestSuite (typeof (SqlStringTest)));
 				return suite;
 			}
 		}

+ 570 - 0
mcs/class/System.Data/Test/System.Data.SqlTypes/SqlDecimalTest.cs

@@ -0,0 +1,570 @@
+//
+// SqlDecimalTest.cs - NUnit Test Cases for System.Data.SqlTypes.SqlDecimal
+//
+// Ville Palo ([email protected])
+//
+// (C) Ville Palo 2002
+// 
+
+using NUnit.Framework;
+using System;
+using System.Data.SqlTypes;
+
+namespace MonoTests.System.Data.SqlTypes
+{
+        public class SqlDecimalTest : TestCase {
+
+		private SqlDecimal Test1;
+        	private SqlDecimal Test2;
+        	private SqlDecimal Test3;
+        	private SqlDecimal Test4;
+        	
+                public SqlDecimalTest() : base ("System.Data.SqlTypes.SqlDecimal") {}
+                public SqlDecimalTest(string name) : base(name) {}
+
+                protected override void TearDown() {}
+
+                protected override void SetUp() 
+                {
+                	Test1 = new SqlDecimal (6464.6464m);
+                	Test2 = new SqlDecimal (10000.00m); 
+                	Test3 = new SqlDecimal (10000.00m);                 
+                	Test4 = new SqlDecimal (-6m);                 
+                }
+
+                public static ITest Suite {
+                        get {
+                                return new TestSuite(typeof(SqlDecimal));
+                        }
+                }
+
+                // Test constructor
+                public void TestCreate()
+                {
+                	// SqlDecimal (decimal)
+			SqlDecimal Test = new SqlDecimal (30.3098m);
+                	AssertEquals ("#A01", (decimal)30.3098, Test.Value);
+                	
+                	try {
+                		SqlDecimal test = new SqlDecimal (Decimal.MaxValue + 1);
+                		Fail ("#A02");                		
+                	} catch (Exception e) {
+                		AssertEquals ("#A03", typeof (OverflowException), e.GetType ());
+                	}
+                	
+                	// SqlDecimal (double)
+                	Test = new SqlDecimal (10e10d);
+                	AssertEquals ("#A05", 100000000000m, Test.Value);
+                	
+                	try {
+                		SqlDecimal test = new SqlDecimal (10e200d);
+                		Fail ("#A06");                		
+                	} catch (Exception e) {
+                		AssertEquals ("#A07", typeof (OverflowException), e.GetType ());
+                	}
+                	
+                	// SqlDecimal (int)
+                	Test = new SqlDecimal (-1);
+                	AssertEquals ("#A08", -1m, Test.Value);
+                
+			// SqlDecimal (long)
+                	Test = new SqlDecimal ((long)(-99999));
+                	AssertEquals ("#A09", -99999m, Test.Value);
+                
+                	// SqlDecimal (byte, byte, bool. int[]
+                 	Test = new SqlDecimal (10, 3, false, new int [4] {200, 1, 0, 0});
+                	AssertEquals ("#A10", -4294967.496m, Test.Value);
+                	
+                	try {                		
+                		Test = new SqlDecimal (100, 100, false, 
+                		                       new int [4] {Int32.MaxValue, 
+                		                       Int32.MaxValue, Int32.MaxValue, 
+                		                       Int32.MaxValue});
+                		Fail ("#A11");
+                	} catch (Exception e) {
+                		AssertEquals ("#A12", typeof (SqlTypeException), e.GetType ());
+                	}
+
+			// sqlDecimal (byte, byte, bool, int, int, int, int)
+			Test = new SqlDecimal (12, 2, true, 100, 100, 0, 0);
+                	AssertEquals ("#A13", 4294967297m, Test.Value);
+                	
+                	try {                		
+                		Test = new SqlDecimal (100, 100, false, 
+                		                       Int32.MaxValue, 
+                		                       Int32.MaxValue, Int32.MaxValue, 
+                		                       Int32.MaxValue);
+                		Fail ("#A14");
+                	} catch (Exception e) {
+                		AssertEquals ("#A15", typeof (SqlTypeException), e.GetType ());
+                	}                	
+                }
+
+                // Test public fields
+                public void TestPublicFields()
+                {
+                        AssertEquals ("#B01", (byte)38, SqlDecimal.MaxPrecision);
+                        AssertEquals ("#B02", (byte)38, SqlDecimal.MaxScale);
+                        
+                        // FIXME: on windows: Conversion overflow
+                        AssertEquals  ("#B03", Decimal.MaxValue, SqlDecimal.MaxValue.Value);
+                        AssertEquals ("#B04", Decimal.MinValue, SqlDecimal.MinValue.Value);
+                	Assert ("#B05", SqlDecimal.Null.IsNull);
+                	Assert ("#B06", !Test1.IsNull);
+                }
+
+                // Test properties
+                public void TestProperties()
+                {
+                	byte[] b = Test1.BinData;
+                	AssertEquals ("#C01", (byte)64, b [0]);
+                	
+                	int[] i = Test1.Data;
+                	AssertEquals ("#C02", 64646464, i [0]);
+                
+                        Assert ("#C03", SqlDecimal.Null.IsNull);
+                        Assert ("#C04", Test1.IsPositive);
+                        Assert ("#C05", !Test4.IsPositive);
+                        AssertEquals ("#C06", (byte)8, Test1.Precision);
+                	AssertEquals ("#C07", (byte)0, Test2.Scale);
+                	AssertEquals ("#C08", 6464.6464m, Test1.Value); 
+                }
+
+                // PUBLIC METHODS
+
+                public void TestArithmeticMethods()
+                {
+
+			// Abs
+			AssertEquals ("#D01", (SqlDecimal)6, SqlDecimal.Abs (Test4));
+                	AssertEquals ("#D02", (SqlDecimal)6464.6464m, SqlDecimal.Abs (Test1));
+                	
+                	AssertEquals ("#D03", SqlDecimal.Null, SqlDecimal.Abs (SqlDecimal.Null));
+                	
+                        // Add()
+                        AssertEquals ("#D04", 16464.6464m, SqlDecimal.Add (Test1, Test2).Value);
+
+                        try {
+                                SqlDecimal test = SqlDecimal.Add (SqlDecimal.MaxValue, SqlDecimal.MaxValue);
+                                Fail ("#D05");
+                        } catch (Exception e) {
+                                AssertEquals ("#D06", typeof (OverflowException), e.GetType ());
+                        }
+                        
+			AssertEquals ("#D07", (SqlDecimal)6465, SqlDecimal.Ceiling(Test1));
+                	AssertEquals ("#D08", SqlDecimal.Null, SqlDecimal.Ceiling(SqlDecimal.Null));
+                	
+                        // Divide()
+                        AssertEquals ("#D09", (SqlDecimal)(-1077.441066m), SqlDecimal.Divide (Test1, Test4));
+                        AssertEquals ("#D10", 1.546875015m, SqlDecimal.Divide (Test2, Test1).Value);
+
+                        try {
+                                SqlDecimal test = SqlDecimal.Divide(Test1, new SqlDecimal(0)).Value;
+                                Fail ("#D11");
+                        } catch(Exception e) {
+                                AssertEquals ("#D12", typeof (DivideByZeroException), e.GetType ());
+                        }
+
+			AssertEquals ("#D13", (SqlDecimal)6464, SqlDecimal.Floor (Test1));
+                	
+                        // Multiply()
+                        AssertEquals ("#D14", 64646464m, SqlDecimal.Multiply (Test1, Test2).Value);
+                        AssertEquals ("#D15", -38787.8784m, SqlDecimal.Multiply (Test1, Test4).Value);
+
+                        try {
+                                SqlDecimal test = SqlDecimal.Multiply (SqlDecimal.MaxValue, Test1);
+                                Fail ("#D16");
+                        } catch (Exception e) {
+                                AssertEquals ("#D17", typeof (OverflowException), e.GetType ());
+                        }
+                        
+                        // Power
+                        AssertEquals ("#D18", (SqlDecimal)41791653.0770m, SqlDecimal.Power (Test1, 2));
+                       
+                       	// Round
+                      	AssertEquals ("#D19", (SqlDecimal)6464.65m, SqlDecimal.Round (Test1, 2));
+                	
+                        // Subtract()
+                        AssertEquals ("#D20", -3535.3536m, SqlDecimal.Subtract (Test1, Test3).Value);
+
+                        try {
+                                SqlDecimal test = SqlDecimal.Subtract(SqlDecimal.MinValue, SqlDecimal.MaxValue);
+                                Fail ("#D21");
+                        } catch (Exception e) {
+                                AssertEquals ("#D22", typeof (OverflowException), e.GetType ());
+                        }                           
+                        
+                        AssertEquals ("#D23", (SqlInt32)1, SqlDecimal.Sign (Test1));
+                        AssertEquals ("#D24", new SqlInt32(-1), SqlDecimal.Sign (Test4));
+                }
+
+		public void TestAdjustScale()
+		{
+			AssertEquals ("#E01", 6464.6464m, SqlDecimal.AdjustScale (Test1, 2, false).Value);
+			AssertEquals ("#E02", 6464.6464m, SqlDecimal.AdjustScale (Test1, 3, true).Value);
+		}
+		
+		public void TestConvertToPrecScale()
+		{
+			AssertEquals ("#F01", new SqlDecimal(6464.6m), SqlDecimal.ConvertToPrecScale (Test1, 5, 1));
+		}
+		
+                public void TestCompareTo()
+                {
+                        SqlString TestString = new SqlString ("This is a test");
+
+                        Assert ("#G01", Test1.CompareTo (Test3) < 0);
+                        Assert ("#G02", Test2.CompareTo (Test1) > 0);
+                        Assert ("#G03", Test2.CompareTo (Test3) == 0);
+                        Assert ("#G04", Test4.CompareTo (SqlDecimal.Null) > 0);
+
+                        try {
+                                Test1.CompareTo (TestString);
+                                Fail("#G05");
+                        } catch(Exception e) {
+                                AssertEquals ("#G06", typeof (ArgumentException), e.GetType ());
+                        }
+                }
+
+                public void TestEqualsMethods()
+                {
+                        Assert ("#H01", !Test1.Equals (Test2));
+                        Assert ("#H02", !Test2.Equals (new SqlString ("TEST")));
+                        Assert ("#H03", Test2.Equals (Test3));
+
+                        // Static Equals()-method
+                        Assert ("#H05", SqlDecimal.Equals (Test2, Test2).Value);
+                        Assert ("#H06", !SqlDecimal.Equals (Test1, Test2).Value);
+                	
+                	// NotEquals
+                        Assert ("#H07", SqlDecimal.NotEquals (Test1, Test2).Value);
+                        Assert ("#H08", SqlDecimal.NotEquals (Test4, Test1).Value);
+                        Assert ("#H09", !SqlDecimal.NotEquals (Test2, Test3).Value);
+                        Assert ("#H10", SqlDecimal.NotEquals (SqlDecimal.Null, Test3).IsNull);                 
+                }
+
+                public void TestGetHashCode()
+                {
+                        // FIXME: Better way to test HashCode
+                        AssertEquals ("#I01", -1281249885, Test1.GetHashCode ());
+                }
+
+                public void TestGetType()
+                {
+                        AssertEquals ("#J01", "System.Data.SqlTypes.SqlDecimal", 
+                                      Test1.GetType ().ToString ());
+                        AssertEquals ("#J02", "System.Decimal", Test1.Value.GetType ().ToString ());
+                }
+
+                public void TestGreaters()
+                {
+                        // GreateThan ()
+                        Assert ("#K01", !SqlDecimal.GreaterThan (Test1, Test2).Value);
+                        Assert ("#K02", SqlDecimal.GreaterThan (Test2, Test1).Value);
+                        Assert ("#K03", !SqlDecimal.GreaterThan (Test2, Test3).Value);
+
+                        // GreaterTharOrEqual ()
+                        Assert ("#K04", !SqlDecimal.GreaterThanOrEqual (Test1, Test2).Value);
+                        Assert ("#K05", SqlDecimal.GreaterThanOrEqual (Test2, Test1).Value);
+                        Assert ("#K06", SqlDecimal.GreaterThanOrEqual (Test2, Test3).Value);
+                }
+
+                public void TestLessers()
+                {
+                        // LessThan()
+                        Assert ("#L01", !SqlDecimal.LessThan (Test3, Test2).Value);
+                        Assert ("#L02", !SqlDecimal.LessThan (Test2, Test1).Value);
+                        Assert ("#L03", SqlDecimal.LessThan (Test1, Test2).Value);
+
+                        // LessThanOrEqual ()
+                        Assert ("#L04", SqlDecimal.LessThanOrEqual (Test1, Test2).Value);
+                        Assert ("#L05", !SqlDecimal.LessThanOrEqual (Test2, Test1).Value);
+                        Assert ("#L06", SqlDecimal.LessThanOrEqual (Test2, Test3).Value);
+                        Assert ("#L07", SqlDecimal.LessThanOrEqual (Test1, SqlDecimal.Null).IsNull);
+                }
+
+                public void TestParse()
+                {
+                        try {
+                                SqlDecimal.Parse (null);
+                                Fail ("#m01");
+                        } catch (Exception e) {
+                                AssertEquals ("#M02", typeof (ArgumentNullException), e.GetType ());
+                        }
+
+                        try {
+                                SqlDecimal.Parse ("not-a-number");
+                                Fail ("#M03");
+                        } catch (Exception e) {
+                                AssertEquals ("#M04", typeof (FormatException), e.GetType ());
+                        }
+
+                         try {
+                                SqlDecimal test = SqlDecimal.Parse ("9e300");
+                                Fail ("#M05");
+                        } catch (Exception e) {
+                                AssertEquals ("#M06", typeof (FormatException), e.GetType ());
+                        }
+
+                        AssertEquals("#M07", 150m, SqlDecimal.Parse ("150").Value);
+                }
+
+                public void TestConversions()
+                {
+                	// ToDouble
+                	AssertEquals ("N01", 6464.6464, Test1.ToDouble ());
+                	
+                        // ToSqlBoolean ()
+                       	AssertEquals ("#N02", new SqlBoolean(1), Test1.ToSqlBoolean ());
+                        
+                        SqlDecimal Test = new SqlDecimal (0);
+                        Assert ("#N03", !Test.ToSqlBoolean ().Value);
+                	
+                	Test = new SqlDecimal (0);
+                	Assert ("#N04", !Test.ToSqlBoolean ().Value);
+                        Assert ("#N05", SqlDecimal.Null.ToSqlBoolean ().IsNull);
+
+                        // ToSqlByte ()
+                        Test = new SqlDecimal (250);
+                        AssertEquals ("#N06", (byte)250, Test.ToSqlByte ().Value);
+
+                        try {
+                                SqlByte b = (byte)Test2.ToSqlByte ();
+                                Fail ("#N07");
+                        } catch (Exception e) {
+                                AssertEquals ("#N08", typeof (OverflowException), e.GetType ());
+                        }
+
+                        // ToSqlDouble ()
+                        AssertEquals ("#N09", (SqlDouble)6464.6464, Test1.ToSqlDouble ());
+
+                        // ToSqlInt16 ()
+                        AssertEquals ("#N10", (short)1, new SqlDecimal (1).ToSqlInt16 ().Value);
+
+                        try {
+                                SqlInt16 test = SqlDecimal.MaxValue.ToSqlInt16().Value;
+                                Fail ("#N11");
+                        } catch (Exception e) {
+                                AssertEquals ("#N12", typeof (OverflowException), e.GetType ());
+                        }        
+
+                        // ToSqlInt32 () 
+                        // FIXME: 6464.6464 --> 64646464 ??? with windows
+                        AssertEquals ("#N13a", (int)64646464, Test1.ToSqlInt32 ().Value);
+			AssertEquals ("#N13b", (int)1212, new SqlDecimal(12.12m).ToSqlInt32 ().Value);
+                	
+                        try {
+                                SqlInt32 test = SqlDecimal.MaxValue.ToSqlInt32 ().Value;
+                                Fail ("#N14");
+                        } catch (Exception e) { 
+                                AssertEquals ("#N15", typeof (OverflowException), e.GetType ());
+                        }
+
+                        // ToSqlInt64 ()
+                        AssertEquals ("#N16", (long)6464, Test1.ToSqlInt64 ().Value);
+
+                        // ToSqlMoney ()
+                        AssertEquals ("#N17", (decimal)6464.6464, Test1.ToSqlMoney ().Value);
+
+                        try {
+                                SqlMoney test = SqlDecimal.MaxValue.ToSqlMoney ().Value;
+                                Fail ("#N18");
+                        } catch (Exception e) {
+                                AssertEquals ("#N19", typeof (OverflowException), e.GetType ());
+                        }        
+
+                        // ToSqlSingle ()
+                        AssertEquals ("#N20", (float)6464.6464, Test1.ToSqlSingle ().Value);
+
+                        // ToSqlString ()
+                        AssertEquals ("#N21", "6464.6464", Test1.ToSqlString ().Value);
+
+                        // ToString ()
+                        AssertEquals ("#N22", "6464.6464", Test1.ToString ());                        
+                }
+                
+                public void TestTruncate()
+                {
+                	AssertEquals ("#O01", (SqlDecimal)6464.64m, SqlDecimal.Truncate (Test1, 2));
+                }
+                
+                // OPERATORS
+
+                public void TestArithmeticOperators()
+                {
+                        // "+"-operator
+                        AssertEquals ("#P01", new SqlDecimal(16464.6464m), Test1 + Test2);
+     
+                        try {
+                                SqlDecimal test = SqlDecimal.MaxValue + SqlDecimal.MaxValue;
+                                Fail ("#P02");
+                        } catch (Exception e) {
+                                AssertEquals ("#P03", typeof (OverflowException), e.GetType ());
+                        }
+
+                        // "/"-operator
+                        AssertEquals ("#P04", (SqlDecimal)1.546875015m, Test2 / Test1);
+
+                        try {
+                                SqlDecimal test = Test3 / new SqlDecimal (0);
+                                Fail ("#P05");
+                        } catch (Exception e) {
+                                AssertEquals ("#P06", typeof (DivideByZeroException), e.GetType ());
+                        }
+
+                        // "*"-operator
+                        AssertEquals ("#P07", (SqlDecimal)64646464, Test1 * Test2);
+
+                        try {
+                                SqlDecimal test = SqlDecimal.MaxValue * Test1;
+                                Fail ("#P08");
+                        } catch (Exception e) {
+                                AssertEquals ("#P09", typeof (OverflowException), e.GetType ());
+                        }
+
+                        // "-"-operator
+                        AssertEquals ("#P10", (SqlDecimal)3535.3536m, Test2 - Test1);
+
+                        try {
+                                SqlDecimal test = SqlDecimal.MinValue - SqlDecimal.MaxValue;
+                                Fail ("#N11");
+                        } catch  (Exception e) {
+                                AssertEquals ("#N12", typeof (OverflowException), e.GetType ());
+                        }
+                }
+
+                public void TestThanOrEqualOperators()
+                {
+
+                        // == -operator
+                        Assert ("#Q01", (Test2 == Test3).Value);
+                        Assert ("#Q02", !(Test1 == Test2).Value);
+                        Assert ("#Q03", (Test1 == SqlDecimal.Null).IsNull);
+                        
+                        // != -operator
+                        Assert ("#Q04", !(Test2 != Test3).Value);
+                        Assert ("#Q05", (Test1 != Test3).Value);
+                        Assert ("#Q06", (Test4 != Test3).Value);
+                        Assert ("#Q07", (Test1 != SqlDecimal.Null).IsNull);
+
+                        // > -operator
+                        Assert ("#Q08", (Test2 > Test1).Value);
+                        Assert ("#Q09", !(Test1 > Test3).Value);
+                        Assert ("#Q10", !(Test2 > Test3).Value);
+                        Assert ("#Q11", (Test1 > SqlDecimal.Null).IsNull);
+
+                        // >=  -operator
+                        Assert ("#Q12", !(Test1 >= Test3).Value);
+                        Assert ("#Q13", (Test3 >= Test1).Value);
+                        Assert ("#Q14", (Test2 >= Test3).Value);
+                        Assert ("#Q15", (Test1 >= SqlDecimal.Null).IsNull);
+
+                        // < -operator
+                        Assert ("#Q16", !(Test2 < Test1).Value);
+                        Assert ("#Q17", (Test1 < Test3).Value);
+                        Assert ("#Q18", !(Test2 < Test3).Value);
+                        Assert ("#Q19", (Test1 < SqlDecimal.Null).IsNull);
+
+                        // <= -operator
+                        Assert ("#Q20", (Test1 <= Test3).Value);
+                        Assert ("#Q21", !(Test3 <= Test1).Value);
+                        Assert ("#Q22", (Test2 <= Test3).Value);
+                        Assert ("#Q23", (Test1 <= SqlDecimal.Null).IsNull);
+                }
+
+                public void TestUnaryNegation()
+                {
+                        AssertEquals ("#R01", 6m, -Test4.Value);
+                        AssertEquals ("#R02", -6464.6464m, -Test1.Value);
+                }
+
+                public void TestSqlBooleanToSqlDouble()
+                {
+                        SqlBoolean TestBoolean = new SqlBoolean (true);
+                        SqlDecimal Result;
+
+                        Result = (SqlDecimal)TestBoolean;
+
+                        AssertEquals ("#S01", 1m, Result.Value);
+
+                        Result = (SqlDecimal)SqlBoolean.Null;
+                        Assert ("#S02", Result.IsNull);
+                }
+		
+		public void TestSqlDecimalToDecimal()
+		{
+			AssertEquals ("#T01", 6464.6464m, (Decimal)Test1);
+		}
+
+                public void TestSqlDoubleToSqlDecimal()
+                {
+                        SqlDouble Test = new SqlDouble (12e10);
+                        AssertEquals ("#U01", 120000000000m, ((SqlDecimal)Test).Value);
+                }
+                
+                public void TestSqlSingleToSqlDecimal()
+                {
+                	SqlSingle Test = new SqlSingle (1e9);
+                	AssertEquals ("#V01", 1000000000m, ((SqlDecimal)Test).Value);
+                	
+                	try {
+                		SqlDecimal test = (SqlDecimal)SqlSingle.MaxValue;
+                		Fail ("#V02");
+                	} catch (Exception e) {
+                		AssertEquals ("#V03", typeof (OverflowException), e.GetType ());
+                	}
+                }
+
+                public void TestSqlStringToSqlDecimal()
+                {
+                        SqlString TestString = new SqlString ("Test string");
+                        SqlString TestString100 = new SqlString ("100");
+
+                        AssertEquals ("#W01", 100m, ((SqlDecimal)TestString100).Value);
+
+                        try {
+                                SqlDecimal test = (SqlDecimal)TestString;
+                                Fail ("#W02");
+                        } catch(Exception e) {
+                                AssertEquals ("#W03", typeof (FormatException), e.GetType ());
+                        }
+                        
+                        try {
+                        	SqlDecimal test = (SqlDecimal)new SqlString("9e100");
+                        	Fail ("#W04");
+                        } catch (Exception e) {
+                        	AssertEquals ("#W05", typeof (FormatException), e.GetType());
+                        }
+                }
+
+		public void TestDecimalToSqlDecimal()
+		{
+			decimal d = 1000.1m;
+			AssertEquals ("#X01", (SqlDecimal)1000.1m, (SqlDecimal)d);		
+		}
+		
+                public void TestByteToSqlDecimal()
+                {                      
+                        AssertEquals ("#Y01", 255m, ((SqlDecimal)SqlByte.MaxValue).Value);
+                }
+                
+
+                public void TestSqlIntToSqlDouble()
+                {
+                        SqlInt16 Test64 = new SqlInt16 (64);
+                        SqlInt32 Test640 = new SqlInt32 (640);
+                        SqlInt64 Test64000 = new SqlInt64 (64000);
+                        AssertEquals ("#Z01", 64m, ((SqlDecimal)Test64).Value);
+                        AssertEquals ("#Z02", 640m,((SqlDecimal)Test640).Value);
+                        AssertEquals ("#Z03", 64000m, ((SqlDecimal)Test64000).Value);
+                }
+
+
+                public void TestSqlMoneyToSqlDecimal()
+                {
+                        SqlMoney TestMoney64 = new SqlMoney(64);
+                        AssertEquals ("#AA01", 64M, ((SqlDecimal)TestMoney64).Value);
+                }
+        }
+}
+

+ 573 - 0
mcs/class/System.Data/Test/System.Data.SqlTypes/SqlStringTest.cs

@@ -0,0 +1,573 @@
+//
+// SqlStringTest.cs - NUnit Test Cases for System.Data.SqlTypes.SqlString
+//
+// Ville Palo ([email protected])
+//
+// (C) Ville Palo 2002
+// 
+
+using NUnit.Framework;
+using System;
+using System.Data.SqlTypes;
+using System.Globalization;
+using System.Threading;
+
+namespace MonoTests.System.Data.SqlTypes
+{
+        public class SqlStringTest : TestCase {
+
+	        private SqlString Test1 = null;
+		private SqlString Test2 = null;
+		private SqlString Test3 = null;
+
+                public SqlStringTest() : base ("System.Data.SqlTypes.SqlString") {}
+                public SqlStringTest(string name) : base(name) {}
+
+                protected override void TearDown() {}
+
+                protected override void SetUp()
+		{
+			Test1 = new SqlString ("First TestString");
+			Test2 = new SqlString ("This is just a test SqlString");
+			Test3 = new SqlString ("This is just a test SqlString");
+			Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-AU");
+		}
+
+                public static ITest Suite {
+                        get {
+
+                                return new TestSuite(typeof(SqlDateTime));
+
+                        }
+
+                }
+
+
+
+                // Test constructor
+
+                public void TestCreate()
+
+                {
+
+			// SqlString (String)
+			SqlString  TestString = new SqlString ("Test");
+                	AssertEquals ("#A01", "Test", TestString.Value);
+
+			// SqlString (String, int)
+			TestString = new SqlString ("Test", 2057);
+                	AssertEquals ("#A02", 2057, TestString.LCID);
+
+			// SqlString (int, SqlCompareOptions, byte[])
+			TestString = new SqlString (2057,
+			                            SqlCompareOptions.BinarySort|SqlCompareOptions.IgnoreCase,
+			                            new byte [2] {123, 221});
+                	AssertEquals ("#A03", 2057, TestString.CompareInfo.LCID);
+                	
+			// SqlString(string, int, SqlCompareOptions)
+			TestString = new SqlString ("Test", 2057, SqlCompareOptions.IgnoreNonSpace);
+                	Assert ("#A04", !TestString.IsNull);
+                	
+			// SqlString (int, SqlCompareOptions, byte[], bool)
+			TestString = new SqlString (2057, SqlCompareOptions.BinarySort, new byte [4] {100, 100, 200, 45}, true);
+                	AssertEquals ("#A05", (byte)63, TestString.GetNonUnicodeBytes () [0]);
+			TestString = new SqlString (2057, SqlCompareOptions.BinarySort, new byte [2] {113, 100}, false);
+                	AssertEquals ("#A06", (String)"qd", TestString.Value);
+                	
+			// SqlString (int, SqlCompareOptions, byte[], int, int)
+			TestString = new SqlString (2057, SqlCompareOptions.BinarySort, new byte [2] {113, 100}, 0, 2);
+                	Assert ("#A07", !TestString.IsNull);
+                	
+			// SqlString (int, SqlCompareOptions, byte[], int, int, bool)
+			TestString = new SqlString (2057, SqlCompareOptions.IgnoreCase, new byte [3] {100, 111, 50}, 1, 2, false);
+                	AssertEquals ("#A08", "o2", TestString.Value);
+			TestString = new SqlString (2057, SqlCompareOptions.IgnoreCase, new byte [3] {123, 111, 222}, 1, 2, true);
+                	Assert ("#A09", !TestString.IsNull);			
+                }
+
+                // Test public fields
+                public void TestPublicFields()
+                {
+			// BinarySort
+			AssertEquals ("#B01", 32768, SqlString.BinarySort);
+                	
+			// IgnoreCase
+			AssertEquals ("#B02", 1, SqlString.IgnoreCase);
+			              
+			// IgnoreKanaType
+			AssertEquals ("#B03", 8, SqlString.IgnoreKanaType);
+
+			// IgnoreNonSpace
+			AssertEquals ("#B04", 2, SqlString.IgnoreNonSpace);
+                	
+			// IgnoreWidth
+			AssertEquals ("#B05", 16, SqlString.IgnoreWidth);
+                	
+			// Null
+			Assert ("#B06", SqlString.Null.IsNull);
+                }
+
+                // Test properties
+                public void TestProperties()
+                {
+			// CompareInfo
+			AssertEquals ("#C01", 3081, Test1.CompareInfo.LCID);
+
+			// CultureInfo
+			AssertEquals ("#C02", 3081, Test1.CultureInfo.LCID);		
+                	
+			// IsNull
+			Assert ("#C03", !Test1.IsNull);
+                	Assert ("C04", SqlString.Null.IsNull);
+                	
+			// LCID
+			AssertEquals ("#C05", 3081, Test1.LCID);
+                	
+			// SqlCompareOptions
+			AssertEquals ("#C06", "IgnoreCase, IgnoreKanaType, IgnoreWidth", 
+			              Test1.SqlCompareOptions.ToString ());
+
+			// Value
+			AssertEquals ("#C07", "First TestString", Test1.Value);
+                }
+
+                // PUBLIC METHODS
+
+                public void TestCompareTo()
+                {
+                        SqlByte Test = new SqlByte (1);
+
+                        Assert ("#D01", Test1.CompareTo (Test3) < 0);
+                        Assert ("#D02", Test2.CompareTo (Test1) > 0);
+                        Assert ("#D03", Test2.CompareTo (Test3) == 0);
+                        Assert ("#D04", Test3.CompareTo (SqlString.Null) > 0);
+
+                        try {
+                                Test1.CompareTo (Test);
+                                Fail("#D05");
+                        } catch(Exception e) {
+                                AssertEquals ("#D06", typeof (ArgumentException), e.GetType ());
+                        }
+                }
+
+                public void TestEqualsMethods()
+                {
+                        Assert ("#E01", !Test1.Equals (Test2));
+                        Assert ("#E02", !Test3.Equals (Test1));
+                        Assert ("#E03", !Test2.Equals (new SqlString ("TEST")));
+                        Assert ("#E04", Test2.Equals (Test3));
+
+                        // Static Equals()-method
+                        Assert ("#E05", SqlString.Equals (Test2, Test3).Value);
+                        Assert ("#E06", !SqlString.Equals (Test1, Test2).Value);
+                }
+
+                public void TestGetHashCode()
+                {
+                        // FIXME: Better way to test HashCode
+                        AssertEquals ("#F01", Test1.GetHashCode (), 
+				      Test1.GetHashCode ());
+			Assert ("#F02", Test1.GetHashCode () != Test2.GetHashCode ());
+			Assert ("#F03", Test2.GetHashCode () == Test2.GetHashCode ());
+                }
+
+                public void TestGetType()
+                {
+                        AssertEquals ("#G01", "System.Data.SqlTypes.SqlString", 
+				      Test1.GetType ().ToString ());
+                        AssertEquals ("#G02", "System.String", 
+				      Test1.Value.GetType ().ToString ());
+                }
+
+		public void TestGreaters()
+		{
+
+                        // GreateThan ()
+                        Assert ("#H01", !SqlString.GreaterThan (Test1, Test2).Value);
+                        Assert ("#H02", SqlString.GreaterThan (Test2, Test1).Value);
+                        Assert ("#H03", !SqlString.GreaterThan (Test2, Test3).Value);
+
+                        // GreaterTharOrEqual ()
+                        Assert ("#H04", !SqlString.GreaterThanOrEqual (Test1, Test2).Value);
+                        Assert ("#H05", SqlString.GreaterThanOrEqual (Test2, Test1).Value);
+                        Assert ("#H06", SqlString.GreaterThanOrEqual (Test2, Test3).Value);
+                }
+
+                public void TestLessers()
+                {
+                        // LessThan()
+                        Assert ("#I01", !SqlString.LessThan (Test2, Test3).Value);
+                        Assert ("#I02", !SqlString.LessThan (Test2, Test1).Value);
+                        Assert ("#I03", SqlString.LessThan (Test1, Test2).Value);
+
+                        // LessThanOrEqual ()
+                        Assert ("#I04", SqlString.LessThanOrEqual (Test1, Test2).Value);
+                        Assert ("#I05", !SqlString.LessThanOrEqual (Test2, Test1).Value);
+                        Assert ("#I06", SqlString.LessThanOrEqual (Test3, Test2).Value);
+                        Assert ("#I07", SqlString.LessThanOrEqual (Test2, SqlString.Null).IsNull);
+                }
+
+                public void TestNotEquals()
+                {
+                        Assert ("#J01", SqlString.NotEquals (Test1, Test2).Value);
+                        Assert ("#J02", SqlString.NotEquals (Test2, Test1).Value);
+                        Assert ("#J03", SqlString.NotEquals (Test3, Test1).Value);
+                        Assert ("#J04", !SqlString.NotEquals (Test2, Test3).Value);
+
+                        Assert ("#J05", SqlString.NotEquals (SqlString.Null, Test3).IsNull);
+                }
+
+		public void TestConcat()
+		{
+			Test1 = new SqlString ("First TestString");
+			Test2 = new SqlString ("This is just a test SqlString");
+			Test3 = new SqlString ("This is just a test SqlString");
+
+			AssertEquals ("#K01", 
+			      (SqlString)"First TestStringThis is just a test SqlString", 
+			      SqlString.Concat (Test1, Test2));
+
+			AssertEquals ("#K02", SqlString.Null, 
+				      SqlString.Concat (Test1, SqlString.Null));
+		}
+
+		public void TestClone()
+		{
+			SqlString TestSqlString  = Test1.Clone ();
+			AssertEquals ("#L01", Test1, TestSqlString);
+		}
+
+		public void TestCompareOptionsFromSqlCompareOptions()
+		{
+			AssertEquals ("#M01", CompareOptions.IgnoreCase,
+				    SqlString.CompareOptionsFromSqlCompareOptions (
+				    SqlCompareOptions.IgnoreCase));
+			AssertEquals ("#M02", CompareOptions.IgnoreCase,
+				    SqlString.CompareOptionsFromSqlCompareOptions (
+				    SqlCompareOptions.IgnoreCase));
+
+		}
+
+		public void TestUnicodeBytes()
+		{
+			AssertEquals ("#N01", (byte)105, Test1.GetNonUnicodeBytes () [1]);
+			AssertEquals ("#N02", (byte)32, Test1.GetNonUnicodeBytes () [5]);
+			AssertEquals ("#N03", (byte)70, Test1.GetUnicodeBytes () [0]);
+			AssertEquals ("#N04", (byte)105, Test1.GetUnicodeBytes () [2]);
+			try {
+				byte test = Test1.GetUnicodeBytes () [105];
+				Fail ("#N05");
+			} catch (Exception e) {
+				AssertEquals ("#N06", typeof (IndexOutOfRangeException), e.GetType());				
+			}
+		}
+				
+                public void TestConversions()
+                {
+
+			SqlString String250 = new SqlString ("250");
+			SqlString String9E300 = new SqlString ("9E300");
+
+                        // ToSqlBoolean ()
+        
+        		try {
+	                        bool test = Test1.ToSqlBoolean ().Value;      			
+        			Fail ("#01");
+        		} catch (Exception e) {
+				AssertEquals ("#01.5", typeof (FormatException), e.GetType());				        			
+        		}
+        		
+        		Assert ("#O02", (new SqlString("1")).ToSqlBoolean ().Value);
+                        Assert ("#O03", !(new SqlString("0")).ToSqlBoolean ().Value);
+                        Assert ("#O04", (new SqlString("True")).ToSqlBoolean ().Value);
+                        Assert ("#O05", !(new SqlString("FALSE")).ToSqlBoolean ().Value);
+                        Assert ("#O06", SqlString.Null.ToSqlBoolean ().IsNull);
+
+                        // ToSqlByte ()
+                        try {
+                        	byte test = Test1.ToSqlByte ().Value;
+                        	Fail ("#07");
+                        } catch (Exception e) {
+                        	AssertEquals ("#O07.5", typeof (FormatException), e.GetType());    
+                        }
+
+			AssertEquals ("#O08", (byte)250, String250.ToSqlByte ().Value);    
+                        try {
+                                SqlByte b = (byte)(new SqlString ("2500")).ToSqlByte ();
+                                Fail ("#O09");
+                        } catch (Exception e) {
+                                AssertEquals ("#O10", typeof (OverflowException), e.GetType ());
+                        }
+
+			// ToSqlDateTime
+			AssertEquals ("#O11", 10, 
+				      (new SqlString ("2002-10-10")).ToSqlDateTime ().Value.Day);
+			
+                        // ToSqlDecimal ()
+			try {
+				AssertEquals ("#O13", (decimal)250, Test1.ToSqlDecimal ().Value);
+				Fail ("#O14");
+			} catch (Exception e) {
+				AssertEquals ("#O15", typeof (FormatException), e.GetType ());
+			}
+
+                        AssertEquals ("#O16", (decimal)250, String250.ToSqlDecimal ().Value);
+
+                        try {
+                                SqlDecimal test = String9E300.ToSqlDecimal ().Value;
+                                Fail ("#O17");
+                        } catch (Exception e) {
+                                AssertEquals ("#O18", typeof (FormatException), e.GetType ());
+                        }      
+
+			// ToSqlDouble
+			AssertEquals ("#O19", (SqlDouble)9e300, String9E300.ToSqlDouble ());
+
+			try {
+				SqlDouble test = (new SqlString ("4e400")).ToSqlDouble ();
+				Fail ("#O20");
+			} catch (Exception e) {
+				AssertEquals ("#O21", typeof (OverflowException), e.GetType ());
+			}
+
+			// ToSqlGuid
+			SqlString TestGuid = new SqlString("11111111-1111-1111-1111-111111111111");
+			AssertEquals ("#O22", new SqlGuid("11111111-1111-1111-1111-111111111111"), TestGuid.ToSqlGuid ());
+
+			try {
+				SqlGuid test = String9E300.ToSqlGuid ();
+			} catch (Exception e) {
+				AssertEquals ("#O23", typeof (FormatException), e.GetType ());
+			}
+			
+                        // ToSqlInt16 ()
+                        AssertEquals ("#O24", (short)250, String250.ToSqlInt16 ().Value);
+
+                        try {
+                                SqlInt16 test = String9E300.ToSqlInt16().Value;
+                                Fail ("#O25");
+                        } catch (Exception e) {
+                                AssertEquals ("#O26", typeof (FormatException), e.GetType ());
+                        }        
+
+                        // ToSqlInt32 ()
+                        AssertEquals ("#O27", (int)250, String250.ToSqlInt32 ().Value);
+
+                        try {
+                                SqlInt32 test = String9E300.ToSqlInt32 ().Value;
+                                Fail ("#O28");
+                        } catch (Exception e) { 
+                                AssertEquals ("#O29", typeof (FormatException), e.GetType ());
+                        }
+
+                        try {
+                                SqlInt32 test = Test1.ToSqlInt32 ().Value;
+                                Fail ("#O30");
+                        } catch (Exception e) { 
+                                AssertEquals ("#O31", typeof (FormatException), e.GetType ());
+                        }
+
+                        // ToSqlInt64 ()
+                        AssertEquals ("#O32", (long)250, String250.ToSqlInt64 ().Value);
+
+                        try {        
+                                SqlInt64 test = String9E300.ToSqlInt64 ().Value;
+                                Fail ("#O33");
+                        } catch (Exception e) {
+                                AssertEquals ("#O34", typeof (FormatException), e.GetType ());
+                        }        
+
+                        // ToSqlMoney ()
+                        AssertEquals ("#O35", (decimal)250, String250.ToSqlMoney ().Value);
+
+                        try {
+                                SqlMoney test = String9E300.ToSqlMoney ().Value;
+                                Fail ("#O36");
+                        } catch (Exception e) {
+                                AssertEquals ("#O37", typeof (FormatException), e.GetType ());
+                        }        
+
+                        // ToSqlSingle ()
+                        AssertEquals ("#O38", (float)250, String250.ToSqlSingle ().Value);
+
+                        try {
+                                SqlSingle test = String9E300.ToSqlSingle().Value;
+                                Fail ("#O39");
+                        } catch (Exception e) {
+                                AssertEquals ("#O40", typeof (OverflowException), e.GetType ());
+                        }        
+
+                        // ToString ()
+                        AssertEquals ("#O41", "First TestString", Test1.ToString ());
+                }
+
+                // OPERATORS
+
+                public void TestArithmeticOperators()
+                {
+			SqlString TestString = new SqlString ("...Testing...");
+			AssertEquals ("#P01", (SqlString)"First TestString...Testing...",
+				      Test1 + TestString);
+			AssertEquals ("#P02", SqlString.Null,
+				      Test1 + SqlString.Null);
+                }
+
+                public void TestThanOrEqualOperators()
+                {
+                        // == -operator
+                        Assert ("#Q01", (Test2 == Test3).Value);
+                        Assert ("#Q02", !(Test1 == Test2).Value);
+                        Assert ("#Q03", (Test1 == SqlString.Null).IsNull);
+                        
+                        // != -operator
+                        Assert ("#Q04", !(Test3 != Test2).Value);
+                        Assert ("#Q05", !(Test2 != Test3).Value);
+                        Assert ("#Q06", (Test1 != Test3).Value);
+                        Assert ("#Q07", (Test1 != SqlString.Null).IsNull);
+
+                        // > -operator
+                        Assert ("#Q08", (Test2 > Test1).Value);
+                        Assert ("#Q09", !(Test1 > Test3).Value);
+                        Assert ("#Q10", !(Test2 > Test3).Value);
+                        Assert ("#Q11", (Test1 > SqlString.Null).IsNull);
+
+                        // >=  -operator
+                        Assert ("#Q12", !(Test1 >= Test3).Value);
+                        Assert ("#Q13", (Test3 >= Test1).Value);
+                        Assert ("#Q14", (Test2 >= Test3).Value);
+                        Assert ("#Q15", (Test1 >= SqlString.Null).IsNull);
+
+                        // < -operator
+                        Assert ("#Q16", (Test1 < Test2).Value);
+                        Assert ("#Q17", (Test1 < Test3).Value);
+                        Assert ("#Q18", !(Test2 < Test3).Value);
+                        Assert ("#Q19", (Test1 < SqlString.Null).IsNull);
+
+                        // <= -operator
+                        Assert ("#Q20", (Test1 <= Test3).Value);
+                        Assert ("#Q21", !(Test3 <= Test1).Value);
+                        Assert ("#Q22", (Test2 <= Test3).Value);
+                        Assert ("#Q23", (Test1 <= SqlString.Null).IsNull);
+                }
+
+                public void TestSqlBooleanToSqlString()
+                {
+                        SqlBoolean TestBoolean = new SqlBoolean (true);
+                        SqlBoolean TestBoolean2 = new SqlBoolean (false);
+                        SqlString Result;
+
+                        Result = (SqlString)TestBoolean;
+                        AssertEquals ("#R01", "True", Result.Value);
+                	
+                	Result = (SqlString)TestBoolean2;
+                        AssertEquals ("#R02", "False", Result.Value);
+                	
+                        Result = (SqlString)SqlBoolean.Null;
+                        Assert ("#R03", Result.IsNull);
+                }
+
+		public void TestSqlByteToBoolean()
+		{
+			SqlByte TestByte = new SqlByte (250);
+			AssertEquals ("#S01", "250", ((SqlString)TestByte).Value);
+			try {
+				SqlString test = ((SqlString)SqlByte.Null).Value;
+				Fail ("#S02");
+			} catch (Exception e) {
+				AssertEquals ("#S03", typeof (SqlNullValueException), e.GetType ());
+			}
+		}
+
+		public void TestSqlDateTimeToSqlString()
+		{			
+			Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-AU");
+			SqlDateTime TestTime = new SqlDateTime(2002, 10, 22, 9, 52, 30);
+			AssertEquals ("#T01", "22/10/2002 9:52:30 AM", ((SqlString)TestTime).Value);			
+		}
+		
+		public void TestSqlDecimalToSqlString()
+		{
+			SqlDecimal TestDecimal = new SqlDecimal (1000.2345);
+			AssertEquals ("#U01", "1000.2345000000000", ((SqlString)TestDecimal).Value);
+		}
+		
+                public void TestSqlDoubleToSqlString()
+                {
+			SqlDouble TestDouble = new SqlDouble (64e64);
+                	AssertEquals ("#V01", "6.4E+65", ((SqlString)TestDouble).Value);
+                }
+
+		public void TestSqlGuidToSqlString()
+		{
+			byte [] b = new byte [16];
+			b [0] = 100;
+			b [1] = 64;
+			SqlGuid TestGuid = new SqlGuid (b);
+			
+			AssertEquals ("#W01", "00004064-0000-0000-0000-000000000000", 
+			              ((SqlString)TestGuid).Value);
+			try {
+				SqlString test = ((SqlString)SqlGuid.Null).Value;
+				Fail ("#W02");
+			} catch (Exception e) {
+				AssertEquals ("#W03", typeof (SqlNullValueException), e.GetType());
+			}
+		}
+		
+		public void TestSqlInt16ToSqlString()
+		{
+			SqlInt16 TestInt = new SqlInt16(20012);
+			AssertEquals ("#X01", "20012", ((SqlString)TestInt).Value);
+			try {
+				SqlString test = ((SqlString)SqlInt16.Null).Value;
+				Fail ("#X02");
+			} catch (Exception e) {
+				AssertEquals ("#X03", typeof (SqlNullValueException), e.GetType ());				
+			}
+		}
+                
+                public void TestSqlInt32ToSqlString()
+                {
+			SqlInt32 TestInt = new SqlInt32(-12456);
+			AssertEquals ("#Y01", "-12456", ((SqlString)TestInt).Value);
+                	try {
+				SqlString test = ((SqlString)SqlInt32.Null).Value;
+                		Fail ("#Y02");
+                	} catch (Exception e) {
+                		AssertEquals ("#Y03", typeof (SqlNullValueException), e.GetType ());                		
+                	}
+                }
+                
+                public void TestSqlInt64ToSqlString()
+                {
+			SqlInt64 TestInt = new SqlInt64(10101010);
+			AssertEquals ("#Z01", "10101010", ((SqlString)TestInt).Value);
+                }
+                
+                public void TestSqlMoneyToSqlString()
+                {
+                	SqlMoney TestMoney = new SqlMoney (646464.6464);
+                	AssertEquals ("#AA01", "646464.6464", ((SqlString)TestMoney).Value);
+                }
+                
+                public void TestSqlSingleToSqlString()
+                {
+                	SqlSingle TestSingle = new SqlSingle (3e20);
+                	AssertEquals ("#AB01", "3E+20", ((SqlString)TestSingle).Value);
+                }
+                                              
+                public void TestSqlStringToString()
+                {
+			AssertEquals ("#AC01", "First TestString",(String)Test1);                	
+                }
+
+		public void TestStringToSqlString()
+		{
+			String TestString = "Test String";
+			AssertEquals ("#AD01", "Test String", ((SqlString)TestString).Value);			
+		}		
+        }
+}
+
+
+