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 underflow(); 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 underflowtest_buf38 virtual int_type underflow() {return base::underflow();} 39 }; 40 main()41int main() 42 { 43 { 44 std::ifstream bs("underflow.dat"); 45 test_buf f(bs.rdbuf()); 46 assert(f.eback() == 0); 47 assert(f.gptr() == 0); 48 assert(f.egptr() == 0); 49 assert(f.underflow() == L'1'); 50 assert(f.eback() != 0); 51 assert(f.eback() == f.gptr()); 52 assert(*f.gptr() == L'1'); 53 assert(f.egptr() - f.eback() == 9); 54 } 55 { 56 std::ifstream bs("underflow.dat"); 57 test_buf f(bs.rdbuf()); 58 assert(f.eback() == 0); 59 assert(f.gptr() == 0); 60 assert(f.egptr() == 0); 61 assert(f.underflow() == L'1'); 62 assert(f.eback() != 0); 63 assert(f.eback() == f.gptr()); 64 assert(*f.gptr() == L'1'); 65 assert(f.egptr() - f.eback() == 9); 66 f.gbump(8); 67 assert(f.sgetc() == L'9'); 68 assert(f.eback()[0] == L'1'); 69 assert(f.eback()[1] == L'2'); 70 assert(f.eback()[2] == L'3'); 71 assert(f.eback()[3] == L'4'); 72 assert(f.gptr() - f.eback() == 8); 73 assert(*f.gptr() == L'9'); 74 assert(f.egptr() - f.gptr() == 1); 75 } 76 { 77 std::ifstream bs("underflow_utf8.dat"); 78 test_buf f(bs.rdbuf()); 79 assert(f.sbumpc() == 0x4E51); 80 assert(f.sbumpc() == 0x4E52); 81 assert(f.sbumpc() == 0x4E53); 82 assert(f.sbumpc() == test_buf::traits_type::eof()); 83 } 84 } 85