2006-11-07 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / System / Test / System.ComponentModel / ByteConverterTests.cs
index 42381d551a97cd5e80cd082d6c62a400bf4c17e7..ca6a8cd78f49c00b3d28fe1cbe86c60c2d986375 100644 (file)
@@ -64,6 +64,15 @@ namespace MonoTests.System.ComponentModel
                        Assert.AreEqual (byte.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "0XFF"), "#6");
                }
 
+               [Test]
+               public void ConvertToString ()
+               {
+                       CultureInfo culture = new MyCultureInfo ();
+                       NumberFormatInfo numberFormatInfo = (NumberFormatInfo) culture.GetFormat (typeof (NumberFormatInfo));
+
+                       Assert.AreEqual (culture.NumberFormat.NegativeSign + "5", converter.ConvertToString (null, culture, -5));
+               }
+
                [Test]
                [ExpectedException (typeof (NotSupportedException))]
                public void ConvertFrom_Object ()
@@ -505,5 +514,39 @@ 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);
+                               }
+                       }
+
+#if NET_2_0
+// 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 (); }
+                       }
+#endif
+               }
        }
 }