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 //===----------------------------------------------------------------------===//
9 // XFAIL: stdlib=apple-libc++ && target={{.+}}-apple-macosx10.{{9|10|11}}
13 // basic_istream<charT,traits>& seekg(off_type off, ios_base::seekdir dir);
18 #include "test_macros.h"
20 int seekoff_called
= 0;
22 template <class CharT
>
24 : public std::basic_streambuf
<CharT
>
26 typedef std::basic_string
<CharT
> string_type
;
27 typedef std::basic_streambuf
<CharT
> base
;
33 testbuf(const string_type
& str
)
36 base::setg(const_cast<CharT
*>(str_
.data()),
37 const_cast<CharT
*>(str_
.data()),
38 const_cast<CharT
*>(str_
.data()) + str_
.size());
41 CharT
* eback() const {return base::eback();}
42 CharT
* gptr() const {return base::gptr();}
43 CharT
* egptr() const {return base::egptr();}
45 typename
base::pos_type
seekoff(typename
base::off_type off
,
46 std::ios_base::seekdir
,
47 std::ios_base::openmode which
)
49 assert(which
== std::ios_base::in
);
58 testbuf
<char> sb(" 123456789");
60 is
.seekg(5, std::ios_base::cur
);
62 assert(seekoff_called
== 1);
63 is
.seekg(-1, std::ios_base::beg
);
65 assert(seekoff_called
== 2);
67 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
69 testbuf
<wchar_t> sb(L
" 123456789");
70 std::wistream
is(&sb
);
71 is
.seekg(5, std::ios_base::cur
);
73 assert(seekoff_called
== 3);
74 is
.seekg(-1, std::ios_base::beg
);
76 assert(seekoff_called
== 4);
80 testbuf
<char> sb(" 123456789");
82 is
.setstate(std::ios_base::eofbit
);
84 is
.seekg(5, std::ios_base::beg
);