]>
Commit | Line | Data |
---|---|---|
4ffe6e87 BK |
1 | // { dg-require-iconv "UCS-2BE" } |
2 | // { dg-require-iconv "UCS-4BE" } | |
3 | ||
985287b8 | 4 | // 2000-08-23 Benjamin Kosnik <bkoz@cygnus.com> |
ae658d47 | 5 | |
748086b7 | 6 | // Copyright (C) 2000, 2001, 2002, 2003, 2007, 2009 Free Software Foundation |
ae658d47 BK |
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 | |
748086b7 | 11 | // Free Software Foundation; either version 3, or (at your option) |
ae658d47 BK |
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 | |
748086b7 JJ |
20 | // with this library; see the file COPYING3. If not see |
21 | // <http://www.gnu.org/licenses/>. | |
ae658d47 BK |
22 | |
23 | // 22.2.1.5 - Template class codecvt [lib.locale.codecvt] | |
24 | ||
25 | #include <locale> | |
fe413112 | 26 | #include <testsuite_hooks.h> |
4ffe6e87 | 27 | #include <ext/codecvt_specializations.h> |
ae658d47 | 28 | |
4ffe6e87 BK |
29 | // Partial specialization using encoding_state. |
30 | // codecvt<unicode_t, wchar_t, encoding_state> | |
ae658d47 BK |
31 | void test01() |
32 | { | |
f13a69ec | 33 | using namespace std; |
ae658d47 | 34 | typedef codecvt_base::result result; |
4ffe6e87 | 35 | typedef unsigned short int_type; |
ae658d47 | 36 | typedef wchar_t ext_type; |
4ffe6e87 BK |
37 | typedef __gnu_cxx::encoding_state state_type; |
38 | typedef codecvt<int_type, ext_type, state_type> unicode_codecvt; | |
ae658d47 BK |
39 | typedef char_traits<int_type> int_traits; |
40 | typedef char_traits<ext_type> ext_traits; | |
41 | ||
11f10e6b | 42 | bool test __attribute__((unused)) = true; |
985287b8 | 43 | int size = 23; |
10cbfb51 UW |
44 | char e_lit_base[96] __attribute__((aligned(__alignof__(ext_type)))) = |
45 | { | |
46 | 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x61, | |
47 | 0x00, 0x00, 0x00, 0x63, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x20, | |
48 | 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x61, | |
49 | 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x20, | |
50 | 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x73, | |
51 | 0x00, 0x00, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x69, 0x00, 0x00, 0x00, 0x6e, | |
52 | 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x74, | |
53 | 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0xa0 | |
985287b8 | 54 | }; |
10cbfb51 | 55 | const ext_type* e_lit = reinterpret_cast<ext_type*>(e_lit_base); |
ae658d47 | 56 | |
10cbfb51 | 57 | char i_lit_base[48] __attribute__((aligned(__alignof__(int_type)))) = |
7dc08a20 | 58 | { |
10cbfb51 UW |
59 | 0x00, 0x62, 0x00, 0x6c, 0x00, 0x61, 0x00, 0x63, 0x00, 0x6b, 0x00, 0x20, |
60 | 0x00, 0x70, 0x00, 0x65, 0x00, 0x61, 0x00, 0x72, 0x00, 0x6c, 0x00, 0x20, | |
61 | 0x00, 0x6a, 0x00, 0x61, 0x00, 0x73, 0x00, 0x6d, 0x00, 0x69, 0x00, 0x6e, | |
62 | 0x00, 0x65, 0x00, 0x20, 0x00, 0x74, 0x00, 0x65, 0x00, 0x61, 0x00, 0xa0 | |
ae658d47 | 63 | }; |
10cbfb51 | 64 | const int_type* i_lit = reinterpret_cast<int_type*>(i_lit_base); |
ae658d47 BK |
65 | |
66 | const ext_type* efrom_next; | |
67 | const int_type* ifrom_next; | |
68 | ext_type* e_arr = new ext_type[size + 1]; | |
69 | ext_type* eto_next; | |
70 | int_type* i_arr = new int_type[size + 1]; | |
71 | int_type* ito_next; | |
72 | ||
73 | // construct a locale object with the specialized facet. | |
74 | locale loc(locale::classic(), new unicode_codecvt); | |
75 | // sanity check the constructed locale has the specialized facet. | |
76 | VERIFY( has_facet<unicode_codecvt>(loc) ); | |
4ffe6e87 | 77 | const unicode_codecvt& cvt = use_facet<unicode_codecvt>(loc); |
ae658d47 BK |
78 | |
79 | // in | |
af779169 BK |
80 | // unicode_codecvt::state_type state01("UCS-2BE", "UCS-4BE", 0xfeff, 0); |
81 | unicode_codecvt::state_type state01("UCS-2BE", "UCS-4BE", 0, 0); | |
ae658d47 | 82 | result r1 = cvt.in(state01, e_lit, e_lit + size, efrom_next, |
7dc08a20 | 83 | i_arr, i_arr + size + 1, ito_next); |
ae658d47 BK |
84 | VERIFY( r1 == codecvt_base::ok ); |
85 | VERIFY( !int_traits::compare(i_arr, i_lit, size) ); | |
86 | VERIFY( efrom_next == e_lit + size ); | |
87 | VERIFY( ito_next == i_arr + size ); | |
88 | ||
89 | // out | |
af779169 | 90 | unicode_codecvt::state_type state02("UCS-2BE", "UCS-4BE", 0, 0); |
ae658d47 | 91 | result r2 = cvt.out(state02, i_lit, i_lit + size, ifrom_next, |
11f10e6b BK |
92 | e_arr, e_arr + size, eto_next); |
93 | VERIFY( r2 == codecvt_base::ok ); // XXX? | |
ae658d47 BK |
94 | VERIFY( !ext_traits::compare(e_arr, e_lit, size) ); |
95 | VERIFY( ifrom_next == i_lit + size ); | |
96 | VERIFY( eto_next == e_arr + size ); | |
97 | ||
98 | // unshift | |
99 | ext_traits::copy(e_arr, e_lit, size); | |
af779169 | 100 | unicode_codecvt::state_type state03("UCS-2BE", "UCS-4BE", 0, 0); |
ae658d47 BK |
101 | result r3 = cvt.unshift(state03, e_arr, e_arr + size, eto_next); |
102 | VERIFY( r3 == codecvt_base::noconv ); | |
103 | VERIFY( !ext_traits::compare(e_arr, e_lit, size) ); | |
104 | VERIFY( eto_next == e_arr ); | |
105 | ||
106 | int i = cvt.encoding(); | |
107 | VERIFY( i == 0 ); | |
108 | ||
109 | VERIFY( !cvt.always_noconv() ); | |
110 | ||
af779169 | 111 | unicode_codecvt::state_type state04("UCS-2BE", "UCS-4BE", 0, 0); |
ae658d47 BK |
112 | int j = cvt.length(state03, e_lit, e_lit + size, 5); |
113 | VERIFY( j == 5 ); | |
114 | ||
115 | int k = cvt.max_length(); | |
116 | VERIFY( k == 1 ); | |
117 | ||
118 | delete [] e_arr; | |
119 | delete [] i_arr; | |
120 | } | |
121 | ||
122 | int main () | |
123 | { | |
124 | test01(); | |
ae658d47 BK |
125 | return 0; |
126 | } | |
33590f13 | 127 |