1// { dg-options "-std=gnu++11" } 2// { dg-require-cstdint "" } 3 4// 2014-04-24 R��diger Sonderfeld 5 6// Copyright (C) 2015 Free Software Foundation, Inc. 7// 8// This file is part of the GNU ISO C++ Library. This library is free 9// software; you can redistribute it and/or modify it under the 10// terms of the GNU General Public License as published by the 11// Free Software Foundation; either version 3, or (at your option) 12// any later version. 13 14// This library is distributed in the hope that it will be useful, 15// but WITHOUT ANY WARRANTY; without even the implied warranty of 16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17// GNU General Public License for more details. 18 19// You should have received a copy of the GNU General Public License along 20// with this library; see the file COPYING3. If not see 21// <http://www.gnu.org/licenses/>. 22 23// [locale.codecvt], C++11 22.4.1.4. specialization. 24 25#include <locale> 26#include <cstring> 27#include <testsuite_hooks.h> 28 29void 30test01() 31{ 32 using namespace std; 33 typedef codecvt<char32_t, char, mbstate_t> codecvt_c32; 34 locale loc_c = locale::classic(); 35 VERIFY(has_facet<codecvt_c32>(loc_c)); 36 const codecvt_c32* const cvt = &use_facet<codecvt_c32>(loc_c); 37 38 VERIFY(!cvt->always_noconv()); 39 VERIFY(cvt->max_length() == 4); 40 VERIFY(cvt->encoding() == 0); 41 42 const char u8dat[] = u8"H\U000000E4ll\U000000F6 \U0001F63F \U000056FD " 43 u8"\U0000222B f(\U000003BA) exp(-2\U000003C0\U000003C9) d\U000003BA " 44 u8"\U0001F6BF \U0001F6BF \U0001F648 \U00000413\U00000435\U0000043E" 45 u8"\U00000433\U00000440\U00000430\U00000444\U00000438\U0000044F \U0000FB05"; 46 const char* const u8dat_end = std::end(u8dat); 47 48 const char32_t u32dat[] = U"H\U000000E4ll\U000000F6 \U0001F63F \U000056FD " 49 U"\U0000222B f(\U000003BA) exp(-2\U000003C0\U000003C9) d\U000003BA " 50 U"\U0001F6BF \U0001F6BF \U0001F648 \U00000413\U00000435\U0000043E" 51 U"\U00000433\U00000440\U00000430\U00000444\U00000438\U0000044F \U0000FB05"; 52 const char32_t* const u32dat_end = std::end(u32dat); 53 54 { 55 const size_t len = u32dat_end - u32dat + 1; 56 char32_t* const buffer = new char32_t[len]; 57 char32_t* const buffer_end = buffer + len; 58 59 const char* from_next; 60 char32_t* to_next; 61 62 codecvt_c32::state_type state01; 63 state01 = {}; 64 codecvt_base::result res = cvt->in(state01, u8dat, u8dat_end, from_next, 65 buffer, buffer_end, to_next); 66 67 VERIFY(res == codecvt_base::ok); 68 VERIFY(from_next == u8dat_end); 69 VERIFY(std::memcmp((void*)buffer, (void*)u32dat, sizeof(u32dat)) == 0); 70 71 delete[] buffer; 72 } 73 74 { 75 const size_t len = u8dat_end - u8dat + 1; 76 char* const buffer = new char[len]; 77 char* const buffer_end = buffer + len; 78 79 const char32_t* from_next; 80 char* to_next; 81 82 codecvt_c32::state_type state01; 83 state01 = {}; 84 codecvt_base::result res = cvt->out(state01, u32dat, u32dat_end, from_next, 85 buffer, buffer_end, to_next); 86 87 VERIFY(res == codecvt_base::ok); 88 VERIFY(from_next == u32dat_end); 89 VERIFY(std::memcmp((void*)buffer, (void*)u8dat, sizeof(u8dat)) == 0); 90 91 delete[] buffer; 92 } 93} 94 95int 96main() 97{ 98 test01(); 99} 100