* CharConverter.cs: Use trimmed value in FormatException.
[mono.git] / mcs / class / System / Test / System.ComponentModel / UInt16ConverterTests.cs
index 399dda788bad5ed69294ba485e8f03955cdb92ee..ad6a982dee670f7a8a317009f85db1bd252a5a9a 100644 (file)
@@ -111,6 +111,15 @@ namespace MonoTests.System.ComponentModel
                                converter.ConvertTo (ushort.MaxValue, typeof (string)), "#3");
                }
 
+               [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]
                public void ConvertFromString_Invalid1 ()
                {
@@ -216,6 +225,38 @@ namespace MonoTests.System.ComponentModel
                                Assert.AreEqual (typeof (FormatException), 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
+               }
        }
 }
-