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 //===----------------------------------------------------------------------===//
8 
9 // FILE_DEPENDENCIES: underflow.dat
10 
11 // <locale>
12 
13 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
14 
15 // wbuffer_convert<Codecvt, Elem, Tr>
16 
17 // int_type pbackfail(int_type c = traits::eof());
18 
19 // This test is not entirely portable
20 
21 // XFAIL: no-wide-characters
22 
23 #include <locale>
24 #include <codecvt>
25 #include <fstream>
26 #include <cassert>
27 
28 #include "test_macros.h"
29 
30 struct test_buf
31     : public std::wbuffer_convert<std::codecvt_utf8<wchar_t> >
32 {
33     typedef std::wbuffer_convert<std::codecvt_utf8<wchar_t> > base;
34     typedef base::char_type   char_type;
35     typedef base::int_type    int_type;
36     typedef base::traits_type traits_type;
37 
38     explicit test_buf(std::streambuf* sb) : base(sb) {}
39 
40     char_type* eback() const {return base::eback();}
41     char_type* gptr()  const {return base::gptr();}
42     char_type* egptr() const {return base::egptr();}
43     void gbump(int n) {base::gbump(n);}
44 
45     virtual int_type pbackfail(int_type c = traits_type::eof()) {return base::pbackfail(c);}
46 };
47 
48 int main(int, char**)
49 {
50     {
51         std::ifstream bs("underflow.dat");
52         test_buf f(bs.rdbuf());
53         assert(f.sbumpc() == L'1');
54         assert(f.sgetc() == L'2');
55         assert(f.pbackfail(L'a') == test_buf::traits_type::eof());
56     }
57     {
58         std::fstream bs("underflow.dat");
59         test_buf f(bs.rdbuf());
60         assert(f.sbumpc() == L'1');
61         assert(f.sgetc() == L'2');
62         assert(f.pbackfail(L'a') == test_buf::traits_type::eof());
63         assert(f.sbumpc() == L'2');
64         assert(f.sgetc() == L'3');
65     }
66 
67   return 0;
68 }
69