blob: 27a3da76270fe7a5db185cf7b79cefadb9f26817 [file] [log] [blame]
Howard Hinnantd23b4642010-05-31 20:58:54 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantd23b4642010-05-31 20:58:54 +00007//
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
21int main()
22{
23 typedef std::codecvt_utf8<wchar_t> Codecvt;
24 typedef std::wstring_convert<Codecvt> Myconv;
Marshall Clow83179a72013-08-27 20:18:59 +000025#if _LIBCPP_STD_VER > 11
26 static_assert(!std::is_convertible<std::string, Myconv>::value, "");
27 static_assert( std::is_constructible<Myconv, std::string>::value, "");
28#endif
Howard Hinnantd23b4642010-05-31 20:58:54 +000029 {
30 Myconv myconv;
31 try
32 {
33 myconv.to_bytes(L"\xDA83");
34 assert(false);
35 }
36 catch (const std::range_error&)
37 {
38 }
39 try
40 {
41 myconv.from_bytes('\xA5');
42 assert(false);
43 }
44 catch (const std::range_error&)
45 {
46 }
47 }
48 {
49 Myconv myconv("byte error");
50 std::string bs = myconv.to_bytes(L"\xDA83");
51 assert(bs == "byte error");
52 try
53 {
54 myconv.from_bytes('\xA5');
55 assert(false);
56 }
57 catch (const std::range_error&)
58 {
59 }
60 }
61 {
62 Myconv myconv("byte error", L"wide error");
63 std::string bs = myconv.to_bytes(L"\xDA83");
64 assert(bs == "byte error");
65 std::wstring ws = myconv.from_bytes('\xA5');
66 assert(ws == L"wide error");
67 }
68}