]>
Commit | Line | Data |
---|---|---|
52066eae | 1 | // { dg-do run { target c++11 } } |
e869c090 RS |
2 | |
3 | // 2014-04-14 Rüdiger Sonderfeld <ruediger@c-plusplus.de> | |
4 | ||
a5544970 | 5 | // Copyright (C) 2014-2019 Free Software Foundation, Inc. |
e869c090 RS |
6 | // |
7 | // This file is part of the GNU ISO C++ Library. This library is free | |
8 | // software; you can redistribute it and/or modify it under the | |
9 | // terms of the GNU General Public License as published by the | |
10 | // Free Software Foundation; either version 3, or (at your option) | |
11 | // any later version. | |
12 | ||
13 | // This library is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | ||
18 | // You should have received a copy of the GNU General Public License along | |
19 | // with this library; see the file COPYING3. If not see | |
20 | // <http://www.gnu.org/licenses/>. | |
21 | ||
22 | // 22.4.5.1.1 (C++11) time_get members [locale.time.get.members] | |
23 | ||
24 | #include <locale> | |
25 | #include <sstream> | |
26 | #include <iterator> | |
27 | #include <testsuite_hooks.h> | |
28 | ||
118c8424 | 29 | #ifdef TEST_TIMEGET_VERBOSE |
e869c090 RS |
30 | # include <iostream> |
31 | # define PRINT(x) cout << #x << ": " << x << endl | |
32 | # define TESTHEAD(x) cout << x << endl | |
33 | #else | |
34 | # define PRINT(x) do {} while(false) | |
35 | # define TESTHEAD(x) do {} while(false) | |
36 | #endif | |
37 | ||
38 | void test01() | |
39 | { | |
40 | using namespace std; | |
e869c090 RS |
41 | |
42 | locale loc_c = locale::classic(); | |
43 | ||
44 | istringstream iss; | |
45 | iss.imbue(loc_c); | |
46 | const time_get<char>& tget = use_facet<time_get<char>>(iss.getloc()); | |
47 | typedef istreambuf_iterator<char> iter; | |
48 | const iter end; | |
49 | ||
50 | tm time; | |
51 | ios_base::iostate err = ios_base::badbit; | |
52 | ||
53 | // check regular operations with format string | |
54 | TESTHEAD("regular operations"); | |
55 | iss.str("d 2014-04-14 01:09:35"); | |
56 | string format = "d %Y-%m-%d %H:%M:%S"; | |
57 | auto ret = tget.get(iter(iss), end, iss, err, &time, | |
58 | format.data(), format.data()+format.size()); | |
59 | PRINT(err); | |
60 | VERIFY(err == ios_base::eofbit); | |
61 | VERIFY(ret == end); | |
62 | PRINT(time.tm_year); | |
63 | VERIFY(time.tm_year == 114); | |
64 | PRINT(time.tm_mon); | |
65 | VERIFY(time.tm_mon == 3); | |
66 | PRINT(time.tm_mday); | |
67 | VERIFY(time.tm_mday == 14); | |
68 | PRINT(time.tm_hour); | |
69 | VERIFY(time.tm_hour == 1); | |
70 | PRINT(time.tm_min); | |
71 | VERIFY(time.tm_min == 9); | |
72 | PRINT(time.tm_sec); | |
73 | VERIFY(time.tm_sec == 35); | |
74 | ||
75 | TESTHEAD("check eof"); | |
76 | iss.str("2020 "); | |
77 | format = "%Y"; | |
78 | ret = tget.get(iter(iss), end, iss, err, &time, | |
79 | format.data(), format.data()+format.size()); | |
80 | VERIFY(err != ios_base::eofbit); | |
81 | VERIFY(time.tm_year == 120); | |
82 | VERIFY(ret != end); | |
83 | ||
84 | TESTHEAD("check broken format"); | |
85 | iss.str("2014-04-14 01:09:35"); | |
86 | format = "%"; | |
87 | ret = tget.get(iter(iss), end, iss, err, &time, | |
88 | format.data(), format.data()+format.size()); | |
89 | VERIFY(err == ios_base::failbit); | |
90 | ||
91 | TESTHEAD("check single format letter version"); | |
92 | iss.str("2020"); | |
93 | ret = tget.get(iter(iss), end, iss, err, &time, 'Y'); | |
94 | VERIFY(err == ios_base::eofbit); | |
95 | VERIFY(time.tm_year == 120); | |
96 | VERIFY(ret == end); | |
97 | ||
98 | TESTHEAD("check skipping of space"); | |
99 | iss.str("2010 07 01"); | |
100 | format = "%Y %m %d"; | |
101 | ret = tget.get(iter(iss), end, iss, err, &time, | |
102 | format.data(), format.data()+format.size()); | |
103 | VERIFY(err == ios_base::eofbit); | |
104 | VERIFY(time.tm_year == 110); | |
105 | VERIFY(time.tm_mon == 6); | |
106 | VERIFY(time.tm_mday == 1); | |
107 | VERIFY(ret == end); | |
108 | ||
109 | TESTHEAD("check mismatch"); | |
110 | iss.str("year: 1970"); | |
111 | format = "jahr: %Y"; | |
112 | ret = tget.get(iter(iss), end, iss, err, &time, | |
113 | format.data(), format.data()+format.size()); | |
114 | VERIFY(err == ios_base::failbit); | |
115 | VERIFY(ret == iter(iss)); | |
116 | ||
117 | TESTHEAD("check case insensitive match"); | |
118 | iss.str("yEaR: 1980"); | |
119 | format = "YeAR: %Y"; | |
120 | ret = tget.get(iter(iss), end, iss, err, &time, | |
121 | format.data(), format.data()+format.size()); | |
122 | VERIFY(err == ios_base::eofbit); | |
123 | VERIFY(ret == end); | |
124 | VERIFY(time.tm_year == 80); | |
125 | } | |
126 | ||
127 | int main() | |
128 | { | |
129 | test01(); | |
130 | return 0; | |
131 | } |