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// wstring_convert(const byte_string& byte_err,
15//                 const wide_string& wide_err = wide_string());
16
17#include <locale>
18#include <codecvt>
19#include <cassert>
20
21#include "test_macros.h"
22
23int main()
24{
25    typedef std::codecvt_utf8<wchar_t> Codecvt;
26    typedef std::wstring_convert<Codecvt> Myconv;
27#if TEST_STD_VER > 11
28    static_assert(!std::is_convertible<std::string, Myconv>::value, "");
29    static_assert( std::is_constructible<Myconv, std::string>::value, "");
30#endif
31#ifndef TEST_HAS_NO_EXCEPTIONS
32    {
33        Myconv myconv;
34        try
35        {
36            myconv.to_bytes(L"\xDA83");
37            assert(false);
38        }
39        catch (const std::range_error&)
40        {
41        }
42        try
43        {
44            myconv.from_bytes('\xA5');
45            assert(false);
46        }
47        catch (const std::range_error&)
48        {
49        }
50    }
51#endif
52    {
53        Myconv myconv("byte error");
54        std::string bs = myconv.to_bytes(L"\xDA83");
55        assert(bs == "byte error");
56#ifndef TEST_HAS_NO_EXCEPTIONS
57        try
58        {
59            myconv.from_bytes('\xA5');
60            assert(false);
61        }
62        catch (const std::range_error&)
63        {
64        }
65#endif
66    }
67    {
68        Myconv myconv("byte error", L"wide error");
69        std::string bs = myconv.to_bytes(L"\xDA83");
70        assert(bs == "byte error");
71        std::wstring ws = myconv.from_bytes('\xA5');
72        assert(ws == L"wide error");
73    }
74}
75