1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <locale>
11 
12 // wbuffer_convert<Codecvt, Elem, Tr>
13 
14 // int_type pbackfail(int_type c = traits::eof());
15 
16 // This test is not entirely portable
17 
18 #include <locale>
19 #include <codecvt>
20 #include <fstream>
21 #include <cassert>
22 
23 struct test_buf
24     : public std::wbuffer_convert<std::codecvt_utf8<wchar_t> >
25 {
26     typedef std::wbuffer_convert<std::codecvt_utf8<wchar_t> > base;
27     typedef base::char_type   char_type;
28     typedef base::int_type    int_type;
29     typedef base::traits_type traits_type;
30 
test_buftest_buf31     explicit test_buf(std::streambuf* sb) : base(sb) {}
32 
ebacktest_buf33     char_type* eback() const {return base::eback();}
gptrtest_buf34     char_type* gptr()  const {return base::gptr();}
egptrtest_buf35     char_type* egptr() const {return base::egptr();}
gbumptest_buf36     void gbump(int n) {base::gbump(n);}
37 
pbackfailtest_buf38     virtual int_type pbackfail(int_type c = traits_type::eof()) {return base::pbackfail(c);}
39 };
40 
main()41 int main()
42 {
43     {
44         std::ifstream bs("underflow.dat");
45         test_buf f(bs.rdbuf());
46         assert(f.sbumpc() == L'1');
47         assert(f.sgetc() == L'2');
48         assert(f.pbackfail(L'a') == test_buf::traits_type::eof());
49     }
50     {
51         std::fstream 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         assert(f.sbumpc() == L'2');
57         assert(f.sgetc() == L'3');
58     }
59 }
60