1 // 2000-08-23 Benjamin Kosnik <bkoz@cygnus.com>
3 // Copyright (C) 2000, 2001 Free Software Foundation
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // 22.2.1.5 - Template class codecvt [lib.locale.codecvt]
24 #include <testsuite_hooks.h>
28 #ifdef _GLIBCPP_USE___ENC_TRAITS
29 #ifdef _GLIBCPP_USE_WCHAR_T
32 initialize_state(__enc_traits
& state
)
35 // Partial specialization using __enc_traits.
36 // codecvt<unicode_t, wchar_t, __enc_traits>
39 typedef codecvt_base::result result
;
40 typedef unsigned short unicode_t
;
41 typedef unicode_t int_type
;
42 typedef wchar_t ext_type
;
43 typedef __enc_traits enc_type
;
44 typedef codecvt
<int_type
, ext_type
, enc_type
> unicode_codecvt
;
45 typedef char_traits
<int_type
> int_traits
;
46 typedef char_traits
<ext_type
> ext_traits
;
50 char e_lit_base
[96] __attribute__((aligned(__alignof__(ext_type
)))) =
52 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x61,
53 0x00, 0x00, 0x00, 0x63, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x20,
54 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x61,
55 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x20,
56 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x73,
57 0x00, 0x00, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x69, 0x00, 0x00, 0x00, 0x6e,
58 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x74,
59 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0xa0
61 const ext_type
* e_lit
= reinterpret_cast<ext_type
*>(e_lit_base
);
63 char i_lit_base
[48] __attribute__((aligned(__alignof__(int_type
)))) =
65 0x00, 0x62, 0x00, 0x6c, 0x00, 0x61, 0x00, 0x63, 0x00, 0x6b, 0x00, 0x20,
66 0x00, 0x70, 0x00, 0x65, 0x00, 0x61, 0x00, 0x72, 0x00, 0x6c, 0x00, 0x20,
67 0x00, 0x6a, 0x00, 0x61, 0x00, 0x73, 0x00, 0x6d, 0x00, 0x69, 0x00, 0x6e,
68 0x00, 0x65, 0x00, 0x20, 0x00, 0x74, 0x00, 0x65, 0x00, 0x61, 0x00, 0xa0
70 const int_type
* i_lit
= reinterpret_cast<int_type
*>(i_lit_base
);
72 const ext_type
* efrom_next
;
73 const int_type
* ifrom_next
;
74 ext_type
* e_arr
= new ext_type
[size
+ 1];
76 int_type
* i_arr
= new int_type
[size
+ 1];
79 // construct a locale object with the specialized facet.
80 locale
loc(locale::classic(), new unicode_codecvt
);
81 // sanity check the constructed locale has the specialized facet.
82 VERIFY( has_facet
<unicode_codecvt
>(loc
) );
83 const unicode_codecvt
& cvt
= use_facet
<unicode_codecvt
>(loc
);
86 unicode_codecvt::state_type
state01("UCS-2BE", "UCS-4BE", 0xfeff, 0);
87 initialize_state(state01
);
88 result r1
= cvt
.in(state01
, e_lit
, e_lit
+ size
, efrom_next
,
89 i_arr
, i_arr
+ size
+ 1, ito_next
);
90 VERIFY( r1
== codecvt_base::ok
);
91 VERIFY( !int_traits::compare(i_arr
, i_lit
, size
) );
92 VERIFY( efrom_next
== e_lit
+ size
);
93 VERIFY( ito_next
== i_arr
+ size
);
96 unicode_codecvt::state_type
state02("UCS-2BE", "UCS-4BE", 0xfeff, 0);
97 initialize_state(state02
);
98 result r2
= cvt
.out(state02
, i_lit
, i_lit
+ size
, ifrom_next
,
99 e_arr
, e_arr
+ size
, eto_next
);
100 // XXX VERIFY( r2 == codecvt_base::ok );
101 VERIFY( !ext_traits::compare(e_arr
, e_lit
, size
) );
102 VERIFY( ifrom_next
== i_lit
+ size
);
103 VERIFY( eto_next
== e_arr
+ size
);
106 ext_traits::copy(e_arr
, e_lit
, size
);
107 unicode_codecvt::state_type
state03("UCS-2BE", "UCS-4BE", 0xfeff, 0);
108 initialize_state(state03
);
109 result r3
= cvt
.unshift(state03
, e_arr
, e_arr
+ size
, eto_next
);
110 VERIFY( r3
== codecvt_base::noconv
);
111 VERIFY( !ext_traits::compare(e_arr
, e_lit
, size
) );
112 VERIFY( eto_next
== e_arr
);
114 int i
= cvt
.encoding();
117 VERIFY( !cvt
.always_noconv() );
119 unicode_codecvt::state_type
state04("UCS-2BE", "UCS-4BE", 0xfeff, 0);
120 initialize_state(state04
);
121 int j
= cvt
.length(state03
, e_lit
, e_lit
+ size
, 5);
124 int k
= cvt
.max_length();
130 #endif // _GLIBCPP_USE_WCHAR_T
131 #endif // _GLIBCPP_USE___ENC_TRAITS
135 #ifdef _GLIBCPP_USE___ENC_TRAITS
136 #ifdef _GLIBCPP_USE_WCHAR_T