2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.Data / Test / System.Data.SqlTypes / SqlStringTest.cs
index 103a7ea2f4cde23447bf5787309a0f3bca883956..3ec66d536d8f26a491e4e9d520e2113b79880659 100644 (file)
@@ -8,6 +8,29 @@
 // (C) 2003 Martin Willemoes Hansen
 // 
 
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using NUnit.Framework;
 using System;
 using System.Data.SqlTypes;
@@ -113,19 +136,21 @@ namespace MonoTests.System.Data.SqlTypes
                [Test]
                 public void Properties()
                 {
-                        // CompareInfo
-                        AssertEquals ("#C01", 3081, Test1.CompareInfo.LCID);
+/* Comment out: This test will succeed only when you're in en-au culture.
+                       // CompareInfo
+                       AssertEquals ("#C01", 3081, Test1.CompareInfo.LCID);
 
                         // CultureInfo
-                        AssertEquals ("#C02", 3081, Test1.CultureInfo.LCID);                
+                       AssertEquals ("#C02", 3081, Test1.CultureInfo.LCID);             
+
+                        // LCID
+                        AssertEquals ("#C05", 3081, Test1.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 ());
@@ -182,7 +207,7 @@ namespace MonoTests.System.Data.SqlTypes
                        Assert ("#D11", T2.CompareTo (T1) != 0);
 
                        // IgnoreNonSpace
-                        T1 = new SqlString ("TESTñ", 2057, SqlCompareOptions.IgnoreNonSpace);
+                        T1 = new SqlString ("TEST\xF1", 2057, SqlCompareOptions.IgnoreNonSpace);
                        T2 = new SqlString ("TESTn", 2057, SqlCompareOptions.IgnoreNonSpace);
                        Assert ("#D12", T2.CompareTo (T1) == 0);
                 
@@ -341,6 +366,104 @@ namespace MonoTests.System.Data.SqlTypes
                         }
                 }
                       
+               [Test]
+               [ExpectedException(typeof (FormatException))]
+               public void ConversionBoolFormatException1 ()
+               {
+                       bool test = Test1.ToSqlBoolean ().Value;                              
+               }
+
+               [Test]
+               [ExpectedException(typeof (FormatException))]
+               public void ConversionByteFormatException ()
+               {
+                       byte test = Test1.ToSqlByte ().Value;
+               }
+
+               [Test]
+               [ExpectedException(typeof (FormatException))]
+               public void ConversionDecimalFormatException1 ()
+               {
+                       Decimal d = Test1.ToSqlDecimal ().Value;
+               }
+
+               [Test]
+               [ExpectedException(typeof (FormatException))]
+               public void ConversionDecimalFormatException2 ()
+               {
+                        SqlString String9E300 = new SqlString ("9E+300");
+                       SqlDecimal test = String9E300.ToSqlDecimal ();
+               }
+
+               [Test]
+               [ExpectedException(typeof (FormatException))]
+               public void ConversionGuidFormatException ()
+               {
+                        SqlString String9E300 = new SqlString ("9E+300");
+                       SqlGuid test = String9E300.ToSqlGuid ();
+               }
+
+               [Test]
+               [ExpectedException(typeof (FormatException))]
+               public void ConversionInt16FormatException ()
+               {
+                        SqlString String9E300 = new SqlString ("9E+300");
+                       SqlInt16 test = String9E300.ToSqlInt16().Value;
+               }
+
+               [Test]
+               [ExpectedException(typeof (FormatException))]
+               public void ConversionInt32FormatException1 ()
+               {
+                        SqlString String9E300 = new SqlString ("9E+300");
+                       SqlInt32 test = String9E300.ToSqlInt32 ().Value;
+               }
+
+               [Test]
+               [ExpectedException(typeof (FormatException))]
+               public void ConversionInt32FormatException2 ()
+               {
+                       SqlInt32 test = Test1.ToSqlInt32 ().Value;
+               }
+
+               [Test]
+               [ExpectedException(typeof (FormatException))]
+               public void ConversionInt64FormatException ()
+               {
+                        SqlString String9E300 = new SqlString ("9E+300");
+                       SqlInt64 test = String9E300.ToSqlInt64 ().Value;
+               }
+
+               [Test]
+               [ExpectedException(typeof (FormatException))]
+               public void ConversionIntMoneyFormatException2 ()
+               {
+                        SqlString String9E300 = new SqlString ("9E+300");
+                       SqlMoney test = String9E300.ToSqlMoney ().Value;
+               }
+
+               [Test]
+               [ExpectedException(typeof(OverflowException))]
+               public void ConversionByteOverflowException ()
+               {
+                       SqlByte b = (new SqlString ("2500")).ToSqlByte ();
+               }
+
+               [Test]
+               [ExpectedException(typeof(OverflowException))]
+               public void ConversionDoubleOverflowException ()
+               {
+                       SqlDouble test = (new SqlString ("4e400")).ToSqlDouble ();
+               }
+
+               [Test]
+               [ExpectedException(typeof(OverflowException))]
+               public void ConversionSingleOverflowException ()
+               {
+                        SqlString String9E300 = new SqlString ("9E+300");
+                       SqlSingle test = String9E300.ToSqlSingle().Value;
+               }
+
                [Test]          
                 public void Conversions()
                 {
@@ -348,15 +471,7 @@ namespace MonoTests.System.Data.SqlTypes
                         SqlString String250 = new SqlString ("250");
                         SqlString String9E300 = new SqlString ("9E+300");
 
-                        // ToSqlBoolean ()
-        
-                        try {
-                                bool test = Test1.ToSqlBoolean ().Value;                              
-                                Fail ("#01");
-                        } catch (Exception e) {
-                                AssertEquals ("#01.5", typeof (FormatException), e.GetType());                                                                
-                        }
-                        
+                        // ToSqlBoolean ()                                
                         Assert ("#O02", (new SqlString("1")).ToSqlBoolean ().Value);
                         Assert ("#O03", !(new SqlString("0")).ToSqlBoolean ().Value);
                         Assert ("#O04", (new SqlString("True")).ToSqlBoolean ().Value);
@@ -364,119 +479,38 @@ namespace MonoTests.System.Data.SqlTypes
                         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)9E+300, 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);
+                        AssertEquals ("#O35", 250.0000M, 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 ());
                 }
@@ -574,7 +608,7 @@ namespace MonoTests.System.Data.SqlTypes
                 public void SqlDecimalToSqlString()
                 {
                         SqlDecimal TestDecimal = new SqlDecimal (1000.2345);
-                        AssertEquals ("#U01", "1000.2345000000000", ((SqlString)TestDecimal).Value);
+                       AssertEquals ("#U01", "1000.2345000000000", ((SqlString)TestDecimal).Value);
                 }
                 
                [Test]
@@ -661,6 +695,19 @@ namespace MonoTests.System.Data.SqlTypes
                         String TestString = "Test String";
                         AssertEquals ("#AD01", "Test String", ((SqlString)TestString).Value);                        
                 }                
+               
+                #if NET_2_0
+                [Test]
+                public void AddSqlString()
+                {
+                        AssertEquals ("#AE01","First TestStringThis is just a test SqlString",(String)(SqlString.Add(Test1, Test2)));
+                        AssertEquals ("#AE02","First TestStringPlainString", (String)(SqlString.Add (Test1, "PlainString")));
+                        Assert ("#AE03",(SqlString.Add (Test1, null)).IsNull);
+                }
+                #endif
+
+
+
         }
 }