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