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<wchar_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 #include <locale>
18 #include <string>
19 #include <vector>
20 #include <cassert>
21 #include <cstddef>
22 
23 #include "test_macros.h"
24 
25 typedef std::codecvt<wchar_t, char, std::mbstate_t> F;
26 
main(int,char **)27 int main(int, char**)
28 {
29     std::locale l = std::locale::classic();
30     const std::basic_string<F::extern_type> from("some text");
31     const std::basic_string<F::intern_type> expected(from.begin(), from.end());
32     std::basic_string<F::intern_type> to(from.size(), F::intern_type());
33     const F& f = std::use_facet<F>(l);
34     std::mbstate_t mbs = {};
35     const F::extern_type* from_next = 0;
36     F::intern_type* to_next = 0;
37     F::result r = f.in(mbs, from.data(), from.data() + from.size(), from_next,
38                             to.data(), to.data() + to.size(), to_next);
39     assert(r == F::ok);
40     assert(static_cast<std::size_t>(from_next - from.data()) == from.size());
41     assert(static_cast<std::size_t>(to_next - to.data()) == expected.size());
42     assert(static_cast<std::size_t>(to_next - to.data()) == expected.size());
43     assert(to == expected);
44 
45   return 0;
46 }
47