]>
Commit | Line | Data |
---|---|---|
a5b4ebc2 JJ |
1 | // { dg-do run { target c++11 } } |
2 | ||
7adcbafe | 3 | // Copyright (C) 2021-2022 Free Software Foundation, Inc. |
a5b4ebc2 JJ |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
8 | // Free Software Foundation; either version 3, or (at your option) | |
9 | // any later version. | |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License along | |
17 | // with this library; see the file COPYING3. If not see | |
18 | // <http://www.gnu.org/licenses/>. | |
19 | ||
20 | #include <locale> | |
21 | #include <sstream> | |
22 | #include <iterator> | |
23 | #include <testsuite_hooks.h> | |
24 | ||
25 | void | |
26 | test01() | |
27 | { | |
28 | using namespace std; | |
29 | ||
30 | locale loc_c = locale::classic(); | |
31 | ||
32 | wistringstream iss; | |
33 | iss.imbue(loc_c); | |
34 | const time_get<wchar_t>& tget = use_facet<time_get<wchar_t>>(iss.getloc()); | |
35 | typedef istreambuf_iterator<wchar_t> iter; | |
36 | const iter end; | |
37 | ||
38 | tm time; | |
39 | ios_base::iostate err = ios_base::badbit; | |
40 | ||
41 | iss.str(L"20:48:01 MAR 31 2016"); | |
42 | wstring format = L"%H:%M:%S %b %d %Y"; | |
43 | auto ret = tget.get(iter(iss), end, iss, err, &time, | |
44 | format.data(), format.data()+format.size()); | |
45 | VERIFY( err == ios_base::eofbit ); | |
46 | VERIFY( ret == end ); | |
47 | VERIFY( time.tm_year == 2016 - 1900 ); | |
48 | VERIFY( time.tm_mon == 2 ); | |
49 | VERIFY( time.tm_mday == 31 ); | |
50 | VERIFY( time.tm_hour == 20 ); | |
51 | VERIFY( time.tm_min == 48 ); | |
52 | VERIFY( time.tm_sec == 01 ); | |
53 | ||
54 | iss.str(L"21:38:11 apr 30 2017"); | |
55 | ret = tget.get(iter(iss), end, iss, err, &time, | |
56 | format.data(), format.data()+format.size()); | |
57 | VERIFY( err == ios_base::eofbit ); | |
58 | VERIFY( ret == end ); | |
59 | VERIFY( time.tm_year == 2017 - 1900 ); | |
60 | VERIFY( time.tm_mon == 3 ); | |
61 | VERIFY( time.tm_mday == 30 ); | |
62 | VERIFY( time.tm_hour == 21 ); | |
63 | VERIFY( time.tm_min == 38 ); | |
64 | VERIFY( time.tm_sec == 11 ); | |
65 | ||
66 | iss.str(L"22:28:21 mAy 29 2018"); | |
67 | ret = tget.get(iter(iss), end, iss, err, &time, | |
68 | format.data(), format.data()+format.size()); | |
69 | VERIFY( err == ios_base::eofbit ); | |
70 | VERIFY( ret == end ); | |
71 | VERIFY( time.tm_year == 2018 - 1900 ); | |
72 | VERIFY( time.tm_mon == 4 ); | |
73 | VERIFY( time.tm_mday == 29 ); | |
74 | VERIFY( time.tm_hour == 22 ); | |
75 | VERIFY( time.tm_min == 28 ); | |
76 | VERIFY( time.tm_sec == 21 ); | |
77 | ||
78 | iss.str(L"23:18:31 JuN 28 2019"); | |
79 | ret = tget.get(iter(iss), end, iss, err, &time, | |
80 | format.data(), format.data()+format.size()); | |
81 | VERIFY( err == ios_base::eofbit ); | |
82 | VERIFY( ret == end ); | |
83 | VERIFY( time.tm_year == 2019 - 1900 ); | |
84 | VERIFY( time.tm_mon == 5 ); | |
85 | VERIFY( time.tm_mday == 28 ); | |
86 | VERIFY( time.tm_hour == 23 ); | |
87 | VERIFY( time.tm_min == 18 ); | |
88 | VERIFY( time.tm_sec == 31 ); | |
89 | } | |
90 | ||
91 | int | |
92 | main() | |
93 | { | |
94 | test01(); | |
95 | return 0; | |
96 | } |