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