//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // template // basic_istream& // getline(basic_istream& is, // basic_string& str); #include #include #include #include "make_string.h" #include "min_allocator.h" #include "stream_types.h" #include "test_macros.h" template void test() { using string_type = std::basic_string, Alloc>; using stream_type = std::basic_istream; using streambuf_type = Streambuf; { streambuf_type sb(MAKE_CSTRING(CharT, " abc\n def\n ghij")); stream_type in(&sb); string_type s(MAKE_CSTRING(CharT, "initial text")); std::getline(in, s); assert(in.good()); assert(s == MAKE_CSTRING(CharT, " abc")); std::getline(in, s); assert(in.good()); assert(s == MAKE_CSTRING(CharT, " def")); std::getline(in, s); assert(in.eof()); assert(s == MAKE_CSTRING(CharT, " ghij")); } #ifndef TEST_HAS_NO_EXCEPTIONS { streambuf_type sb(MAKE_CSTRING(CharT, "hello")); stream_type is(&sb); is.exceptions(std::ios_base::eofbit); string_type s; bool threw = false; try { std::getline(is, s); } catch (std::ios::failure const&) { threw = true; } assert(!is.bad()); assert(!is.fail()); assert(is.eof()); assert(threw); assert(s == MAKE_CSTRING(CharT, "hello")); } { streambuf_type sb(MAKE_CSTRING(CharT, "")); stream_type is(&sb); is.exceptions(std::ios_base::failbit); string_type s; bool threw = false; try { std::getline(is, s); } catch (std::ios::failure const&) { threw = true; } assert(!is.bad()); assert(is.fail()); assert(is.eof()); assert(threw); assert(s == MAKE_CSTRING(CharT, "")); } #endif // TEST_HAS_NO_EXCEPTIONS } template