| 1 | // 1999-07-23 bkoz |
| 2 | |
| 3 | // Copyright (C) 1999-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 | // 27.4.4.1 basic_ios constructors |
| 22 | |
| 23 | #include <ios> |
| 24 | #include <sstream> |
| 25 | #include <testsuite_hooks.h> |
| 26 | |
| 27 | void test01() |
| 28 | { |
| 29 | std::string str_01("jade cove, big sur"); |
| 30 | std::string str_05; |
| 31 | std::stringbuf strb_01; |
| 32 | std::stringbuf strb_02(str_01, std::ios_base::in); |
| 33 | std::stringbuf strb_03(str_01, std::ios_base::out); |
| 34 | const std::ios_base::fmtflags flag01 = std::ios_base::skipws | |
| 35 | std::ios_base::dec; |
| 36 | std::ios_base::fmtflags flag02; |
| 37 | const std::locale glocale = std::locale(); |
| 38 | |
| 39 | // explicit basic_ios(streambuf* sb) |
| 40 | std::ios ios_00(0); |
| 41 | std::ios ios_01(&strb_01); |
| 42 | std::ios ios_02(&strb_02); |
| 43 | std::ios ios_03(&strb_03); |
| 44 | |
| 45 | // basic_ios() |
| 46 | // NB: This is protected so need to go through fstream |
| 47 | |
| 48 | // void init(sreambuf* sb) |
| 49 | // NB: This is protected so need to go through fstream/stringstream |
| 50 | // Can double-check the accuracy of the above initializations though. |
| 51 | VERIFY( ios_00.rdbuf() == 0 ); |
| 52 | VERIFY( ios_00.tie() == 0 ); |
| 53 | VERIFY( ios_00.rdstate() == std::ios_base::badbit ); |
| 54 | VERIFY( ios_00.exceptions() == std::ios_base::goodbit ); |
| 55 | flag02 = ios_00.flags(); |
| 56 | VERIFY( flag02 == flag01 ); |
| 57 | VERIFY( ios_00.width() == 0 ); |
| 58 | VERIFY( ios_00.precision() == 6 ); |
| 59 | VERIFY( ios_00.fill() == ios_00.widen(' ') ); |
| 60 | VERIFY( ios_00.getloc() == glocale ); |
| 61 | |
| 62 | VERIFY( ios_01.rdbuf() == &strb_01 ); |
| 63 | VERIFY( ios_01.tie() == 0 ); |
| 64 | VERIFY( ios_01.rdstate() == std::ios_base::goodbit ); |
| 65 | VERIFY( ios_01.exceptions() == std::ios_base::goodbit ); |
| 66 | flag02 = ios_01.flags(); |
| 67 | VERIFY( flag02 == flag01 ); |
| 68 | VERIFY( ios_01.width() == 0 ); |
| 69 | VERIFY( ios_01.precision() == 6 ); |
| 70 | VERIFY( ios_01.fill() == ios_01.widen(' ') ); |
| 71 | VERIFY( ios_01.getloc() == glocale ); |
| 72 | } |
| 73 | |
| 74 | int main() |
| 75 | { |
| 76 | test01(); |
| 77 | return 0; |
| 78 | } |