Merge pull request #1909 from esdrubal/reflection
[mono.git] / mcs / class / System / Test / System.ComponentModel / SByteConverterTests.cs
index 901a25252e09f5f5d04d66ca4a68ee3e1b4f6bd2..f4c7ba6579f7ff87403916f3072a0690d10b2fd2 100644 (file)
@@ -41,6 +41,7 @@ namespace MonoTests.System.ComponentModel
                {
                        Assert.IsTrue (converter.CanConvertTo (typeof (string)), "#1");
                        Assert.IsFalse (converter.CanConvertTo (typeof (object)), "#2");
+                       Assert.IsTrue (converter.CanConvertTo (typeof (int)), "#3");
                }
 
                [Test]
@@ -108,6 +109,25 @@ namespace MonoTests.System.ComponentModel
                                converter.ConvertTo (sbyte.MaxValue, typeof (string)), "#3");
                }
 
+               [Test]
+               public void ConvertToString ()
+               {
+                       CultureInfo culture = new MyCultureInfo ();
+                       NumberFormatInfo numberFormatInfo = (NumberFormatInfo) culture.GetFormat (typeof (NumberFormatInfo));
+
+                       Assert.AreEqual (numberFormatInfo.NegativeSign + "5", converter.ConvertToString (null, culture, (sbyte) -5), "#1");
+                       Assert.AreEqual (culture.NumberFormat.NegativeSign + "5", converter.ConvertToString (null, culture, (short) -5), "#2");
+               }
+
+               [Test]
+               public void ConvertFromString ()
+               {
+                       CultureInfo culture = new MyCultureInfo ();
+                       NumberFormatInfo numberFormatInfo = (NumberFormatInfo) culture.GetFormat (typeof (NumberFormatInfo));
+
+                       Assert.AreEqual (-5, converter.ConvertFrom (null, culture, numberFormatInfo.NegativeSign + "5"));
+               }
+
                [Test]
                public void ConvertFromString_Invalid1 ()
                {
@@ -225,6 +245,38 @@ namespace MonoTests.System.ComponentModel
                                Assert.AreEqual (typeof (OverflowException), ex.InnerException.GetType (), "#3");
                        }
                }
+
+               [Serializable]
+               private sealed class MyCultureInfo : CultureInfo
+               {
+                       internal MyCultureInfo ()
+                               : base ("en-US")
+                       {
+                       }
+
+                       public override object GetFormat (Type formatType)
+                       {
+                               if (formatType == typeof (NumberFormatInfo)) {
+                                       NumberFormatInfo nfi = (NumberFormatInfo) ((NumberFormatInfo) base.GetFormat (formatType)).Clone ();
+
+                                       nfi.NegativeSign = "myNegativeSign";
+                                       return NumberFormatInfo.ReadOnly (nfi);
+                               } else {
+                                       return base.GetFormat (formatType);
+                               }
+                       }
+
+// adding this override in 1.x shows different result in .NET (it is ignored).
+// Some compatibility kids might want to fix this issue.
+                       public override NumberFormatInfo NumberFormat {
+                               get {
+                                       NumberFormatInfo nfi = (NumberFormatInfo) base.NumberFormat.Clone ();
+                                       nfi.NegativeSign = "myNegativeSign";
+                                       return nfi;
+                               }
+                               set { throw new NotSupportedException (); }
+                       }
+               }
        }
 }