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