1 // TestConvert.cs - NUnit Test Cases for System.Convert class
3 // Krister Hansson (ds99krha@thn.htu.se)
4 // Andreas Jonsson (ds99anjn@thn.htu.se)
6 // (C) Krister Hansson & Andreas Jonsson
11 using System.Globalization;
13 namespace MonoTests.System {
16 public class ConvertTest : Assertion {
47 tryDT = new DateTime(2002,1,1);
52 tryInt64 = 123456789012;
53 tryObj = new Object();
55 tryFloat = 1234.2345f;
56 falseString = "false";
63 ci = new CultureInfo("en-US");
64 ci.NumberFormat.NumberDecimalDigits = 3;
67 public void TestChangeType() {
70 AssertEquals("#A01", (short)12345, Convert.ChangeType(tryInt32, typeof(short)));
72 AssertEquals("#A02", 'A', Convert.ChangeType(65, typeof(char)));
74 AssertEquals("#A03", 66, Convert.ChangeType('B', typeof(int)));
76 AssertEquals("#A04", ((ulong)12345), Convert.ChangeType(tryInt32, typeof(ulong)));
79 AssertEquals("#A05", true, Convert.ChangeType(tryDec, TypeCode.Boolean));
81 AssertEquals("#A06", 'f', Convert.ChangeType("f", TypeCode.Char));
83 AssertEquals("#A07", (decimal)123456789012, Convert.ChangeType(tryInt64, TypeCode.Decimal));
85 AssertEquals("#A08", (int)34567, Convert.ChangeType(tryUI16, TypeCode.Int32));
88 AssertEquals("#A09", (double)567891234, Convert.ChangeType(tryUI32, typeof(double), ci));
90 AssertEquals("#A10", (ushort)0, Convert.ChangeType(tryByte, typeof(ushort), ci));
92 AssertEquals("#A11", (decimal)567891234, Convert.ChangeType(tryUI32, typeof(decimal), ci));
94 AssertEquals("#A12", (float)1234, Convert.ChangeType(tryInt16, typeof(float), ci));
96 AssertEquals("#A13", null, Convert.ChangeType(null, null, ci));
99 AssertEquals("#A14", (decimal)0, Convert.ChangeType(tryByte, TypeCode.Decimal, ci));
101 AssertEquals("#A15", "f", Convert.ChangeType('f', TypeCode.String, ci));
103 AssertEquals("#A16", 'D', Convert.ChangeType(68, TypeCode.Char, ci));
105 AssertEquals("#A17", (long)34567, Convert.ChangeType(tryUI16, TypeCode.Int64, ci));
107 AssertEquals("#A18", null, Convert.ChangeType(null, TypeCode.Empty, ci));
108 } catch (Exception e) {
109 Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e);
113 Convert.ChangeType(boolTrue, typeof(char));
116 catch (Exception e) {
117 AssertEquals("#A25", typeof(InvalidCastException), e.GetType());
121 Convert.ChangeType(tryChar, typeof(DateTime));
124 catch (Exception e) {
125 AssertEquals("#A26", typeof(InvalidCastException), e.GetType());
129 Convert.ChangeType(ci, TypeCode.String);
132 catch (Exception e) {
133 AssertEquals("#A27", typeof(InvalidCastException), e.GetType());
137 Convert.ChangeType(tryInt32, null);
140 catch (Exception e) {
141 AssertEquals("#A28", typeof(ArgumentNullException), e.GetType());
146 Convert.ChangeType(boolTrue, typeof(DateTime), ci);
149 catch (Exception e) {
150 AssertEquals("#A29", typeof(InvalidCastException), e.GetType());
154 Convert.ChangeType(ci, typeof(DateTime), ci);
157 catch (Exception e) {
158 AssertEquals("#A30", typeof(InvalidCastException), e.GetType());
161 /* Should throw ArgumentException but throws InvalidCastException
163 Convert.ChangeType(tryUI32, typeof(FormatException), ci);
166 catch (Exception e) {
167 AssertEquals("#A??", typeof(ArgumentException), e.GetType());
171 Convert.ChangeType(tryUI32, TypeCode.Byte, ci);
174 catch (Exception e) {
175 AssertEquals("#A31", typeof(OverflowException), e.GetType());
179 Convert.ChangeType(boolTrue, TypeCode.Char, ci);
182 catch (Exception e) {
183 AssertEquals("#A32", typeof(InvalidCastException), e.GetType());
187 Convert.ChangeType(boolTrue, null, ci);
190 catch (Exception e) {
191 AssertEquals("#A33", typeof(ArgumentNullException), e.GetType());
195 /* should fail to convert string to any enumeration type. */
196 Convert.ChangeType("random string", typeof(DayOfWeek));
199 catch (Exception e) {
200 AssertEquals("#A34", typeof(InvalidCastException), e.GetType());
205 public void TestGetTypeCode() {
208 AssertEquals("#B01", TypeCode.String, Convert.GetTypeCode(tryStr));
210 AssertEquals("#B02", TypeCode.UInt16, Convert.GetTypeCode(tryUI16));
212 AssertEquals("#B03", TypeCode.UInt32, Convert.GetTypeCode(tryUI32));
214 AssertEquals("#B04", TypeCode.UInt64, Convert.GetTypeCode(tryUI64));
216 AssertEquals("#B05", TypeCode.Double, Convert.GetTypeCode(tryDbl));
218 AssertEquals("#B06", TypeCode.Int16, Convert.GetTypeCode(tryInt16));
220 AssertEquals("#B07", TypeCode.Int64, Convert.GetTypeCode(tryInt64));
222 AssertEquals("#B08", TypeCode.Object, Convert.GetTypeCode(tryObj));
224 AssertEquals("#B09", TypeCode.SByte, Convert.GetTypeCode(trySByte));
226 AssertEquals("#B10", TypeCode.Single, Convert.GetTypeCode(tryFloat));
228 AssertEquals("#B11", TypeCode.Byte, Convert.GetTypeCode(tryByte));
230 AssertEquals("#B12", TypeCode.Char, Convert.GetTypeCode(tryChar));
232 // AssertEquals("#B13", TypeCode.DateTime, Convert.GetTypeCode(tryDT));
234 AssertEquals("#B14", TypeCode.Decimal, Convert.GetTypeCode(tryDec));
236 AssertEquals("#B15", TypeCode.Int32, Convert.GetTypeCode(tryInt32));
238 AssertEquals("#B16", TypeCode.Boolean, Convert.GetTypeCode(boolTrue));
239 } catch (Exception e) {
240 Fail ("Unexpected exception at " + marker + ": " + e);
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));
252 public void TestToBoolean() {
253 tryObj = (object)tryDbl;
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));
275 Convert.ToBoolean(tryChar);
278 catch (Exception e) {
279 AssertEquals("#D20", typeof(InvalidCastException), e.GetType());
283 Convert.ToBoolean(tryDT);
286 catch (Exception e) {
287 AssertEquals("#D21", typeof(InvalidCastException), e.GetType());
291 Convert.ToBoolean(tryStr);
294 catch (Exception e) {
295 AssertEquals("#D22", typeof(FormatException), e.GetType());
299 Convert.ToBoolean(nullString);
302 catch (Exception e) {
303 AssertEquals("#D23", typeof(FormatException), e.GetType());
307 public void TestToByte() {
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));
331 Convert.ToByte('\u03A9'); // sign of Omega on Win2k
334 catch (Exception e) {
335 AssertEquals("#E25", typeof(OverflowException), e.GetType());
339 Convert.ToByte(tryDT);
342 catch (Exception e) {
343 AssertEquals("#D26", typeof(InvalidCastException), e.GetType());
347 Convert.ToByte((decimal)22000);
350 catch (Exception e) {
351 AssertEquals("#E27", typeof(OverflowException), e.GetType());
355 Convert.ToByte((double)255.5);
358 catch (Exception e) {
359 AssertEquals("#E28", typeof(OverflowException), e.GetType());
363 Convert.ToByte(-tryInt16);
366 catch (Exception e) {
367 AssertEquals("#E29", typeof(OverflowException), e.GetType());
371 Convert.ToByte((int)-256);
374 catch (Exception e) {
375 AssertEquals("#E30", typeof(OverflowException), e.GetType());
379 Convert.ToByte(tryInt64);
382 catch (Exception e) {
383 AssertEquals("#E31", typeof(OverflowException), e.GetType());
387 Convert.ToByte((object)ci);
390 catch (Exception e) {
391 AssertEquals("#E32", typeof(InvalidCastException), e.GetType());
395 Convert.ToByte((sbyte)-1);
398 catch (Exception e) {
399 AssertEquals("#E33", typeof(OverflowException), e.GetType());
403 Convert.ToByte((float)-0.6f);
406 catch (Exception e) {
407 AssertEquals("#E34", typeof(OverflowException), e.GetType());
411 Convert.ToByte("1a1");
414 catch (Exception e) {
415 AssertEquals("#E35", typeof(FormatException), e.GetType());
419 Convert.ToByte("457");
422 catch (Exception e) {
423 AssertEquals("#E36", typeof(OverflowException), e.GetType());
427 Convert.ToByte((ushort)30000);
430 catch (Exception e) {
431 AssertEquals("#E37", typeof(OverflowException), e.GetType());
435 Convert.ToByte((uint)300);
438 catch (Exception e) {
439 AssertEquals("#E38", typeof(OverflowException), e.GetType());
443 Convert.ToByte((ulong)987654321321);
446 catch (Exception e) {
447 AssertEquals("#E39", typeof(OverflowException), e.GetType());
451 Convert.ToByte("10010111", 3);
454 catch (Exception e) {
455 AssertEquals("#E40", typeof(ArgumentException), e.GetType());
459 Convert.ToByte("3F3", 16);
462 catch (Exception e) {
463 AssertEquals("#E41", typeof(OverflowException), e.GetType());
467 public void TestToChar(){
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));
483 Convert.ToChar(boolTrue);
486 catch (Exception e) {
487 AssertEquals("#F20", typeof(InvalidCastException), e.GetType());
491 Convert.ToChar(tryDT);
494 catch (Exception e) {
495 AssertEquals("#F21", typeof(InvalidCastException), e.GetType());
499 Convert.ToChar(tryDec);
502 catch (Exception e) {
503 AssertEquals("#F22", typeof(InvalidCastException), e.GetType());
507 Convert.ToChar(tryDbl);
510 catch (Exception e) {
511 AssertEquals("#F23", typeof(InvalidCastException), e.GetType());
515 Convert.ToChar((short)-1);
518 catch (Exception e) {
519 AssertEquals("#F24", typeof(OverflowException), e.GetType());
523 Convert.ToChar(Int32.MinValue);
526 catch (Exception e) {
527 AssertEquals("#F25", typeof(OverflowException), e.GetType());
531 Convert.ToChar(Int32.MaxValue);
534 catch (Exception e) {
535 AssertEquals("#F26", typeof(OverflowException), e.GetType());
539 Convert.ToChar(tryInt64);
542 catch (Exception e) {
543 AssertEquals("#F27", typeof(OverflowException), e.GetType());
547 Convert.ToChar((long)-123);
550 catch (Exception e) {
551 AssertEquals("#F28", typeof(OverflowException), e.GetType());
558 catch (Exception e) {
559 AssertEquals("#F29", typeof(InvalidCastException), e.GetType());
563 Convert.ToChar(-trySByte);
566 catch (Exception e) {
567 AssertEquals("#F30", typeof(OverflowException), e.GetType());
571 Convert.ToChar(tryFloat);
574 catch (Exception e) {
575 AssertEquals("#F31", typeof(InvalidCastException), e.GetType());
579 Convert.ToChar("foo");
582 catch (Exception e) {
583 AssertEquals("#F32", typeof(FormatException), e.GetType());
587 Convert.ToChar(null);
590 catch (Exception e) {
591 AssertEquals("#F33", typeof(ArgumentNullException), e.GetType());
595 Convert.ToChar(new Exception(), ci);
598 catch (Exception e) {
599 AssertEquals("#F34", typeof(InvalidCastException), e.GetType());
603 Convert.ToChar(null, ci);
606 catch (Exception e) {
607 AssertEquals("#F35", typeof(ArgumentNullException), e.GetType());
611 Convert.ToChar("", ci);
614 catch (Exception e) {
615 AssertEquals("#F36", typeof(FormatException), e.GetType());
619 Convert.ToChar(tryStr, ci);
622 catch (Exception e) {
623 AssertEquals("#F37", typeof(FormatException), e.GetType());
627 /*[Ignore ("http://bugzilla.ximian.com/show_bug.cgi?id=45286")]
629 [ExpectedException (typeof (ArgumentOutOfRangeException))]
631 Convert.ToDateTime("20002-25-01");
634 public void TestToDateTime() {
635 string dateString = "01/01/2002";
638 AssertEquals("#G01", tryDT, Convert.ToDateTime(tryDT));
640 AssertEquals("#G02", tryDT, Convert.ToDateTime(dateString));
642 AssertEquals("#G03", tryDT, Convert.ToDateTime(dateString, ci));
643 } catch (Exception e) {
644 Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e);
648 Convert.ToDateTime(boolTrue);
651 catch (Exception e) {
652 AssertEquals("#G10", typeof(InvalidCastException), e.GetType());
656 Convert.ToDateTime(tryByte);
659 catch (Exception e) {
660 AssertEquals("#G11", typeof(InvalidCastException), e.GetType());
664 Convert.ToDateTime(tryChar);
667 catch (Exception e) {
668 AssertEquals("#G12", typeof(InvalidCastException), e.GetType());
672 Convert.ToDateTime(tryDec);
675 catch (Exception e) {
676 AssertEquals("#G13", typeof(InvalidCastException), e.GetType());
680 Convert.ToDateTime(tryDbl);
683 catch (Exception e) {
684 AssertEquals("#G14", typeof(InvalidCastException), e.GetType());
688 Convert.ToDateTime(tryInt16);
691 catch (Exception e) {
692 AssertEquals("#G15", typeof(InvalidCastException), e.GetType());
696 Convert.ToDateTime(tryInt32);
699 catch (Exception e) {
700 AssertEquals("#G16", typeof(InvalidCastException), e.GetType());
704 Convert.ToDateTime(tryInt64);
707 catch (Exception e) {
708 AssertEquals("#G17", typeof(InvalidCastException), e.GetType());
712 Convert.ToDateTime(ci);
715 catch (Exception e) {
716 AssertEquals("#G18", typeof(InvalidCastException), e.GetType());
720 Convert.ToDateTime(trySByte);
723 catch (Exception e) {
724 AssertEquals("#G19", typeof(InvalidCastException), e.GetType());
728 Convert.ToDateTime(tryFloat);
731 catch (Exception e) {
732 AssertEquals("#G20", typeof(InvalidCastException), e.GetType());
736 Convert.ToDateTime("20a2-01-01");
739 catch (Exception e) {
740 AssertEquals("#G21", typeof(FormatException), e.GetType());
744 Convert.ToDateTime(tryUI16);
747 catch (Exception e) {
748 AssertEquals("#G23", typeof(InvalidCastException), e.GetType());
752 Convert.ToDateTime(tryUI32);
755 catch (Exception e) {
756 AssertEquals("#G24", typeof(InvalidCastException), e.GetType());
760 Convert.ToDateTime(tryUI64);
763 catch (Exception e) {
764 AssertEquals("#G25", typeof(InvalidCastException), e.GetType());
768 Convert.ToDateTime(ci, ci);
771 catch (Exception e) {
772 AssertEquals("#G26", typeof(InvalidCastException), e.GetType());
776 Convert.ToDateTime("20a2-01-01", ci);
779 catch (Exception e) {
780 AssertEquals("#G27", typeof(FormatException), e.GetType());
783 // this is supported by .net 1.1 (defect 41845)
785 Convert.ToDateTime("20022-01-01");
788 catch (Exception e) {
789 AssertEquals("#G28", typeof(ArgumentOutOfRangeException), e.GetType());
793 Convert.ToDateTime("2002-21-01");
796 catch (Exception e) {
797 AssertEquals("#G29", typeof(FormatException), e.GetType());
801 Convert.ToDateTime("2002-111-01");
804 catch (Exception e) {
805 AssertEquals("#G30", typeof(FormatException), e.GetType());
809 Convert.ToDateTime("2002-01-41");
812 catch (Exception e) {
813 AssertEquals("#G31", typeof(FormatException), e.GetType());
817 Convert.ToDateTime("2002-01-111");
820 catch (Exception e) {
821 AssertEquals("#G32", typeof(FormatException), e.GetType());
825 AssertEquals("#G33", tryDT, Convert.ToDateTime("2002-01-01"));
826 } catch (Exception e) {
827 Fail ("Unexpected exception at #G33 " + e);
831 Convert.ToDateTime("2002-01-11 34:11:11");
834 catch (Exception e) {
835 AssertEquals("#G34", typeof(FormatException), e.GetType());
839 Convert.ToDateTime("2002-01-11 11:70:11");
842 catch (Exception e) {
843 AssertEquals("#G35", typeof(FormatException), e.GetType());
847 Convert.ToDateTime("2002-01-11 11:11:70");
850 catch (Exception e) {
851 AssertEquals("#G36", typeof(FormatException), e.GetType());
856 public void TestToDecimal() {
857 AssertEquals("#H01", (decimal)1, Convert.ToDecimal(boolTrue));
858 AssertEquals("#H02", (decimal)0, Convert.ToDecimal(boolFalse));
859 AssertEquals("#H03", (decimal)tryByte, Convert.ToDecimal(tryByte));
860 AssertEquals("#H04", tryDec, Convert.ToDecimal(tryDec));
861 AssertEquals("#H05", (decimal)tryDbl, Convert.ToDecimal(tryDbl));
862 AssertEquals("#H06", (decimal)tryInt16, Convert.ToDecimal(tryInt16));
863 AssertEquals("#H07", (decimal)tryInt32, Convert.ToDecimal(tryInt32));
864 AssertEquals("#H08", (decimal)tryInt64, Convert.ToDecimal(tryInt64));
865 AssertEquals("#H09", (decimal)trySByte, Convert.ToDecimal(trySByte));
866 AssertEquals("#H10", (decimal)tryFloat, Convert.ToDecimal(tryFloat));
867 string sep = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
868 // AssertEquals("#H11", (decimal)23456.432, Convert.ToDecimal("23456" + sep + "432"));
869 // Note: changed because the number were the same but with a different base
870 // and this isn't a Convert bug (but a Decimal bug). See #60227 for more details.
871 // http://bugzilla.ximian.com/show_bug.cgi?id=60227
872 Assert ("#H11", Decimal.Equals (23456.432m, Convert.ToDecimal ("23456" + sep + "432")));
873 AssertEquals("#H12", (decimal)tryUI16, Convert.ToDecimal(tryUI16));
874 AssertEquals("#H13", (decimal)tryUI32, Convert.ToDecimal(tryUI32));
875 AssertEquals("#H14", (decimal)tryUI64, Convert.ToDecimal(tryUI64));
876 AssertEquals("#H15", (decimal)63784, Convert.ToDecimal("63784", ci));
879 Convert.ToDecimal(tryChar);
882 catch (Exception e) {
883 AssertEquals("#H20", typeof(InvalidCastException), e.GetType());
887 Convert.ToDecimal(tryDT);
890 catch (Exception e) {
891 AssertEquals("#H21", typeof(InvalidCastException), e.GetType());
895 Convert.ToDecimal(double.MaxValue);
898 catch (Exception e) {
899 AssertEquals("#H22", typeof(OverflowException), e.GetType());
903 Convert.ToDecimal(double.MinValue);
906 catch (Exception e) {
907 AssertEquals("#H23", typeof(OverflowException), e.GetType());
911 Convert.ToDecimal(ci);
914 catch (Exception e) {
915 AssertEquals("#H24", typeof(InvalidCastException), e.GetType());
919 Convert.ToDecimal(tryStr);
922 catch (Exception e) {
923 AssertEquals("#H25", typeof(FormatException), e.GetType());
927 string maxDec = decimal.MaxValue.ToString();
928 maxDec = maxDec + "1";
929 Convert.ToDecimal(maxDec);
932 catch (Exception e) {
933 AssertEquals("#H26", typeof(OverflowException), e.GetType());
937 Convert.ToDecimal(ci, ci);
940 catch (Exception e) {
941 AssertEquals("#H27", typeof(InvalidCastException), e.GetType());
945 Convert.ToDecimal(tryStr, ci);
948 catch (Exception e) {
949 AssertEquals("#H28", typeof(FormatException), e.GetType());
953 string maxDec = decimal.MaxValue.ToString();
954 maxDec = maxDec + "1";
955 Convert.ToDecimal(maxDec, ci);
958 catch (Exception e) {
959 AssertEquals("#H29", typeof(OverflowException), e.GetType());
963 public void TestToDouble() {
966 AssertEquals("#I01", (double)1, Convert.ToDouble(boolTrue));
968 AssertEquals("#I02", (double)0, Convert.ToDouble(boolFalse));
970 AssertEquals("#I03", (double)tryByte, Convert.ToDouble(tryByte));
972 AssertEquals("#I04", tryDbl, Convert.ToDouble(tryDbl));
974 AssertEquals("#I05", (double)tryDec, Convert.ToDouble(tryDec));
976 AssertEquals("#I06", (double)tryInt16, Convert.ToDouble(tryInt16));
978 AssertEquals("#I07", (double)tryInt32, Convert.ToDouble(tryInt32));
980 AssertEquals("#I08", (double)tryInt64, Convert.ToDouble(tryInt64));
982 AssertEquals("#I09", (double)trySByte, Convert.ToDouble(trySByte));
984 AssertEquals("#I10", (double)tryFloat, Convert.ToDouble(tryFloat));
986 string sep = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
987 AssertEquals("#I11", (double)23456.432, Convert.ToDouble("23456" + sep + "432"));
989 AssertEquals("#I12", (double)tryUI16, Convert.ToDouble(tryUI16));
991 AssertEquals("#I13", (double)tryUI32, Convert.ToDouble(tryUI32));
993 AssertEquals("#I14", (double)tryUI64, Convert.ToDouble(tryUI64));
995 AssertEquals("#H15", (double)63784, Convert.ToDouble("63784", ci));
996 } catch (Exception e) {
997 Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e);
1001 Convert.ToDouble(tryChar);
1004 catch (Exception e) {
1005 AssertEquals("#I20", typeof(InvalidCastException), e.GetType());
1009 Convert.ToDouble(tryDT);
1012 catch (Exception e) {
1013 AssertEquals("#I21", typeof(InvalidCastException), e.GetType());
1017 Convert.ToDouble(ci);
1020 catch (Exception e) {
1021 AssertEquals("#I22", typeof(InvalidCastException), e.GetType());
1025 Convert.ToDouble(tryStr);
1028 catch (Exception e) {
1029 AssertEquals("#I23", typeof(FormatException), e.GetType());
1033 string maxDec = double.MaxValue.ToString();
1034 maxDec = maxDec + "1";
1035 Convert.ToDouble(maxDec);
1038 catch (Exception e) {
1039 AssertEquals("#I24", typeof(OverflowException), e.GetType());
1043 Convert.ToDouble(ci, ci);
1046 catch (Exception e) {
1047 AssertEquals("#I25", typeof(InvalidCastException), e.GetType());
1051 Convert.ToDouble(tryStr, ci);
1054 catch (Exception e) {
1055 AssertEquals("#I26", typeof(FormatException), e.GetType());
1059 string maxDec = double.MaxValue.ToString();
1060 maxDec = maxDec + "1";
1061 Convert.ToDouble(maxDec, ci);
1064 catch (Exception e) {
1065 AssertEquals("#I27", typeof(OverflowException), e.GetType());
1069 Convert.ToDouble(tryObj, ci);
1072 catch (Exception e) {
1073 AssertEquals("#I28", typeof(InvalidCastException), e.GetType());
1077 public void TestToInt16() {
1078 AssertEquals("#J01", (short)0, Convert.ToInt16(boolFalse));
1079 AssertEquals("#J02", (short)1, Convert.ToInt16(boolTrue));
1080 AssertEquals("#J03", (short)97, Convert.ToInt16(tryChar));
1081 AssertEquals("#J04", (short)1234, Convert.ToInt16(tryDec));
1082 AssertEquals("#J05", (short)0, Convert.ToInt16(tryDbl));
1083 AssertEquals("#J06", (short)1234, Convert.ToInt16(tryInt16));
1084 AssertEquals("#J07", (short)12345, Convert.ToInt16(tryInt32));
1085 AssertEquals("#J08", (short)30000, Convert.ToInt16((long)30000));
1086 AssertEquals("#J09", (short)123, Convert.ToInt16(trySByte));
1087 AssertEquals("#J10", (short)1234, Convert.ToInt16(tryFloat));
1088 AssertEquals("#J11", (short)578, Convert.ToInt16("578"));
1089 AssertEquals("#J12", (short)15500, Convert.ToInt16((ushort)15500));
1090 AssertEquals("#J13", (short)5489, Convert.ToInt16((uint)5489));
1091 AssertEquals("#J14", (short)9876, Convert.ToInt16((ulong)9876));
1092 AssertEquals("#J15", (short)14, Convert.ToInt16("14", ci));
1093 AssertEquals("#J16", (short)11, Convert.ToInt16("01011", 2));
1094 AssertEquals("#J17", (short)1540, Convert.ToInt16("3004", 8));
1095 AssertEquals("#J18", (short)321, Convert.ToInt16("321", 10));
1096 AssertEquals("#J19", (short)2748, Convert.ToInt16("ABC", 16));
1099 Convert.ToInt16(char.MaxValue);
1102 catch (Exception e) {
1103 AssertEquals("#J25", typeof(OverflowException), e.GetType());
1107 Convert.ToInt16(tryDT);
1110 catch (Exception e) {
1111 AssertEquals("#J26", typeof(InvalidCastException), e.GetType());
1115 Convert.ToInt16((decimal)(short.MaxValue + 1));
1118 catch (Exception e) {
1119 AssertEquals("#J27", typeof(OverflowException), e.GetType());
1123 Convert.ToInt16((decimal)(short.MinValue - 1));
1126 catch (Exception e) {
1127 AssertEquals("#J28", typeof(OverflowException), e.GetType());
1131 Convert.ToInt16((double)(short.MaxValue + 1));
1134 catch (Exception e) {
1135 AssertEquals("#J29", typeof(OverflowException), e.GetType());
1139 Convert.ToInt16((double)(short.MinValue - 1));
1142 catch (Exception e) {
1143 AssertEquals("#J30", typeof(OverflowException), e.GetType());
1147 Convert.ToInt16(50000);
1150 catch (Exception e) {
1151 AssertEquals("#J31", typeof(OverflowException), e.GetType());
1155 Convert.ToInt16(-50000);
1158 catch (Exception e) {
1159 AssertEquals("#J32", typeof(OverflowException), e.GetType());
1163 Convert.ToInt16(tryInt64);
1166 catch (Exception e) {
1167 AssertEquals("#J33", typeof(OverflowException), e.GetType());
1171 Convert.ToInt16(-tryInt64);
1174 catch (Exception e) {
1175 AssertEquals("#J34", typeof(OverflowException), e.GetType());
1179 Convert.ToInt16(tryObj);
1182 catch (Exception e) {
1183 AssertEquals("#J35", typeof(InvalidCastException), e.GetType());
1187 Convert.ToInt16((float)32767.5);
1190 catch (Exception e) {
1191 AssertEquals("#J36", typeof(OverflowException), e.GetType());
1195 Convert.ToInt16((float)-33000.54);
1198 catch (Exception e) {
1199 AssertEquals("#J37", typeof(OverflowException), e.GetType());
1203 Convert.ToInt16(tryStr);
1206 catch (Exception e) {
1207 AssertEquals("#J38", typeof(FormatException), e.GetType());
1211 Convert.ToInt16("-33000");
1214 catch (Exception e) {
1215 AssertEquals("#J39", typeof(OverflowException), e.GetType());
1219 Convert.ToInt16(ushort.MaxValue);
1222 catch (Exception e) {
1223 AssertEquals("#J40", typeof(OverflowException), e.GetType());
1227 Convert.ToInt16(uint.MaxValue);
1230 catch (Exception e) {
1231 AssertEquals("#J41", typeof(OverflowException), e.GetType());
1235 Convert.ToInt16(ulong.MaxValue);
1238 catch (Exception e) {
1239 AssertEquals("#J42", typeof(OverflowException), e.GetType());
1243 Convert.ToInt16(tryObj, ci);
1246 catch (Exception e) {
1247 AssertEquals("#J43", typeof(InvalidCastException), e.GetType());
1251 Convert.ToInt16(tryStr, ci);
1254 catch (Exception e) {
1255 AssertEquals("#J44", typeof(FormatException), e.GetType());
1259 Convert.ToInt16("-33000", ci);
1262 catch (Exception e) {
1263 AssertEquals("#J45", typeof(OverflowException), e.GetType());
1267 Convert.ToInt16("321", 11);
1270 catch (Exception e) {
1271 AssertEquals("#J46", typeof(ArgumentException), e.GetType());
1275 Convert.ToInt16("D8BF1", 16);
1278 catch (Exception e) {
1279 AssertEquals("#J47", typeof(OverflowException), e.GetType());
1283 public void TestToInt32() {
1284 long tryMax = long.MaxValue;
1285 long tryMin = long.MinValue;
1286 AssertEquals("#K01", (int)0, Convert.ToInt32(boolFalse));
1287 AssertEquals("#K02", (int)1, Convert.ToInt32(boolTrue));
1288 AssertEquals("#K03", (int)0, Convert.ToInt32(tryByte));
1289 AssertEquals("#K04", (int)97, Convert.ToInt32(tryChar));
1290 AssertEquals("#K05", (int)1234, Convert.ToInt32(tryDec));
1291 AssertEquals("#K06", (int)0, Convert.ToInt32(tryDbl));
1292 AssertEquals("#K07", (int)1234, Convert.ToInt32(tryInt16));
1293 AssertEquals("#K08", (int)12345, Convert.ToInt32(tryInt32));
1294 AssertEquals("#K09", (int)60000, Convert.ToInt32((long)60000));
1295 AssertEquals("#K10", (int)123, Convert.ToInt32(trySByte));
1296 AssertEquals("#K11", (int)1234, Convert.ToInt32(tryFloat));
1297 AssertEquals("#K12", (int)9876, Convert.ToInt32((string)"9876"));
1298 AssertEquals("#K13", (int)34567, Convert.ToInt32(tryUI16));
1299 AssertEquals("#K14", (int)567891234, Convert.ToInt32(tryUI32));
1300 AssertEquals("#K15", (int)0, Convert.ToInt32(tryUI64));
1301 AssertEquals("#K16", (int)123, Convert.ToInt32("123", ci));
1302 AssertEquals("#K17", (int)128, Convert.ToInt32("10000000", 2));
1303 AssertEquals("#K18", (int)302, Convert.ToInt32("456", 8));
1304 AssertEquals("#K19", (int)456, Convert.ToInt32("456", 10));
1305 AssertEquals("#K20", (int)1110, Convert.ToInt32("456", 16));
1308 Convert.ToInt32(tryDT);
1311 catch (Exception e) {
1312 AssertEquals("#K25", typeof(InvalidCastException), e.GetType());
1316 Convert.ToInt32((decimal)tryMax);
1319 catch (Exception e) {
1320 AssertEquals("#K26", typeof(OverflowException), e.GetType());
1324 Convert.ToInt32((decimal)tryMin);
1327 catch (Exception e) {
1328 AssertEquals("#K27", typeof(OverflowException), e.GetType());
1332 Convert.ToInt32((double)tryMax);
1335 catch (Exception e) {
1336 AssertEquals("#K28", typeof(OverflowException), e.GetType());
1340 Convert.ToInt32((double)tryMin);
1343 catch (Exception e) {
1344 AssertEquals("#K29", typeof(OverflowException), e.GetType());
1348 Convert.ToInt32(tryInt64);
1351 catch (Exception e) {
1352 AssertEquals("#K30", typeof(OverflowException), e.GetType());
1356 Convert.ToInt32(-tryInt64);
1359 catch (Exception e) {
1360 AssertEquals("#K31", typeof(OverflowException), e.GetType());
1364 Convert.ToInt32(tryObj);
1367 catch (Exception e) {
1368 AssertEquals("#K32", typeof(InvalidCastException), e.GetType());
1372 Convert.ToInt32((float)tryMax);
1375 catch (Exception e) {
1376 AssertEquals("#K33", typeof(OverflowException), e.GetType());
1380 Convert.ToInt32((float)tryMin);
1383 catch (Exception e) {
1384 AssertEquals("#K34", typeof(OverflowException), e.GetType());
1388 Convert.ToInt32(tryStr, ci);
1391 catch (Exception e) {
1392 AssertEquals("#K35", typeof(FormatException), e.GetType());
1396 Convert.ToInt32("-46565465123");
1399 catch (Exception e) {
1400 AssertEquals("#K36", typeof(OverflowException), e.GetType());
1404 Convert.ToInt32("46565465123");
1407 catch (Exception e) {
1408 AssertEquals("#K37", typeof(OverflowException), e.GetType());
1412 Convert.ToInt32((uint)tryMax);
1415 catch (Exception e) {
1416 AssertEquals("#K38", typeof(OverflowException), e.GetType());
1420 Convert.ToInt32((ulong)tryMax);
1423 catch (Exception e) {
1424 AssertEquals("#K39", typeof(OverflowException), e.GetType());
1428 Convert.ToInt32(tryObj, ci);
1431 catch (Exception e) {
1432 AssertEquals("#K40", typeof(InvalidCastException), e.GetType());
1436 Convert.ToInt32(tryStr, ci);
1439 catch (Exception e) {
1440 AssertEquals("#K41", typeof(FormatException), e.GetType());
1444 Convert.ToInt32("-46565465123", ci);
1447 catch (Exception e) {
1448 AssertEquals("#K42", typeof(OverflowException), e.GetType());
1452 Convert.ToInt32("654", 9);
1455 catch (Exception e) {
1456 AssertEquals("#K43", typeof(ArgumentException), e.GetType());
1460 public void TestToInt64() {
1461 decimal longMax = long.MaxValue;
1463 decimal longMin = long.MinValue;
1466 AssertEquals("#L01", (long)0, Convert.ToInt64(boolFalse));
1467 AssertEquals("#L02", (long)1, Convert.ToInt64(boolTrue));
1468 AssertEquals("#L03", (long)97, Convert.ToInt64(tryChar));
1469 AssertEquals("#L04", (long)1234, Convert.ToInt64(tryDec));
1470 AssertEquals("#L05", (long)0, Convert.ToInt64(tryDbl));
1471 AssertEquals("#L06", (long)1234, Convert.ToInt64(tryInt16));
1472 AssertEquals("#L07", (long)12345, Convert.ToInt64(tryInt32));
1473 AssertEquals("#L08", (long)123456789012, Convert.ToInt64(tryInt64));
1474 AssertEquals("#L09", (long)123, Convert.ToInt64(trySByte));
1475 AssertEquals("#L10", (long)1234, Convert.ToInt64(tryFloat));
1476 AssertEquals("#L11", (long)564897, Convert.ToInt64("564897"));
1477 AssertEquals("#L12", (long)34567, Convert.ToInt64(tryUI16));
1478 AssertEquals("#L13", (long)567891234, Convert.ToInt64(tryUI32));
1479 AssertEquals("#L14", (long)0, Convert.ToInt64(tryUI64));
1480 AssertEquals("#L15", (long)-2548751, Convert.ToInt64("-2548751", ci));
1481 AssertEquals("#L16", (long)24987562, Convert.ToInt64("1011111010100011110101010", 2));
1482 AssertEquals("#L17", (long)-24578965, Convert.ToInt64("1777777777777642172153", 8));
1483 AssertEquals("#L18", (long)248759757, Convert.ToInt64("248759757", 10));
1484 AssertEquals("#L19", (long)256, Convert.ToInt64("100", 16));
1487 Convert.ToInt64(tryDT);
1490 catch (Exception e) {
1491 AssertEquals("#L20", typeof(InvalidCastException), e.GetType());
1495 Convert.ToInt64((decimal)longMax + 1);
1498 catch (Exception e) {
1499 AssertEquals("#L21", typeof(OverflowException), e.GetType());
1503 Convert.ToInt64((decimal)longMin);
1506 catch (Exception e) {
1507 AssertEquals("#L24", typeof(OverflowException), e.GetType());
1511 Convert.ToInt64((double)longMax);
1514 catch (Exception e) {
1515 AssertEquals("#L25:"+longMax, typeof(OverflowException), e.GetType());
1519 Convert.ToInt64((double)longMin);
1522 catch (Exception e) {
1523 AssertEquals("#L26", typeof(OverflowException), e.GetType());
1527 Convert.ToInt64(new Exception());
1530 catch (Exception e) {
1531 AssertEquals("#L27", typeof(InvalidCastException), e.GetType());
1535 Convert.ToInt64(((float)longMax)*100);
1538 catch (Exception e) {
1539 AssertEquals("#L28:"+longMax, typeof(OverflowException), e.GetType());
1543 Convert.ToInt64(((float)longMin)*100);
1546 catch (Exception e) {
1547 AssertEquals("#L29", typeof(OverflowException), e.GetType());
1551 Convert.ToInt64("-567b3");
1554 catch (Exception e) {
1555 AssertEquals("#L30", typeof(FormatException), e.GetType());
1559 Convert.ToInt64(longMax.ToString());
1562 catch (Exception e) {
1563 AssertEquals("#L31:", typeof(OverflowException), e.GetType());
1567 Convert.ToInt64(ulong.MaxValue);
1570 catch (Exception e) {
1571 AssertEquals("#L32", typeof(OverflowException), e.GetType());
1575 Convert.ToInt64(tryStr, ci);
1578 catch (Exception e) {
1579 AssertEquals("#L32b", typeof(FormatException), e.GetType());
1583 Convert.ToInt64(longMin.ToString(), ci);
1586 catch (Exception e) {
1587 AssertEquals("#L33", typeof(OverflowException), e.GetType());
1591 Convert.ToInt64("321", 11);
1594 catch (Exception e) {
1595 AssertEquals("#L34", typeof(ArgumentException), e.GetType());
1599 public void TestToSByte() {
1602 AssertEquals("#M01", (sbyte)0, Convert.ToSByte(boolFalse));
1604 AssertEquals("#M02", (sbyte)1, Convert.ToSByte(boolTrue));
1606 AssertEquals("#M03", (sbyte)97, Convert.ToSByte(tryChar));
1608 AssertEquals("#M04", (sbyte)15, Convert.ToSByte((decimal)15));
1610 AssertEquals("#M05", (sbyte)0, Convert.ToSByte(tryDbl));
1612 AssertEquals("#M06", (sbyte)127, Convert.ToSByte((short)127));
1614 AssertEquals("#M07", (sbyte)-128, Convert.ToSByte((int)-128));
1616 AssertEquals("#M08", (sbyte)30, Convert.ToSByte((long)30));
1618 AssertEquals("#M09", (sbyte)123, Convert.ToSByte(trySByte));
1620 AssertEquals("#M10", (sbyte)12, Convert.ToSByte((float)12.46987f));
1622 AssertEquals("#M11", (sbyte)1, Convert.ToSByte("1"));
1624 AssertEquals("#M12", (sbyte)99, Convert.ToSByte((ushort)99));
1626 AssertEquals("#M13", (sbyte)54, Convert.ToSByte((uint)54));
1628 AssertEquals("#M14", (sbyte)127, Convert.ToSByte((ulong)127));
1630 AssertEquals("#M15", (sbyte)14, Convert.ToSByte("14", ci));
1632 AssertEquals("#M16", (sbyte)11, Convert.ToSByte("01011", 2));
1634 AssertEquals("#M17", (sbyte)5, Convert.ToSByte("5", 8));
1636 AssertEquals("#M18", (sbyte)100, Convert.ToSByte("100", 10));
1638 AssertEquals("#M19", (sbyte)-1, Convert.ToSByte("FF", 16));
1639 } catch (Exception e) {
1640 Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e);
1644 Convert.ToSByte((byte)200);
1647 catch (Exception e) {
1648 AssertEquals("#M25", typeof(OverflowException), e.GetType());
1652 Convert.ToSByte((char)130);
1655 catch (Exception e) {
1656 AssertEquals("#M26", typeof(OverflowException), e.GetType());
1660 Convert.ToSByte(tryDT);
1663 catch (Exception e) {
1664 AssertEquals("#M27", typeof(InvalidCastException), e.GetType());
1668 Convert.ToSByte((decimal)127.5m);
1671 catch (Exception e) {
1672 AssertEquals("#M28", typeof(OverflowException), e.GetType());
1676 Convert.ToSByte((decimal)-200m);
1679 catch (Exception e) {
1680 AssertEquals("#M29", typeof(OverflowException), e.GetType());
1684 Convert.ToSByte((double)150);
1687 catch (Exception e) {
1688 AssertEquals("#M30", typeof(OverflowException), e.GetType());
1692 Convert.ToSByte((double)-128.6);
1695 catch (Exception e) {
1696 AssertEquals("#M31", typeof(OverflowException), e.GetType());
1700 Convert.ToSByte((short)150);
1703 catch (Exception e) {
1704 AssertEquals("#M32", typeof(OverflowException), e.GetType());
1708 Convert.ToSByte((short)-300);
1711 catch (Exception e) {
1712 AssertEquals("#M33", typeof(OverflowException), e.GetType());
1716 Convert.ToSByte((int)1500);
1719 catch (Exception e) {
1720 AssertEquals("#M34", typeof(OverflowException), e.GetType());
1724 Convert.ToSByte((int)-1286);
1727 catch (Exception e) {
1728 AssertEquals("#M35", typeof(OverflowException), e.GetType());
1732 Convert.ToSByte((long)128);
1735 catch (Exception e) {
1736 AssertEquals("#M36", typeof(OverflowException), e.GetType());
1740 Convert.ToSByte((long)-129);
1743 catch (Exception e) {
1744 AssertEquals("#M37", typeof(OverflowException), e.GetType());
1748 Convert.ToSByte(new NumberFormatInfo());
1751 catch (Exception e) {
1752 AssertEquals("#M38", typeof(InvalidCastException), e.GetType());
1756 Convert.ToSByte((float)333);
1759 catch (Exception e) {
1760 AssertEquals("#M39", typeof(OverflowException), e.GetType());
1764 Convert.ToSByte((float)-666);
1767 catch (Exception e) {
1768 AssertEquals("#M40", typeof(OverflowException), e.GetType());
1772 Convert.ToSByte("B3");
1775 catch (Exception e) {
1776 AssertEquals("#M41", typeof(FormatException), e.GetType());
1780 Convert.ToSByte("251");
1783 catch (Exception e) {
1784 AssertEquals("#M42", typeof(OverflowException), e.GetType());
1788 Convert.ToSByte(ushort.MaxValue);
1791 catch (Exception e) {
1792 AssertEquals("#M43", typeof(OverflowException), e.GetType());
1796 Convert.ToSByte((uint)600);
1799 catch (Exception e) {
1800 AssertEquals("#M44", typeof(OverflowException), e.GetType());
1804 Convert.ToSByte(ulong.MaxValue);
1807 catch (Exception e) {
1808 AssertEquals("#M45", typeof(OverflowException), e.GetType());
1812 Convert.ToSByte(ci, ci);
1815 catch (Exception e) {
1816 AssertEquals("#M46", typeof(InvalidCastException), e.GetType());
1820 Convert.ToSByte(tryStr, ci);
1823 catch (Exception e) {
1824 AssertEquals("#M47", typeof(FormatException), e.GetType());
1828 Convert.ToSByte("325", ci);
1831 catch (Exception e) {
1832 AssertEquals("#M48", typeof(OverflowException), e.GetType());
1836 Convert.ToSByte("5D", 15);
1839 catch (Exception e) {
1840 AssertEquals("#M49", typeof(ArgumentException), e.GetType());
1844 Convert.ToSByte("111111111", 2);
1847 catch (Exception e) {
1848 AssertEquals("#M50", typeof(OverflowException), e.GetType());
1852 public void TestToSingle() {
1855 AssertEquals("#N01", (float)0, Convert.ToSingle(boolFalse));
1857 AssertEquals("#N02", (float)1, Convert.ToSingle(boolTrue));
1859 AssertEquals("#N03", (float)0, Convert.ToSingle(tryByte));
1861 AssertEquals("#N04", (float)1234,234, Convert.ToSingle(tryDec));
1863 AssertEquals("#N05", (float)0, Convert.ToSingle(tryDbl));
1865 AssertEquals("#N06", (float)1234, Convert.ToSingle(tryInt16));
1867 AssertEquals("#N07", (float)12345, Convert.ToSingle(tryInt32));
1869 AssertEquals("#N08", (float)123456789012, Convert.ToSingle(tryInt64));
1871 AssertEquals("#N09", (float)123, Convert.ToSingle(trySByte));
1873 AssertEquals("#N10", (float)1234,2345, Convert.ToSingle(tryFloat));
1875 AssertEquals("#N11", (float)987, Convert.ToSingle("987"));
1877 AssertEquals("#N12", (float)34567, Convert.ToSingle(tryUI16));
1879 AssertEquals("#N13", (float)567891234, Convert.ToSingle(tryUI32));
1881 AssertEquals("#N14", (float)0, Convert.ToSingle(tryUI64));
1883 AssertEquals("#N15", (float)654.234, Convert.ToSingle("654.234", ci));
1884 } catch (Exception e) {
1885 Fail ("Unexpected exception at iTest = " + iTest + ": e = " + e);
1889 Convert.ToSingle(tryChar);
1892 catch (Exception e) {
1893 AssertEquals("#N25", typeof(InvalidCastException), e.GetType());
1897 Convert.ToSingle(tryDT);
1900 catch (Exception e) {
1901 AssertEquals("#N26", typeof(InvalidCastException), e.GetType());
1905 Convert.ToSingle(tryObj);
1908 catch (Exception e) {
1909 AssertEquals("#N27", typeof(InvalidCastException), e.GetType());
1913 Convert.ToSingle("A345H");
1916 catch (Exception e) {
1917 AssertEquals("#N28", typeof(FormatException), e.GetType());
1921 Convert.ToSingle(double.MaxValue.ToString());
1924 catch (Exception e) {
1925 AssertEquals("#N29", typeof(OverflowException), e.GetType());
1929 Convert.ToSingle(tryObj, ci);
1932 catch (Exception e) {
1933 AssertEquals("#N30", typeof(InvalidCastException), e.GetType());
1937 Convert.ToSingle("J345K", ci);
1940 catch (Exception e) {
1941 AssertEquals("#N31", typeof(FormatException), e.GetType());
1945 Convert.ToSingle("11000000000000000000000000000000000000000000000", ci);
1948 catch (Exception e) {
1949 AssertEquals("#N32", typeof(OverflowException), e.GetType());
1953 public void TestToString() {
1956 AssertEquals("#O01", "False", Convert.ToString(boolFalse));
1957 AssertEquals("#O02", "True", Convert.ToString(boolTrue));
1958 AssertEquals("#O03", "123", Convert.ToString(tryByte));
1959 AssertEquals("#O04", "a", Convert.ToString(tryChar));
1960 AssertEquals("#O05", tryDT.ToString(), Convert.ToString(tryDT));
1961 AssertEquals("#O06", tryDec.ToString(), Convert.ToString(tryDec));
1962 AssertEquals("#O07", tryDbl.ToString(), Convert.ToString(tryDbl));
1963 AssertEquals("#O08", "1234", Convert.ToString(tryInt16));
1964 AssertEquals("#O09", "12345", Convert.ToString(tryInt32));
1965 AssertEquals("#O10", "123456789012", Convert.ToString(tryInt64));
1966 AssertEquals("#O11", "123", Convert.ToString(trySByte));
1967 AssertEquals("#O12", tryFloat.ToString(), Convert.ToString(tryFloat));
1968 AssertEquals("#O13", "foobar", Convert.ToString(tryStr));
1969 AssertEquals("#O14", "34567", Convert.ToString(tryUI16));
1970 AssertEquals("#O15", "567891234", Convert.ToString(tryUI32));
1971 AssertEquals("#O16", "True", Convert.ToString(boolTrue, ci));
1972 AssertEquals("#O17", "False", Convert.ToString(boolFalse, ci));
1973 AssertEquals("#O18", "123", Convert.ToString(tryByte, ci));
1974 AssertEquals("#O19", "1111011", Convert.ToString(tryByte, 2));
1975 AssertEquals("#O20", "173", Convert.ToString(tryByte, 8));
1976 AssertEquals("#O21", "123", Convert.ToString(tryByte, 10));
1977 AssertEquals("#O22", "7b", Convert.ToString(tryByte, 16));
1978 AssertEquals("#O23", "a", Convert.ToString(tryChar, ci));
1979 AssertEquals("#O24", tryDT.ToString(ci), Convert.ToString(tryDT, ci));
1980 AssertEquals("#O25", tryDec.ToString(ci), Convert.ToString(tryDec,ci));
1981 AssertEquals("#O26", tryDbl.ToString(ci), Convert.ToString(tryDbl, ci));
1982 AssertEquals("#O27", "1234", Convert.ToString(tryInt16, ci));
1983 AssertEquals("#O28", "10011010010", Convert.ToString(tryInt16, 2));
1984 AssertEquals("#O29", "2322", Convert.ToString(tryInt16, 8));
1985 AssertEquals("#O30", "1234", Convert.ToString(tryInt16, 10));
1986 AssertEquals("#O31", "4d2", Convert.ToString(tryInt16, 16));
1987 AssertEquals("#O32", "12345", Convert.ToString(tryInt32, ci));
1988 AssertEquals("#O33", "11000000111001", Convert.ToString(tryInt32, 2));
1989 AssertEquals("#O34", "30071", Convert.ToString(tryInt32, 8));
1990 AssertEquals("#O35", "12345", Convert.ToString(tryInt32, 10));
1991 AssertEquals("#O36", "3039", Convert.ToString(tryInt32, 16));
1992 AssertEquals("#O37", "123456789012", Convert.ToString(tryInt64, ci));
1993 AssertEquals("#O38", "1110010111110100110010001101000010100",
1994 Convert.ToString(tryInt64, 2));
1995 AssertEquals("#O39", "1627646215024", Convert.ToString(tryInt64, 8));
1996 AssertEquals("#O40", "123456789012", Convert.ToString(tryInt64, 10));
1997 AssertEquals("#O41", "1cbe991a14", Convert.ToString(tryInt64, 16));
1998 AssertEquals("#O42", "123", Convert.ToString((trySByte), ci));
1999 AssertEquals("#O43", tryFloat.ToString(ci), Convert.ToString((tryFloat), ci));
2000 AssertEquals("#O44", "foobar", Convert.ToString((tryStr), ci));
2001 AssertEquals("#O45", "34567", Convert.ToString((tryUI16), ci));
2002 AssertEquals("#O46", "567891234", Convert.ToString((tryUI32), ci));
2003 AssertEquals("#O47", "0", Convert.ToString(tryUI64));
2004 AssertEquals("#O48", "0", Convert.ToString((tryUI64), ci));
2007 Convert.ToString(tryInt16, 5);
2010 catch (Exception e) {
2011 AssertEquals("#O55", typeof(ArgumentException), e.GetType());
2015 Convert.ToString(tryInt32, 17);
2018 catch (Exception e) {
2019 AssertEquals("#O56", typeof(ArgumentException), e.GetType());
2023 Convert.ToString(tryInt64, 1);
2026 catch (Exception e) {
2027 AssertEquals("#O57", typeof(ArgumentException), e.GetType());
2031 public void TestToUInt16() {
2032 AssertEquals("#P01", (ushort)0, Convert.ToUInt16(boolFalse));
2033 AssertEquals("#P02", (ushort)1, Convert.ToUInt16(boolTrue));
2034 AssertEquals("#P03", (ushort)0, Convert.ToUInt16(tryByte));
2035 AssertEquals("#P04", (ushort)97, Convert.ToUInt16(tryChar));
2036 AssertEquals("#P05", (ushort)1234, Convert.ToUInt16(tryDec));
2037 AssertEquals("#P06", (ushort)0, Convert.ToUInt16(tryDbl));
2038 AssertEquals("#P07", (ushort)1234, Convert.ToUInt16(tryInt16));
2039 AssertEquals("#P08", (ushort)12345, Convert.ToUInt16(tryInt32));
2040 AssertEquals("#P09", (ushort)43752, Convert.ToUInt16((long)43752));
2041 AssertEquals("#P10", (ushort)123, Convert.ToUInt16(trySByte));
2042 AssertEquals("#P11", (ushort)1234, Convert.ToUInt16(tryFloat));
2043 AssertEquals("#P12", (ushort)123, Convert.ToUInt16((string)"123"));
2044 AssertEquals("#P13", (ushort)34567, Convert.ToUInt16(tryUI16));
2045 AssertEquals("#P14", (ushort)56789, Convert.ToUInt16((uint)56789));
2046 AssertEquals("#P15", (ushort)0, Convert.ToUInt16(tryUI64));
2047 AssertEquals("#P16", (ushort)31, Convert.ToUInt16("31", ci));
2048 AssertEquals("#P17", (ushort)14, Convert.ToUInt16("1110", 2));
2049 AssertEquals("#P18", (ushort)32, Convert.ToUInt16("40", 8));
2050 AssertEquals("#P19", (ushort)40, Convert.ToUInt16("40", 10));
2051 AssertEquals("#P20", (ushort)64, Convert.ToUInt16("40", 16));
2055 Convert.ToUInt16(tryDT);
2058 catch (Exception e) {
2059 AssertEquals("#P25", typeof(InvalidCastException), e.GetType());
2063 Convert.ToUInt16(decimal.MaxValue);
2066 catch (Exception e) {
2067 AssertEquals("#P26", typeof(OverflowException), e.GetType());
2071 Convert.ToUInt16(decimal.MinValue);
2074 catch (Exception e) {
2075 AssertEquals("#P27", typeof(OverflowException), e.GetType());
2079 Convert.ToUInt16(double.MaxValue);
2082 catch (Exception e) {
2083 AssertEquals("#P28", typeof(OverflowException), e.GetType());
2087 Convert.ToUInt16(double.MinValue);
2090 catch (Exception e) {
2091 AssertEquals("#P29", typeof(OverflowException), e.GetType());
2095 Convert.ToUInt16(short.MinValue);
2098 catch (Exception e) {
2099 AssertEquals("#P30", typeof(OverflowException), e.GetType());
2103 Convert.ToUInt16(int.MaxValue);
2106 catch (Exception e) {
2107 AssertEquals("#P31", typeof(OverflowException), e.GetType());
2111 Convert.ToUInt16(int.MinValue);
2114 catch (Exception e) {
2115 AssertEquals("#P32", typeof(OverflowException), e.GetType());
2119 Convert.ToUInt16(long.MaxValue);
2122 catch (Exception e) {
2123 AssertEquals("#P33", typeof(OverflowException), e.GetType());
2127 Convert.ToUInt16(long.MinValue);
2130 catch (Exception e) {
2131 AssertEquals("#P34", typeof(OverflowException), e.GetType());
2135 Convert.ToUInt16(tryObj);
2138 catch (Exception e) {
2139 AssertEquals("#P35", typeof(InvalidCastException), e.GetType());
2143 Convert.ToUInt16(sbyte.MinValue);
2146 catch (Exception e) {
2147 AssertEquals("#P36", typeof(OverflowException), e.GetType());
2151 Convert.ToUInt16(float.MaxValue);
2154 catch (Exception e) {
2155 AssertEquals("#P37", typeof(OverflowException), e.GetType());
2159 Convert.ToUInt16(float.MinValue);
2162 catch (Exception e) {
2163 AssertEquals("#P38", typeof(OverflowException), e.GetType());
2167 Convert.ToUInt16("1A2");
2170 catch (Exception e) {
2171 AssertEquals("#P39", typeof(FormatException), e.GetType());
2175 Convert.ToUInt16("-32800");
2178 catch (Exception e) {
2179 AssertEquals("#P40", typeof(OverflowException), e.GetType());
2183 Convert.ToUInt16(int.MaxValue.ToString());
2186 catch (Exception e) {
2187 AssertEquals("#P41", typeof(OverflowException), e.GetType());
2191 Convert.ToUInt16(ulong.MaxValue);
2194 catch (Exception e) {
2195 AssertEquals("#P42", typeof(OverflowException), e.GetType());
2199 Convert.ToUInt16("1A2", ci);
2202 catch (Exception e) {
2203 AssertEquals("#P43", typeof(FormatException), e.GetType());
2207 Convert.ToUInt16("-32800", ci);
2210 catch (Exception e) {
2211 AssertEquals("#P44", typeof(OverflowException), e.GetType());
2215 Convert.ToUInt16("456987", ci);
2218 catch (Exception e) {
2219 AssertEquals("#P45", typeof(OverflowException), e.GetType());
2223 Convert.ToUInt16("40", 9);
2226 catch (Exception e) {
2227 AssertEquals("#P46", typeof(ArgumentException), e.GetType());
2231 Convert.ToUInt16 ("abcde", 16);
2234 catch (Exception e) {
2235 AssertEquals ("#P47", typeof (OverflowException), e.GetType ());
2239 public void TestSignedToInt() {
2240 // String cannot contain a minus sign if the base is not 10.
2241 // But can if it is ten, and + is allowed everywhere.
2242 AssertEquals("Signed0", -1, Convert.ToInt32 ("-1", 10));
2243 AssertEquals("Signed1", 1, Convert.ToInt32 ("+1", 10));
2244 AssertEquals("Signed2", 1, Convert.ToInt32 ("+1", 2));
2245 AssertEquals("Signed3", 1, Convert.ToInt32 ("+1", 8));
2246 AssertEquals("Signed4", 1, Convert.ToInt32 ("+1", 16));
2249 Convert.ToInt32("-1", 2);
2255 Convert.ToInt32("-1", 8);
2261 Convert.ToInt32("-1", 16);
2270 public void TestToUInt32() {
2271 AssertEquals("#Q01", (uint)1, Convert.ToUInt32(boolTrue));
2272 AssertEquals("#Q02", (uint)0, Convert.ToUInt32(boolFalse));
2273 AssertEquals("#Q03", (uint)0, Convert.ToUInt32(tryByte));
2274 AssertEquals("#Q04", (uint)97, Convert.ToUInt32(tryChar));
2275 AssertEquals("#Q05", (uint)1234, Convert.ToUInt32(tryDec));
2276 AssertEquals("#Q06", (uint)0, Convert.ToUInt32(tryDbl));
2277 AssertEquals("#Q07", (uint)1234, Convert.ToUInt32(tryInt16));
2278 AssertEquals("#Q08", (uint)12345, Convert.ToUInt32(tryInt32));
2279 AssertEquals("#Q09", (uint)1234567890, Convert.ToUInt32((long)1234567890));
2280 AssertEquals("#Q10", (uint)123, Convert.ToUInt32(trySByte));
2281 AssertEquals("#Q11", (uint)1234, Convert.ToUInt32(tryFloat));
2282 AssertEquals("#Q12", (uint)3456789, Convert.ToUInt32("3456789"));
2283 AssertEquals("#Q13", (uint)34567, Convert.ToUInt32(tryUI16));
2284 AssertEquals("#Q14", (uint)567891234, Convert.ToUInt32(tryUI32));
2285 AssertEquals("#Q15", (uint)0, Convert.ToUInt32(tryUI64));
2286 AssertEquals("#Q16", (uint)415, Convert.ToUInt32("110011111", 2));
2287 AssertEquals("#Q17", (uint)156, Convert.ToUInt32("234" ,8));
2288 AssertEquals("#Q18", (uint)234, Convert.ToUInt32("234" ,10));
2289 AssertEquals("#Q19", (uint)564, Convert.ToUInt32("234" ,16));
2293 Convert.ToUInt32(tryDT);
2296 catch (Exception e) {
2297 AssertEquals("#Q25", typeof(InvalidCastException), e.GetType());
2301 Convert.ToUInt32(decimal.MaxValue);
2304 catch (Exception e) {
2305 AssertEquals("#Q26", typeof(OverflowException), e.GetType());
2309 Convert.ToUInt32((decimal)-150);
2312 catch (Exception e) {
2313 AssertEquals("#Q27", typeof(OverflowException), e.GetType());
2317 Convert.ToUInt32(double.MaxValue);
2320 catch (Exception e) {
2321 AssertEquals("#Q28", typeof(OverflowException), e.GetType());
2325 Convert.ToUInt32((double)-1);
2328 catch (Exception e) {
2329 AssertEquals("#Q29", typeof(OverflowException), e.GetType());
2333 Convert.ToUInt32(short.MinValue);
2336 catch (Exception e) {
2337 AssertEquals("#Q30", typeof(OverflowException), e.GetType());
2341 Convert.ToUInt32(int.MinValue);
2344 catch (Exception e) {
2345 AssertEquals("#Q31", typeof(OverflowException), e.GetType());
2349 Convert.ToUInt32(long.MaxValue);
2352 catch (Exception e) {
2353 AssertEquals("#Q32", typeof(OverflowException), e.GetType());
2357 Convert.ToUInt32((long)-50000);
2360 catch (Exception e) {
2361 AssertEquals("#Q33", typeof(OverflowException), e.GetType());
2365 Convert.ToUInt32(new Exception());
2368 catch (Exception e) {
2369 AssertEquals("#Q34", typeof(InvalidCastException), e.GetType());
2373 Convert.ToUInt32(sbyte.MinValue);
2376 catch (Exception e) {
2377 AssertEquals("#Q35", typeof(OverflowException), e.GetType());
2381 Convert.ToUInt32(float.MaxValue);
2384 catch (Exception e) {
2385 AssertEquals("#Q36", typeof(OverflowException), e.GetType());
2389 Convert.ToUInt32(float.MinValue);
2392 catch (Exception e) {
2393 AssertEquals("#Q37", typeof(OverflowException), e.GetType());
2397 Convert.ToUInt32("45t54");
2400 catch (Exception e) {
2401 AssertEquals("#Q38", typeof(FormatException), e.GetType());
2405 Convert.ToUInt32("-55");
2408 catch (Exception e) {
2409 AssertEquals("#Q39", typeof(OverflowException), e.GetType());
2413 Convert.ToUInt32(ulong.MaxValue);
2416 catch (Exception e) {
2417 AssertEquals("#Q40", typeof(OverflowException), e.GetType());
2421 Convert.ToUInt32(new Exception(), ci);
2424 catch (Exception e) {
2425 AssertEquals("#Q41", typeof(InvalidCastException), e.GetType());
2429 Convert.ToUInt32(tryStr, ci);
2432 catch (Exception e) {
2433 AssertEquals("#Q42", typeof(FormatException), e.GetType());
2437 Convert.ToUInt32("-50", ci);
2440 catch (Exception e) {
2441 AssertEquals("#Q43", typeof(OverflowException), e.GetType());
2445 Convert.ToUInt32(decimal.MaxValue.ToString(), ci);
2448 catch (Exception e) {
2449 AssertEquals("#Q44", typeof(OverflowException), e.GetType());
2453 Convert.ToUInt32("1001110", 1);
2456 catch (Exception e) {
2457 AssertEquals("#Q45", typeof(ArgumentException), e.GetType());
2461 public void TestToUInt64()
2465 AssertEquals("#R01", (ulong)1, Convert.ToUInt64(boolTrue));
2467 AssertEquals("#R02", (ulong)0, Convert.ToUInt64(boolFalse));
2469 AssertEquals("#R03", (ulong)0, Convert.ToUInt64(tryByte));
2471 AssertEquals("#R04", (ulong)97, Convert.ToUInt64(tryChar));
2473 AssertEquals("#R05", (ulong)1234, Convert.ToUInt64(tryDec));
2475 AssertEquals("#R06", (ulong)0, Convert.ToUInt64(tryDbl));
2477 AssertEquals("#R07", (ulong)1234, Convert.ToUInt64(tryInt16));
2479 AssertEquals("#R08", (ulong)12345, Convert.ToUInt64(tryInt32));
2481 AssertEquals("#R09", (ulong)123456789012, Convert.ToUInt64(tryInt64));
2483 AssertEquals("#R10", (ulong)123, Convert.ToUInt64(trySByte));
2485 AssertEquals("#R11", (ulong)1234, Convert.ToUInt64(tryFloat));
2487 AssertEquals("#R12", (ulong)345678, Convert.ToUInt64("345678"));
2489 AssertEquals("#R13", (ulong)34567, Convert.ToUInt64(tryUI16));
2491 AssertEquals("#R14", (ulong)567891234, Convert.ToUInt64(tryUI32));
2493 AssertEquals("#R15", (ulong)0, Convert.ToUInt64(tryUI64));
2495 AssertEquals("#R16", (ulong)123, Convert.ToUInt64("123", ci));
2497 AssertEquals("#R17", (ulong)4, Convert.ToUInt64("100", 2));
2499 AssertEquals("#R18", (ulong)64, Convert.ToUInt64("100", 8));
2501 AssertEquals("#R19", (ulong)100, Convert.ToUInt64("100", 10));
2503 AssertEquals("#R20", (ulong)256, Convert.ToUInt64("100", 16));
2504 } catch (Exception e) {
2505 Fail ("Unexpected exception caught when iTest = " + iTest + ": e = " + e);
2509 Convert.ToUInt64(tryDT);
2512 catch (Exception e) {
2513 AssertEquals("#R25", typeof(InvalidCastException), e.GetType());
2517 Convert.ToUInt64(decimal.MaxValue);
2520 catch (Exception e) {
2521 AssertEquals("#R26", typeof(OverflowException), e.GetType());
2525 Convert.ToUInt64((decimal)-140);
2528 catch (Exception e) {
2529 AssertEquals("#R27", typeof(OverflowException), e.GetType());
2533 Convert.ToUInt64(double.MaxValue);
2536 catch (Exception e) {
2537 AssertEquals("#R28", typeof(OverflowException), e.GetType());
2541 Convert.ToUInt64((double)-1);
2544 catch (Exception e) {
2545 AssertEquals("#R29", typeof(OverflowException), e.GetType());
2549 Convert.ToUInt64(short.MinValue);
2552 catch (Exception e) {
2553 AssertEquals("#R30", typeof(OverflowException), e.GetType());
2557 Convert.ToUInt64(int.MinValue);
2560 catch (Exception e) {
2561 AssertEquals("#R31", typeof(OverflowException), e.GetType());
2565 Convert.ToUInt64(long.MinValue);
2568 catch (Exception e) {
2569 AssertEquals("#R32", typeof(OverflowException), e.GetType());
2573 Convert.ToUInt64(tryObj);
2576 catch (Exception e) {
2577 AssertEquals("#R33", typeof(InvalidCastException), e.GetType());
2581 Convert.ToUInt64(sbyte.MinValue);
2584 catch (Exception e) {
2585 AssertEquals("#R34", typeof(OverflowException), e.GetType());
2589 Convert.ToUInt64(float.MinValue);
2592 catch (Exception e) {
2593 AssertEquals("#R35", typeof(OverflowException), e.GetType());
2597 Convert.ToUInt64(float.MaxValue);
2600 catch (Exception e) {
2601 AssertEquals("#R36", typeof(OverflowException), e.GetType());
2605 Convert.ToUInt64("234rt78");
2608 catch (Exception e) {
2609 AssertEquals("#R37", typeof(FormatException), e.GetType());
2613 Convert.ToUInt64("-68");
2616 catch (Exception e) {
2617 AssertEquals("#R38", typeof(OverflowException), e.GetType());
2621 Convert.ToUInt64(decimal.MaxValue.ToString());
2624 catch (Exception e) {
2625 AssertEquals("#R39", typeof(OverflowException), e.GetType());
2629 Convert.ToUInt64("23rd2", ci);
2632 catch (Exception e) {
2633 AssertEquals("#R40", typeof(FormatException), e.GetType());
2637 Convert.ToUInt64(decimal.MinValue.ToString(), ci);
2640 catch (Exception e) {
2641 AssertEquals("#R41", typeof(OverflowException), e.GetType());
2645 Convert.ToUInt64(decimal.MaxValue.ToString(), ci);
2648 catch (Exception e) {
2649 AssertEquals("#R42", typeof(OverflowException), e.GetType());
2653 Convert.ToUInt64("132", 9);
2656 catch (Exception e) {
2657 AssertEquals("#R43", typeof(ArgumentException), e.GetType());
2661 AssertEquals ("#L35", (ulong) 256, Convert.ToUInt64 ("0x100", 16));
2662 AssertEquals ("#L36", (ulong) 256, Convert.ToUInt64 ("0X100", 16));
2663 AssertEquals ("#L37", ulong.MaxValue, Convert.ToUInt64 ("0xFFFFFFFFFFFFFFFF", 16));
2667 [ExpectedException (typeof (FormatException))]
2668 public void TestInvalidBase64() {
2669 // This has to be a multiple of 4 characters, otherwise you
2670 // are testing something else. Ideally one will become a byte
2673 // This test is designed to see what happens with invalid bytes
2674 string brokenB64 = "AB~\u00a3";
2675 Convert.FromBase64String(brokenB64);
2679 public void TestBeginWithSpaces ()
2681 byte[] bb = new byte[] { 1, 2, 3};
2682 string s = Convert.ToBase64String (bb);
2683 byte [] b2 = Convert.FromBase64String (" " + s);
2684 Assertion.AssertEquals ("#01", 3, b2.Length);
2685 for (int i = 0; i < 3; i++)
2686 Assertion.AssertEquals ("#0" + (i + 2), bb [i], b2 [i]);
2689 public void TestToBase64CharArray ()
2691 byte[] byteArr = {33, 127, 255, 109, 170, 54};
2693 char[] expectedCharArr = {'I', 'X', '/', '/', 'b', 'a', 'o', '2'};
2694 char[] result = new Char[8];
2696 Convert.ToBase64CharArray(byteArr, 0, byteArr.Length, result, 0);
2698 for (int i = 0; i < expectedCharArr.Length; i++) {
2699 AssertEquals("#S0" + i, expectedCharArr[i], result[i]);
2704 [ExpectedException (typeof(ArgumentNullException))]
2705 public void ToBase64CharArray_InNull ()
2707 byte[] byteArr = {33, 127, 255, 109, 170, 54};
2708 char[] result = new Char[8];
2709 Convert.ToBase64CharArray (null, 0, byteArr.Length, result, 0);
2713 [ExpectedException (typeof(ArgumentNullException))]
2714 public void ToBase64CharArray_OutNull ()
2716 byte[] byteArr = {33, 127, 255, 109, 170, 54};
2717 Convert.ToBase64CharArray (byteArr, 0, byteArr.Length, null, 0);
2721 [ExpectedException (typeof(ArgumentOutOfRangeException))]
2722 public void ToBase64CharArray_OffsetInNegative ()
2724 byte[] byteArr = {33, 127, 255, 109, 170, 54};
2725 char[] result = new Char[8];
2726 Convert.ToBase64CharArray (byteArr, -1, byteArr.Length, result, 0);
2730 [ExpectedException (typeof(ArgumentOutOfRangeException))]
2731 public void ToBase64CharArray_LengthNegative ()
2733 byte[] byteArr = {33, 127, 255, 109, 170, 54};
2734 char[] result = new Char[8];
2735 Convert.ToBase64CharArray (byteArr, 0, -5, result, 0);
2739 [ExpectedException (typeof(ArgumentOutOfRangeException))]
2740 public void ToBase64CharArray_OffsetOutNegative ()
2742 byte[] byteArr = {33, 127, 255, 109, 170, 54};
2743 char[] result = new Char[8];
2744 Convert.ToBase64CharArray (byteArr, 0, byteArr.Length, result, -2);
2748 [ExpectedException (typeof(ArgumentOutOfRangeException))]
2749 public void ToBase64CharArray_TotalIn ()
2751 byte[] byteArr = {33, 127, 255, 109, 170, 54};
2752 char[] result = new Char[8];
2753 Convert.ToBase64CharArray (byteArr, 4, byteArr.Length, result, 0);
2757 [ExpectedException (typeof(ArgumentOutOfRangeException))]
2758 public void ToBase64CharArray_TotalInOverflow ()
2760 byte[] byteArr = {33, 127, 255, 109, 170, 54};
2761 char[] result = new Char[8];
2762 Convert.ToBase64CharArray (byteArr, Int32.MaxValue, byteArr.Length, result, 0);
2766 [ExpectedException (typeof(ArgumentOutOfRangeException))]
2767 public void ToBase64CharArray_TotalOut ()
2769 byte[] byteArr = {33, 127, 255, 109, 170, 54};
2770 char[] result = new Char[8];
2771 Convert.ToBase64CharArray (byteArr, 0, byteArr.Length, result, 2);
2775 [ExpectedException (typeof(ArgumentOutOfRangeException))]
2776 public void ToBase64CharArray_TotalOutOverflow ()
2778 byte[] byteArr = {33, 127, 255, 109, 170, 54};
2779 char[] result = new Char[8];
2780 Convert.ToBase64CharArray (byteArr, 0, byteArr.Length, result, Int32.MaxValue);
2783 public void TestToBase64String() {
2784 byte[] byteArr = {33, 127, 255, 109, 170, 54};
2785 string expectedStr = "IX//bao2";
2789 result1 = Convert.ToBase64String(byteArr);
2790 result2 = Convert.ToBase64String(byteArr, 0, byteArr.Length);
2792 AssertEquals("#T01", expectedStr, result1);
2793 AssertEquals("#T02", expectedStr, result2);
2796 Convert.ToBase64String(null);
2799 catch (Exception e) {
2800 AssertEquals("#T05", typeof(ArgumentNullException), e.GetType());
2804 Convert.ToBase64String(byteArr, -1, byteArr.Length);
2807 catch (Exception e) {
2808 AssertEquals("#T06", typeof(ArgumentOutOfRangeException), e.GetType());
2812 Convert.ToBase64String(byteArr, 0, -10);
2815 catch (Exception e) {
2816 AssertEquals("#T07", typeof(ArgumentOutOfRangeException), e.GetType());
2820 Convert.ToBase64String(byteArr, 4, byteArr.Length);
2823 catch (Exception e) {
2824 AssertEquals("#T08", typeof(ArgumentOutOfRangeException), e.GetType());
2828 /* Have experienced some problems with FromBase64CharArray using mono. Something
2829 * about error in a unicode file.
2831 * However the test seems to run fine using mono in a cygwin environment
2835 [ExpectedException (typeof (ArgumentNullException))]
2836 public void FromBase64CharArray_Null ()
2838 Convert.FromBase64CharArray (null, 1, 5);
2842 [ExpectedException (typeof (FormatException))]
2843 public void FromBase64CharArray_Empty ()
2845 Convert.FromBase64CharArray (new char[0], 0, 0);
2849 [ExpectedException (typeof (FormatException))]
2850 public void FormatBase64CharArray_OnlyWhitespace ()
2852 Convert.FromBase64CharArray (new char[3] {' ',
2857 [ExpectedException (typeof (ArgumentOutOfRangeException))]
2858 public void FromBase64CharArray_OutOfRangeStart ()
2860 Convert.FromBase64CharArray (new char [4], -1, 4);
2864 [ExpectedException (typeof (ArgumentOutOfRangeException))]
2865 public void FromBase64CharArray_OutOfRangeLength ()
2867 Convert.FromBase64CharArray (new char [4], 2, 4);
2871 [ExpectedException (typeof (ArgumentOutOfRangeException))]
2872 public void FromBase64CharArray_Overflow ()
2874 Convert.FromBase64CharArray (new char [4], Int32.MaxValue, 4);
2878 [ExpectedException (typeof (FormatException))]
2879 public void FromBase64CharArray_InvalidLength ()
2881 Convert.FromBase64CharArray (new char [4], 0, 3);
2885 [ExpectedException (typeof (FormatException))]
2886 public void FromBase64CharArray_WideChar ()
2888 char[] c = new char [4] { 'A', 'A', 'A', (char) Char.MaxValue };
2889 Convert.FromBase64CharArray (c, 0, 4);
2893 public void FromBase64CharArray ()
2895 char[] charArr = {'M','o','n','o','m','o','n','o'};
2896 byte[] expectedByteArr = {50, 137, 232, 154, 137, 232};
2898 byte[] fromCharArr = Convert.FromBase64CharArray(charArr, 0, 8);
2900 for (int i = 0; i < fromCharArr.Length; i++){
2901 AssertEquals("#U0" + i, expectedByteArr[i], fromCharArr[i]);
2905 /* Have experienced some problems with FromBase64String using mono. Something about
2906 * error in a unicode file.
2908 * However the test seems to run fine using mono in a cygwin environment
2912 [ExpectedException (typeof (ArgumentNullException))]
2913 public void FromBase64String_Null ()
2915 Convert.FromBase64String (null);
2919 [ExpectedException (typeof (FormatException))]
2920 public void FromBase64String_InvalidLength ()
2922 Convert.FromBase64String ("foo");
2926 [ExpectedException (typeof (FormatException))]
2927 public void FromBase64String_InvalidLength2 ()
2929 Convert.FromBase64String (tryStr);
2933 public void FromBase64String_InvalidLengthBecauseOfIgnoredChars ()
2935 byte[] result = Convert.FromBase64String ("AAAA\t");
2936 AssertEquals ("InvalidLengthBecauseOfIgnoredChars", 3, result.Length);
2939 private const string ignored = "\t\r\n ";
2940 private const string base64data = "AAAAAAAAAAAAAAAAAAAA"; // 15 bytes 0x00
2943 public void FromBase64_IgnoreCharsBefore ()
2945 string s = ignored + base64data;
2946 byte[] data = Convert.FromBase64String (s);
2947 AssertEquals ("String-IgnoreCharsBefore-Ignored", 15, data.Length);
2949 char[] c = s.ToCharArray ();
2950 data = Convert.FromBase64CharArray (c, 0, c.Length);
2951 AssertEquals ("CharArray-IgnoreCharsBefore-Ignored", 15, data.Length);
2955 public void FromBase64_IgnoreCharsInside ()
2957 string s = base64data + ignored + base64data;
2958 byte[] data = Convert.FromBase64String (s);
2959 AssertEquals ("String-IgnoreCharsInside-Ignored", 30, data.Length);
2961 char[] c = s.ToCharArray ();
2962 data = Convert.FromBase64CharArray (c, 0, c.Length);
2963 AssertEquals ("CharArray-IgnoreCharsInside-Ignored", 30, data.Length);
2967 public void FromBase64_IgnoreCharsAfter ()
2969 string s = base64data + ignored;
2970 byte[] data = Convert.FromBase64String (s);
2971 AssertEquals ("String-IgnoreCharsAfter-Ignored", 15, data.Length);
2973 char[] c = s.ToCharArray ();
2974 data = Convert.FromBase64CharArray (c, 0, c.Length);
2975 AssertEquals ("CharArray-IgnoreCharsAfter-Ignored", 15, data.Length);
2979 public void FromBase64_Empty ()
2981 AssertEquals (new byte[0], Convert.FromBase64String (string.Empty));
2986 [ExpectedException (typeof (FormatException))]
2988 public void FromBase64_OnlyWhiteSpace ()
2991 AssertEquals (new byte[0], Convert.FromBase64String (" \r\t"));
2993 Convert.FromBase64String (" \r\t");
2998 [ExpectedException (typeof (FormatException))]
2999 public void FromBase64_InvalidChar ()
3001 Convert.FromBase64String ("amVsb3U=\u0100");
3005 [ExpectedException (typeof (FormatException))]
3006 public void FromBase64_Min ()
3008 Convert.FromBase64String ("amVsb3U= \r \n\u007B");
3012 public void FromBase64_TrailingEqualAndSpaces () // From bug #75840.
3014 string base64 = "\n fdy6S2NLpnT4fMdokUHSHsmpcvo= ";
3015 byte [] bytes = Convert.FromBase64String (base64);
3016 AssertEquals ("#01", 20, bytes.Length);
3017 byte [] target = new byte [] { 0x7D, 0xDC, 0xBA, 0x4B, 0x63, 0x4B, 0xA6, 0x74, 0xF8, 0x7C, 0xC7,
3018 0x68, 0x91, 0x41, 0xD2, 0x1E, 0xC9, 0xA9, 0x72, 0xFA };
3020 for (int i = 0; i < 20; i++) {
3021 if (bytes [i] != target [i])
3022 Fail ("Item #" + i);
3026 public void TestConvertFromNull() {
3028 AssertEquals ("#W1", false, Convert.ToBoolean (null as object));
3029 AssertEquals ("#W2", 0, Convert.ToByte (null as object));
3030 AssertEquals ("#W3", 0, Convert.ToChar (null as object));
3031 AssertEquals ("#W4", new DateTime (1,1,1,0,0,0), Convert.ToDateTime (null as object));
3032 AssertEquals ("#W5", 0, Convert.ToDecimal (null as object));
3033 AssertEquals ("#W6", 0, Convert.ToDouble (null as object));
3034 AssertEquals ("#W7", 0, Convert.ToInt16 (null as object));
3035 AssertEquals ("#W8", 0, Convert.ToInt32 (null as object));
3036 AssertEquals ("#W9", 0, Convert.ToInt64 (null as object));
3037 AssertEquals ("#W10", 0, Convert.ToSByte (null as object));
3038 AssertEquals ("#W11", 0, Convert.ToSingle (null as object));
3039 AssertEquals ("#W12", "", Convert.ToString (null as object));
3040 AssertEquals ("#W13", 0, Convert.ToUInt16 (null as object));
3041 AssertEquals ("#W14", 0, Convert.ToUInt32 (null as object));
3042 AssertEquals ("#W15", 0, Convert.ToUInt64 (null as object));
3043 AssertEquals ("#W16", false, Convert.ToBoolean (null as string));
3044 AssertEquals ("#W17", 0, Convert.ToByte (null as string));
3047 Convert.ToChar (null as string);
3049 } catch (Exception e) {
3050 AssertEquals ("#W18", typeof (ArgumentNullException), e.GetType ());
3053 AssertEquals ("#W19", new DateTime (1,1,1,0,0,0), Convert.ToDateTime (null as string));
3054 AssertEquals ("#W20", 0, Convert.ToDecimal (null as string));
3055 AssertEquals ("#W21", 0, Convert.ToDouble (null as string));
3056 AssertEquals ("#W22", 0, Convert.ToInt16 (null as string));
3057 AssertEquals ("#W23", 0, Convert.ToInt32 (null as string));
3058 AssertEquals ("#W24", 0, Convert.ToInt64 (null as string));
3059 AssertEquals ("#W25", 0, Convert.ToSByte (null as string));
3060 AssertEquals ("#W26", 0, Convert.ToSingle (null as string));
3061 AssertEquals ("#W27", null, Convert.ToString (null as string));
3062 AssertEquals ("#W28", 0, Convert.ToUInt16 (null as string));
3063 AssertEquals ("#W29", 0, Convert.ToUInt32 (null as string));
3064 AssertEquals ("#W30", 0, Convert.ToUInt64 (null as string));
3068 public void ToByte_PrefixedHexStringInBase16 ()
3070 AssertEquals ("0xff", 255, Convert.ToByte ("0xff", 16));
3071 AssertEquals ("0xfF", 255, Convert.ToByte ("0xfF", 16));
3072 AssertEquals ("0xFf", 255, Convert.ToByte ("0xFf", 16));
3073 AssertEquals ("0xFF", 255, Convert.ToByte ("0xFF", 16));
3075 AssertEquals ("0Xff", 255, Convert.ToByte ("0Xff", 16));
3076 AssertEquals ("0XfF", 255, Convert.ToByte ("0XfF", 16));
3077 AssertEquals ("0XFf", 255, Convert.ToByte ("0XFf", 16));
3078 AssertEquals ("0XFF", 255, Convert.ToByte ("0XFF", 16));
3080 AssertEquals ("0x0", Byte.MinValue, Convert.ToByte ("0x0", 16));
3084 [ExpectedException (typeof (OverflowException))]
3085 public void ToByte_NegativeString ()
3087 Convert.ToByte ("-1");
3091 [ExpectedException (typeof (ArgumentException))]
3092 public void ToByte_NegativeStringNonBase10 ()
3094 Convert.ToByte ("-0", 16);
3098 [ExpectedException (typeof (OverflowException))]
3099 public void ToByte_NegativeString_Base10 ()
3101 Convert.ToByte ("-0", 10);
3105 public void ToByte_NegativeZeroString ()
3107 Convert.ToByte ("-0");
3108 Convert.ToByte ("-0", null);
3112 [ExpectedException (typeof (OverflowException))]
3113 public void ToUInt16_NegativeString ()
3115 Convert.ToUInt16 ("-1");
3119 [ExpectedException (typeof (ArgumentException))]
3120 public void ToUInt16_NegativeStringNonBase10 ()
3122 Convert.ToUInt16 ("-0", 16);
3126 [ExpectedException (typeof (OverflowException))]
3127 public void ToUInt16_NegativeString_Base10 ()
3129 Convert.ToUInt16 ("-0", 10);
3133 public void ToUInt16_NegativeZeroString ()
3135 Convert.ToUInt16 ("-0");
3136 Convert.ToUInt16 ("-0", null);
3140 [ExpectedException (typeof (OverflowException))]
3141 public void ToUInt32_NegativeString ()
3143 Convert.ToUInt32 ("-1");
3147 [ExpectedException (typeof (ArgumentException))]
3148 public void ToUInt32_NegativeStringNonBase10 ()
3150 Convert.ToUInt32 ("-0", 16);
3154 [ExpectedException (typeof (OverflowException))]
3155 public void ToUInt32_NegativeString_Base10 ()
3157 Convert.ToUInt32 ("-0", 10);
3161 public void ToUInt32_NegativeZeroString ()
3163 Convert.ToUInt32 ("-0");
3164 Convert.ToUInt32 ("-0", null);
3168 [ExpectedException (typeof (OverflowException))]
3169 public void ToUInt64_NegativeString ()
3171 Convert.ToUInt64 ("-1");
3175 [ExpectedException (typeof (ArgumentException))]
3176 public void ToUInt64_NegativeStringNonBase10 ()
3178 Convert.ToUInt64 ("-0", 16);
3182 [ExpectedException (typeof (OverflowException))]
3183 public void ToUInt64_NegativeString_Base10 ()
3185 Convert.ToUInt64 ("-0", 10);
3189 public void ToUInt64_NegativeZeroString ()
3191 Convert.ToUInt64 ("-0");
3192 Convert.ToUInt64 ("-0", null);
3198 public void ToByte_MaxValue ()
3200 AssertEquals ("ff,16", Byte.MaxValue, Convert.ToByte ("ff", 16));
3201 AssertEquals ("0xFF,16", Byte.MaxValue, Convert.ToByte ("0XFF", 16));
3202 AssertEquals ("255,10", Byte.MaxValue, Convert.ToByte ("255", 10));
3203 AssertEquals ("377,8", Byte.MaxValue, Convert.ToByte ("377", 8));
3204 AssertEquals ("11111111,2", Byte.MaxValue, Convert.ToByte ("11111111", 2));
3208 public void ToByte_MinValue ()
3210 AssertEquals ("0,16", Byte.MinValue, Convert.ToByte ("0", 16));
3211 AssertEquals ("0x0,16", Byte.MinValue, Convert.ToByte ("0x0", 16));
3212 AssertEquals ("0,10", Byte.MinValue, Convert.ToByte ("0", 10));
3213 AssertEquals ("0,8", Byte.MinValue, Convert.ToByte ("0", 8));
3214 AssertEquals ("0,2", Byte.MinValue, Convert.ToByte ("0", 2));
3218 public void ToUInt16_MaxValue ()
3220 AssertEquals ("ffff,16", UInt16.MaxValue, Convert.ToUInt16 ("ffff", 16));
3221 AssertEquals ("0XFFFF,16", UInt16.MaxValue, Convert.ToUInt16 ("0XFFFF", 16));
3222 AssertEquals ("65535,10", UInt16.MaxValue, Convert.ToUInt16 ("65535", 10));
3223 AssertEquals ("177777,8", UInt16.MaxValue, Convert.ToUInt16 ("177777", 8));
3224 AssertEquals ("1111111111111111,2", UInt16.MaxValue, Convert.ToUInt16 ("1111111111111111", 2));
3228 public void ToUInt16_MinValue ()
3230 AssertEquals ("0,16", UInt16.MinValue, Convert.ToUInt16 ("0", 16));
3231 AssertEquals ("0x0,16", UInt16.MinValue, Convert.ToUInt16 ("0x0", 16));
3232 AssertEquals ("0,10", UInt16.MinValue, Convert.ToUInt16 ("0", 10));
3233 AssertEquals ("0,8", UInt16.MinValue, Convert.ToUInt16 ("0", 8));
3234 AssertEquals ("0,2", UInt16.MinValue, Convert.ToUInt16 ("0", 2));
3238 public void ToUInt32_MaxValue ()
3240 AssertEquals ("ffffffff,16", UInt32.MaxValue, Convert.ToUInt32 ("ffffffff", 16));
3241 AssertEquals ("0XFFFFFFFF,16", UInt32.MaxValue, Convert.ToUInt32 ("0XFFFFFFFF", 16));
3242 AssertEquals ("4294967295,10", UInt32.MaxValue, Convert.ToUInt32 ("4294967295", 10));
3243 AssertEquals ("37777777777,8", UInt32.MaxValue, Convert.ToUInt32 ("37777777777", 8));
3244 AssertEquals ("11111111111111111111111111111111,2", UInt32.MaxValue, Convert.ToUInt32 ("11111111111111111111111111111111", 2));
3248 public void ToUInt32_MinValue ()
3250 AssertEquals ("0,16", UInt32.MinValue, Convert.ToUInt32 ("0", 16));
3251 AssertEquals ("0x0,16", UInt32.MinValue, Convert.ToUInt32 ("0x0", 16));
3252 AssertEquals ("0,10", UInt32.MinValue, Convert.ToUInt32 ("0", 10));
3253 AssertEquals ("0,8", UInt32.MinValue, Convert.ToUInt32 ("0", 8));
3254 AssertEquals ("0,2", UInt32.MinValue, Convert.ToUInt32 ("0", 2));
3258 public void ToUInt64_MaxValue ()
3260 AssertEquals ("ffffffffffffffff,16", UInt64.MaxValue, Convert.ToUInt64 ("ffffffffffffffff", 16));
3261 AssertEquals ("0XFFFFFFFFFFFFFFFF,16", UInt64.MaxValue, Convert.ToUInt64 ("0XFFFFFFFFFFFFFFFF", 16));
3262 AssertEquals ("18446744073709551615,10", UInt64.MaxValue, Convert.ToUInt64 ("18446744073709551615", 10));
3263 AssertEquals ("1777777777777777777777,8", UInt64.MaxValue, Convert.ToUInt64 ("1777777777777777777777", 8));
3264 AssertEquals ("1111111111111111111111111111111111111111111111111111111111111111,2", UInt64.MaxValue, Convert.ToUInt64 ("1111111111111111111111111111111111111111111111111111111111111111", 2));
3268 public void ToUInt64_MinValue ()
3270 AssertEquals ("0,16", UInt64.MinValue, Convert.ToUInt64 ("0", 16));
3271 AssertEquals ("0x0,16", UInt64.MinValue, Convert.ToUInt64 ("0x0", 16));
3272 AssertEquals ("0,10", UInt64.MinValue, Convert.ToUInt64 ("0", 10));
3273 AssertEquals ("0,8", UInt64.MinValue, Convert.ToUInt64 ("0", 8));
3274 AssertEquals ("0,2", UInt64.MinValue, Convert.ToUInt64 ("0", 2));
3280 public void ToSByte_MaxValue ()
3282 AssertEquals ("7F,16", SByte.MaxValue, Convert.ToSByte ("7f", 16));
3283 AssertEquals ("0X7F,16", SByte.MaxValue, Convert.ToSByte ("0X7F", 16));
3284 AssertEquals ("127,10", SByte.MaxValue, Convert.ToSByte ("127", 10));
3285 AssertEquals ("177,8", SByte.MaxValue, Convert.ToSByte ("177", 8));
3286 AssertEquals ("1111111,2", SByte.MaxValue, Convert.ToSByte ("1111111", 2));
3290 public void ToSByte_MinValue ()
3292 AssertEquals ("80,16", SByte.MinValue, Convert.ToSByte ("80", 16));
3293 AssertEquals ("-128,10", SByte.MinValue, Convert.ToSByte ("-128", 10));
3294 AssertEquals ("200,8", SByte.MinValue, Convert.ToSByte ("200", 8));
3295 AssertEquals ("10000000,2", SByte.MinValue, Convert.ToSByte ("10000000", 2));
3299 public void ToInt16_MaxValue ()
3301 AssertEquals ("7FFF,16", Int16.MaxValue, Convert.ToInt16 ("7fff", 16));
3302 AssertEquals ("0X7FFF,16", Int16.MaxValue, Convert.ToInt16 ("0X7FFF", 16));
3303 AssertEquals ("32767,10", Int16.MaxValue, Convert.ToInt16 ("32767", 10));
3304 AssertEquals ("77777,8", Int16.MaxValue, Convert.ToInt16 ("77777", 8));
3305 AssertEquals ("111111111111111,2", Int16.MaxValue, Convert.ToInt16 ("111111111111111", 2));
3309 public void ToInt16_MinValue ()
3311 AssertEquals ("8000,16", Int16.MinValue, Convert.ToInt16 ("8000", 16));
3312 AssertEquals ("-32768,10", Int16.MinValue, Convert.ToInt16 ("-32768", 10));
3313 AssertEquals ("100000,8", Int16.MinValue, Convert.ToInt16 ("100000", 8));
3314 AssertEquals ("1000000000000000,2", Int16.MinValue, Convert.ToInt16 ("1000000000000000", 2));
3318 public void ToInt32_MaxValue ()
3320 AssertEquals ("7fffffff,16", Int32.MaxValue, Convert.ToInt32 ("7fffffff", 16));
3321 AssertEquals ("0X7FFFFFFF,16", Int32.MaxValue, Convert.ToInt32 ("0X7FFFFFFF", 16));
3322 AssertEquals ("2147483647,10", Int32.MaxValue, Convert.ToInt32 ("2147483647", 10));
3323 AssertEquals ("17777777777,8", Int32.MaxValue, Convert.ToInt32 ("17777777777", 8));
3324 AssertEquals ("1111111111111111111111111111111,2", Int32.MaxValue, Convert.ToInt32 ("1111111111111111111111111111111", 2));
3328 public void ToInt32_MinValue ()
3330 AssertEquals ("80000000,16", Int32.MinValue, Convert.ToInt32 ("80000000", 16));
3331 AssertEquals ("-2147483648,10", Int32.MinValue, Convert.ToInt32 ("-2147483648", 10));
3332 AssertEquals ("20000000000,8", Int32.MinValue, Convert.ToInt32 ("20000000000", 8));
3333 AssertEquals ("10000000000000000000000000000000,2", Int32.MinValue, Convert.ToInt32 ("10000000000000000000000000000000", 2));
3337 public void ToInt64_MaxValue ()
3339 AssertEquals ("7fffffffffffffff,16", Int64.MaxValue, Convert.ToInt64 ("7fffffffffffffff", 16));
3340 AssertEquals ("0X7FFFFFFFFFFFFFFF,16", Int64.MaxValue, Convert.ToInt64 ("0X7FFFFFFFFFFFFFFF", 16));
3341 AssertEquals ("9223372036854775807,10", Int64.MaxValue, Convert.ToInt64 ("9223372036854775807", 10));
3342 AssertEquals ("777777777777777777777,8", Int64.MaxValue, Convert.ToInt64 ("777777777777777777777", 8));
3343 AssertEquals ("111111111111111111111111111111111111111111111111111111111111111,2", Int64.MaxValue, Convert.ToInt64 ("111111111111111111111111111111111111111111111111111111111111111", 2));
3347 public void ToInt64_MinValue ()
3349 AssertEquals ("8000000000000000,16", Int64.MinValue, Convert.ToInt64 ("8000000000000000", 16));
3350 AssertEquals ("0x8000000000000000,16", Int64.MinValue, Convert.ToInt64 ("0x8000000000000000", 16));
3351 AssertEquals ("-9223372036854775808,10", Int64.MinValue, Convert.ToInt64 ("-9223372036854775808", 10));
3352 AssertEquals ("1000000000000000000000,8", Int64.MinValue, Convert.ToInt64 ("1000000000000000000000", 8));
3353 AssertEquals ("1000000000000000000000000000000000000000000000000000000000000000,2", Int64.MinValue, Convert.ToInt64 ("1000000000000000000000000000000000000000000000000000000000000000", 2));
3359 [ExpectedException (typeof (OverflowException))]
3360 public void ToSByte_OverMaxValue ()
3362 string max_plus1 = "128";
3363 Convert.ToSByte (max_plus1);
3367 [ExpectedException (typeof (OverflowException))]
3368 public void ToSByte_OverMinValue ()
3370 string min_minus1 = "-129";
3371 Convert.ToSByte (min_minus1);
3375 [ExpectedException (typeof (OverflowException))]
3376 public void ToInt16_OverMaxValue ()
3378 string max_plus1 = "32768";
3379 Convert.ToInt16 (max_plus1);
3383 [ExpectedException (typeof (OverflowException))]
3384 public void ToInt16_OverMinValue ()
3386 string min_minus1 = "-32769";
3387 Convert.ToInt16 (min_minus1);
3391 [ExpectedException (typeof (OverflowException))]
3392 public void ToInt32_OverMaxValue ()
3394 string max_plus1 = "2147483648";
3395 Convert.ToInt32 (max_plus1);
3399 [ExpectedException (typeof (OverflowException))]
3400 public void ToInt32_OverMinValue ()
3402 string min_minus1 = "-2147483649";
3403 Convert.ToInt32 (min_minus1);
3407 [ExpectedException (typeof (OverflowException))]
3408 public void ToInt64_OverMaxValue ()
3410 string max_plus1 = "9223372036854775808";
3411 Convert.ToInt64 (max_plus1);
3415 [ExpectedException (typeof (OverflowException))]
3416 public void ToInt64_OverMinValue ()
3418 string min_minus1 = "-9223372036854775809";
3419 Convert.ToInt64 (min_minus1);
3425 [ExpectedException (typeof (OverflowException))]
3426 public void ToByte_OverMaxValue ()
3428 string max_plus1 = "257";
3429 Convert.ToByte (max_plus1);
3433 [ExpectedException (typeof (OverflowException))]
3434 public void ToByte_OverMinValue ()
3436 string min_minus1 = "-1";
3437 Convert.ToByte (min_minus1);
3441 [ExpectedException (typeof (OverflowException))]
3442 public void ToUInt16_OverMaxValue ()
3444 string max_plus1 = "65536";
3445 Convert.ToUInt16 (max_plus1);
3449 [ExpectedException (typeof (OverflowException))]
3450 public void ToUInt16_OverMinValue ()
3452 string min_minus1 = "-1";
3453 Convert.ToUInt16 (min_minus1);
3457 [ExpectedException (typeof (OverflowException))]
3458 public void ToUInt32_OverMaxValue ()
3460 string max_plus1 = "4294967296";
3461 Convert.ToUInt32 (max_plus1);
3465 [ExpectedException (typeof (OverflowException))]
3466 public void ToUInt32_OverMinValue ()
3468 string min_minus1 = "-1";
3469 Convert.ToUInt32 (min_minus1);
3473 [ExpectedException (typeof (OverflowException))]
3474 public void ToUInt64_OverMaxValue ()
3476 string max_plus1 = "18446744073709551616";
3477 Convert.ToUInt64 (max_plus1);
3481 [ExpectedException (typeof (OverflowException))]
3482 public void ToUInt64_OverMinValue ()
3484 string min_minus1 = "-1";
3485 Convert.ToUInt64 (min_minus1);
3489 public void To_NullString ()
3493 AssertEquals ("ToSByte", 0, Convert.ToSByte (s));
3494 AssertEquals ("ToSByte+base", 0, Convert.ToSByte (s, 10));
3495 AssertEquals ("ToInt16", 0, Convert.ToInt16 (s));
3496 AssertEquals ("ToInt16+base", 0, Convert.ToInt16 (s, 10));
3497 AssertEquals ("ToInt32", 0, Convert.ToInt32 (s));
3498 AssertEquals ("ToInt32+base", 0, Convert.ToInt32 (s, 10));
3499 AssertEquals ("ToInt64", 0, Convert.ToInt64 (s));
3500 AssertEquals ("ToInt64+base", 0, Convert.ToInt64 (s, 10));
3502 AssertEquals ("ToByte", 0, Convert.ToByte (s));
3503 AssertEquals ("ToByte+base", 0, Convert.ToByte (s, 10));
3504 AssertEquals ("ToUInt16", 0, Convert.ToUInt16 (s));
3505 AssertEquals ("ToUInt16+base", 0, Convert.ToUInt16 (s, 10));
3506 AssertEquals ("ToUInt32", 0, Convert.ToUInt32 (s));
3507 AssertEquals ("ToUInt32+base", 0, Convert.ToUInt32 (s, 10));
3508 AssertEquals ("ToUInt64", 0, Convert.ToUInt64 (s));
3509 AssertEquals ("ToUInt64+base", 0, Convert.ToUInt64 (s, 10));
3513 public void To_NullObject ()
3517 AssertEquals ("ToSByte", 0, Convert.ToSByte (o));
3518 AssertEquals ("ToInt16", 0, Convert.ToInt16 (o));
3519 AssertEquals ("ToInt32", 0, Convert.ToInt32 (o));
3520 AssertEquals ("ToInt64", 0, Convert.ToInt64 (o));
3522 AssertEquals ("ToByte", 0, Convert.ToByte (o));
3523 AssertEquals ("ToUInt16", 0, Convert.ToUInt16 (o));
3524 AssertEquals ("ToUInt32", 0, Convert.ToUInt32 (o));
3525 AssertEquals ("ToUInt64", 0, Convert.ToUInt64 (o));
3529 public void To_NullObjectFormatProvider ()
3532 IFormatProvider fp = (IFormatProvider) new NumberFormatInfo ();
3534 AssertEquals ("ToSByte", 0, Convert.ToSByte (o, fp));
3535 AssertEquals ("ToInt16", 0, Convert.ToInt16 (o, fp));
3536 AssertEquals ("ToInt32", 0, Convert.ToInt32 (o, fp));
3537 AssertEquals ("ToInt64", 0, Convert.ToInt64 (o, fp));
3539 AssertEquals ("ToByte", 0, Convert.ToByte (o, fp));
3540 AssertEquals ("ToUInt16", 0, Convert.ToUInt16 (o, fp));
3541 AssertEquals ("ToUInt32", 0, Convert.ToUInt32 (o, fp));
3542 AssertEquals ("ToUInt64", 0, Convert.ToUInt64 (o, fp));
3546 [ExpectedException (typeof (ArgumentNullException))]
3547 public void ToSByte_NullStringFormatProvider ()
3550 // SByte is a "special" case ???
3551 Convert.ToSByte (s, new NumberFormatInfo ());
3555 public void To_NullStringFormatProvider ()
3558 IFormatProvider fp = (IFormatProvider) new NumberFormatInfo ();
3561 AssertEquals ("ToInt16", 0, Convert.ToInt16 (s, fp));
3562 AssertEquals ("ToInt32", 0, Convert.ToInt32 (s, fp));
3563 AssertEquals ("ToInt64", 0, Convert.ToInt64 (s, fp));
3565 AssertEquals ("ToByte", 0, Convert.ToByte (s, fp));
3566 AssertEquals ("ToUInt16", 0, Convert.ToUInt16 (s, fp));
3567 AssertEquals ("ToUInt32", 0, Convert.ToUInt32 (s, fp));
3568 AssertEquals ("ToUInt64", 0, Convert.ToUInt64 (s, fp));
3572 [ExpectedException (typeof (InvalidCastException))]
3573 public void ChangeTypeToTypeCodeEmpty ()
3575 Convert.ChangeType (true, TypeCode.Empty);
3579 // 2005/01/10: The docs say this should throw an InvalidCastException,
3580 // however, MS.NET 1.1 throws a NullReferenceException. Assuming docs
3583 [ExpectedException (typeof (InvalidCastException))]
3585 [ExpectedException (typeof (NullReferenceException))]
3587 public void ChangeTypeNullToValuetype ()
3589 Convert.ChangeType (null, typeof (int));
3593 public void ToString_MinMax_WithBase ()
3595 AssertEquals ("Byte.MinValue base 2", "0", Convert.ToString (Byte.MinValue, 2));
3596 AssertEquals ("Byte.MinValue base 8", "0", Convert.ToString (Byte.MinValue, 8));
3597 AssertEquals ("Byte.MinValue base 10", "0", Convert.ToString (Byte.MinValue, 10));
3598 AssertEquals ("Byte.MinValue base 16", "0", Convert.ToString (Byte.MinValue, 16));
3600 AssertEquals ("Byte.MaxValue base 2", "11111111", Convert.ToString (Byte.MaxValue, 2));
3601 AssertEquals ("Byte.MaxValue base 8", "377", Convert.ToString (Byte.MaxValue, 8));
3602 AssertEquals ("Byte.MaxValue base 10", "255", Convert.ToString (Byte.MaxValue, 10));
3603 AssertEquals ("Byte.MaxValue base 16", "ff", Convert.ToString (Byte.MaxValue, 16));
3605 AssertEquals ("Int16.MinValue base 2", "1000000000000000", Convert.ToString (Int16.MinValue, 2));
3606 AssertEquals ("Int16.MinValue base 8", "100000", Convert.ToString (Int16.MinValue, 8));
3607 AssertEquals ("Int16.MinValue base 10", "-32768", Convert.ToString (Int16.MinValue, 10));
3608 AssertEquals ("Int16.MinValue base 16", "8000", Convert.ToString (Int16.MinValue, 16));
3610 AssertEquals ("Int16.MaxValue base 2", "111111111111111", Convert.ToString (Int16.MaxValue, 2));
3611 AssertEquals ("Int16.MaxValue base 8", "77777", Convert.ToString (Int16.MaxValue, 8));
3612 AssertEquals ("Int16.MaxValue base 10", "32767", Convert.ToString (Int16.MaxValue, 10));
3613 AssertEquals ("Int16.MaxValue base 16", "7fff", Convert.ToString (Int16.MaxValue, 16));
3615 AssertEquals ("Int32.MinValue base 2", "10000000000000000000000000000000", Convert.ToString (Int32.MinValue, 2));
3616 AssertEquals ("Int32.MinValue base 8", "20000000000", Convert.ToString (Int32.MinValue, 8));
3617 AssertEquals ("Int32.MinValue base 10", "-2147483648", Convert.ToString (Int32.MinValue, 10));
3618 AssertEquals ("Int32.MinValue base 16", "80000000", Convert.ToString (Int32.MinValue, 16));
3620 AssertEquals ("Int32.MaxValue base 2", "1111111111111111111111111111111", Convert.ToString (Int32.MaxValue, 2));
3621 AssertEquals ("Int32.MaxValue base 8", "17777777777", Convert.ToString (Int32.MaxValue, 8));
3622 AssertEquals ("Int32.MaxValue base 10", "2147483647", Convert.ToString (Int32.MaxValue, 10));
3623 AssertEquals ("Int32.MaxValue base 16", "7fffffff", Convert.ToString (Int32.MaxValue, 16));
3625 AssertEquals ("Int64.MinValue base 2", "1000000000000000000000000000000000000000000000000000000000000000", Convert.ToString (Int64.MinValue, 2));
3626 AssertEquals ("Int64.MinValue base 8", "1000000000000000000000", Convert.ToString (Int64.MinValue, 8));
3627 AssertEquals ("Int64.MinValue base 10", "-9223372036854775808", Convert.ToString (Int64.MinValue, 10));
3628 AssertEquals ("Int64.MinValue base 16", "8000000000000000", Convert.ToString (Int64.MinValue, 16));
3630 AssertEquals ("Int64.MaxValue base 2", "111111111111111111111111111111111111111111111111111111111111111", Convert.ToString (Int64.MaxValue, 2));
3631 AssertEquals ("Int64.MaxValue base 8", "777777777777777777777", Convert.ToString (Int64.MaxValue, 8));
3632 AssertEquals ("Int64.MaxValue base 10", "9223372036854775807", Convert.ToString (Int64.MaxValue, 10));
3633 AssertEquals ("Int64.MaxValue base 16", "7fffffffffffffff", Convert.ToString (Int64.MaxValue, 16));
3637 [ExpectedException (typeof (FormatException))]
3638 public void ToByte_BadHexPrefix1 ()
3640 Convert.ToByte ("#10", 16);
3644 [ExpectedException (typeof (FormatException))]
3645 public void ToByte_BadHexPrefix2 ()
3647 Convert.ToByte ("&H10", 16);
3651 [ExpectedException (typeof (FormatException))]
3652 public void ToByte_BadHexPrefix3 ()
3654 Convert.ToByte ("&h10", 16);
3658 [ExpectedException (typeof (FormatException))]
3659 public void ToInt16_BadHexPrefix1 ()
3661 Convert.ToInt16 ("#10", 16);
3665 [ExpectedException (typeof (FormatException))]
3666 public void ToInt16_BadHexPrefix2 ()
3668 Convert.ToInt16 ("&H10", 16);
3672 [ExpectedException (typeof (FormatException))]
3673 public void ToInt16_BadHexPrefix3 ()
3675 Convert.ToInt16 ("&h10", 16);
3679 [ExpectedException (typeof (FormatException))]
3680 public void ToInt32_BadHexPrefix1 ()
3682 Convert.ToInt32 ("#10", 16);
3686 [ExpectedException (typeof (FormatException))]
3687 public void ToInt32_BadHexPrefix2 ()
3689 Convert.ToInt32 ("&H10", 16);
3693 [ExpectedException (typeof (FormatException))]
3694 public void ToInt32_BadHexPrefix3 ()
3696 Convert.ToInt32 ("&h10", 16);
3700 [ExpectedException (typeof (FormatException))]
3701 public void ToInt64_BadHexPrefix1 ()
3703 Convert.ToInt64 ("#10", 16);
3707 [ExpectedException (typeof (FormatException))]
3708 public void ToInt64_BadHexPrefix2 ()
3710 Convert.ToInt64 ("&H10", 16);
3714 [ExpectedException (typeof (FormatException))]
3715 public void ToInt64_BadHexPrefix3 ()
3717 Convert.ToInt64 ("&h10", 16);
3721 [ExpectedException (typeof (FormatException))]
3722 public void ToSByte_BadHexPrefix1 ()
3724 Convert.ToSByte ("#10", 16);
3728 [ExpectedException (typeof (FormatException))]
3729 public void ToSByte_BadHexPrefix2 ()
3731 Convert.ToSByte ("&H10", 16);
3735 [ExpectedException (typeof (FormatException))]
3736 public void ToSByte_BadHexPrefix3 ()
3738 Convert.ToSByte ("&h10", 16);
3742 [ExpectedException (typeof (FormatException))]
3743 public void ToUInt16_BadHexPrefix1 ()
3745 Convert.ToUInt16 ("#10", 16);
3749 [ExpectedException (typeof (FormatException))]
3750 public void ToUInt16_BadHexPrefix2 ()
3752 Convert.ToUInt16 ("&H10", 16);
3756 [ExpectedException (typeof (FormatException))]
3757 public void ToUInt16_BadHexPrefix3 ()
3759 Convert.ToUInt16 ("&h10", 16);
3763 [ExpectedException (typeof (FormatException))]
3764 public void ToUInt32_BadHexPrefix1 ()
3766 Convert.ToUInt32 ("#10", 16);
3770 [ExpectedException (typeof (FormatException))]
3771 public void ToUInt32_BadHexPrefix2 ()
3773 Convert.ToUInt32 ("&H10", 16);
3777 [ExpectedException (typeof (FormatException))]
3778 public void ToUInt32_BadHexPrefix3 ()
3780 Convert.ToUInt32 ("&h10", 16);
3784 [ExpectedException (typeof (FormatException))]
3785 public void ToUInt64_BadHexPrefix1 ()
3787 Convert.ToUInt64 ("#10", 16);
3791 [ExpectedException (typeof (FormatException))]
3792 public void ToUInt64_BadHexPrefix2 ()
3794 Convert.ToUInt64 ("&H10", 16);
3798 [ExpectedException (typeof (FormatException))]
3799 public void ToUInt64_BadHexPrefix3 ()
3801 Convert.ToUInt64 ("&h10", 16);
3805 public void ToSByte_Base16_MinMax ()
3807 AssertEquals ("80,16", SByte.MinValue, Convert.ToSByte ("80", 16));
3808 AssertEquals ("0x80,16", SByte.MinValue, Convert.ToSByte ("0x80", 16));
3809 AssertEquals ("0X80,16", SByte.MinValue, Convert.ToSByte ("0X80", 16));
3811 AssertEquals ("7f,16", SByte.MaxValue, Convert.ToSByte ("7f", 16));
3812 AssertEquals ("7F,16", SByte.MaxValue, Convert.ToSByte ("7F", 16));
3813 AssertEquals ("0x7f,16", SByte.MaxValue, Convert.ToSByte ("0x7f", 16));
3814 AssertEquals ("0X7F,16", SByte.MaxValue, Convert.ToSByte ("0X7F", 16));
3818 public void ToInt16_Base16_MinMax ()
3820 AssertEquals ("8000,16", short.MinValue, Convert.ToInt16 ("8000", 16));
3821 AssertEquals ("0x8000,16", short.MinValue, Convert.ToInt16 ("0x8000", 16));
3822 AssertEquals ("0X8000,16", short.MinValue, Convert.ToInt16 ("0X8000", 16));
3824 AssertEquals ("7fff,16", short.MaxValue, Convert.ToInt16 ("7fff", 16));
3825 AssertEquals ("7FFF,16", short.MaxValue, Convert.ToInt16 ("7FFF", 16));
3826 AssertEquals ("0x7fff,16", short.MaxValue, Convert.ToInt16 ("0x7fff", 16));
3827 AssertEquals ("0X7FFF,16", short.MaxValue, Convert.ToInt16 ("0X7FFF", 16));
3831 public void ToInt32_Base16_MinMax ()
3833 AssertEquals ("80000000,16", int.MinValue, Convert.ToInt32 ("80000000", 16));
3834 AssertEquals ("0x80000000,16", int.MinValue, Convert.ToInt32 ("0x80000000", 16));
3835 AssertEquals ("0X80000000,16", int.MinValue, Convert.ToInt32 ("0X80000000", 16));
3837 AssertEquals ("7fffffff,16", int.MaxValue, Convert.ToInt32 ("7fffffff", 16));
3838 AssertEquals ("7FFFFFFF,16", int.MaxValue, Convert.ToInt32 ("7FFFFFFF", 16));
3839 AssertEquals ("0x7fffffff,16", int.MaxValue, Convert.ToInt32 ("0x7fffffff", 16));
3840 AssertEquals ("0X7FFFFFFF,16", int.MaxValue, Convert.ToInt32 ("0X7FFFFFFF", 16));
3844 [ExpectedException (typeof (FormatException))]
3845 public void ToByte_Base10_InvalidChars1 ()
3847 Convert.ToByte ("0-1", 10);
3851 [ExpectedException (typeof (FormatException))]
3852 public void ToByte_Base10_InvalidChars2 ()
3854 Convert.ToByte ("FF", 10);
3858 [ExpectedException (typeof (FormatException))]
3859 public void ToInt16_Base10_InvalidChars1 ()
3861 Convert.ToInt16 ("0-1", 10);
3865 [ExpectedException (typeof (FormatException))]
3866 public void ToInt16_Base10_InvalidChars2 ()
3868 Convert.ToInt16 ("FF", 10);
3872 [ExpectedException (typeof (FormatException))]
3873 public void ToInt32_Base10_InvalidChars1 ()
3875 Convert.ToInt32 ("0-1", 10);
3879 [ExpectedException (typeof (FormatException))]
3880 public void ToInt32_Base10_InvalidChars2 ()
3882 Convert.ToInt32 ("FF", 10);
3886 [ExpectedException (typeof (FormatException))]
3887 public void ToInt64_Base10_InvalidChars1 ()
3889 Convert.ToInt64 ("0-1", 10);
3893 [ExpectedException (typeof (FormatException))]
3894 public void ToInt64_Base10_InvalidChars2 ()
3896 Convert.ToInt64 ("FF", 10);
3900 [ExpectedException (typeof (FormatException))]
3901 public void ToSByte_Base10_InvalidChars1 ()
3903 Convert.ToSByte ("0-1", 10);
3907 [ExpectedException (typeof (FormatException))]
3908 public void ToSByte_Base10_InvalidChars2 ()
3910 Convert.ToSByte ("FF", 10);
3914 [ExpectedException (typeof (FormatException))]
3915 public void ToUInt16_Base10_InvalidChars1 ()
3917 Convert.ToUInt16 ("0-1", 10);
3921 [ExpectedException (typeof (FormatException))]
3922 public void ToUInt16_Base10_InvalidChars2 ()
3924 Convert.ToUInt16 ("FF", 10);
3928 [ExpectedException (typeof (FormatException))]
3929 public void ToUInt32_Base10_InvalidChars1 ()
3931 Convert.ToUInt32 ("0-1", 10);
3935 [ExpectedException (typeof (FormatException))]
3936 public void ToUInt32_Base10_InvalidChars2 ()
3938 Convert.ToUInt32 ("FF", 10);
3942 [ExpectedException (typeof (FormatException))]
3943 public void ToUInt64_Base10_InvalidChars1 ()
3945 Convert.ToUInt64 ("0-1", 10);
3949 [ExpectedException (typeof (FormatException))]
3950 public void ToUInt64_Base10_InvalidChars2 ()
3952 Convert.ToUInt64 ("FF", 10);
3956 [ExpectedException (typeof (FormatException))]
3957 public void ToByte_Base16_InvalidChars1 ()
3959 Convert.ToByte ("0-1", 16);
3963 [ExpectedException (typeof (FormatException))]
3964 public void ToByte_Base16_InvalidChars2 ()
3966 Convert.ToByte ("GG", 16);
3970 [ExpectedException (typeof (FormatException))]
3971 public void ToInt16_Base16_InvalidChars1 ()
3973 Convert.ToInt16 ("0-1", 16);
3977 [ExpectedException (typeof (FormatException))]
3978 public void ToInt16_Base16_InvalidChars2 ()
3980 Convert.ToInt16 ("GG", 16);
3984 [ExpectedException (typeof (FormatException))]
3985 public void ToInt32_Base16_InvalidChars1 ()
3987 Convert.ToInt32 ("0-1", 16);
3991 [ExpectedException (typeof (FormatException))]
3992 public void ToInt32_Base16_InvalidChars2 ()
3994 Convert.ToInt32 ("GG", 16);
3998 [ExpectedException (typeof (FormatException))]
3999 public void ToInt64_Base16_InvalidChars1 ()
4001 Convert.ToInt64 ("0-1", 16);
4005 [ExpectedException (typeof (FormatException))]
4006 public void ToInt64_Base16_InvalidChars2 ()
4008 Convert.ToInt64 ("GG", 16);
4012 [ExpectedException (typeof (FormatException))]
4013 public void ToSByte_Base16_InvalidChars1 ()
4015 Convert.ToSByte ("0-1", 16);
4019 [ExpectedException (typeof (FormatException))]
4020 public void ToSByte_Base16_InvalidChars2 ()
4022 Convert.ToSByte ("GG", 16);
4026 [ExpectedException (typeof (FormatException))]
4027 public void ToUInt16_Base16_InvalidChars1 ()
4029 Convert.ToUInt16 ("0-1", 16);
4033 [ExpectedException (typeof (FormatException))]
4034 public void ToUInt16_Base16_InvalidChars2 ()
4036 Convert.ToUInt16 ("GG", 16);
4040 [ExpectedException (typeof (FormatException))]
4041 public void ToUInt32_Base16_InvalidChars1 ()
4043 Convert.ToUInt32 ("0-1", 16);
4047 [ExpectedException (typeof (FormatException))]
4048 public void ToUInt32_Base16_InvalidChars2 ()
4050 Convert.ToUInt32 ("GG", 16);
4054 [ExpectedException (typeof (FormatException))]
4055 public void ToUInt64_Base16_InvalidChars1 ()
4057 Convert.ToUInt64 ("0-1", 16);
4061 [ExpectedException (typeof (FormatException))]
4062 public void ToUInt64_Base16_InvalidChars2 ()
4064 Convert.ToUInt64 ("GG", 16);
4068 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4069 public void ToByte_Base2_Empty ()
4071 Convert.ToByte ("", 2);
4075 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4076 public void ToByte_Base8_Empty ()
4078 Convert.ToByte ("", 8);
4082 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4083 public void ToByte_Base10_Empty ()
4085 Convert.ToByte ("", 10);
4089 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4090 public void ToByte_Base16_Empty ()
4092 Convert.ToByte ("", 16);
4096 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4097 public void ToInt16_Base2_Empty ()
4099 Convert.ToInt16 ("", 2);
4103 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4104 public void ToInt16_Base8_Empty ()
4106 Convert.ToInt16 ("", 8);
4110 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4111 public void ToInt16_Base10_Empty ()
4113 Convert.ToInt16 ("", 10);
4117 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4118 public void ToInt16_Base16_Empty ()
4120 Convert.ToInt16 ("", 16);
4124 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4125 public void ToInt32_Base2_Empty ()
4127 Convert.ToInt32 ("", 2);
4131 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4132 public void ToInt32_Base8_Empty ()
4134 Convert.ToInt32 ("", 8);
4138 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4139 public void ToInt32_Base10_Empty ()
4141 Convert.ToInt32 ("", 10);
4145 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4146 public void ToInt32_Base16_Empty ()
4148 Convert.ToInt32 ("", 16);
4152 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4153 public void ToInt64_Base2_Empty ()
4155 Convert.ToInt64 ("", 2);
4159 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4160 public void ToInt64_Base8_Empty ()
4162 Convert.ToInt64 ("", 8);
4166 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4167 public void ToInt64_Base10_Empty ()
4169 Convert.ToInt64 ("", 10);
4173 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4174 public void ToInt64_Base16_Empty ()
4176 Convert.ToInt64 ("", 16);
4180 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4181 public void ToSByte_Base2_Empty ()
4183 Convert.ToSByte ("", 2);
4187 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4188 public void ToSByte_Base8_Empty ()
4190 Convert.ToSByte ("", 8);
4194 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4195 public void ToSByte_Base10_Empty ()
4197 Convert.ToSByte ("", 10);
4201 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4202 public void ToSByte_Base16_Empty ()
4204 Convert.ToSByte ("", 16);
4208 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4209 public void ToUInt16_Base2_Empty ()
4211 Convert.ToUInt16 ("", 2);
4215 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4216 public void ToUInt16_Base8_Empty ()
4218 Convert.ToUInt16 ("", 8);
4222 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4223 public void ToUInt16_Base10_Empty ()
4225 Convert.ToUInt16 ("", 10);
4229 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4230 public void ToUInt16_Base16_Empty ()
4232 Convert.ToUInt16 ("", 16);
4236 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4237 public void ToUInt32_Base2_Empty ()
4239 Convert.ToUInt32 ("", 2);
4243 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4244 public void ToUInt32_Base8_Empty ()
4246 Convert.ToUInt32 ("", 8);
4250 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4251 public void ToUInt32_Base10_Empty ()
4253 Convert.ToUInt32 ("", 10);
4257 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4258 public void ToUInt32_Base16_Empty ()
4260 Convert.ToUInt32 ("", 16);
4264 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4265 public void ToUInt64_Base2_Empty ()
4267 Convert.ToUInt64 ("", 2);
4271 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4272 public void ToUInt64_Base8_Empty ()
4274 Convert.ToUInt64 ("", 8);
4278 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4279 public void ToUInt64_Base10_Empty ()
4281 Convert.ToUInt64 ("", 10);
4285 [ExpectedException (typeof (ArgumentOutOfRangeException))]
4286 public void ToUInt64_Base16_Empty ()
4288 Convert.ToUInt64 ("", 16);
4292 [ExpectedException (typeof (FormatException))]
4293 public void ToByte_HexPrefixOnly ()
4295 Convert.ToByte ("0x", 16);
4299 [ExpectedException (typeof (FormatException))]
4300 public void ToInt16_HexPrefixOnly ()
4302 Convert.ToInt16 ("0x", 16);
4306 [ExpectedException (typeof (FormatException))]
4307 public void ToInt32_HexPrefixOnly ()
4309 Convert.ToInt32 ("0x", 16);
4313 [ExpectedException (typeof (FormatException))]
4314 public void ToInt64_HexPrefixOnly ()
4316 Convert.ToInt64 ("0x", 16);
4320 [ExpectedException (typeof (FormatException))]
4321 public void ToSByte_HexPrefixOnly ()
4323 Convert.ToSByte ("0x", 16);
4327 [ExpectedException (typeof (FormatException))]
4328 public void ToUInt16_HexPrefixOnly ()
4330 Convert.ToUInt16 ("0x", 16);
4334 [ExpectedException (typeof (FormatException))]
4335 public void ToUInt32_HexPrefixOnly ()
4337 Convert.ToUInt32 ("0x", 16);
4341 [ExpectedException (typeof (FormatException))]
4342 public void ToUInt64_HexPrefixOnly ()
4344 Convert.ToUInt64 ("0x", 16);
4348 [ExpectedException (typeof (ArgumentException))]
4349 public void ToByte_Base2_NegativeSignOnly ()
4351 Convert.ToByte ("-", 2);
4355 [ExpectedException (typeof (ArgumentException))]
4356 public void ToByte_Base8_NegativeSignOnly ()
4358 Convert.ToByte ("-", 8);
4362 [ExpectedException (typeof (OverflowException))]
4363 public void ToByte_Base10_NegativeSignOnly ()
4365 Convert.ToByte ("-", 10);
4369 [ExpectedException (typeof (ArgumentException))]
4370 public void ToByte_Base16_NegativeSignOnly ()
4372 Convert.ToByte ("-", 16);
4376 [ExpectedException (typeof (ArgumentException))]
4377 public void ToInt16_Base2_NegativeSignOnly ()
4379 Convert.ToInt16 ("-", 2);
4383 [ExpectedException (typeof (ArgumentException))]
4384 public void ToInt16_Base8_NegativeSignOnly ()
4386 Convert.ToInt16 ("-", 8);
4390 [ExpectedException (typeof (FormatException))]
4391 public void ToInt16_Base10_NegativeSignOnly ()
4393 Convert.ToInt16 ("-", 10);
4397 [ExpectedException (typeof (ArgumentException))]
4398 public void ToInt16_Base16_NegativeSignOnly ()
4400 Convert.ToInt16 ("-", 16);
4404 [ExpectedException (typeof (ArgumentException))]
4405 public void ToInt32_Base2_NegativeSignOnly ()
4407 Convert.ToInt32 ("-", 2);
4411 [ExpectedException (typeof (ArgumentException))]
4412 public void ToInt32_Base8_NegativeSignOnly ()
4414 Convert.ToInt32 ("-", 8);
4418 [ExpectedException (typeof (FormatException))]
4419 public void ToInt32_Base10_NegativeSignOnly ()
4421 Convert.ToInt32 ("-", 10);
4425 [ExpectedException (typeof (ArgumentException))]
4426 public void ToInt32_Base16_NegativeSignOnly ()
4428 Convert.ToInt32 ("-", 16);
4432 [ExpectedException (typeof (ArgumentException))]
4433 public void ToInt64_Base2_NegativeSignOnly ()
4435 Convert.ToInt64 ("-", 2);
4439 [ExpectedException (typeof (ArgumentException))]
4440 public void ToInt64_Base8_NegativeSignOnly ()
4442 Convert.ToInt64 ("-", 8);
4446 [ExpectedException (typeof (FormatException))]
4447 public void ToInt64_Base10_NegativeSignOnly ()
4449 Convert.ToInt64 ("-", 10);
4453 [ExpectedException (typeof (ArgumentException))]
4454 public void ToInt64_Base16_NegativeSignOnly ()
4456 Convert.ToInt64 ("-", 16);
4460 [ExpectedException (typeof (ArgumentException))]
4461 public void ToSByte_Base2_NegativeSignOnly ()
4463 Convert.ToSByte ("-", 2);
4467 [ExpectedException (typeof (ArgumentException))]
4468 public void ToSByte_Base8_NegativeSignOnly ()
4470 Convert.ToSByte ("-", 8);
4474 [ExpectedException (typeof (FormatException))]
4475 public void ToSByte_Base10_NegativeSignOnly ()
4477 Convert.ToSByte ("-", 10);
4481 [ExpectedException (typeof (ArgumentException))]
4482 public void ToSByte_Base16_NegativeSignOnly ()
4484 Convert.ToSByte ("-", 16);
4488 [ExpectedException (typeof (ArgumentException))]
4489 public void ToUInt16_Base2_NegativeSignOnly ()
4491 Convert.ToUInt16 ("-", 2);
4495 [ExpectedException (typeof (ArgumentException))]
4496 public void ToUInt16_Base8_NegativeSignOnly ()
4498 Convert.ToUInt16 ("-", 8);
4502 [ExpectedException (typeof (OverflowException))]
4503 public void ToUInt16_Base10_NegativeSignOnly ()
4505 Convert.ToUInt16 ("-", 10);
4509 [ExpectedException (typeof (ArgumentException))]
4510 public void ToUInt16_Base16_NegativeSignOnly ()
4512 Convert.ToUInt16 ("-", 16);
4516 [ExpectedException (typeof (ArgumentException))]
4517 public void ToUInt32_Base2_NegativeSignOnly ()
4519 Convert.ToUInt32 ("-", 2);
4523 [ExpectedException (typeof (ArgumentException))]
4524 public void ToUInt32_Base8_NegativeSignOnly ()
4526 Convert.ToUInt32 ("-", 8);
4530 [ExpectedException (typeof (OverflowException))]
4531 public void ToUInt32_Base10_NegativeSignOnly ()
4533 Convert.ToUInt32 ("-", 10);
4537 [ExpectedException (typeof (ArgumentException))]
4538 public void ToUInt32_Base16_NegativeSignOnly ()
4540 Convert.ToUInt32 ("-", 16);
4544 [ExpectedException (typeof (ArgumentException))]
4545 public void ToUInt64_Base2_NegativeSignOnly ()
4547 Convert.ToUInt64 ("-", 2);
4551 [ExpectedException (typeof (ArgumentException))]
4552 public void ToUInt64_Base8_NegativeSignOnly ()
4554 Convert.ToUInt64 ("-", 8);
4558 [ExpectedException (typeof (OverflowException))]
4559 public void ToUInt64_Base10_NegativeSignOnly ()
4561 Convert.ToUInt64 ("-", 10);
4565 [ExpectedException (typeof (ArgumentException))]
4566 public void ToUInt64_Base16_NegativeSignOnly ()
4568 Convert.ToUInt64 ("-", 16);