1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // REQUIRES: locale.en_US.UTF-8
11 // REQUIRES: locale.fr_FR.UTF-8
12 // REQUIRES: locale.ru_RU.UTF-8
13 // REQUIRES: locale.zh_CN.UTF-8
14
15 // GLIBC Expects "10/06/2009" for fr_FR as opposed to "10.06.2009"
16 // GLIBC also failes on the zh_CN test.
17 // XFAIL: linux
18
19 // <locale>
20
21 // class time_get_byname<charT, InputIterator>
22
23 // iter_type
24 // get_date(iter_type s, iter_type end, ios_base& str,
25 // ios_base::iostate& err, tm* t) const;
26
27 #include <locale>
28 #include <cassert>
29 #include "test_iterators.h"
30
31 #include "platform_support.h" // locale name macros
32
33 typedef input_iterator<const char*> I;
34
35 typedef std::time_get_byname<char, I> F;
36
37 class my_facet
38 : public F
39 {
40 public:
my_facet(const std::string & nm,std::size_t refs=0)41 explicit my_facet(const std::string& nm, std::size_t refs = 0)
42 : F(nm, refs) {}
43 };
44
main()45 int main()
46 {
47 std::ios ios(0);
48 std::ios_base::iostate err;
49 std::tm t;
50 {
51 const my_facet f(LOCALE_en_US_UTF_8, 1);
52 const char in[] = "06/10/2009";
53 err = std::ios_base::goodbit;
54 t = std::tm();
55 I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
56 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
57 assert(t.tm_mon == 5);
58 assert(t.tm_mday == 10);
59 assert(t.tm_year == 109);
60 assert(err == std::ios_base::eofbit);
61 }
62 {
63 const my_facet f(LOCALE_fr_FR_UTF_8, 1);
64 const char in[] = "10.06.2009";
65 err = std::ios_base::goodbit;
66 t = std::tm();
67 I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
68 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
69 assert(t.tm_mon == 5);
70 assert(t.tm_mday == 10);
71 assert(t.tm_year == 109);
72 assert(err == std::ios_base::eofbit);
73 }
74 {
75 const my_facet f(LOCALE_ru_RU_UTF_8, 1);
76 const char in[] = "10.06.2009";
77 err = std::ios_base::goodbit;
78 t = std::tm();
79 I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
80 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
81 assert(t.tm_mon == 5);
82 assert(t.tm_mday == 10);
83 assert(t.tm_year == 109);
84 assert(err == std::ios_base::eofbit);
85 }
86
87 {
88 const my_facet f(LOCALE_zh_CN_UTF_8, 1);
89 const char in[] = "2009/06/10";
90 err = std::ios_base::goodbit;
91 t = std::tm();
92 I i = f.get_date(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t);
93 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
94 assert(t.tm_mon == 5);
95 assert(t.tm_mday == 10);
96 assert(t.tm_year == 109);
97 assert(err == std::ios_base::eofbit);
98 }
99 }
100