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 out(stateT& state,
14 // const internT* from, const internT* from_end, const internT*& from_next,
15 // externT* to, externT* to_end, externT*& 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 <stdio.h>
31
32 #include "test_macros.h"
33
34 typedef std::codecvt<char16_t, char, std::mbstate_t> F;
35
main(int,char **)36 int main(int, char**)
37 {
38 std::locale l = std::locale::classic();
39 const F& f = std::use_facet<F>(l);
40 {
41 F::intern_type from[9] = {'s', 'o', 'm', 'e', ' ', 't', 'e', 'x', 't'};
42 char to[9] = {0};
43 std::mbstate_t mbs = {};
44 const F::intern_type* from_next = 0;
45 char* to_next = 0;
46 F::result r = f.out(mbs, from, from + 9, from_next,
47 to, to + 9, to_next);
48 assert(r == F::ok);
49 assert(from_next - from == 9);
50 assert(to_next - to == 9);
51 for (unsigned i = 0; i < 9; ++i)
52 assert(to[i] == from[i]);
53 }
54
55 return 0;
56 }
57