2 // System.ComponentModel.UInt64Converter 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 UInt64ConverterTests
22 private UInt64Converter converter;
27 converter = new UInt64Converter ();
31 public void CanConvertFrom ()
33 Assert.IsTrue (converter.CanConvertFrom (typeof (string)), "#1");
34 Assert.IsFalse (converter.CanConvertFrom (typeof (ulong)), "#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 (ulong.MinValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#0"), "#1");
50 Assert.AreEqual (ulong.MinValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#0x0"), "#2");
51 Assert.AreEqual (ulong.MinValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#0X0"), "#3");
52 Assert.AreEqual (ulong.MinValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "0x0"), "#4");
53 Assert.AreEqual (ulong.MinValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "0X0"), "#5");
57 public void ConvertFrom_MaxValue ()
59 Assert.AreEqual (ulong.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#ffffffffffffffff"), "#1");
60 Assert.AreEqual (ulong.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#FFFFFFFFFFFFFFFF"), "#2");
61 Assert.AreEqual (ulong.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#0xffffffffffffffff"), "#3");
62 Assert.AreEqual (ulong.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "#0XFFFFFFFFFFFFFFFF"), "#4");
63 Assert.AreEqual (ulong.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "0xffffffffffffffff"), "#5");
64 Assert.AreEqual (ulong.MaxValue, converter.ConvertFrom (null, CultureInfo.InvariantCulture, "0XFFFFFFFFFFFFFFFF"), "#6");
68 [ExpectedException (typeof (NotSupportedException))]
69 public void ConvertFrom_Object ()
71 converter.ConvertFrom (new object ());
75 [ExpectedException (typeof (NotSupportedException))]
76 public void ConvertFrom_Int32 ()
78 converter.ConvertFrom (10);
82 public void ConvertTo_MinValue ()
84 Assert.AreEqual (ulong.MinValue.ToString (CultureInfo.InvariantCulture),
85 converter.ConvertTo (null, CultureInfo.InvariantCulture, ulong.MinValue,
86 typeof (string)), "#1");
87 Assert.AreEqual (ulong.MinValue.ToString (CultureInfo.CurrentCulture),
88 converter.ConvertTo (null, CultureInfo.CurrentCulture, ulong.MinValue,
89 typeof (string)), "#2");
90 Assert.AreEqual (ulong.MinValue.ToString (CultureInfo.CurrentCulture),
91 converter.ConvertTo (ulong.MinValue, typeof (string)), "#3");
95 public void ConvertTo_MaxValue ()
97 Assert.AreEqual (ulong.MaxValue.ToString (CultureInfo.InvariantCulture),
98 converter.ConvertTo (null, CultureInfo.InvariantCulture, ulong.MaxValue,
99 typeof (string)), "#1");
100 Assert.AreEqual (ulong.MaxValue.ToString (CultureInfo.CurrentCulture),
101 converter.ConvertTo (null, CultureInfo.CurrentCulture, ulong.MaxValue,
102 typeof (string)), "#2");
103 Assert.AreEqual (ulong.MaxValue.ToString (CultureInfo.CurrentCulture),
104 converter.ConvertTo (ulong.MaxValue, typeof (string)), "#3");
108 public void ConvertFromString_Invalid1 ()
111 converter.ConvertFromString (null, CultureInfo.InvariantCulture, "*1");
113 } catch (AssertionException) {
115 } catch (Exception ex) {
116 Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
117 Assert.IsNotNull (ex.InnerException, "#3");
118 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
123 public void ConvertFromString_Invalid2 ()
126 converter.ConvertFromString (null, CultureInfo.InvariantCulture,
127 double.MaxValue.ToString(CultureInfo.InvariantCulture));
129 } catch (AssertionException) {
131 } catch (Exception ex) {
132 Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
133 Assert.IsNotNull (ex.InnerException, "#3");
134 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
139 public void ConvertFromString_Invalid3 ()
142 converter.ConvertFromString ("*1");
144 } catch (AssertionException) {
146 } catch (Exception ex) {
147 Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
148 Assert.IsNotNull (ex.InnerException, "#3");
149 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
154 public void ConvertFromString_Invalid4 ()
157 converter.ConvertFromString (double.MaxValue.ToString (CultureInfo.CurrentCulture));
159 } catch (AssertionException) {
161 } catch (Exception ex) {
162 Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
163 Assert.IsNotNull (ex.InnerException, "#3");
164 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
169 public void ConvertFrom_InvalidString1 ()
172 converter.ConvertFrom (null, CultureInfo.InvariantCulture, "*1");
174 } catch (AssertionException) {
176 } catch (Exception ex) {
177 Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
178 Assert.IsNotNull (ex.InnerException, "#3");
179 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
184 public void ConvertFrom_InvalidString2 ()
187 converter.ConvertFrom (null, CultureInfo.InvariantCulture,
188 double.MaxValue.ToString (CultureInfo.InvariantCulture));
190 } catch (AssertionException) {
192 } catch (Exception ex) {
193 Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
194 Assert.IsNotNull (ex.InnerException, "#3");
195 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
200 public void ConvertFrom_InvalidString3 ()
203 converter.ConvertFrom ("*1");
205 } catch (AssertionException) {
207 } catch (Exception ex) {
208 Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
209 Assert.IsNotNull (ex.InnerException, "#3");
210 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
215 public void ConvertFrom_InvalidString4 ()
218 converter.ConvertFrom (double.MaxValue.ToString (CultureInfo.CurrentCulture));
220 } catch (AssertionException) {
222 } catch (Exception ex) {
223 Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
224 Assert.IsNotNull (ex.InnerException, "#3");
225 Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");