brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 1947e81 Raw
67 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_WSTRING_CONVERT12 13// wbuffer_convert<Codecvt, Elem, Tr>14 15// pos_type seekoff(off_type off, ios_base::seekdir way,16//                  ios_base::openmode which = ios_base::in | ios_base::out);17// pos_type seekpos(pos_type sp,18//                  ios_base::openmode which = ios_base::in | ios_base::out);19 20// This test is not entirely portable21 22// XFAIL: no-wide-characters23 24// TODO: Avoid using <fstream> in this test.25// XFAIL: no-filesystem26 27#include <locale>28#include <codecvt>29#include <fstream>30#include <cassert>31 32class test_codecvt33    : public std::codecvt<wchar_t, char, std::mbstate_t>34{35    typedef std::codecvt<wchar_t, char, std::mbstate_t> base;36public:37    explicit test_codecvt(std::size_t refs = 0) : base(refs) {}38    ~test_codecvt() {}39};40 41int main(int, char**)42{43    {44        wchar_t buf[10];45        typedef std::wbuffer_convert<test_codecvt> test_buf;46        typedef test_buf::pos_type pos_type;47        std::fstream bs("seekoff.dat", std::ios::trunc | std::ios::in48                                                       | std::ios::out);49        test_buf f(bs.rdbuf());50        f.pubsetbuf(buf, sizeof(buf)/sizeof(buf[0]));51        f.sputn(L"abcdefghijklmnopqrstuvwxyz", 26);52        assert(buf[0] == L'v');53        pos_type p = f.pubseekoff(-15, std::ios_base::cur);54        assert(p == 11);55        assert(f.sgetc() == L'l');56        f.pubseekoff(0, std::ios_base::beg);57        assert(f.sgetc() == L'a');58        f.pubseekoff(-1, std::ios_base::end);59        assert(f.sgetc() == L'z');60        assert(f.pubseekpos(p) == p);61        assert(f.sgetc() == L'l');62    }63    std::remove("seekoff.dat");64 65  return 0;66}67