66 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <locale>10 11// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT -D_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT12 13// wbuffer_convert<Codecvt, Elem, Tr>14 15// int_type pbackfail(int_type c = traits::eof());16 17// This test is not entirely portable18 19// XFAIL: no-wide-characters20 21#include <locale>22#include <cassert>23#include <codecvt>24#include <sstream>25 26struct test_buf27 : 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 34 explicit test_buf(std::streambuf* sb) : base(sb) {}35 36 char_type* eback() const {return base::eback();}37 char_type* gptr() const {return base::gptr();}38 char_type* egptr() const {return base::egptr();}39 void gbump(int n) {base::gbump(n);}40 41 virtual int_type pbackfail(int_type c = traits_type::eof()) {return base::pbackfail(c);}42};43 44int main(int, char**)45{46 std::string const s = "123456789";47 {48 std::istringstream in(s);49 test_buf f(in.rdbuf());50 assert(f.sbumpc() == L'1');51 assert(f.sgetc() == L'2');52 assert(f.pbackfail(L'a') == test_buf::traits_type::eof());53 }54 {55 std::istringstream in(s);56 test_buf f(in.rdbuf());57 assert(f.sbumpc() == L'1');58 assert(f.sgetc() == L'2');59 assert(f.pbackfail(L'a') == test_buf::traits_type::eof());60 assert(f.sbumpc() == L'2');61 assert(f.sgetc() == L'3');62 }63 64 return 0;65}66