Debian Codegraph @

libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/08.cc

raw
1 // Copyright (C) 2004-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 // 27.6.1.2.2 arithmetic extractors
19
20 #include <istream>
21 #include <sstream>
22 #include <locale>
23 #include <testsuite_hooks.h>
24
25 namespace std {
26 class test_numpunct2 : public numpunct<wchar_t>
27 {
28 protected:
29 string
30 do_grouping() const
31 { return string("\002\003"); }
32 };
33 } // namespace std
34
35 void test08()
36 {
37 // manufactured locale, grouping is turned on
38 unsigned int h4 = 0, h3 = 0, h2 = 0;
39 const std::wstring s1(L"1,22 205,19 22,123,22");
40
41 std::wistringstream is(s1);
42 is.imbue(std::locale(std::locale(), new std::test_numpunct2));
43
44 // Basic operation.
45 is >> h4;
46 VERIFY( h4 == 122 );
47 VERIFY( is.good() );
48
49 is.clear();
50 is >> h3;
51 VERIFY( h3 == 20519 );
52 VERIFY( is.good() );
53
54 is.clear();
55 is >> h2;
56 VERIFY( h2 == 2212322 );
57 VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) );
58 }
59
60 int main()
61 {
62 test08();
63 return 0;
64 }