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 -D_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT
12
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 portable
21
22 // XFAIL: no-wide-characters
23
24 // TODO: Avoid using <fstream> in this test.
25 // XFAIL: no-filesystem
26
27 #include <locale>
28 #include <codecvt>
29 #include <fstream>
30 #include <cassert>
31
32 class test_codecvt
33 : public std::codecvt<wchar_t, char, std::mbstate_t>
34 {
35 typedef std::codecvt<wchar_t, char, std::mbstate_t> base;
36 public:
test_codecvt(std::size_t refs=0)37 explicit test_codecvt(std::size_t refs = 0) : base(refs) {}
~test_codecvt()38 ~test_codecvt() {}
39 };
40
main(int,char **)41 int 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::in
48 | 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