2 // System.ComponentModel.UInt16Converter test cases
5 // Gert Driesen (drieseng@users.sourceforge.net)
7 // (c) 2005 Novell, Inc. (http://www.ximian.com)
11 using System.ComponentModel;
12 using System.ComponentModel.Design.Serialization;
13 using System.Globalization;
15 using NUnit.Framework;
17 namespace MonoTests.System.ComponentModel
20 public class UInt16ConverterTests
22 private UInt16Converter converter;
27 converter = new UInt16Converter ();
31 public void CanConvertFrom ()
33 Assert.IsTrue (converter.CanConvertFrom (typeof (string)), "#1");
34 Assert.IsFalse (converter.CanConvertFrom (typeof (short)), "#2");
35 Assert.IsFalse (converter.CanConvertFrom (typeof (object)), "#3");
36 Assert.IsTrue (converter.CanConvertFrom (typeof (InstanceDescriptor)), "#4");
40 public void CanConvertTo ()
42 Assert.IsTrue (converter.CanConvertTo (typeof (string)), "#1");
43 Assert.IsFalse (converter.CanConvertTo (typeof (object)), "#2");
47 public void ConvertFrom_MinValue ()
49 Assert.AreEqual (ushort.MinValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#0"), "#1");
50 Assert.AreEqual (ushort.MinValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#0x0"), "#2");
51 Assert.AreEqual (ushort.MinValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#0X0"), "#3");
52 Assert.AreEqual (ushort.MinValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "0x0"), "#4");
53 Assert.AreEqual (ushort.MinValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "0X0"), "#5");
57 public void ConvertFrom_MaxValue ()
59 Assert.AreEqual (ushort.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#ffff"), "#1");
60 Assert.AreEqual (ushort.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#FFFF"), "#2");
61 Assert.AreEqual (ushort.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#0xffff"), "#3");
62 Assert.AreEqual (ushort.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#0XFFFF"), "#4");
63 Assert.AreEqual (ushort.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "0xffff"), "#5");
64 Assert.AreEqual (ushort.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "0XFFFF"), "#6");
68 [ExpectedException (typeof (NotSupportedException))]
69 public void ConvertFrom_Object ()
71 converter.ConvertFrom (new object ());
75 [ExpectedException (typeof (NotSupportedException))]
76 public void ConvertFrom_Int16 ()
78 converter.ConvertFrom ((short) 10);
82 [ExpectedException (typeof (NotSupportedException))]
83 public void ConvertFrom_Int32 ()
85 converter.ConvertFrom (10);
89 public void ConvertTo_MinValue ()
91 Assert.AreEqual (ushort.MinValue.ToString (CultureInfo.InvariantCulture),
92 converter.ConvertTo (null, CultureInfo.InvariantCulture, ushort.MinValue,
93 typeof (string)), "#1");
94 Assert.AreEqual (ushort.MinValue.ToString (CultureInfo.CurrentCulture),
95 converter.ConvertTo (null, CultureInfo.CurrentCulture, ushort.MinValue,
96 typeof (string)), "#2");
97 Assert.AreEqual (ushort.MinValue.ToString (CultureInfo.CurrentCulture),
98 converter.ConvertTo (ushort.MinValue, typeof (string)), "#3");
102 public void ConvertTo_MaxValue ()
104 Assert.AreEqual (ushort.MaxValue.ToString (CultureInfo.InvariantCulture),
105 converter.ConvertTo (null, CultureInfo.InvariantCulture, ushort.MaxValue,
106 typeof (string)), "#1");
107 Assert.AreEqual (ushort.MaxValue.ToString (CultureInfo.CurrentCulture),
108 converter.ConvertTo (null, CultureInfo.CurrentCulture, ushort.MaxValue,
109 typeof (string)), "#2");
110 Assert.AreEqual (ushort.MaxValue.ToString (CultureInfo.CurrentCulture),
111 converter.ConvertTo (ushort.MaxValue, typeof (string)), "#3");
115 public void ConvertFromString_Invalid1 ()
118 converter.ConvertFromString (null, CultureInfo.InvariantCulture, "*1");
120 } catch (Exception ex) {
121 Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
122 Assert.IsNotNull (ex.InnerException, "#3");
123 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
128 public void ConvertFromString_Invalid2 ()
131 converter.ConvertFromString (null, CultureInfo.InvariantCulture,
132 double.MaxValue.ToString(CultureInfo.InvariantCulture));
134 } catch (Exception ex) {
135 Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
136 Assert.IsNotNull (ex.InnerException, "#3");
137 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
142 public void ConvertFromString_Invalid3 ()
145 converter.ConvertFromString ("*1");
147 } catch (Exception ex) {
148 Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
149 Assert.IsNotNull (ex.InnerException, "#3");
150 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
155 public void ConvertFromString_Invalid4 ()
158 converter.ConvertFromString (double.MaxValue.ToString (CultureInfo.CurrentCulture));
160 } catch (Exception ex) {
161 Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
162 Assert.IsNotNull (ex.InnerException, "#3");
163 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
168 public void ConvertFrom_InvalidString1 ()
171 converter.ConvertFrom (null, CultureInfo.InvariantCulture, "*1");
173 } catch (Exception ex) {
174 Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
175 Assert.IsNotNull (ex.InnerException, "#3");
176 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
181 public void ConvertFrom_InvalidString2 ()
184 converter.ConvertFrom (null, CultureInfo.InvariantCulture,
185 double.MaxValue.ToString (CultureInfo.InvariantCulture));
187 } catch (Exception ex) {
188 Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
189 Assert.IsNotNull (ex.InnerException, "#3");
190 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
195 public void ConvertFrom_InvalidString3 ()
198 converter.ConvertFrom ("*1");
200 } catch (Exception ex) {
201 Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
202 Assert.IsNotNull (ex.InnerException, "#3");
203 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
208 public void ConvertFrom_InvalidString4 ()
211 converter.ConvertFrom (double.MaxValue.ToString (CultureInfo.CurrentCulture));
213 } catch (Exception ex) {
214 Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
215 Assert.IsNotNull (ex.InnerException, "#3");
216 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");