2009-07-11 Michael Barker <mike@middlesoft.co.uk>
[mono.git] / mcs / class / corlib / Test / System / ConvertTest.cs
1 // TestConvert.cs - NUnit Test Cases for System.Convert class
2 //
3 // Krister Hansson (ds99krha@thn.htu.se)
4 // Andreas Jonsson (ds99anjn@thn.htu.se)
5 // 
6 // (C) Krister Hansson & Andreas Jonsson
7 // 
8
9 using NUnit.Framework;
10 using System;
11 using System.Globalization;
12
13 namespace MonoTests.System {
14
15         [TestFixture]
16         public class ConvertTest {
17
18                 bool boolTrue;
19                 bool boolFalse;
20                 byte tryByte;
21                 char tryChar;
22                 DateTime tryDT;
23                 decimal tryDec;
24                 double tryDbl;
25                 short tryInt16;
26                 int tryInt32;
27                 long tryInt64;
28                 object tryObj;
29                 sbyte trySByte;
30                 float tryFloat;
31                 string falseString;
32                 string trueString;
33                 string nullString;
34                 string tryStr;
35                 ushort tryUI16;
36                 uint tryUI32;
37                 ulong tryUI64;
38                 CultureInfo ci;
39
40                 [SetUp]         
41                 public void SetUp ()
42                 {
43                         boolTrue = true;
44                         boolFalse = false;
45                         tryByte = 0;
46                         tryChar = 'a';
47                         tryDT = new DateTime(2002,1,1);
48                         tryDec = 1234.2345m;
49                         tryDbl = 0;
50                         tryInt16 = 1234;
51                         tryInt32 = 12345;
52                         tryInt64 = 123456789012;
53                         tryObj = new Object();
54                         trySByte = 123;
55                         tryFloat = 1234.2345f;
56                         falseString = "false";
57                         trueString = "true";
58                         nullString = "null";
59                         tryStr = "foobar";
60                         tryUI16 = 34567;
61                         tryUI32 = 567891234;
62                         tryUI64 = 0;
63                         ci = new CultureInfo("en-US");
64                         ci.NumberFormat.NumberDecimalDigits = 3;
65                 }
66
67                 public void TestChangeType() {
68                         int iTest = 1;
69                         try {
70                                 Assert.AreEqual ((short)12345, Convert.ChangeType(tryInt32, typeof(short)), "#A01");
71                                 iTest++;
72                                 Assert.AreEqual ('A', Convert.ChangeType(65, typeof(char)), "#A02");
73                                 iTest++;
74                                 Assert.AreEqual (66, Convert.ChangeType('B', typeof(int)), "#A03");
75                                 iTest++;
76                                 Assert.AreEqual (((ulong)12345), Convert.ChangeType(tryInt32, typeof(ulong)), "#A04");
77                                 
78                                 iTest++;
79                                 Assert.AreEqual (true, Convert.ChangeType(tryDec, TypeCode.Boolean), "#A05");
80                                 iTest++;
81                                 Assert.AreEqual ('f', Convert.ChangeType("f", TypeCode.Char), "#A06");
82                                 iTest++;
83                                 Assert.AreEqual ((decimal)123456789012, Convert.ChangeType(tryInt64, TypeCode.Decimal), "#A07");
84                                 iTest++;
85                                 Assert.AreEqual ((int)34567, Convert.ChangeType(tryUI16, TypeCode.Int32), "#A08");
86
87                                 iTest++;
88                                 Assert.AreEqual ((double)567891234, Convert.ChangeType(tryUI32, typeof(double), ci), "#A09");
89                                 iTest++;
90                                 Assert.AreEqual ((ushort)0, Convert.ChangeType(tryByte, typeof(ushort), ci), "#A10");
91                                 iTest++;
92                                 Assert.AreEqual ((decimal)567891234, Convert.ChangeType(tryUI32, typeof(decimal), ci), "#A11");
93                                 iTest++;
94                                 Assert.AreEqual ((float)1234, Convert.ChangeType(tryInt16, typeof(float), ci), "#A12");
95                                 iTest++;
96                                 Assert.AreEqual (null, Convert.ChangeType(null, null, ci), "#A13");
97
98                                 iTest++;
99                                 Assert.AreEqual ((decimal)0, Convert.ChangeType(tryByte, TypeCode.Decimal, ci), "#A14");
100                                 iTest++;
101                                 Assert.AreEqual ("f", Convert.ChangeType('f', TypeCode.String, ci), "#A15");
102                                 iTest++;
103                                 Assert.AreEqual ('D', Convert.ChangeType(68, TypeCode.Char, ci), "#A16");
104                                 iTest++;
105                                 Assert.AreEqual ((long)34567, Convert.ChangeType(tryUI16, TypeCode.Int64, ci), "#A17");
106                                 iTest++;
107                                 Assert.AreEqual (null, Convert.ChangeType(null, TypeCode.Empty, ci), "#A18");
108                         } catch (Exception e) {
109                                 Assert.Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e);
110                         }
111                         
112                         try {
113                                 Convert.ChangeType(boolTrue, typeof(char));
114                                 Assert.Fail ();
115                         }
116                         catch (Exception e) {
117                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#A25");
118                         }
119                         
120                         try {
121                                 Convert.ChangeType(tryChar, typeof(DateTime));
122                                 Assert.Fail ();
123                         }
124                         catch (Exception e) {
125                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#A26");
126                         }
127
128                         try {
129                                 Convert.ChangeType(ci, TypeCode.String);
130                                 Assert.Fail ();
131                         }
132                         catch (Exception e) {
133                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#A27");
134                         }
135
136                         try {
137                                 Convert.ChangeType(tryInt32, null);
138                                 Assert.Fail ();
139                         }
140                         catch (Exception e) {
141                                 Assert.AreEqual (typeof(ArgumentNullException), e.GetType(), "#A28");
142                         }
143
144                         try 
145                         {
146                                 Convert.ChangeType(boolTrue, typeof(DateTime), ci);
147                                 Assert.Fail ();
148                         }
149                         catch (Exception e) {
150                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#A29");
151                         }
152                         
153                         try {
154                                 Convert.ChangeType(ci, typeof(DateTime), ci);
155                                 Assert.Fail ();
156                         }
157                         catch (Exception e) {
158                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#A30");
159                         }
160
161                         /* Should throw ArgumentException but throws InvalidCastException
162                         try {
163                                 Convert.ChangeType(tryUI32, typeof(FormatException), ci);
164                                 Assert.Fail ();
165                         }
166                         catch (Exception e) {
167                                 Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#A??");
168                         }*/
169
170                         try {
171                                 Convert.ChangeType(tryUI32, TypeCode.Byte, ci);
172                                 Assert.Fail ();
173                         }
174                         catch (Exception e) {
175                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#A31");
176                         }
177
178                         try {
179                                 Convert.ChangeType(boolTrue, TypeCode.Char, ci);
180                                 Assert.Fail ();
181                         }
182                         catch (Exception e) {
183                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#A32");
184                         }
185
186                         try {
187                                 Convert.ChangeType(boolTrue, null, ci);
188                                 Assert.Fail ();
189                         }
190                         catch (Exception e) {
191                                 Assert.AreEqual (typeof(ArgumentNullException), e.GetType(), "#A33");
192                         }
193
194                         try {
195                                 /* should fail to convert string to any enumeration type. */
196                                 Convert.ChangeType("random string", typeof(DayOfWeek));
197                                 Assert.Fail ();
198                         }
199                         catch (Exception e) {
200                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#A34");
201                         }
202
203                 }               
204
205                 public void TestGetTypeCode() {
206                         int marker = 1;
207                         try {
208                                 Assert.AreEqual (TypeCode.String, Convert.GetTypeCode(tryStr), "#B01");
209                                 marker++;
210                                 Assert.AreEqual (TypeCode.UInt16, Convert.GetTypeCode(tryUI16), "#B02");
211                                 marker++;
212                                 Assert.AreEqual (TypeCode.UInt32, Convert.GetTypeCode(tryUI32), "#B03");
213                                 marker++;
214                                 Assert.AreEqual (TypeCode.UInt64, Convert.GetTypeCode(tryUI64), "#B04");
215                                 marker++;
216                                 Assert.AreEqual (TypeCode.Double, Convert.GetTypeCode(tryDbl), "#B05");
217                                 marker++;
218                                 Assert.AreEqual (TypeCode.Int16, Convert.GetTypeCode(tryInt16), "#B06");
219                                 marker++;
220                                 Assert.AreEqual (TypeCode.Int64, Convert.GetTypeCode(tryInt64), "#B07");
221                                 marker++;
222                                 Assert.AreEqual (TypeCode.Object, Convert.GetTypeCode(tryObj), "#B08");
223                                 marker++;
224                                 Assert.AreEqual (TypeCode.SByte, Convert.GetTypeCode(trySByte), "#B09");
225                                 marker++;
226                                 Assert.AreEqual (TypeCode.Single, Convert.GetTypeCode(tryFloat), "#B10");
227                                 marker++;
228                                 Assert.AreEqual (TypeCode.Byte, Convert.GetTypeCode(tryByte), "#B11");
229                                 marker++;
230                                 Assert.AreEqual (TypeCode.Char, Convert.GetTypeCode(tryChar), "#B12");
231                                 marker++;
232 //                              Assert.AreEqual (TypeCode.DateTime, Convert.GetTypeCode(tryDT), "#B13");
233                                 marker++;
234                                 Assert.AreEqual (TypeCode.Decimal, Convert.GetTypeCode(tryDec), "#B14");
235                                 marker++;
236                                 Assert.AreEqual (TypeCode.Int32, Convert.GetTypeCode(tryInt32), "#B15");
237                                 marker++;
238                                 Assert.AreEqual (TypeCode.Boolean, Convert.GetTypeCode(boolTrue), "#B16");
239                         } catch (Exception e) {
240                                 Assert.Fail ("Unexpected exception at " + marker + ": " + e);
241                         }
242                 }
243
244                 public void TestIsDBNull() {
245                         Assert.AreEqual (false, Convert.IsDBNull(tryInt32), "#C01");
246                         Assert.AreEqual (true, Convert.IsDBNull(Convert.DBNull), "#C02");
247                         Assert.AreEqual (false, Convert.IsDBNull(boolTrue), "#C03");
248                         Assert.AreEqual (false, Convert.IsDBNull(tryChar), "#C04");
249                         Assert.AreEqual (false, Convert.IsDBNull(tryFloat), "#C05");
250                 }
251                 
252                 public void TestToBoolean() {
253                         tryObj = (object)tryDbl;
254                         
255                         Assert.AreEqual (true, Convert.ToBoolean(boolTrue), "#D01");
256                         Assert.AreEqual (false, Convert.ToBoolean(tryByte), "#D02");
257                         Assert.AreEqual (true, Convert.ToBoolean(tryDec), "#D03");
258                         Assert.AreEqual (false, Convert.ToBoolean(tryDbl), "#D04");
259                         Assert.AreEqual (true, Convert.ToBoolean(tryInt16), "#D05");
260                         Assert.AreEqual (true, Convert.ToBoolean(tryInt32), "#D06");
261                         Assert.AreEqual (true, Convert.ToBoolean(tryInt64), "#D07");
262                         Assert.AreEqual (false, Convert.ToBoolean(tryObj), "#D08");
263                         Assert.AreEqual (true, Convert.ToBoolean(trySByte), "#D09");
264                         Assert.AreEqual (true, Convert.ToBoolean(tryFloat), "#D10");
265                         Assert.AreEqual (true, Convert.ToBoolean(trueString), "#D11");
266                         Assert.AreEqual (false, Convert.ToBoolean(falseString), "#D12");
267                         Assert.AreEqual (true, Convert.ToBoolean(tryUI16), "#D13");
268                         Assert.AreEqual (true, Convert.ToBoolean(tryUI32), "#D14");
269                         Assert.AreEqual (false, Convert.ToBoolean(tryUI64), "#D15");
270                         Assert.AreEqual (false, Convert.ToBoolean(tryObj, ci), "#D16");
271                         Assert.AreEqual (true, Convert.ToBoolean(trueString, ci), "#D17");
272                         Assert.AreEqual (false, Convert.ToBoolean(falseString, ci), "#D18");
273                         
274                         try {
275                                 Convert.ToBoolean(tryChar);
276                                 Assert.Fail ();
277                         }
278                         catch (Exception e) {
279                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#D20");
280                         }
281                         
282                         try {
283                                 Convert.ToBoolean(tryDT);
284                                 Assert.Fail ();
285                         }
286                         catch (Exception e) {
287                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#D21");
288                         }
289
290                         try {
291                                 Convert.ToBoolean(tryStr);
292                                 Assert.Fail ();
293                         }
294                         catch (Exception e) {
295                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#D22");
296                         }
297
298                         try {
299                                 Convert.ToBoolean(nullString);
300                                 Assert.Fail ();
301                         }
302                         catch (Exception e) {
303                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#D23");
304                         }
305                 }
306
307                 public void TestToByte() {
308                         
309                         Assert.AreEqual ((byte)1, Convert.ToByte(boolTrue), "#E01");
310                         Assert.AreEqual ((byte)0, Convert.ToByte(boolFalse), "#E02");
311                         Assert.AreEqual (tryByte, Convert.ToByte(tryByte), "#E03");
312                         Assert.AreEqual ((byte)114, Convert.ToByte('r'), "#E04");
313                         Assert.AreEqual ((byte)201, Convert.ToByte((decimal)200.6), "#E05");
314                         Assert.AreEqual ((byte)125, Convert.ToByte((double)125.4), "#E06");
315                         Assert.AreEqual ((byte)255, Convert.ToByte((short)255), "#E07");
316                         Assert.AreEqual ((byte)254, Convert.ToByte((int)254), "#E08");
317                         Assert.AreEqual ((byte)34, Convert.ToByte((long)34), "#E09");
318                         Assert.AreEqual ((byte)1, Convert.ToByte((object)boolTrue), "#E10");
319                         Assert.AreEqual ((byte)123, Convert.ToByte((float)123.49f), "#E11");
320                         Assert.AreEqual ((byte)57, Convert.ToByte("57"), "#E12");
321                         Assert.AreEqual ((byte)75, Convert.ToByte((ushort)75), "#E13");
322                         Assert.AreEqual ((byte)184, Convert.ToByte((uint)184), "#E14");
323                         Assert.AreEqual ((byte)241, Convert.ToByte((ulong)241), "#E15");
324                         Assert.AreEqual ((byte)123, Convert.ToByte(trySByte, ci), "#E16");
325                         Assert.AreEqual ((byte)27, Convert.ToByte("011011", 2), "#E17");
326                         Assert.AreEqual ((byte)13, Convert.ToByte("15", 8), "#E18");
327                         Assert.AreEqual ((byte)27, Convert.ToByte("27", 10), "#E19");
328                         Assert.AreEqual ((byte)250, Convert.ToByte("FA", 16), "#E20");
329
330                         try {
331                                 Convert.ToByte('\u03A9'); // sign of Omega on Win2k
332                                 Assert.Fail ();
333                         }
334                         catch (Exception e) {
335                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E25");
336                         }
337
338                         try {
339                                 Convert.ToByte(tryDT);
340                                 Assert.Fail ();
341                         }
342                         catch (Exception e) {
343                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#D26");
344                         }
345
346                         try {
347                                 Convert.ToByte((decimal)22000);
348                                 Assert.Fail ();
349                         }
350                         catch (Exception e) {
351                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E27");
352                         }
353
354                         try {
355                                 Convert.ToByte((double)255.5);
356                                 Assert.Fail ();
357                         }
358                         catch (Exception e) {
359                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E28");
360                         }
361
362                         try {
363                                 Convert.ToByte(-tryInt16);
364                                 Assert.Fail ();
365                         }
366                         catch (Exception e) {
367                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E29");
368                         }
369
370                         try {
371                                 Convert.ToByte((int)-256);
372                                 Assert.Fail ();
373                         }
374                         catch (Exception e) {
375                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E30");
376                         }
377
378                         try {
379                                 Convert.ToByte(tryInt64);
380                                 Assert.Fail ();
381                         }
382                         catch (Exception e) {
383                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E31");
384                         }
385
386                         try {
387                                 Convert.ToByte((object)ci);
388                                 Assert.Fail ();
389                         }
390                         catch (Exception e) {
391                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#E32");
392                         }
393
394                         try {
395                                 Convert.ToByte((sbyte)-1);
396                                 Assert.Fail ();
397                         }
398                         catch (Exception e) {
399                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E33");
400                         }
401
402                         try {
403                                 Convert.ToByte((float)-0.6f);           
404                                 Assert.Fail ();
405                         }
406                         catch (Exception e) {
407                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E34");
408                         }
409
410                         try {
411                                 Convert.ToByte("1a1");          
412                                 Assert.Fail ();
413                         }
414                         catch (Exception e) {
415                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#E35");
416                         }
417
418                         try {
419                                 Convert.ToByte("457");          
420                                 Assert.Fail ();
421                         }
422                         catch (Exception e) {
423                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E36");
424                         }
425
426                         try {
427                                 Convert.ToByte((ushort)30000);
428                                 Assert.Fail ();
429                         }
430                         catch (Exception e) {
431                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E37");
432                         }
433
434                         try {
435                                 Convert.ToByte((uint)300);
436                                 Assert.Fail ();
437                         }
438                         catch (Exception e) {
439                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E38");
440                         }
441
442                         try {
443                                 Convert.ToByte((ulong)987654321321);
444                                 Assert.Fail ();
445                         }
446                         catch (Exception e) {
447                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E39");
448                         }
449
450                         try {
451                                 Convert.ToByte("10010111", 3);
452                                 Assert.Fail ();
453                         }
454                         catch (Exception e) {
455                                 Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#E40");
456                         }
457
458                         try {
459                                 Convert.ToByte("3F3", 16);
460                                 Assert.Fail ();
461                         }
462                         catch (Exception e) {
463                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#E41");
464                         }
465                 }
466
467                 public void TestToChar(){
468                         tryByte = 58;
469                         Assert.AreEqual (':', Convert.ToChar(tryByte), "#F01");
470                         Assert.AreEqual ('a', Convert.ToChar(tryChar), "#F02");
471                         Assert.AreEqual ('A', Convert.ToChar((short)65), "#F03");
472                         Assert.AreEqual ('x', Convert.ToChar((int)120), "#F04");
473                         Assert.AreEqual ('"', Convert.ToChar((long)34), "#F05");
474                         Assert.AreEqual ('-', Convert.ToChar((sbyte)45), "#F06");
475                         Assert.AreEqual ('@', Convert.ToChar("@"), "#F07");
476                         Assert.AreEqual ('K', Convert.ToChar((ushort)75), "#F08");
477                         Assert.AreEqual ('=', Convert.ToChar((uint)61), "#F09");
478                         // Assert.AreEqual ('E', Convert.ToChar((ulong)200), "#F10");
479                         Assert.AreEqual ('{', Convert.ToChar((object)trySByte, ci), "#F11");
480                         Assert.AreEqual ('o', Convert.ToChar(tryStr.Substring(1, 1), ci), "#F12");
481                         
482                         try {
483                                 Convert.ToChar(boolTrue);
484                                 Assert.Fail ();
485                         }
486                         catch (Exception e) {
487                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#F20");
488                         }
489
490                         try {
491                                 Convert.ToChar(tryDT);
492                                 Assert.Fail ();
493                         }
494                         catch (Exception e) {
495                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#F21");
496                         }
497
498                         try {
499                                 Convert.ToChar(tryDec);
500                                 Assert.Fail ();
501                         }
502                         catch (Exception e) {
503                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#F22");
504                         }
505
506                         try {
507                                 Convert.ToChar(tryDbl);
508                                 Assert.Fail ();
509                         }
510                         catch (Exception e) {
511                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#F23");
512                         }
513
514                         try {
515                                 Convert.ToChar((short)-1);
516                                 Assert.Fail ();
517                         }
518                         catch (Exception e) {
519                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#F24");
520                         }
521
522                         try {
523                                 Convert.ToChar(Int32.MinValue);
524                                 Assert.Fail ();
525                         }
526                         catch (Exception e) {
527                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#F25");
528                         }
529
530                         try {
531                                 Convert.ToChar(Int32.MaxValue);
532                                 Assert.Fail ();
533                         }
534                         catch (Exception e) {
535                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#F26");
536                         }
537
538                         try {
539                                 Convert.ToChar(tryInt64);
540                                 Assert.Fail ();
541                         }
542                         catch (Exception e) {
543                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#F27");
544                         }
545
546                         try {
547                                 Convert.ToChar((long)-123);
548                                 Assert.Fail ();
549                         }
550                         catch (Exception e) {
551                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#F28");
552                         }
553
554                         try {
555                                 Convert.ToChar(ci);
556                                 Assert.Fail ();
557                         }
558                         catch (Exception e) {
559                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#F29");
560                         }
561
562                         try {
563                                 Convert.ToChar(-trySByte);
564                                 Assert.Fail ();
565                         }
566                         catch (Exception e) {
567                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#F30");
568                         }
569
570                         try {
571                                 Convert.ToChar(tryFloat);
572                                 Assert.Fail ();
573                         }
574                         catch (Exception e) {
575                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#F31");
576                         }
577
578                         try {
579                                 Convert.ToChar("foo");
580                                 Assert.Fail ();
581                         }
582                         catch (Exception e) {
583                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#F32");
584                         }
585                         
586                         try {
587                                 Convert.ToChar(null);
588                                 Assert.Fail ();
589                         }
590                         catch (Exception e) {
591                                 Assert.AreEqual (typeof(ArgumentNullException), e.GetType(), "#F33");
592                         }
593
594                         try {
595                                 Convert.ToChar(new Exception(), ci);
596                                 Assert.Fail ();
597                         }
598                         catch (Exception e) {
599                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#F34");
600                         }
601
602                         try {
603                                 Convert.ToChar(null, ci);
604                                 Assert.Fail ();
605                         }
606                         catch (Exception e) {
607                                 Assert.AreEqual (typeof(ArgumentNullException), e.GetType(), "#F35");
608                         }
609
610                         try {
611                                 Convert.ToChar("", ci);
612                                 Assert.Fail ();
613                         }
614                         catch (Exception e) {
615                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#F36");
616                         }
617
618                         try {
619                                 Convert.ToChar(tryStr, ci);
620                                 Assert.Fail ();
621                         }
622                         catch (Exception e) {
623                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#F37");
624                         }
625                 }
626
627                 /*[Ignore ("http://bugzilla.ximian.com/show_bug.cgi?id=45286")]
628                 [Test]
629                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
630                 public void G22 () {
631                         Convert.ToDateTime("20002-25-01");
632                 } */
633
634                 public void TestToDateTime() {
635                         string dateString = "01/01/2002";
636                         int iTest = 1;
637                         try {
638                                 Assert.AreEqual (tryDT, Convert.ToDateTime(tryDT), "#G01");
639                                 iTest++;
640                                 Assert.AreEqual (tryDT, Convert.ToDateTime(dateString), "#G02");
641                                 iTest++;
642                                 Assert.AreEqual (tryDT, Convert.ToDateTime(dateString, ci), "#G03");
643                         } catch (Exception e) {
644                                 Assert.Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e);
645                         }
646
647                         try {
648                                 Convert.ToDateTime(boolTrue);
649                                 Assert.Fail ();
650                         }
651                         catch (Exception e) {
652                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G10");
653                         }
654
655                         try {
656                                 Convert.ToDateTime(tryByte);
657                                 Assert.Fail ();
658                         }
659                         catch (Exception e) {
660                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G11");
661                         }
662
663                         try {
664                                 Convert.ToDateTime(tryChar);
665                                 Assert.Fail ();
666                         }
667                         catch (Exception e) {
668                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G12");
669                         }
670
671                         try {
672                                 Convert.ToDateTime(tryDec);
673                                 Assert.Fail ();
674                         }
675                         catch (Exception e) {
676                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G13");
677                         }
678
679                         try {
680                                 Convert.ToDateTime(tryDbl);
681                                 Assert.Fail ();
682                         }
683                         catch (Exception e) {
684                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G14");
685                         }
686
687                         try {
688                                 Convert.ToDateTime(tryInt16);
689                                 Assert.Fail ();
690                         }
691                         catch (Exception e) {
692                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G15");
693                         }
694
695                         try {
696                                 Convert.ToDateTime(tryInt32);
697                                 Assert.Fail ();
698                         }
699                         catch (Exception e) {
700                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G16");
701                         }
702
703                         try {
704                                 Convert.ToDateTime(tryInt64);
705                                 Assert.Fail ();
706                         }
707                         catch (Exception e) {
708                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G17");
709                         }
710
711                         try {
712                                 Convert.ToDateTime(ci);
713                                 Assert.Fail ();
714                         }
715                         catch (Exception e) {
716                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G18");
717                         }
718
719                         try {
720                                 Convert.ToDateTime(trySByte);
721                                 Assert.Fail ();
722                         }
723                         catch (Exception e) {
724                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G19");
725                         }
726
727                         try {
728                                 Convert.ToDateTime(tryFloat);
729                                 Assert.Fail ();
730                         }
731                         catch (Exception e) {
732                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G20");
733                         }
734
735                         try {
736                                 Convert.ToDateTime("20a2-01-01");
737                                 Assert.Fail ();
738                         }
739                         catch (Exception e) {
740                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#G21");
741                         }
742
743                         try {
744                                 Convert.ToDateTime(tryUI16);
745                                 Assert.Fail ();
746                         }
747                         catch (Exception e) {
748                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G23");
749                         }
750
751                         try {
752                                 Convert.ToDateTime(tryUI32);
753                                 Assert.Fail ();
754                         }
755                         catch (Exception e) {
756                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G24");
757                         }
758
759                         try {
760                                 Convert.ToDateTime(tryUI64);
761                                 Assert.Fail ();
762                         }
763                         catch (Exception e) {
764                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G25");
765                         }
766
767                         try {
768                                 Convert.ToDateTime(ci, ci);
769                                 Assert.Fail ();
770                         }
771                         catch (Exception e) {
772                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#G26");
773                         }
774
775                         try {
776                                 Convert.ToDateTime("20a2-01-01", ci);
777                                 Assert.Fail ();
778                         }
779                         catch (Exception e) {
780                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#G27");
781                         }
782
783                         // this is supported by .net 1.1 (defect 41845)
784                         try {
785                                 Convert.ToDateTime("20022-01-01");
786                                 Assert.Fail ();
787                         }
788                         catch (Exception e) {
789 #if NET_2_0
790                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#G28");
791 #else
792                                 Assert.AreEqual (typeof(ArgumentOutOfRangeException), e.GetType(), "#G28");
793 #endif
794                         }
795
796                         try {
797                                 Convert.ToDateTime("2002-21-01");
798                                 Assert.Fail ();
799                         }
800                         catch (Exception e) {
801                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#G29");
802                         }
803
804                         try {
805                                 Convert.ToDateTime("2002-111-01");
806                                 Assert.Fail ();
807                         }
808                         catch (Exception e) {
809                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#G30");
810                         }
811
812                         try {
813                                 Convert.ToDateTime("2002-01-41");
814                                 Assert.Fail ();
815                         }
816                         catch (Exception e) {
817                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#G31");
818                         }
819
820                         try {
821                                 Convert.ToDateTime("2002-01-111");
822                                 Assert.Fail ();
823                         }
824                         catch (Exception e) {
825                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#G32");
826                         }
827
828                         try {
829                                 Assert.AreEqual (tryDT, Convert.ToDateTime("2002-01-01"), "#G33");
830                         } catch (Exception e) {
831                                 Assert.Fail ("Unexpected exception at #G33 " + e);
832                         }
833
834                         try {
835                                 Convert.ToDateTime("2002-01-11 34:11:11");
836                                 Assert.Fail ();
837                         }
838                         catch (Exception e) {
839                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#G34");
840                         }
841
842                         try {
843                                 Convert.ToDateTime("2002-01-11 11:70:11");
844                                 Assert.Fail ();
845                         }
846                         catch (Exception e) {
847                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#G35");
848                         }
849
850                         try {
851                                 Convert.ToDateTime("2002-01-11 11:11:70");
852                                 Assert.Fail ();
853                         }
854                         catch (Exception e) {
855                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#G36");
856                         }
857
858                 }
859
860                 public void TestToDecimal() {
861                         Assert.AreEqual ((decimal)1, Convert.ToDecimal(boolTrue), "#H01");
862                         Assert.AreEqual ((decimal)0, Convert.ToDecimal(boolFalse), "#H02");
863                         Assert.AreEqual ((decimal)tryByte, Convert.ToDecimal(tryByte), "#H03");
864                         Assert.AreEqual (tryDec, Convert.ToDecimal(tryDec), "#H04");
865                         Assert.AreEqual ((decimal)tryDbl, Convert.ToDecimal(tryDbl), "#H05");
866                         Assert.AreEqual ((decimal)tryInt16, Convert.ToDecimal(tryInt16), "#H06");
867                         Assert.AreEqual ((decimal)tryInt32, Convert.ToDecimal(tryInt32), "#H07");
868                         Assert.AreEqual ((decimal)tryInt64, Convert.ToDecimal(tryInt64), "#H08");
869                         Assert.AreEqual ((decimal)trySByte, Convert.ToDecimal(trySByte), "#H09");
870                         Assert.AreEqual ((decimal)tryFloat, Convert.ToDecimal(tryFloat), "#H10");
871                         string sep = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
872 //                      Assert.AreEqual ((decimal)23456.432, Convert.ToDecimal("23456" + sep + "432"), "#H11");
873 //                      Note: changed because the number were the same but with a different base
874 //                      and this isn't a Convert bug (but a Decimal bug). See #60227 for more details.
875 //                      http://bugzilla.ximian.com/show_bug.cgi?id=60227
876                         Assert.IsTrue (Decimal.Equals (23456.432m, Convert.ToDecimal ("23456" + sep + "432")), "#H11");
877                         Assert.AreEqual ((decimal)tryUI16, Convert.ToDecimal(tryUI16), "#H12");
878                         Assert.AreEqual ((decimal)tryUI32, Convert.ToDecimal(tryUI32), "#H13");
879                         Assert.AreEqual ((decimal)tryUI64, Convert.ToDecimal(tryUI64), "#H14");
880                         Assert.AreEqual ((decimal)63784, Convert.ToDecimal("63784", ci), "#H15");
881                         
882                         try {
883                                 Convert.ToDecimal(tryChar);
884                                 Assert.Fail ();
885                         }
886                         catch (Exception e) {
887                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#H20");
888                         }
889
890                         try {
891                                 Convert.ToDecimal(tryDT);
892                                 Assert.Fail ();
893                         }
894                         catch (Exception e) {
895                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#H21");
896                         }
897
898                         try {
899                                 Convert.ToDecimal(double.MaxValue);
900                                 Assert.Fail ();
901                         }
902                         catch (Exception e) {
903                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#H22");
904                         }
905
906                         try {
907                                 Convert.ToDecimal(double.MinValue);
908                                 Assert.Fail ();
909                         }
910                         catch (Exception e) {
911                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#H23");
912                         }
913
914                         try {
915                                 Convert.ToDecimal(ci);
916                                 Assert.Fail ();
917                         }
918                         catch (Exception e) {
919                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#H24");
920                         }
921                         
922                         try {
923                                 Convert.ToDecimal(tryStr);
924                                 Assert.Fail ();
925                         }
926                         catch (Exception e) {
927                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#H25");
928                         }
929                         
930                         try {
931                                 string maxDec = decimal.MaxValue.ToString();
932                                 maxDec = maxDec + "1";                          
933                                 Convert.ToDecimal(maxDec);
934                                 Assert.Fail ();
935                         }
936                         catch (Exception e) {
937                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#H26");
938                         }
939
940                         try {
941                                 Convert.ToDecimal(ci, ci);
942                                 Assert.Fail ();
943                         }
944                         catch (Exception e) {
945                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#H27");
946                         }
947
948                         try {
949                                 Convert.ToDecimal(tryStr, ci);
950                                 Assert.Fail ();
951                         }
952                         catch (Exception e) {
953                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#H28");
954                         }
955                         
956                         try {
957                                 string maxDec = decimal.MaxValue.ToString();
958                                 maxDec = maxDec + "1";
959                                 Convert.ToDecimal(maxDec, ci);
960                                 Assert.Fail ();
961                         }
962                         catch (Exception e) {
963                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#H29");
964                         }
965                 }
966                 
967                 public void TestToDouble() {
968                         int iTest = 1;
969                         try {
970                                 Assert.AreEqual ((double)1, Convert.ToDouble(boolTrue), "#I01");
971                                 iTest++;
972                                 Assert.AreEqual ((double)0, Convert.ToDouble(boolFalse), "#I02");
973                                 iTest++;
974                                 Assert.AreEqual ((double)tryByte, Convert.ToDouble(tryByte), "#I03");
975                                 iTest++;
976                                 Assert.AreEqual (tryDbl, Convert.ToDouble(tryDbl), "#I04");
977                                 iTest++;
978                                 Assert.AreEqual ((double)tryDec, Convert.ToDouble(tryDec), "#I05");
979                                 iTest++;
980                                 Assert.AreEqual ((double)tryInt16, Convert.ToDouble(tryInt16), "#I06");
981                                 iTest++;
982                                 Assert.AreEqual ((double)tryInt32, Convert.ToDouble(tryInt32), "#I07");
983                                 iTest++;
984                                 Assert.AreEqual ((double)tryInt64, Convert.ToDouble(tryInt64), "#I08");
985                                 iTest++;
986                                 Assert.AreEqual ((double)trySByte, Convert.ToDouble(trySByte), "#I09");
987                                 iTest++;
988                                 Assert.AreEqual ((double)tryFloat, Convert.ToDouble(tryFloat), "#I10");
989                                 iTest++;
990                                 string sep = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
991                                 Assert.AreEqual ((double)23456.432, Convert.ToDouble("23456" + sep + "432"), "#I11");
992                                 iTest++;
993                                 Assert.AreEqual ((double)tryUI16, Convert.ToDouble(tryUI16), "#I12");
994                                 iTest++;
995                                 Assert.AreEqual ((double)tryUI32, Convert.ToDouble(tryUI32), "#I13");
996                                 iTest++;
997                                 Assert.AreEqual ((double)tryUI64, Convert.ToDouble(tryUI64), "#I14");
998                                 iTest++;
999                                 Assert.AreEqual ((double)63784, Convert.ToDouble("63784", ci), "#H15");
1000                         } catch (Exception e) {
1001                                 Assert.Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e);
1002                         }
1003                         
1004                         try {
1005                                 Convert.ToDouble(tryChar);
1006                                 Assert.Fail ();
1007                         }
1008                         catch (Exception e) {
1009                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#I20");
1010                         }
1011
1012                         try {
1013                                 Convert.ToDouble(tryDT);
1014                                 Assert.Fail ();
1015                         }
1016                         catch (Exception e) {
1017                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#I21");
1018                         }
1019
1020                         try {
1021                                 Convert.ToDouble(ci);
1022                                 Assert.Fail ();
1023                         }
1024                         catch (Exception e) {
1025                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#I22");
1026                         }
1027                         
1028                         try {
1029                                 Convert.ToDouble(tryStr);
1030                                 Assert.Fail ();
1031                         }
1032                         catch (Exception e) {
1033                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#I23");
1034                         }
1035                         
1036                         try {
1037                                 string maxDec = double.MaxValue.ToString();
1038                                 maxDec = maxDec + "1";                          
1039                                 Convert.ToDouble(maxDec);
1040                                 Assert.Fail ();
1041                         }
1042                         catch (Exception e) {
1043                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#I24");
1044                         }
1045
1046                         try {
1047                                 Convert.ToDouble(ci, ci);
1048                                 Assert.Fail ();
1049                         }
1050                         catch (Exception e) {
1051                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#I25");
1052                         }
1053
1054                         try {
1055                                 Convert.ToDouble(tryStr, ci);
1056                                 Assert.Fail ();
1057                         }
1058                         catch (Exception e) {
1059                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#I26");
1060                         }
1061                         
1062                         try {
1063                                 string maxDec = double.MaxValue.ToString();
1064                                 maxDec = maxDec + "1";
1065                                 Convert.ToDouble(maxDec, ci);
1066                                 Assert.Fail ();
1067                         }
1068                         catch (Exception e) {
1069                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#I27");
1070                         }
1071
1072                         try {
1073                                 Convert.ToDouble(tryObj, ci);
1074                                 Assert.Fail ();
1075                         }
1076                         catch (Exception e) {
1077                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#I28");
1078                         }
1079                 }
1080
1081                 public void TestToInt16() {
1082                         Assert.AreEqual ((short)0, Convert.ToInt16(boolFalse), "#J01");
1083                         Assert.AreEqual ((short)1, Convert.ToInt16(boolTrue), "#J02");
1084                         Assert.AreEqual ((short)97, Convert.ToInt16(tryChar), "#J03");
1085                         Assert.AreEqual ((short)1234, Convert.ToInt16(tryDec), "#J04");
1086                         Assert.AreEqual ((short)0, Convert.ToInt16(tryDbl), "#J05");
1087                         Assert.AreEqual ((short)1234, Convert.ToInt16(tryInt16), "#J06");
1088                         Assert.AreEqual ((short)12345, Convert.ToInt16(tryInt32), "#J07");
1089                         Assert.AreEqual ((short)30000, Convert.ToInt16((long)30000), "#J08");
1090                         Assert.AreEqual ((short)123, Convert.ToInt16(trySByte), "#J09");
1091                         Assert.AreEqual ((short)1234, Convert.ToInt16(tryFloat), "#J10");
1092                         Assert.AreEqual ((short)578, Convert.ToInt16("578"), "#J11");
1093                         Assert.AreEqual ((short)15500, Convert.ToInt16((ushort)15500), "#J12");
1094                         Assert.AreEqual ((short)5489, Convert.ToInt16((uint)5489), "#J13");
1095                         Assert.AreEqual ((short)9876, Convert.ToInt16((ulong)9876), "#J14");
1096                         Assert.AreEqual ((short)14, Convert.ToInt16("14", ci), "#J15");
1097                         Assert.AreEqual ((short)11, Convert.ToInt16("01011", 2), "#J16");
1098                         Assert.AreEqual ((short)1540, Convert.ToInt16("3004", 8), "#J17");
1099                         Assert.AreEqual ((short)321, Convert.ToInt16("321", 10), "#J18");
1100                         Assert.AreEqual ((short)2748, Convert.ToInt16("ABC", 16), "#J19");
1101
1102                         try {
1103                                 Convert.ToInt16(char.MaxValue);
1104                                 Assert.Fail ();
1105                         }
1106                         catch (Exception e) {
1107                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J25");
1108                         }
1109
1110                         try {
1111                                 Convert.ToInt16(tryDT);
1112                                 Assert.Fail ();
1113                         }
1114                         catch (Exception e) {
1115                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#J26");
1116                         }
1117
1118                         try {
1119                                 Convert.ToInt16((decimal)(short.MaxValue + 1));
1120                                 Assert.Fail ();
1121                         }
1122                         catch (Exception e) {
1123                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J27");
1124                         }
1125
1126                         try {
1127                                 Convert.ToInt16((decimal)(short.MinValue - 1));
1128                                 Assert.Fail ();
1129                         }
1130                         catch (Exception e) {
1131                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J28");
1132                         }
1133
1134                         try {
1135                                 Convert.ToInt16((double)(short.MaxValue + 1));
1136                                 Assert.Fail ();
1137                         }
1138                         catch (Exception e) {
1139                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J29");
1140                         }
1141
1142                         try {
1143                                 Convert.ToInt16((double)(short.MinValue - 1));
1144                                 Assert.Fail ();
1145                         }
1146                         catch (Exception e) {
1147                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J30");
1148                         }
1149
1150                         try {
1151                                 Convert.ToInt16(50000);
1152                                 Assert.Fail ();
1153                         }
1154                         catch (Exception e) {
1155                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J31");
1156                         }
1157
1158                         try {
1159                                 Convert.ToInt16(-50000);
1160                                 Assert.Fail ();
1161                         }
1162                         catch (Exception e) {
1163                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J32");
1164                         }
1165
1166                         try {
1167                                 Convert.ToInt16(tryInt64);
1168                                 Assert.Fail ();
1169                         }
1170                         catch (Exception e) {
1171                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J33");
1172                         }
1173
1174                         try {
1175                                 Convert.ToInt16(-tryInt64);
1176                                 Assert.Fail ();
1177                         }
1178                         catch (Exception e) {
1179                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J34");
1180                         }
1181
1182                         try {
1183                                 Convert.ToInt16(tryObj);
1184                                 Assert.Fail ();
1185                         }
1186                         catch (Exception e) {
1187                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#J35");
1188                         }
1189
1190                         try {
1191                                 Convert.ToInt16((float)32767.5);
1192                                 Assert.Fail ();
1193                         }
1194                         catch (Exception e) {
1195                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J36");
1196                         }
1197
1198                         try {
1199                                 Convert.ToInt16((float)-33000.54);
1200                                 Assert.Fail ();
1201                         }
1202                         catch (Exception e) {
1203                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J37");
1204                         }
1205
1206                         try {
1207                                 Convert.ToInt16(tryStr);
1208                                 Assert.Fail ();
1209                         }
1210                         catch (Exception e) {
1211                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#J38");
1212                         }
1213                         
1214                         try {
1215                                 Convert.ToInt16("-33000");
1216                                 Assert.Fail ();
1217                         }
1218                         catch (Exception e) {
1219                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J39");
1220                         }
1221
1222                         try {                                                   
1223                                 Convert.ToInt16(ushort.MaxValue);
1224                                 Assert.Fail ();
1225                         }
1226                         catch (Exception e) {
1227                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J40");
1228                         }
1229
1230                         try {                                                   
1231                                 Convert.ToInt16(uint.MaxValue);
1232                                 Assert.Fail ();
1233                         }
1234                         catch (Exception e) {
1235                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J41");
1236                         }
1237
1238                         try {                                                   
1239                                 Convert.ToInt16(ulong.MaxValue);
1240                                 Assert.Fail ();
1241                         }
1242                         catch (Exception e) {
1243                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J42");
1244                         }
1245
1246                         try {
1247                                 Convert.ToInt16(tryObj, ci);
1248                                 Assert.Fail ();
1249                         }
1250                         catch (Exception e) {
1251                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#J43");
1252                         }
1253
1254                         try {
1255                                 Convert.ToInt16(tryStr, ci);
1256                                 Assert.Fail ();
1257                         }
1258                         catch (Exception e) {
1259                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#J44");
1260                         }
1261                         
1262                         try {
1263                                 Convert.ToInt16("-33000", ci);
1264                                 Assert.Fail ();
1265                         }
1266                         catch (Exception e) {
1267                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J45");
1268                         }
1269
1270                         try {
1271                                 Convert.ToInt16("321", 11);
1272                                 Assert.Fail ();
1273                         }
1274                         catch (Exception e) {
1275                                 Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#J46");
1276                         }
1277
1278                         try {
1279                                 Convert.ToInt16("D8BF1", 16);
1280                                 Assert.Fail ();
1281                         }
1282                         catch (Exception e) {
1283                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#J47");
1284                         }
1285                 }
1286
1287                 public void TestToInt32() {
1288                         long tryMax = long.MaxValue;
1289                         long tryMin = long.MinValue;
1290                         Assert.AreEqual ((int)0, Convert.ToInt32(boolFalse), "#K01");
1291                         Assert.AreEqual ((int)1, Convert.ToInt32(boolTrue), "#K02");
1292                         Assert.AreEqual ((int)0, Convert.ToInt32(tryByte), "#K03");
1293                         Assert.AreEqual ((int)97, Convert.ToInt32(tryChar), "#K04");
1294                         Assert.AreEqual ((int)1234, Convert.ToInt32(tryDec), "#K05");
1295                         Assert.AreEqual ((int)0, Convert.ToInt32(tryDbl), "#K06");
1296                         Assert.AreEqual ((int)1234, Convert.ToInt32(tryInt16), "#K07");
1297                         Assert.AreEqual ((int)12345, Convert.ToInt32(tryInt32), "#K08");
1298                         Assert.AreEqual ((int)60000, Convert.ToInt32((long)60000), "#K09");
1299                         Assert.AreEqual ((int)123, Convert.ToInt32(trySByte), "#K10");
1300                         Assert.AreEqual ((int)1234, Convert.ToInt32(tryFloat), "#K11");
1301                         Assert.AreEqual ((int)9876, Convert.ToInt32((string)"9876"), "#K12");
1302                         Assert.AreEqual ((int)34567, Convert.ToInt32(tryUI16), "#K13");
1303                         Assert.AreEqual ((int)567891234, Convert.ToInt32(tryUI32), "#K14");
1304                         Assert.AreEqual ((int)0, Convert.ToInt32(tryUI64), "#K15");
1305                         Assert.AreEqual ((int)123, Convert.ToInt32("123", ci), "#K16");
1306                         Assert.AreEqual ((int)128, Convert.ToInt32("10000000", 2), "#K17");
1307                         Assert.AreEqual ((int)302, Convert.ToInt32("456", 8), "#K18");
1308                         Assert.AreEqual ((int)456, Convert.ToInt32("456", 10), "#K19");
1309                         Assert.AreEqual ((int)1110, Convert.ToInt32("456", 16), "#K20");
1310
1311                         try {                                                   
1312                                 Convert.ToInt32(tryDT);
1313                                 Assert.Fail ();
1314                         }
1315                         catch (Exception e) {
1316                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#K25");
1317                         }
1318
1319                         try {                           
1320                                 Convert.ToInt32((decimal)tryMax);
1321                                 Assert.Fail ();
1322                         }
1323                         catch (Exception e) {
1324                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K26");
1325                         }
1326
1327                         try {
1328                                 Convert.ToInt32((decimal)tryMin);
1329                                 Assert.Fail ();
1330                         }
1331                         catch (Exception e) {
1332                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K27");
1333                         }
1334
1335                         try {
1336                                 Convert.ToInt32((double)tryMax);
1337                                 Assert.Fail ();
1338                         }
1339                         catch (Exception e) {
1340                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K28");
1341                         }
1342
1343                         try {
1344                                 Convert.ToInt32((double)tryMin);
1345                                 Assert.Fail ();
1346                         }
1347                         catch (Exception e) {
1348                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K29");
1349                         }
1350
1351                         try {                                                   
1352                                 Convert.ToInt32(tryInt64);
1353                                 Assert.Fail ();
1354                         }
1355                         catch (Exception e) {
1356                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K30");
1357                         }
1358
1359                         try {
1360                                 Convert.ToInt32(-tryInt64);
1361                                 Assert.Fail ();
1362                         }
1363                         catch (Exception e) {
1364                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K31");
1365                         }
1366
1367                         try {
1368                                 Convert.ToInt32(tryObj);
1369                                 Assert.Fail ();
1370                         }
1371                         catch (Exception e) {
1372                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#K32");
1373                         }
1374
1375                         try {
1376                                 Convert.ToInt32((float)tryMax);
1377                                 Assert.Fail ();
1378                         }
1379                         catch (Exception e) {
1380                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K33");
1381                         }
1382
1383                         try {
1384                                 Convert.ToInt32((float)tryMin);
1385                                 Assert.Fail ();
1386                         }
1387                         catch (Exception e) {
1388                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K34");
1389                         }
1390                         
1391                         try {
1392                                 Convert.ToInt32(tryStr, ci);
1393                                 Assert.Fail ();
1394                         }
1395                         catch (Exception e) {
1396                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#K35");
1397                         }
1398
1399                         try {
1400                                 Convert.ToInt32("-46565465123");
1401                                 Assert.Fail ();
1402                         }
1403                         catch (Exception e) {
1404                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K36");
1405                         }
1406
1407                         try {
1408                                 Convert.ToInt32("46565465123");
1409                                 Assert.Fail ();
1410                         }
1411                         catch (Exception e) {
1412                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K37");
1413                         }
1414
1415                         try {
1416                                 Convert.ToInt32((uint)tryMax);
1417                                 Assert.Fail ();
1418                         }
1419                         catch (Exception e) {
1420                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K38");
1421                         }
1422
1423                         try {
1424                                 Convert.ToInt32((ulong)tryMax);
1425                                 Assert.Fail ();
1426                         }
1427                         catch (Exception e) {
1428                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K39");
1429                         }
1430
1431                         try {
1432                                 Convert.ToInt32(tryObj, ci);
1433                                 Assert.Fail ();
1434                         }
1435                         catch (Exception e) {
1436                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#K40");
1437                         }
1438
1439                         try {
1440                                 Convert.ToInt32(tryStr, ci);
1441                                 Assert.Fail ();
1442                         }
1443                         catch (Exception e) {
1444                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#K41");
1445                         }
1446
1447                         try {
1448                                 Convert.ToInt32("-46565465123", ci);
1449                                 Assert.Fail ();
1450                         }
1451                         catch (Exception e) {
1452                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#K42");
1453                         }
1454                         
1455                         try {
1456                                 Convert.ToInt32("654", 9);
1457                                 Assert.Fail ();
1458                         }
1459                         catch (Exception e) {
1460                                 Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#K43");
1461                         }
1462                 }
1463
1464                 public void TestToInt64() {
1465                         decimal longMax = long.MaxValue;
1466                         longMax += 1000000;
1467                         decimal longMin = long.MinValue;
1468                         longMin -= 1000000;
1469
1470                         Assert.AreEqual ((long)0, Convert.ToInt64(boolFalse), "#L01");
1471                         Assert.AreEqual ((long)1, Convert.ToInt64(boolTrue), "#L02");
1472                         Assert.AreEqual ((long)97, Convert.ToInt64(tryChar), "#L03");
1473                         Assert.AreEqual ((long)1234, Convert.ToInt64(tryDec), "#L04");
1474                         Assert.AreEqual ((long)0, Convert.ToInt64(tryDbl), "#L05");
1475                         Assert.AreEqual ((long)1234, Convert.ToInt64(tryInt16), "#L06");
1476                         Assert.AreEqual ((long)12345, Convert.ToInt64(tryInt32), "#L07");
1477                         Assert.AreEqual ((long)123456789012, Convert.ToInt64(tryInt64), "#L08");
1478                         Assert.AreEqual ((long)123, Convert.ToInt64(trySByte), "#L09");
1479                         Assert.AreEqual ((long)1234, Convert.ToInt64(tryFloat), "#L10");
1480                         Assert.AreEqual ((long)564897, Convert.ToInt64("564897"), "#L11");
1481                         Assert.AreEqual ((long)34567, Convert.ToInt64(tryUI16), "#L12");
1482                         Assert.AreEqual ((long)567891234, Convert.ToInt64(tryUI32), "#L13");
1483                         Assert.AreEqual ((long)0, Convert.ToInt64(tryUI64), "#L14");
1484                         Assert.AreEqual ((long)-2548751, Convert.ToInt64("-2548751", ci), "#L15");
1485                         Assert.AreEqual ((long)24987562, Convert.ToInt64("1011111010100011110101010", 2), "#L16");
1486                         Assert.AreEqual ((long)-24578965, Convert.ToInt64("1777777777777642172153", 8), "#L17");
1487                         Assert.AreEqual ((long)248759757, Convert.ToInt64("248759757", 10), "#L18");
1488                         Assert.AreEqual ((long)256, Convert.ToInt64("100", 16), "#L19");
1489
1490                         try {
1491                                 Convert.ToInt64(tryDT);
1492                                 Assert.Fail ();
1493                         }
1494                         catch (Exception e) {
1495                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#L20");
1496                         }
1497
1498                         try {
1499                                 Convert.ToInt64((decimal)longMax + 1);
1500                                 Assert.Fail ();
1501                         }
1502                         catch (Exception e) {
1503                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L21");
1504                         }
1505
1506                         try {
1507                                 Convert.ToInt64((decimal)longMin);
1508                                 Assert.Fail ();
1509                         }
1510                         catch (Exception e) {
1511                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L24");
1512                         }
1513
1514                         try {
1515                                 Convert.ToInt64((double)longMax);
1516                                 Assert.Fail ();
1517                         }
1518                         catch (Exception e) {
1519                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L25:"+longMax);
1520                         }
1521
1522                         try {
1523                                 Convert.ToInt64((double)longMin);
1524                                 Assert.Fail ();
1525                         }
1526                         catch (Exception e) {
1527                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L26");
1528                         }
1529
1530                         try {
1531                                 Convert.ToInt64(new Exception());
1532                                 Assert.Fail ();
1533                         }
1534                         catch (Exception e) {
1535                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#L27");
1536                         }
1537
1538                         try {
1539                                 Convert.ToInt64(((float)longMax)*100);
1540                                 Assert.Fail ();
1541                         }
1542                         catch (Exception e) {
1543                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L28:"+longMax);
1544                         }
1545
1546                         try {
1547                                 Convert.ToInt64(((float)longMin)*100);
1548                                 Assert.Fail ();
1549                         }
1550                         catch (Exception e) {
1551                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L29");
1552                         }
1553
1554                         try {
1555                                 Convert.ToInt64("-567b3");
1556                                 Assert.Fail ();
1557                         }
1558                         catch (Exception e) {
1559                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#L30");
1560                         }
1561
1562                         try {
1563                                 Convert.ToInt64(longMax.ToString());
1564                                 Assert.Fail ();
1565                         }
1566                         catch (Exception e) {
1567                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L31:");
1568                         }
1569
1570                         try {
1571                                 Convert.ToInt64(ulong.MaxValue);
1572                                 Assert.Fail ();
1573                         }
1574                         catch (Exception e) {
1575                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L32");
1576                         }
1577
1578                         try {
1579                                 Convert.ToInt64(tryStr, ci);
1580                                 Assert.Fail ();
1581                         }
1582                         catch (Exception e) {
1583                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#L32b");
1584                         }
1585                         
1586                         try {
1587                                 Convert.ToInt64(longMin.ToString(), ci);
1588                                 Assert.Fail ();
1589                         }
1590                         catch (Exception e) {
1591                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#L33");
1592                         }
1593
1594                         try {
1595                                 Convert.ToInt64("321", 11);
1596                                 Assert.Fail ();
1597                         }
1598                         catch (Exception e) {
1599                                 Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#L34");
1600                         }
1601                 }
1602
1603                 public void TestToSByte() {
1604                         int iTest = 1;
1605                         try {
1606                                 Assert.AreEqual ((sbyte)0, Convert.ToSByte(boolFalse), "#M01");
1607                                 iTest++;
1608                                 Assert.AreEqual ((sbyte)1, Convert.ToSByte(boolTrue), "#M02");
1609                                 iTest++;
1610                                 Assert.AreEqual ((sbyte)97, Convert.ToSByte(tryChar), "#M03");
1611                                 iTest++;
1612                                 Assert.AreEqual ((sbyte)15, Convert.ToSByte((decimal)15), "#M04");
1613                                 iTest++;
1614                                 Assert.AreEqual ((sbyte)0, Convert.ToSByte(tryDbl), "#M05");
1615                                 iTest++;
1616                                 Assert.AreEqual ((sbyte)127, Convert.ToSByte((short)127), "#M06");
1617                                 iTest++;
1618                                 Assert.AreEqual ((sbyte)-128, Convert.ToSByte((int)-128), "#M07");
1619                                 iTest++;
1620                                 Assert.AreEqual ((sbyte)30, Convert.ToSByte((long)30), "#M08");
1621                                 iTest++;
1622                                 Assert.AreEqual ((sbyte)123, Convert.ToSByte(trySByte), "#M09");
1623                                 iTest++;
1624                                 Assert.AreEqual ((sbyte)12, Convert.ToSByte((float)12.46987f), "#M10");
1625                                 iTest++;
1626                                 Assert.AreEqual ((sbyte)1, Convert.ToSByte("1"), "#M11");
1627                                 iTest++;
1628                                 Assert.AreEqual ((sbyte)99, Convert.ToSByte((ushort)99), "#M12");
1629                                 iTest++;
1630                                 Assert.AreEqual ((sbyte)54, Convert.ToSByte((uint)54), "#M13");
1631                                 iTest++;
1632                                 Assert.AreEqual ((sbyte)127, Convert.ToSByte((ulong)127), "#M14");
1633                                 iTest++;
1634                                 Assert.AreEqual ((sbyte)14, Convert.ToSByte("14", ci), "#M15");
1635                                 iTest++;
1636                                 Assert.AreEqual ((sbyte)11, Convert.ToSByte("01011", 2), "#M16");
1637                                 iTest++;
1638                                 Assert.AreEqual ((sbyte)5, Convert.ToSByte("5", 8), "#M17");
1639                                 iTest++;
1640                                 Assert.AreEqual ((sbyte)100, Convert.ToSByte("100", 10), "#M18");
1641                                 iTest++;
1642                                 Assert.AreEqual ((sbyte)-1, Convert.ToSByte("FF", 16), "#M19");
1643                         } catch (Exception e) {
1644                                 Assert.Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e);
1645                         }
1646
1647                         try {
1648                                 Convert.ToSByte((byte)200);
1649                                 Assert.Fail ();
1650                         }
1651                         catch (Exception e) {
1652                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M25");
1653                         }
1654
1655                         try {
1656                                 Convert.ToSByte((char)130);
1657                                 Assert.Fail ();
1658                         }
1659                         catch (Exception e) {
1660                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M26");
1661                         }
1662
1663                         try {
1664                                 Convert.ToSByte(tryDT);
1665                                 Assert.Fail ();
1666                         }
1667                         catch (Exception e) {
1668                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#M27");
1669                         }
1670
1671                         try {
1672                                 Convert.ToSByte((decimal)127.5m);
1673                                 Assert.Fail ();
1674                         }
1675                         catch (Exception e) {
1676                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M28");
1677                         }
1678
1679                         try {
1680                                 Convert.ToSByte((decimal)-200m);
1681                                 Assert.Fail ();
1682                         }
1683                         catch (Exception e) {
1684                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M29");
1685                         }
1686
1687                         try {
1688                                 Convert.ToSByte((double)150);
1689                                 Assert.Fail ();
1690                         }
1691                         catch (Exception e) {
1692                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M30");
1693                         }
1694
1695                         try {
1696                                 Convert.ToSByte((double)-128.6);
1697                                 Assert.Fail ();
1698                         }
1699                         catch (Exception e) {
1700                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M31");
1701                         }
1702
1703                         try {
1704                                 Convert.ToSByte((short)150);
1705                                 Assert.Fail ();
1706                         }
1707                         catch (Exception e) {
1708                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M32");
1709                         }
1710
1711                         try {
1712                                 Convert.ToSByte((short)-300);
1713                                 Assert.Fail ();
1714                         }
1715                         catch (Exception e) {
1716                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M33");
1717                         }
1718
1719                         try {
1720                                 Convert.ToSByte((int)1500);
1721                                 Assert.Fail ();
1722                         }
1723                         catch (Exception e) {
1724                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M34");
1725                         }
1726
1727                         try {
1728                                 Convert.ToSByte((int)-1286);
1729                                 Assert.Fail ();
1730                         }
1731                         catch (Exception e) {
1732                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M35");
1733                         }
1734
1735                         try {
1736                                 Convert.ToSByte((long)128);
1737                                 Assert.Fail ();
1738                         }
1739                         catch (Exception e) {
1740                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M36");
1741                         }
1742
1743                         try {
1744                                 Convert.ToSByte((long)-129);
1745                                 Assert.Fail ();
1746                         }
1747                         catch (Exception e) {
1748                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M37");
1749                         }
1750
1751                         try {
1752                                 Convert.ToSByte(new NumberFormatInfo());
1753                                 Assert.Fail ();
1754                         }
1755                         catch (Exception e) {
1756                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#M38");
1757                         }
1758
1759                         try {
1760                                 Convert.ToSByte((float)333);
1761                                 Assert.Fail ();
1762                         }
1763                         catch (Exception e) {
1764                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M39");
1765                         }
1766
1767                         try {
1768                                 Convert.ToSByte((float)-666);
1769                                 Assert.Fail ();
1770                         }
1771                         catch (Exception e) {
1772                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M40");
1773                         }
1774
1775                         try {
1776                                 Convert.ToSByte("B3");
1777                                 Assert.Fail ();
1778                         }
1779                         catch (Exception e) {
1780                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#M41");
1781                         }
1782
1783                         try {
1784                                 Convert.ToSByte("251");
1785                                 Assert.Fail ();
1786                         }
1787                         catch (Exception e) {
1788                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M42");
1789                         }
1790
1791                         try {
1792                                 Convert.ToSByte(ushort.MaxValue);
1793                                 Assert.Fail ();
1794                         }
1795                         catch (Exception e) {
1796                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M43");
1797                         }
1798
1799                         try {
1800                                 Convert.ToSByte((uint)600);
1801                                 Assert.Fail ();
1802                         }
1803                         catch (Exception e) {
1804                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M44");
1805                         }
1806
1807                         try {
1808                                 Convert.ToSByte(ulong.MaxValue);
1809                                 Assert.Fail ();
1810                         }
1811                         catch (Exception e) {
1812                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M45");
1813                         }
1814
1815                         try {
1816                                 Convert.ToSByte(ci, ci);
1817                                 Assert.Fail ();
1818                         }
1819                         catch (Exception e) {
1820                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#M46");
1821                         }
1822
1823                         try {
1824                                 Convert.ToSByte(tryStr, ci);
1825                                 Assert.Fail ();
1826                         }
1827                         catch (Exception e) {
1828                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#M47");
1829                         }
1830                         
1831                         try {
1832                                 Convert.ToSByte("325", ci);
1833                                 Assert.Fail ();
1834                         }
1835                         catch (Exception e) {
1836                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M48");
1837                         }
1838
1839                         try {
1840                                 Convert.ToSByte("5D", 15);
1841                                 Assert.Fail ();
1842                         }
1843                         catch (Exception e) {
1844                                 Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#M49");
1845                         }
1846                         
1847                         try {                                                   
1848                                 Convert.ToSByte("111111111", 2);
1849                                 Assert.Fail ();
1850                         }
1851                         catch (Exception e) {
1852                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#M50");
1853                         }
1854                 }
1855
1856                 public void TestToSingle() {
1857                         int iTest = 1;
1858                         try {
1859                                 Assert.AreEqual ((float)0, Convert.ToSingle(boolFalse), "#N01");
1860                                 iTest++;
1861                                 Assert.AreEqual ((float)1, Convert.ToSingle(boolTrue), "#N02");
1862                                 iTest++;
1863                                 Assert.AreEqual ((float)0, Convert.ToSingle(tryByte), "#N03");
1864                                 iTest++;
1865                                 Assert.AreEqual ((float)1234, 234, Convert.ToSingle(tryDec), "#N04");
1866                                 iTest++;
1867                                 Assert.AreEqual ((float)0, Convert.ToSingle(tryDbl), "#N05");
1868                                 iTest++;
1869                                 Assert.AreEqual ((float)1234, Convert.ToSingle(tryInt16), "#N06");
1870                                 iTest++;
1871                                 Assert.AreEqual ((float)12345, Convert.ToSingle(tryInt32), "#N07");
1872                                 iTest++;
1873                                 Assert.AreEqual ((float)123456789012, Convert.ToSingle(tryInt64), "#N08");
1874                                 iTest++;
1875                                 Assert.AreEqual ((float)123, Convert.ToSingle(trySByte), "#N09");
1876                                 iTest++;
1877                                 Assert.AreEqual ((float)1234, 2345, Convert.ToSingle(tryFloat), "#N10");
1878                                 iTest++;
1879                                 Assert.AreEqual ((float)987, Convert.ToSingle("987"), "#N11");
1880                                 iTest++;
1881                                 Assert.AreEqual ((float)34567, Convert.ToSingle(tryUI16), "#N12");
1882                                 iTest++;
1883                                 Assert.AreEqual ((float)567891234, Convert.ToSingle(tryUI32), "#N13");
1884                                 iTest++;
1885                                 Assert.AreEqual ((float)0, Convert.ToSingle(tryUI64), "#N14");
1886                                 iTest++;
1887                                 Assert.AreEqual ((float)654.234, Convert.ToSingle("654.234", ci), "#N15");
1888                         } catch (Exception e) {
1889                                 Assert.Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e);
1890                         }
1891
1892                         try {
1893                                 Convert.ToSingle(tryChar);
1894                                 Assert.Fail ();
1895                         }
1896                         catch (Exception e) {
1897                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#N25");
1898                         }
1899
1900                         try {
1901                                 Convert.ToSingle(tryDT);
1902                                 Assert.Fail ();
1903                         }
1904                         catch (Exception e) {
1905                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#N26");
1906                         }
1907
1908                         try {
1909                                 Convert.ToSingle(tryObj);
1910                                 Assert.Fail ();
1911                         }
1912                         catch (Exception e) {
1913                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#N27");
1914                         }
1915                         
1916                         try {
1917                                 Convert.ToSingle("A345H");
1918                                 Assert.Fail ();
1919                         }
1920                         catch (Exception e) {
1921                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#N28");
1922                         }
1923                         
1924                         try {
1925                                 Convert.ToSingle(double.MaxValue.ToString());
1926                                 Assert.Fail ();
1927                         }
1928                         catch (Exception e) {
1929                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#N29");
1930                         }
1931
1932                         try {
1933                                 Convert.ToSingle(tryObj, ci);
1934                                 Assert.Fail ();
1935                         }
1936                         catch (Exception e) {
1937                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#N30");
1938                         }
1939
1940                         try {
1941                                 Convert.ToSingle("J345K", ci);
1942                                 Assert.Fail ();
1943                         }
1944                         catch (Exception e) {
1945                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#N31");
1946                         }
1947
1948                         try {
1949                                 Convert.ToSingle("11000000000000000000000000000000000000000000000", ci);
1950                                 Assert.Fail ();
1951                         }
1952                         catch (Exception e) {
1953                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#N32");
1954                         }
1955                 }
1956
1957                 public void TestToString() {
1958                         
1959                         tryByte = 123;
1960                         Assert.AreEqual ("False", Convert.ToString(boolFalse), "#O01");
1961                         Assert.AreEqual ("True", Convert.ToString(boolTrue), "#O02");
1962                         Assert.AreEqual ("123", Convert.ToString(tryByte), "#O03");
1963                         Assert.AreEqual ("a", Convert.ToString(tryChar), "#O04");
1964                         Assert.AreEqual (tryDT.ToString(), Convert.ToString(tryDT), "#O05");
1965                         Assert.AreEqual (tryDec.ToString(), Convert.ToString(tryDec), "#O06");
1966                         Assert.AreEqual (tryDbl.ToString(), Convert.ToString(tryDbl), "#O07");
1967                         Assert.AreEqual ("1234", Convert.ToString(tryInt16), "#O08");
1968                         Assert.AreEqual ("12345", Convert.ToString(tryInt32), "#O09");
1969                         Assert.AreEqual ("123456789012", Convert.ToString(tryInt64), "#O10");
1970                         Assert.AreEqual ("123", Convert.ToString(trySByte), "#O11");
1971                         Assert.AreEqual (tryFloat.ToString(), Convert.ToString(tryFloat), "#O12");
1972                         Assert.AreEqual ("foobar", Convert.ToString(tryStr), "#O13");
1973                         Assert.AreEqual ("34567", Convert.ToString(tryUI16), "#O14");
1974                         Assert.AreEqual ("567891234", Convert.ToString(tryUI32), "#O15");
1975                         Assert.AreEqual ("True", Convert.ToString(boolTrue, ci), "#O16");
1976                         Assert.AreEqual ("False", Convert.ToString(boolFalse, ci), "#O17");
1977                         Assert.AreEqual ("123", Convert.ToString(tryByte, ci), "#O18");
1978                         Assert.AreEqual ("1111011", Convert.ToString(tryByte, 2), "#O19");
1979                         Assert.AreEqual ("173", Convert.ToString(tryByte, 8), "#O20");
1980                         Assert.AreEqual ("123", Convert.ToString(tryByte, 10), "#O21");
1981                         Assert.AreEqual ("7b", Convert.ToString(tryByte, 16), "#O22");
1982                         Assert.AreEqual ("a", Convert.ToString(tryChar, ci), "#O23");
1983                         Assert.AreEqual (tryDT.ToString(ci), Convert.ToString(tryDT, ci), "#O24");
1984                         Assert.AreEqual (tryDec.ToString(ci), Convert.ToString(tryDec, ci), "#O25");
1985                         Assert.AreEqual (tryDbl.ToString(ci), Convert.ToString(tryDbl, ci), "#O26");
1986                         Assert.AreEqual ("1234", Convert.ToString(tryInt16, ci), "#O27");
1987                         Assert.AreEqual ("10011010010", Convert.ToString(tryInt16, 2), "#O28");
1988                         Assert.AreEqual ("2322", Convert.ToString(tryInt16, 8), "#O29");
1989                         Assert.AreEqual ("1234", Convert.ToString(tryInt16, 10), "#O30");
1990                         Assert.AreEqual ("4d2", Convert.ToString(tryInt16, 16), "#O31");
1991                         Assert.AreEqual ("12345", Convert.ToString(tryInt32, ci), "#O32");
1992                         Assert.AreEqual ("11000000111001", Convert.ToString(tryInt32, 2), "#O33");
1993                         Assert.AreEqual ("30071", Convert.ToString(tryInt32, 8), "#O34");
1994                         Assert.AreEqual ("12345", Convert.ToString(tryInt32, 10), "#O35");
1995                         Assert.AreEqual ("3039", Convert.ToString(tryInt32, 16), "#O36");
1996                         Assert.AreEqual ("123456789012", Convert.ToString(tryInt64, ci), "#O37");
1997                         Assert.AreEqual ("1110010111110100110010001101000010100", Convert.ToString(tryInt64, 2), "#O38");
1998                         Assert.AreEqual ("1627646215024", Convert.ToString(tryInt64, 8), "#O39");
1999                         Assert.AreEqual ("123456789012", Convert.ToString(tryInt64, 10), "#O40");
2000                         Assert.AreEqual ("1cbe991a14", Convert.ToString(tryInt64, 16), "#O41");
2001                         Assert.AreEqual ("123", Convert.ToString((trySByte), ci), "#O42");
2002                         Assert.AreEqual (tryFloat.ToString(ci), Convert.ToString((tryFloat), ci), "#O43");
2003                         Assert.AreEqual ("foobar", Convert.ToString((tryStr), ci), "#O44");
2004                         Assert.AreEqual ("34567", Convert.ToString((tryUI16), ci), "#O45");
2005                         Assert.AreEqual ("567891234", Convert.ToString((tryUI32), ci), "#O46");
2006                         Assert.AreEqual ("0", Convert.ToString(tryUI64), "#O47");
2007                         Assert.AreEqual ("0", Convert.ToString((tryUI64), ci), "#O48");
2008
2009                         try {
2010                                 Convert.ToString(tryInt16, 5);
2011                                 Assert.Fail ();
2012                         }
2013                         catch (Exception e) {
2014                                 Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#O55");
2015                         }
2016
2017                         try {
2018                                 Convert.ToString(tryInt32, 17);
2019                                 Assert.Fail ();
2020                         }
2021                         catch (Exception e) {
2022                                 Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#O56");
2023                         }
2024
2025                         try {
2026                                 Convert.ToString(tryInt64, 1);
2027                                 Assert.Fail ();
2028                         }
2029                         catch (Exception e) {
2030                                 Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#O57");
2031                         }                       
2032                 }
2033
2034                 public void TestToUInt16() {
2035                         Assert.AreEqual ((ushort)0, Convert.ToUInt16(boolFalse), "#P01");
2036                         Assert.AreEqual ((ushort)1, Convert.ToUInt16(boolTrue), "#P02");
2037                         Assert.AreEqual ((ushort)0, Convert.ToUInt16(tryByte), "#P03");
2038                         Assert.AreEqual ((ushort)97, Convert.ToUInt16(tryChar), "#P04");
2039                         Assert.AreEqual ((ushort)1234, Convert.ToUInt16(tryDec), "#P05");
2040                         Assert.AreEqual ((ushort)0, Convert.ToUInt16(tryDbl), "#P06");
2041                         Assert.AreEqual ((ushort)1234, Convert.ToUInt16(tryInt16), "#P07");
2042                         Assert.AreEqual ((ushort)12345, Convert.ToUInt16(tryInt32), "#P08");
2043                         Assert.AreEqual ((ushort)43752, Convert.ToUInt16((long)43752), "#P09");
2044                         Assert.AreEqual ((ushort)123, Convert.ToUInt16(trySByte), "#P10");
2045                         Assert.AreEqual ((ushort)1234, Convert.ToUInt16(tryFloat), "#P11");
2046                         Assert.AreEqual ((ushort)123, Convert.ToUInt16((string)"123"), "#P12");
2047                         Assert.AreEqual ((ushort)34567, Convert.ToUInt16(tryUI16), "#P13");
2048                         Assert.AreEqual ((ushort)56789, Convert.ToUInt16((uint)56789), "#P14");
2049                         Assert.AreEqual ((ushort)0, Convert.ToUInt16(tryUI64), "#P15");
2050                         Assert.AreEqual ((ushort)31, Convert.ToUInt16("31", ci), "#P16");
2051                         Assert.AreEqual ((ushort)14, Convert.ToUInt16("1110", 2), "#P17");
2052                         Assert.AreEqual ((ushort)32, Convert.ToUInt16("40", 8), "#P18");
2053                         Assert.AreEqual ((ushort)40, Convert.ToUInt16("40", 10), "#P19");
2054                         Assert.AreEqual ((ushort)64, Convert.ToUInt16("40", 16), "#P20");
2055
2056
2057                         try {
2058                                 Convert.ToUInt16(tryDT);
2059                                 Assert.Fail ();
2060                         }
2061                         catch (Exception e) {
2062                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#P25");
2063                         }
2064
2065                         try {
2066                                 Convert.ToUInt16(decimal.MaxValue);
2067                                 Assert.Fail ();
2068                         }
2069                         catch (Exception e) {
2070                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P26");
2071                         }
2072
2073                         try {
2074                                 Convert.ToUInt16(decimal.MinValue);
2075                                 Assert.Fail ();
2076                         }
2077                         catch (Exception e) {
2078                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P27");
2079                         }
2080
2081                         try {
2082                                 Convert.ToUInt16(double.MaxValue);
2083                                 Assert.Fail ();
2084                         }
2085                         catch (Exception e) {
2086                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P28");
2087                         }
2088
2089                         try {
2090                                 Convert.ToUInt16(double.MinValue);
2091                                 Assert.Fail ();
2092                         }
2093                         catch (Exception e) {
2094                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P29");
2095                         }
2096
2097                         try {
2098                                 Convert.ToUInt16(short.MinValue);
2099                                 Assert.Fail ();
2100                         }
2101                         catch (Exception e) {
2102                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P30");
2103                         }
2104
2105                         try {
2106                                 Convert.ToUInt16(int.MaxValue);
2107                                 Assert.Fail ();
2108                         }
2109                         catch (Exception e) {
2110                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P31");
2111                         }
2112
2113                         try {
2114                                 Convert.ToUInt16(int.MinValue);
2115                                 Assert.Fail ();
2116                         }
2117                         catch (Exception e) {
2118                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P32");
2119                         }
2120
2121                         try {
2122                                 Convert.ToUInt16(long.MaxValue);
2123                                 Assert.Fail ();
2124                         }
2125                         catch (Exception e) {
2126                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P33");
2127                         }
2128
2129                         try {
2130                                 Convert.ToUInt16(long.MinValue);
2131                                 Assert.Fail ();
2132                         }
2133                         catch (Exception e) {
2134                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P34");
2135                         }
2136
2137                         try {
2138                                 Convert.ToUInt16(tryObj);
2139                                 Assert.Fail ();
2140                         }
2141                         catch (Exception e) {
2142                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#P35");
2143                         }
2144
2145                         try {
2146                                 Convert.ToUInt16(sbyte.MinValue);
2147                                 Assert.Fail ();
2148                         }
2149                         catch (Exception e) {
2150                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P36");
2151                         }
2152
2153                         try {
2154                                 Convert.ToUInt16(float.MaxValue);
2155                                 Assert.Fail ();
2156                         }
2157                         catch (Exception e) {
2158                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P37");
2159                         }
2160
2161                         try {
2162                                 Convert.ToUInt16(float.MinValue);
2163                                 Assert.Fail ();
2164                         }
2165                         catch (Exception e) {
2166                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P38");
2167                         }
2168                         
2169                         try {
2170                                 Convert.ToUInt16("1A2");
2171                                 Assert.Fail ();
2172                         }
2173                         catch (Exception e) {
2174                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#P39");
2175                         }
2176
2177                         try {
2178                                 Convert.ToUInt16("-32800");
2179                                 Assert.Fail ();
2180                         }
2181                         catch (Exception e) {
2182                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P40");
2183                         }
2184
2185                         try {
2186                                 Convert.ToUInt16(int.MaxValue.ToString());
2187                                 Assert.Fail ();
2188                         }
2189                         catch (Exception e) {
2190                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P41");
2191                         }
2192
2193                         try {
2194                                 Convert.ToUInt16(ulong.MaxValue);
2195                                 Assert.Fail ();
2196                         }
2197                         catch (Exception e) {
2198                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P42");
2199                         }
2200
2201                         try {
2202                                 Convert.ToUInt16("1A2", ci);
2203                                 Assert.Fail ();
2204                         }
2205                         catch (Exception e) {
2206                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#P43");
2207                         }
2208
2209                         try {
2210                                 Convert.ToUInt16("-32800", ci);
2211                                 Assert.Fail ();
2212                         }
2213                         catch (Exception e) {
2214                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P44");
2215                         }
2216
2217                         try {
2218                                 Convert.ToUInt16("456987", ci);
2219                                 Assert.Fail ();
2220                         }
2221                         catch (Exception e) {
2222                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#P45");
2223                         }
2224
2225                         try {
2226                                 Convert.ToUInt16("40", 9);
2227                                 Assert.Fail ();
2228                         }
2229                         catch (Exception e) {
2230                                 Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#P46");
2231                         }
2232
2233                         try {
2234                                 Convert.ToUInt16 ("abcde", 16);
2235                                 Assert.Fail ();
2236                         }
2237                         catch (Exception e) {
2238                                 Assert.AreEqual (typeof (OverflowException), e.GetType (), "#P47");
2239                         }
2240                 }
2241
2242                 public void TestSignedToInt() {
2243                   //  String cannot contain a minus sign if the base is not 10.
2244                   // But can if it is ten, and + is allowed everywhere.
2245                   Assert.AreEqual (-1, Convert.ToInt32 ("-1", 10), "Signed0");
2246                   Assert.AreEqual (1, Convert.ToInt32 ("+1", 10), "Signed1");
2247                   Assert.AreEqual (1, Convert.ToInt32 ("+1", 2), "Signed2");
2248                   Assert.AreEqual (1, Convert.ToInt32 ("+1", 8), "Signed3");
2249                   Assert.AreEqual (1, Convert.ToInt32 ("+1", 16), "Signed4");
2250                   
2251                   try {
2252                         Convert.ToInt32("-1", 2);
2253                         Assert.Fail ();
2254                   }
2255                   catch (Exception) {
2256                   }
2257                   try {
2258                         Convert.ToInt32("-1", 8);
2259                         Assert.Fail ();
2260                   }
2261                   catch (Exception) {
2262                   }
2263                   try {
2264                         Convert.ToInt32("-1", 16);
2265                         Assert.Fail ();
2266                   }
2267                   catch (Exception) {
2268                   }
2269
2270
2271                 }
2272         
2273                 public void TestToUInt32() {
2274                         Assert.AreEqual ((uint)1, Convert.ToUInt32(boolTrue), "#Q01");
2275                         Assert.AreEqual ((uint)0, Convert.ToUInt32(boolFalse), "#Q02");
2276                         Assert.AreEqual ((uint)0, Convert.ToUInt32(tryByte), "#Q03");
2277                         Assert.AreEqual ((uint)97, Convert.ToUInt32(tryChar), "#Q04");
2278                         Assert.AreEqual ((uint)1234, Convert.ToUInt32(tryDec), "#Q05");
2279                         Assert.AreEqual ((uint)0, Convert.ToUInt32(tryDbl), "#Q06");
2280                         Assert.AreEqual ((uint)1234, Convert.ToUInt32(tryInt16), "#Q07");
2281                         Assert.AreEqual ((uint)12345, Convert.ToUInt32(tryInt32), "#Q08");
2282                         Assert.AreEqual ((uint)1234567890, Convert.ToUInt32((long)1234567890), "#Q09");
2283                         Assert.AreEqual ((uint)123, Convert.ToUInt32(trySByte), "#Q10");
2284                         Assert.AreEqual ((uint)1234, Convert.ToUInt32(tryFloat), "#Q11");
2285                         Assert.AreEqual ((uint)3456789, Convert.ToUInt32("3456789"), "#Q12");
2286                         Assert.AreEqual ((uint)34567, Convert.ToUInt32(tryUI16), "#Q13");
2287                         Assert.AreEqual ((uint)567891234, Convert.ToUInt32(tryUI32), "#Q14");
2288                         Assert.AreEqual ((uint)0, Convert.ToUInt32(tryUI64), "#Q15");
2289                         Assert.AreEqual ((uint)415, Convert.ToUInt32("110011111", 2), "#Q16");
2290                         Assert.AreEqual ((uint)156, Convert.ToUInt32("234", 8), "#Q17");
2291                         Assert.AreEqual ((uint)234, Convert.ToUInt32("234", 10), "#Q18");
2292                         Assert.AreEqual ((uint)564, Convert.ToUInt32("234", 16), "#Q19");
2293                         
2294
2295                         try {
2296                                 Convert.ToUInt32(tryDT);
2297                                 Assert.Fail ();
2298                         }
2299                         catch (Exception e) {
2300                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#Q25");
2301                         }
2302
2303                         try {
2304                                 Convert.ToUInt32(decimal.MaxValue);
2305                                 Assert.Fail ();
2306                         }
2307                         catch (Exception e) {
2308                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q26");
2309                         }
2310
2311                         try {
2312                                 Convert.ToUInt32((decimal)-150);
2313                                 Assert.Fail ();
2314                         }
2315                         catch (Exception e) {
2316                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q27");
2317                         }
2318
2319                         try {
2320                                 Convert.ToUInt32(double.MaxValue);
2321                                 Assert.Fail ();
2322                         }
2323                         catch (Exception e) {
2324                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q28");
2325                         }
2326
2327                         try {
2328                                 Convert.ToUInt32((double)-1);
2329                                 Assert.Fail ();
2330                         }
2331                         catch (Exception e) {
2332                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q29");
2333                         }
2334
2335                         try {
2336                                 Convert.ToUInt32(short.MinValue);
2337                                 Assert.Fail ();
2338                         }
2339                         catch (Exception e) {
2340                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q30");
2341                         }
2342
2343                         try {
2344                                 Convert.ToUInt32(int.MinValue);
2345                                 Assert.Fail ();
2346                         }
2347                         catch (Exception e) {
2348                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q31");
2349                         }
2350
2351                         try {
2352                                 Convert.ToUInt32(long.MaxValue);
2353                                 Assert.Fail ();
2354                         }
2355                         catch (Exception e) {
2356                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q32");
2357                         }
2358
2359                         try {
2360                                 Convert.ToUInt32((long)-50000);
2361                                 Assert.Fail ();
2362                         }
2363                         catch (Exception e) {
2364                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q33");
2365                         }
2366
2367                         try {
2368                                 Convert.ToUInt32(new Exception());
2369                                 Assert.Fail ();
2370                         }
2371                         catch (Exception e) {
2372                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#Q34");
2373                         }
2374
2375                         try {
2376                                 Convert.ToUInt32(sbyte.MinValue);
2377                                 Assert.Fail ();
2378                         }
2379                         catch (Exception e) {
2380                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q35");
2381                         }
2382
2383                         try {
2384                                 Convert.ToUInt32(float.MaxValue);
2385                                 Assert.Fail ();
2386                         }
2387                         catch (Exception e) {
2388                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q36");
2389                         }
2390
2391                         try {
2392                                 Convert.ToUInt32(float.MinValue);
2393                                 Assert.Fail ();
2394                         }
2395                         catch (Exception e) {
2396                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q37");
2397                         }
2398
2399                         try {
2400                                 Convert.ToUInt32("45t54");
2401                                 Assert.Fail ();
2402                         }
2403                         catch (Exception e) {
2404                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#Q38");
2405                         }
2406
2407                         try {
2408                                 Convert.ToUInt32("-55");
2409                                 Assert.Fail ();
2410                         }
2411                         catch (Exception e) {
2412                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q39");
2413                         }
2414
2415                         try {
2416                                 Convert.ToUInt32(ulong.MaxValue);
2417                                 Assert.Fail ();
2418                         }
2419                         catch (Exception e) {
2420                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q40");
2421                         }
2422
2423                         try {
2424                                 Convert.ToUInt32(new Exception(), ci);
2425                                 Assert.Fail ();
2426                         }
2427                         catch (Exception e) {
2428                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#Q41");
2429                         }
2430
2431                         try {
2432                                 Convert.ToUInt32(tryStr, ci);
2433                                 Assert.Fail ();
2434                         }
2435                         catch (Exception e) {
2436                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#Q42");
2437                         }
2438
2439                         try {
2440                                 Convert.ToUInt32("-50", ci);
2441                                 Assert.Fail ();
2442                         }
2443                         catch (Exception e) {
2444                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q43");
2445                         }
2446
2447                         try {
2448                                 Convert.ToUInt32(decimal.MaxValue.ToString(), ci);
2449                                 Assert.Fail ();
2450                         }
2451                         catch (Exception e) {
2452                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#Q44");
2453                         }
2454
2455                         try {
2456                                 Convert.ToUInt32("1001110", 1);
2457                                 Assert.Fail ();
2458                         }
2459                         catch (Exception e) {
2460                                 Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#Q45");
2461                         }
2462                 }
2463
2464                 public void TestToUInt64() 
2465                 {
2466                         int iTest = 1;
2467                         try {
2468                                 Assert.AreEqual ((ulong)1, Convert.ToUInt64(boolTrue), "#R01");
2469                                 iTest++;
2470                                 Assert.AreEqual ((ulong)0, Convert.ToUInt64(boolFalse), "#R02");
2471                                 iTest++;
2472                                 Assert.AreEqual ((ulong)0, Convert.ToUInt64(tryByte), "#R03");
2473                                 iTest++;
2474                                 Assert.AreEqual ((ulong)97, Convert.ToUInt64(tryChar), "#R04");
2475                                 iTest++;
2476                                 Assert.AreEqual ((ulong)1234, Convert.ToUInt64(tryDec), "#R05");
2477                                 iTest++;
2478                                 Assert.AreEqual ((ulong)0, Convert.ToUInt64(tryDbl), "#R06");
2479                                 iTest++;
2480                                 Assert.AreEqual ((ulong)1234, Convert.ToUInt64(tryInt16), "#R07");
2481                                 iTest++;
2482                                 Assert.AreEqual ((ulong)12345, Convert.ToUInt64(tryInt32), "#R08");
2483                                 iTest++;
2484                                 Assert.AreEqual ((ulong)123456789012, Convert.ToUInt64(tryInt64), "#R09");
2485                                 iTest++;
2486                                 Assert.AreEqual ((ulong)123, Convert.ToUInt64(trySByte), "#R10");
2487                                 iTest++;
2488                                 Assert.AreEqual ((ulong)1234, Convert.ToUInt64(tryFloat), "#R11");
2489                                 iTest++;
2490                                 Assert.AreEqual ((ulong)345678, Convert.ToUInt64("345678"), "#R12");
2491                                 iTest++;
2492                                 Assert.AreEqual ((ulong)34567, Convert.ToUInt64(tryUI16), "#R13");
2493                                 iTest++;
2494                                 Assert.AreEqual ((ulong)567891234, Convert.ToUInt64(tryUI32), "#R14");
2495                                 iTest++;
2496                                 Assert.AreEqual ((ulong)0, Convert.ToUInt64(tryUI64), "#R15");
2497                                 iTest++;
2498                                 Assert.AreEqual ((ulong)123, Convert.ToUInt64("123", ci), "#R16");
2499                                 iTest++;
2500                                 Assert.AreEqual ((ulong)4, Convert.ToUInt64("100", 2), "#R17");
2501                                 iTest++;
2502                                 Assert.AreEqual ((ulong)64, Convert.ToUInt64("100", 8), "#R18");
2503                                 iTest++;
2504                                 Assert.AreEqual ((ulong)100, Convert.ToUInt64("100", 10), "#R19");
2505                                 iTest++;
2506                                 Assert.AreEqual ((ulong)256, Convert.ToUInt64("100", 16), "#R20");
2507                         } catch (Exception e) {
2508                                 Assert.Fail ("Unexpected exception caught when iTest = " + iTest + ": e = " + e);
2509                         }
2510
2511                         try {
2512                                 Convert.ToUInt64(tryDT);
2513                                 Assert.Fail ();
2514                         }
2515                         catch (Exception e) {
2516                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#R25");
2517                         }
2518
2519                         try {
2520                                 Convert.ToUInt64(decimal.MaxValue);
2521                                 Assert.Fail ();
2522                         }
2523                         catch (Exception e) {
2524                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R26");
2525                         }
2526
2527                         try {
2528                                 Convert.ToUInt64((decimal)-140);
2529                                 Assert.Fail ();
2530                         }
2531                         catch (Exception e) {
2532                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R27");
2533                         }
2534
2535                         try {
2536                                 Convert.ToUInt64(double.MaxValue);
2537                                 Assert.Fail ();
2538                         }
2539                         catch (Exception e) {
2540                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R28");
2541                         }
2542
2543                         try {
2544                                 Convert.ToUInt64((double)-1);
2545                                 Assert.Fail ();
2546                         }
2547                         catch (Exception e) {
2548                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R29");
2549                         }
2550
2551                         try {
2552                                 Convert.ToUInt64(short.MinValue);
2553                                 Assert.Fail ();
2554                         }
2555                         catch (Exception e) {
2556                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R30");
2557                         }
2558
2559                         try {
2560                                 Convert.ToUInt64(int.MinValue);
2561                                 Assert.Fail ();
2562                         }
2563                         catch (Exception e) {
2564                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R31");
2565                         }
2566
2567                         try {
2568                                 Convert.ToUInt64(long.MinValue);
2569                                 Assert.Fail ();
2570                         }
2571                         catch (Exception e) {
2572                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R32");
2573                         }
2574
2575                         try {
2576                                 Convert.ToUInt64(tryObj);
2577                                 Assert.Fail ();
2578                         }
2579                         catch (Exception e) {
2580                                 Assert.AreEqual (typeof(InvalidCastException), e.GetType(), "#R33");
2581                         }
2582
2583                         try {
2584                                 Convert.ToUInt64(sbyte.MinValue);
2585                                 Assert.Fail ();
2586                         }
2587                         catch (Exception e) {
2588                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R34");
2589                         }
2590
2591                         try {
2592                                 Convert.ToUInt64(float.MinValue);
2593                                 Assert.Fail ();
2594                         }
2595                         catch (Exception e) {
2596                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R35");
2597                         }
2598
2599                         try {
2600                                 Convert.ToUInt64(float.MaxValue);
2601                                 Assert.Fail ();
2602                         }
2603                         catch (Exception e) {
2604                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R36");
2605                         }
2606
2607                         try {
2608                                 Convert.ToUInt64("234rt78");
2609                                 Assert.Fail ();
2610                         }
2611                         catch (Exception e) {
2612                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#R37");
2613                         }
2614
2615                         try {
2616                                 Convert.ToUInt64("-68");
2617                                 Assert.Fail ();
2618                         }
2619                         catch (Exception e) {
2620                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R38");
2621                         }
2622
2623                         try {
2624                                 Convert.ToUInt64(decimal.MaxValue.ToString());
2625                                 Assert.Fail ();
2626                         }
2627                         catch (Exception e) {
2628                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R39");
2629                         }
2630
2631                         try {
2632                                 Convert.ToUInt64("23rd2", ci);
2633                                 Assert.Fail ();
2634                         }
2635                         catch (Exception e) {
2636                                 Assert.AreEqual (typeof(FormatException), e.GetType(), "#R40");
2637                         }
2638
2639                         try {
2640                                 Convert.ToUInt64(decimal.MinValue.ToString(), ci);
2641                                 Assert.Fail ();
2642                         }
2643                         catch (Exception e) {
2644                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R41");
2645                         }
2646
2647                         try {
2648                                 Convert.ToUInt64(decimal.MaxValue.ToString(), ci);
2649                                 Assert.Fail ();
2650                         }
2651                         catch (Exception e) {
2652                                 Assert.AreEqual (typeof(OverflowException), e.GetType(), "#R42");
2653                         }
2654
2655                         try {
2656                                 Convert.ToUInt64("132", 9);
2657                                 Assert.Fail ();
2658                         }
2659                         catch (Exception e) {
2660                                 Assert.AreEqual (typeof(ArgumentException), e.GetType(), "#R43");
2661                         }
2662
2663
2664                         Assert.AreEqual ((ulong) 256, Convert.ToUInt64 ("0x100", 16), "#L35");
2665                         Assert.AreEqual ((ulong) 256, Convert.ToUInt64 ("0X100", 16), "#L36");
2666                         Assert.AreEqual (ulong.MaxValue, Convert.ToUInt64 ("0xFFFFFFFFFFFFFFFF", 16), "#L37");
2667                 }
2668
2669                 [Test]
2670                 [ExpectedException (typeof (FormatException))]
2671                 public void TestInvalidBase64() {
2672                   // This has to be a multiple of 4 characters, otherwise you 
2673                   // are testing something else. Ideally one will become a byte
2674                   // > 128
2675                   //
2676                   // This test is designed to see what happens with invalid bytes
2677                   string brokenB64 = "AB~\u00a3";
2678                   Convert.FromBase64String(brokenB64);
2679                 }
2680
2681                 [Test]
2682                 public void TestBeginWithSpaces ()
2683                 {
2684                         byte[] bb = new byte[] { 1, 2, 3};
2685                         string s = Convert.ToBase64String (bb);
2686                         byte [] b2 = Convert.FromBase64String ("     " + s);
2687                         Assert.AreEqual (3, b2.Length, "#01");
2688                         for (int i = 0; i < 3; i++)
2689                                 Assert.AreEqual (bb [i], b2 [i], "#0" + (i + 2));
2690                 }
2691                 
2692                 public void TestToBase64CharArray ()
2693                 {
2694                         byte[] byteArr = {33, 127, 255, 109, 170, 54};
2695                         //                                                 0    1        2        3    4        5        6        7
2696                         char[] expectedCharArr = {'I', 'X', '/', '/', 'b', 'a', 'o', '2'};
2697                         char[] result = new Char[8];
2698                         
2699                         Convert.ToBase64CharArray(byteArr, 0, byteArr.Length, result, 0);
2700
2701                         for (int i = 0; i < expectedCharArr.Length; i++) {
2702                                 Assert.AreEqual (expectedCharArr[i], result[i], "#S0" + i);
2703                         }
2704                 }
2705
2706                 [Test]
2707                 [ExpectedException (typeof(ArgumentNullException))]
2708                 public void ToBase64CharArray_InNull ()
2709                 {
2710                         byte[] byteArr = {33, 127, 255, 109, 170, 54};
2711                         char[] result = new Char[8];
2712                         Convert.ToBase64CharArray (null, 0, byteArr.Length, result, 0);
2713                 }
2714
2715                 [Test]
2716                 [ExpectedException (typeof(ArgumentNullException))]
2717                 public void ToBase64CharArray_OutNull ()
2718                 {
2719                         byte[] byteArr = {33, 127, 255, 109, 170, 54};
2720                         Convert.ToBase64CharArray (byteArr, 0, byteArr.Length, null, 0);
2721                 }
2722
2723                 [Test]
2724                 [ExpectedException (typeof(ArgumentOutOfRangeException))]
2725                 public void ToBase64CharArray_OffsetInNegative ()
2726                 {
2727                         byte[] byteArr = {33, 127, 255, 109, 170, 54};
2728                         char[] result = new Char[8];
2729                         Convert.ToBase64CharArray (byteArr, -1, byteArr.Length, result, 0);
2730                 }
2731
2732                 [Test]
2733                 [ExpectedException (typeof(ArgumentOutOfRangeException))]
2734                 public void ToBase64CharArray_LengthNegative ()
2735                 {
2736                         byte[] byteArr = {33, 127, 255, 109, 170, 54};
2737                         char[] result = new Char[8];
2738                         Convert.ToBase64CharArray (byteArr, 0, -5, result, 0);
2739                 }
2740
2741                 [Test]
2742                 [ExpectedException (typeof(ArgumentOutOfRangeException))]
2743                 public void ToBase64CharArray_OffsetOutNegative ()
2744                 {
2745                         byte[] byteArr = {33, 127, 255, 109, 170, 54};
2746                         char[] result = new Char[8];
2747                         Convert.ToBase64CharArray (byteArr, 0, byteArr.Length, result, -2);
2748                 }
2749
2750                 [Test]
2751                 [ExpectedException (typeof(ArgumentOutOfRangeException))]
2752                 public void ToBase64CharArray_TotalIn ()
2753                 {
2754                         byte[] byteArr = {33, 127, 255, 109, 170, 54};
2755                         char[] result = new Char[8];
2756                         Convert.ToBase64CharArray (byteArr, 4, byteArr.Length, result, 0);
2757                 }
2758
2759                 [Test]
2760                 [ExpectedException (typeof(ArgumentOutOfRangeException))]
2761                 public void ToBase64CharArray_TotalInOverflow ()
2762                 {
2763                         byte[] byteArr = {33, 127, 255, 109, 170, 54};
2764                         char[] result = new Char[8];
2765                         Convert.ToBase64CharArray (byteArr, Int32.MaxValue, byteArr.Length, result, 0);
2766                 }
2767
2768                 [Test]
2769                 [ExpectedException (typeof(ArgumentOutOfRangeException))]
2770                 public void ToBase64CharArray_TotalOut ()
2771                 {
2772                         byte[] byteArr = {33, 127, 255, 109, 170, 54};
2773                         char[] result = new Char[8];
2774                         Convert.ToBase64CharArray (byteArr, 0, byteArr.Length, result, 2);
2775                 }
2776
2777                 [Test]
2778                 [ExpectedException (typeof(ArgumentOutOfRangeException))]
2779                 public void ToBase64CharArray_TotalOutOverflow ()
2780                 {
2781                         byte[] byteArr = {33, 127, 255, 109, 170, 54};
2782                         char[] result = new Char[8];
2783                         Convert.ToBase64CharArray (byteArr, 0, byteArr.Length, result, Int32.MaxValue);
2784                 }
2785
2786                 public void TestToBase64String() {
2787                         byte[] byteArr = {33, 127, 255, 109, 170, 54};
2788                         string expectedStr = "IX//bao2";
2789                         string result1;
2790                         string result2;
2791                         
2792                         result1 = Convert.ToBase64String(byteArr);
2793                         result2 = Convert.ToBase64String(byteArr, 0, byteArr.Length);
2794
2795                         Assert.AreEqual (expectedStr, result1, "#T01");
2796                         Assert.AreEqual (expectedStr, result2, "#T02");
2797
2798                         try {
2799                                 Convert.ToBase64String(null);
2800                                 Assert.Fail ();
2801                         }
2802                         catch (Exception e) {
2803                                 Assert.AreEqual (typeof(ArgumentNullException), e.GetType(), "#T05");
2804                         }
2805                         
2806                         try {
2807                                 Convert.ToBase64String(byteArr, -1, byteArr.Length);
2808                                 Assert.Fail ();
2809                         }
2810                         catch (Exception e) {
2811                                 Assert.AreEqual (typeof(ArgumentOutOfRangeException), e.GetType(), "#T06");
2812                         }
2813
2814                         try {
2815                                 Convert.ToBase64String(byteArr, 0, -10);
2816                                 Assert.Fail ();
2817                         }
2818                         catch (Exception e) {
2819                                 Assert.AreEqual (typeof(ArgumentOutOfRangeException), e.GetType(), "#T07");
2820                         }
2821
2822                         try {
2823                                 Convert.ToBase64String(byteArr, 4, byteArr.Length);
2824                                 Assert.Fail ();
2825                         }
2826                         catch (Exception e) {
2827                                 Assert.AreEqual (typeof(ArgumentOutOfRangeException), e.GetType(), "#T08");
2828                         }               
2829                 }
2830 #if NET_2_0
2831                 [Test]
2832                 public void ToBase64String_Bug76876 ()
2833                 {
2834                         byte[] bs = Convert.FromBase64String ("ZuBZ7PESb3VRXgrl/KSRJd/hTGBvaEvEplqH3izPomDv5nBjS9MzcD1h8tOWzS7/wYGnaip8\nbhBfCrpWxivi8G7R08oBcADIiclpZeqRxai9kG4WoBUzJ6MCbxuvb1k757q+D9nqoL0p9Rer\n+5+vNodYkHYwqnKKyMBSQ11sspw=\n");
2835                         string s = Convert.ToBase64String (bs, Base64FormattingOptions.None);
2836                         Assert.IsTrue (!s.Contains ("\n"), "no new line");
2837                 }
2838 #endif
2839                 /* Have experienced some problems with FromBase64CharArray using mono. Something 
2840                  * about error in a unicode file.
2841                  *
2842                  * However the test seems to run fine using mono in a cygwin environment
2843                  */
2844
2845                 [Test]
2846                 [ExpectedException (typeof (ArgumentNullException))]
2847                 public void FromBase64CharArray_Null ()
2848                 {
2849                         Convert.FromBase64CharArray (null, 1, 5);
2850                 }
2851
2852                 [Test]
2853                 [ExpectedException (typeof (FormatException))]
2854                 [Category ("TargetJvmNotWorking")]
2855                 public void FromBase64CharArray_Empty ()
2856                 {
2857                         Convert.FromBase64CharArray (new char[0], 0, 0);
2858                 }
2859
2860                 [Test]
2861                 [ExpectedException (typeof (FormatException))]
2862                 [Category ("TargetJvmNotWorking")]
2863                 public void FormatBase64CharArray_OnlyWhitespace ()
2864                 {
2865                         Convert.FromBase64CharArray (new char[3] {' ', 
2866                                 '\r', '\t'}, 0, 3);
2867                 }
2868
2869                 [Test]
2870                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
2871                 public void FromBase64CharArray_OutOfRangeStart () 
2872                 {
2873                         Convert.FromBase64CharArray (new char [4], -1, 4);
2874                 }
2875
2876                 [Test]
2877                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
2878                 public void FromBase64CharArray_OutOfRangeLength () 
2879                 {
2880                         Convert.FromBase64CharArray (new char [4], 2, 4);
2881                 }
2882
2883                 [Test]
2884                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
2885                 public void FromBase64CharArray_Overflow () 
2886                 {
2887                         Convert.FromBase64CharArray (new char [4], Int32.MaxValue, 4);
2888                 }
2889
2890                 [Test]
2891                 [ExpectedException (typeof (FormatException))]
2892                 public void FromBase64CharArray_InvalidLength () 
2893                 {
2894                         Convert.FromBase64CharArray (new char [4], 0, 3);
2895                 }
2896
2897                 [Test]
2898                 [ExpectedException (typeof (FormatException))]
2899                 public void FromBase64CharArray_WideChar () 
2900                 {
2901                         char[] c = new char [4] { 'A', 'A', 'A', (char) Char.MaxValue };
2902                         Convert.FromBase64CharArray (c, 0, 4);
2903                 }
2904
2905                 [Test]
2906                 public void FromBase64CharArray ()
2907                 {
2908                         char[] charArr = {'M','o','n','o','m','o','n','o'};
2909                         byte[] expectedByteArr = {50, 137, 232, 154, 137, 232};
2910                         
2911                         byte[] fromCharArr = Convert.FromBase64CharArray(charArr, 0, 8);                        
2912
2913                         for (int i = 0; i < fromCharArr.Length; i++){
2914                                 Assert.AreEqual (expectedByteArr[i], fromCharArr[i], "#U0" + i);
2915                         }
2916                 }
2917
2918                 /* Have experienced some problems with FromBase64String using mono. Something about 
2919                  * error in a unicode file.
2920                  *
2921                  * However the test seems to run fine using mono in a cygwin environment
2922                  */
2923
2924                 [Test]
2925                 [ExpectedException (typeof (ArgumentNullException))]
2926                 public void FromBase64String_Null () 
2927                 {
2928                         Convert.FromBase64String (null);
2929                 }
2930
2931                 [Test]
2932                 [ExpectedException (typeof (FormatException))]
2933                 public void FromBase64String_InvalidLength () 
2934                 {
2935                         Convert.FromBase64String ("foo");
2936                 }
2937
2938                 [Test]
2939                 [ExpectedException (typeof (FormatException))]
2940                 public void FromBase64String_InvalidLength2 () 
2941                 {
2942                         Convert.FromBase64String (tryStr);
2943                 }
2944
2945                 [Test]
2946                 public void FromBase64String_InvalidLengthBecauseOfIgnoredChars () 
2947                 {
2948                         byte[] result = Convert.FromBase64String ("AAAA\t");
2949                         Assert.AreEqual (3, result.Length, "InvalidLengthBecauseOfIgnoredChars");
2950                 }
2951
2952                 private const string ignored = "\t\r\n ";
2953                 private const string base64data = "AAAAAAAAAAAAAAAAAAAA"; // 15 bytes 0x00
2954
2955                 [Test]
2956                 public void FromBase64_IgnoreCharsBefore ()
2957                 {
2958                         string s = ignored + base64data;
2959                         byte[] data = Convert.FromBase64String (s);
2960                         Assert.AreEqual (15, data.Length, "String-IgnoreCharsBefore-Ignored");
2961
2962                         char[] c = s.ToCharArray ();
2963                         data = Convert.FromBase64CharArray (c, 0, c.Length);
2964                         Assert.AreEqual (15, data.Length, "CharArray-IgnoreCharsBefore-Ignored");
2965                 }
2966
2967                 [Test]
2968                 public void FromBase64_IgnoreCharsInside () 
2969                 {
2970                         string s = base64data + ignored + base64data;
2971                         byte[] data = Convert.FromBase64String (s);
2972                         Assert.AreEqual (30, data.Length, "String-IgnoreCharsInside-Ignored");
2973
2974                         char[] c = s.ToCharArray ();
2975                         data = Convert.FromBase64CharArray (c, 0, c.Length);
2976                         Assert.AreEqual (30, data.Length, "CharArray-IgnoreCharsInside-Ignored");
2977                 }
2978
2979                 [Test]
2980                 public void FromBase64_IgnoreCharsAfter () 
2981                 {
2982                         string s = base64data + ignored;
2983                         byte[] data = Convert.FromBase64String (s);
2984                         Assert.AreEqual (15, data.Length, "String-IgnoreCharsAfter-Ignored");
2985
2986                         char[] c = s.ToCharArray ();
2987                         data = Convert.FromBase64CharArray (c, 0, c.Length);
2988                         Assert.AreEqual (15, data.Length, "CharArray-IgnoreCharsAfter-Ignored");
2989                 }
2990
2991                 [Test]
2992                 [Category ("TargetJvmNotWorking")]
2993                 public void FromBase64_Empty ()
2994                 {
2995                         Assert.AreEqual (new byte[0], Convert.FromBase64String (string.Empty));
2996                 }
2997
2998                 [Test]
2999 #if !NET_2_0
3000                 [ExpectedException (typeof (FormatException))]
3001 #endif
3002                 public void FromBase64_OnlyWhiteSpace ()
3003                 {
3004 #if NET_2_0
3005                         Assert.AreEqual (new byte[0], Convert.FromBase64String ("  \r\t"));
3006 #else
3007                         Convert.FromBase64String ("  \r\t");
3008 #endif
3009                 }
3010
3011                 [Test]
3012                 [ExpectedException (typeof (FormatException))]
3013                 public void FromBase64_InvalidChar ()
3014                 {
3015                         Convert.FromBase64String ("amVsb3U=\u0100");
3016                 }
3017
3018                 [Test]
3019                 [ExpectedException (typeof (FormatException))]
3020                 public void FromBase64_Min ()
3021                 {
3022                         Convert.FromBase64String ("amVsb3U=   \r \n\u007B");
3023                 }
3024
3025                 [Test]
3026                 public void FromBase64_TrailingEqualAndSpaces () // From bug #75840.
3027                 {
3028                         string base64 = "\n     fdy6S2NLpnT4fMdokUHSHsmpcvo=    ";
3029                         byte [] bytes = Convert.FromBase64String (base64);
3030                         Assert.AreEqual (20, bytes.Length, "#01");
3031                         byte [] target = new byte [] { 0x7D, 0xDC, 0xBA, 0x4B, 0x63, 0x4B, 0xA6, 0x74, 0xF8, 0x7C, 0xC7,
3032                                                         0x68, 0x91, 0x41, 0xD2, 0x1E, 0xC9, 0xA9, 0x72, 0xFA };
3033
3034                         for (int i = 0; i < 20; i++) {
3035                                 if (bytes [i] != target [i])
3036                                         Assert.Fail ("Item #" + i);
3037                         }
3038                 }
3039
3040                 public void TestConvertFromNull() {
3041                         
3042                         Assert.AreEqual (false, Convert.ToBoolean (null as object), "#W1");
3043                         Assert.AreEqual (0, Convert.ToByte (null as object), "#W2");
3044                         Assert.AreEqual (0, Convert.ToChar (null as object), "#W3");
3045                         Assert.AreEqual (new DateTime (1, 1, 1, 0, 0, 0), Convert.ToDateTime (null as object), "#W4");
3046                         Assert.AreEqual (0, Convert.ToDecimal (null as object), "#W5");
3047                         Assert.AreEqual (0, Convert.ToDouble (null as object), "#W6");
3048                         Assert.AreEqual (0, Convert.ToInt16 (null as object), "#W7");
3049                         Assert.AreEqual (0, Convert.ToInt32 (null as object), "#W8");
3050                         Assert.AreEqual (0, Convert.ToInt64 (null as object), "#W9");
3051                         Assert.AreEqual (0, Convert.ToSByte (null as object), "#W10");
3052                         Assert.AreEqual (0, Convert.ToSingle (null as object), "#W11");
3053                         Assert.AreEqual ("", Convert.ToString (null as object), "#W12");
3054                         Assert.AreEqual (0, Convert.ToUInt16 (null as object), "#W13");
3055                         Assert.AreEqual (0, Convert.ToUInt32 (null as object), "#W14");
3056                         Assert.AreEqual (0, Convert.ToUInt64 (null as object), "#W15");
3057                         Assert.AreEqual (false, Convert.ToBoolean (null as string), "#W16");
3058                         Assert.AreEqual (0, Convert.ToByte (null as string), "#W17");
3059
3060                         try {
3061                                 Convert.ToChar (null as string);
3062                                 Assert.Fail ();
3063                         } catch (Exception e) {
3064                                 Assert.AreEqual (typeof (ArgumentNullException), e.GetType (), "#W18");
3065                         }
3066                         
3067                         Assert.AreEqual (new DateTime (1, 1, 1, 0, 0, 0), Convert.ToDateTime (null as string), "#W19");
3068                         Assert.AreEqual (0, Convert.ToDecimal (null as string), "#W20");
3069                         Assert.AreEqual (0, Convert.ToDouble (null as string), "#W21");
3070                         Assert.AreEqual (0, Convert.ToInt16 (null as string), "#W22");
3071                         Assert.AreEqual (0, Convert.ToInt32 (null as string), "#W23");
3072                         Assert.AreEqual (0, Convert.ToInt64 (null as string), "#W24");
3073                         Assert.AreEqual (0, Convert.ToSByte (null as string), "#W25");
3074                         Assert.AreEqual (0, Convert.ToSingle (null as string), "#W26");
3075                         Assert.AreEqual (null, Convert.ToString (null as string), "#W27");
3076                         Assert.AreEqual (0, Convert.ToUInt16 (null as string), "#W28");
3077                         Assert.AreEqual (0, Convert.ToUInt32 (null as string), "#W29");
3078                         Assert.AreEqual (0, Convert.ToUInt64 (null as string), "#W30");
3079                 }
3080
3081                 [Test]
3082                 [ExpectedException (typeof (FormatException))]
3083                 public void FromBase64StringInvalidFormat ()
3084                 {
3085                         Convert.FromBase64String ("Tgtm+DBN====");
3086                 }
3087
3088                 [Test]
3089                 [ExpectedException (typeof (FormatException))]
3090                 public void FromBase64StringInvalidFormat2 ()
3091                 {
3092                         Convert.FromBase64String ("Tgtm+DBN========");
3093                 }
3094
3095                 [Test]
3096                 public void ToByte_PrefixedHexStringInBase16 () 
3097                 {
3098                         Assert.AreEqual (255, Convert.ToByte ("0xff", 16), "0xff");
3099                         Assert.AreEqual (255, Convert.ToByte ("0xfF", 16), "0xfF");
3100                         Assert.AreEqual (255, Convert.ToByte ("0xFf", 16), "0xFf");
3101                         Assert.AreEqual (255, Convert.ToByte ("0xFF", 16), "0xFF");
3102
3103                         Assert.AreEqual (255, Convert.ToByte ("0Xff", 16), "0Xff");
3104                         Assert.AreEqual (255, Convert.ToByte ("0XfF", 16), "0XfF");
3105                         Assert.AreEqual (255, Convert.ToByte ("0XFf", 16), "0XFf");
3106                         Assert.AreEqual (255, Convert.ToByte ("0XFF", 16), "0XFF");
3107
3108                         Assert.AreEqual (Byte.MinValue, Convert.ToByte ("0x0", 16), "0x0");
3109                 }
3110
3111                 [Test]
3112                 [ExpectedException (typeof (OverflowException))]
3113                 public void ToByte_NegativeString () 
3114                 {
3115                         Convert.ToByte ("-1");
3116                 }
3117
3118                 [Test]
3119                 [ExpectedException (typeof (ArgumentException))]
3120                 public void ToByte_NegativeStringNonBase10 () 
3121                 {
3122                         Convert.ToByte ("-0", 16);
3123                 }
3124
3125                 [Test]
3126                 [ExpectedException (typeof (OverflowException))]
3127                 public void ToByte_NegativeString_Base10 ()
3128                 {
3129                         Convert.ToByte ("-0", 10);
3130                 }
3131
3132                 [Test]
3133                 public void ToByte_NegativeZeroString () 
3134                 {
3135                         Convert.ToByte ("-0");
3136                         Convert.ToByte ("-0", null);
3137                 }
3138
3139                 [Test]
3140                 [ExpectedException (typeof (OverflowException))]
3141                 public void ToUInt16_NegativeString () 
3142                 {
3143                         Convert.ToUInt16 ("-1");
3144                 }
3145
3146                 [Test]
3147                 [ExpectedException (typeof (ArgumentException))]
3148                 public void ToUInt16_NegativeStringNonBase10 () 
3149                 {
3150                         Convert.ToUInt16 ("-0", 16);
3151                 }
3152
3153                 [Test]
3154                 [ExpectedException (typeof (OverflowException))]
3155                 public void ToUInt16_NegativeString_Base10 ()
3156                 {
3157                         Convert.ToUInt16 ("-0", 10);
3158                 }
3159
3160                 [Test]
3161                 public void ToUInt16_NegativeZeroString () 
3162                 {
3163                         Convert.ToUInt16 ("-0");
3164                         Convert.ToUInt16 ("-0", null);
3165                 }
3166
3167                 [Test]
3168                 [ExpectedException (typeof (OverflowException))]
3169                 public void ToUInt32_NegativeString () 
3170                 {
3171                         Convert.ToUInt32 ("-1");
3172                 }
3173
3174                 [Test]
3175                 [ExpectedException (typeof (ArgumentException))]
3176                 public void ToUInt32_NegativeStringNonBase10 () 
3177                 {
3178                         Convert.ToUInt32 ("-0", 16);
3179                 }
3180
3181                 [Test]
3182                 [ExpectedException (typeof (OverflowException))]
3183                 public void ToUInt32_NegativeString_Base10 ()
3184                 {
3185                         Convert.ToUInt32 ("-0", 10);
3186                 }
3187
3188                 [Test]
3189                 public void ToUInt32_NegativeZeroString () 
3190                 {
3191                         Convert.ToUInt32 ("-0");
3192                         Convert.ToUInt32 ("-0", null);
3193                 }
3194
3195                 [Test]
3196                 [ExpectedException (typeof (OverflowException))]
3197                 public void ToUInt64_NegativeString () 
3198                 {
3199                         Convert.ToUInt64 ("-1");
3200                 }
3201
3202                 [Test]
3203                 [ExpectedException (typeof (ArgumentException))]
3204                 public void ToUInt64_NegativeStringNonBase10 () 
3205                 {
3206                         Convert.ToUInt64 ("-0", 16);
3207                 }
3208
3209                 [Test]
3210                 [ExpectedException (typeof (OverflowException))]
3211                 public void ToUInt64_NegativeString_Base10 ()
3212                 {
3213                         Convert.ToUInt64 ("-0", 10);
3214                 }
3215
3216                 [Test]
3217                 public void ToUInt64_NegativeZeroString () 
3218                 {
3219                         Convert.ToUInt64 ("-0");
3220                         Convert.ToUInt64 ("-0", null);
3221                 }
3222
3223                 // min/max unsigned
3224
3225                 [Test]
3226                 public void ToByte_MaxValue ()
3227                 {
3228                         Assert.AreEqual (Byte.MaxValue, Convert.ToByte ("ff", 16), "ff,16");
3229                         Assert.AreEqual (Byte.MaxValue, Convert.ToByte ("0XFF", 16), "0xFF,16");
3230                         Assert.AreEqual (Byte.MaxValue, Convert.ToByte ("255", 10), "255,10");
3231                         Assert.AreEqual (Byte.MaxValue, Convert.ToByte ("377", 8), "377,8");
3232                         Assert.AreEqual (Byte.MaxValue, Convert.ToByte ("11111111", 2), "11111111,2");
3233                 }
3234
3235                 [Test]
3236                 public void ToByte_MinValue ()
3237                 {
3238                         Assert.AreEqual (Byte.MinValue, Convert.ToByte ("0", 16), "0,16");
3239                         Assert.AreEqual (Byte.MinValue, Convert.ToByte ("0x0", 16), "0x0,16");
3240                         Assert.AreEqual (Byte.MinValue, Convert.ToByte ("0", 10), "0,10");
3241                         Assert.AreEqual (Byte.MinValue, Convert.ToByte ("0", 8), "0,8");
3242                         Assert.AreEqual (Byte.MinValue, Convert.ToByte ("0", 2), "0,2");
3243                 }
3244
3245                 [Test]
3246                 public void ToUInt16_MaxValue ()
3247                 {
3248                         Assert.AreEqual (UInt16.MaxValue, Convert.ToUInt16 ("ffff", 16), "ffff,16");
3249                         Assert.AreEqual (UInt16.MaxValue, Convert.ToUInt16 ("0XFFFF", 16), "0XFFFF,16");
3250                         Assert.AreEqual (UInt16.MaxValue, Convert.ToUInt16 ("65535", 10), "65535,10");
3251                         Assert.AreEqual (UInt16.MaxValue, Convert.ToUInt16 ("177777", 8), "177777,8");
3252                         Assert.AreEqual (UInt16.MaxValue, Convert.ToUInt16 ("1111111111111111", 2), "1111111111111111,2");
3253                 }
3254
3255                 [Test]
3256                 public void ToUInt16_MinValue ()
3257                 {
3258                         Assert.AreEqual (UInt16.MinValue, Convert.ToUInt16 ("0", 16), "0,16");
3259                         Assert.AreEqual (UInt16.MinValue, Convert.ToUInt16 ("0x0", 16), "0x0,16");
3260                         Assert.AreEqual (UInt16.MinValue, Convert.ToUInt16 ("0", 10), "0,10");
3261                         Assert.AreEqual (UInt16.MinValue, Convert.ToUInt16 ("0", 8), "0,8");
3262                         Assert.AreEqual (UInt16.MinValue, Convert.ToUInt16 ("0", 2), "0,2");
3263                 }
3264
3265                 [Test]
3266                 public void ToUInt32_MaxValue ()
3267                 {
3268                         Assert.AreEqual (UInt32.MaxValue, Convert.ToUInt32 ("ffffffff", 16), "ffffffff,16");
3269                         Assert.AreEqual (UInt32.MaxValue, Convert.ToUInt32 ("0XFFFFFFFF", 16), "0XFFFFFFFF,16");
3270                         Assert.AreEqual (UInt32.MaxValue, Convert.ToUInt32 ("4294967295", 10), "4294967295,10");
3271                         Assert.AreEqual (UInt32.MaxValue, Convert.ToUInt32 ("37777777777", 8), "37777777777,8");
3272                         Assert.AreEqual (UInt32.MaxValue, Convert.ToUInt32 ("11111111111111111111111111111111", 2), "11111111111111111111111111111111,2");
3273                 }
3274
3275                 [Test]
3276                 public void ToUInt32_MinValue ()
3277                 {
3278                         Assert.AreEqual (UInt32.MinValue, Convert.ToUInt32 ("0", 16), "0,16");
3279                         Assert.AreEqual (UInt32.MinValue, Convert.ToUInt32 ("0x0", 16), "0x0,16");
3280                         Assert.AreEqual (UInt32.MinValue, Convert.ToUInt32 ("0", 10), "0,10");
3281                         Assert.AreEqual (UInt32.MinValue, Convert.ToUInt32 ("0", 8), "0,8");
3282                         Assert.AreEqual (UInt32.MinValue, Convert.ToUInt32 ("0", 2), "0,2");
3283                 }
3284
3285                 [Test]
3286                 public void ToUInt64_MaxValue ()
3287                 {
3288                         Assert.AreEqual (UInt64.MaxValue, Convert.ToUInt64 ("ffffffffffffffff", 16), "ffffffffffffffff,16");
3289                         Assert.AreEqual (UInt64.MaxValue, Convert.ToUInt64 ("0XFFFFFFFFFFFFFFFF", 16), "0XFFFFFFFFFFFFFFFF,16");
3290                         Assert.AreEqual (UInt64.MaxValue, Convert.ToUInt64 ("18446744073709551615", 10), "18446744073709551615,10");
3291                         Assert.AreEqual (UInt64.MaxValue, Convert.ToUInt64 ("1777777777777777777777", 8), "1777777777777777777777,8");
3292                         Assert.AreEqual (UInt64.MaxValue, Convert.ToUInt64 ("1111111111111111111111111111111111111111111111111111111111111111", 2), "1111111111111111111111111111111111111111111111111111111111111111,2");
3293                 }
3294
3295                 [Test]
3296                 public void ToUInt64_MinValue ()
3297                 {
3298                         Assert.AreEqual (UInt64.MinValue, Convert.ToUInt64 ("0", 16), "0,16");
3299                         Assert.AreEqual (UInt64.MinValue, Convert.ToUInt64 ("0x0", 16), "0x0,16");
3300                         Assert.AreEqual (UInt64.MinValue, Convert.ToUInt64 ("0", 10), "0,10");
3301                         Assert.AreEqual (UInt64.MinValue, Convert.ToUInt64 ("0", 8), "0,8");
3302                         Assert.AreEqual (UInt64.MinValue, Convert.ToUInt64 ("0", 2), "0,2");
3303                 }
3304
3305                 // min/max signed
3306
3307                 [Test]
3308                 public void ToSByte_MaxValue ()
3309                 {
3310                         Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("7f", 16), "7F,16");
3311                         Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("0X7F", 16), "0X7F,16");
3312                         Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("127", 10), "127,10");
3313                         Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("177", 8), "177,8");
3314                         Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("1111111", 2), "1111111,2");
3315                 }
3316
3317                 [Test]
3318                 public void ToSByte_MinValue ()
3319                 {
3320                         Assert.AreEqual (SByte.MinValue, Convert.ToSByte ("80", 16), "80,16");
3321                         Assert.AreEqual (SByte.MinValue, Convert.ToSByte ("-128", 10), "-128,10");
3322                         Assert.AreEqual (SByte.MinValue, Convert.ToSByte ("200", 8), "200,8");
3323                         Assert.AreEqual (SByte.MinValue, Convert.ToSByte ("10000000", 2), "10000000,2");
3324                 }
3325
3326                 [Test]
3327                 public void ToInt16_MaxValue ()
3328                 {
3329                         Assert.AreEqual (Int16.MaxValue, Convert.ToInt16 ("7fff", 16), "7FFF,16");
3330                         Assert.AreEqual (Int16.MaxValue, Convert.ToInt16 ("0X7FFF", 16), "0X7FFF,16");
3331                         Assert.AreEqual (Int16.MaxValue, Convert.ToInt16 ("32767", 10), "32767,10");
3332                         Assert.AreEqual (Int16.MaxValue, Convert.ToInt16 ("77777", 8), "77777,8");
3333                         Assert.AreEqual (Int16.MaxValue, Convert.ToInt16 ("111111111111111", 2), "111111111111111,2");
3334                 }
3335
3336                 [Test]
3337                 public void ToInt16_MinValue ()
3338                 {
3339                         Assert.AreEqual (Int16.MinValue, Convert.ToInt16 ("8000", 16), "8000,16");
3340                         Assert.AreEqual (Int16.MinValue, Convert.ToInt16 ("-32768", 10), "-32768,10");
3341                         Assert.AreEqual (Int16.MinValue, Convert.ToInt16 ("100000", 8), "100000,8");
3342                         Assert.AreEqual (Int16.MinValue, Convert.ToInt16 ("1000000000000000", 2), "1000000000000000,2");
3343                 }
3344
3345                 [Test]
3346                 public void ToInt32_MaxValue ()
3347                 {
3348                         Assert.AreEqual (Int32.MaxValue, Convert.ToInt32 ("7fffffff", 16), "7fffffff,16");
3349                         Assert.AreEqual (Int32.MaxValue, Convert.ToInt32 ("0X7FFFFFFF", 16), "0X7FFFFFFF,16");
3350                         Assert.AreEqual (Int32.MaxValue, Convert.ToInt32 ("2147483647", 10), "2147483647,10");
3351                         Assert.AreEqual (Int32.MaxValue, Convert.ToInt32 ("17777777777", 8), "17777777777,8");
3352                         Assert.AreEqual (Int32.MaxValue, Convert.ToInt32 ("1111111111111111111111111111111", 2), "1111111111111111111111111111111,2");
3353                 }
3354
3355                 [Test]
3356                 public void ToInt32_MinValue ()
3357                 {
3358                         Assert.AreEqual (Int32.MinValue, Convert.ToInt32 ("80000000", 16), "80000000,16");
3359                         Assert.AreEqual (Int32.MinValue, Convert.ToInt32 ("-2147483648", 10), "-2147483648,10");
3360                         Assert.AreEqual (Int32.MinValue, Convert.ToInt32 ("20000000000", 8), "20000000000,8");
3361                         Assert.AreEqual (Int32.MinValue, Convert.ToInt32 ("10000000000000000000000000000000", 2), "10000000000000000000000000000000,2");
3362                 }
3363
3364                 [Test]
3365                 public void ToInt64_MaxValue ()
3366                 {
3367                         Assert.AreEqual (Int64.MaxValue, Convert.ToInt64 ("7fffffffffffffff", 16), "7fffffffffffffff,16");
3368                         Assert.AreEqual (Int64.MaxValue, Convert.ToInt64 ("0X7FFFFFFFFFFFFFFF", 16), "0X7FFFFFFFFFFFFFFF,16");
3369                         Assert.AreEqual (Int64.MaxValue, Convert.ToInt64 ("9223372036854775807", 10), "9223372036854775807,10");
3370                         Assert.AreEqual (Int64.MaxValue, Convert.ToInt64 ("777777777777777777777", 8), "777777777777777777777,8");
3371                         Assert.AreEqual (Int64.MaxValue, Convert.ToInt64 ("111111111111111111111111111111111111111111111111111111111111111", 2), "111111111111111111111111111111111111111111111111111111111111111,2");
3372                 }
3373
3374                 [Test]
3375                 public void ToInt64_MinValue ()
3376                 {
3377                         Assert.AreEqual (Int64.MinValue, Convert.ToInt64 ("8000000000000000", 16), "8000000000000000,16");
3378                         Assert.AreEqual (Int64.MinValue, Convert.ToInt64 ("0x8000000000000000", 16), "0x8000000000000000,16");
3379                         Assert.AreEqual (Int64.MinValue, Convert.ToInt64 ("-9223372036854775808", 10), "-9223372036854775808,10");
3380                         Assert.AreEqual (Int64.MinValue, Convert.ToInt64 ("1000000000000000000000", 8), "1000000000000000000000,8");
3381                         Assert.AreEqual (Int64.MinValue, Convert.ToInt64 ("1000000000000000000000000000000000000000000000000000000000000000", 2), "1000000000000000000000000000000000000000000000000000000000000000,2");
3382                 }
3383
3384                 // signed types
3385
3386                 [Test]
3387                 [ExpectedException (typeof (OverflowException))]
3388                 public void ToSByte_OverMaxValue ()
3389                 {
3390                         string max_plus1 = "128";
3391                         Convert.ToSByte (max_plus1);
3392                 }
3393
3394                 [Test]
3395                 [ExpectedException (typeof (OverflowException))]
3396                 public void ToSByte_OverMinValue ()
3397                 {
3398                         string min_minus1 = "-129";
3399                         Convert.ToSByte (min_minus1);
3400                 }
3401
3402                 [Test]
3403                 [ExpectedException (typeof (OverflowException))]
3404                 public void ToInt16_OverMaxValue ()
3405                 {
3406                         string max_plus1 = "32768";
3407                         Convert.ToInt16 (max_plus1);
3408                 }
3409
3410                 [Test]
3411                 [ExpectedException (typeof (OverflowException))]
3412                 public void ToInt16_OverMinValue ()
3413                 {
3414                         string min_minus1 = "-32769";
3415                         Convert.ToInt16 (min_minus1);
3416                 }
3417
3418                 [Test]
3419                 [ExpectedException (typeof (OverflowException))]
3420                 public void ToInt32_OverMaxValue ()
3421                 {
3422                         string max_plus1 = "2147483648";
3423                         Convert.ToInt32 (max_plus1);
3424                 }
3425
3426                 [Test]
3427                 [ExpectedException (typeof (OverflowException))]
3428                 public void ToInt32_OverMinValue ()
3429                 {
3430                         string min_minus1 = "-2147483649";
3431                         Convert.ToInt32 (min_minus1);
3432                 }
3433
3434                 [Test]
3435                 [ExpectedException (typeof (OverflowException))]
3436                 public void ToInt64_OverMaxValue ()
3437                 {
3438                         string max_plus1 = "9223372036854775808";
3439                         Convert.ToInt64 (max_plus1);
3440                 }
3441
3442                 [Test]
3443                 [ExpectedException (typeof (OverflowException))]
3444                 public void ToInt64_OverMinValue ()
3445                 {
3446                         string min_minus1 = "-9223372036854775809";
3447                         Convert.ToInt64 (min_minus1);
3448                 }
3449
3450                 // unsigned types
3451
3452                 [Test]
3453                 [ExpectedException (typeof (OverflowException))]
3454                 public void ToByte_OverMaxValue ()
3455                 {
3456                         string max_plus1 = "257";
3457                         Convert.ToByte (max_plus1);
3458                 }
3459
3460                 [Test]
3461                 [ExpectedException (typeof (OverflowException))]
3462                 public void ToByte_OverMinValue ()
3463                 {
3464                         string min_minus1 = "-1";
3465                         Convert.ToByte (min_minus1);
3466                 }
3467
3468                 [Test]
3469                 [ExpectedException (typeof (OverflowException))]
3470                 public void ToUInt16_OverMaxValue ()
3471                 {
3472                         string max_plus1 = "65536";
3473                         Convert.ToUInt16 (max_plus1);
3474                 }
3475
3476                 [Test]
3477                 [ExpectedException (typeof (OverflowException))]
3478                 public void ToUInt16_OverMinValue ()
3479                 {
3480                         string min_minus1 = "-1";
3481                         Convert.ToUInt16 (min_minus1);
3482                 }
3483
3484                 [Test]
3485                 [ExpectedException (typeof (OverflowException))]
3486                 public void ToUInt32_OverMaxValue ()
3487                 {
3488                         string max_plus1 = "4294967296";
3489                         Convert.ToUInt32 (max_plus1);
3490                 }
3491
3492                 [Test]
3493                 [ExpectedException (typeof (OverflowException))]
3494                 public void ToUInt32_OverMinValue ()
3495                 {
3496                         string min_minus1 = "-1";
3497                         Convert.ToUInt32 (min_minus1);
3498                 }
3499
3500                 [Test]
3501                 [ExpectedException (typeof (OverflowException))]
3502                 public void ToUInt64_OverMaxValue ()
3503                 {
3504                         string max_plus1 = "18446744073709551616";
3505                         Convert.ToUInt64 (max_plus1);
3506                 }
3507
3508                 [Test]
3509                 [ExpectedException (typeof (OverflowException))]
3510                 public void ToUInt64_OverMinValue ()
3511                 {
3512                         string min_minus1 = "-1";
3513                         Convert.ToUInt64 (min_minus1);
3514                 }
3515
3516                 [Test]
3517                 public void To_NullString () 
3518                 {
3519                         string s = null;
3520                         // signed
3521                         Assert.AreEqual (0, Convert.ToSByte (s), "ToSByte");
3522                         Assert.AreEqual (0, Convert.ToSByte (s, 10), "ToSByte+base");
3523                         Assert.AreEqual (0, Convert.ToInt16 (s), "ToInt16");
3524                         Assert.AreEqual (0, Convert.ToInt16 (s, 10), "ToInt16+base");
3525                         Assert.AreEqual (0, Convert.ToInt32 (s), "ToInt32");
3526                         Assert.AreEqual (0, Convert.ToInt32 (s, 10), "ToInt32+base");
3527                         Assert.AreEqual (0, Convert.ToInt64 (s), "ToInt64");
3528                         Assert.AreEqual (0, Convert.ToInt64 (s, 10), "ToInt64+base");
3529                         // unsigned
3530                         Assert.AreEqual (0, Convert.ToByte (s), "ToByte");
3531                         Assert.AreEqual (0, Convert.ToByte (s, 10), "ToByte+base");
3532                         Assert.AreEqual (0, Convert.ToUInt16 (s), "ToUInt16");
3533                         Assert.AreEqual (0, Convert.ToUInt16 (s, 10), "ToUInt16+base");
3534                         Assert.AreEqual (0, Convert.ToUInt32 (s), "ToUInt32");
3535                         Assert.AreEqual (0, Convert.ToUInt32 (s, 10), "ToUInt32+base");
3536                         Assert.AreEqual (0, Convert.ToUInt64 (s), "ToUInt64");
3537                         Assert.AreEqual (0, Convert.ToUInt64 (s, 10), "ToUInt64+base");
3538                 }
3539
3540                 [Test]
3541                 public void To_NullObject () 
3542                 {
3543                         object o = null;
3544                         // signed
3545                         Assert.AreEqual (0, Convert.ToSByte (o), "ToSByte");
3546                         Assert.AreEqual (0, Convert.ToInt16 (o), "ToInt16");
3547                         Assert.AreEqual (0, Convert.ToInt32 (o), "ToInt32");
3548                         Assert.AreEqual (0, Convert.ToInt64 (o), "ToInt64");
3549                         // unsigned
3550                         Assert.AreEqual (0, Convert.ToByte (o), "ToByte");
3551                         Assert.AreEqual (0, Convert.ToUInt16 (o), "ToUInt16");
3552                         Assert.AreEqual (0, Convert.ToUInt32 (o), "ToUInt32");
3553                         Assert.AreEqual (0, Convert.ToUInt64 (o), "ToUInt64");
3554                 }
3555
3556                 [Test]
3557                 public void To_NullObjectFormatProvider () 
3558                 {
3559                         object o = null;
3560                         IFormatProvider fp = (IFormatProvider) new NumberFormatInfo ();
3561                         // signed
3562                         Assert.AreEqual (0, Convert.ToSByte (o, fp), "ToSByte");
3563                         Assert.AreEqual (0, Convert.ToInt16 (o, fp), "ToInt16");
3564                         Assert.AreEqual (0, Convert.ToInt32 (o, fp), "ToInt32");
3565                         Assert.AreEqual (0, Convert.ToInt64 (o, fp), "ToInt64");
3566                         // unsigned
3567                         Assert.AreEqual (0, Convert.ToByte (o, fp), "ToByte");
3568                         Assert.AreEqual (0, Convert.ToUInt16 (o, fp), "ToUInt16");
3569                         Assert.AreEqual (0, Convert.ToUInt32 (o, fp), "ToUInt32");
3570                         Assert.AreEqual (0, Convert.ToUInt64 (o, fp), "ToUInt64");
3571                 }
3572
3573                 [Test]
3574                 [ExpectedException (typeof (ArgumentNullException))]
3575                 public void ToSByte_NullStringFormatProvider () 
3576                 {
3577                         string s = null;
3578                         // SByte is a "special" case ???
3579                         Convert.ToSByte (s, new NumberFormatInfo ());
3580                 }
3581
3582                 [Test]
3583                 public void To_NullStringFormatProvider () 
3584                 {
3585                         string s = null;
3586                         IFormatProvider fp = (IFormatProvider) new NumberFormatInfo ();
3587                         // signed
3588                         // No SByte here
3589                         Assert.AreEqual (0, Convert.ToInt16 (s, fp), "ToInt16");
3590                         Assert.AreEqual (0, Convert.ToInt32 (s, fp), "ToInt32");
3591                         Assert.AreEqual (0, Convert.ToInt64 (s, fp), "ToInt64");
3592                         // unsigned
3593                         Assert.AreEqual (0, Convert.ToByte (s, fp), "ToByte");
3594                         Assert.AreEqual (0, Convert.ToUInt16 (s, fp), "ToUInt16");
3595                         Assert.AreEqual (0, Convert.ToUInt32 (s, fp), "ToUInt32");
3596                         Assert.AreEqual (0, Convert.ToUInt64 (s, fp), "ToUInt64");
3597                 }
3598
3599                 [Test]
3600                 [ExpectedException (typeof (InvalidCastException))]
3601                 public void ChangeTypeToTypeCodeEmpty ()
3602                 {
3603                         Convert.ChangeType (true, TypeCode.Empty);
3604                 }
3605
3606                 [Test]
3607                 // 2005/01/10: The docs say this should throw an InvalidCastException,
3608                 // however, MS.NET 1.1 throws a NullReferenceException. Assuming docs
3609                 // are wrong.
3610 #if NET_2_0
3611                 [ExpectedException (typeof (InvalidCastException))]
3612 #else
3613                 [ExpectedException (typeof (NullReferenceException))]
3614 #endif
3615                 public void ChangeTypeNullToValuetype ()
3616                 {
3617                         Convert.ChangeType (null, typeof (int));
3618                 }
3619
3620                 [Test]
3621                 public void ToString_MinMax_WithBase () 
3622                 {
3623                         Assert.AreEqual ("0", Convert.ToString (Byte.MinValue, 2), "Byte.MinValue base 2");
3624                         Assert.AreEqual ("0", Convert.ToString (Byte.MinValue, 8), "Byte.MinValue base 8");
3625                         Assert.AreEqual ("0", Convert.ToString (Byte.MinValue, 10), "Byte.MinValue base 10");
3626                         Assert.AreEqual ("0", Convert.ToString (Byte.MinValue, 16), "Byte.MinValue base 16");
3627
3628                         Assert.AreEqual ("11111111", Convert.ToString (Byte.MaxValue, 2), "Byte.MaxValue base 2");
3629                         Assert.AreEqual ("377", Convert.ToString (Byte.MaxValue, 8), "Byte.MaxValue base 8");
3630                         Assert.AreEqual ("255", Convert.ToString (Byte.MaxValue, 10), "Byte.MaxValue base 10");
3631                         Assert.AreEqual ("ff", Convert.ToString (Byte.MaxValue, 16), "Byte.MaxValue base 16");
3632
3633                         Assert.AreEqual ("1000000000000000", Convert.ToString (Int16.MinValue, 2), "Int16.MinValue base 2");
3634                         Assert.AreEqual ("100000", Convert.ToString (Int16.MinValue, 8), "Int16.MinValue base 8");
3635                         Assert.AreEqual ("-32768", Convert.ToString (Int16.MinValue, 10), "Int16.MinValue base 10");
3636                         Assert.AreEqual ("8000", Convert.ToString (Int16.MinValue, 16), "Int16.MinValue base 16");
3637
3638                         Assert.AreEqual ("111111111111111", Convert.ToString (Int16.MaxValue, 2), "Int16.MaxValue base 2");
3639                         Assert.AreEqual ("77777", Convert.ToString (Int16.MaxValue, 8), "Int16.MaxValue base 8");
3640                         Assert.AreEqual ("32767", Convert.ToString (Int16.MaxValue, 10), "Int16.MaxValue base 10");
3641                         Assert.AreEqual ("7fff", Convert.ToString (Int16.MaxValue, 16), "Int16.MaxValue base 16");
3642
3643                         Assert.AreEqual ("10000000000000000000000000000000", Convert.ToString (Int32.MinValue, 2), "Int32.MinValue base 2");
3644                         Assert.AreEqual ("20000000000", Convert.ToString (Int32.MinValue, 8), "Int32.MinValue base 8");
3645                         Assert.AreEqual ("-2147483648", Convert.ToString (Int32.MinValue, 10), "Int32.MinValue base 10");
3646                         Assert.AreEqual ("80000000", Convert.ToString (Int32.MinValue, 16), "Int32.MinValue base 16");
3647
3648                         Assert.AreEqual ("1111111111111111111111111111111", Convert.ToString (Int32.MaxValue, 2), "Int32.MaxValue base 2");
3649                         Assert.AreEqual ("17777777777", Convert.ToString (Int32.MaxValue, 8), "Int32.MaxValue base 8");
3650                         Assert.AreEqual ("2147483647", Convert.ToString (Int32.MaxValue, 10), "Int32.MaxValue base 10");
3651                         Assert.AreEqual ("7fffffff", Convert.ToString (Int32.MaxValue, 16), "Int32.MaxValue base 16");
3652
3653                         Assert.AreEqual ("1000000000000000000000000000000000000000000000000000000000000000", Convert.ToString (Int64.MinValue, 2), "Int64.MinValue base 2");
3654                         Assert.AreEqual ("1000000000000000000000", Convert.ToString (Int64.MinValue, 8), "Int64.MinValue base 8");
3655                         Assert.AreEqual ("-9223372036854775808", Convert.ToString (Int64.MinValue, 10), "Int64.MinValue base 10");
3656                         Assert.AreEqual ("8000000000000000", Convert.ToString (Int64.MinValue, 16), "Int64.MinValue base 16");
3657
3658                         Assert.AreEqual ("111111111111111111111111111111111111111111111111111111111111111", Convert.ToString (Int64.MaxValue, 2), "Int64.MaxValue base 2");
3659                         Assert.AreEqual ("777777777777777777777", Convert.ToString (Int64.MaxValue, 8), "Int64.MaxValue base 8");
3660                         Assert.AreEqual ("9223372036854775807", Convert.ToString (Int64.MaxValue, 10), "Int64.MaxValue base 10");
3661                         Assert.AreEqual ("7fffffffffffffff", Convert.ToString (Int64.MaxValue, 16), "Int64.MaxValue base 16");
3662                 }
3663
3664                 [Test]
3665                 [ExpectedException (typeof (FormatException))]
3666                 public void ToByte_BadHexPrefix1 ()
3667                 {
3668                         Convert.ToByte ("#10", 16);
3669                 }
3670
3671                 [Test]
3672                 [ExpectedException (typeof (FormatException))]
3673                 public void ToByte_BadHexPrefix2 ()
3674                 {
3675                         Convert.ToByte ("&H10", 16);
3676                 }
3677
3678                 [Test]
3679                 [ExpectedException (typeof (FormatException))]
3680                 public void ToByte_BadHexPrefix3 ()
3681                 {
3682                         Convert.ToByte ("&h10", 16);
3683                 }
3684
3685                 [Test]
3686                 [ExpectedException (typeof (FormatException))]
3687                 public void ToInt16_BadHexPrefix1 ()
3688                 {
3689                         Convert.ToInt16 ("#10", 16);
3690                 }
3691
3692                 [Test]
3693                 [ExpectedException (typeof (FormatException))]
3694                 public void ToInt16_BadHexPrefix2 ()
3695                 {
3696                         Convert.ToInt16 ("&H10", 16);
3697                 }
3698
3699                 [Test]
3700                 [ExpectedException (typeof (FormatException))]
3701                 public void ToInt16_BadHexPrefix3 ()
3702                 {
3703                         Convert.ToInt16 ("&h10", 16);
3704                 }
3705
3706                 [Test]
3707                 [ExpectedException (typeof (FormatException))]
3708                 public void ToInt32_BadHexPrefix1 ()
3709                 {
3710                         Convert.ToInt32 ("#10", 16);
3711                 }
3712
3713                 [Test]
3714                 [ExpectedException (typeof (FormatException))]
3715                 public void ToInt32_BadHexPrefix2 ()
3716                 {
3717                         Convert.ToInt32 ("&H10", 16);
3718                 }
3719
3720                 [Test]
3721                 [ExpectedException (typeof (FormatException))]
3722                 public void ToInt32_BadHexPrefix3 ()
3723                 {
3724                         Convert.ToInt32 ("&h10", 16);
3725                 }
3726
3727                 [Test]
3728                 [ExpectedException (typeof (FormatException))]
3729                 public void ToInt64_BadHexPrefix1 ()
3730                 {
3731                         Convert.ToInt64 ("#10", 16);
3732                 }
3733
3734                 [Test]
3735                 [ExpectedException (typeof (FormatException))]
3736                 public void ToInt64_BadHexPrefix2 ()
3737                 {
3738                         Convert.ToInt64 ("&H10", 16);
3739                 }
3740
3741                 [Test]
3742                 [ExpectedException (typeof (FormatException))]
3743                 public void ToInt64_BadHexPrefix3 ()
3744                 {
3745                         Convert.ToInt64 ("&h10", 16);
3746                 }
3747
3748                 [Test]
3749                 [ExpectedException (typeof (FormatException))]
3750                 public void ToSByte_BadHexPrefix1 ()
3751                 {
3752                         Convert.ToSByte ("#10", 16);
3753                 }
3754
3755                 [Test]
3756                 [ExpectedException (typeof (FormatException))]
3757                 public void ToSByte_BadHexPrefix2 ()
3758                 {
3759                         Convert.ToSByte ("&H10", 16);
3760                 }
3761
3762                 [Test]
3763                 [ExpectedException (typeof (FormatException))]
3764                 public void ToSByte_BadHexPrefix3 ()
3765                 {
3766                         Convert.ToSByte ("&h10", 16);
3767                 }
3768
3769                 [Test]
3770                 [ExpectedException (typeof (FormatException))]
3771                 public void ToUInt16_BadHexPrefix1 ()
3772                 {
3773                         Convert.ToUInt16 ("#10", 16);
3774                 }
3775
3776                 [Test]
3777                 [ExpectedException (typeof (FormatException))]
3778                 public void ToUInt16_BadHexPrefix2 ()
3779                 {
3780                         Convert.ToUInt16 ("&H10", 16);
3781                 }
3782
3783                 [Test]
3784                 [ExpectedException (typeof (FormatException))]
3785                 public void ToUInt16_BadHexPrefix3 ()
3786                 {
3787                         Convert.ToUInt16 ("&h10", 16);
3788                 }
3789
3790                 [Test]
3791                 [ExpectedException (typeof (FormatException))]
3792                 public void ToUInt32_BadHexPrefix1 ()
3793                 {
3794                         Convert.ToUInt32 ("#10", 16);
3795                 }
3796
3797                 [Test]
3798                 [ExpectedException (typeof (FormatException))]
3799                 public void ToUInt32_BadHexPrefix2 ()
3800                 {
3801                         Convert.ToUInt32 ("&H10", 16);
3802                 }
3803
3804                 [Test]
3805                 [ExpectedException (typeof (FormatException))]
3806                 public void ToUInt32_BadHexPrefix3 ()
3807                 {
3808                         Convert.ToUInt32 ("&h10", 16);
3809                 }
3810
3811                 [Test]
3812                 [ExpectedException (typeof (FormatException))]
3813                 public void ToUInt64_BadHexPrefix1 ()
3814                 {
3815                         Convert.ToUInt64 ("#10", 16);
3816                 }
3817
3818                 [Test]
3819                 [ExpectedException (typeof (FormatException))]
3820                 public void ToUInt64_BadHexPrefix2 ()
3821                 {
3822                         Convert.ToUInt64 ("&H10", 16);
3823                 }
3824
3825                 [Test]
3826                 [ExpectedException (typeof (FormatException))]
3827                 public void ToUInt64_BadHexPrefix3 ()
3828                 {
3829                         Convert.ToUInt64 ("&h10", 16);
3830                 }
3831
3832                 [Test]
3833                 public void ToSByte_Base16_MinMax ()
3834                 {
3835                         Assert.AreEqual (SByte.MinValue, Convert.ToSByte ("80", 16), "80,16");
3836                         Assert.AreEqual (SByte.MinValue, Convert.ToSByte ("0x80", 16), "0x80,16");
3837                         Assert.AreEqual (SByte.MinValue, Convert.ToSByte ("0X80", 16), "0X80,16");
3838
3839                         Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("7f", 16), "7f,16");
3840                         Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("7F", 16), "7F,16");
3841                         Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("0x7f", 16), "0x7f,16");
3842                         Assert.AreEqual (SByte.MaxValue, Convert.ToSByte ("0X7F", 16), "0X7F,16");
3843                 }
3844
3845                 [Test]
3846                 public void ToInt16_Base16_MinMax ()
3847                 {
3848                         Assert.AreEqual (short.MinValue, Convert.ToInt16 ("8000", 16), "8000,16");
3849                         Assert.AreEqual (short.MinValue, Convert.ToInt16 ("0x8000", 16), "0x8000,16");
3850                         Assert.AreEqual (short.MinValue, Convert.ToInt16 ("0X8000", 16), "0X8000,16");
3851
3852                         Assert.AreEqual (short.MaxValue, Convert.ToInt16 ("7fff", 16), "7fff,16");
3853                         Assert.AreEqual (short.MaxValue, Convert.ToInt16 ("7FFF", 16), "7FFF,16");
3854                         Assert.AreEqual (short.MaxValue, Convert.ToInt16 ("0x7fff", 16), "0x7fff,16");
3855                         Assert.AreEqual (short.MaxValue, Convert.ToInt16 ("0X7FFF", 16), "0X7FFF,16");
3856                 }
3857
3858                 [Test]
3859                 public void ToInt32_Base16_MinMax ()
3860                 {
3861                         Assert.AreEqual (int.MinValue, Convert.ToInt32 ("80000000", 16), "80000000,16");
3862                         Assert.AreEqual (int.MinValue, Convert.ToInt32 ("0x80000000", 16), "0x80000000,16");
3863                         Assert.AreEqual (int.MinValue, Convert.ToInt32 ("0X80000000", 16), "0X80000000,16");
3864
3865                         Assert.AreEqual (int.MaxValue, Convert.ToInt32 ("7fffffff", 16), "7fffffff,16");
3866                         Assert.AreEqual (int.MaxValue, Convert.ToInt32 ("7FFFFFFF", 16), "7FFFFFFF,16");
3867                         Assert.AreEqual (int.MaxValue, Convert.ToInt32 ("0x7fffffff", 16), "0x7fffffff,16");
3868                         Assert.AreEqual (int.MaxValue, Convert.ToInt32 ("0X7FFFFFFF", 16), "0X7FFFFFFF,16");
3869                 }
3870
3871                 [Test]
3872                 [ExpectedException (typeof (FormatException))]
3873                 public void ToByte_Base10_InvalidChars1 ()
3874                 {
3875                         Convert.ToByte ("0-1", 10);
3876                 }
3877
3878                 [Test]
3879                 [ExpectedException (typeof (FormatException))]
3880                 public void ToByte_Base10_InvalidChars2 ()
3881                 {
3882                         Convert.ToByte ("FF", 10);
3883                 }
3884
3885                 [Test]
3886                 [ExpectedException (typeof (FormatException))]
3887                 public void ToInt16_Base10_InvalidChars1 ()
3888                 {
3889                         Convert.ToInt16 ("0-1", 10);
3890                 }
3891
3892                 [Test]
3893                 [ExpectedException (typeof (FormatException))]
3894                 public void ToInt16_Base10_InvalidChars2 ()
3895                 {
3896                         Convert.ToInt16 ("FF", 10);
3897                 }
3898
3899                 [Test]
3900                 [ExpectedException (typeof (FormatException))]
3901                 public void ToInt32_Base10_InvalidChars1 ()
3902                 {
3903                         Convert.ToInt32 ("0-1", 10);
3904                 }
3905
3906                 [Test]
3907                 [ExpectedException (typeof (FormatException))]
3908                 public void ToInt32_Base10_InvalidChars2 ()
3909                 {
3910                         Convert.ToInt32 ("FF", 10);
3911                 }
3912
3913                 [Test]
3914                 [ExpectedException (typeof (FormatException))]
3915                 public void ToInt64_Base10_InvalidChars1 ()
3916                 {
3917                         Convert.ToInt64 ("0-1", 10);
3918                 }
3919
3920                 [Test]
3921                 [ExpectedException (typeof (FormatException))]
3922                 public void ToInt64_Base10_InvalidChars2 ()
3923                 {
3924                         Convert.ToInt64 ("FF", 10);
3925                 }
3926
3927                 [Test]
3928                 [ExpectedException (typeof (FormatException))]
3929                 public void ToSByte_Base10_InvalidChars1 ()
3930                 {
3931                         Convert.ToSByte ("0-1", 10);
3932                 }
3933
3934                 [Test]
3935                 [ExpectedException (typeof (FormatException))]
3936                 public void ToSByte_Base10_InvalidChars2 ()
3937                 {
3938                         Convert.ToSByte ("FF", 10);
3939                 }
3940
3941                 [Test]
3942                 [ExpectedException (typeof (FormatException))]
3943                 public void ToUInt16_Base10_InvalidChars1 ()
3944                 {
3945                         Convert.ToUInt16 ("0-1", 10);
3946                 }
3947
3948                 [Test]
3949                 [ExpectedException (typeof (FormatException))]
3950                 public void ToUInt16_Base10_InvalidChars2 ()
3951                 {
3952                         Convert.ToUInt16 ("FF", 10);
3953                 }
3954
3955                 [Test]
3956                 [ExpectedException (typeof (FormatException))]
3957                 public void ToUInt32_Base10_InvalidChars1 ()
3958                 {
3959                         Convert.ToUInt32 ("0-1", 10);
3960                 }
3961
3962                 [Test]
3963                 [ExpectedException (typeof (FormatException))]
3964                 public void ToUInt32_Base10_InvalidChars2 ()
3965                 {
3966                         Convert.ToUInt32 ("FF", 10);
3967                 }
3968
3969                 [Test]
3970                 [ExpectedException (typeof (FormatException))]
3971                 public void ToUInt64_Base10_InvalidChars1 ()
3972                 {
3973                         Convert.ToUInt64 ("0-1", 10);
3974                 }
3975
3976                 [Test]
3977                 [ExpectedException (typeof (FormatException))]
3978                 public void ToUInt64_Base10_InvalidChars2 ()
3979                 {
3980                         Convert.ToUInt64 ("FF", 10);
3981                 }
3982
3983                 [Test]
3984                 [ExpectedException (typeof (FormatException))]
3985                 public void ToByte_Base16_InvalidChars1 ()
3986                 {
3987                         Convert.ToByte ("0-1", 16);
3988                 }
3989
3990                 [Test]
3991                 [ExpectedException (typeof (FormatException))]
3992                 public void ToByte_Base16_InvalidChars2 ()
3993                 {
3994                         Convert.ToByte ("GG", 16);
3995                 }
3996
3997                 [Test]
3998                 [ExpectedException (typeof (FormatException))]
3999                 public void ToInt16_Base16_InvalidChars1 ()
4000                 {
4001                         Convert.ToInt16 ("0-1", 16);
4002                 }
4003
4004                 [Test]
4005                 [ExpectedException (typeof (FormatException))]
4006                 public void ToInt16_Base16_InvalidChars2 ()
4007                 {
4008                         Convert.ToInt16 ("GG", 16);
4009                 }
4010
4011                 [Test]
4012                 [ExpectedException (typeof (FormatException))]
4013                 public void ToInt32_Base16_InvalidChars1 ()
4014                 {
4015                         Convert.ToInt32 ("0-1", 16);
4016                 }
4017
4018                 [Test]
4019                 [ExpectedException (typeof (FormatException))]
4020                 public void ToInt32_Base16_InvalidChars2 ()
4021                 {
4022                         Convert.ToInt32 ("GG", 16);
4023                 }
4024
4025                 [Test]
4026                 [ExpectedException (typeof (FormatException))]
4027                 public void ToInt64_Base16_InvalidChars1 ()
4028                 {
4029                         Convert.ToInt64 ("0-1", 16);
4030                 }
4031
4032                 [Test]
4033                 [ExpectedException (typeof (FormatException))]
4034                 public void ToInt64_Base16_InvalidChars2 ()
4035                 {
4036                         Convert.ToInt64 ("GG", 16);
4037                 }
4038
4039                 [Test]
4040                 [ExpectedException (typeof (FormatException))]
4041                 public void ToSByte_Base16_InvalidChars1 ()
4042                 {
4043                         Convert.ToSByte ("0-1", 16);
4044                 }
4045
4046                 [Test]
4047                 [ExpectedException (typeof (FormatException))]
4048                 public void ToSByte_Base16_InvalidChars2 ()
4049                 {
4050                         Convert.ToSByte ("GG", 16);
4051                 }
4052
4053                 [Test]
4054                 [ExpectedException (typeof (FormatException))]
4055                 public void ToUInt16_Base16_InvalidChars1 ()
4056                 {
4057                         Convert.ToUInt16 ("0-1", 16);
4058                 }
4059
4060                 [Test]
4061                 [ExpectedException (typeof (FormatException))]
4062                 public void ToUInt16_Base16_InvalidChars2 ()
4063                 {
4064                         Convert.ToUInt16 ("GG", 16);
4065                 }
4066
4067                 [Test]
4068                 [ExpectedException (typeof (FormatException))]
4069                 public void ToUInt32_Base16_InvalidChars1 ()
4070                 {
4071                         Convert.ToUInt32 ("0-1", 16);
4072                 }
4073
4074                 [Test]
4075                 [ExpectedException (typeof (FormatException))]
4076                 public void ToUInt32_Base16_InvalidChars2 ()
4077                 {
4078                         Convert.ToUInt32 ("GG", 16);
4079                 }
4080
4081                 [Test]
4082                 [ExpectedException (typeof (FormatException))]
4083                 public void ToUInt64_Base16_InvalidChars1 ()
4084                 {
4085                         Convert.ToUInt64 ("0-1", 16);
4086                 }
4087
4088                 [Test]
4089                 [ExpectedException (typeof (FormatException))]
4090                 public void ToUInt64_Base16_InvalidChars2 ()
4091                 {
4092                         Convert.ToUInt64 ("GG", 16);
4093                 }
4094
4095                 [Test]
4096                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4097                 public void ToByte_Base2_Empty ()
4098                 {
4099                         Convert.ToByte ("", 2);
4100                 }
4101
4102                 [Test]
4103                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4104                 public void ToByte_Base8_Empty ()
4105                 {
4106                         Convert.ToByte ("", 8);
4107                 }
4108
4109                 [Test]
4110                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4111                 public void ToByte_Base10_Empty ()
4112                 {
4113                         Convert.ToByte ("", 10);
4114                 }
4115
4116                 [Test]
4117                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4118                 public void ToByte_Base16_Empty ()
4119                 {
4120                         Convert.ToByte ("", 16);
4121                 }
4122
4123                 [Test]
4124                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4125                 public void ToInt16_Base2_Empty ()
4126                 {
4127                         Convert.ToInt16 ("", 2);
4128                 }
4129
4130                 [Test]
4131                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4132                 public void ToInt16_Base8_Empty ()
4133                 {
4134                         Convert.ToInt16 ("", 8);
4135                 }
4136
4137                 [Test]
4138                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4139                 public void ToInt16_Base10_Empty ()
4140                 {
4141                         Convert.ToInt16 ("", 10);
4142                 }
4143
4144                 [Test]
4145                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4146                 public void ToInt16_Base16_Empty ()
4147                 {
4148                         Convert.ToInt16 ("", 16);
4149                 }
4150
4151                 [Test]
4152                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4153                 public void ToInt32_Base2_Empty ()
4154                 {
4155                         Convert.ToInt32 ("", 2);
4156                 }
4157
4158                 [Test]
4159                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4160                 public void ToInt32_Base8_Empty ()
4161                 {
4162                         Convert.ToInt32 ("", 8);
4163                 }
4164
4165                 [Test]
4166                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4167                 public void ToInt32_Base10_Empty ()
4168                 {
4169                         Convert.ToInt32 ("", 10);
4170                 }
4171
4172                 [Test]
4173                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4174                 public void ToInt32_Base16_Empty ()
4175                 {
4176                         Convert.ToInt32 ("", 16);
4177                 }
4178
4179                 [Test]
4180                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4181                 public void ToInt64_Base2_Empty ()
4182                 {
4183                         Convert.ToInt64 ("", 2);
4184                 }
4185
4186                 [Test]
4187                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4188                 public void ToInt64_Base8_Empty ()
4189                 {
4190                         Convert.ToInt64 ("", 8);
4191                 }
4192
4193                 [Test]
4194                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4195                 public void ToInt64_Base10_Empty ()
4196                 {
4197                         Convert.ToInt64 ("", 10);
4198                 }
4199
4200                 [Test]
4201                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4202                 public void ToInt64_Base16_Empty ()
4203                 {
4204                         Convert.ToInt64 ("", 16);
4205                 }
4206
4207                 [Test]
4208                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4209                 public void ToSByte_Base2_Empty ()
4210                 {
4211                         Convert.ToSByte ("", 2);
4212                 }
4213
4214                 [Test]
4215                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4216                 public void ToSByte_Base8_Empty ()
4217                 {
4218                         Convert.ToSByte ("", 8);
4219                 }
4220
4221                 [Test]
4222                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4223                 public void ToSByte_Base10_Empty ()
4224                 {
4225                         Convert.ToSByte ("", 10);
4226                 }
4227
4228                 [Test]
4229                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4230                 public void ToSByte_Base16_Empty ()
4231                 {
4232                         Convert.ToSByte ("", 16);
4233                 }
4234
4235                 [Test]
4236                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4237                 public void ToUInt16_Base2_Empty ()
4238                 {
4239                         Convert.ToUInt16 ("", 2);
4240                 }
4241
4242                 [Test]
4243                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4244                 public void ToUInt16_Base8_Empty ()
4245                 {
4246                         Convert.ToUInt16 ("", 8);
4247                 }
4248
4249                 [Test]
4250                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4251                 public void ToUInt16_Base10_Empty ()
4252                 {
4253                         Convert.ToUInt16 ("", 10);
4254                 }
4255
4256                 [Test]
4257                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4258                 public void ToUInt16_Base16_Empty ()
4259                 {
4260                         Convert.ToUInt16 ("", 16);
4261                 }
4262
4263                 [Test]
4264                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4265                 public void ToUInt32_Base2_Empty ()
4266                 {
4267                         Convert.ToUInt32 ("", 2);
4268                 }
4269
4270                 [Test]
4271                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4272                 public void ToUInt32_Base8_Empty ()
4273                 {
4274                         Convert.ToUInt32 ("", 8);
4275                 }
4276
4277                 [Test]
4278                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4279                 public void ToUInt32_Base10_Empty ()
4280                 {
4281                         Convert.ToUInt32 ("", 10);
4282                 }
4283
4284                 [Test]
4285                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4286                 public void ToUInt32_Base16_Empty ()
4287                 {
4288                         Convert.ToUInt32 ("", 16);
4289                 }
4290
4291                 [Test]
4292                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4293                 public void ToUInt64_Base2_Empty ()
4294                 {
4295                         Convert.ToUInt64 ("", 2);
4296                 }
4297
4298                 [Test]
4299                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4300                 public void ToUInt64_Base8_Empty ()
4301                 {
4302                         Convert.ToUInt64 ("", 8);
4303                 }
4304
4305                 [Test]
4306                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4307                 public void ToUInt64_Base10_Empty ()
4308                 {
4309                         Convert.ToUInt64 ("", 10);
4310                 }
4311
4312                 [Test]
4313                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4314                 public void ToUInt64_Base16_Empty ()
4315                 {
4316                         Convert.ToUInt64 ("", 16);
4317                 }
4318
4319                 [Test]
4320                 [ExpectedException (typeof (FormatException))]
4321                 public void ToByte_HexPrefixOnly ()
4322                 {
4323                         Convert.ToByte ("0x", 16);
4324                 }
4325
4326                 [Test]
4327                 [ExpectedException (typeof (FormatException))]
4328                 public void ToInt16_HexPrefixOnly ()
4329                 {
4330                         Convert.ToInt16 ("0x", 16);
4331                 }
4332
4333                 [Test]
4334                 [ExpectedException (typeof (FormatException))]
4335                 public void ToInt32_HexPrefixOnly ()
4336                 {
4337                         Convert.ToInt32 ("0x", 16);
4338                 }
4339
4340                 [Test]
4341                 [ExpectedException (typeof (FormatException))]
4342                 public void ToInt64_HexPrefixOnly ()
4343                 {
4344                         Convert.ToInt64 ("0x", 16);
4345                 }
4346
4347                 [Test]
4348                 [ExpectedException (typeof (FormatException))]
4349                 public void ToSByte_HexPrefixOnly ()
4350                 {
4351                         Convert.ToSByte ("0x", 16);
4352                 }
4353
4354                 [Test]
4355                 [ExpectedException (typeof (FormatException))]
4356                 public void ToUInt16_HexPrefixOnly ()
4357                 {
4358                         Convert.ToUInt16 ("0x", 16);
4359                 }
4360
4361                 [Test]
4362                 [ExpectedException (typeof (FormatException))]
4363                 public void ToUInt32_HexPrefixOnly ()
4364                 {
4365                         Convert.ToUInt32 ("0x", 16);
4366                 }
4367
4368                 [Test]
4369                 [ExpectedException (typeof (FormatException))]
4370                 public void ToUInt64_HexPrefixOnly ()
4371                 {
4372                         Convert.ToUInt64 ("0x", 16);
4373                 }
4374
4375                 [Test]
4376                 [ExpectedException (typeof (ArgumentException))]
4377                 public void ToByte_Base2_NegativeSignOnly ()
4378                 {
4379                         Convert.ToByte ("-", 2);
4380                 }
4381
4382                 [Test]
4383                 [ExpectedException (typeof (ArgumentException))]
4384                 public void ToByte_Base8_NegativeSignOnly ()
4385                 {
4386                         Convert.ToByte ("-", 8);
4387                 }
4388
4389                 [Test]
4390                 [ExpectedException (typeof (OverflowException))]
4391                 public void ToByte_Base10_NegativeSignOnly ()
4392                 {
4393                         Convert.ToByte ("-", 10);
4394                 }
4395
4396                 [Test]
4397                 [ExpectedException (typeof (ArgumentException))]
4398                 public void ToByte_Base16_NegativeSignOnly ()
4399                 {
4400                         Convert.ToByte ("-", 16);
4401                 }
4402
4403                 [Test]
4404                 [ExpectedException (typeof (ArgumentException))]
4405                 public void ToInt16_Base2_NegativeSignOnly ()
4406                 {
4407                         Convert.ToInt16 ("-", 2);
4408                 }
4409
4410                 [Test]
4411                 [ExpectedException (typeof (ArgumentException))]
4412                 public void ToInt16_Base8_NegativeSignOnly ()
4413                 {
4414                         Convert.ToInt16 ("-", 8);
4415                 }
4416
4417                 [Test]
4418                 [ExpectedException (typeof (FormatException))]
4419                 public void ToInt16_Base10_NegativeSignOnly ()
4420                 {
4421                         Convert.ToInt16 ("-", 10);
4422                 }
4423
4424                 [Test]
4425                 [ExpectedException (typeof (ArgumentException))]
4426                 public void ToInt16_Base16_NegativeSignOnly ()
4427                 {
4428                         Convert.ToInt16 ("-", 16);
4429                 }
4430
4431                 [Test]
4432                 [ExpectedException (typeof (ArgumentException))]
4433                 public void ToInt32_Base2_NegativeSignOnly ()
4434                 {
4435                         Convert.ToInt32 ("-", 2);
4436                 }
4437
4438                 [Test]
4439                 [ExpectedException (typeof (ArgumentException))]
4440                 public void ToInt32_Base8_NegativeSignOnly ()
4441                 {
4442                         Convert.ToInt32 ("-", 8);
4443                 }
4444
4445                 [Test]
4446                 [ExpectedException (typeof (FormatException))]
4447                 public void ToInt32_Base10_NegativeSignOnly ()
4448                 {
4449                         Convert.ToInt32 ("-", 10);
4450                 }
4451
4452                 [Test]
4453                 [ExpectedException (typeof (ArgumentException))]
4454                 public void ToInt32_Base16_NegativeSignOnly ()
4455                 {
4456                         Convert.ToInt32 ("-", 16);
4457                 }
4458
4459                 [Test]
4460                 [ExpectedException (typeof (ArgumentException))]
4461                 public void ToInt64_Base2_NegativeSignOnly ()
4462                 {
4463                         Convert.ToInt64 ("-", 2);
4464                 }
4465
4466                 [Test]
4467                 [ExpectedException (typeof (ArgumentException))]
4468                 public void ToInt64_Base8_NegativeSignOnly ()
4469                 {
4470                         Convert.ToInt64 ("-", 8);
4471                 }
4472
4473                 [Test]
4474                 [ExpectedException (typeof (FormatException))]
4475                 public void ToInt64_Base10_NegativeSignOnly ()
4476                 {
4477                         Convert.ToInt64 ("-", 10);
4478                 }
4479
4480                 [Test]
4481                 [ExpectedException (typeof (ArgumentException))]
4482                 public void ToInt64_Base16_NegativeSignOnly ()
4483                 {
4484                         Convert.ToInt64 ("-", 16);
4485                 }
4486
4487                 [Test]
4488                 [ExpectedException (typeof (ArgumentException))]
4489                 public void ToSByte_Base2_NegativeSignOnly ()
4490                 {
4491                         Convert.ToSByte ("-", 2);
4492                 }
4493
4494                 [Test]
4495                 [ExpectedException (typeof (ArgumentException))]
4496                 public void ToSByte_Base8_NegativeSignOnly ()
4497                 {
4498                         Convert.ToSByte ("-", 8);
4499                 }
4500
4501                 [Test]
4502                 [ExpectedException (typeof (FormatException))]
4503                 public void ToSByte_Base10_NegativeSignOnly ()
4504                 {
4505                         Convert.ToSByte ("-", 10);
4506                 }
4507
4508                 [Test]
4509                 [ExpectedException (typeof (ArgumentException))]
4510                 public void ToSByte_Base16_NegativeSignOnly ()
4511                 {
4512                         Convert.ToSByte ("-", 16);
4513                 }
4514
4515                 [Test]
4516                 [ExpectedException (typeof (ArgumentException))]
4517                 public void ToUInt16_Base2_NegativeSignOnly ()
4518                 {
4519                         Convert.ToUInt16 ("-", 2);
4520                 }
4521
4522                 [Test]
4523                 [ExpectedException (typeof (ArgumentException))]
4524                 public void ToUInt16_Base8_NegativeSignOnly ()
4525                 {
4526                         Convert.ToUInt16 ("-", 8);
4527                 }
4528
4529                 [Test]
4530                 [ExpectedException (typeof (OverflowException))]
4531                 public void ToUInt16_Base10_NegativeSignOnly ()
4532                 {
4533                         Convert.ToUInt16 ("-", 10);
4534                 }
4535
4536                 [Test]
4537                 [ExpectedException (typeof (ArgumentException))]
4538                 public void ToUInt16_Base16_NegativeSignOnly ()
4539                 {
4540                         Convert.ToUInt16 ("-", 16);
4541                 }
4542
4543                 [Test]
4544                 [ExpectedException (typeof (ArgumentException))]
4545                 public void ToUInt32_Base2_NegativeSignOnly ()
4546                 {
4547                         Convert.ToUInt32 ("-", 2);
4548                 }
4549
4550                 [Test]
4551                 [ExpectedException (typeof (ArgumentException))]
4552                 public void ToUInt32_Base8_NegativeSignOnly ()
4553                 {
4554                         Convert.ToUInt32 ("-", 8);
4555                 }
4556
4557                 [Test]
4558                 [ExpectedException (typeof (OverflowException))]
4559                 public void ToUInt32_Base10_NegativeSignOnly ()
4560                 {
4561                         Convert.ToUInt32 ("-", 10);
4562                 }
4563
4564                 [Test]
4565                 [ExpectedException (typeof (ArgumentException))]
4566                 public void ToUInt32_Base16_NegativeSignOnly ()
4567                 {
4568                         Convert.ToUInt32 ("-", 16);
4569                 }
4570
4571                 [Test]
4572                 [ExpectedException (typeof (ArgumentException))]
4573                 public void ToUInt64_Base2_NegativeSignOnly ()
4574                 {
4575                         Convert.ToUInt64 ("-", 2);
4576                 }
4577
4578                 [Test]
4579                 [ExpectedException (typeof (ArgumentException))]
4580                 public void ToUInt64_Base8_NegativeSignOnly ()
4581                 {
4582                         Convert.ToUInt64 ("-", 8);
4583                 }
4584
4585                 [Test]
4586                 [ExpectedException (typeof (OverflowException))]
4587                 public void ToUInt64_Base10_NegativeSignOnly ()
4588                 {
4589                         Convert.ToUInt64 ("-", 10);
4590                 }
4591
4592                 [Test]
4593                 [ExpectedException (typeof (ArgumentException))]
4594                 public void ToUInt64_Base16_NegativeSignOnly ()
4595                 {
4596                         Convert.ToUInt64 ("-", 16);
4597                 }
4598
4599                 [Test] // bug #481687
4600                 public void ChangeType_Value_IConvertible ()
4601                 {
4602                         BitmapStatus bitmapStatus = new BitmapStatus (3);
4603                         Image c1 = Convert.ChangeType (bitmapStatus, typeof (Image)) as Image;
4604                         Assert.IsNotNull (c1, "#A1");
4605                         Assert.AreEqual (32, c1.ColorDepth, "#A2");
4606
4607                         bitmapStatus.ConvertToImage = false;
4608                         object c2 = Convert.ChangeType (bitmapStatus, typeof (Image));
4609                         Assert.IsNull (c2, "#B");
4610
4611                         object c3 = Convert.ChangeType (bitmapStatus, typeof (int));
4612                         Assert.IsNotNull (c3, "#C1");
4613                         Assert.AreEqual (3, c3, "#C2");
4614                 }
4615
4616                 // This is a simple and happy struct.
4617                 struct Foo {
4618                 }
4619                 
4620                 [Test]
4621                 [ExpectedException (typeof (InvalidCastException))]
4622                 public void ChangeType_ShouldThrowOnString ()
4623                 {
4624                         Convert.ChangeType ("this-is-a-string", typeof (Foo));
4625                 }
4626         }
4627
4628         public class Image
4629         {
4630                 private int colorDepth;
4631
4632                 public Image ()
4633                 {
4634                         colorDepth = 8;
4635                 }
4636
4637                 public Image (int colorDepth)
4638                 {
4639                         this.colorDepth = colorDepth;
4640                 }
4641
4642                 public int ColorDepth {
4643                         get { return colorDepth; }
4644                 }
4645         }
4646
4647         public class BitmapStatus : IConvertible
4648         {
4649                 protected int m_Status;
4650                 private bool convertToImage;
4651
4652                 public BitmapStatus (int status)
4653                 {
4654                         m_Status = status;
4655                         convertToImage = true;
4656                 }
4657
4658                 public bool ConvertToImage {
4659                         get { return convertToImage; }
4660                         set { convertToImage = value; }
4661                 }
4662
4663                 TypeCode IConvertible.GetTypeCode ()
4664                 {
4665                         return TypeCode.Int32;
4666                 }
4667
4668                 bool IConvertible.ToBoolean (IFormatProvider provider)
4669                 {
4670                         return (bool)((IConvertible)this).ToType (typeof (bool), provider);
4671                 }
4672
4673                 byte IConvertible.ToByte (IFormatProvider provider)
4674                 {
4675                         return (byte)((IConvertible)this).ToType (typeof (byte), provider);
4676                 }
4677
4678                 char IConvertible.ToChar (IFormatProvider provider)
4679                 {
4680                         return (char)((IConvertible)this).ToType (typeof (char), provider);
4681                 }
4682
4683                 DateTime IConvertible.ToDateTime (IFormatProvider provider)
4684                 {
4685                         return (DateTime)((IConvertible)this).ToType (typeof (DateTime), provider);
4686                 }
4687
4688                 decimal IConvertible.ToDecimal (IFormatProvider provider)
4689                 {
4690                         return (decimal)((IConvertible)this).ToType (typeof (decimal), provider);
4691                 }
4692
4693                 double IConvertible.ToDouble (IFormatProvider provider)
4694                 {
4695                         return (double)((IConvertible)this).ToType (typeof (double), provider);
4696                 }
4697
4698                 short IConvertible.ToInt16 (IFormatProvider provider)
4699                 {
4700                         return (short)((IConvertible)this).ToType (typeof (short), provider);
4701                 }
4702
4703                 int IConvertible.ToInt32 (IFormatProvider provider)
4704                 {
4705                         return (int)m_Status;
4706                 }
4707
4708                 long IConvertible.ToInt64 (IFormatProvider provider)
4709                 {
4710                         return (long)((IConvertible)this).ToType (typeof (long), provider);
4711                 }
4712
4713                 sbyte IConvertible.ToSByte (IFormatProvider provider)
4714                 {
4715                         return (sbyte)((IConvertible)this).ToType (typeof (sbyte), provider);
4716                 }
4717
4718                 float IConvertible.ToSingle (IFormatProvider provider)
4719                 {
4720                         return (float)((IConvertible)this).ToType (typeof (float), provider);
4721                 }
4722
4723                 string IConvertible.ToString (IFormatProvider provider)
4724                 {
4725                         return (string)((IConvertible)this).ToType (typeof (string), provider);
4726                 }
4727
4728                 object IConvertible.ToType (Type conversionType, IFormatProvider provider)
4729                 {
4730                         if (ConvertToImage && conversionType == typeof (Image))
4731                                 return new Image (32);
4732                         else if (conversionType.IsAssignableFrom (typeof (int)))
4733                                 return Convert.ChangeType (1, conversionType, provider);
4734                         return null;
4735                 }
4736
4737                 ushort IConvertible.ToUInt16 (IFormatProvider provider)
4738                 {
4739                         return (ushort)((IConvertible)this).ToType (typeof (ushort), provider);
4740                 }
4741
4742                 uint IConvertible.ToUInt32 (IFormatProvider provider)
4743                 {
4744                         return (uint)((IConvertible)this).ToType (typeof (uint), provider);
4745                 }
4746
4747                 ulong IConvertible.ToUInt64 (IFormatProvider provider)
4748                 {
4749                         return (ulong)((IConvertible)this).ToType (typeof (ulong), provider);
4750                 }
4751         }
4752 }