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 // template <> class codecvt<char16_t, char, mbstate_t>
12 
13 // result in(stateT& state,
14 //           const externT* from, const externT* from_end, const externT*& from_next,
15 //           internT* to, internT* to_end, internT*& to_next) const;
16 
17 // This test runs in C++20, but we have deprecated codecvt<char(16|32), char, mbstate_t> in C++20.
18 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
19 
20 // Test is intended to convert between UTF8 and UTF16/32, it will fail on
21 // z/OS since at default char type on z/OS is EBCDIC character which has
22 // value different from ASCII character.
23 // UNSUPPORTED: target={{.+}}-zos{{.*}}
24 
25 #include <locale>
26 #include <string>
27 #include <vector>
28 #include <cassert>
29 
30 #include "test_macros.h"
31 
32 typedef std::codecvt<char16_t, char, std::mbstate_t> F;
33 
main(int,char **)34 int main(int, char**)
35 {
36     std::locale l = std::locale::classic();
37     const char from[] = "some text";
38     F::intern_type to[9];
39     const F& f = std::use_facet<F>(l);
40     std::mbstate_t mbs = {};
41     const char* from_next = 0;
42     F::intern_type* to_next = 0;
43     assert(f.in(mbs, from, from + 9, from_next,
44                      to, to + 9, to_next) == F::ok);
45     assert(from_next - from == 9);
46     assert(to_next - to == 9);
47     for (unsigned i = 0; i < 9; ++i)
48         assert(to[i] == from[i]);
49 
50   return 0;
51 }
52