1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // In macosx10.9 to macosx10.14, streams are provided in the dylib AND they
11 // have a bug in how they handle null-termination in case of errors (see D40677).
12 // XFAIL: with_system_cxx_lib=macosx10.14
13 // XFAIL: with_system_cxx_lib=macosx10.13
14 // XFAIL: with_system_cxx_lib=macosx10.12
15 // XFAIL: with_system_cxx_lib=macosx10.11
16 // XFAIL: with_system_cxx_lib=macosx10.10
17 // XFAIL: with_system_cxx_lib=macosx10.9
21 // basic_istream<charT,traits>& get(char_type* s, streamsize n, char_type delim);
26 #include "test_macros.h"
28 template <class CharT>
30 : public std::basic_streambuf<CharT>
32 typedef std::basic_string<CharT> string_type;
33 typedef std::basic_streambuf<CharT> base;
39 testbuf(const string_type& str)
42 base::setg(const_cast<CharT*>(str_.data()),
43 const_cast<CharT*>(str_.data()),
44 const_cast<CharT*>(str_.data()) + str_.size());
47 CharT* eback() const {return base::eback();}
48 CharT* gptr() const {return base::gptr();}
49 CharT* egptr() const {return base::egptr();}
55 testbuf<char> sb(" * * ");
61 assert(std::string(s) == " ");
62 assert(is.gcount() == 2);
66 assert(std::string(s) == "");
67 assert(is.gcount() == 0);
69 assert(is.get() == '*');
73 assert(std::string(s) == " ");
74 assert(is.gcount() == 4);
75 assert(is.get() == '*');
79 assert(std::string(s) == " ");
80 assert(is.gcount() == 1);
81 // Check that even in error case the buffer is properly 0-terminated.
85 assert(std::string(s) == "");
86 assert(is.gcount() == 0);
88 #ifndef TEST_HAS_NO_EXCEPTIONS
90 testbuf<char> sb(" ");
93 is.exceptions(std::istream::eofbit | std::istream::badbit);
99 catch (std::ios_base::failure&)
104 assert(std::string(s) == " ");
105 assert(is.gcount() == 1);
109 testbuf<wchar_t> sb(L" * * ");
110 std::wistream is(&sb);
115 assert(std::wstring(s) == L" ");
116 assert(is.gcount() == 2);
120 assert(std::wstring(s) == L"");
121 assert(is.gcount() == 0);
123 assert(is.get() == L'*');
127 assert(std::wstring(s) == L" ");
128 assert(is.gcount() == 4);
129 assert(is.get() == L'*');
133 assert(std::wstring(s) == L" ");
134 assert(is.gcount() == 1);
135 // Check that even in error case the buffer is properly 0-terminated.
139 assert(std::wstring(s) == L"");
140 assert(is.gcount() == 0);
142 #ifndef TEST_HAS_NO_EXCEPTIONS
144 testbuf<wchar_t> sb(L" ");
145 std::wistream is(&sb);
146 wchar_t s[5] = L"test";
147 is.exceptions(std::wistream::eofbit | std::wistream::badbit);
153 catch (std::ios_base::failure&)
158 assert(std::wstring(s) == L" ");
159 assert(is.gcount() == 1);