1 // Copyright (C) 2015-2018 Free Software Foundation, Inc. 2 // 3 // This file is part of the GNU ISO C++ Library. This library is free 4 // software; you can redistribute it and/or modify it under the 5 // terms of the GNU General Public License as published by the 6 // Free Software Foundation; either version 3, or (at your option) 7 // any later version. 8 9 // This library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 14 // You should have received a copy of the GNU General Public License along 15 // with this library; see the file COPYING3. If not see 16 // <http://www.gnu.org/licenses/>. 17 18 // { dg-do run { target c++11 } } 19 20 // libstdc++/66441 21 22 #include <locale> 23 #include <codecvt> 24 #include <testsuite_hooks.h> 25 26 void test01()27test01() 28 { 29 // convert from UCS-4 to UTF16BE with BOM. 30 using cvt = std::codecvt_utf16<char32_t, 0x10FFFF, std::generate_header>; 31 std::wstring_convert<cvt, char32_t> conv; 32 auto to = conv.to_bytes(U"ab\u00e7"); 33 34 VERIFY( to.length() == 8 ); 35 VERIFY( (unsigned char)to[0] == 0xfe ); 36 VERIFY( (unsigned char)to[1] == 0xff ); 37 VERIFY( (unsigned char)to[2] == 0x00 ); 38 VERIFY( (unsigned char)to[3] == 0x61 ); 39 VERIFY( (unsigned char)to[4] == 0x00 ); 40 VERIFY( (unsigned char)to[5] == 0x62 ); 41 VERIFY( (unsigned char)to[6] == 0x00 ); 42 VERIFY( (unsigned char)to[7] == 0xe7 ); 43 } 44 45 int main()46main() 47 { 48 test01(); 49 } 50