Debian Codegraph @

libstdc++-v3/testsuite/27_io/manipulators/adjustfield/char/1.cc

raw
1 // 981027 ncm work with libstdc++v3
2
3 // Copyright (C) 1997-2025 Free Software Foundation, Inc.
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
21 #include <sstream>
22 #include <locale>
23 #include <iomanip>
24 #include <testsuite_hooks.h>
25
26 struct MyNP : std::numpunct<char>
27 {
28 std::string do_truename() const;
29 std::string do_falsename() const;
30 };
31
32 std::string
33 MyNP::do_truename() const
34 {
35 std::string s("yea");
36 return s;
37 }
38
39 std::string
40 MyNP::do_falsename() const
41 {
42 std::string s("nay");
43 return s;
44 }
45
46 void
47 test01()
48 {
49 const char lit[] = "1 0\n"
50 "true false\n"
51 ": true:\n"
52 ":true :\n"
53 ": false:\n"
54 ": 1:\n"
55 ":1 :\n"
56 ": 0:\n"
57 "yea nay\n"
58 ": yea:\n"
59 ":yea :\n"
60 ": nay:\n";
61
62 std::ostringstream oss;
63 oss << true << " " << false << std::endl;
64 oss << std::boolalpha;
65 oss << true << " " << false << std::endl;
66
67 oss << ":" << std::setw(6) << std::internal << true << ":" << std::endl;
68 oss << ":" << std::setw(6) << std::left << true << ":" << std::endl;
69 oss << ":" << std::setw(6) << std::right << false << ":" << std::endl;
70 oss << std::noboolalpha;
71 oss << ":" << std::setw(3) << std::internal << true << ":" << std::endl;
72 oss << ":" << std::setw(3) << std::left << true << ":" << std::endl;
73 oss << ":" << std::setw(3) << std::right << false << ":" << std::endl;
74
75 std::locale loc = std::locale(std::locale::classic(), new MyNP);
76 oss.imbue(loc);
77
78 oss << std::boolalpha;
79 oss << true << " " << false << std::endl;
80
81 oss << ":" << std::setw(6) << std::internal << true << ":" << std::endl;
82 oss << ":" << std::setw(6) << std::left << true << ":" << std::endl;
83 oss << ":" << std::setw(6) << std::right << false << ":" << std::endl;
84
85 VERIFY( oss.good() );
86 VERIFY( oss.str() == lit );
87 }
88
89 int
90 main()
91 {
92 test01();
93 return 0;
94 }