Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / localization / locales / locale.convenience / conversions / conversions.buffer / underflow.pass.cpp
blob32a3b18dda030dcf46ad302e0e27802ddb645c6d
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 // <locale>
11 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
13 // wbuffer_convert<Codecvt, Elem, Tr>
15 // int_type underflow();
17 // This test is not entirely portable
19 // XFAIL: no-wide-characters
21 #include <locale>
22 #include <cassert>
23 #include <codecvt>
24 #include <sstream>
26 #include "test_macros.h"
28 struct test_buf
29 : public std::wbuffer_convert<std::codecvt_utf8<wchar_t> >
31 typedef std::wbuffer_convert<std::codecvt_utf8<wchar_t> > base;
32 typedef base::char_type char_type;
33 typedef base::int_type int_type;
34 typedef base::traits_type traits_type;
36 explicit test_buf(std::streambuf* sb) : base(sb) {}
38 char_type* eback() const {return base::eback();}
39 char_type* gptr() const {return base::gptr();}
40 char_type* egptr() const {return base::egptr();}
41 void gbump(int n) {base::gbump(n);}
43 virtual int_type underflow() {return base::underflow();}
46 int main(int, char**)
49 std::string s = "123456789";
50 std::istringstream bs(s);
51 test_buf f(bs.rdbuf());
52 assert(f.eback() == 0);
53 assert(f.gptr() == 0);
54 assert(f.egptr() == 0);
55 assert(f.underflow() == L'1');
56 assert(f.eback() != 0);
57 assert(f.eback() == f.gptr());
58 assert(*f.gptr() == L'1');
59 assert(f.egptr() - f.eback() == 9);
62 std::string s = "123456789";
63 std::istringstream bs(s);
64 test_buf f(bs.rdbuf());
65 assert(f.eback() == 0);
66 assert(f.gptr() == 0);
67 assert(f.egptr() == 0);
68 assert(f.underflow() == L'1');
69 assert(f.eback() != 0);
70 assert(f.eback() == f.gptr());
71 assert(*f.gptr() == L'1');
72 assert(f.egptr() - f.eback() == 9);
73 f.gbump(8);
74 assert(f.sgetc() == L'9');
75 assert(f.eback()[0] == L'1');
76 assert(f.eback()[1] == L'2');
77 assert(f.eback()[2] == L'3');
78 assert(f.eback()[3] == L'4');
79 assert(f.gptr() - f.eback() == 8);
80 assert(*f.gptr() == L'9');
81 assert(f.egptr() - f.gptr() == 1);
84 std::string s = "乑乒乓";
85 std::istringstream bs(s);
86 test_buf f(bs.rdbuf());
87 assert(f.sbumpc() == 0x4E51);
88 assert(f.sbumpc() == 0x4E52);
89 assert(f.sbumpc() == 0x4E53);
90 assert(f.sbumpc() == test_buf::traits_type::eof());
93 return 0;