sync.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//===----------------------------------------------------------------------===// 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// The LLVM Compiler Infrastructure 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This file is distributed under the University of Illinois Open Source 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// License. See LICENSE.TXT for details. 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//===----------------------------------------------------------------------===// 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 10cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// <istream> 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// int sync(); 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <istream> 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <cassert> 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)int sync_called = 0; 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)template <class CharT> 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)struct testbuf 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : public std::basic_streambuf<CharT> 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles){ 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) typedef std::basic_string<CharT> string_type; 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) typedef std::basic_streambuf<CharT> base; 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)private: 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) string_type str_; 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)public: 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) testbuf() {} 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) testbuf(const string_type& str) 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : str_(str) 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::setg(const_cast<CharT*>(str_.data()), 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const_cast<CharT*>(str_.data()), 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const_cast<CharT*>(str_.data()) + str_.size()); 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CharT* eback() const {return base::eback();} 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CharT* gptr() const {return base::gptr();} 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CharT* egptr() const {return base::egptr();} 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)protected: 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int sync() 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ++sync_called; 46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return 5; 47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)int main() 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles){ 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 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