]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf8_utf16/66855.cc
1 // Copyright (C) 2015-2017 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-do run { target c++11 } }
21 #include <testsuite_hooks.h>
26 std::codecvt_utf8_utf16
<char16_t
> cvt
;
27 char16_t utf16
[] = u
"\ub098\ub294\ud0dc\uc624";
32 auto res
= cvt
.out(st
, utf16
, utf16
+4, nf16
, utf8
, utf8
+16, nt8
);
33 VERIFY( res
== std::codecvt_base::ok
);
37 const char* nf8
= nt8
;
39 res
= cvt
.in(st
, utf8
, nf8
, nf8
, buf
, buf
+4, nt16
);
40 VERIFY( res
== std::codecvt_base::ok
);
41 VERIFY( nt16
== buf
+4 );
42 VERIFY( buf
[0] == utf16
[0] );
43 VERIFY( buf
[1] == utf16
[1] );
44 VERIFY( buf
[2] == utf16
[2] );
45 VERIFY( buf
[3] == utf16
[3] );
51 // Endianness flag should make no difference.
52 std::codecvt_utf8_utf16
<char16_t
, 0x10ffff, std::little_endian
> cvt
;
53 char16_t utf16
[] = u
"\ub098\ub294\ud0dc\uc624";
58 auto res
= cvt
.out(st
, utf16
, utf16
+4, nf16
, utf8
, utf8
+16, nt8
);
59 VERIFY( res
== std::codecvt_base::ok
);
63 const char* nf8
= nt8
;
65 res
= cvt
.in(st
, utf8
, nf8
, nf8
, buf
, buf
+4, nt16
);
66 VERIFY( res
== std::codecvt_base::ok
);
67 VERIFY( nt16
== buf
+4 );
68 VERIFY( buf
[0] == utf16
[0] );
69 VERIFY( buf
[1] == utf16
[1] );
70 VERIFY( buf
[2] == utf16
[2] );
71 VERIFY( buf
[3] == utf16
[3] );