[AMDGPU] Implement IR variant of isFMAFasterThanFMulAndFAdd (#121465)
[llvm-project.git] / libcxx / test / std / input.output / iostream.format / input.streams / istream.unformatted / unget.pass.cpp
blob1b3ed2a169a31b61c8ac0453146b52525985782f
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>& unget();
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();}
43 int main(int, char**)
46 testbuf<char> sb(" 123456789");
47 std::istream is(&sb);
48 is.get();
49 is.get();
50 is.get();
51 is.unget();
52 assert(is.good());
53 assert(is.gcount() == 0);
54 is.unget();
55 assert(is.good());
56 assert(is.gcount() == 0);
57 is.unget();
58 assert(is.good());
59 assert(is.gcount() == 0);
60 is.unget();
61 assert(is.bad());
62 assert(is.gcount() == 0);
64 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
66 testbuf<wchar_t> sb(L" 123456789");
67 std::wistream is(&sb);
68 is.get();
69 is.get();
70 is.get();
71 is.unget();
72 assert(is.good());
73 assert(is.gcount() == 0);
74 is.unget();
75 assert(is.good());
76 assert(is.gcount() == 0);
77 is.unget();
78 assert(is.good());
79 assert(is.gcount() == 0);
80 is.unget();
81 assert(is.bad());
82 assert(is.gcount() == 0);
84 #endif
85 #ifndef TEST_HAS_NO_EXCEPTIONS
87 testbuf<char> sb;
88 std::basic_istream<char> is(&sb);
89 is.exceptions(std::ios_base::badbit);
90 bool threw = false;
91 try {
92 is.unget();
93 } catch (std::ios_base::failure&) {
94 threw = true;
96 assert(threw);
97 assert( is.bad());
98 assert(!is.eof());
99 assert( is.fail());
101 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
103 testbuf<wchar_t> sb;
104 std::basic_istream<wchar_t> is(&sb);
105 is.exceptions(std::ios_base::badbit);
106 bool threw = false;
107 try {
108 is.unget();
109 } catch (std::ios_base::failure&) {
110 threw = true;
112 assert(threw);
113 assert( is.bad());
114 assert(!is.eof());
115 assert( is.fail());
117 #endif
118 #endif // TEST_HAS_NO_EXCEPTIONS
120 return 0;