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 // <locale>
16
17 // class time_get_byname<charT, InputIterator>
18
19 // iter_type get(iter_type s, iter_type end, ios_base& f,
20 // ios_base::iostate& err, tm *t, char format, char modifier = 0) const;
21
22 // TODO: investigation needed
23 // XFAIL: linux-gnu
24
25 #include <locale>
26 #include <cassert>
27 #include "test_iterators.h"
28
29 #include "platform_support.h" // locale name macros
30
31 typedef input_iterator<const wchar_t*> I;
32
33 typedef std::time_get_byname<wchar_t, I> F;
34
35 class my_facet
36 : public F
37 {
38 public:
my_facet(const std::string & nm,std::size_t refs=0)39 explicit my_facet(const std::string& nm, std::size_t refs = 0)
40 : F(nm, refs) {}
41 };
42
main()43 int main()
44 {
45 std::ios ios(0);
46 std::ios_base::iostate err;
47 std::tm t;
48 {
49 const my_facet f(LOCALE_en_US_UTF_8, 1);
50 const wchar_t in[] = L"Sat Dec 31 23:55:59 2061";
51 err = std::ios_base::goodbit;
52 t = std::tm();
53 I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'c');
54 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
55 assert(t.tm_sec == 59);
56 assert(t.tm_min == 55);
57 assert(t.tm_hour == 23);
58 assert(t.tm_mday == 31);
59 assert(t.tm_mon == 11);
60 assert(t.tm_year == 161);
61 assert(t.tm_wday == 6);
62 assert(err == std::ios_base::eofbit);
63 }
64 {
65 const my_facet f(LOCALE_en_US_UTF_8, 1);
66 const wchar_t in[] = L"23:55:59";
67 err = std::ios_base::goodbit;
68 t = std::tm();
69 I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'X');
70 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
71 assert(t.tm_sec == 59);
72 assert(t.tm_min == 55);
73 assert(t.tm_hour == 23);
74 assert(err == std::ios_base::eofbit);
75 }
76 {
77 const my_facet f(LOCALE_fr_FR_UTF_8, 1);
78 const wchar_t in[] = L"Sam 31 d""\xE9""c 23:55:59 2061";
79 err = std::ios_base::goodbit;
80 t = std::tm();
81 I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'c');
82 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
83 assert(t.tm_sec == 59);
84 assert(t.tm_min == 55);
85 assert(t.tm_hour == 23);
86 assert(t.tm_mday == 31);
87 assert(t.tm_mon == 11);
88 assert(t.tm_year == 161);
89 assert(t.tm_wday == 6);
90 assert(err == std::ios_base::eofbit);
91 }
92 {
93 const my_facet f(LOCALE_fr_FR_UTF_8, 1);
94 const wchar_t in[] = L"23:55:59";
95 err = std::ios_base::goodbit;
96 t = std::tm();
97 I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'X');
98 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
99 assert(t.tm_sec == 59);
100 assert(t.tm_min == 55);
101 assert(t.tm_hour == 23);
102 assert(err == std::ios_base::eofbit);
103 }
104 #ifdef __APPLE__
105 {
106 const my_facet f("ru_RU", 1);
107 const wchar_t in[] = L"\x441\x443\x431\x431\x43E\x442\x430"
108 ", 31 "
109 "\x434\x435\x43A\x430\x431\x440\x44F"
110 " 2061 "
111 "\x433"
112 ". 23:55:59";
113 err = std::ios_base::goodbit;
114 t = std::tm();
115 I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'c');
116 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
117 assert(t.tm_sec == 59);
118 assert(t.tm_min == 55);
119 assert(t.tm_hour == 23);
120 assert(t.tm_mday == 31);
121 assert(t.tm_mon == 11);
122 assert(t.tm_year == 161);
123 assert(t.tm_wday == 6);
124 assert(err == std::ios_base::eofbit);
125 }
126 #endif
127 {
128 const my_facet f(LOCALE_ru_RU_UTF_8, 1);
129 const wchar_t in[] = L"23:55:59";
130 err = std::ios_base::goodbit;
131 t = std::tm();
132 I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'X');
133 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
134 assert(t.tm_sec == 59);
135 assert(t.tm_min == 55);
136 assert(t.tm_hour == 23);
137 assert(err == std::ios_base::eofbit);
138 }
139 #ifdef __APPLE__
140 {
141 const my_facet f("zh_CN", 1);
142 const wchar_t in[] = L"\x516D"
143 " 12/31 23:55:59 2061";
144 err = std::ios_base::goodbit;
145 t = std::tm();
146 I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'c');
147 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
148 assert(t.tm_sec == 59);
149 assert(t.tm_min == 55);
150 assert(t.tm_hour == 23);
151 assert(t.tm_mday == 31);
152 assert(t.tm_mon == 11);
153 assert(t.tm_year == 161);
154 assert(t.tm_wday == 6);
155 assert(err == std::ios_base::eofbit);
156 }
157 #endif
158 {
159 const my_facet f(LOCALE_zh_CN_UTF_8, 1);
160 const wchar_t in[] = L"23""\x65F6""55""\x5206""59""\x79D2";
161 err = std::ios_base::goodbit;
162 t = std::tm();
163 I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'X');
164 assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
165 assert(t.tm_sec == 59);
166 assert(t.tm_min == 55);
167 assert(t.tm_hour == 23);
168 assert(err == std::ios_base::eofbit);
169 }
170 }
171