• 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 // <istream>
11 
12 // int sync();
13 
14 #include <istream>
15 #include <cassert>
16 
17 int sync_called = 0;
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 
testbuftestbuf29     testbuf() {}
testbuftestbuf30     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 
ebacktestbuf38     CharT* eback() const {return base::eback();}
gptrtestbuf39     CharT* gptr() const {return base::gptr();}
egptrtestbuf40     CharT* egptr() const {return base::egptr();}
41 
42 protected:
synctestbuf43     int sync()
44     {
45         ++sync_called;
46         return 5;
47     }
48 };
49 
main()50 int main()
51 {
52     {
53         testbuf<char> sb(" 123456789");
54         std::istream is(&sb);
55         assert(is.sync() == 0);
56         assert(sync_called = 1);
57     }
58     {
59         testbuf<wchar_t> sb(L" 123456789");
60         std::wistream is(&sb);
61         assert(is.sync() == 0);
62         assert(sync_called = 2);
63     }
64 }
65