| 1 | // Copyright (C) 2020-2025 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 | #include "codecvt_unicode.h" |
| 21 | |
| 22 | #include <codecvt> |
| 23 | |
| 24 | using namespace std; |
| 25 | |
| 26 | void |
| 27 | test_utf8_utf32_codecvts () |
| 28 | { |
| 29 | using codecvt_c32 = codecvt<char32_t, char, mbstate_t>; |
| 30 | auto &loc_c = locale::classic (); |
| 31 | VERIFY (has_facet<codecvt_c32> (loc_c)); |
| 32 | |
| 33 | auto &cvt = use_facet<codecvt_c32> (loc_c); |
| 34 | test_utf8_utf32_cvt (cvt); |
| 35 | |
| 36 | codecvt_utf8<char32_t> cvt2; |
| 37 | test_utf8_utf32_cvt (cvt2); |
| 38 | } |
| 39 | |
| 40 | void |
| 41 | test_utf8_utf16_codecvts () |
| 42 | { |
| 43 | using codecvt_c16 = codecvt<char16_t, char, mbstate_t>; |
| 44 | auto &loc_c = locale::classic (); |
| 45 | VERIFY (has_facet<codecvt_c16> (loc_c)); |
| 46 | |
| 47 | auto &cvt = use_facet<codecvt_c16> (loc_c); |
| 48 | test_utf8_utf16_cvt (cvt); |
| 49 | |
| 50 | codecvt_utf8_utf16<char16_t> cvt2; |
| 51 | test_utf8_utf16_cvt (cvt2); |
| 52 | |
| 53 | codecvt_utf8_utf16<char32_t> cvt3; |
| 54 | test_utf8_utf16_cvt (cvt3); |
| 55 | } |
| 56 | |
| 57 | void |
| 58 | test_utf8_ucs2_codecvts () |
| 59 | { |
| 60 | codecvt_utf8<char16_t> cvt; |
| 61 | test_utf8_ucs2_cvt (cvt); |
| 62 | } |
| 63 | |
| 64 | void |
| 65 | test_utf16_utf32_codecvts () |
| 66 | { |
| 67 | codecvt_utf16<char32_t> cvt; |
| 68 | test_utf16_utf32_cvt (cvt, utf16_big_endian); |
| 69 | |
| 70 | codecvt_utf16<char32_t, 0x10FFFF, codecvt_mode::little_endian> cvt2; |
| 71 | test_utf16_utf32_cvt (cvt2, utf16_little_endian); |
| 72 | } |
| 73 | |
| 74 | void |
| 75 | test_utf16_ucs2_codecvts () |
| 76 | { |
| 77 | codecvt_utf16<char16_t> cvt; |
| 78 | test_utf16_ucs2_cvt (cvt, utf16_big_endian); |
| 79 | |
| 80 | codecvt_utf16<char16_t, 0x10FFFF, codecvt_mode::little_endian> cvt2; |
| 81 | test_utf16_ucs2_cvt (cvt2, utf16_little_endian); |
| 82 | } |
| 83 | |
| 84 | int |
| 85 | main () |
| 86 | { |
| 87 | test_utf8_utf32_codecvts (); |
| 88 | test_utf8_utf16_codecvts (); |
| 89 | test_utf8_ucs2_codecvts (); |
| 90 | test_utf16_utf32_codecvts (); |
| 91 | test_utf16_ucs2_codecvts (); |
| 92 | } |