]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/numpunct/members/pod/2.cc
1 // 2003-07-09 Benjamin Kosnik <bkoz@redhat.com>
3 // Copyright (C) 2003 Free Software Foundation, Inc.
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,
25 #include <ext/pod_char_traits.h>
26 #include <testsuite_hooks.h>
28 typedef unsigned short value_type
;
29 typedef unsigned int int_type
;
30 typedef __gnu_cxx::character
<value_type
, int_type
> podchar_type
;
32 // Member specializations for the existing facet classes.
33 // NB: This isn't especially portable. Perhaps a better way would be
34 // to just specialize all of numpunct and ctype.
40 do_is(mask __m
, char_type __c
) const { return true; }
45 do_is(const char_type
* __lo
, const char_type
* __hi
, mask
* __vec
) const
51 do_scan_is(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const
57 do_scan_not(mask __m
, const char_type
* __lo
, const char_type
* __hi
) const
63 do_toupper(char_type __c
) const
69 do_toupper(char_type
* __lo
, const char_type
* __hi
) const
75 do_tolower(char_type __c
) const
81 do_tolower(char_type
* __lo
, const char_type
* __hi
) const
87 do_widen(char __c
) const
89 char_type ret
= { value_type(__c
) };
96 do_widen(const char* __lo
, const char* __hi
, char_type
* __dest
) const
100 *__dest
= this->do_widen(*__lo
);
109 ctype
<podchar_type
>::
110 do_narrow(char_type __wc
, char) const
111 { return static_cast<char>(__wc
.value
); }
115 ctype
<podchar_type
>::
116 do_narrow(const podchar_type
* __lo
, const podchar_type
* __hi
,
117 char __dfault
, char* __dest
) const
121 *__dest
= this->do_narrow(*__lo
, char());
129 ctype
<podchar_type
>::~ctype() { }
133 numpunct
<podchar_type
>::_M_initialize_numpunct(__c_locale __cloc
)
136 _M_data
= new __numpunct_cache
<podchar_type
>;
138 _M_data
->_M_grouping
= "";
139 _M_data
->_M_use_grouping
= false;
141 _M_data
->_M_decimal_point
.value
= value_type('.');
142 _M_data
->_M_thousands_sep
.value
= value_type(',');
144 for (size_t i
= 0; i
< __num_base::_S_oend
; ++i
)
146 value_type v
= __num_base::_S_atoms_out
[i
];
147 _M_data
->_M_atoms_out
[i
].value
= v
;
149 _M_data
->_M_atoms_out
[__num_base::_S_oend
] = podchar_type();
151 for (size_t i
= 0; i
< __num_base::_S_iend
; ++i
)
152 _M_data
->_M_atoms_in
[i
].value
= value_type(__num_base::_S_atoms_in
[i
]);
153 _M_data
->_M_atoms_in
[__num_base::_S_iend
] = podchar_type();
156 podchar_type
* __truename
= new podchar_type
[4 + 1];
157 __truename
[0].value
= value_type('t');
158 __truename
[1].value
= value_type('r');
159 __truename
[2].value
= value_type('u');
160 __truename
[3].value
= value_type('e');
161 __truename
[4] = podchar_type();
162 _M_data
->_M_truename
= __truename
;
165 podchar_type
* __falsename
= new podchar_type
[5 + 1];
166 __falsename
[0].value
= value_type('f');
167 __falsename
[1].value
= value_type('a');
168 __falsename
[2].value
= value_type('l');
169 __falsename
[3].value
= value_type('s');
170 __falsename
[4].value
= value_type('e');
171 __falsename
[5] = podchar_type();
172 _M_data
->_M_falsename
= __falsename
;
176 numpunct
<podchar_type
>::~numpunct()
180 // Check for numpunct and ctype dependencies. Make sure that numpunct
181 // can be created without ctype.
185 typedef numpunct
<podchar_type
>::string_type string_type
;
186 typedef basic_ostringstream
<podchar_type
> ostream_type
;
190 // Test formatted output.
192 const locale loc
= locale::classic();
194 os
.setf(ios_base::boolalpha
);
195 os
.exceptions(ios_base::badbit
);
197 // 1: fail, no num_put.
200 // Calls to num_put.put will fail, as there's no num_put facet.
204 catch(const bad_cast
& obj
)
211 const locale
loc2(loc
, new num_put
<podchar_type
>);
216 // Calls to ctype.widen will fail, as there's no ctype facet.
220 catch(const bad_cast
& obj
)
226 // 3: fail, no numpunct
227 const locale
loc3(loc
, new ctype
<podchar_type
>);
232 // Formatted output fails as no numpunct.
236 catch(const bad_cast
& obj
)
243 const locale
loc4(loc3
, new numpunct
<podchar_type
>);
249 string_type s
= os
.str();
250 VERIFY( s
.length() == 3 );
252 VERIFY( os
.narrow(s
[0], char()) == '5' );
253 VERIFY( os
.narrow(s
[1], char()) == '0' );
254 VERIFY( os
.narrow(s
[2], char()) == '0' );
256 catch(const bad_cast
& obj
)