brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · 65ec28c Raw
95 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 underflow();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 26#include "test_macros.h"27 28struct test_buf29    : 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* eback() const {return base::eback();}39    char_type* gptr()  const {return base::gptr();}40    char_type* egptr() const {return base::egptr();}41    void gbump(int n) {base::gbump(n);}42 43    virtual int_type underflow() {return base::underflow();}44};45 46int main(int, char**)47{48    {49        std::string s = "123456789";50        std::istringstream bs(s);51        test_buf f(bs.rdbuf());52        assert(f.eback() == 0);53        assert(f.gptr() == 0);54        assert(f.egptr() == 0);55        assert(f.underflow() == L'1');56        assert(f.eback() != 0);57        assert(f.eback() == f.gptr());58        assert(*f.gptr() == L'1');59        assert(f.egptr() - f.eback() == 9);60    }61    {62        std::string s = "123456789";63        std::istringstream bs(s);64        test_buf f(bs.rdbuf());65        assert(f.eback() == 0);66        assert(f.gptr() == 0);67        assert(f.egptr() == 0);68        assert(f.underflow() == L'1');69        assert(f.eback() != 0);70        assert(f.eback() == f.gptr());71        assert(*f.gptr() == L'1');72        assert(f.egptr() - f.eback() == 9);73        f.gbump(8);74        assert(f.sgetc() == L'9');75        assert(f.eback()[0] == L'1');76        assert(f.eback()[1] == L'2');77        assert(f.eback()[2] == L'3');78        assert(f.eback()[3] == L'4');79        assert(f.gptr() - f.eback() == 8);80        assert(*f.gptr() == L'9');81        assert(f.egptr() - f.gptr() == 1);82    }83    {84        std::string s = "乑乒乓";85        std::istringstream bs(s);86        test_buf f(bs.rdbuf());87        assert(f.sbumpc() == 0x4E51);88        assert(f.sbumpc() == 0x4E52);89        assert(f.sbumpc() == 0x4E53);90        assert(f.sbumpc() == test_buf::traits_type::eof());91    }92 93    return 0;94}95