1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
13 // wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>
15 // size_t converted() const;
17 // XFAIL: no-wide-characters
23 #include "test_macros.h"
25 template <class CharT
, std::size_t = sizeof(CharT
)>
27 template <class CharT
>
28 struct TestHelper
<CharT
, 2> {
31 template <class CharT
>
32 struct TestHelper
<CharT
, 4> {
36 template <class CharT
>
37 void TestHelper
<CharT
, 2>::test() {
38 static_assert((std::is_same
<CharT
, wchar_t>::value
), "");
40 typedef std::codecvt_utf8
<CharT
> Codecvt
;
41 typedef std::wstring_convert
<Codecvt
> Myconv
;
43 assert(myconv
.converted() == 0);
44 std::string bs
= myconv
.to_bytes(L
"\u1005");
45 assert(myconv
.converted() == 1);
46 bs
= myconv
.to_bytes(L
"\u1005e");
47 assert(myconv
.converted() == 2);
48 std::wstring ws
= myconv
.from_bytes("\xE1\x80\x85");
49 assert(myconv
.converted() == 3);
53 template <class CharT
>
54 void TestHelper
<CharT
, 4>::test() {
55 static_assert((std::is_same
<CharT
, wchar_t>::value
), "");
57 typedef std::codecvt_utf8
<CharT
> Codecvt
;
58 typedef std::wstring_convert
<Codecvt
> Myconv
;
60 assert(myconv
.converted() == 0);
61 std::string bs
= myconv
.to_bytes(L
"\U00040003");
62 assert(myconv
.converted() == 1);
63 bs
= myconv
.to_bytes(L
"\U00040003e");
64 assert(myconv
.converted() == 2);
65 std::wstring ws
= myconv
.from_bytes("\xF1\x80\x80\x83");
66 assert(myconv
.converted() == 4);
70 int main(int, char**) {
71 TestHelper
<wchar_t>::test();