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