summaryrefslogtreecommitdiff
path: root/tests/src/CoreMangLib/cti/system/datetime/datetimeparseexact1.cs
blob: b249da69a68610ad01f470612aaeea572d150539 (plain)
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
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Globalization;

public class DateTimeParseExact1
{
    private const  int c_MIN_STRING_LEN = 1;
    private const  int c_MAX_STRING_LEN = 2048;
    private const  int c_NUM_LOOPS      = 100;
    private static CultureInfo CurrentCulture = TestLibrary.Utilities.CurrentCulture;
    private static CultureInfo EnglishCulture = new CultureInfo("en-US");
    private static string[] c_MONTHS = EnglishCulture.DateTimeFormat.MonthGenitiveNames;
    private static string[] c_MONTHS_SH = EnglishCulture.DateTimeFormat.AbbreviatedMonthGenitiveNames;
    private static string[] c_DAYS_SH = EnglishCulture.DateTimeFormat.AbbreviatedDayNames;

    public static int Main()
    {
        DateTimeParseExact1 test = new DateTimeParseExact1();

        TestLibrary.TestFramework.BeginTestCase("DateTimeParseExact1");

        if (test.RunTests())
        {
            TestLibrary.TestFramework.EndTestCase();
            TestLibrary.TestFramework.LogInformation("PASS");
            return 100;
        }
        else
        {
            TestLibrary.TestFramework.EndTestCase();
            TestLibrary.TestFramework.LogInformation("FAIL");
            return 0;
        }
    }

    public bool RunTests()
    {
        bool retVal = true;

        TestLibrary.TestFramework.LogInformation("[Positive]");
        retVal = PosTest1() && retVal;
        retVal = PosTest15() && retVal;

        TestLibrary.Utilities.CurrentCulture = EnglishCulture;
        retVal = PosTest2() && retVal;
        retVal = PosTest3() && retVal;
        retVal = PosTest5() && retVal;
        retVal = PosTest7() && retVal;
        retVal = PosTest8() && retVal;
        retVal = PosTest9() && retVal;
        retVal = PosTest10() && retVal;
        retVal = PosTest12() && retVal;
        retVal = PosTest13() && retVal;
        retVal = PosTest14() && retVal;
        TestLibrary.Utilities.CurrentCulture = CurrentCulture;

        TestLibrary.TestFramework.LogInformation("[Negative]");
        retVal = NegTest1() && retVal;
        retVal = NegTest2() && retVal;
        retVal = NegTest3() && retVal;
        retVal = NegTest4() && retVal;
        retVal = NegTest5() && retVal;

        return retVal;
    }

    public bool PosTest1()
    {
        bool     retVal = true;
        MyFormater formater = new MyFormater();
        string   dateBefore = "";
        DateTime dateAfter;

        TestLibrary.TestFramework.BeginScenario("PosTest1: DateTime.ParseExact(G, DateTime.Now)");

        try
        {
            dateBefore = DateTime.Now.ToString();

            dateAfter = DateTime.ParseExact( dateBefore, "G", formater );

            if (!dateBefore.Equals(dateAfter.ToString()))
            {
                TestLibrary.TestFramework.LogError("001", "DateTime.ParseExact(" + dateBefore + ") did not equal " + dateAfter.ToString());
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Failing date: " + dateBefore);
            TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }

    public bool PosTest2()
    {
        bool     retVal = true;
        MyFormater formater = new MyFormater();
        DateTime dateAfter;
        string   dateBefore = "";
        int      day;    // 1 - 29
        int      year;   // 1900 - 2000
        int      month;  // 1 - 12

        TestLibrary.TestFramework.BeginScenario("PosTest2: DateTime.ParseExact(d, M/d/yyyy (ShortDatePattern ex: 1/3/2002))");

        // Skipping test because format 'd' on some platforms represents the year using two digits, 
        // this cause extrange results. Some dates are shifted 1 hour backward. See DDB 173277 - MAC bug
        // Culture could be customized and dateseparator may be different than / or MM is used in the format
        if (String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.ShortDatePattern, "M/d/yyyy", StringComparison.Ordinal) != 0)
        {
            TestLibrary.TestFramework.LogInformation("Skipping test case, ShortDatePattern: " + TestLibrary.Utilities.CurrentCulture.DateTimeFormat.ShortDatePattern);
            return retVal;
        }

        try
        {
            for(int i=0; i<c_NUM_LOOPS; i++)
            {
                day    = (TestLibrary.Generator.GetInt32(-55) % 28)  + 1;
                year   = (TestLibrary.Generator.GetInt32(-55) % 100) + 1900;
                month  = (TestLibrary.Generator.GetInt32(-55) % 12)  + 1;

                dateBefore = month + "/" + day + "/" + year;
                dateAfter  = DateTime.ParseExact( dateBefore, "d", formater);

                if (month != dateAfter.Month || day != dateAfter.Day || year != dateAfter.Year)
                {
                    TestLibrary.TestFramework.LogError("003", "DateTime.ParseExact(" + dateBefore + ") did not equal " + dateAfter.ToString() + ".  Got M="+dateAfter.Month+", d="+dateAfter.Day+", y="+dateAfter.Year);
                    retVal = false;
                }
             }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Failing date: " + dateBefore);
            TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }

    public bool PosTest3()
    {
        bool     retVal = true;
        MyFormater formater = new MyFormater();
        DateTime dateAfter;
        string   dateBefore = "";
        int      dayOfWeek; // 0 - 6
        int      day;       // 1 - 28
        int      year;      // 1900 - 2000
        int      month;     // 0 - 11

        TestLibrary.TestFramework.BeginScenario("PosTest3: DateTime.ParseExact(D, dddd, MMMM dd, yyyy (LongDatePattern ex: Thursday, January 03, 2002))");
        // Culture could be customized
        if (String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongDatePattern, "dddd, MMMM dd, yyyy", StringComparison.Ordinal) != 0 &&
            String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongDatePattern, "dddd, MMMM d, yyyy", StringComparison.Ordinal) != 0)
        {
            TestLibrary.TestFramework.LogInformation("Skipping test case, LongDatePattern: " + TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongDatePattern);
            return retVal;
        }

        try
        {
            for(int i=0; i<c_NUM_LOOPS; i++)
            {
                day       = (TestLibrary.Generator.GetInt32(-55) % 27) + 1;
                year      = (TestLibrary.Generator.GetInt32(-55) % 100) + 1900;
                month     = (TestLibrary.Generator.GetInt32(-55) % 12);

		        // cheat and get day of the week
                dateAfter = DateTime.Parse( (month+1) + "/" + day + "/" + year);
                dayOfWeek = (int)dateAfter.DayOfWeek;

                // parse the date
                dateBefore = (DayOfWeek)dayOfWeek + ", " + c_MONTHS[month] + " " +
                            (String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongDatePattern, "dddd, MMMM dd, yyyy", StringComparison.Ordinal) == 0 && 10 > day ? "0" : "") + day + ", " + year;
                dateAfter  = DateTime.ParseExact( dateBefore, "D", formater );

                if ((month+1) != dateAfter.Month || day != dateAfter.Day || year != dateAfter.Year || (DayOfWeek)dayOfWeek != dateAfter.DayOfWeek)
                {
                    TestLibrary.TestFramework.LogError("005", "DateTime.ParseExact(" + dateBefore + ") did not equal (" + dateAfter.DayOfWeek + ", " + c_MONTHS[dateAfter.Month-1] + " " + dateAfter.Day + ", " + dateAfter.Year + ")");
                    retVal = false;
                }
             }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("006", "Failing date: " + dateBefore);
            TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }

    public bool PosTest5()
    {
        bool     retVal = true;
        MyFormater formater = new MyFormater();
        DateTime dateAfter;
        string   dateBefore = "";
        int      dayOfWeek; // 0 - 6
        int      day;       // 1 - 28
        int      year;      // 1900 - 2000
        int      month;     // 0 - 11
        int      hour;      // 0 - 11
        int      minute;    // 0 - 59
        int      second;    // 0 - 59
        int      timeOfDay; // 0 -1
        string[] twelveHour = new string[2] {"AM", "PM"};
        DateTime dateBeforeForValidity;

        TestLibrary.TestFramework.BeginScenario("PosTest5: DateTime.ParseExact(F, dddd, MMMM dd, yyyy h:mm:ss tt (FullDateTimePattern ex: Thursday, January 03, 2002 12:00:00 AM))");

        // Culture could be customized
        if (!((String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongDatePattern, "dddd, MMMM dd, yyyy", StringComparison.Ordinal) == 0 ||
               String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongDatePattern, "dddd, MMMM d, yyyy", StringComparison.Ordinal) == 0) && 
              (String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongTimePattern, "hh:mm:ss tt", StringComparison.Ordinal) == 0 ||
               String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongTimePattern, "h:mm:ss tt", StringComparison.Ordinal) == 0)))

        {
            TestLibrary.TestFramework.LogInformation("Skipping test case, " +
                                                     " LongDatePattern: " + TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongDatePattern +
                                                     " LongTimePattern: " + TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongTimePattern);
            return retVal;
        }

        try
        {
            for(int i=0; i<c_NUM_LOOPS; i++)
            {
                day       = (TestLibrary.Generator.GetInt32(-55) % 27) + 1;
                year      = (TestLibrary.Generator.GetInt32(-55) % 100) + 1900;
                month     = (TestLibrary.Generator.GetInt32(-55) % 12);
                hour      = (TestLibrary.Generator.GetInt32(-55) % 12);
                minute    = (TestLibrary.Generator.GetInt32(-55) % 60);
                second    = (TestLibrary.Generator.GetInt32(-55) % 60);
                timeOfDay = (TestLibrary.Generator.GetInt32(-55) % 2);

                dateBeforeForValidity = new DateTime(year, month + 1, day, hour, minute, second);

        		// cheat and get day of the week
                dateAfter = DateTime.Parse( (month+1) + "/" + day + "/" + year);
                dayOfWeek = (int)dateAfter.DayOfWeek;

                // parse the date
                dateBefore = (DayOfWeek)dayOfWeek + ", " + 
                             c_MONTHS[month] + " " +
                             (String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongDatePattern, "dddd, MMMM dd, yyyy", StringComparison.Ordinal) == 0 && 10 > day ? "0" : "") + day + ", " + 
                             year + " " +
                             (String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongTimePattern, "hh:mm:ss tt", StringComparison.Ordinal) == 0 && 10 > hour ? "0" : "") + hour + ":" + 
                             (10 > minute ? "0" : "") + minute + ":" + 
                             (10 > second ? "0" : "") + second + " " + twelveHour[timeOfDay];

                if (!TestLibrary.Utilities.IsWindows)
                {
                    dateAfter = DateTime.Parse(dateBefore);
                    TimeSpan span = dateAfter - dateAfter.ToUniversalTime();
                    String strSpan = (span.Duration()==span ? "+" : "-") + 
                        (10 > span.Duration().Hours ? "0" : "") + span.Duration().Hours + 
                        ":" + (10 > span.Minutes ? "0" : "") + span.Minutes;
                    dateBefore += " " + strSpan;
                }
                
                dateAfter  = DateTime.ParseExact( dateBefore, "F", formater );
                
                //Dev10 Bug 686124: For mac, the ambiguous and invalid points in time on the Mac
                if (false == TimeZoneInfo.Local.IsInvalidTime(dateBeforeForValidity))
                {
                    if ((month + 1) != dateAfter.Month
                           || day != dateAfter.Day
                           || year != dateAfter.Year
                           || (DayOfWeek)dayOfWeek != dateAfter.DayOfWeek
                           || (hour + timeOfDay * 12) != dateAfter.Hour
                           || minute != dateAfter.Minute
                           || second != dateAfter.Second)
                    {
                        TestLibrary.TestFramework.LogError("009", "DateTime.ParseExact(" + dateBefore + ") did not equal (" + dateAfter.DayOfWeek + ", " + c_MONTHS[dateAfter.Month - 1] + " " + dateAfter.Day + ", " + dateAfter.Year + " " + dateAfter.Hour + ":" + dateAfter.Minute + ":" + dateAfter.Second + ")");
                        retVal = false;
                    }
                }
             }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("010", "Failing date: " + dateBefore);
            TestLibrary.TestFramework.LogError("010", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }

    public bool PosTest7()
    {
        bool     retVal = true;
        MyFormater formater = new MyFormater();
        DateTime dateAfter;
        string   dateBefore = "";
        int      day;       // 1 - 28
        int      month;     // 1 - 12
        int      year;      // 1900 - 2000
        int      hour;      // 0 - 11
        int      minute;    // 0 - 59
        int      second;    // 0 - 59
        int      timeOfDay; // 0 -1
        string[] twelveHour = new string[2] {"AM", "PM"};

        DateTime dateBeforeForValidity;

        TestLibrary.TestFramework.BeginScenario("PosTest7: DateTime.ParseExact(G, ex: 1/3/2002 12:00:00 AM)");

        // Culture could be customized
        if (!(String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.ShortDatePattern, "M/d/yyyy", StringComparison.Ordinal) == 0 &&
              (String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongTimePattern, "hh:mm:ss tt", StringComparison.Ordinal) == 0 ||
               String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongTimePattern, "h:mm:ss tt", StringComparison.Ordinal) == 0)))
        {
            TestLibrary.TestFramework.LogInformation("Skipping test case, " +
                                                     " ShortDatePattern: " + TestLibrary.Utilities.CurrentCulture.DateTimeFormat.ShortDatePattern +
                                                     " LongTimePattern: " + TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongTimePattern);
            return retVal;
        }

        try
        {
            for(int i=0; i<c_NUM_LOOPS; i++)
            {
                day       = (TestLibrary.Generator.GetInt32(-55) % 27) + 1;
                year      = (TestLibrary.Generator.GetInt32(-55) % 100) + 1930;
                month     = (TestLibrary.Generator.GetInt32(-55) % 12) + 1;
                hour      = (TestLibrary.Generator.GetInt32(-55) % 12);
                minute    = (TestLibrary.Generator.GetInt32(-55) % 60);
                second    = (TestLibrary.Generator.GetInt32(-55) % 60);
                timeOfDay = (TestLibrary.Generator.GetInt32(-55) % 2);
                dateBeforeForValidity = new DateTime(year, month, day, hour, minute, second);

                // parse the date
                dateBefore =  month + "/" + + day + "/" + year + " " +
                              (String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongTimePattern, "hh:mm:ss tt", StringComparison.Ordinal) == 0 && 10 > hour ? "0" : "") + hour + ":" + 
                              (10 > minute ? "0" : "") + minute + ":" + (10 > second ? "0" : "") + second + " " + twelveHour[timeOfDay];

                if (!TestLibrary.Utilities.IsWindows)
                {
                    dateAfter = DateTime.Parse(dateBefore);
                    TimeSpan span = dateAfter - dateAfter.ToUniversalTime();
                    String strSpan = (span.Duration()==span ? "+" : "-") + 
                        (10 > span.Duration().Hours ? "0" : "") + span.Duration().Hours + 
                        ":" + (10 > span.Minutes ? "0" : "") + span.Minutes;
                    dateBefore += " " + strSpan;
                }

                dateAfter = DateTime.ParseExact(dateBefore, "G", formater);

                //Dev10 Bug 686124: For mac, the ambiguous and invalid points in time on the Mac
                if (false == TimeZoneInfo.Local.IsInvalidTime(dateBeforeForValidity))
                {
                    if (month != dateAfter.Month
                           || day != dateAfter.Day
                           || year != dateAfter.Year
                           || (hour + timeOfDay * 12) != dateAfter.Hour
                           || minute != dateAfter.Minute
                           || second != dateAfter.Second)
                    {
                        TestLibrary.TestFramework.LogError("013", "DateTime.ParseExact(" + dateBefore + ") did not equal (" + dateAfter.Month + "/" + dateAfter.Day + "/" + dateAfter.Year + " " + dateAfter.Hour + ":" + dateAfter.Minute + ":" + dateAfter.Second + ")");
                        retVal = false;
                    }
                }
             }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("014", "Failing date: " + dateBefore);
            TestLibrary.TestFramework.LogError("014", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }

    public bool PosTest8()
    {
        bool     retVal = true;
        MyFormater formater = new MyFormater();
        DateTime dateAfter;
        string   dateBefore = "";
        int      day;       // 1 - 28
        int      month;     // 0 - 11

        TestLibrary.TestFramework.BeginScenario("PosTest8: DateTime.ParseExact(m, MMMM dd (MonthDayPattern ex: January 03))");

        // Culture could be customized
        if (String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.MonthDayPattern, "MMMM dd", StringComparison.Ordinal) != 0)
        {
            TestLibrary.TestFramework.LogInformation("Skipping test case, MonthDayPattern: " + TestLibrary.Utilities.CurrentCulture.DateTimeFormat.MonthDayPattern);
            return retVal;
        }

        try
        {
            for(int i=0; i<c_NUM_LOOPS; i++)
            {
                day       = (TestLibrary.Generator.GetInt32(-55) % 27) + 1;
                month     = (TestLibrary.Generator.GetInt32(-55) % 12);

                // parse the date
                dateBefore = c_MONTHS[month] + " " + (10>day?"0":"") + day;
                dateAfter  = DateTime.ParseExact( dateBefore, "m", formater );

                if ((month+1) != dateAfter.Month 
                       || day != dateAfter.Day)
                {
                    TestLibrary.TestFramework.LogError("015", "DateTime.ParseExact(" + dateBefore + ") did not equal (" + c_MONTHS[dateAfter.Month-1] + " " + dateAfter.Day + ")");
                    retVal = false;
                }
             }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("016", "Failing date: " + dateBefore);
            TestLibrary.TestFramework.LogError("016", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }

    public bool PosTest9()
    {
        bool     retVal = true;
        MyFormater formater = new MyFormater();
        DateTime dateAfter;
        string   dateBefore = "";
        int      dayOfWeek; // 0 - 6
        int      day;       // 1 - 28
        int      year;      // 1900 - 2000
        int      month;     // 0 - 11
        int      hour;      // 12 - 23
        int      minute;    // 0 - 59
        int      second;    // 0 - 59
        DateTime dateBeforeForValidity;

        TestLibrary.TestFramework.BeginScenario("PosTest9: DateTime.ParseExact(R, ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern ex: Thu, 03 Jan 2002 00:00:00 GMT))");

        // if there is any change in RFC1123Pattern, this test case would fail. The formatting should be updated!!!
        if (String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.RFC1123Pattern, "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'", StringComparison.Ordinal) != 0)
        {
            TestLibrary.TestFramework.LogError("PosTest9", "Skipping test case, RFC1123Pattern: " + TestLibrary.Utilities.CurrentCulture.DateTimeFormat.RFC1123Pattern);
            return false;
        }

        try
        {
            for(int i=0; i<c_NUM_LOOPS; i++)
            {
                day       = (TestLibrary.Generator.GetInt32(-55) % 27) + 1;
                year      = (TestLibrary.Generator.GetInt32(-55) % 100) + 1900;
                month     = (TestLibrary.Generator.GetInt32(-55) % 12);
                hour      = (TestLibrary.Generator.GetInt32(-55) % 12) + 12;	// Parse will convert perform GMT -> PST conversion
                minute    = (TestLibrary.Generator.GetInt32(-55) % 60);
                second    = (TestLibrary.Generator.GetInt32(-55) % 60);
                dayOfWeek = (TestLibrary.Generator.GetInt32(-55) % 7);

                dateBeforeForValidity = new DateTime(year, month + 1, day, hour, minute, second);

		// cheat and get day of the week
                dateAfter = DateTime.Parse( (month+1) + "/" + day + "/" + year);
                dayOfWeek = (int)dateAfter.DayOfWeek;

                // parse the date
                dateBefore = c_DAYS_SH[dayOfWeek] + ", " + (10>day?"0":"") + day + " " + c_MONTHS_SH[month] + " " + year + " " + (10>hour?"0":"") + hour + ":" + (10>minute?"0":"") + minute + ":" + (10>second?"0":"") + second + " GMT";
                dateAfter  = DateTime.ParseExact( dateBefore, "R", formater );

                //Dev10 Bug 686124: For mac, the ambiguous and invalid points in time on the Mac
                if (false == TimeZoneInfo.Local.IsInvalidTime(dateBeforeForValidity))
                {
                    if ((month + 1) != dateAfter.Month
                           || day != dateAfter.Day
                           || year != dateAfter.Year
                           || (DayOfWeek)dayOfWeek != dateAfter.DayOfWeek
                           || minute != dateAfter.Minute
                           || second != dateAfter.Second)
                    {
                        TestLibrary.TestFramework.LogError("017", "DateTime.ParseExact(" + dateBefore + ") did not equal (" + c_DAYS_SH[(int)dateAfter.DayOfWeek] + ", " + dateAfter.Day + " " + c_MONTHS_SH[dateAfter.Month - 1] + " " + dateAfter.Year + " " + dateAfter.Hour + ":" + dateAfter.Minute + ":" + dateAfter.Second + " GMT)");
                        retVal = false;
                    }
                }
             }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("018", "Failing date: " + dateBefore);
            TestLibrary.TestFramework.LogError("018", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }

    public bool PosTest10()
    {
        bool     retVal = true;
        MyFormater formater = new MyFormater();
        DateTime dateAfter;
        string   dateBefore = "";
        int      day;       // 1 - 28
        int      month;     // 1 - 12
        int      year;      // 1900 - 2000
        int      hour;      // 0 - 23
        int      minute;    // 0 - 59
        int      second;    // 0 - 59
        DateTime dateBeforeForValidity;

        TestLibrary.TestFramework.BeginScenario("PosTest10: DateTime.ParseExact(s, yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern ex: 2002-01-03T00:00:00))");
        // if there is any change in SortableDateTimePattern, this test case would fail, The formatting should be updated!!!
        if (String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.SortableDateTimePattern, "yyyy'-'MM'-'dd'T'HH':'mm':'ss", StringComparison.Ordinal) != 0)
        {
            TestLibrary.TestFramework.LogError("PosTest10", "Skipping test case, SortableDateTimePattern: " + TestLibrary.Utilities.CurrentCulture.DateTimeFormat.SortableDateTimePattern);
            return false;
        }

        try
        {
            for(int i=0; i<c_NUM_LOOPS; i++)
            {
                day       = (TestLibrary.Generator.GetInt32(-55) % 27) + 1;
                year      = (TestLibrary.Generator.GetInt32(-55) % 100) + 1900;
                month     = (TestLibrary.Generator.GetInt32(-55) % 12) + 1;
                hour      = (TestLibrary.Generator.GetInt32(-55) % 24);
                minute    = (TestLibrary.Generator.GetInt32(-55) % 60);
                second    = (TestLibrary.Generator.GetInt32(-55) % 60);

                dateBeforeForValidity = new DateTime(year, month, day, hour, minute, second);

                // parse the date
                dateBefore = year + "-" + (10>month?"0":"") + month + "-" + (10>day?"0":"") + day + "T" + ((10 > hour) ? "0" : "") + hour + ":" + ((10 > minute) ? "0" : "") + minute + ":" + ((10 > second) ? "0" : "") + second;
                dateAfter  = DateTime.ParseExact( dateBefore, "s", formater );

                //Dev10 Bug 686124: For mac, the ambiguous and invalid points in time on the Mac
                if (false == TimeZoneInfo.Local.IsInvalidTime(dateBeforeForValidity))
                {
                    if (month != dateAfter.Month
                           || day != dateAfter.Day
                           || year != dateAfter.Year
                           || hour != dateAfter.Hour
                           || minute != dateAfter.Minute
                           || second != dateAfter.Second)
                    {
                        TestLibrary.TestFramework.LogError("019", "DateTime.ParseExact(" + dateBefore + ") did not equal (" + dateAfter.Year + "-" + dateAfter.Month + "-" + dateAfter.Day + "T" + dateAfter.Hour + ":" + dateAfter.Minute + ":" + dateAfter.Second + ")");
                        retVal = false;
                    }
                }
             }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("020", "Failing date: " + dateBefore);
            TestLibrary.TestFramework.LogError("020", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }

    public bool PosTest12()
    {
        bool     retVal = true;
        MyFormater formater = new MyFormater();
        DateTime dateAfter;
        string   dateBefore = "";
        int      hour;      // 0 - 11
        int      minute;    // 0 - 59
        int      second;    // 0 - 59
        int      timeOfDay; // 0 -1
        string[] twelveHour = new string[2] {"AM", "PM"};

        TestLibrary.TestFramework.BeginScenario("PosTest12: DateTime.ParseExact(T, h:mm:ss tt (LongTimePattern ex: 12:00:00 AM))");

        // Culture could be customized
        if (String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongTimePattern, "hh:mm:ss tt", StringComparison.Ordinal) != 0 &&
            String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongTimePattern, "h:mm:ss tt", StringComparison.Ordinal) != 0)
        {
            TestLibrary.TestFramework.LogInformation("Skipping test case, " + " LongTimePattern: " + TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongTimePattern);
            return retVal;
        }

        try
        {
            for(int i=0; i<c_NUM_LOOPS; i++)
            {
                hour      = (TestLibrary.Generator.GetInt32(-55) % 12);
                minute    = (TestLibrary.Generator.GetInt32(-55) % 60);
                second    = (TestLibrary.Generator.GetInt32(-55) % 60);
                timeOfDay = (TestLibrary.Generator.GetInt32(-55) % 2);

                // parse the date
                int newHour = hour==0?12:hour;
                dateBefore = (String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.LongTimePattern, "hh:mm:ss tt", StringComparison.Ordinal) == 0 && 10 > newHour ? "0" : "") + newHour + 
                             ":" + (10 > minute ? "0" : "") + minute + ":" + (10 > second ? "0" : "") + second + " " + twelveHour[timeOfDay];
                if (!TestLibrary.Utilities.IsWindows)
                {
                    dateAfter = DateTime.Parse(dateBefore);
                    TimeSpan span = dateAfter - dateAfter.ToUniversalTime();
                    String strSpan = (span.Duration()==span ? "+" : "-") + 
                        (10 > span.Duration().Hours ? "0" : "") + span.Duration().Hours + 
                        ":" + (10 > span.Minutes ? "0" : "") + span.Minutes;
                    dateBefore += " " + strSpan;
                }

                dateAfter = DateTime.ParseExact(dateBefore, "T", formater);

                if ((hour + timeOfDay*12) != dateAfter.Hour
                       || minute != dateAfter.Minute
                       || second != dateAfter.Second)
                {
                    TestLibrary.TestFramework.LogError("023", "DateTime.ParseExact(" + dateBefore + ") did not equal (" + dateAfter.Hour + ":" + dateAfter.Minute + ":" + dateAfter.Second + ")");
                    retVal = false;
                }
             }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("024", "Failing date: " + dateBefore);
            TestLibrary.TestFramework.LogError("024", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }

    public bool PosTest13()
    {
        bool     retVal = true;
        MyFormater formater = new MyFormater();
        DateTime dateAfter;
        string   dateBefore = "";
        int      day;       // 1 - 28
        int      month;     // 1 - 12
        int      year;      // 1900 - 2000
        int      hour;      // 12 - 23
        int      minute;    // 0 - 59
        int      second;    // 0 - 59
        DateTime dateBeforeForValidity;

        TestLibrary.TestFramework.BeginScenario("PosTest13: DateTime.ParseExact(u, yyyy'-'MM'-'dd HH':'mm':'ss'Z' (UniversalSortableDateTimePattern ex: 2002-01-03 00:00:00Z))");
        
        // if there is any change in SortableDateTimePattern, this test case would fail, The formatting should be updated!!!
        if (String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.UniversalSortableDateTimePattern, "yyyy'-'MM'-'dd HH':'mm':'ss'Z'", StringComparison.Ordinal) != 0)
        {
            TestLibrary.TestFramework.LogError("PosTest13", "Skipping test case, UniversalSortableDateTimePattern: " + TestLibrary.Utilities.CurrentCulture.DateTimeFormat.UniversalSortableDateTimePattern);
            return false;
        }

        try
        {
            for(int i=0; i<c_NUM_LOOPS; i++)
            {
                day       = (TestLibrary.Generator.GetInt32(-55) % 27) + 1;
                year      = (TestLibrary.Generator.GetInt32(-55) % 100) + 1900;
                month     = (TestLibrary.Generator.GetInt32(-55) % 12) + 1;
                hour      = (TestLibrary.Generator.GetInt32(-55) % 12) + 12;	// conversion
                minute    = (TestLibrary.Generator.GetInt32(-55) % 60);
                second    = (TestLibrary.Generator.GetInt32(-55) % 60);

                dateBeforeForValidity = new DateTime(year, month, day, hour, minute, second);

                // parse the date
                dateBefore = year + "-" + (10>month?"0":"") + month + "-" + (10>day?"0":"") + day + " " + ((10 > hour) ? "0" : "") + hour + ":" + ((10 > minute) ? "0" : "") + minute + ":" + ((10 > second) ? "0" : "") + second +"Z";
                dateAfter  = DateTime.ParseExact( dateBefore, "u", formater );

                //Dev10 Bug 686124: For mac, the ambiguous and invalid points in time on the Mac
                if (false == TimeZoneInfo.Local.IsInvalidTime(dateBeforeForValidity))
                {
                    if (month != dateAfter.Month
                           || day != dateAfter.Day
                           || year != dateAfter.Year
                           || minute != dateAfter.Minute
                           || second != dateAfter.Second)
                    {
                        TestLibrary.TestFramework.LogError("025", "DateTime.ParseExact(" + dateBefore + ") did not equal (" + dateAfter.Year + "-" + dateAfter.Month + "-" + dateAfter.Day + " " + dateAfter.Hour + ":" + dateAfter.Minute + ":" + dateAfter.Second + "Z)");
                        retVal = false;
                    }
                }
             }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("026", "Failing date: " + dateBefore);
            TestLibrary.TestFramework.LogError("026", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }

    public bool PosTest14()
    {
        bool     retVal = true;
        MyFormater formater = new MyFormater();
        DateTime dateAfter;
        string   dateBefore = "";
        int      year;      // 1900 - 2000
        int      month;     // 0 - 11

        TestLibrary.TestFramework.BeginScenario("PosTest14: DateTime.ParseExact(y, MMMM, yyyy (YearMonthPattern ex: January, 2002))");
        
        // Culture could be customized
        if (String.Compare(TestLibrary.Utilities.CurrentCulture.DateTimeFormat.YearMonthPattern, "MMMM, yyyy", StringComparison.Ordinal) != 0 )
        {
            TestLibrary.TestFramework.LogInformation("Skipping test case, YearMonthPattern: " + TestLibrary.Utilities.CurrentCulture.DateTimeFormat.YearMonthPattern);
            return retVal;
        }

        try
        {
            for(int i=0; i<c_NUM_LOOPS; i++)
            {
                year      = (TestLibrary.Generator.GetInt32(-55) % 100) + 1900;
                month     = (TestLibrary.Generator.GetInt32(-55) % 12);

                dateBefore = c_MONTHS[month] + ", " + year;
                dateAfter = DateTime.ParseExact(dateBefore, "y", formater);

                if ((month+1) != dateAfter.Month
                        || year != dateAfter.Year)
                {
                    TestLibrary.TestFramework.LogError("027", "DateTime.ParseExact(" + dateBefore + ") did not equal (" + c_MONTHS[dateAfter.Month-1] + ", " + dateAfter.Year + ")-("+dateAfter.ToString()+")-DST("+dateAfter.IsDaylightSavingTime()+")");
                    retVal = false;
                }
             }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("028", "Failing date: " + dateBefore);
            TestLibrary.TestFramework.LogError("028", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }

    public bool PosTest15()
    {
        bool     retVal = true;
        MyFormater formater = new MyFormater();
        string   dateBefore = "";
        DateTime dateAfter;

        TestLibrary.TestFramework.BeginScenario("PosTest15: DateTime.ParseExact(G, DateTime.Now, null)");

        try
        {
            dateBefore = DateTime.Now.ToString();

            dateAfter = DateTime.ParseExact( dateBefore, "G", null );

            if (!dateBefore.Equals(dateAfter.ToString()))
            {
                TestLibrary.TestFramework.LogError("101", "DateTime.ParseExact(" + dateBefore + ") did not equal " + dateAfter.ToString());
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("102", "Failing date: " + dateBefore);
            TestLibrary.TestFramework.LogError("102", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }

    public bool NegTest1()
    {
        bool      retVal = true;
        MyFormater formater = new MyFormater();

        TestLibrary.TestFramework.BeginScenario("NegTest1: DateTime.ParseExact(null)");

        try
        {
            DateTime.ParseExact(null, "d", formater);

            TestLibrary.TestFramework.LogError("029", "DateTime.ParseExact(null) should have thrown");
            retVal = false;
        }
        catch (ArgumentNullException)
        {
            // expected
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("030", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }

    public bool NegTest2()
    {
        bool      retVal = true;
        MyFormater formater = new MyFormater();

        TestLibrary.TestFramework.BeginScenario("NegTest2: DateTime.ParseExact(String.Empty)");

        try
        {
            DateTime.ParseExact(String.Empty, "d", formater);

            TestLibrary.TestFramework.LogError("031", "DateTime.ParseExact(String.Empty) should have thrown");
            retVal = false;
        }
        catch (FormatException)
        {
            // expected
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("032", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }

    public bool NegTest3()
    {
        bool   retVal = true;
        MyFormater formater = new MyFormater();
        string strDateTime = "";
        DateTime dateAfter;
        string[] formats = new string[17] {"d", "D", "f", "F", "g", "G", "m", "M", "r", "R", "s", "t", "T", "u", "U", "y", "Y"};
        string   format;
        int      formatIndex;
       

        TestLibrary.TestFramework.BeginScenario("NegTest3: DateTime.ParseExact(<garbage>)");

        try
        {
            for (int i=0; i<c_NUM_LOOPS; i++)
            {
                try
                {
                    formatIndex = TestLibrary.Generator.GetInt32(-55) % 34;

                    if (0 <= formatIndex && formatIndex < 17)
                    {
                        format = formats[formatIndex];
                    }
                    else
                    {
                        format = TestLibrary.Generator.GetChar(-55) + "";
                    }

                    strDateTime = TestLibrary.Generator.GetString(-55, false, c_MIN_STRING_LEN, c_MAX_STRING_LEN);
                    dateAfter = DateTime.ParseExact(strDateTime, format, formater);

                    TestLibrary.TestFramework.LogError("033", "DateTime.ParseExact(" + strDateTime + ", "+ format + ") should have thrown (" + dateAfter + ")");
                    retVal = false;
                }
                catch (FormatException)
                {
                    // expected
                }
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("034", "Failing date: " + strDateTime);
            TestLibrary.TestFramework.LogError("034", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }

    public bool NegTest4()
    {
        bool     retVal = true;
        MyFormater formater = new MyFormater();
        string   dateBefore = "";
        DateTime dateAfter;

        TestLibrary.TestFramework.BeginScenario("NegTest4: DateTime.ParseExact(\"\", DateTime.Now, formater)");

        try
        {
            dateBefore = DateTime.Now.ToString();

            dateAfter = DateTime.ParseExact( dateBefore, "", formater );

            TestLibrary.TestFramework.LogError("103", "DateTime.ParseExact(" + dateBefore + ") should have thrown " + dateAfter.ToString());
            retVal = false;
        }
        catch (System.FormatException)
        {
            // expected
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("104", "Failing date: " + dateBefore);
            TestLibrary.TestFramework.LogError("104", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }

    public bool NegTest5()
    {
        bool     retVal = true;
        MyFormater formater = new MyFormater();
        string   dateBefore = "";
        DateTime dateAfter;

        TestLibrary.TestFramework.BeginScenario("NegTest5: DateTime.ParseExact(null, DateTime.Now, formater)");

        try
        {
            dateBefore = DateTime.Now.ToString();

            dateAfter = DateTime.ParseExact( dateBefore, null, formater );

            TestLibrary.TestFramework.LogError("105", "DateTime.ParseExact(" + dateBefore + ") should have thrown " + dateAfter.ToString());
            retVal = false;
        }
        catch (System.ArgumentNullException)
        {
            // expected
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("106", "Failing date: " + dateBefore);
            TestLibrary.TestFramework.LogError("106", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }
}

public class MyFormater : IFormatProvider
{
    public object GetFormat(Type formatType)
    {
        if (typeof(IFormatProvider) == formatType)
        {
            return this;
        }
        else
        {
            return null;
        }
    }
}