| 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 | // libstdc++/38210 |
| 25 | void test01() |
| 26 | { |
| 27 | using namespace std; |
| 28 | |
| 29 | ostringstream oss1, oss2, oss3, oss4; |
| 30 | string result1, result2, result3, result4; |
| 31 | |
| 32 | const num_put<char>& ng1 = use_facet<num_put<char> >(oss1.getloc()); |
| 33 | const num_put<char>& ng2 = use_facet<num_put<char> >(oss2.getloc()); |
| 34 | const num_put<char>& ng3 = use_facet<num_put<char> >(oss3.getloc()); |
| 35 | const num_put<char>& ng4 = use_facet<num_put<char> >(oss4.getloc()); |
| 36 | |
| 37 | void* p = (void*)0x1; |
| 38 | |
| 39 | oss1.width(5); |
| 40 | ng1.put(oss1.rdbuf(), oss1, '*', p); |
| 41 | result1 = oss1.str(); |
| 42 | VERIFY( result1 == "**0x1" ); |
| 43 | |
| 44 | oss2.width(5); |
| 45 | oss2.setf(ios_base::right, ios_base::adjustfield); |
| 46 | ng2.put(oss2.rdbuf(), oss2, '*', p); |
| 47 | result2 = oss2.str(); |
| 48 | VERIFY( result2 == "**0x1" ); |
| 49 | |
| 50 | oss3.width(5); |
| 51 | oss3.setf(ios_base::internal, ios_base::adjustfield); |
| 52 | ng3.put(oss3.rdbuf(), oss3, '*', p); |
| 53 | result3 = oss3.str(); |
| 54 | VERIFY( result3 == "0x**1" ); |
| 55 | |
| 56 | oss4.width(5); |
| 57 | oss4.setf(ios_base::left, ios_base::adjustfield); |
| 58 | ng4.put(oss4.rdbuf(), oss4, '*', p); |
| 59 | result4 = oss4.str(); |
| 60 | VERIFY( result4 == "0x1**" ); |
| 61 | } |
| 62 | |
| 63 | int main() |
| 64 | { |
| 65 | test01(); |
| 66 | return 0; |
| 67 | } |