]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/time_get/get/char/1.cc
1 // { dg-do run { target c++11 } }
3 // 2014-04-14 RĂ¼diger Sonderfeld <ruediger@c-plusplus.de>
5 // Copyright (C) 2014-2020 Free Software Foundation, Inc.
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)
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.
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/>.
22 // 22.4.5.1.1 (C++11) time_get members [locale.time.get.members]
27 #include <testsuite_hooks.h>
29 #ifdef TEST_TIMEGET_VERBOSE
31 # define PRINT(x) cout << #x << ": " << x << endl
32 # define TESTHEAD(x) cout << x << endl
34 # define PRINT(x) do {} while(false)
35 # define TESTHEAD(x) do {} while(false)
42 locale loc_c
= locale::classic();
46 const time_get
<char>& tget
= use_facet
<time_get
<char>>(iss
.getloc());
47 typedef istreambuf_iterator
<char> iter
;
51 ios_base::iostate err
= ios_base::badbit
;
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());
60 VERIFY(err
== ios_base::eofbit
);
63 VERIFY(time
.tm_year
== 114);
65 VERIFY(time
.tm_mon
== 3);
67 VERIFY(time
.tm_mday
== 14);
69 VERIFY(time
.tm_hour
== 1);
71 VERIFY(time
.tm_min
== 9);
73 VERIFY(time
.tm_sec
== 35);
75 TESTHEAD("check eof");
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);
84 TESTHEAD("check broken format");
85 iss
.str("2014-04-14 01:09:35");
87 ret
= tget
.get(iter(iss
), end
, iss
, err
, &time
,
88 format
.data(), format
.data()+format
.size());
89 VERIFY(err
== ios_base::failbit
);
91 TESTHEAD("check single format letter version");
93 ret
= tget
.get(iter(iss
), end
, iss
, err
, &time
, 'Y');
94 VERIFY(err
== ios_base::eofbit
);
95 VERIFY(time
.tm_year
== 120);
98 TESTHEAD("check skipping of space");
99 iss
.str("2010 07 01");
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);
109 TESTHEAD("check mismatch");
110 iss
.str("year: 1970");
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
));
117 TESTHEAD("check case insensitive match");
118 iss
.str("yEaR: 1980");
120 ret
= tget
.get(iter(iss
), end
, iss
, err
, &time
,
121 format
.data(), format
.data()+format
.size());
122 VERIFY(err
== ios_base::eofbit
);
124 VERIFY(time
.tm_year
== 80);