ctor_err_string.pass.cpp revision d23b464e21648e252d5ae501b2db2e93dc02b1f7
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. 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 21int main() 22{ 23 typedef std::codecvt_utf8<wchar_t> Codecvt; 24 typedef std::wstring_convert<Codecvt> Myconv; 25 { 26 Myconv myconv; 27 try 28 { 29 myconv.to_bytes(L"\xDA83"); 30 assert(false); 31 } 32 catch (const std::range_error&) 33 { 34 } 35 try 36 { 37 myconv.from_bytes('\xA5'); 38 assert(false); 39 } 40 catch (const std::range_error&) 41 { 42 } 43 } 44 { 45 Myconv myconv("byte error"); 46 std::string bs = myconv.to_bytes(L"\xDA83"); 47 assert(bs == "byte error"); 48 try 49 { 50 myconv.from_bytes('\xA5'); 51 assert(false); 52 } 53 catch (const std::range_error&) 54 { 55 } 56 } 57 { 58 Myconv myconv("byte error", L"wide error"); 59 std::string bs = myconv.to_bytes(L"\xDA83"); 60 assert(bs == "byte error"); 61 std::wstring ws = myconv.from_bytes('\xA5'); 62 assert(ws == L"wide error"); 63 } 64} 65