gcc/libstdc++-v3/testsuite/testsuite_character.h
Chris Jefferson 8b5bc374b1 mt_allocator.h (__mt_alloc::__mt_alloc): Remove name of unused parameter.
2005-12-26  Chris Jefferson  <chris@bubblescope.net>

	* include/ext/mt_allocator.h (__mt_alloc::__mt_alloc): Remove
	name of unused parameter.
	* include/bits/stream_iterator.h (istream_iterator::istream_iterator):
	Construct _M_value.
	* include/debug/functions.h (__check_valid_range): Add
	__attribute__((unused)).
	* include/tr1/hashtable (hashtable::end): Remove name of unused
	parameter.
	* include/tr1/tuple_iterate.h (tuple::tuple): Likewise.
	(tuple::operator=): Add __attribute__((unused)).
	* include/tr1/functional (Fnv_hash<4>::hash): Add static_cast.
	(Fnv_hash<8>::hash): Likewise.

	* testsuite/25_algorithms/iter_swap/20577.cc (swap): Remove name of
	unused parameter.
	* testsuite/25_algorithms/unique_copy/check_type.cc (S2::S2,X2::X2):
	Likewise.
	* testsuite/22_locale/ctype/narrow/char/19955.cc (do_narrow): Likewise.
	* testsuite/22_locale/ctype/is/char/9858.cc (Derived::do_is, 
	Derived::do_scan_is, Derived::do_scan_not, Derived2::do_is,
	Derived2::do_scan_is, Derived2::do_scan_not): Likewise.
	* testsuite/22_locale/time_put/put/wchar_t/12439_1.cc (TP::do_put):
	Likewise.
	* testsuite/22_locale/time_put/put/wchar_t/12439_3.cc (TP::do_put):
	Likewise.
	* testsuite/22_locale/time_put/put/char/12439_1.cc (TP::do_put):
	Likewise.
	* testsuite/22_locale/time_put/put/char/12439_3.cc (TP::do_put):
	Likewise.
	* testsuite/testsuite_io.h (fail_num_get::do_get, fail_num_put::do_put):
	Likewise.
	* testsuite/25_algorithms/find/17441.cc (find): Likewise.
	* testsuite/23_containers/vector/cons/clear_allocator.cc
	(clear_alloc::clear_alloc): Likewise.
	* testsuite/23_containers/vector/bool/clear_allocator.cc
	(clear_alloc::clear_alloc): Likewise.
	* testsuite/23_containers/list/cons/clear_allocator.cc
	(clear_alloc::clear_alloc): Likewise.
	* testsuite/23_containers/set/modifiers/16728.cc (test_container):
	Likewise.
	* testsuite/27_io/basic_ios/cons/char/3.cc (char_traits::to_char_type,
	to_int_type): Likewise.
	* testsuite/27_io/basic_filebuf/imbue/12206.cc (codecvt::do_out, do_in,
	do_unshift, do_length): Likewise.
	* testsuite/21_strings/basic_string/capacity/1.cc 
	(operator==(A<T>,A<T>), operator<(A<T>,A<T>),
	char_traits::to_char_type, char_traits::to_int_type): Likewise
	* testsuite/testsuite_character.h (ctype::do_is, ctype::do_scan_is,
	ctype::do_scan_not, do_toupper, do_tolower): Likewise.
	* testsuite/25_algorithms/replace_copy/check_type.cc (Z::operator=):
	Add missing return statement.
	* testsuite/25_algorithms/replace_copy_if/check_type.cc (Z::operator=):
	Likewise.
	* testsuite/testsuite_iterators.h (output_iterator_wrapper::operator=,
	random_access_iterator_wrapper::operator==): Likewise.
	* testsuite/20_util/functional/binders/1.cc (s::f_int_int_const,
	s::f_int_int, s::f_int_void_const, s::f_int_void): Likewise.
	* testsuite/27_io/types/1.cc (test01): Likewise.
	* testsuite/27_io/basic_ostream/write/wchar_t/1.cc (test01): Likewise.
	* testsuite/27_io/basic_ostream/write/char/1.cc (test01): Likewise.
	* testsuite/21_strings/c_strings/wchar_t/24559.cc (main): Likewise.
	* testsuite/27_io/basic_istream/ignore/wchar_t/2.cc (check): Add static
	cast.
	* testsuite/27_io/basic_istream/ignore/char/2.cc (check): Likewise.
	* testsuite/27_io/basic_istream/getline/wchar_t/5.cc (check): Likewise.
	* testsuite/27_io/basic_istream/getline/char/5.cc (check): Likewise.
	* testsuite/testsuite_allocator.h (check_new): Likewise.
	(check_deallocate_null): Add missing return value.
	* testsuite/ext/pool_allocator/allocate_chunk.cc (test01):
	Make variable unsigned.
	* testsuite/23_containers/vector/modifiers/erase/1.cc (N,N1,N2,N3,N4,
	N5,test01): Likewise.
	* testsuite/26_numerics/valarray/valarray_subset_assignment.cc
	(check_array): Likewise.
	(main): Removed unused variable.
	* testsuite/27_io/basic_streambuf/in_avail/wchar_t/1.cc (test05):
	Removed unused variable.
	* testsuite/27_io/basic_ostream/flush/wchar_t/1.cc (test01): Likewise.
	* testsuite/27_io/basic_ostream/flush/char/1.cc (test01): Likewise.
	* testsuite/27_io/basic_ostream/endl/wchar_t/1.cc (test01): Likewise.
	* testsuite/27_io/basic_ostream/endl/char/1.cc (test01): Likewise.
	* testsuite/27_io/basic_ostream/ends/wchar_t/1.cc (test01): Likewise.
	* testsuite/27_io/basic_ostream/ends/char/1.cc (test01): Likewise.
	* testsuite/tr1/2_general_utilities/memory/shared_ptr/
	assign/shared_ptr.cc (test01): Correct return type.	
	* testsuite/27_io/basic_filebuf/close/char/2.cc (test_02):
	Add default value to close_num.

From-SVN: r109062
2005-12-26 10:53:42 +00:00

541 lines
13 KiB
C++

// -*- C++ -*-
// Testing character type and state type with char_traits and codecvt
// specializations for the C++ library testsuite.
//
// Copyright (C) 2003, 2005 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
//
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#ifndef _GLIBCXX_TESTSUITE_CHARACTER_H
#define _GLIBCXX_TESTSUITE_CHARACTER_H
#include <climits>
#include <string> // for char_traits
#include <locale> // for codecvt
#include <ext/pod_char_traits.h>
namespace __gnu_test
{
struct pod_int
{
int value;
};
inline bool
operator==(const pod_int& lhs, const pod_int& rhs)
{ return lhs.value == rhs.value; }
inline bool
operator<(const pod_int& lhs, const pod_int& rhs)
{ return lhs.value < rhs.value; }
struct pod_state
{
unsigned long value;
};
inline bool
operator==(const pod_state& lhs, const pod_state& rhs)
{ return lhs.value == rhs.value; }
inline bool
operator<(const pod_state& lhs, const pod_state& rhs)
{ return lhs.value < rhs.value; }
// Alternate character types.
using __gnu_cxx::character;
typedef character<unsigned char, pod_int, pod_state> pod_char;
typedef character<unsigned char, unsigned int, pod_state> pod_uchar;
typedef character<unsigned short, unsigned int> pod_ushort;
typedef character<unsigned int, unsigned long> pod_uint;
}
namespace __gnu_cxx
{
// Specializations.
// pod_char
template<>
template<typename V2>
inline __gnu_test::pod_char::char_type
__gnu_test::pod_char::char_type::from(const V2& v)
{
char_type ret = { static_cast<value_type>(v.value) };
return ret;
}
template<>
template<typename V2>
inline V2
__gnu_test::pod_char::char_type::to(const char_type& c)
{
V2 ret = { c.value };
return ret;
}
template<>
template<typename V2>
inline __gnu_test::pod_uchar::char_type
__gnu_test::pod_uchar::char_type::from(const V2& v)
{
char_type ret;
ret.value = (v >> 5);
return ret;
}
template<>
template<typename V2>
inline V2
__gnu_test::pod_uchar::char_type::to(const char_type& c)
{ return static_cast<V2>(c.value << 5); }
}; // namespace __gnu_test
namespace std
{
// codecvt specialization
//
// The conversion performed by the specialization is not supposed to
// be useful, rather it has been designed to demonstrate the
// essential features of stateful conversions:
// * Number and value of bytes for each internal character depends on the
// state in addition to the character itself.
// * Unshift produces an unshift sequence and resets the state. On input
// the unshift sequence causes the state to be reset.
//
// The conversion for output is as follows:
// 1. Calculate the value tmp by xor-ing the state and the internal
// character
// 2. Split tmp into either two or three bytes depending on the value of
// state. Output those bytes.
// 3. tmp becomes the new value of state.
template<>
class codecvt<__gnu_test::pod_uchar, char, __gnu_test::pod_state>
: public __codecvt_abstract_base<__gnu_test::pod_uchar, char,
__gnu_test::pod_state>
{
public:
typedef codecvt_base::result result;
typedef __gnu_test::pod_uchar intern_type;
typedef char extern_type;
typedef __gnu_test::pod_state state_type;
typedef __codecvt_abstract_base<intern_type, extern_type, state_type>
base_type;
explicit codecvt(size_t refs = 0) : base_type(refs)
{ }
static locale::id id;
protected:
~codecvt()
{ }
virtual result
do_out(state_type& state, const intern_type* from,
const intern_type* from_end, const intern_type*& from_next,
extern_type* to, extern_type* to_limit,
extern_type*& to_next) const
{
while (from < from_end && to < to_limit)
{
unsigned char tmp = (state.value ^ from->value);
if (state.value & 0x8)
{
if (to >= to_limit - 2)
break;
*to++ = (tmp & 0x7);
*to++ = ((tmp >> 3) & 0x7);
*to++ = ((tmp >> 6) & 0x3);
}
else
{
if (to >= to_limit - 1)
break;
*to++ = (tmp & 0xf);
*to++ = ((tmp >> 4) & 0xf);
}
state.value = tmp;
++from;
}
from_next = from;
to_next = to;
return (from < from_end) ? partial : ok;
}
virtual result
do_in(state_type& state, const extern_type* from,
const extern_type* from_end, const extern_type*& from_next,
intern_type* to, intern_type* to_limit,
intern_type*& to_next) const
{
while (from < from_end && to < to_limit)
{
unsigned char c = *from;
if (c & 0xc0)
{
// Unshift sequence
state.value &= c;
++from;
continue;
}
unsigned char tmp;
if (state.value & 0x8)
{
if (from >= from_end - 2)
break;
tmp = (*from++ & 0x7);
tmp |= ((*from++ << 3) & 0x38);
tmp |= ((*from++ << 6) & 0xc0);
}
else
{
if (from >= from_end - 1)
break;
tmp = (*from++ & 0xf);
tmp |= ((*from++ << 4) & 0xf0);
}
to->value = (tmp ^ state.value);
state.value = tmp;
++to;
}
from_next = from;
to_next = to;
return (from < from_end) ? partial : ok;
}
virtual result
do_unshift(state_type& state, extern_type* to, extern_type* to_limit,
extern_type*& to_next) const
{
for (unsigned int i = 0; i < CHAR_BIT; ++i)
{
unsigned int mask = (1 << i);
if (state.value & mask)
{
if (to == to_limit)
{
to_next = to;
return partial;
}
state.value &= ~mask;
*to++ = static_cast<unsigned char>(~mask);
}
}
to_next = to;
return state.value == 0 ? ok : error;
}
virtual int
do_encoding() const throw()
{ return -1; }
virtual bool
do_always_noconv() const throw()
{ return false; }
virtual int
do_length(state_type& state, const extern_type* from,
const extern_type* end, size_t max) const
{
const extern_type* beg = from;
while (from < end && max)
{
unsigned char c = *from;
if (c & 0xc0)
{
// Unshift sequence
state.value &= c;
++from;
continue;
}
unsigned char tmp;
if (state.value & 0x8)
{
if (from >= end - 2)
break;
tmp = (*from++ & 0x7);
tmp |= ((*from++ << 3) & 0x38);
tmp |= ((*from++ << 6) & 0xc0);
}
else
{
if (from >= end - 1)
break;
tmp = (*from++ & 0xf);
tmp |= ((*from++ << 4) & 0xf0);
}
state.value = tmp;
--max;
}
return from - beg;
}
// Maximum 8 bytes unshift sequence followed by max 3 bytes for
// one character.
virtual int
do_max_length() const throw()
{ return 11; }
};
template<>
class ctype<__gnu_test::pod_uchar>
: public __ctype_abstract_base<__gnu_test::pod_uchar>
{
public:
typedef __gnu_test::pod_uchar char_type;
explicit ctype(size_t refs = 0)
: __ctype_abstract_base<__gnu_test::pod_uchar>(refs) { }
static locale::id id;
protected:
~ctype()
{ }
virtual bool
do_is(mask, char_type) const
{ return false; }
virtual const char_type*
do_is(const char_type* low, const char_type* high, mask* vec) const
{
fill_n(vec, high - low, mask());
return high;
}
virtual const char_type*
do_scan_is(mask, const char_type*, const char_type* high) const
{ return high; }
virtual const char_type*
do_scan_not(mask, const char_type* low, const char_type*) const
{ return low; }
virtual char_type
do_toupper(char_type c) const
{ return c; }
virtual const char_type*
do_toupper(char_type*, const char_type* high) const
{ return high; }
virtual char_type
do_tolower(char_type c) const
{ return c; }
virtual const char_type*
do_tolower(char_type*, const char_type* high) const
{ return high; }
virtual char_type
do_widen(char c) const
{ return __gnu_test::pod_uchar::from<char>(c); }
virtual const char*
do_widen(const char* low, const char* high, char_type* dest) const
{
transform(low, high, dest, &__gnu_test::pod_uchar::from<char>);
return high;
}
virtual char
do_narrow(char_type, char dfault) const
{ return dfault; }
virtual const char_type*
do_narrow(const char_type* low, const char_type* high,
char dfault, char* dest) const
{
fill_n(dest, high - low, dfault);
return high;
}
};
// numpunct specializations
template<>
class numpunct<__gnu_test::pod_uint>
: public locale::facet
{
public:
typedef __gnu_test::pod_uint char_type;
typedef basic_string<char_type> string_type;
static locale::id id;
explicit
numpunct(size_t refs = 0)
: locale::facet(refs)
{ }
char_type
decimal_point() const
{ return this->do_decimal_point(); }
char_type
thousands_sep() const
{ return this->do_thousands_sep(); }
string
grouping() const
{ return this->do_grouping(); }
string_type
truename() const
{ return this->do_truename(); }
string_type
falsename() const
{ return this->do_falsename(); }
protected:
~numpunct()
{ }
virtual char_type
do_decimal_point() const
{ return char_type(); }
virtual char_type
do_thousands_sep() const
{ return char_type(); }
virtual string
do_grouping() const
{ return string(); }
virtual string_type
do_truename() const
{ return string_type(); }
virtual string_type
do_falsename() const
{ return string_type(); }
};
template<>
class moneypunct<__gnu_test::pod_uint>
: public locale::facet, public money_base
{
public:
typedef __gnu_test::pod_uint char_type;
typedef basic_string<char_type> string_type;
static locale::id id;
static const bool intl = false;
explicit
moneypunct(size_t refs = 0)
: locale::facet(refs)
{ }
char_type
decimal_point() const
{ return this->do_decimal_point(); }
char_type
thousands_sep() const
{ return this->do_thousands_sep(); }
string
grouping() const
{ return this->do_grouping(); }
string_type
curr_symbol() const
{ return this->do_curr_symbol(); }
string_type
positive_sign() const
{ return this->do_positive_sign(); }
string_type
negative_sign() const
{ return this->do_negative_sign(); }
int
frac_digits() const
{ return this->do_frac_digits(); }
pattern
pos_format() const
{ return this->do_pos_format(); }
pattern
neg_format() const
{ return this->do_neg_format(); }
protected:
~moneypunct()
{ }
virtual char_type
do_decimal_point() const
{ return char_type(); }
virtual char_type
do_thousands_sep() const
{ return char_type(); }
virtual string
do_grouping() const
{ return string(); }
virtual string_type
do_curr_symbol() const
{ return string_type(); }
string_type
do_positive_sign() const
{ return string_type(); }
string_type
do_negative_sign() const
{ return string_type(); }
int
do_frac_digits() const
{ return 0; }
pattern
do_pos_format() const
{ return pattern(); }
pattern
do_neg_format() const
{ return pattern(); }
};
} // namespace std
#endif // _GLIBCXX_TESTSUITE_CHARACTER_H