Merge pull request #900 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / corlib / Test / System / Int64Test.cs
1 // Int64Test.cs - NUnit Test Cases for the System.Int64 struct
2 //
3 // Author: Martin Weindel (martin.weindel@t-online.de)
4 //
5 // (C) Martin Weindel, 2001
6 // 
7 // tests ToString and Parse function with the culture independent 
8 // NumberFormatInfo.InvariantInfo
9
10 using NUnit.Framework;
11 using System;
12 using System.Globalization;
13 using System.Threading;
14
15     /// <summary>
16     /// Tests for System.Int64
17     /// </summary>
18 namespace MonoTests.System
19 {
20
21 [TestFixture]
22 public class Int64Test 
23 {
24         private const Int64 MyInt64_1 = -42;
25         private const Int64 MyInt64_2 = -9223372036854775808;
26         private const Int64 MyInt64_3 = 9223372036854775807;
27         private const string MyString1 = "-42";
28         private const string MyString2 = "-9223372036854775808";
29         private const string MyString3 = "9223372036854775807";
30         private string[] Formats1 = {"c", "d", "e", "f", "g", "n", "p", "x" };
31         private string[] Formats2 = {"c5", "d5", "e5", "f5", "g5", "n5", "p5", "x5" };
32         private string[] Results1 = {"", "-9223372036854775808", "-9.223372e+018", "-9223372036854775808.00",
33                                           "-9223372036854775808", "-9,223,372,036,854,775,808.00", "-922,337,203,685,477,580,800.00 %", "8000000000000000"};
34         private string[] Results2 = {"", "9223372036854775807", "9.22337e+018", "9223372036854775807.00000",
35                                           "9.2234e+18", "9,223,372,036,854,775,807.00000", "922,337,203,685,477,580,700.00000 %", "7fffffffffffffff"};
36         private string[] ResultsNfi1 = {"("+NumberFormatInfo.InvariantInfo.CurrencySymbol+"9,223,372,036,854,775,808.00)", "-9223372036854775808", "-9.223372e+018", "-9223372036854775808.00",
37                                           "-9223372036854775808", "-9,223,372,036,854,775,808.00", "-922,337,203,685,477,580,800.00 %", "8000000000000000"};
38         private string[] ResultsNfi2 = {""+NumberFormatInfo.InvariantInfo.CurrencySymbol+"9,223,372,036,854,775,807.00000", "9223372036854775807", "9.22337e+018", "9223372036854775807.00000",
39                                           "9.2234e+18", "9,223,372,036,854,775,807.00000", "922,337,203,685,477,580,700.00000 %", "7fffffffffffffff"};
40
41         private long[] vals
42         = { 0, Int64.MaxValue, Int64.MinValue,
43               1L, 12L, 123L, 1234L, -123L, 
44               1234567890123456L, 6543210987654321L };
45
46         private const long val1 = -1234567L;
47         private const long val2 = 1234567L;
48         private const string sval1Test1 = "  -1,234,567   ";
49         private const string sval1Test2 = "  -1234567   ";
50         //private const string sval1Test3 = "  -12345,,,,67   "; // interesting: this case works on SDK Beta2, but the specification says nothing about this case
51         private const string sval1Test4 = "  -12345 67   ";
52         private  string sval1Test5 = "  -"+NumberFormatInfo.InvariantInfo.CurrencySymbol+"1,234,567.00 ";
53         private  string sval1Test6 = "("+NumberFormatInfo.InvariantInfo.CurrencySymbol+"1,234,567.00)";
54         private const string sval1Test7 = "-1,234,567.00";
55         private const string sval1UserPercent1 = "-%%%1~2~3~4~5~6~7~0~0;0";
56         private const string sval2UserPercent1 = "%%%1~2~3~4~5~6~7~0~0;0";
57         private const NumberStyles style1 =  NumberStyles.AllowLeadingWhite | NumberStyles.AllowLeadingSign
58                                         | NumberStyles.AllowTrailingWhite | NumberStyles.AllowThousands;
59         private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
60         private NumberFormatInfo NfiUser;
61
62         private CultureInfo old_culture;
63
64         [SetUp]
65         public void SetUp () 
66         {
67                 old_culture = Thread.CurrentThread.CurrentCulture;
68
69                 // Set culture to en-US and don't let the user override.
70                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US", false);
71
72                 int cdd = NumberFormatInfo.CurrentInfo.CurrencyDecimalDigits;
73                 string csym = NumberFormatInfo.CurrentInfo.CurrencySymbol;
74                 string csuffix = (cdd > 0 ? "." : "").PadRight(cdd + (cdd > 0 ? 1 : 0), '0');
75                 
76                 string decimals = new String ('0', NumberFormatInfo.CurrentInfo.NumberDecimalDigits);
77                 string perPattern = new string[] {"n %","n%","%n"} [NumberFormatInfo.CurrentInfo.PercentPositivePattern];
78                 
79                 Results1[0] = "(" + csym + "9,223,372,036,854,775,808" + csuffix + ")";
80                 Results1[3] = "-9223372036854775808." + decimals;
81                 Results1[5] = "-9,223,372,036,854,775,808." + decimals;
82                 Results1[6] = perPattern.Replace ("n","-922,337,203,685,477,580,800.00");
83                 
84                 Results2[0] = csym + "9,223,372,036,854,775,807.00000";
85                 Results2[6] = perPattern.Replace ("n","922,337,203,685,477,580,700.00000");
86                 
87                 NfiUser = new NumberFormatInfo();
88                 NfiUser.CurrencyDecimalDigits = 3;
89                 NfiUser.CurrencyDecimalSeparator = ":";
90                 NfiUser.CurrencyGroupSeparator = "/";
91                 NfiUser.CurrencyGroupSizes = new int[] { 2,1,0 };
92                 NfiUser.CurrencyNegativePattern = 10;  // n $-
93                 NfiUser.CurrencyPositivePattern = 3;  // n $
94                 NfiUser.CurrencySymbol = "XYZ";
95                 NfiUser.PercentDecimalDigits = 1;
96                 NfiUser.PercentDecimalSeparator = ";";
97                 NfiUser.PercentGroupSeparator = "~";
98                 NfiUser.PercentGroupSizes = new int[] {1};
99                 NfiUser.PercentNegativePattern = 2;
100                 NfiUser.PercentPositivePattern = 2;
101                 NfiUser.PercentSymbol = "%%%";
102         }
103
104         [TearDown]
105         public void TearDown ()
106         {
107                 Thread.CurrentThread.CurrentCulture = old_culture;
108         }
109
110         [Test]
111         public void TestMinMax()
112         {
113                 
114                 Assert.AreEqual(Int64.MinValue, MyInt64_2);
115                 Assert.AreEqual(Int64.MaxValue, MyInt64_3);
116         }
117
118         [Test]  
119         public void TestCompareTo()
120         {
121                 Assert.IsTrue(MyInt64_3.CompareTo(MyInt64_2) > 0);
122                 Assert.IsTrue(MyInt64_2.CompareTo(MyInt64_2) == 0);
123                 Assert.IsTrue(MyInt64_1.CompareTo((object)(Int64)(-42)) == 0);
124                 Assert.IsTrue(MyInt64_2.CompareTo(MyInt64_3) < 0);
125                 try {
126                         MyInt64_2.CompareTo((object)(Int16)100);
127                         Assert.Fail("Should raise a System.ArgumentException");
128                 }
129                 catch (Exception e) {
130                         Assert.IsTrue(typeof(ArgumentException) == e.GetType());
131                 }
132         }
133
134         [Test]
135         public void TestEquals()
136         {
137                 Assert.IsTrue(MyInt64_1.Equals(MyInt64_1));
138                 Assert.IsTrue(MyInt64_1.Equals((object)(Int64)(-42)));
139                 Assert.IsTrue(MyInt64_1.Equals((object)(SByte)(-42)) == false);
140                 Assert.IsTrue(MyInt64_1.Equals(MyInt64_2) == false);
141         }
142
143         [Test]  
144         public void TestGetHashCode()
145         {
146                 try {
147                         MyInt64_1.GetHashCode();
148                         MyInt64_2.GetHashCode();
149                         MyInt64_3.GetHashCode();
150                 }
151                 catch {
152                         Assert.Fail("GetHashCode should not raise an exception here");
153                 }
154         }
155
156         [Test]  
157     public void TestRoundTripGeneral() 
158     {
159         foreach(long lv in vals) 
160         {
161             string s = lv.ToString(Nfi);
162             long lv2 = Int64.Parse(s);
163             Assert.IsTrue(lv == lv2);
164             long lv3 = Int64.Parse(s, NumberStyles.Integer, Nfi);
165             Assert.IsTrue(lv == lv3);
166         }
167     }
168
169         [Test]
170     public void TestRoundTripHex() 
171     {
172         foreach(long lv in vals) 
173         {
174             string s = lv.ToString("x", Nfi);
175             long lv2 = Int64.Parse(s, NumberStyles.HexNumber, Nfi);
176             Assert.IsTrue(lv == lv2);
177         }
178     }
179
180         [Test]
181     public void TestParseNull()
182     {
183         try 
184         {
185             Int64.Parse(null);
186             Assert.Fail("Should raise System.ArgumentNullException"); 
187         } 
188         catch (ArgumentNullException) 
189         {
190             // ok
191         }
192     }
193
194         [Test]
195     public void TestParse()
196     {
197         long lv;
198
199         lv = Int64.Parse(sval1Test1, style1, Nfi);
200         Assert.AreEqual(val1, lv, "Long value should be equal for Test1");
201
202         try
203         {
204             lv = Int64.Parse(sval1Test1, Nfi);
205             Assert.Fail("Should raise FormatException 1");
206         }
207         catch (FormatException)
208         {
209             // ok
210         }
211
212         lv = Int64.Parse(sval1Test2, style1, Nfi);
213         Assert.AreEqual(val1, lv, "Value should be the same for Test2 with style1");
214         lv = Int64.Parse(sval1Test2, Nfi);
215         Assert.AreEqual(val1, lv, "Value should be the same for Test2 without style1");
216
217         try
218         {
219             lv = Int64.Parse(sval1Test4, style1, Nfi);
220             Assert.Fail("Should raise FormatException 3");
221         }
222         catch (FormatException)
223         {
224             // ok
225         }
226
227         lv = Int64.Parse(sval1Test5, NumberStyles.Currency, Nfi);
228         Assert.AreEqual(val1, lv, "Value should be the same for Test5 and currency style");
229
230         //test Parse(string s)
231         Assert.IsTrue(MyInt64_1 == Int64.Parse(MyString1));
232         Assert.IsTrue(MyInt64_2 == Int64.Parse(MyString2));
233         Assert.IsTrue(MyInt64_3 == Int64.Parse(MyString3));
234         try {
235                 Int64.Parse(null);
236                 Assert.Fail("#1:Should raise a System.ArgumentNullException");
237         }
238         catch (Exception e) {
239                 Assert.IsTrue(typeof(ArgumentNullException) == e.GetType(), "#2");
240         }
241         try {
242                 Int64.Parse("not-a-number");
243                 Assert.Fail("#3:Should raise a System.FormatException");
244         }
245         catch (Exception e) {
246                 Assert.IsTrue(typeof(FormatException) == e.GetType(), "#4");
247         }
248         //test Parse(string s, NumberStyles style)
249         try {
250                 double OverInt = (double)Int64.MaxValue + 1;
251                 Int64.Parse(OverInt.ToString(), NumberStyles.Float);
252                 Assert.Fail("#5:Should raise a System.OverflowException");
253         }
254         catch (Exception e) {
255                 Assert.IsTrue(typeof(OverflowException) == e.GetType(), "#6");
256         }
257         try {
258                 Int64.Parse("10000000000000000", NumberStyles.HexNumber);
259                 Assert.Fail("#7:Should raise a System.OverflowException");
260         }
261         catch (Exception e) {
262                 Assert.IsTrue(typeof(OverflowException) == e.GetType(), "#8");
263         }
264         try {
265                 double OverInt = (double)Int64.MaxValue + 1;
266                 Int64.Parse(OverInt.ToString(), NumberStyles.Integer);
267                 Assert.Fail("#9:Should raise a System.FormatException");
268         }
269         catch (Exception e) {
270                 Assert.IsTrue(typeof(FormatException) == e.GetType(), "#10");
271         }
272         Assert.AreEqual((long)42, Int64.Parse(" "+NumberFormatInfo.CurrentInfo.CurrencySymbol+"42 ", NumberStyles.Currency), "A1");
273         try {
274                 Int64.Parse(NumberFormatInfo.CurrentInfo.CurrencySymbol+"42", NumberStyles.Integer);
275                 Assert.Fail("#11:Should raise a System.FormatException");
276         }
277         catch (Exception e) {
278                 Assert.IsTrue(typeof(FormatException) == e.GetType(), "#12");
279         }
280         //test Parse(string s, IFormatProvider provider)
281         Assert.IsTrue(-42 == Int64.Parse(" -42 ", Nfi), "A2");
282         try {
283                 Int64.Parse("%42", Nfi);
284                 Assert.Fail("#13:Should raise a System.FormatException");
285         }
286         catch (Exception e) {
287                 Assert.IsTrue(typeof(FormatException) == e.GetType(), "#14");
288         }
289         //test Parse(string s, NumberStyles style, IFormatProvider provider)
290         Assert.IsTrue(16 == Int64.Parse(" 10 ", NumberStyles.HexNumber, Nfi), "A3");
291         try {
292                 Int64.Parse(NumberFormatInfo.CurrentInfo.CurrencySymbol+"42", NumberStyles.Integer, Nfi);
293                 Assert.Fail("#15:Should raise a System.FormatException");
294         }
295         catch (Exception e) {
296                 Assert.IsTrue(typeof(FormatException) == e.GetType(), "#16");
297         }
298         try {
299                 long.Parse ("9223372036854775808");
300                 Assert.Fail ("#17:should raise an OverflowException");
301         } catch (Exception e) {
302                 Assert.IsTrue(typeof(OverflowException) == e.GetType(), "#18");
303         }
304         try {
305                 long.Parse ("9223372036854775808", CultureInfo.InvariantCulture);
306                 Assert.Fail ("#19:should raise an OverflowException");
307         } catch (Exception e) {
308                 Assert.IsTrue(typeof(OverflowException) == e.GetType(), "#20");
309         }
310
311                 try {
312                         Int64.Parse ("5", NumberStyles.Any, CultureInfo.InvariantCulture);
313                         Assert.Fail ("C#42");
314                 } catch (FormatException) {
315                 }
316
317         // Pass a DateTimeFormatInfo, it is unable to format
318         // numbers, but we should not crash
319         
320         Int64.Parse ("123", new DateTimeFormatInfo ());
321         
322         Assert.AreEqual (734561, Int64.Parse ("734561\0"), "#21");
323         Assert.AreEqual (734561, Int64.Parse ("734561\0\0\0    \0"), "#22");
324         Assert.AreEqual (734561, Int64.Parse ("734561\0\0\0    "), "#23");
325         Assert.AreEqual (734561, Int64.Parse ("734561\0\0\0"), "#24");
326
327         Assert.AreEqual (0, Int64.Parse ("0+", NumberStyles.Any), "#30");
328     }
329
330         [Test]
331         public void TestParseExponent ()
332         {
333                 Assert.AreEqual (2, long.Parse ("2E0", NumberStyles.AllowExponent), "A#1");
334                 Assert.AreEqual (20, long.Parse ("2E1", NumberStyles.AllowExponent), "A#2");
335                 Assert.AreEqual (200, long.Parse ("2E2", NumberStyles.AllowExponent), "A#3");
336                 Assert.AreEqual (2000000, long.Parse ("2E6", NumberStyles.AllowExponent), "A#4");
337                 Assert.AreEqual (200, long.Parse ("2E+2", NumberStyles.AllowExponent), "A#5");
338                 Assert.AreEqual (2, long.Parse ("2", NumberStyles.AllowExponent), "A#6");
339                 Assert.AreEqual (21, long.Parse ("2.1E1", NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent), "A#7");
340                 Assert.AreEqual (520, long.Parse (".52E3", NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent), "A#8");
341                 Assert.AreEqual (32500000, long.Parse ("32.5E6", NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent), "A#9");
342                 Assert.AreEqual (890, long.Parse ("8.9000E2", NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent), "A#10");            
343
344                 try {
345                         long.Parse ("2E");
346                         Assert.Fail ("B#1");
347                 } catch (FormatException) {
348                 }
349
350                 try {
351                         long.Parse ("2E3.0", NumberStyles.AllowExponent); // decimal notation for the exponent
352                         Assert.Fail ("B#2");
353                 } catch (FormatException) {
354                 }
355
356                 try {
357                         long.Parse ("2E 2", NumberStyles.AllowExponent);
358                         Assert.Fail ("B#3");
359                 } catch (FormatException) {
360                 }
361
362                 try {
363                         long.Parse ("2E2 ", NumberStyles.AllowExponent);
364                         Assert.Fail ("B#4");
365                 } catch (FormatException) {
366                 }
367
368                 try {
369                         long.Parse ("2E66", NumberStyles.AllowExponent); // final result overflow
370                         Assert.Fail ("B#5");
371                 } catch (OverflowException) {
372                 }
373
374                 try {
375                         long exponent = (long) Int32.MaxValue + 10;
376                         long.Parse ("2E" + exponent.ToString (), NumberStyles.AllowExponent);
377                         Assert.Fail ("B#6");
378                 } catch (OverflowException) {
379                 }
380
381                 try {
382                         long.Parse ("2E-1", NumberStyles.AllowExponent); // negative exponent
383                         Assert.Fail ("B#7");
384                 } catch (OverflowException) {
385                 }
386                 
387                 try {
388                         long.Parse ("2 math e1", NumberStyles.AllowExponent);
389                         Assert.Fail ("B#8");
390                 } catch (FormatException) {
391                 }
392
393                 try {
394                         long.Parse ("2.09E1",  NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent);
395                         Assert.Fail ("B#9");
396                 } catch (OverflowException) {
397                 }
398         }
399
400         [Test]
401         public void TestTryParse()
402         {
403                 long result;
404
405                 Assert.AreEqual (true, long.TryParse (MyString1, out result));
406                 Assert.AreEqual (MyInt64_1, result);
407                 Assert.AreEqual (true, long.TryParse (MyString2, out result));
408                 Assert.AreEqual (MyInt64_2, result);
409                 Assert.AreEqual (true, long.TryParse (MyString3, out result));
410                 Assert.AreEqual (MyInt64_3, result);
411
412                 Assert.AreEqual (true, long.TryParse ("1", out result));
413                 Assert.AreEqual (1, result);
414                 Assert.AreEqual (true, long.TryParse (" 1", out result));
415                 Assert.AreEqual (1, result);
416                 Assert.AreEqual (true, long.TryParse ("     1", out result));
417                 Assert.AreEqual (1, result);
418                 Assert.AreEqual (true, long.TryParse ("1    ", out result));
419                 Assert.AreEqual (1, result);
420                 Assert.AreEqual (true, long.TryParse ("+1", out result));
421                 Assert.AreEqual (1, result);
422                 Assert.AreEqual (true, long.TryParse ("-1", out result));
423                 Assert.AreEqual (-1, result);
424                 Assert.AreEqual (true, long.TryParse ("  -1", out result));
425                 Assert.AreEqual (-1, result);
426                 Assert.AreEqual (true, long.TryParse ("  -1  ", out result));
427                 Assert.AreEqual (-1, result);
428                 Assert.AreEqual (true, long.TryParse ("  -1  ", out result));
429                 Assert.AreEqual (-1, result);
430
431                 result = 1;
432                 Assert.AreEqual (false, long.TryParse (null, out result));
433                 Assert.AreEqual (0, result);
434
435                 Assert.AreEqual (false, long.TryParse ("not-a-number", out result));
436
437                 double OverInt = (double)long.MaxValue + 1;
438                 Assert.AreEqual (false, long.TryParse (OverInt.ToString (), out result));
439                 Assert.AreEqual (false, long.TryParse (OverInt.ToString (), NumberStyles.None, CultureInfo.InvariantCulture, out result));
440
441                 Assert.AreEqual (false, long.TryParse ("$42", NumberStyles.Integer, null, out result));
442                 Assert.AreEqual (false, long.TryParse ("%42", NumberStyles.Integer, Nfi, out result));
443                 Assert.AreEqual (false, long.TryParse ("$42", NumberStyles.Integer, Nfi, out result));
444                 Assert.AreEqual (false, long.TryParse (" - 1 ", out result));
445                 Assert.AreEqual (false, long.TryParse (" - ", out result));
446                 Assert.AreEqual (true, long.TryParse ("100000000", NumberStyles.HexNumber, Nfi, out result));
447                 Assert.AreEqual (true, long.TryParse ("10000000000", out result));
448                 Assert.AreEqual (true, long.TryParse ("-10000000000", out result));
449                 Assert.AreEqual (true, long.TryParse ("7fffffff", NumberStyles.HexNumber, Nfi, out result));
450                 Assert.AreEqual (int.MaxValue, result);
451                 Assert.AreEqual (true, long.TryParse ("80000000", NumberStyles.HexNumber, Nfi, out result));
452                 Assert.AreEqual (2147483648, result);
453                 Assert.AreEqual (true, long.TryParse ("ffffffff", NumberStyles.HexNumber, Nfi, out result));
454                 Assert.AreEqual (uint.MaxValue, result);
455                 Assert.AreEqual (true, long.TryParse ("100000000", NumberStyles.HexNumber, Nfi, out result));
456                 Assert.IsFalse (long.TryParse ("-", NumberStyles.AllowLeadingSign, Nfi, out result));
457                 Assert.IsFalse (long.TryParse (Nfi.CurrencySymbol + "-", NumberStyles.AllowLeadingSign | NumberStyles.AllowCurrencySymbol, Nfi, out result));
458         }       
459
460         [Test]
461     public void TestToString() 
462     {
463         string s;
464
465         s = val1.ToString("c", Nfi);
466         Assert.IsTrue(s.Equals(sval1Test6), "val1 does not become sval1Test6");
467
468         s = val1.ToString("n", Nfi);
469         Assert.AreEqual(sval1Test7, s, "val1 does not become sval1Test7");
470
471         //test ToString()
472         Assert.AreEqual(MyString1, MyInt64_1.ToString(), "MyInt64_1.ToString()");
473         Assert.AreEqual(MyString2, MyInt64_2.ToString(), "MyInt64_2.ToString()");
474         Assert.AreEqual(MyString3, MyInt64_3.ToString(), "MyInt64_3.ToString()");
475         //test ToString(string format)
476         for (int i=0; i < Formats1.Length; i++) {
477                 Assert.AreEqual(Results1[i], MyInt64_2.ToString(Formats1[i]), "MyInt64_2.ToString(Formats1["+i+"])");
478                 Assert.AreEqual(Results2[i], MyInt64_3.ToString(Formats2[i]), "MyInt64_3.ToString(Formats2["+i+"])");
479         }
480         //test ToString(string format, IFormatProvider provider);
481         for (int i=0; i < Formats1.Length; i++) {
482                 Assert.AreEqual(ResultsNfi1[i], MyInt64_2.ToString(Formats1[i], Nfi), "MyInt64_2.ToString(Formats1["+i+"], Nfi)");
483                 Assert.AreEqual(ResultsNfi2[i], MyInt64_3.ToString(Formats2[i], Nfi), "MyInt64_3.ToString(Formats2["+i+"], Nfi)");
484         }
485         try {
486                 MyInt64_1.ToString("z");
487                 Assert.Fail("Should raise a System.FormatException");
488         }
489         catch (Exception e) {
490                 Assert.AreEqual(typeof(FormatException), e.GetType(), "Exception is wrong type");
491         }
492     }
493
494         [Test]
495         public void TestUserCurrency ()
496         {
497                 string s = "";
498                 long v;
499                 s = val1.ToString ("c", NfiUser);
500                 Assert.AreEqual ("1234/5/67:000 XYZ-", s, "Currency value type 1 is not what we want to try to parse");
501                 v = Int64.Parse ("1234/5/67:000   XYZ-", NumberStyles.Currency, NfiUser);
502                 Assert.AreEqual (val1, v);
503
504                 s = val2.ToString ("c", NfiUser);
505                 Assert.AreEqual ("1234/5/67:000 XYZ", s, "Currency value type 2 is not what we want to try to parse");
506                 v = Int64.Parse (s, NumberStyles.Currency, NfiUser);
507                 Assert.AreEqual (val2, v);
508         }
509
510         [Test]
511     public void TestUserPercent()
512     {
513         string s;
514
515         s = val1.ToString("p", NfiUser);
516         Assert.IsTrue(s.Equals(sval1UserPercent1));
517
518         s = val2.ToString("p", NfiUser);
519         Assert.IsTrue(s.Equals(sval2UserPercent1));
520     }
521
522                 [Test]
523                 public void Parse_MaxValue ()
524                 {
525                         Assert.AreEqual (Int64.MaxValue, Int64.Parse ("9223372036854775807"), "9223372036854775807");
526                 }
527
528                 [Test]
529                 public void Parse_MinValue ()
530                 {
531                         Assert.AreEqual (Int64.MinValue, Int64.Parse ("-9223372036854775808"), "-9223372036854775808,10");
532                 }
533
534                 [Test]
535                 [ExpectedException (typeof (OverflowException))]
536                 public void Parse_OverByOneMaxValue ()
537                 {
538                         Int64.Parse ("9223372036854775808");
539                 }
540
541                 [Test]
542                 [ExpectedException (typeof (OverflowException))]
543                 public void Parse_WayOverMaxValue ()
544                 {
545                         Int64.Parse ("1" + Int64.MaxValue.ToString ());
546                 }
547
548                 [Test]
549                 [ExpectedException (typeof (OverflowException))]
550                 public void Parse_OverByOneMinValue ()
551                 {
552                         Int64.Parse ("-9223372036854775809");
553                 }
554
555                 [Test]
556                 [ExpectedException (typeof (OverflowException))]
557                 public void Parse_WayOverMinValue ()
558                 {
559                         Int64.Parse (Int64.MinValue.ToString () + "1");
560                 }
561
562                 [Test]
563                 public void ToString_Defaults () 
564                 {
565                         Int64 i = 254;
566                         // everything defaults to "G"
567                         string def = i.ToString ("G");
568                         Assert.AreEqual (def, i.ToString (), "ToString()");
569                         Assert.AreEqual (def, i.ToString ((IFormatProvider)null), "ToString((IFormatProvider)null)");
570                         Assert.AreEqual (def, i.ToString ((string)null), "ToString((string)null)");
571                         Assert.AreEqual (def, i.ToString (String.Empty), "ToString(empty)");
572                         Assert.AreEqual (def, i.ToString (null, null), "ToString(null,null)");
573                         Assert.AreEqual (def, i.ToString (String.Empty, null), "ToString(empty,null)");
574
575                         Assert.AreEqual ("254", def, "ToString(G)");
576                 }
577         }
578 }