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