Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / input.output / iostream.format / input.streams / istream.unformatted / get_chart.pass.cpp
blobfe15b3678f0e95f2c253f6d90af24e984623f528
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 // XFAIL: stdlib=apple-libc++ && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14}}
11 // <istream>
13 // basic_istream<charT,traits>& get(char_type& c);
15 #include <istream>
16 #include <cassert>
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(" ");
47 std::istream is(&sb);
48 char c;
49 is.get(c);
50 assert(!is.eof());
51 assert(!is.fail());
52 assert(c == ' ');
53 assert(is.gcount() == 1);
56 testbuf<char> sb(" abc");
57 std::istream is(&sb);
58 char c;
59 is.get(c);
60 assert(!is.eof());
61 assert(!is.fail());
62 assert(c == ' ');
63 assert(is.gcount() == 1);
64 is.get(c);
65 assert(!is.eof());
66 assert(!is.fail());
67 assert(c == 'a');
68 assert(is.gcount() == 1);
69 is.get(c);
70 assert(!is.eof());
71 assert(!is.fail());
72 assert(c == 'b');
73 assert(is.gcount() == 1);
74 is.get(c);
75 assert(!is.eof());
76 assert(!is.fail());
77 assert(c == 'c');
78 assert(is.gcount() == 1);
80 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
82 testbuf<wchar_t> sb(L" abc");
83 std::wistream is(&sb);
84 wchar_t c;
85 is.get(c);
86 assert(!is.eof());
87 assert(!is.fail());
88 assert(c == L' ');
89 assert(is.gcount() == 1);
90 is.get(c);
91 assert(!is.eof());
92 assert(!is.fail());
93 assert(c == L'a');
94 assert(is.gcount() == 1);
95 is.get(c);
96 assert(!is.eof());
97 assert(!is.fail());
98 assert(c == L'b');
99 assert(is.gcount() == 1);
100 is.get(c);
101 assert(!is.eof());
102 assert(!is.fail());
103 assert(c == L'c');
104 assert(is.gcount() == 1);
106 #endif // TEST_HAS_NO_WIDE_CHARACTERS
107 #ifndef TEST_HAS_NO_EXCEPTIONS
109 testbuf<char> sb("rrrrrrrrr");
110 std::basic_istream<char> is(&sb);
111 is.exceptions(std::ios_base::eofbit);
113 bool threw = false;
114 try {
115 while (true) {
116 char c;
117 is.get(c);
118 if (is.eof())
119 break;
121 } catch (std::ios_base::failure const&) {
122 threw = true;
125 assert(!is.bad());
126 assert( is.fail());
127 assert( is.eof());
128 assert(threw);
130 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
132 testbuf<wchar_t> sb(L"rrrrrrrrr");
133 std::basic_istream<wchar_t> is(&sb);
134 is.exceptions(std::ios_base::eofbit);
136 bool threw = false;
137 try {
138 while (true) {
139 wchar_t c;
140 is.get(c);
141 if (is.eof())
142 break;
144 } catch (std::ios_base::failure const&) {
145 threw = true;
148 assert(!is.bad());
149 assert( is.fail());
150 assert( is.eof());
151 assert(threw);
153 #endif // TEST_HAS_NO_WIDE_CHARACTERS
154 #endif // TEST_HAS_NO_EXCEPTIONS
156 return 0;