[flang][OpenMP] Parse METADIRECTIVE in specification part (#123397)
[llvm-project.git] / libcxx / test / std / input.output / iostream.format / input.streams / istream.unformatted / seekg_off.pass.cpp
bloba0c5dd1dbdc0aba2568bc4e3a8dceec84f418bff
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(off_type off, ios_base::seekdir dir);
13 #include <istream>
14 #include <cassert>
15 #include <streambuf>
17 #include "test_macros.h"
19 int seekoff_called = 0;
21 template <class CharT>
22 struct testbuf
23 : public std::basic_streambuf<CharT>
25 typedef std::basic_string<CharT> string_type;
26 typedef std::basic_streambuf<CharT> base;
27 private:
28 string_type str_;
29 public:
31 testbuf() {}
32 testbuf(const string_type& str)
33 : str_(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();}
43 protected:
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);
49 ++seekoff_called;
50 return off;
54 int main(int, char**)
57 testbuf<char> sb(" 123456789");
58 std::istream is(&sb);
59 is.seekg(5, std::ios_base::cur);
60 assert(is.good());
61 assert(seekoff_called == 1);
62 is.seekg(-1, std::ios_base::beg);
63 assert(is.fail());
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);
71 assert(is.good());
72 assert(seekoff_called == 3);
73 is.seekg(-1, std::ios_base::beg);
74 assert(is.fail());
75 assert(seekoff_called == 4);
77 #endif
79 testbuf<char> sb(" 123456789");
80 std::istream is(&sb);
81 is.setstate(std::ios_base::eofbit);
82 assert(is.eof());
83 is.seekg(5, std::ios_base::beg);
84 assert(is.good());
85 assert(!is.eof());
88 return 0;