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