Merge pull request #901 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / corlib / Test / System / Int32Test.cs
1 // Int32Test.cs - NUnit Test Cases for the System.Int32 struct
2 //
3 // Mario Martinez (mariom925@home.om)
4 //
5 // (C) Ximian, Inc.  http://www.ximian.com
6 // 
7
8 using NUnit.Framework;
9 using System;
10 using System.Threading;
11 using System.Globalization;
12
13 namespace MonoTests.System
14 {
15
16 [TestFixture]
17 public class Int32Test 
18 {
19         private const Int32 MyInt32_1 = -42;
20         private const Int32 MyInt32_2 = -2147483648;
21         private const Int32 MyInt32_3 = 2147483647;
22         private const string MyString1 = "-42";
23         private const string MyString2 = "-2147483648";
24         private const string MyString3 = "2147483647";
25         private string[] Formats1 = {"c", "d", "e", "f", "g", "n", "p", "x" };
26         private string[] Formats2 = {"c5", "d5", "e5", "f5", "g5", "n5", "p5", "x5" };
27         private string[] Results1 = {null,
28                                         "-2147483648", "-2.147484e+009", "-2147483648.00",
29                                         "-2147483648", "-2,147,483,648.00", "-214,748,364,800.00 %", "80000000"};
30         private string[] Results2 = {null,
31                                         "2147483647", "2.14748e+009", "2147483647.00000",
32                                         "2.1475e+09", "2,147,483,647.00000", "214,748,364,700.00000 %", "7fffffff"};
33         private string[] ResultsNfi1 = {"("+NumberFormatInfo.InvariantInfo.CurrencySymbol+"2,147,483,648.00)",
34                                         "-2147483648", "-2.147484e+009", "-2147483648.00",
35                                         "-2147483648", "-2,147,483,648.00", "-214,748,364,800.00 %", "80000000"};
36         private string[] ResultsNfi2 = {NumberFormatInfo.InvariantInfo.CurrencySymbol+"2,147,483,647.00000",
37                                         "2147483647", "2.14748e+009", "2147483647.00000",
38                                         "2.1475e+09", "2,147,483,647.00000", "214,748,364,700.00000 %", "7fffffff"};
39         private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
40         private NumberFormatInfo NfiUser;
41         
42         private CultureInfo old_culture;
43
44         [TestFixtureSetUp]
45         public void SetUpFixture() 
46         {
47                 old_culture = Thread.CurrentThread.CurrentCulture;
48
49                 // Set culture to en-US and don't let the user override.
50                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US", false);
51
52                 // We can't initialize this until we set the culture.
53                 
54                 string decimals = new String ('0', NumberFormatInfo.CurrentInfo.NumberDecimalDigits);
55                 string perPattern = new string[] {"n %","n%","%n"} [NumberFormatInfo.CurrentInfo.PercentPositivePattern];
56                 
57                 Results1 [0] = "("+NumberFormatInfo.CurrentInfo.CurrencySymbol+"2,147,483,648.00)";
58                 Results1 [3] = "-2147483648." + decimals;
59                 Results1 [5] = "-2,147,483,648." + decimals;
60                 Results1 [6] = perPattern.Replace ("n","-214,748,364,800.00");
61                 
62                 Results2 [0] = NumberFormatInfo.CurrentInfo.CurrencySymbol+"2,147,483,647.00000";
63                 Results2 [6] = perPattern.Replace ("n","214,748,364,700.00000");
64
65                 NfiUser = new NumberFormatInfo ();
66                 NfiUser.CurrencyDecimalDigits = 3;
67                 NfiUser.CurrencyDecimalSeparator = ":";
68                 NfiUser.CurrencyGroupSeparator = "/";
69                 NfiUser.CurrencyGroupSizes = new int[] { 2, 1, 0 };
70                 NfiUser.CurrencyNegativePattern = 10;  // n $-
71                 NfiUser.CurrencyPositivePattern = 3;  // n $
72                 NfiUser.CurrencySymbol = "XYZ";
73                 NfiUser.PercentDecimalDigits = 1;
74                 NfiUser.PercentDecimalSeparator = ";";
75                 NfiUser.PercentGroupSeparator = "~";
76                 NfiUser.PercentGroupSizes = new int[] { 1 };
77                 NfiUser.PercentNegativePattern = 2;
78                 NfiUser.PercentPositivePattern = 2;
79                 NfiUser.PercentSymbol = "%%%";
80         }
81         
82         [SetUp]
83         public void Setup ()
84         {
85                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US", false);
86         }
87
88         [TestFixtureTearDown]
89         public void TearDown()
90         {
91                 Thread.CurrentThread.CurrentCulture = old_culture;
92         }
93
94         [Test]
95         public void TestMinMax()
96         {
97                 
98                 Assert.AreEqual(Int32.MinValue, MyInt32_2, "#A01");
99                 Assert.AreEqual(Int32.MaxValue, MyInt32_3, "#A02");
100         }
101
102         [Test]  
103         public void TestCompareTo()
104         {
105                 Assert.IsTrue(MyInt32_3.CompareTo(MyInt32_2) > 0, "MyInt32_3.CompareTo(MyInt32_2) > 0");
106                 Assert.IsTrue(MyInt32_2.CompareTo(MyInt32_2) == 0, "MyInt32_2.CompareTo(MyInt32_2) == 0");
107                 Assert.IsTrue(MyInt32_1.CompareTo((object)(Int32)(-42)) == 0, "MyInt32_1.CompareTo((Int32)(-42)) == 0");
108                 Assert.IsTrue(MyInt32_2.CompareTo(MyInt32_3) < 0, "MyInt32_2.CompareTo(MyInt32_3) < 0");
109                 try {
110                         MyInt32_2.CompareTo((object)(Int16)100);
111                         Assert.Fail("Should raise a System.ArgumentException");
112                 }
113                 catch (Exception e) {
114                         Assert.IsTrue(typeof(ArgumentException) == e.GetType(), "typeof(ArgumentException) == e.GetType()");
115                 }
116         }
117
118         [Test]
119         public void TestEquals()
120         {
121                 Assert.IsTrue (MyInt32_1.Equals (MyInt32_1), "#B01");
122                 Assert.IsTrue (MyInt32_1.Equals ((Int32)(-42)), "#B02");
123                 Assert.IsTrue (MyInt32_1.Equals ((object)(SByte)(-42)) == false, "#B03");
124                 Assert.IsTrue (MyInt32_1.Equals (MyInt32_2) == false, "#B04");
125         }
126
127         [Test]  
128         public void TestGetHashCode()
129         {
130                 try {
131                         MyInt32_1.GetHashCode();
132                         MyInt32_2.GetHashCode();
133                         MyInt32_3.GetHashCode();
134                 }
135                 catch {
136                         Assert.Fail("GetHashCode should not raise an exception here");
137                 }
138         }
139
140         [Test]  
141         public void TestParse()
142         {
143                 //test Parse(string s)
144                 Assert.AreEqual (MyInt32_1, Int32.Parse (MyString1), "#C01");
145                 Assert.AreEqual (MyInt32_2, Int32.Parse (MyString2), "#C02");
146                 Assert.AreEqual (MyInt32_3, Int32.Parse (MyString3), "#C03");
147
148                 Assert.AreEqual (1, Int32.Parse ("1"), "#C04");
149                 Assert.AreEqual (1, Int32.Parse (" 1"), "#C05");
150                 Assert.AreEqual (1, Int32.Parse ("     1"), "#C06");
151                 Assert.AreEqual (1, Int32.Parse ("1    "), "#C07");
152                 Assert.AreEqual (1, Int32.Parse ("+1"), "#C08");
153                 Assert.AreEqual (-1, Int32.Parse ("-1"), "#C09");
154                 Assert.AreEqual (-1, Int32.Parse ("  -1"), "#C10");
155                 Assert.AreEqual (-1, Int32.Parse ("  -1  "), "#C11");
156                 Assert.AreEqual (-1, Int32.Parse ("  -1  "), "#C12");
157
158                 try {
159                         Int32.Parse(null);
160                         Assert.Fail ("#C13: Should raise a System.ArgumentNullException");
161                 }
162                 catch (Exception e) {
163                         Assert.IsTrue (typeof (ArgumentNullException) == e.GetType(), "#C14");
164                 }
165                 try {
166                         Int32.Parse("not-a-number");
167                         Assert.Fail ("#C15: Should raise a System.FormatException");
168                 }
169                 catch (Exception e) {
170                         Assert.IsTrue (typeof (FormatException) == e.GetType(), "#C16");
171                 }
172                 try {
173                         double OverInt = (double)Int32.MaxValue + 1;
174                         Int32.Parse(OverInt.ToString());
175                         Assert.Fail ("#C17: Should raise a System.OverflowException");
176                 }
177                 catch (Exception e) {
178                         Assert.AreEqual (typeof (OverflowException), e.GetType(), "#C18");
179                 }
180                 //test Parse(string s, NumberStyles style)
181                 Assert.AreEqual (42, Int32.Parse (" $42 ", NumberStyles.Currency), "#C19");
182                 try {
183                         Int32.Parse("$42", NumberStyles.Integer);
184                         Assert.Fail ("#C20: Should raise a System.FormatException");
185                 }
186                 catch (Exception e) {
187                         Assert.IsTrue (typeof (FormatException) == e.GetType(), "#C21");
188                 }
189                 //test Parse(string s, IFormatProvider provider)
190                 Assert.AreEqual (-42, Int32.Parse (" -42 ", Nfi), "#C22");
191                 try {
192                         Int32.Parse("%42", Nfi);
193                         Assert.Fail ("#C23: Should raise a System.FormatException");
194                 }
195                 catch (Exception e) {
196                         Assert.IsTrue (typeof (FormatException) == e.GetType(), "#C24");
197                 }
198                 //test Parse(string s, NumberStyles style, IFormatProvider provider)
199                 Assert.AreEqual (16, Int32.Parse (" 10 ", NumberStyles.HexNumber, Nfi), "#C25");
200                 try {
201                         Int32.Parse("$42", NumberStyles.Integer, Nfi);
202                         Assert.Fail ("#C26: Should raise a System.FormatException");
203                 }
204                 catch (Exception e) {
205                         Assert.IsTrue(typeof (FormatException) == e.GetType(), "#C27");
206                 }
207
208                 try {
209                         Int32.Parse (" - 1 ");
210                         Assert.Fail ("#C28: Should raise FormatException");
211                 } catch (Exception e){
212                         Assert.IsTrue (typeof (FormatException) == e.GetType (), "#C29");
213                 }
214
215                 try {
216                         Int32.Parse (" - ");
217                         Assert.Fail ("#C30: Should raise FormatException");
218                 } catch (Exception e){
219                         Assert.IsTrue (typeof (FormatException) == e.GetType (), "#C31");
220                 }
221                 Assert.AreEqual (-123, Int32.Parse ("ffffff85", NumberStyles.HexNumber, Nfi), "#C32");
222                 try {
223                         Int32.Parse ("100000000", NumberStyles.HexNumber, Nfi);
224                         Assert.Fail ("#C33: Should raise OverflowException");
225                 } catch (Exception e){
226                         Assert.IsTrue (typeof (OverflowException) == e.GetType (), "#C34");
227                 }
228                 try {
229                         Int32.Parse ("2147483648");
230                         Assert.Fail ("C#35: should raise OverflowException");
231                 } catch (Exception e) {
232                         Assert.IsTrue (typeof (OverflowException) == e.GetType (), "C#36");
233                 }
234                 try {
235                         Int32.Parse ("2147483648", CultureInfo.InvariantCulture);
236                         Assert.Fail ("C#37: should raise OverflowException");
237                 } catch (Exception e) {
238                         Assert.IsTrue (typeof (OverflowException) == e.GetType (), "C#38");
239                 }
240
241                 try {
242                         Int32.Parse (null);
243                         Assert.Fail ("C#39: Should raise an ArgumentNullException");
244                 } catch (Exception e){
245                         Assert.IsTrue (typeof (ArgumentNullException) == e.GetType (), "C#40");
246                 }
247
248                 try {
249                         Int32.Parse ("123", (NumberStyles) 60000);
250                         Assert.Fail ("C#41 Should raise an ArgumentException");
251                 } catch (Exception e){
252                         Assert.IsTrue (typeof (ArgumentException) == e.GetType (), "C#42");
253                 }
254
255                 try {
256                         Int32.Parse ("5", NumberStyles.Any, CultureInfo.InvariantCulture);
257                         Assert.Fail ("C#42");
258                 } catch (FormatException) {
259                 }
260
261                 try {
262                         Int32.Parse ("\xFF15\xFF15", NumberStyles.Any, CultureInfo.InvariantCulture);
263                         Assert.Fail ("C#43");
264                 } catch (FormatException) {
265                 }
266
267                 // Pass a DateTimeFormatInfo, it is unable to format
268                 // numbers, but we should not crash
269                 
270                 Int32.Parse ("123", new DateTimeFormatInfo ());
271
272                 Assert.AreEqual (734561, Int32.Parse ("734561\0"), "C#43");
273                 Assert.AreEqual (734561, Int32.Parse ("734561\0\0\0    \0"), "C#44");
274                 Assert.AreEqual (734561, Int32.Parse ("734561\0\0\0    "), "C#45");
275                 Assert.AreEqual (734561, Int32.Parse ("734561\0\0\0"), "C#46");
276
277                 Assert.AreEqual (0, Int32.Parse ("0+", NumberStyles.Any), "#50");
278         }
279
280         [Test]
281         public void TestParseExponent ()
282         {
283                 Assert.AreEqual (2, Int32.Parse ("2E0", NumberStyles.AllowExponent), "A#1");
284                 Assert.AreEqual (20, Int32.Parse ("2E1", NumberStyles.AllowExponent), "A#2");
285                 Assert.AreEqual (200, Int32.Parse ("2E2", NumberStyles.AllowExponent), "A#3");
286                 Assert.AreEqual (2000000, Int32.Parse ("2E6", NumberStyles.AllowExponent), "A#4");
287                 Assert.AreEqual (200, Int32.Parse ("2E+2", NumberStyles.AllowExponent), "A#5");
288                 Assert.AreEqual (2, Int32.Parse ("2", NumberStyles.AllowExponent), "A#6");
289                 Assert.AreEqual (21, Int32.Parse ("2.1E1", NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent), "A#7");
290                 Assert.AreEqual (520, Int32.Parse (".52E3", NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent), "A#8");
291                 Assert.AreEqual (32500000, Int32.Parse ("32.5E6", NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent), "A#9");
292                 Assert.AreEqual (890, Int32.Parse ("8.9000E2", NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent), "A#10");
293                 Assert.AreEqual (35, Int32.Parse ("3500E-02", NumberStyles.AllowExponent), "A#5");
294
295                 try {
296                         Int32.Parse ("2E");
297                         Assert.Fail ("B#1");
298                 } catch (FormatException) {
299                 }
300
301                 try {
302                         Int32.Parse ("2E3.0", NumberStyles.AllowExponent); // decimal notation for the exponent
303                         Assert.Fail ("B#2");
304                 } catch (FormatException) {
305                 }
306
307                 try {
308                         Int32.Parse ("2E 2", NumberStyles.AllowExponent);
309                         Assert.Fail ("B#3");
310                 } catch (FormatException) {
311                 }
312
313                 try {
314                         Int32.Parse ("2E2 ", NumberStyles.AllowExponent);
315                         Assert.Fail ("B#4");
316                 } catch (FormatException) {
317                 }
318
319                 try {
320                         Int32.Parse ("2E66", NumberStyles.AllowExponent); // final result overflow
321                         Assert.Fail ("B#5");
322                 } catch (OverflowException) {
323                 }
324
325                 try {
326                         long exponent = (long)Int32.MaxValue + 10;
327                         Int32.Parse ("2E" + exponent.ToString (), NumberStyles.AllowExponent);
328                         Assert.Fail ("B#6");
329                 } catch (OverflowException) {
330                 }
331
332                 try {
333                         Int32.Parse ("2E-1", NumberStyles.AllowExponent);
334                         Assert.Fail ("B#7");
335                 } catch (OverflowException){
336                 }
337
338                 try {
339                         Int32.Parse ("2 math e1", NumberStyles.AllowExponent);
340                         Assert.Fail ("B#8");
341                 } catch (FormatException) {
342                 }
343
344                 try {
345                         Int32.Parse ("2.09E1",  NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent);
346                         Assert.Fail ("B#9");
347                 } catch (OverflowException) {
348                 }
349         }
350
351         [Test]
352         public void TestTryParse()
353         {
354                 int result;
355
356                 Assert.AreEqual (true, Int32.TryParse (MyString1, out result));
357                 Assert.AreEqual (MyInt32_1, result);
358                 Assert.AreEqual (true, Int32.TryParse (MyString2, out result));
359                 Assert.AreEqual (MyInt32_2, result);
360                 Assert.AreEqual (true, Int32.TryParse (MyString3, out result));
361                 Assert.AreEqual (MyInt32_3, result);
362
363                 Assert.AreEqual (true, Int32.TryParse ("1", out result));
364                 Assert.AreEqual (1, result);
365                 Assert.AreEqual (true, Int32.TryParse (" 1", out result));
366                 Assert.AreEqual (1, result);
367                 Assert.AreEqual (true, Int32.TryParse ("     1", out result));
368                 Assert.AreEqual (1, result);
369                 Assert.AreEqual (true, Int32.TryParse ("1    ", out result));
370                 Assert.AreEqual (1, result);
371                 Assert.AreEqual (true, Int32.TryParse ("+1", out result));
372                 Assert.AreEqual (1, result);
373                 Assert.AreEqual (true, Int32.TryParse ("-1", out result));
374                 Assert.AreEqual (-1, result);
375                 Assert.AreEqual (true, Int32.TryParse ("  -1", out result));
376                 Assert.AreEqual (-1, result);
377                 Assert.AreEqual (true, Int32.TryParse ("  -1  ", out result));
378                 Assert.AreEqual (-1, result);
379                 Assert.AreEqual (true, Int32.TryParse ("  -1  ", out result));
380                 Assert.AreEqual (-1, result);
381
382                 result = 1;
383                 Assert.AreEqual (false, Int32.TryParse (null, out result));
384                 Assert.AreEqual (0, result);
385
386                 Assert.AreEqual (false, Int32.TryParse ("not-a-number", out result));
387
388                 double OverInt = (double)Int32.MaxValue + 1;
389                 Assert.AreEqual (false, Int32.TryParse (OverInt.ToString (), out result));
390                 Assert.AreEqual (false, Int32.TryParse (OverInt.ToString (), NumberStyles.None, CultureInfo.InvariantCulture, out result));
391
392                 Assert.AreEqual (false, Int32.TryParse ("$42", NumberStyles.Integer, null, out result));
393                 Assert.AreEqual (false, Int32.TryParse ("%42", NumberStyles.Integer, Nfi, out result));
394                 Assert.AreEqual (false, Int32.TryParse ("$42", NumberStyles.Integer, Nfi, out result));
395                 Assert.AreEqual (false, Int32.TryParse (" - 1 ", out result));
396                 Assert.AreEqual (false, Int32.TryParse (" - ", out result));
397                 Assert.AreEqual (false, Int32.TryParse ("100000000", NumberStyles.HexNumber, Nfi, out result));
398                 Assert.AreEqual (false, Int32.TryParse ("10000000000", out result));
399                 Assert.AreEqual (false, Int32.TryParse ("-10000000000", out result));
400                 Assert.AreEqual (true, Int32.TryParse ("7fffffff", NumberStyles.HexNumber, Nfi, out result));
401                 Assert.AreEqual (Int32.MaxValue, result);
402                 Assert.AreEqual (true, Int32.TryParse ("80000000", NumberStyles.HexNumber, Nfi, out result));
403                 Assert.AreEqual (Int32.MinValue, result);
404                 Assert.AreEqual (true, Int32.TryParse ("ffffffff", NumberStyles.HexNumber, Nfi, out result));
405                 Assert.AreEqual (-1, result);
406                 Assert.AreEqual (false, Int32.TryParse ("100000000", NumberStyles.HexNumber, Nfi, out result));
407                 Assert.IsFalse (int.TryParse ("-", NumberStyles.AllowLeadingSign, Nfi, out result));
408                 Assert.IsFalse (int.TryParse (Nfi.CurrencySymbol + "-", NumberStyles.AllowLeadingSign | NumberStyles.AllowCurrencySymbol, Nfi, out result));
409         }
410
411         [Test]  
412         public void TestToString()
413         {
414                 //test ToString()
415                 Assert.AreEqual (MyString1, MyInt32_1.ToString (), "#D01");
416                 Assert.AreEqual (MyString2, MyInt32_2.ToString (), "#D02");
417                 Assert.AreEqual (MyString3, MyInt32_3.ToString (), "#D03");
418
419                 //test ToString(string format, IFormatProvider provider);
420                 for (int i=0; i < Formats1.Length; i++) {
421                         Assert.AreEqual (ResultsNfi1 [i], MyInt32_2.ToString (Formats1 [i], Nfi),
422                                                          "#D04(" + i + "," + Formats1 [i] + ")");
423                         Assert.AreEqual (ResultsNfi2 [i], MyInt32_3.ToString (Formats2 [i], Nfi), 
424                                                          "#D05(" + i + "," + Formats2 [i] + ")");
425                 }
426
427                 //test ToString(string format)
428                 for (int i=0; i < Formats1.Length; i++) {
429                         Assert.AreEqual (Results1 [i], MyInt32_2.ToString(Formats1[i]), "#D06(" + i + ")");
430                         Assert.AreEqual (Results2 [i], MyInt32_3.ToString(Formats2[i]),
431                                                          "#D07(" + i + ")");
432                                       
433                 }
434
435                 try {
436                         MyInt32_1.ToString("z");
437                         Assert.Fail ("#D08: Should raise a System.FormatException");
438                 }
439                 catch (Exception e) {
440                         Assert.IsTrue (typeof (FormatException) == e.GetType(), "#D09");
441                 }
442         }
443
444         [Test]
445         public void TestCustomToString()
446         {
447                 int i = 123;
448
449                 Assert.AreEqual ("00123", i.ToString ("00000"), "Custom format string 00000");
450                 Assert.AreEqual ("123", i.ToString ("####"), "Custom format string ####");
451                 Assert.AreEqual ("0123", i.ToString ("0###"), "Custom format string ####");
452                 Assert.AreEqual ("0123", i.ToString ("#0###"), "Custom format string ####");
453                 Assert.AreEqual ("000123", i.ToString ("0#0###"), "Custom format string ####");
454         }
455
456         [Test]
457         public void TestSections ()
458         {
459                 int hundred = 100;
460                 int neghund = -100;
461                 
462                 Assert.IsTrue ( hundred.ToString ("#;#") == "100", "#TS1");
463                 Assert.IsTrue ( hundred.ToString ("-#;#") == "-100", "#TS2");
464                 Assert.IsTrue ( neghund.ToString ("#;#") == "100", "#TS3");
465                 Assert.IsTrue ( neghund.ToString ("#;-#") == "-100", "#TS3");
466         }
467         
468         [Test]
469         public void ToString_Defaults () 
470         {
471                 Int32 i = 254;
472                 // everything defaults to "G"
473                 string def = i.ToString ("G");
474                 Assert.AreEqual (def, i.ToString (), "ToString()");
475                 Assert.AreEqual (def, i.ToString ((IFormatProvider)null), "ToString((IFormatProvider)null)");
476                 Assert.AreEqual (def, i.ToString ((string)null), "ToString((string)null)");
477                 Assert.AreEqual (def, i.ToString (String.Empty), "ToString(empty)");
478                 Assert.AreEqual (def, i.ToString (null, null), "ToString(null,null)");
479                 Assert.AreEqual (def, i.ToString (String.Empty, null), "ToString(empty,null)");
480
481                 Assert.AreEqual ("254", def, "ToString(G)");
482         }
483
484         [Test]
485         public void ParseRespectCurrentCulture ()
486         {
487                 var old = Thread.CurrentThread.CurrentCulture;
488                 var cur = (CultureInfo)old.Clone ();
489
490                 NumberFormatInfo ninfo = new NumberFormatInfo ();
491                 ninfo.NegativeSign = ">";
492                 ninfo.PositiveSign = "%";
493                 cur.NumberFormat = ninfo;
494
495                 Thread.CurrentThread.CurrentCulture = cur;
496
497                 int val = 0;
498
499                 try {
500                         Assert.IsTrue (int.TryParse (">11", out val), "#1");
501                         Assert.AreEqual (-11, val, "#2");
502                         Assert.IsTrue (int.TryParse ("%11", out val), "#3");
503                         Assert.AreEqual (11, val, "#4");
504                 } finally {
505                         Thread.CurrentThread.CurrentCulture = old;
506                 }
507         }
508
509         [Test]
510         public void TestUserCurrency ()
511         {
512                 const int val1 = -1234567;
513                 const int val2 = 1234567;
514
515                 string s = "";
516                 int v;
517                 s = val1.ToString ("c", NfiUser);
518                 Assert.AreEqual ("1234/5/67:000 XYZ-", s, "Currency value type 1 is not what we want to try to parse");
519                 v = Int32.Parse ("1234/5/67:000   XYZ-", NumberStyles.Currency, NfiUser);
520                 Assert.AreEqual (val1, v);
521
522                 s = val2.ToString ("c", NfiUser);
523                 Assert.AreEqual ("1234/5/67:000 XYZ", s, "Currency value type 2 is not what we want to try to parse");
524                 v = Int32.Parse (s, NumberStyles.Currency, NfiUser);
525                 Assert.AreEqual (val2, v);
526         }
527 }
528
529 }