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