]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/time_get/get/char/2.cc
[committed] [RISC-V] Fix false-positive uninitialized variable
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / time_get / get / char / 2.cc
1 // { dg-do run { target c++11 } }
2 // { dg-require-namedlocale "de_DE.UTF-8" }
3
4 // 2014-04-14 RĂ¼diger Sonderfeld <ruediger@c-plusplus.de>
5
6 // Copyright (C) 2014-2024 Free Software Foundation, Inc.
7 //
8 // This file is part of the GNU ISO C++ Library. This library is free
9 // software; you can redistribute it and/or modify it under the
10 // terms of the GNU General Public License as published by the
11 // Free Software Foundation; either version 3, or (at your option)
12 // any later version.
13
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18
19 // You should have received a copy of the GNU General Public License along
20 // with this library; see the file COPYING3. If not see
21 // <http://www.gnu.org/licenses/>.
22
23 // 22.4.5.1.1 (C++11) time_get members [locale.time.get.members]
24
25 #include <locale>
26 #include <sstream>
27 #include <testsuite_hooks.h>
28
29 #ifdef TEST_TIMEGET_VERBOSE
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 test02()
39 {
40 using namespace std;
41
42 locale loc_c = locale::classic();
43 locale loc_de = locale("de_DE.UTF-8");
44 VERIFY( loc_de != loc_c );
45
46 istringstream iss;
47 iss.imbue(loc_de);
48 const time_get<char>& tget = use_facet<time_get<char>>(iss.getloc());
49 typedef istreambuf_iterator<char> iter;
50 const iter end;
51
52 ios_base::iostate err;
53 tm time;
54
55 TESTHEAD("German locale test");
56 iss.str("Montag, den 14. April 2014");
57 string format = "%A, den %d. %B %Y";
58 auto ret = tget.get(iter(iss), end, iss, err, &time,
59 format.data(), format.data()+format.size());
60 PRINT(err);
61 VERIFY(err == ios_base::eofbit);
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_wday);
67 VERIFY(time.tm_wday == 1);
68 PRINT(time.tm_mday);
69 VERIFY(time.tm_mday == 14);
70 VERIFY(end == end);
71
72 TESTHEAD("German locale: Check case-insensitivity");
73 tm time2;
74 iss.str("Montag, den 14. April 2014");
75 format = "%A, DEN %d. %B %Y"; // check case-insensitivity
76 ret = tget.get(iter(iss), end, iss, err, &time2,
77 format.data(), format.data()+format.size());
78 PRINT(err);
79 VERIFY(err == ios_base::eofbit);
80 PRINT(time2.tm_year);
81 VERIFY(time2.tm_year == 114);
82 PRINT(time2.tm_mon);
83 VERIFY(time2.tm_mon == 3);
84 PRINT(time2.tm_wday);
85 VERIFY(time2.tm_wday == 1);
86 PRINT(time2.tm_mday);
87 VERIFY(time2.tm_mday == 14);
88 VERIFY(end == end);
89
90 TESTHEAD("German locale: Check single");
91 iss.str("Mittwoch");
92 ret = tget.get(iter(iss), end, iss, err, &time, 'A');
93 PRINT(err);
94 VERIFY(err == ios_base::eofbit);
95 PRINT(time.tm_wday);
96 VERIFY(time.tm_wday == 3);
97 VERIFY(end == end);
98 }
99
100 int main()
101 {
102 test02();
103 }