1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <locale>
11
12 // wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>
13
14 // size_t converted() const;
15
16 #include <locale>
17 #include <codecvt>
18 #include <cassert>
19
20 template <class CharT, size_t = sizeof(CharT)>
21 struct TestHelper;
22 template <class CharT>
23 struct TestHelper<CharT, 2> {
24 static void test();
25 };
26 template <class CharT>
27 struct TestHelper<CharT, 4> {
28 static void test();
29 };
30
31 template <class CharT>
test()32 void TestHelper<CharT, 2>::test() {
33 static_assert((std::is_same<CharT, wchar_t>::value), "");
34 {
35 typedef std::codecvt_utf8<CharT> Codecvt;
36 typedef std::wstring_convert<Codecvt> Myconv;
37 Myconv myconv;
38 assert(myconv.converted() == 0);
39 std::string bs = myconv.to_bytes(L"\x1005");
40 assert(myconv.converted() == 1);
41 bs = myconv.to_bytes(L"\x1005\x65");
42 assert(myconv.converted() == 2);
43 std::wstring ws = myconv.from_bytes("\xE1\x80\x85");
44 assert(myconv.converted() == 3);
45 }
46 }
47
48 template <class CharT>
test()49 void TestHelper<CharT, 4>::test() {
50 static_assert((std::is_same<CharT, wchar_t>::value), "");
51 {
52 typedef std::codecvt_utf8<CharT> Codecvt;
53 typedef std::wstring_convert<Codecvt> Myconv;
54 Myconv myconv;
55 assert(myconv.converted() == 0);
56 std::string bs = myconv.to_bytes(L"\x40003");
57 assert(myconv.converted() == 1);
58 bs = myconv.to_bytes(L"\x40003\x65");
59 assert(myconv.converted() == 2);
60 std::wstring ws = myconv.from_bytes("\xF1\x80\x80\x83");
61 assert(myconv.converted() == 4);
62 }
63 }
64
main()65 int main() { TestHelper<wchar_t>::test(); }
66