| 1 | // Copyright (C) 2008-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.2.2.1 num_put members |
| 19 | |
| 20 | #include <locale> |
| 21 | #include <sstream> |
| 22 | #include <testsuite_hooks.h> |
| 23 | |
| 24 | class my_punct : public std::numpunct<char> |
| 25 | { |
| 26 | protected: |
| 27 | std::string do_falsename() const { return "-no-"; } |
| 28 | }; |
| 29 | |
| 30 | // libstdc++/38196 |
| 31 | void test01() |
| 32 | { |
| 33 | using namespace std; |
| 34 | |
| 35 | ostringstream oss1, oss2, oss3, oss4; |
| 36 | string result1, result2, result3, result4; |
| 37 | |
| 38 | oss1.imbue(locale(oss1.getloc(), new my_punct)); |
| 39 | oss2.imbue(locale(oss2.getloc(), new my_punct)); |
| 40 | oss3.imbue(locale(oss3.getloc(), new my_punct)); |
| 41 | oss4.imbue(locale(oss4.getloc(), new my_punct)); |
| 42 | const num_put<char>& ng1 = use_facet<num_put<char> >(oss1.getloc()); |
| 43 | const num_put<char>& ng2 = use_facet<num_put<char> >(oss2.getloc()); |
| 44 | const num_put<char>& ng3 = use_facet<num_put<char> >(oss3.getloc()); |
| 45 | const num_put<char>& ng4 = use_facet<num_put<char> >(oss4.getloc()); |
| 46 | |
| 47 | oss1.width(6); |
| 48 | oss1.setf(ios_base::boolalpha); |
| 49 | ng1.put(oss1.rdbuf(), oss1, '*', false); |
| 50 | result1 = oss1.str(); |
| 51 | VERIFY( result1 == "**-no-" ); |
| 52 | |
| 53 | oss2.width(6); |
| 54 | oss2.setf(ios_base::right, ios_base::adjustfield); |
| 55 | oss2.setf(ios_base::boolalpha); |
| 56 | ng2.put(oss2.rdbuf(), oss2, '*', false); |
| 57 | result2 = oss2.str(); |
| 58 | VERIFY( result2 == "**-no-" ); |
| 59 | |
| 60 | oss3.width(6); |
| 61 | oss3.setf(ios_base::internal, ios_base::adjustfield); |
| 62 | oss3.setf(ios_base::boolalpha); |
| 63 | ng3.put(oss3.rdbuf(), oss3, '*', false); |
| 64 | result3 = oss3.str(); |
| 65 | VERIFY( result3 == "**-no-" ); |
| 66 | |
| 67 | oss4.width(6); |
| 68 | oss4.setf(ios_base::left, ios_base::adjustfield); |
| 69 | oss4.setf(ios_base::boolalpha); |
| 70 | ng4.put(oss4.rdbuf(), oss4, '*', false); |
| 71 | result4 = oss4.str(); |
| 72 | VERIFY( result4 == "-no-**" ); |
| 73 | } |
| 74 | |
| 75 | int main() |
| 76 | { |
| 77 | test01(); |
| 78 | return 0; |
| 79 | } |