[SandboxVec][Utils] Implement Utils::verifyFunction() (#124356)
[llvm-project.git] / libcxx / test / std / input.output / iostream.format / input.streams / istream.unformatted / seekg.pass.cpp
blobb4f5922d914f5bd6654f7e14df655de71226f900
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // <istream>
11 // basic_istream<charT,traits>& seekg(pos_type pos);
13 #include <istream>
14 #include <cassert>
15 #include <streambuf>
17 #include "test_macros.h"
19 template <class CharT>
20 struct testbuf
21 : public std::basic_streambuf<CharT>
23 typedef std::basic_string<CharT> string_type;
24 typedef std::basic_streambuf<CharT> base;
25 private:
26 string_type str_;
27 public:
29 testbuf() {}
30 testbuf(const string_type& str)
31 : str_(str)
33 base::setg(const_cast<CharT*>(str_.data()),
34 const_cast<CharT*>(str_.data()),
35 const_cast<CharT*>(str_.data()) + str_.size());
38 CharT* eback() const {return base::eback();}
39 CharT* gptr() const {return base::gptr();}
40 CharT* egptr() const {return base::egptr();}
41 protected:
42 typename base::pos_type seekpos(typename base::pos_type sp,
43 std::ios_base::openmode which)
45 assert(which == std::ios_base::in);
46 return sp;
50 int main(int, char**)
53 testbuf<char> sb(" 123456789");
54 std::istream is(&sb);
55 is.seekg(5);
56 assert(is.good());
57 is.seekg(-1);
58 assert(is.fail());
60 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
62 testbuf<wchar_t> sb(L" 123456789");
63 std::wistream is(&sb);
64 is.seekg(5);
65 assert(is.good());
66 is.seekg(-1);
67 assert(is.fail());
69 #endif
71 testbuf<char> sb(" 123456789");
72 std::istream is(&sb);
73 is.setstate(std::ios_base::eofbit);
74 assert(is.eof());
75 is.seekg(5);
76 assert(is.good());
77 assert(!is.eof());
80 return 0;