summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/22_locale/conversions/string/66441.cc
blob: 89a70bd5c6a808aa3d1f3f6a3949f7c05a0b7b7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// { dg-do run { target c++11 } }

// libstdc++/66441

#include <locale>
#include <codecvt>
#include <testsuite_hooks.h>

void
test01()
{
  // convert from UCS-4 to UTF16BE with BOM.
  using cvt = std::codecvt_utf16<char32_t, 0x10FFFF, std::generate_header>;
  std::wstring_convert<cvt, char32_t> conv;
  auto to = conv.to_bytes(U"ab\u00e7");

  VERIFY( to.length() == 8 );
  VERIFY( (unsigned char)to[0] == 0xfe );
  VERIFY( (unsigned char)to[1] == 0xff );
  VERIFY( (unsigned char)to[2] == 0x00 );
  VERIFY( (unsigned char)to[3] == 0x61 );
  VERIFY( (unsigned char)to[4] == 0x00 );
  VERIFY( (unsigned char)to[5] == 0x62 );
  VERIFY( (unsigned char)to[6] == 0x00 );
  VERIFY( (unsigned char)to[7] == 0xe7 );
}

int
main()
{
  test01();
}