In .:
[mono.git] / mcs / class / System / Test / System.ComponentModel / UInt64ConverterTests.cs
1 //
2 // System.ComponentModel.UInt64Converter test cases
3 //
4 // Authors:
5 //      Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // (c) 2005 Novell, Inc. (http://www.ximian.com)
8 //
9
10 using System;
11 using System.ComponentModel;
12 using System.ComponentModel.Design.Serialization;
13 using System.Globalization;
14
15 using NUnit.Framework;
16
17 namespace MonoTests.System.ComponentModel
18 {
19         [TestFixture]
20         public class UInt64ConverterTests
21         {
22                 private UInt64Converter converter;
23                 
24                 [SetUp]
25                 public void SetUp ()
26                 {
27                         converter = new UInt64Converter ();
28                 }
29
30                 [Test]
31                 public void CanConvertFrom ()
32                 {
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");
37                 }
38
39                 [Test]
40                 public void CanConvertTo ()
41                 {
42                         Assert.IsTrue (converter.CanConvertTo (typeof (string)), "#1");
43                         Assert.IsFalse (converter.CanConvertTo (typeof (object)), "#2");
44                 }
45
46                 [Test]
47                 public void ConvertFrom_MinValue ()
48                 {
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");
54                 }
55
56                 [Test]
57                 public void ConvertFrom_MaxValue ()
58                 {
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");
65                 }
66
67                 [Test]
68                 [ExpectedException (typeof (NotSupportedException))]
69                 public void ConvertFrom_Object ()
70                 {
71                         converter.ConvertFrom (new object ());
72                 }
73
74                 [Test]
75                 [ExpectedException (typeof (NotSupportedException))]
76                 public void ConvertFrom_Int32 ()
77                 {
78                         converter.ConvertFrom (10);
79                 }
80
81                 [Test]
82                 public void ConvertTo_MinValue ()
83                 {
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");
92                 }
93
94                 [Test]
95                 public void ConvertTo_MaxValue ()
96                 {
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");
105                 }
106
107                 [Test]
108                 public void ConvertFromString_Invalid1 ()
109                 {
110                         try {
111                                 converter.ConvertFromString (null, CultureInfo.InvariantCulture, "*1");
112                                 Assert.Fail ("#1");
113                         } catch (AssertionException) {
114                                 throw;
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");
119                         }
120                 }
121
122                 [Test]
123                 public void ConvertFromString_Invalid2 ()
124                 {
125                         try {
126                                 converter.ConvertFromString (null, CultureInfo.InvariantCulture,
127                                         double.MaxValue.ToString(CultureInfo.InvariantCulture));
128                                 Assert.Fail ("#1");
129                         } catch (AssertionException) {
130                                 throw;
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");
135                         }
136                 }
137
138                 [Test]
139                 public void ConvertFromString_Invalid3 ()
140                 {
141                         try {
142                                 converter.ConvertFromString ("*1");
143                                 Assert.Fail ("#1");
144                         } catch (AssertionException) {
145                                 throw;
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");
150                         }
151                 }
152
153                 [Test]
154                 public void ConvertFromString_Invalid4 ()
155                 {
156                         try {
157                                 converter.ConvertFromString (double.MaxValue.ToString (CultureInfo.CurrentCulture));
158                                 Assert.Fail ("#1");
159                         } catch (AssertionException) {
160                                 throw;
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");
165                         }
166                 }
167
168                 [Test]
169                 public void ConvertFrom_InvalidString1 ()
170                 {
171                         try {
172                                 converter.ConvertFrom (null, CultureInfo.InvariantCulture, "*1");
173                                 Assert.Fail ("#1");
174                         } catch (AssertionException) {
175                                 throw;
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");
180                         }
181                 }
182
183                 [Test]
184                 public void ConvertFrom_InvalidString2 ()
185                 {
186                         try {
187                                 converter.ConvertFrom (null, CultureInfo.InvariantCulture,
188                                         double.MaxValue.ToString (CultureInfo.InvariantCulture));
189                                 Assert.Fail ("#1");
190                         } catch (AssertionException) {
191                                 throw;
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");
196                         }
197                 }
198
199                 [Test]
200                 public void ConvertFrom_InvalidString3 ()
201                 {
202                         try {
203                                 converter.ConvertFrom ("*1");
204                                 Assert.Fail ("#1");
205                         } catch (AssertionException) {
206                                 throw;
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");
211                         }
212                 }
213
214                 [Test]
215                 public void ConvertFrom_InvalidString4 ()
216                 {
217                         try {
218                                 converter.ConvertFrom (double.MaxValue.ToString (CultureInfo.CurrentCulture));
219                                 Assert.Fail ("#1");
220                         } catch (AssertionException) {
221                                 throw;
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");
226                         }
227                 }
228         }
229 }
230