• 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 // <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 
20 int seekpos_called = 0;
21 
22 template <class CharT>
23 struct testbuf
24     : public std::basic_streambuf<CharT>
25 {
26     typedef std::basic_streambuf<CharT> base;
testbuftestbuf27     testbuf() {}
28 
29 protected:
30 
31     typename base::pos_type
seekpostestbuf32     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 
main()40 int 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