1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // XFAIL: with_system_cxx_lib=macosx10.7 11 12 // <istream> 13 14 // basic_istream<charT,traits>& get(char_type& c); 15 16 #include <istream> 17 #include <cassert> 18 19 template <class CharT> 20 struct testbuf 21 : public std::basic_streambuf<CharT> 22 { 23 typedef std::basic_string<CharT> string_type; 24 typedef std::basic_streambuf<CharT> base; 25 private: 26 string_type str_; 27 public: 28 29 testbuf() {} 30 testbuf(const string_type& str) 31 : str_(str) 32 { 33 base::setg(const_cast<CharT*>(str_.data()), 34 const_cast<CharT*>(str_.data()), 35 const_cast<CharT*>(str_.data()) + str_.size()); 36 } 37 38 CharT* eback() const {return base::eback();} 39 CharT* gptr() const {return base::gptr();} 40 CharT* egptr() const {return base::egptr();} 41 }; 42 43 int main() 44 { 45 { 46 testbuf<char> sb(" "); 47 std::istream is(&sb); 48 char c; 49 is.get(c); 50 assert(!is.eof()); 51 assert(!is.fail()); 52 assert(c == ' '); 53 assert(is.gcount() == 1); 54 } 55 { 56 testbuf<char> sb(" abc"); 57 std::istream is(&sb); 58 char c; 59 is.get(c); 60 assert(!is.eof()); 61 assert(!is.fail()); 62 assert(c == ' '); 63 assert(is.gcount() == 1); 64 is.get(c); 65 assert(!is.eof()); 66 assert(!is.fail()); 67 assert(c == 'a'); 68 assert(is.gcount() == 1); 69 is.get(c); 70 assert(!is.eof()); 71 assert(!is.fail()); 72 assert(c == 'b'); 73 assert(is.gcount() == 1); 74 is.get(c); 75 assert(!is.eof()); 76 assert(!is.fail()); 77 assert(c == 'c'); 78 assert(is.gcount() == 1); 79 } 80 { 81 testbuf<wchar_t> sb(L" abc"); 82 std::wistream is(&sb); 83 wchar_t c; 84 is.get(c); 85 assert(!is.eof()); 86 assert(!is.fail()); 87 assert(c == L' '); 88 assert(is.gcount() == 1); 89 is.get(c); 90 assert(!is.eof()); 91 assert(!is.fail()); 92 assert(c == L'a'); 93 assert(is.gcount() == 1); 94 is.get(c); 95 assert(!is.eof()); 96 assert(!is.fail()); 97 assert(c == L'b'); 98 assert(is.gcount() == 1); 99 is.get(c); 100 assert(!is.eof()); 101 assert(!is.fail()); 102 assert(c == L'c'); 103 assert(is.gcount() == 1); 104 } 105 } 106