seekp.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <ostream> 11 12// template <class charT, class traits = char_traits<charT> > 13// class basic_ostream; 14 15// basic_ostream<charT,traits>& seekp(pos_type pos); 16 17#include <ostream> 18#include <cassert> 19 20int seekpos_called = 0; 21 22template <class CharT> 23struct testbuf 24 : public std::basic_streambuf<CharT> 25{ 26 typedef std::basic_streambuf<CharT> base; 27 testbuf() {} 28 29protected: 30 31 typename base::pos_type 32 seekpos(typename base::pos_type sp, std::ios_base::openmode which) 33 { 34 ++seekpos_called; 35 assert(which == std::ios_base::out); 36 return sp; 37 } 38}; 39 40int main() 41{ 42 { 43 std::ostream os((std::streambuf*)0); 44 assert(&os.seekp(5) == &os); 45 assert(seekpos_called == 0); 46 } 47 { 48 testbuf<char> sb; 49 std::ostream os(&sb); 50 assert(&os.seekp(10) == &os); 51 assert(seekpos_called == 1); 52 assert(os.good()); 53 assert(&os.seekp(-1) == &os); 54 assert(seekpos_called == 2); 55 assert(os.fail()); 56 } 57} 58