1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // basic_istream<charT,traits>& seekg(off_type off, ios_base::seekdir dir);
17 #include "test_macros.h"
19 int seekoff_called
= 0;
21 template <class CharT
>
23 : public std::basic_streambuf
<CharT
>
25 typedef std::basic_string
<CharT
> string_type
;
26 typedef std::basic_streambuf
<CharT
> base
;
32 testbuf(const string_type
& str
)
35 base::setg(const_cast<CharT
*>(str_
.data()),
36 const_cast<CharT
*>(str_
.data()),
37 const_cast<CharT
*>(str_
.data()) + str_
.size());
40 CharT
* eback() const {return base::eback();}
41 CharT
* gptr() const {return base::gptr();}
42 CharT
* egptr() const {return base::egptr();}
44 typename
base::pos_type
seekoff(typename
base::off_type off
,
45 std::ios_base::seekdir
,
46 std::ios_base::openmode which
)
48 assert(which
== std::ios_base::in
);
57 testbuf
<char> sb(" 123456789");
59 is
.seekg(5, std::ios_base::cur
);
61 assert(seekoff_called
== 1);
62 is
.seekg(-1, std::ios_base::beg
);
64 assert(seekoff_called
== 2);
66 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
68 testbuf
<wchar_t> sb(L
" 123456789");
69 std::wistream
is(&sb
);
70 is
.seekg(5, std::ios_base::cur
);
72 assert(seekoff_called
== 3);
73 is
.seekg(-1, std::ios_base::beg
);
75 assert(seekoff_called
== 4);
79 testbuf
<char> sb(" 123456789");
81 is
.setstate(std::ios_base::eofbit
);
83 is
.seekg(5, std::ios_base::beg
);