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(off_type off, ios_base::seekdir dir);
16 
17 #include <ostream>
18 #include <cassert>
19 
20 int seekoff_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
seekofftestbuf32     seekoff(typename base::off_type off, std::ios_base::seekdir way,
33                                          std::ios_base::openmode which)
34     {
35         ++seekoff_called;
36         assert(way == std::ios_base::beg);
37         assert(which == std::ios_base::out);
38         return off;
39     }
40 };
41 
main()42 int main()
43 {
44     {
45         std::ostream os((std::streambuf*)0);
46         assert(&os.seekp(5, std::ios_base::beg) == &os);
47         assert(seekoff_called == 0);
48     }
49     {
50         testbuf<char> sb;
51         std::ostream os(&sb);
52         assert(&os.seekp(10, std::ios_base::beg) == &os);
53         assert(seekoff_called == 1);
54         assert(os.good());
55         assert(&os.seekp(-1, std::ios_base::beg) == &os);
56         assert(seekoff_called == 2);
57         assert(os.fail());
58     }
59 }
60