Debian Codegraph @

libstdc++-v3/testsuite/22_locale/time_get/get_year/char/6.cc

raw symbols SCIP
1 // Copyright (C) 2001-2025 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // 22.2.5.1.1 time_get members
19
20 #include <locale>
21 #include <sstream>
22 #include <testsuite_hooks.h>
23
24 void test01()
25 {
26 using namespace std;
27
28 typedef istreambuf_iterator<char> iterator_type;
29
30 locale loc_c = locale::classic();
31
32 iterator_type end;
33
34 istringstream iss;
35 iss.imbue(loc_c);
36 const time_get<char>& tim_get = use_facet<time_get<char> >(iss.getloc());
37 ios_base::iostate errorstate = ios_base::goodbit;
38
39 iss.str("69");
40 iterator_type is_it01(iss);
41 tm time01;
42 tim_get.get_year(is_it01, end, iss, errorstate, &time01);
43 VERIFY( time01.tm_year == 1969 - 1900 );
44 VERIFY( errorstate == ios_base::eofbit );
45
46 iss.str("68 ");
47 iterator_type is_it02(iss);
48 tm time02;
49 errorstate = ios_base::goodbit;
50 iterator_type ret02 = tim_get.get_year(is_it02, end, iss, errorstate,
51 &time02);
52 VERIFY( time02.tm_year == 2068 - 1900 );
53 VERIFY( errorstate == ios_base::goodbit );
54 VERIFY( *ret02 == ' ' );
55
56 iss.str("0069");
57 iterator_type is_it03(iss);
58 tm time03;
59 errorstate = ios_base::goodbit;
60 iterator_type ret03 = tim_get.get_year(is_it03, end, iss, errorstate,
61 &time03);
62 VERIFY( time03.tm_year == 69 - 1900 );
63 VERIFY( errorstate == ios_base::eofbit );
64
65 iss.str("0068");
66 iterator_type is_it04(iss);
67 tm time04;
68 errorstate = ios_base::goodbit;
69 iterator_type ret04 = tim_get.get_year(is_it04, end, iss, errorstate,
70 &time04);
71 VERIFY( time04.tm_year == 68 - 1900 );
72 VERIFY( errorstate == ios_base::eofbit );
73 }
74
75 int main()
76 {
77 test01();
78 return 0;
79 }