• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_lib=x86_64-apple-darwin11
11 // XFAIL: with_system_lib=x86_64-apple-darwin12
12 
13 // <istream>
14 
15 // basic_istream<charT,traits>& get(char_type& c);
16 
17 #include <istream>
18 #include <cassert>
19 
20 template <class CharT>
21 struct testbuf
22     : public std::basic_streambuf<CharT>
23 {
24     typedef std::basic_string<CharT> string_type;
25     typedef std::basic_streambuf<CharT> base;
26 private:
27     string_type str_;
28 public:
29 
testbuftestbuf30     testbuf() {}
testbuftestbuf31     testbuf(const string_type& str)
32         : str_(str)
33     {
34         base::setg(const_cast<CharT*>(str_.data()),
35                    const_cast<CharT*>(str_.data()),
36                    const_cast<CharT*>(str_.data()) + str_.size());
37     }
38 
ebacktestbuf39     CharT* eback() const {return base::eback();}
gptrtestbuf40     CharT* gptr() const {return base::gptr();}
egptrtestbuf41     CharT* egptr() const {return base::egptr();}
42 };
43 
main()44 int main()
45 {
46     {
47         testbuf<char> sb("          ");
48         std::istream is(&sb);
49         char c;
50         is.get(c);
51         assert(!is.eof());
52         assert(!is.fail());
53         assert(c == ' ');
54         assert(is.gcount() == 1);
55     }
56     {
57         testbuf<char> sb(" abc");
58         std::istream is(&sb);
59         char c;
60         is.get(c);
61         assert(!is.eof());
62         assert(!is.fail());
63         assert(c == ' ');
64         assert(is.gcount() == 1);
65         is.get(c);
66         assert(!is.eof());
67         assert(!is.fail());
68         assert(c == 'a');
69         assert(is.gcount() == 1);
70         is.get(c);
71         assert(!is.eof());
72         assert(!is.fail());
73         assert(c == 'b');
74         assert(is.gcount() == 1);
75         is.get(c);
76         assert(!is.eof());
77         assert(!is.fail());
78         assert(c == 'c');
79         assert(is.gcount() == 1);
80     }
81     {
82         testbuf<wchar_t> sb(L" abc");
83         std::wistream is(&sb);
84         wchar_t c;
85         is.get(c);
86         assert(!is.eof());
87         assert(!is.fail());
88         assert(c == L' ');
89         assert(is.gcount() == 1);
90         is.get(c);
91         assert(!is.eof());
92         assert(!is.fail());
93         assert(c == L'a');
94         assert(is.gcount() == 1);
95         is.get(c);
96         assert(!is.eof());
97         assert(!is.fail());
98         assert(c == L'b');
99         assert(is.gcount() == 1);
100         is.get(c);
101         assert(!is.eof());
102         assert(!is.fail());
103         assert(c == L'c');
104         assert(is.gcount() == 1);
105     }
106 }
107