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