[sgen] Make sure we don't sweep a block if we're not supposed to
[mono.git] / mcs / class / corlib / Test / System.Globalization / CultureInfoTest.cs
1 //
2 // System.Globalization.CultureInfo Test Cases
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (c) 2005 Novell, Inc. (http://www.novell.com)
8 //
9
10 using System;
11 using System.Globalization;
12 using System.IO;
13 using System.Runtime.Serialization.Formatters.Binary;
14 using System.Threading;
15
16 using NUnit.Framework;
17
18 namespace MonoTests.System.Globalization
19 {
20         [TestFixture]
21         public class CultureInfoTest
22         {
23                 CultureInfo old_culture;
24
25                 [SetUp]
26                 public void Setup ()
27                 {
28                         old_culture = Thread.CurrentThread.CurrentCulture;
29                 }
30
31                 [TearDown]
32                 public void TearDown ()
33                 {
34                         Thread.CurrentThread.CurrentCulture = old_culture;
35                 }
36
37                 [Test]
38                 public void Constructor0 ()
39                 {
40                         CultureInfo ci = new CultureInfo (2067);
41                         Assert.IsFalse (ci.IsReadOnly, "#1");
42                         Assert.AreEqual (2067, ci.LCID, "#2");
43                         Assert.AreEqual ("nl-BE", ci.Name, "#3");
44                         Assert.IsTrue (ci.UseUserOverride, "#4");
45                 }
46
47                 [Test]
48                 public void Constructor0_Identifier_Negative ()
49                 {
50                         try {
51                                 new CultureInfo (-1);
52                                 Assert.Fail ("#1");
53                         } catch (ArgumentOutOfRangeException ex) {
54                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
55                                 Assert.IsNull (ex.InnerException, "#3");
56                                 Assert.IsNotNull (ex.Message, "#4");
57                                 Assert.IsNotNull (ex.ParamName, "#5");
58                                 Assert.AreEqual ("culture", ex.ParamName, "#6");
59                         }
60                 }
61
62                 [Test]
63                 public void Constructor1 ()
64                 {
65                         CultureInfo ci = new CultureInfo ("nl-BE");
66                         Assert.IsFalse (ci.IsReadOnly, "#1");
67                         Assert.AreEqual (2067, ci.LCID, "#2");
68                         Assert.AreEqual ("nl-BE", ci.Name, "#3");
69                         Assert.IsTrue (ci.UseUserOverride, "#4");
70                 }
71
72                 [Test]
73                 public void Constructor1_Name_Null ()
74                 {
75                         try {
76                                 new CultureInfo ((string) null);
77                                 Assert.Fail ("#1");
78                         } catch (ArgumentNullException ex) {
79                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
80                                 Assert.IsNull (ex.InnerException, "#3");
81                                 Assert.IsNotNull (ex.Message, "#4");
82                                 Assert.IsNotNull (ex.ParamName, "#5");
83                                 Assert.AreEqual ("name", ex.ParamName, "#6");
84                         }
85                 }
86
87                 [Test]
88                 public void Constructor2 ()
89                 {
90                         CultureInfo ci = new CultureInfo (2067, false);
91                         Assert.IsFalse (ci.IsReadOnly, "#A1");
92                         Assert.AreEqual (2067, ci.LCID, "#A2");
93                         Assert.AreEqual ("nl-BE", ci.Name, "#A3");
94                         Assert.IsFalse (ci.UseUserOverride, "#A4");
95
96                         ci = new CultureInfo (2067, true);
97                         Assert.IsFalse (ci.IsReadOnly, "#B1");
98                         Assert.AreEqual (2067, ci.LCID, "#B2");
99                         Assert.AreEqual ("nl-BE", ci.Name, "#B3");
100                         Assert.IsTrue (ci.UseUserOverride, "#B4");
101                 }
102
103                 [Test]
104                 public void Constructor2_Identifier_Negative ()
105                 {
106                         try {
107                                 new CultureInfo (-1, false);
108                                 Assert.Fail ("#1");
109                         } catch (ArgumentOutOfRangeException ex) {
110                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
111                                 Assert.IsNull (ex.InnerException, "#3");
112                                 Assert.IsNotNull (ex.Message, "#4");
113                                 Assert.IsNotNull (ex.ParamName, "#5");
114                                 Assert.AreEqual ("culture", ex.ParamName, "#6");
115                         }
116                 }
117
118                 [Test]
119                 public void Constructor3 ()
120                 {
121                         CultureInfo ci = new CultureInfo ("nl-BE", false);
122                         Assert.IsFalse (ci.IsReadOnly, "#A1");
123                         Assert.AreEqual (2067, ci.LCID, "#A2");
124                         Assert.AreEqual ("nl-BE", ci.Name, "#A3");
125                         Assert.IsFalse (ci.UseUserOverride, "#A4");
126
127                         ci = new CultureInfo ("nl-BE", true);
128                         Assert.IsFalse (ci.IsReadOnly, "#B1");
129                         Assert.AreEqual (2067, ci.LCID, "#B2");
130                         Assert.AreEqual ("nl-BE", ci.Name, "#B3");
131                         Assert.IsTrue (ci.UseUserOverride, "#B4");
132                 }
133
134                 [Test]
135                 public void Constructor3_Name_Null ()
136                 {
137                         try {
138                                 new CultureInfo ((string) null, false);
139                                 Assert.Fail ("#1");
140                         } catch (ArgumentNullException ex) {
141                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
142                                 Assert.IsNull (ex.InnerException, "#3");
143                                 Assert.IsNotNull (ex.Message, "#4");
144                                 Assert.IsNotNull (ex.ParamName, "#5");
145                                 Assert.AreEqual ("name", ex.ParamName, "#6");
146                         }
147                 }
148
149                 [Test]
150                 public void ClearCachedData ()
151                 {
152                         var dt = DateTime.Now;
153                         old_culture.ClearCachedData (); // It can be any culture instance as the method should be static
154                         dt = DateTime.Now;
155                 }
156
157                 [Test]
158                 public void CreateSpecificCulture ()
159                 {
160                         var ci = CultureInfo.CreateSpecificCulture ("en");
161                         Assert.AreEqual ("en-US", ci.Name, "#1");
162
163                         ci = CultureInfo.CreateSpecificCulture ("en-GB");
164                         Assert.AreEqual ("en-GB", ci.Name, "#2");
165
166                         ci = CultureInfo.CreateSpecificCulture ("en-----");
167                         Assert.AreEqual ("en-US", ci.Name, "#3");
168
169                         ci = CultureInfo.CreateSpecificCulture ("en-GB-");
170                         Assert.AreEqual ("en-US", ci.Name, "#4");
171
172                         ci = CultureInfo.CreateSpecificCulture ("");
173                         Assert.AreEqual (CultureInfo.InvariantCulture, ci, "#5");
174
175                         ci = CultureInfo.CreateSpecificCulture ("zh-hant");
176                         Assert.AreEqual ("zh-HK", ci.Name, "#6");
177
178                         ci = CultureInfo.CreateSpecificCulture ("zh-hans");
179                         Assert.AreEqual ("zh-CN", ci.Name, "#7");
180
181                         ci = CultureInfo.CreateSpecificCulture ("zh-hans-CN");
182                         Assert.AreEqual ("zh-CN", ci.Name, "#8");
183
184                         ci = CultureInfo.CreateSpecificCulture ("zh-hant-US");
185                         Assert.AreEqual ("zh-HK", ci.Name, "#9");
186
187                         ci = CultureInfo.CreateSpecificCulture ("az-CyrlM-BR");
188                         Assert.AreEqual ("az-Latn-AZ", ci.Name, "#10");
189                 }
190
191                 [Test]
192                 public void CreateSpecificCulture_Invalid ()
193                 {
194                         try {
195                                 CultureInfo.CreateSpecificCulture ("uy32");
196                                 Assert.Fail ("#1");
197                         } catch (CultureNotFoundException) {
198                         }
199
200                         try {
201                                 CultureInfo.CreateSpecificCulture (null);
202                                 Assert.Fail ("#2");
203                         } catch (ArgumentNullException) {
204                                 // .NET throws NRE which is lame
205                         }
206                 }
207
208                 [Test]
209                 public void DateTimeFormat_Neutral_Culture ()
210                 {
211                         CultureInfo ci = new CultureInfo ("nl");
212                         try {
213                                 DateTimeFormatInfo dfi = ci.DateTimeFormat;
214                                 Assert.IsNotNull (dfi, "#1");
215                         } catch (NotSupportedException ex) {
216                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
217                                 Assert.IsNull (ex.InnerException, "#3");
218                                 Assert.IsNotNull (ex.Message, "#4");
219                         }
220                 }
221
222                 [Test] // bug #72081
223                 public void GetAllCulturesInvariant ()
224                 {
225                         CultureInfo invariant = CultureInfo.InvariantCulture;
226                         CultureInfo [] infos = CultureInfo.GetCultures (CultureTypes.AllCultures);
227                         foreach (CultureInfo culture in infos) {
228                                 if (culture.Equals (invariant))
229                                         return;
230                         }
231
232                         Assert.Fail ("InvariantCulture not found in the array from GetCultures()");
233                 }
234
235                 [Test]
236                 public void GetAllCultures_Specific ()
237                 {
238                         CultureInfo [] infos = CultureInfo.GetCultures (CultureTypes.SpecificCultures);
239                         foreach (CultureInfo ci in infos) {
240                                 Assert.IsNotNull (ci.DateTimeFormat);
241                         }
242                 }
243
244                 [Test]
245                 public void TrySetNeutralCultureNotInvariant ()
246                 {
247                         Thread.CurrentThread.CurrentCulture = new CultureInfo ("ar");
248                 }
249
250                 [Test]
251                 // make sure that all CultureInfo holds non-null calendars.
252                 public void OptionalCalendars ()
253                 {
254 #if MOBILE
255                         // ensure the linker does not remove them so we can test them
256                         Assert.IsNotNull (typeof (UmAlQuraCalendar), "UmAlQuraCalendar");
257 #endif
258                         foreach (CultureInfo ci in CultureInfo.GetCultures (
259                                 CultureTypes.AllCultures))
260                                 Assert.IsNotNull (ci.OptionalCalendars, String.Format ("{0} {1}",
261                                         ci.LCID, ci.Name));
262                 }
263
264                 [Test] // bug #77347
265                 public void CloneNeutral ()
266                 {
267                         CultureInfo culture = new CultureInfo ("en");
268                         CultureInfo cultureClone = culture.Clone () as CultureInfo;
269                         Assert.IsTrue (culture.Equals (cultureClone));
270                 }
271
272                 [Test]
273                 public void IsNeutral ()
274                 {
275                         var ci = new CultureInfo (0x6C1A);
276                         Assert.IsTrue (ci.IsNeutralCulture, "#1");
277                         Assert.AreEqual ("srp", ci.ThreeLetterISOLanguageName, "#2");
278
279                         ci = new CultureInfo ("en-US");
280                         Assert.IsFalse (ci.IsNeutralCulture, "#1a");
281                         Assert.AreEqual ("eng", ci.ThreeLetterISOLanguageName, "#2a");
282                 }
283
284                 [Test] // bug #81930
285                 public void IsReadOnly ()
286                 {
287                         CultureInfo ci;
288
289                         ci = new CultureInfo ("en-US");
290                         Assert.IsFalse (ci.IsReadOnly, "#A1");
291                         Assert.IsFalse (ci.NumberFormat.IsReadOnly, "#A2");
292                         Assert.IsFalse (ci.DateTimeFormat.IsReadOnly, "#A3");
293                         ci.NumberFormat.NumberGroupSeparator = ",";
294                         ci.NumberFormat = new NumberFormatInfo ();
295                         ci.DateTimeFormat.DateSeparator = "/";
296                         ci.DateTimeFormat = new DateTimeFormatInfo ();
297                         Assert.IsFalse (ci.NumberFormat.IsReadOnly, "#A4");
298                         Assert.IsFalse (ci.DateTimeFormat.IsReadOnly, "#A5");
299
300                         ci = new CultureInfo (CultureInfo.InvariantCulture.LCID);
301                         Assert.IsFalse (ci.IsReadOnly, "#B1");
302                         Assert.IsFalse (ci.NumberFormat.IsReadOnly, "#B2");
303                         Assert.IsFalse (ci.DateTimeFormat.IsReadOnly, "#B3");
304                         ci.NumberFormat.NumberGroupSeparator = ",";
305                         ci.NumberFormat = new NumberFormatInfo ();
306                         ci.DateTimeFormat.DateSeparator = "/";
307                         ci.DateTimeFormat = new DateTimeFormatInfo ();
308                         Assert.IsFalse (ci.NumberFormat.IsReadOnly, "#B4");
309                         Assert.IsFalse (ci.DateTimeFormat.IsReadOnly, "#B5");
310
311                         ci = CultureInfo.CurrentCulture;
312                         Assert.IsTrue (ci.IsReadOnly, "#C1:" + ci.DisplayName);
313                         Assert.IsTrue (ci.NumberFormat.IsReadOnly, "#C2");
314                         Assert.IsTrue (ci.DateTimeFormat.IsReadOnly, "#C3");
315                         try {
316                                 ci.NumberFormat.NumberGroupSeparator = ",";
317                                 Assert.Fail ("#C4");
318                         } catch (InvalidOperationException ex) {
319                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C5");
320                                 Assert.IsNull (ex.InnerException, "#C6");
321                                 Assert.IsNotNull (ex.Message, "#C7");
322                         }
323
324                         ci = CultureInfo.CurrentUICulture;
325                         Assert.IsTrue (ci.IsReadOnly, "#D1");
326                         Assert.IsTrue (ci.NumberFormat.IsReadOnly, "#D2");
327                         Assert.IsTrue (ci.DateTimeFormat.IsReadOnly, "#D3");
328                         try {
329                                 ci.NumberFormat.NumberGroupSeparator = ",";
330                                 Assert.Fail ("#D4");
331                         } catch (InvalidOperationException ex) {
332                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D5");
333                                 Assert.IsNull (ex.InnerException, "#D6");
334                                 Assert.IsNotNull (ex.Message, "#D7");
335                         }
336
337                         ci = CultureInfo.InvariantCulture;
338                         Assert.IsTrue (ci.IsReadOnly, "#F1");
339                         Assert.IsTrue (ci.NumberFormat.IsReadOnly, "#F2");
340                         Assert.IsTrue (ci.DateTimeFormat.IsReadOnly, "#F3");
341                         try {
342                                 ci.NumberFormat.NumberGroupSeparator = ",";
343                                 Assert.Fail ("#F4");
344                         } catch (InvalidOperationException ex) {
345                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#F5");
346                                 Assert.IsNull (ex.InnerException, "#F6");
347                                 Assert.IsNotNull (ex.Message, "#F7");
348                         }
349
350                         ci = new CultureInfo (string.Empty);
351                         Assert.IsFalse (ci.IsReadOnly, "#G1");
352                         Assert.IsFalse (ci.NumberFormat.IsReadOnly, "#G2");
353                         Assert.IsFalse (ci.DateTimeFormat.IsReadOnly, "#G3");
354                         ci.NumberFormat.NumberGroupSeparator = ",";
355                         ci.NumberFormat = new NumberFormatInfo ();
356                         ci.DateTimeFormat.DateSeparator = "/";
357                         ci.DateTimeFormat = new DateTimeFormatInfo ();
358                         Assert.IsFalse (ci.NumberFormat.IsReadOnly, "#G4");
359                         Assert.IsFalse (ci.DateTimeFormat.IsReadOnly, "#G5");
360                 }
361
362                 [Test]
363                 public void IsReadOnly_GetCultures ()
364                 {
365                         foreach (CultureInfo ci in CultureInfo.GetCultures (CultureTypes.AllCultures)) {
366                                 string cultureMsg = String.Format ("{0} {1}", ci.LCID, ci.Name);
367                                 Assert.IsFalse (ci.IsReadOnly, "#1:" + cultureMsg);
368                                 if (ci.IsNeutralCulture)
369                                         continue;
370                                 Assert.IsFalse (ci.NumberFormat.IsReadOnly, "#2:" + cultureMsg);
371                                 Assert.IsFalse (ci.DateTimeFormat.IsReadOnly, "#3:" + cultureMsg);
372                         }
373                 }
374
375                 [Test]
376                 [Category ("NotWorking")]
377                 public void IsReadOnly_InstalledUICulture ()
378                 {
379                         CultureInfo ci = CultureInfo.InstalledUICulture;
380                         Assert.IsTrue (ci.IsReadOnly, "#1");
381                         Assert.IsTrue (ci.NumberFormat.IsReadOnly, "#2");
382                         Assert.IsTrue (ci.DateTimeFormat.IsReadOnly, "#3");
383                         try {
384                                 ci.NumberFormat.NumberGroupSeparator = ",";
385                                 Assert.Fail ("#4");
386                         } catch (InvalidOperationException ex) {
387                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#5");
388                                 Assert.IsNull (ex.InnerException, "#6");
389                                 Assert.IsNotNull (ex.Message, "#7");
390                         }
391                 }
392
393                 [Test] // bug #69652
394                 public void Norwegian ()
395                 {
396                         new CultureInfo ("no");
397                         new CultureInfo ("nb-NO");
398                         new CultureInfo ("nn-NO");
399                 }
400
401                 [Test]
402                 public void NumberFormat_Neutral_Culture ()
403                 {
404                         CultureInfo ci = new CultureInfo ("nl");
405                         try {
406                                 NumberFormatInfo nfi = ci.NumberFormat;
407                                 Assert.IsNotNull (nfi, "#1");
408                         } catch (NotSupportedException ex) {
409                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
410                                 Assert.IsNull (ex.InnerException, "#3");
411                                 Assert.IsNotNull (ex.Message, "#4");
412                         }
413                 }
414
415                 [Test]
416                 [Category ("NotDotNet")] // On MS, the NumberFormatInfo of the CultureInfo matching the current locale is not read-only
417                 public void GetCultureInfo_Identifier ()
418                 {
419                         foreach (CultureInfo ci in CultureInfo.GetCultures (CultureTypes.AllCultures)) {
420                                 string cultureMsg = String.Format ("{0} {1}", ci.LCID, ci.Name);
421                                 CultureInfo culture = CultureInfo.GetCultureInfo (ci.LCID);
422                                 Assert.IsTrue (culture.IsReadOnly, "#1:" + cultureMsg);
423                                 if (culture.IsNeutralCulture)
424                                         continue;
425                                 Assert.IsTrue (culture.NumberFormat.IsReadOnly, "#2:" + cultureMsg);
426                                 Assert.IsTrue (culture.DateTimeFormat.IsReadOnly, "#3:" + cultureMsg);
427                         }
428                 }
429
430                 [Test]
431                 public void GetCultureInfo_Identifier_Nonpositive ()
432                 {
433                         try {
434                                 CultureInfo.GetCultureInfo (0);
435                                 Assert.Fail ("#1");
436                         } catch (ArgumentOutOfRangeException ex) {
437                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
438                                 Assert.IsNull (ex.InnerException, "#3");
439                                 Assert.IsNotNull (ex.Message, "#4");
440                                 Assert.IsNotNull (ex.ParamName, "#5");
441                                 Assert.AreEqual ("culture", ex.ParamName, "#6");
442                         }
443                 }
444
445                 [Test]
446                 public void GetCultureInfo_Identifier_NotSupported ()
447                 {
448                         try {
449                                 CultureInfo.GetCultureInfo (666);
450                                 Assert.Fail ("#1");
451                         } catch (ArgumentException ex) {
452                                 Assert.AreEqual (typeof (CultureNotFoundException), ex.GetType (), "#2");
453                                 Assert.IsNull (ex.InnerException, "#3");
454                                 Assert.IsNotNull (ex.Message, "#4");
455                                 Assert.IsNotNull (ex.ParamName, "#5");
456                                 Assert.AreEqual ("culture", ex.ParamName, "#6");
457                         }
458                 }
459
460                 [Test]
461                 [Category ("NotDotNet")] // On MS, the NumberFormatInfo of the CultureInfo matching the current locale is not read-only
462                 public void GetCultureInfo_Name ()
463                 {
464                         foreach (CultureInfo ci in CultureInfo.GetCultures (CultureTypes.AllCultures)) {
465                                 string cultureMsg = String.Format ("{0} {1}", ci.LCID, ci.Name);
466                                 CultureInfo culture = CultureInfo.GetCultureInfo (ci.Name);
467                                 Assert.IsTrue (culture.IsReadOnly, "#1:" + cultureMsg);
468                                 if (culture.IsNeutralCulture)
469                                         continue;
470                                 Assert.IsTrue (culture.NumberFormat.IsReadOnly, "#2:" + cultureMsg);
471                                 Assert.IsTrue (culture.DateTimeFormat.IsReadOnly, "#3:" + cultureMsg);
472                         }
473                 }
474
475                 [Test]
476                 public void GetCultureInfo_Name_NotSupported ()
477                 {
478                         try {
479                                 CultureInfo.GetCultureInfo ("666");
480                                 Assert.Fail ("#1");
481                         } catch (ArgumentException ex) {
482                                 Assert.AreEqual (typeof (CultureNotFoundException), ex.GetType (), "#2");
483                                 Assert.IsNull (ex.InnerException, "#3");
484                                 Assert.IsNotNull (ex.Message, "#4");
485                                 Assert.IsNotNull (ex.ParamName, "#5");
486                                 Assert.AreEqual ("name", ex.ParamName, "#6");
487                         }
488                 }
489
490                 [Test]
491                 public void GetCultureInfo_Name_Null ()
492                 {
493                         try {
494                                 CultureInfo.GetCultureInfo ((string) null);
495                                 Assert.Fail ("#1");
496                         } catch (ArgumentNullException ex) {
497                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
498                                 Assert.IsNull (ex.InnerException, "#3");
499                                 Assert.IsNotNull (ex.Message, "#4");
500                                 Assert.IsNotNull (ex.ParamName, "#5");
501                                 Assert.AreEqual ("name", ex.ParamName, "#6");
502                         }
503                 }
504
505                 [Test]
506                 public void UseUserOverride_CurrentCulture ()
507                 {
508                         CultureInfo ci = CultureInfo.CurrentCulture;
509                         bool expected = (ci.LCID != CultureInfo.InvariantCulture.LCID);
510                         Assert.AreEqual (expected, ci.UseUserOverride, "#1");
511
512                         ci = (CultureInfo) ci.Clone ();
513                         Assert.AreEqual (expected, ci.UseUserOverride, "#2");
514                 }
515
516                 [Test]
517                 public void UseUserOverride_CurrentUICulture ()
518                 {
519                         CultureInfo ci = CultureInfo.CurrentCulture;
520                         bool expected = (ci.LCID != CultureInfo.InvariantCulture.LCID);
521                         Assert.AreEqual (expected, ci.UseUserOverride, "#1");
522
523                         ci = (CultureInfo) ci.Clone ();
524                         Assert.AreEqual (expected, ci.UseUserOverride, "#2");
525                 }
526
527                 [Test]
528                 public void UseUserOverride_GetCultureInfo ()
529                 {
530                         CultureInfo culture;
531
532                         foreach (CultureInfo ci in CultureInfo.GetCultures (CultureTypes.AllCultures)) {
533                                 string cultureMsg = String.Format ("{0} {1}", ci.LCID, ci.Name);
534                                 culture = CultureInfo.GetCultureInfo (ci.Name);
535                                 Assert.IsFalse (culture.UseUserOverride, "#1: " + cultureMsg);
536                                 culture = CultureInfo.GetCultureInfo (ci.LCID);
537                                 Assert.IsFalse (culture.UseUserOverride, "#2: " + cultureMsg);
538                         }
539                 }
540
541                 [Test]
542                 public void UseUserOverride_GetCultures ()
543                 {
544                         foreach (CultureInfo ci in CultureInfo.GetCultures (CultureTypes.AllCultures)) {
545                                 string cultureMsg = String.Format ("{0} {1}", ci.LCID, ci.Name);
546                                 if (ci.LCID == CultureInfo.InvariantCulture.LCID)
547                                         Assert.IsFalse (ci.UseUserOverride, cultureMsg);
548                                 else
549                                         Assert.IsTrue (ci.UseUserOverride, cultureMsg);
550                         }
551                 }
552
553                 [Test]
554                 public void UseUserOverride_InvariantCulture ()
555                 {
556                         CultureInfo ci = CultureInfo.InvariantCulture;
557                         Assert.IsFalse (ci.UseUserOverride, "#21");
558
559                         ci = (CultureInfo) ci.Clone ();
560                         Assert.IsFalse (ci.UseUserOverride, "#2");
561                 }
562
563                 [Test]
564                 public void Bug402128 ()
565                 {
566                         var culture = new CultureInfo ("en-US");
567                         var ms = new MemoryStream ();
568                         var formatter = new BinaryFormatter ();
569                         formatter.Serialize (ms, culture);
570                         ms.Seek (0, SeekOrigin.Begin);
571                         var deserializedCulture = (CultureInfo) formatter.Deserialize (ms);
572                 }
573
574                 [Test]
575                 public void ZhHant ()
576                 {
577                         Assert.AreEqual (31748, new CultureInfo ("zh-Hant").LCID);
578                         Assert.AreEqual (31748, CultureInfo.GetCultureInfo ("zh-Hant").LCID);
579                         Assert.AreEqual (31748, new CultureInfo ("zh-CHT").LCID);
580                         Assert.AreEqual (31748, new CultureInfo ("zh-CHT").Parent.LCID);
581                 }
582
583                 [Test]
584                 public void ZhHans ()
585                 {
586                         Assert.AreEqual (4, new CultureInfo ("zh-Hans").LCID);
587                         Assert.AreEqual (4, CultureInfo.GetCultureInfo ("zh-Hans").LCID);
588                         Assert.AreEqual (4, new CultureInfo ("zh-CHS").LCID);
589                         Assert.AreEqual (4, new CultureInfo ("zh-CHS").Parent.LCID);
590                 }
591
592                 [Test]
593                 [SetCulture ("zh-TW")]
594                 public void ParentOfZh ()
595                 {
596                         Assert.AreEqual (31748, CultureInfo.CurrentCulture.Parent.LCID);
597                         Assert.AreEqual (31748, CultureInfo.CurrentCulture.Parent.Parent.LCID);
598                 }
599                 
600                 [Test]
601                 public void CurrentCulture ()
602                 {
603                         Assert.IsNotNull (CultureInfo.CurrentCulture, "CurrentCulture");
604                 }
605                 
606                 [Test]
607                 [ExpectedException (typeof (CultureNotFoundException))]
608                 public void CultureNotFound ()
609                 {
610                         // that's how the 'locale' gets defined for a device with an English UI
611                         // and it's international settings set for Hong Kong
612                         // https://bugzilla.xamarin.com/show_bug.cgi?id=3471
613                         new CultureInfo ("en-HK");
614                 }
615
616                 [Test]
617                 public void ChineseSimplifiedDontEqual ()
618                 {
619                         CultureInfo zh1 = new CultureInfo ("zh-Hans");
620                         CultureInfo zh2 = new CultureInfo ("zh-CHS");
621
622                         Assert.IsFalse (zh1.Equals (zh2), "#1");
623                         Assert.IsFalse (zh2.Equals (zh1), "#2");
624                 }
625
626 #if NET_4_5
627                 CountdownEvent barrier = new CountdownEvent (3);
628                 AutoResetEvent[] evt = new AutoResetEvent [] { new AutoResetEvent (false), new AutoResetEvent (false), new AutoResetEvent (false), new AutoResetEvent (false)};
629
630                 CultureInfo[] initial_culture = new CultureInfo[4];
631                 CultureInfo[] changed_culture = new CultureInfo[4];
632                 CultureInfo[] changed_culture2 = new CultureInfo[4];
633                 CultureInfo alternative_culture = new CultureInfo("pt-BR");
634
635                 void StepAllPhases (int index)
636                 {
637                         initial_culture [index] = CultureInfo.CurrentCulture;
638                         /*Phase 1 - we witness the original value */
639                         barrier.Signal ();
640
641                         /*Phase 2 - main thread changes culture */
642                         evt [index].WaitOne ();
643
644                         /*Phase 3 - we witness the new value */
645                         changed_culture [index] = CultureInfo.CurrentCulture;
646                         barrier.Signal ();
647
648                         /* Phase 4 - main thread changes culture back */
649                         evt [index].WaitOne ();
650
651                         /*Phase 5 - we witness the new value */
652                         changed_culture2 [index] = CultureInfo.CurrentCulture;
653                         barrier.Signal ();
654                 }
655
656                 void ThreadWithoutChange () {
657                         StepAllPhases (1);
658                 }
659
660                 void ThreadWithChange () {
661                         Thread.CurrentThread.CurrentCulture = alternative_culture;
662                         StepAllPhases (2);
663                 }
664
665                 void ThreadPoolWithoutChange () {
666                         StepAllPhases (3);
667                 }
668
669                 [Test]
670                 public void DefaultThreadCurrentCulture () {
671
672                         Action c = () => {
673                                 var orig_culture = CultureInfo.CurrentCulture;
674                                 var new_culture = new CultureInfo("fr-FR");
675
676                                 /* Phase 0 - warm up */
677                                 new Thread (ThreadWithoutChange).Start ();
678                                 new Thread (ThreadWithChange).Start ();
679                                 Action x = ThreadPoolWithoutChange;
680                                 x.BeginInvoke (null, null);
681
682                                 /* Phase 1 - let everyone witness initial values */
683                                 initial_culture [0] = CultureInfo.CurrentCulture;
684                                 barrier.Wait ();
685                                 barrier.Reset ();
686
687                                 /* Phase 2 - change the default culture*/
688                                 CultureInfo.DefaultThreadCurrentCulture = new_culture;
689                                 evt [1].Set ();
690                                 evt [2].Set ();
691                                 evt [3].Set ();
692
693                                 /* Phase 3 - let everyone witness the new value */
694                                 changed_culture [0] = CultureInfo.CurrentCulture;
695                                 barrier.Wait ();
696                                 barrier.Reset ();
697
698                                 /* Phase 4 - revert the default culture back to null */
699                                 CultureInfo.DefaultThreadCurrentCulture = null;
700                                 evt [1].Set ();
701                                 evt [2].Set ();
702                                 evt [3].Set ();
703
704                                 /* Phase 5 - let everyone witness the new value */
705                                 changed_culture2 [0] = CultureInfo.CurrentCulture;
706                                 barrier.Wait ();
707                                 barrier.Reset ();
708
709                                 CultureInfo.DefaultThreadCurrentCulture = null;
710
711                                 Assert.AreEqual (orig_culture, initial_culture [0], "#1");
712                                 Assert.AreEqual (orig_culture, initial_culture [1], "#2");
713                                 Assert.AreEqual (alternative_culture, initial_culture [2], "#3");
714                                 Assert.AreEqual (orig_culture, initial_culture [3], "#4");
715
716                                 Assert.AreEqual (new_culture, changed_culture [0], "#5");
717                                 Assert.AreEqual (new_culture, changed_culture [1], "#6");
718                                 Assert.AreEqual (alternative_culture, changed_culture [2], "#7");
719                                 Assert.AreEqual (new_culture, changed_culture [3], "#8");
720
721                                 Assert.AreEqual (orig_culture, changed_culture2 [0], "#9");
722                                 Assert.AreEqual (orig_culture, changed_culture2 [1], "#10");
723                                 Assert.AreEqual (alternative_culture, changed_culture2 [2], "#11");
724                                 Assert.AreEqual (orig_culture, changed_culture2 [3], "#12");
725                         };
726                         var ar = c.BeginInvoke (null, null);
727                         ar.AsyncWaitHandle.WaitOne ();
728                 }
729
730                 [Test]
731                 public void DefaultThreadCurrentCultureAndNumberFormaters () {
732                         string us_str = null;
733                         string br_str = null;
734                         var thread = new Thread (() => {
735                                 CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
736                                 us_str = 100000.ToString ("C");
737                                 CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("pt-BR");
738                                 br_str = 100000.ToString ("C");
739                         });
740                         thread.Start ();
741                         thread.Join ();
742                         CultureInfo.DefaultThreadCurrentCulture = null;
743                         Assert.AreEqual ("$100,000.00", us_str, "#1");
744                         Assert.AreEqual ("R$ 100.000,00", br_str, "#2");
745                 }
746 #endif
747         }
748 }