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 // <locale> 10 11 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS 12 13 // wbuffer_convert<Codecvt, Elem, Tr> 14 15 // int_type overflow(int_type c = traits::eof()); 16 17 // This test is not entirely portable 18 19 // XFAIL: no-wide-characters 20 21 #include <locale> 22 #include <codecvt> 23 #include <fstream> 24 #include <cassert> 25 26 #include "test_macros.h" 27 28 struct test_buf 29 : public std::wbuffer_convert<std::codecvt_utf8<wchar_t> > 30 { 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; 35 36 explicit test_buf(std::streambuf* sb) : base(sb) {} 37 38 char_type* pbase() const {return base::pbase();} 39 char_type* pptr() const {return base::pptr();} 40 char_type* epptr() const {return base::epptr();} 41 void gbump(int n) {base::gbump(n);} 42 43 virtual int_type overflow(int_type c = traits_type::eof()) {return base::overflow(c);} 44 }; 45 46 int main(int, char**) 47 { 48 { 49 std::ofstream bs("overflow.dat"); 50 test_buf f(bs.rdbuf()); 51 assert(f.pbase() == 0); 52 assert(f.pptr() == 0); 53 assert(f.epptr() == 0); 54 assert(f.overflow(L'a') == L'a'); 55 assert(f.pbase() != 0); 56 assert(f.pptr() == f.pbase()); 57 assert(f.epptr() - f.pbase() == 4095); 58 } 59 { 60 std::ifstream bs("overflow.dat"); 61 test_buf f(bs.rdbuf()); 62 assert(f.sgetc() == L'a'); 63 } 64 std::remove("overflow.dat"); 65 { 66 std::ofstream bs("overflow.dat"); 67 test_buf f(bs.rdbuf()); 68 f.pubsetbuf(0, 0); 69 assert(f.pbase() == 0); 70 assert(f.pptr() == 0); 71 assert(f.epptr() == 0); 72 assert(f.overflow('a') == 'a'); 73 assert(f.pbase() == 0); 74 assert(f.pptr() == 0); 75 assert(f.epptr() == 0); 76 } 77 { 78 std::ifstream bs("overflow.dat"); 79 test_buf f(bs.rdbuf()); 80 assert(f.sgetc() == L'a'); 81 } 82 std::remove("overflow.dat"); 83 { 84 std::ofstream bs("overflow.dat"); 85 test_buf f(bs.rdbuf()); 86 assert(f.sputc(0x4E51) == 0x4E51); 87 assert(f.sputc(0x4E52) == 0x4E52); 88 assert(f.sputc(0x4E53) == 0x4E53); 89 } 90 { 91 std::ifstream f("overflow.dat"); 92 assert(f.is_open()); 93 assert(f.get() == 0xE4); 94 assert(f.get() == 0xB9); 95 assert(f.get() == 0x91); 96 assert(f.get() == 0xE4); 97 assert(f.get() == 0xB9); 98 assert(f.get() == 0x92); 99 assert(f.get() == 0xE4); 100 assert(f.get() == 0xB9); 101 assert(f.get() == 0x93); 102 assert(f.get() == -1); 103 } 104 std::remove("overflow.dat"); 105 106 return 0; 107 } 108