first commit

This commit is contained in:
Jose Caban
2025-06-07 11:34:38 -04:00
commit 0eb2d7c07d
4708 changed files with 1500614 additions and 0 deletions

View File

@@ -0,0 +1,949 @@
/************************************************************************
*
* 21.strings.h - definitions of helpers used in clause 21 tests
*
* $Id: 21.strings.h 648752 2008-04-16 17:01:56Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#ifndef RW_21_STRINGS_H_INCLUDED
#define RW_21_STRINGS_H_INCLUDED
#include <rw_char.h> // for rw_expand()
#include <testdefs.h>
#include <23.containers.h> // for ContainerIds
/**************************************************************************/
// defines enumerations identifying basic_string template arguments,
// sets of overloaded functions, member types used in the declarations
// of their signatures, and specific overloads of such member functions
struct StringIds: ContainerIds {
// identifiers for the charT template argument
enum CharId { Char, WChar, UChar };
// identifiers for the Traits template argument
enum TraitsId { DefaultTraits, UserTraits };
// identifies a set of overloaded member or non-member
// string functions
enum FuncId {
// 6 bits, 64 functions max
/* 0 */ fid_append,
/* 1 */ fid_assign,
/* 2 */ fid_erase,
/* 3 */ fid_insert,
/* 4 */ fid_replace,
/* 5 */ fid_op_plus_eq,
/* 6 */ fid_find,
/* 7 */ fid_rfind,
/* 8 */ fid_find_first_of,
/* 9 */ fid_find_last_of,
/* 10 */ fid_find_first_not_of,
/* 11 */ fid_find_last_not_of,
/* 12 */ fid_compare,
/* 13 */ fid_substr,
/* 14 */ fid_op_index,
/* */ fid_op_index_const = fid_op_index,
/* 15 */ fid_at,
/* */ fid_at_const = fid_at,
/* 16 */ fid_copy,
/* 17 */ fid_ctor,
/* 18 */ fid_op_set,
/* 19 */ fid_swap,
/* 20 */ fid_push_back,
/* 21 */ fid_op_plus,
/* 22 */ fid_op_equal,
/* 23 */ fid_op_not_equal,
/* 24 */ fid_op_less,
/* 25 */ fid_op_less_equal,
/* 26 */ fid_op_greater,
/* 27 */ fid_op_greater_equal,
/* 28 */ fid_size,
/* 29 */ fid_length,
/* 30 */ fid_max_size,
/* 31 */ fid_resize,
/* 32 */ fid_capacity,
/* 33 */ fid_reserve,
/* 34 */ fid_clear,
/* 35 */ fid_empty,
/* 36 */ fid_begin,
/* */ fid_begin_const = fid_begin,
/* 37 */ fid_end,
/* */ fid_end_const = fid_end,
/* 38 */ fid_rbegin,
/* */ fid_rbegin_const = fid_rbegin,
/* 39 */ fid_rend,
/* */ fid_rend_const = fid_rend,
/* 40 */ fid_c_str,
/* 41 */ fid_data,
/* 42 */ fid_get_allocator,
/* 43 */ fid_extractor,
/* 44 */ fid_inserter,
/* 45 */ fid_getline,
/* -- */ fid_bits = 6,
/* -- */ fid_mask = 63
};
// identifies the type of a function argument, including
// the implicit this
enum ArgId {
// 4 bits, 16 types max
/* 0 */ arg_void, // void
/* 1 */ arg_size, // size_type
/* 2 */ arg_val, // value_type
/* 3 */ arg_ptr, // pointer
/* 4 */ arg_cptr, // const_pointer
/* 5 */ arg_ref, // reference
/* 6 */ arg_cref, // const_reference
/* 7 */ arg_iter, // iterator
/* 8 */ arg_citer, // const_iterator
/* 9 */ arg_range, // Iterator, Iterator
/* 10 */ arg_str, // string& (or this for member functions)
/* 11 */ arg_cstr, // const string& (or const this for members)
/* 12 */ arg_alloc, // const allocator&
/* 13 */ arg_istream, // istream&
/* 14 */ arg_ostream, // ostream&
/* -- */ arg_bits = 4,
/* -- */ arg_mask = 15
};
enum {
// bit designating a member function
bit_member = 1 << (fid_bits + 6 * arg_bits)
};
// define the helper macros
#include <rw_sigdefs.h>
// unique identifiers for all overloads of each member function
// 6 bits for FuncId
// 6 * 4 bits for ArgId (at most 6 arguments including this)
// 1 bit for membership
enum OverloadId {
//////////////////////////////////////////////////////////////
// append (const_pointer)
MEMBER_1 (append, str, cptr),
// append (const basic_string&)
MEMBER_1 (append, str, cstr),
// append (const_pointer, size_type)
MEMBER_2 (append, str, cptr, size),
// append (const basic_string&, size_type, size_type)
MEMBER_3 (append, str, cstr, size, size),
// append (size_type, value_type)
MEMBER_2 (append, str, size, val),
// append (InputIterator, InputIterator)
MEMBER_1 (append, str, range),
//////////////////////////////////////////////////////////////
// assign (const_pointer)
MEMBER_1 (assign, str, cptr),
// assign (const basic_string&)
MEMBER_1 (assign, str, cstr),
// assign (const_pointer, size_type)
MEMBER_2 (assign, str, cptr, size),
// assign (const basic_string&, size_type, size_type)
MEMBER_3 (assign, str, cstr, size, size),
// assign (size_type, value_type)
MEMBER_2 (assign, str, size, val),
// assign (InputIterator, InputIterator)
MEMBER_1 (assign, str, range),
//////////////////////////////////////////////////////////////
// erase ()
MEMBER_0 (erase, str),
// erase (size_type)
MEMBER_1 (erase, str, size),
// erase (size_type, size_type)
MEMBER_2 (erase, str, size, size),
// erase (iterator)
MEMBER_1 (erase, str, iter),
// erase (iterator, iterator)
MEMBER_2 (erase, str, iter, iter),
//////////////////////////////////////////////////////////////
// insert (size_type, const_pointer)
MEMBER_2 (insert, str, size, cptr),
// insert (size_type, const basic_string&)
MEMBER_2 (insert, str, size, cstr),
// insert (size_type, const_pointer, size_type)
MEMBER_3 (insert, str, size, cptr, size),
// insert (size_type, const basic_string&, size_type, size_type)
MEMBER_4 (insert, str, size, cstr, size, size),
// insert (size_type, size_type, value_type)
MEMBER_3 (insert, str, size, size, val),
// insert (iterator, value_type)
MEMBER_2 (insert, str, iter, val),
// insert (iterator, size_type, value_type)
MEMBER_3 (insert, str, iter, size, val),
// insert (iterator, InputIterator, InputIterator)
MEMBER_2 (insert, str, iter, range),
//////////////////////////////////////////////////////////////
// (size_type, size_type, const_pointer)
MEMBER_3 (replace, str, size, size, cptr),
// (size_type, size_type, const basic_string&)
MEMBER_3 (replace, str, size, size, cstr),
// (size_type, size_type, const_pointer, size_type)
MEMBER_4 (replace, str, size, size, cptr, size),
// (size_type, size_type, const basic_string&, size_type, size_type)
MEMBER_5 (replace, str, size, size, cstr, size, size),
// (size_type, size_type, size_type, value_type)
MEMBER_4 (replace, str, size, size, size, val),
// (iterator, iterator, const_pointer)
MEMBER_3 (replace, str, iter, iter, cptr),
// (iterator, iterator, const basic_string&)
MEMBER_3 (replace, str, iter, iter, cstr),
// (iterator, iterator, const_pointer, size_type)
MEMBER_4 (replace, str, iter, iter, cptr, size),
// (iterator, iterator, size_type, value_type)
MEMBER_4 (replace, str, iter, iter, size, val),
// (iterator, iterator, InputIterator, InputIterator)
MEMBER_3 (replace, str, iter, iter, range),
//////////////////////////////////////////////////////////////
// operator+= (const_pointer)
MEMBER_1 (op_plus_eq, str, cptr),
// operator+= (const basic_string&)
MEMBER_1 (op_plus_eq, str, cstr),
// operator+= (value_type)
MEMBER_1 (op_plus_eq, str, val),
//////////////////////////////////////////////////////////////
// overloads of find, rfind, find_first_of, find_last_of,
// find_first_not_of, find_last_not_of
// find (const_pointer) const
MEMBER_1 (find, cstr, cptr),
// find (const basic_string&) const
MEMBER_1 (find, cstr, cstr),
// find (const_pointer, size_type) const
MEMBER_2 (find, cstr, cptr, size),
// find (const_pointer, size_type, size_type) const
MEMBER_3 (find, cstr, cptr, size, size),
// find (const basic_string&, size_type) const
MEMBER_2 (find, cstr, cstr, size),
// find (value_type) const
MEMBER_1 (find, cstr, val),
// find (value_type, size_type) const
MEMBER_2 (find, cstr, val, size),
//////////////////////////////////////////////////////////////
// rfind (const_pointer) const
MEMBER_1 (rfind, cstr, cptr),
// rfind (const basic_string&) const
MEMBER_1 (rfind, cstr, cstr),
// rfind (const_pointer, size_type) const
MEMBER_2 (rfind, cstr, cptr, size),
// rfind (const_pointer, size_type, size_type) const
MEMBER_3 (rfind, cstr, cptr, size, size),
// rfind (const basic_string&, size_type) const
MEMBER_2 (rfind, cstr, cstr, size),
// rfind (value_type) const
MEMBER_1 (rfind, cstr, val),
// rfind (value_type, size_type) const
MEMBER_2 (rfind, cstr, val, size),
//////////////////////////////////////////////////////////////
// find_first_of (const_pointer) const
MEMBER_1 (find_first_of, cstr, cptr),
// find_first_of (const basic_string&) const
MEMBER_1 (find_first_of, cstr, cstr),
// find_first_of (const_pointer, size_type) const
MEMBER_2 (find_first_of, cstr, cptr, size),
// find_first_of (const_pointer, size_type, size_type) const
MEMBER_3 (find_first_of, cstr, cptr, size, size),
// find_first_of (const basic_string&, size_type) const
MEMBER_2 (find_first_of, cstr, cstr, size),
// find_first_of (value_type) const
MEMBER_1 (find_first_of, cstr, val),
// find_first_of (value_type, size_type) const
MEMBER_2 (find_first_of, cstr, val, size),
//////////////////////////////////////////////////////////////
// find_last_of (const_pointer) const
MEMBER_1 (find_last_of, cstr, cptr),
// find_last_of (const basic_string&) const
MEMBER_1 (find_last_of, cstr, cstr),
// find_last_of (const_pointer, size_type) const
MEMBER_2 (find_last_of, cstr, cptr, size),
// find_last_of (const_pointer, size_type, size_type) const
MEMBER_3 (find_last_of, cstr, cptr, size, size),
// find_last_of (const basic_string&, size_type) const
MEMBER_2 (find_last_of, cstr, cstr, size),
// find_last_of (value_type) const
MEMBER_1 (find_last_of, cstr, val),
// find_last_of (value_type, size_type) const
MEMBER_2 (find_last_of, cstr, val, size),
//////////////////////////////////////////////////////////////
// find_first_not_of (const_pointer) const
MEMBER_1 (find_first_not_of, cstr, cptr),
// find_first_not_of (const basic_string&) const
MEMBER_1 (find_first_not_of, cstr, cstr),
// find_first_not_of (const_pointer, size_type) const
MEMBER_2 (find_first_not_of, cstr, cptr, size),
// find_first_not_of (const_pointer, size_type, size_type) const
MEMBER_3 (find_first_not_of, cstr, cptr, size, size),
// find_first_not_of (const basic_string&, size_type) const
MEMBER_2 (find_first_not_of, cstr, cstr, size),
// find_first_not_of (value_type) const
MEMBER_1 (find_first_not_of, cstr, val),
// find_first_not_of (value_type, size_type) const
MEMBER_2 (find_first_not_of, cstr, val, size),
//////////////////////////////////////////////////////////////
// find_last_not_of (const_pointer) const
MEMBER_1 (find_last_not_of, cstr, cptr),
// find_last_not_of (const basic_string&) const
MEMBER_1 (find_last_not_of, cstr, cstr),
// find_last_not_of (const_pointer, size_type) const
MEMBER_2 (find_last_not_of, cstr, cptr, size),
// find_last_not_of (const_pointer, size_type, size_type) const
MEMBER_3 (find_last_not_of, cstr, cptr, size, size),
// find_last_not_of (const basic_string&, size_type) const
MEMBER_2 (find_last_not_of, cstr, cstr, size),
// find_last_not_of (value_type) const
MEMBER_1 (find_last_not_of, cstr, val),
// find_last_not_of (value_type, size_type) const
MEMBER_2 (find_last_not_of, cstr, val, size),
//////////////////////////////////////////////////////////////
// compare (const_pointer) const
MEMBER_1 (compare, cstr, cptr),
// compare (const basic_string&) const
MEMBER_1 (compare, cstr, cstr),
// compare (size_type, size_type, const_pointer) const
MEMBER_3 (compare, cstr, size, size, cptr),
// compare (size_type, size_type, const basic_string&) const
MEMBER_3 (compare, cstr, size, size, cstr),
// compare (size_type, size_type, const_pointer, size_type) const
MEMBER_4 (compare, cstr, size, size, cptr, size),
// compare (size_type, size_type, const basic_string&,
// size_type, size_type) const
MEMBER_5 (compare, cstr, size, size, cstr, size, size),
//////////////////////////////////////////////////////////////
// substr (void) const
MEMBER_0 (substr, cstr),
// substr (size_type) const
MEMBER_1 (substr, cstr, size),
// substr (size_type, size_type) const
MEMBER_2 (substr, cstr, size, size),
//////////////////////////////////////////////////////////////
// operator[] (size_type)
MEMBER_1 (op_index, str, size),
// operator[] (size_type) const
MEMBER_1 (op_index_const, cstr, size),
// at (size_type)
MEMBER_1 (at, str, size),
// at (size_type) const
MEMBER_1 (at_const, cstr, size),
//////////////////////////////////////////////////////////////
// copy (pointer, size_type) const
MEMBER_2 (copy, cstr, ptr, size),
// copy (pointer, size_type, size_type) const
MEMBER_3 (copy, cstr, ptr, size, size),
//////////////////////////////////////////////////////////////
// basic_string (void)
MEMBER_0 (ctor, str),
// basic_string (const allocator_type&)
MEMBER_1 (ctor, str, alloc),
// basic_string (const_pointer)
MEMBER_1 (ctor, str, cptr),
// basic_string (const_pointer, const allocator_type&)
MEMBER_2 (ctor, str, cptr, alloc),
// basic_string (const basic_string&)
MEMBER_1 (ctor, str, cstr),
// basic_string (const_pointer, size_type)
MEMBER_2 (ctor, str, cptr, size),
// basic_string (const_pointer, size_type, const allocator_type&)
MEMBER_3 (ctor, str, cptr, size, alloc),
// basic_string (const basic_string&, size_type)
MEMBER_2 (ctor, str, cstr, size),
// basic_string (const basic_string&, size_type, const allocator&)
MEMBER_3 (ctor, str, cstr, size, alloc),
// basic_string (const basic_string&, size_type, size_type)
MEMBER_3 (ctor, str, cstr, size, size),
// basic_string (const basic_string&, size_type, size_type, allocator&)
MEMBER_4 (ctor, str, cstr, size, size, alloc),
// basic_string (size_type, value_type)
MEMBER_2 (ctor, str, size, val),
// basic_string (size_type, value_type, const allocator_type&)
MEMBER_3 (ctor, str, size, val, alloc),
// basic_string (InputIterator, InputIterator)
MEMBER_1 (ctor, str, range),
// basic_string (InputIterator, InputIterator, const allocator&)
MEMBER_2 (ctor, str, range, alloc),
//////////////////////////////////////////////////////////////
// operator= (const_pointer)
MEMBER_1 (op_set, str, cptr),
// operator= (const basic_string&)
MEMBER_1 (op_set, str, cstr),
// operator= (value_type)
MEMBER_1 (op_set, str, val),
//////////////////////////////////////////////////////////////
// swap (basic_string&)
MEMBER_1 (swap, str, str),
//////////////////////////////////////////////////////////////
// push_back (value_type)
MEMBER_1 (push_back, str, val),
//////////////////////////////////////////////////////////////
// operator+ (const_pointer, const basic_string&)
NON_MEMBER_2 (op_plus, cptr, cstr),
// operator+ (const basic_string&, const basic_string&)
NON_MEMBER_2 (op_plus, cstr, cstr),
// operator+ (const basic_string&, const_pointer)
NON_MEMBER_2 (op_plus, cstr, cptr),
// operator+ (const basic_string&, value_type)
NON_MEMBER_2 (op_plus, cstr, val),
// operator+ (value_type, const basic_string&)
NON_MEMBER_2 (op_plus, val, cstr),
//////////////////////////////////////////////////////////////
// operator== (const_pointer, const basic_string&)
NON_MEMBER_2 (op_equal, cptr, cstr),
// operator== (const basic_string&, const basic_string&)
NON_MEMBER_2 (op_equal, cstr, cstr),
// operator== (const basic_string&, const_pointer)
NON_MEMBER_2 (op_equal, cstr, cptr),
//////////////////////////////////////////////////////////////
// operator!= (const_pointer, const basic_string&)
NON_MEMBER_2 (op_not_equal, cptr, cstr),
// operator!= (const basic_string&, const basic_string&)
NON_MEMBER_2 (op_not_equal, cstr, cstr),
// operator!= (const basic_string&, const_pointer)
NON_MEMBER_2 (op_not_equal, cstr, cptr),
//////////////////////////////////////////////////////////////
// operator< (const_pointer, const basic_string&)
NON_MEMBER_2 (op_less, cptr, cstr),
// operator< (const basic_string&, const basic_string&)
NON_MEMBER_2 (op_less, cstr, cstr),
// operator< (const basic_string&, const_pointer)
NON_MEMBER_2 (op_less, cstr, cptr),
//////////////////////////////////////////////////////////////
// operator<= (const_pointer, const basic_string&)
NON_MEMBER_2 (op_less_equal, cptr, cstr),
// operator<= (const basic_string&, const basic_string&)
NON_MEMBER_2 (op_less_equal, cstr, cstr),
// operator<= (const basic_string&, const_pointer)
NON_MEMBER_2 (op_less_equal, cstr, cptr),
//////////////////////////////////////////////////////////////
// operator> (const_pointer, const basic_string&)
NON_MEMBER_2 (op_greater, cptr, cstr),
// operator> (const basic_string&, const basic_string&)
NON_MEMBER_2 (op_greater, cstr, cstr),
// operator> (const basic_string&, const_pointer)
NON_MEMBER_2 (op_greater, cstr, cptr),
//////////////////////////////////////////////////////////////
// operator>= (const_pointer, const basic_string&)
NON_MEMBER_2 (op_greater_equal, cptr, cstr),
// operator>= (const basic_string&, const basic_string&)
NON_MEMBER_2 (op_greater_equal, cstr, cstr),
// operator>= (const basic_string&, const_pointer)
NON_MEMBER_2 (op_greater_equal, cstr, cptr),
//////////////////////////////////////////////////////////////
// size () const
MEMBER_0 (size, cstr),
//////////////////////////////////////////////////////////////
// length () const
MEMBER_0 (length, cstr),
//////////////////////////////////////////////////////////////
// max_size () const
MEMBER_0 (max_size, cstr),
//////////////////////////////////////////////////////////////
// resize (size_type, value_type)
MEMBER_2 (resize, str, size, val),
// resize (size_type)
MEMBER_1 (resize, str, size),
//////////////////////////////////////////////////////////////
// capacity () const
MEMBER_0 (capacity, cstr),
//////////////////////////////////////////////////////////////
// reserve (size_type)
MEMBER_1 (reserve, str, size),
// reserve ()
MEMBER_0 (reserve, str),
//////////////////////////////////////////////////////////////
// clear ()
MEMBER_0 (clear, str),
//////////////////////////////////////////////////////////////
// empty () const
MEMBER_0 (empty, cstr),
//////////////////////////////////////////////////////////////
// begin ()
MEMBER_0 (begin, str),
// begin () const
MEMBER_0 (begin_const, cstr),
// end ()
MEMBER_0 (end, str),
// end () const
MEMBER_0 (end_const, cstr),
//////////////////////////////////////////////////////////////
// rbegin ()
MEMBER_0 (rbegin, str),
// rbegin () const
MEMBER_0 (rbegin_const, cstr),
// rend ()
MEMBER_0 (rend, str),
// rend () const
MEMBER_0 (rend_const, cstr),
//////////////////////////////////////////////////////////////
// c_str () const
MEMBER_0 (c_str, cstr),
// data () const
MEMBER_0 (data, cstr),
//////////////////////////////////////////////////////////////
// get_allocator () const
MEMBER_0 (get_allocator, cstr),
//////////////////////////////////////////////////////////////
// operator>> (istream&, basic_string&)
NON_MEMBER_2 (extractor, istream, str),
// operator<< (ostream&, const basic_string&)
NON_MEMBER_2 (inserter, ostream, cstr),
//////////////////////////////////////////////////////////////
// getline (istream&, basic_string&)
NON_MEMBER_2 (getline, istream, str),
// getline (istream&, basic_string&, value_type)
NON_MEMBER_3 (getline, istream, str, val)
};
// clean up helper macros used above
#include <rw_sigdefs.h>
static ArgId arg_type (OverloadId id, int argno) {
return ArgId (((int (id) >> fid_bits) >> argno * arg_bits) & arg_mask);
}
};
/**************************************************************************/
static const _RWSTD_SIZE_T
NPOS = _RWSTD_SIZE_MAX;
/**************************************************************************/
struct StringFunc
{
StringIds::CharId char_id_;
StringIds::TraitsId traits_id_;
StringIds::AllocId alloc_id_;
StringIds::IteratorId iter_id_;
StringIds::OverloadId which_;
};
// describes a single test case for any overload of any string
// function (the same test case can be used to exercise more
// than one overload of the same function)
struct StringTestCase
{
int line; // test case line number
int off; // offset (position argument)
int size; // size (count argument)
int off2; // offset 2 (position argument)
int size2; // size 2 (count argument)
int val; // value (single character to append)
const char* str; // controlled sequence
_RWSTD_SIZE_T str_len; // length of sequence
const char* arg; // sequence to insert
_RWSTD_SIZE_T arg_len; // length of sequence
const char* res; // resulting sequence
_RWSTD_SIZE_T nres; // length of sequence or expected result
// value for find, rfind, compare, etc
int bthrow; // exception expected
};
// describes a set of test cases for a single overload of a function
struct StringTest
{
// string function overload to exercise
StringIds::OverloadId which;
// test cases to exercise overload withh
const StringTestCase *cases;
// number of test cases
_RWSTD_SIZE_T case_count;
};
// sets the {CLASS}, {FUNC}, {FUNCSIG}, and optionally {FUNCALL}
// environment variables as follows:
// CLASS: the name of basic_string specialization
// FUNC: the name of the basic_string function
// FUNCSIG: the name and signature of a specific overload
// of the basic_string function
// FUNCALL: a string describing the call to the basic_string function
// with function with function arguments expanded (as specified
// by the TestCase argument)
_TEST_EXPORT void
rw_setvars (const StringFunc&, const StringTestCase* = 0);
typedef void StringTestFunc (const StringFunc&, const StringTestCase&);
_TEST_EXPORT int
rw_run_string_test (int, char**, const char*, const char*,
StringTestFunc*, const StringTest*, _RWSTD_SIZE_T);
typedef void VoidFunc ();
_TEST_EXPORT int
rw_run_string_test (int, char**, const char*, const char*,
VoidFunc* const*, const StringTest*, _RWSTD_SIZE_T);
/**************************************************************************/
template <class charT>
class StringTestCaseData
{
private:
enum { BUFSIZE = 256 };
// small buffers to avoid expensive dynamic memory allocation
// in most test cases (will dynamically allocate sufficient
// storage if necessary)
charT str_buf_ [BUFSIZE];
charT arg_buf_ [BUFSIZE];
charT res_buf_ [BUFSIZE];
// not defined, not copiable, not assignable
StringTestCaseData (const StringTestCaseData&);
void operator= (const StringTestCaseData&);
// for convenience
typedef _RWSTD_SIZE_T SizeType;
public:
SizeType strlen_; // the length of the expanded string
SizeType arglen_; // the length of the expanded argument
SizeType reslen_; // the length of the expanded result
// the offset and extent (the number of elements) of
// the first range into the string object being modified
SizeType off1_;
SizeType ext1_;
// the offset and extent (the number of elements) of
// the argument of the function call
SizeType off2_;
SizeType ext2_;
const charT* const str_; // pointer to the expanded string
const charT* const arg_; // pointer to the expanded argument
const charT* const res_; // pointer to the expanded result
const StringFunc &func_;
const StringTestCase &tcase_;
// converts the narrow (and possibly) condensed strings to fully
// expanded wide character arrays that can be used to construct
// basic_string objects
StringTestCaseData (const StringFunc &func, const StringTestCase &tcase)
: strlen_ (BUFSIZE), arglen_ (BUFSIZE), reslen_ (BUFSIZE),
str_ (rw_expand (str_buf_, tcase.str, tcase.str_len, &strlen_)),
arg_ (rw_expand (arg_buf_, tcase.arg, tcase.arg_len, &arglen_)),
res_ (rw_expand (res_buf_, tcase.res, tcase.nres, &reslen_)),
func_ (func), tcase_ (tcase) {
// compute the offset and extent of the string object
// representing the controlled sequence and the offset
// and extent of the argument of the function call
const SizeType argl = tcase_.arg ? arglen_ : strlen_;
off1_ = SizeType (tcase_.off) < strlen_ ?
SizeType (tcase_.off) : strlen_;
ext1_ = off1_ + tcase_.size < strlen_ ?
SizeType (tcase_.size) : strlen_ - off1_;
off2_ = SizeType (tcase_.off2) < argl ?
SizeType (tcase_.off2) : argl;
ext2_ = off2_ + tcase_.size2 < argl ?
SizeType (tcase_.size2) : argl - off2_;
}
~StringTestCaseData () {
// clean up dynamically allocated memory (if any)
if (str_ != str_buf_)
delete[] _RWSTD_CONST_CAST (charT*, str_);
if (arg_ != arg_buf_)
delete[] _RWSTD_CONST_CAST (charT*, arg_);
if (res_ != res_buf_)
delete[] _RWSTD_CONST_CAST (charT*, res_);
}
};
/**************************************************************************/
// encapsulates the state of a string object without regard to type
// used in exception safety tests to determine changes to the state
// after a modifying operation throws an exception
struct _TEST_EXPORT StringState
{
const void* data_;
_RWSTD_SIZE_T size_;
_RWSTD_SIZE_T capacity_;
// invokes rw_assert() to verify that two states are the same
// returns 1 when the two states compare equal, and 0 otherwise
int assert_equal (const StringState&, int, int, const char*) const;
};
// creates a StringState object from a basic_string
template <class String>
inline StringState
rw_get_string_state (const String &str)
{
const StringState state = {
str.data (), str.size (), str.capacity ()
};
return state;
}
/**************************************************************************/
// base class-functor for the range template overloads testing
template <class String>
struct RangeBase {
typedef typename String::value_type StringChar;
typedef typename String::pointer StringPtr;
typedef typename String::const_pointer StringConstPtr;
typedef typename String::iterator StringIter;
typedef typename String::const_iterator StringConstIter;
typedef typename String::reverse_iterator StringRevIter;
typedef typename String::const_reverse_iterator StringConstRevIter;
RangeBase () { }
virtual ~RangeBase () { /* silence warnings */ }
static StringPtr
begin (String &str, StringPtr*) {
return _RWSTD_CONST_CAST (StringPtr, str.data ());
}
static StringConstPtr
begin (const String &str, StringConstPtr*) {
return str.data ();
}
#ifndef _RWSTD_NO_DEBUG_ITER
// when debugging iterators are enabled string::iterator and
// string::pointer are distinct types; otherwise they are the
// same type
static StringIter
begin (String &str, StringIter*) {
return str.begin ();
}
static StringConstIter
begin (const String &str, StringConstIter*) {
return str.begin ();
}
#endif // _RWSTD_NO_DEBUG_ITER
static StringRevIter
begin (String &str, StringRevIter*) {
return str.rbegin ();
}
static StringConstRevIter
begin (const String &str, StringConstRevIter*) {
return str.rbegin ();
}
virtual String&
operator() (String &str, const StringTestCaseData<StringChar>&) const {
RW_ASSERT (!"logic error: should be never called");
return str;
}
};
/**************************************************************************/
#define Disabled(which) \
StringIds::opt_memfun_disabled [which & ~StringIds::fid_mask]
#ifndef _RWSTD_NO_WCHAR_T
# define TEST_DISPATCH(Alloc, fname, func, tcase) \
if (StringIds::DefaultTraits == func.traits_id_) { \
if (StringIds::Char == func.char_id_) \
fname (char (), (std::char_traits<char>*)0, \
(Alloc<char>*)0, func, tcase); \
else if (StringIds::WChar == func.char_id_) \
fname (wchar_t (), (std::char_traits<wchar_t>*)0, \
(Alloc<wchar_t>*)0, func, tcase); \
else \
rw_note (0, 0, 0, \
"%{$CLASS} tests not implemented"); \
} \
else { \
if (StringIds::Char == func.char_id_) \
fname (char (), (UserTraits<char>*)0, \
(Alloc<char>*)0, func, tcase); \
else if (StringIds::WChar == func.char_id_) \
fname (wchar_t (), (UserTraits<wchar_t>*)0, \
(Alloc<wchar_t>*)0, func, tcase); \
else \
fname (UserChar (), (UserTraits<UserChar>*)0, \
(Alloc<UserChar>*)0, func, tcase); \
} \
(void)0
#else // if defined (_RWSTD_NO_WCHAR_T)
# define TEST_DISPATCH(Alloc, fname, func, tcase) \
if (StringIds::DefaultTraits == func.traits_id_) { \
if (StringIds::Char == func.char_id_) \
fname (char (), (std::char_traits<char>*)0, \
(Alloc<char>*)0, func, tcase); \
else if (StringIds::WChar == func.char_id_) \
RW_ASSERT (!"logic error: wchar_t disabled"); \
else \
rw_note (0, 0, 0, \
"%{$CLASS} tests not implemented"); \
} \
} \
else { \
if (StringIds::Char == func.char_id_) \
fname (char (), (UserTraits<char>*)0, \
(Alloc<char>*)0, func, tcase); \
else if (StringIds::WChar == func.char_id_) \
RW_ASSERT (!"logic error: wchar_t disabled"); \
else if (StringIds::UChar == func.char_id_) \
fname (UserChar (), (UserTraits<UserChar>*)0, \
(Alloc<UserChar>*)0, func, tcase); \
} \
(void)0
#endif // _RWSTD_NO_WCHAR_T
#define DEFINE_STRING_TEST_DISPATCH(fname) \
static void \
fname (const StringFunc &func, \
const StringTestCase &tcase) { \
if (StringIds::DefaultAlloc == func.alloc_id_) { \
TEST_DISPATCH (std::allocator, fname, func, tcase); \
} \
else if (StringIds::UserAlloc == func.alloc_id_) { \
TEST_DISPATCH (UserAlloc, fname, func, tcase); \
} \
else \
RW_ASSERT (!"logic error: bad allocator"); \
} typedef void rw_unused_typedef
#define TFUNC(charT, Traits, Allocator) \
void (*)(charT*, Traits<charT>*, Allocator<charT>*, \
const StringTestCaseData<charT>&)
#define TFUNC_ADDR(fname, charT, Traits, Allocator) \
(VoidFunc*)(TFUNC (charT, Traits, Allocator)) \
&fname<charT, Traits<charT>, Allocator<charT> >
#ifndef _RWSTD_NO_WCHAR_T
# define DEFINE_STRING_TEST_FUNCTIONS(fname) \
static VoidFunc* const fname ## _func_array [] = { \
TFUNC_ADDR (fname, char, std::char_traits, std::allocator), \
TFUNC_ADDR (fname, char, std::char_traits, UserAlloc), \
TFUNC_ADDR (fname, char, UserTraits, std::allocator), \
TFUNC_ADDR (fname, char, UserTraits, UserAlloc), \
\
TFUNC_ADDR (fname, wchar_t, std::char_traits, std::allocator), \
TFUNC_ADDR (fname, wchar_t, std::char_traits, UserAlloc), \
TFUNC_ADDR (fname, wchar_t, UserTraits, std::allocator), \
TFUNC_ADDR (fname, wchar_t, UserTraits, UserAlloc), \
\
(VoidFunc*)0, /* std::char_traits<UserChar> not allowed */ \
(VoidFunc*)0, /* std::char_traits<UserChar> not allowed */ \
TFUNC_ADDR (fname, UserChar, UserTraits, std::allocator), \
TFUNC_ADDR (fname, UserChar, UserTraits, UserAlloc) \
}
#else // if defined (_RWSTD_NO_WCHAR_T)
# define DEFINE_STRING_TEST_FUNCTIONS(fname) \
static VoidFunc* const fname ## _func_array [] = { \
TFUNC_ADDR (fname, char, std::char_traits, std::allocator), \
TFUNC_ADDR (fname, char, std::char_traits, UserAlloc), \
TFUNC_ADDR (fname, char, UserTraits, std::allocator), \
TFUNC_ADDR (fname, char, UserTraits, UserAlloc), \
\
(VoidFunc*)0, /* wchar_t disabled */ \
(VoidFunc*)0, /* wchar_t disabled */ \
(VoidFunc*)0, /* wchar_t disabled */ \
(VoidFunc*)0, /* wchar_t disabled */ \
\
(VoidFunc*)0, /* std::char_traits<UserChar> not allowed */ \
(VoidFunc*)0, /* std::char_traits<UserChar> not allowed */ \
TFUNC_ADDR (fname, UserChar, UserTraits, std::allocator), \
TFUNC_ADDR (fname, UserChar, UserTraits, UserAlloc) \
}
#endif // _RWSTD_NO_WCHAR_T
#endif // RW_21_STRINGS_H_INCLUDED

View File

@@ -0,0 +1,420 @@
/************************************************************************
*
* 23.containers.h - definitions of helpers used in clause 23 tests
*
* $Id: 23.containers.h$
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#ifndef RW_23_CONTAINERS_H_INCLUDED
#define RW_23_CONTAINERS_H_INCLUDED
#include <testdefs.h>
#include <rw_value.h> // for UserClass, UserPOD
#include <rw_char.h> // for rw_expand ()
/**************************************************************************/
// defines enumerations identifying the general template arguments,
// sets of overloaded functions, member types used in the declarations
// of their signatures, and specific overloads of such member functions
struct ContainerIds {
// identifiers for the T template argument
enum ElemId { UserPOD, UserClass };
// identifiers for the Allocator template argument
enum AllocId { DefaultAlloc, UserAlloc };
// identifiers for the Iterator template argument
// used with member templates
enum IteratorId {
None,
Input, Forward, Bidir, Random,
Pointer, ConstPointer,
Iterator, ConstIterator,
ReverseIterator, ConstReverseIterator
};
enum ContainerId {
List, Vector, Deque, Queue, Stack
};
// identifies a set of overloaded member or non-member
// container functions
enum FuncId {
// 6 bits, 64 functions max
// common
/* 0 */ fid_ctor,
/* 1 */ fid_op_set,
/* 2 */ fid_assign,
/* 3 */ fid_get_allocator,
/* 4 */ fid_begin,
/* */ fid_begin_const = fid_begin,
/* 5 */ fid_end,
/* */ fid_end_const = fid_end,
/* 6 */ fid_rbegin,
/* */ fid_rbegin_const = fid_rbegin,
/* 7 */ fid_rend,
/* */ fid_rend_const = fid_rend,
/* 8 */ fid_empty,
/* 9 */ fid_size,
/* 10 */ fid_max_size,
/* 11 */ fid_resize,
/* 12 */ fid_insert,
/* 13 */ fid_erase,
/* 14 */ fid_swap,
/* 15 */ fid_clear,
/* 16 */ fid_op_equal,
/* 17 */ fid_op_less,
/* 18 */ fid_op_not_equal,
/* 19 */ fid_op_greater,
/* 20 */ fid_op_greater_equal,
/* 21 */ fid_op_less_equal,
/* 22 */ fid_push_back,
// list, deque, vector
/* 23 */ fid_front,
/* */ fid_front_const = fid_front,
/* 24 */ fid_back,
/* */ fid_back_const = fid_back,
/* 25 */ fid_pop_back,
// list, deque
/* 26 */ fid_push_front,
/* 27 */ fid_pop_front,
// list
/* 28 */ fid_splice,
/* 29 */ fid_remove,
/* 30 */ fid_remove_if,
/* 31 */ fid_unique,
/* 32 */ fid_merge,
/* 33 */ fid_sort,
/* 34 */ fid_reverse,
// vector, string, deque
/* 35 */ fid_op_index,
/* */ fid_op_index_const = fid_op_index,
/* 36 */ fid_at,
/* */ fid_at_const = fid_at,
// vector, string
/* 37 */ fid_capacity,
/* 38 */ fid_reserve,
// vector<bool>
/* 39 */ fid_flip,
/* -- */ fid_bits = 6,
/* -- */ fid_mask = 63
};
// identifies the type of a function argument, including
// the implicit this
enum ArgId {
// 4 bits, 16 types max
/* 0 */ arg_void, // void
/* 1 */ arg_size, // size_type
/* 2 */ arg_val, // value_type
/* 3 */ arg_ref, // reference
/* 4 */ arg_cref, // const_reference
/* 5 */ arg_iter, // iterator
/* 6 */ arg_citer, // const_iterator
/* 7 */ arg_range, // Iterator, Iterator
/* 8 */ arg_cont, // container& (or this for member functions)
/* 9 */ arg_ccont, // const container& (or const this for members)
/* 10 */ arg_alloc, // const allocator&
/* 11 */ arg_pred, // Predicate
/* 12 */ arg_bpred, // BinaryPredicate
/* 13 */ arg_comp, // Compare
/* -- */ arg_bits = 4,
/* -- */ arg_mask = 15
};
enum {
// bit designating a member function
bit_member = 1 << (fid_bits + 6 * arg_bits)
};
static ArgId arg_type (_RWSTD_SIZE_T id, int argno) {
return ArgId (((id >> fid_bits) >> argno * arg_bits) & arg_mask);
}
};
/**************************************************************************/
struct ContainerFunc
{
ContainerIds::ElemId elem_id_;
ContainerIds::AllocId alloc_id_;
ContainerIds::IteratorId iter_id_;
ContainerIds::ContainerId cont_id_;
_RWSTD_SIZE_T which_;
};
// describes a single test case for any overload of any container
// function (the same test case can be used to exercise more
// than one overload of the same function)
struct ContainerTestCase
{
int line; // test case line number
int off; // offset (position argument)
int size; // size (count argument)
int off2; // offset 2 (position argument)
int size2; // size 2 (count argument)
int val; // value (single character to append)
const char* str; // controlled sequence
_RWSTD_SIZE_T str_len; // length of sequence
const char* arg; // sequence to insert
_RWSTD_SIZE_T arg_len; // length of sequence
const char* res; // resulting sequence
_RWSTD_SIZE_T nres; // length of sequence or expected result value
int bthrow; // exception expected
};
// describes a set of test cases for a single overload of a function
struct ContainerTest
{
// container function overload to exercise
_RWSTD_SIZE_T which;
// test cases to exercise overload with
const ContainerTestCase *cases;
// number of test cases
_RWSTD_SIZE_T case_count;
};
typedef void ContainerTestFunc (const ContainerFunc&, const ContainerTestCase&);
_TEST_EXPORT int
rw_run_cont_test (int, char**, const char*, const char*,
ContainerIds::ContainerId, ContainerTestFunc*,
const ContainerTest*, _RWSTD_SIZE_T);
typedef void VoidFunc ();
_TEST_EXPORT int
rw_run_cont_test (int, char**, const char*, const char*,
ContainerIds::ContainerId, VoidFunc* const*,
const ContainerTest*, _RWSTD_SIZE_T);
/**************************************************************************/
template <class T>
class ContainerTestCaseData
{
private:
// not defined, not copyable, not assignable
ContainerTestCaseData (const ContainerTestCaseData&);
void operator= (const ContainerTestCaseData&);
// for convenience
typedef _RWSTD_SIZE_T SizeType;
public:
SizeType strlen_; // the length of the expanded string
SizeType arglen_; // the length of the expanded argument
SizeType reslen_; // the length of the expanded result
// the offset and extent (the number of elements) of
// the first range into the container object being modified
SizeType off1_;
SizeType ext1_;
// the offset and extent (the number of elements) of
// the argument of the function call
SizeType off2_;
SizeType ext2_;
const T* str_; // pointer to the expanded string
const T* arg_; // pointer to the expanded argument
const T* res_; // pointer to the expanded result
const ContainerFunc &func_;
const ContainerTestCase &tcase_;
// converts the narrow (and possibly) condensed strings to fully
// expanded wide character arrays that can be used to construct
// container objects
ContainerTestCaseData (const ContainerFunc&,
const ContainerTestCase&);
~ContainerTestCaseData ();
};
template <class T>
ContainerTestCaseData<T>::
ContainerTestCaseData (const ContainerFunc &func,
const ContainerTestCase &tcase)
: func_ (func), tcase_ (tcase)
{
char buf [256];
strlen_ = sizeof (buf);
char* str = rw_expand (buf, tcase.str, tcase.str_len, &strlen_);
str_ = T::from_char (str, strlen_);
if (str != buf)
delete[] str;
arglen_ = sizeof (buf);
str = rw_expand (buf, tcase.arg, tcase.arg_len, &arglen_);
arg_ = T::from_char (str, arglen_);
if (str != buf)
delete[] str;
reslen_ = sizeof (buf);
str = rw_expand (buf, tcase.res, tcase.nres, &reslen_);
res_ = T::from_char (str, reslen_);
if (str != buf)
delete[] str;
// compute the offset and extent of the container object
// representing the controlled sequence and the offset
// and extent of the argument of the function call
const SizeType argl = tcase_.arg ? arglen_ : strlen_;
off1_ = SizeType (tcase_.off) < strlen_ ?
SizeType (tcase_.off) : strlen_;
ext1_ = off1_ + tcase_.size < strlen_ ?
SizeType (tcase_.size) : strlen_ - off1_;
off2_ = SizeType (tcase_.off2) < argl ?
SizeType (tcase_.off2) : argl;
ext2_ = off2_ + tcase_.size2 < argl ?
SizeType (tcase_.size2) : argl - off2_;
}
template <class T>
ContainerTestCaseData<T>::
~ContainerTestCaseData ()
{
// clean up dynamically allocated memory
// cast away the constness of the pointers to work around
// an HP aCC 6.16 and prior bug described in STDCXX-802
delete[] _RWSTD_CONST_CAST (T*, str_);
delete[] _RWSTD_CONST_CAST (T*, arg_);
delete[] _RWSTD_CONST_CAST (T*, res_);
}
/**************************************************************************/
// base class-functor for the range template overloads testing
template <class Cont>
struct ContRangeBase {
typedef typename Cont::value_type ContVal;
typedef typename Cont::iterator ContIter;
typedef typename Cont::const_iterator ContConstIter;
typedef typename Cont::reverse_iterator ContRevIter;
typedef typename Cont::const_reverse_iterator ContConstRevIter;
ContRangeBase () { }
virtual ~ContRangeBase () { /* silence warnings */ }
static ContIter
begin (Cont &cont, ContIter*) {
return cont.begin ();
}
static ContConstIter
begin (const Cont &cont, ContConstIter*) {
return cont.begin ();
}
static ContRevIter
begin (Cont &cont, ContRevIter*) {
return cont.rbegin ();
}
static ContConstRevIter
begin (const Cont &cont, ContConstRevIter*) {
return cont.rbegin ();
}
virtual Cont&
operator() (Cont &cont, const ContainerTestCaseData<ContVal>&) const {
RW_ASSERT (!"logic error: should be never called");
return cont;
}
};
/**************************************************************************/
# define CONTAINER_TEST_DISPATCH(Alloc, fname, func, tcase) \
if (ContainerIds::UserPOD == func.elem_id_) \
fname (UserPOD (), (Alloc<UserPOD>*)0, func, tcase); \
else \
fname (UserClass (), (Alloc<UserClass>*)0, func, tcase)
#define DEFINE_CONTAINER_TEST_DISPATCH(fname) \
static void \
fname (const ContainerFunc &func, \
const ContainerTestCase &tcase) { \
if (ContainerIds::DefaultAlloc == func.alloc_id_) { \
CONTAINER_TEST_DISPATCH (std::allocator, fname, func, tcase); \
} \
else if (ContainerIds::UserAlloc == func.alloc_id_) { \
CONTAINER_TEST_DISPATCH (UserAlloc, fname, func, tcase); \
} \
else \
RW_ASSERT (!"logic error: bad allocator"); \
} typedef void rw_unused_typedef
#define CONTAINER_TFUNC(T, Allocator) \
void (*)(T*, Allocator<T>*, \
const ContainerTestCaseData<T>&)
#define CONTAINER_TFUNC_ADDR(fname, T, Allocator) \
(VoidFunc*)(CONTAINER_TFUNC (T, Allocator)) \
&fname<T, Allocator<T> >
#define DEFINE_CONTAINER_TEST_FUNCTIONS(fname) \
static VoidFunc* const fname ## _func_array [] = { \
CONTAINER_TFUNC_ADDR (fname, UserPOD, std::allocator), \
CONTAINER_TFUNC_ADDR (fname, UserPOD, UserAlloc), \
\
CONTAINER_TFUNC_ADDR (fname, UserClass, std::allocator), \
CONTAINER_TFUNC_ADDR (fname, UserClass, UserAlloc) \
}
#endif // RW_23_CONTAINERS_H_INCLUDED

View File

@@ -0,0 +1,282 @@
/************************************************************************
*
* 23.list.h - definitions of helpers used in clause 23.list tests
*
* $Id: 23.list.h
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#ifndef RW_23_LIST_H_INCLUDED
#define RW_23_LIST_H_INCLUDED
#include <23.containers.h>
#include <driver.h> // for rw_assert()
#include <rw_sigdefs.h> // for helper macros
/**************************************************************************/
// defines enumerations identifying list template arguments,
// sets of overloaded functions, member types used in the declarations
// of their signatures, and specific overloads of such member functions
struct ListIds : ContainerIds
{
// unique identifiers for all overloads of each member function
// 6 bits for FuncId
// 6 * 4 bits for ArgId (at most 6 arguments including this)
// 1 bit for membership
enum OverloadId {
//////////////////////////////////////////////////////////////
// list ()
MEMBER_0 (ctor, cont),
// list (const allocator_type&)
MEMBER_1 (ctor, cont, alloc),
// list (const list&)
MEMBER_1 (ctor, cont, ccont),
// list (size_type)
MEMBER_1 (ctor, cont, size),
// list (size_type, const value_type&)
MEMBER_2 (ctor, cont, size, cref),
// list (size_type, const value_type&, const allocator_type&)
MEMBER_3 (ctor, cont, size, cref, alloc),
// list (InputIterator, InputIterator)
MEMBER_1 (ctor, cont, range),
// list (InputIterator, InputIterator, const allocator&)
MEMBER_2 (ctor, cont, range, alloc),
//////////////////////////////////////////////////////////////
// operator= (const list&)
MEMBER_1 (op_set, cont, ccont),
//////////////////////////////////////////////////////////////
// assign (size_type, const value_type&)
MEMBER_2 (assign, cont, size, cref),
// assign (InputIterator, InputIterator)
MEMBER_1 (assign, cont, range),
//////////////////////////////////////////////////////////////
// get_allocator () const
MEMBER_0 (get_allocator, ccont),
//////////////////////////////////////////////////////////////
// begin ()
MEMBER_0 (begin, cont),
// begin () const
MEMBER_0 (begin_const, ccont),
// end ()
MEMBER_0 (end, cont),
// end () const
MEMBER_0 (end_const, ccont),
//////////////////////////////////////////////////////////////
// rbegin ()
MEMBER_0 (rbegin, cont),
// rbegin () const
MEMBER_0 (rbegin_const, ccont),
// rend ()
MEMBER_0 (rend, cont),
// rend () const
MEMBER_0 (rend_const, ccont),
//////////////////////////////////////////////////////////////
// empty ()
MEMBER_0 (empty, ccont),
//////////////////////////////////////////////////////////////
// size ()
MEMBER_0 (size, ccont),
//////////////////////////////////////////////////////////////
// max_size ()
MEMBER_0 (max_size, ccont),
//////////////////////////////////////////////////////////////
// resize (size_type)
MEMBER_1 (resize, cont, size),
// resize (size_type, value_type)
MEMBER_2 (resize, cont, size, val),
//////////////////////////////////////////////////////////////
// front ()
MEMBER_0 (front, cont),
// front () const
MEMBER_0 (front_const, ccont),
// back ()
MEMBER_0 (back, cont),
// back () const
MEMBER_0 (back_const, ccont),
//////////////////////////////////////////////////////////////
// push_front (const value_type&)
MEMBER_1 (push_front, cont, cref),
// pop_front ()
MEMBER_0 (pop_front, cont),
// push_back (const value_type&)
MEMBER_1 (push_back, cont, cref),
// pop_back ()
MEMBER_0 (pop_back, cont),
//////////////////////////////////////////////////////////////
// insert (iterator, const value_type&)
MEMBER_2 (insert, cont, iter, cref),
// insert (iterator, size_type, const value_type&)
MEMBER_3 (insert, cont, iter, size, cref),
// insert (iterator, InputIterator, InputIterator)
MEMBER_2 (insert, cont, iter, range),
//////////////////////////////////////////////////////////////
// erase (iterator)
MEMBER_1 (erase, cont, iter),
// erase (iterator, iterator)
MEMBER_2 (erase, cont, iter, iter),
//////////////////////////////////////////////////////////////
// swap (list&)
MEMBER_1 (swap, cont, cont),
// swap (list&, list&)
NON_MEMBER_2 (swap, cont, cont),
//////////////////////////////////////////////////////////////
// clear ()
MEMBER_0 (clear, cont),
//////////////////////////////////////////////////////////////
// splice (iterator, list&)
MEMBER_2 (splice, cont, iter, cont),
// splice (iterator, list&, iterator)
MEMBER_3 (splice, cont, iter, cont, iter),
// splice (iterator, list&, iterator, iterator)
MEMBER_4 (splice, cont, iter, cont, iter, iter),
//////////////////////////////////////////////////////////////
// remove (const value_type&)
MEMBER_1 (remove, cont, cref),
// remove_if (Predicate)
MEMBER_1 (remove_if, cont, pred),
//////////////////////////////////////////////////////////////
// unique (BinaryPredicate)
MEMBER_1 (unique, cont, bpred),
//////////////////////////////////////////////////////////////
// merge (list&)
MEMBER_1 (merge, cont, cont),
// merge (list&, Compare)
MEMBER_2 (merge, cont, cont, comp),
//////////////////////////////////////////////////////////////
// sort ()
MEMBER_0 (sort, cont),
// sort (Compare)
MEMBER_1 (sort, cont, comp),
//////////////////////////////////////////////////////////////
// reverse ()
MEMBER_0 (reverse, cont),
//////////////////////////////////////////////////////////////
// operator== (const list&, const list&)
NON_MEMBER_2 (op_equal, ccont, ccont),
//////////////////////////////////////////////////////////////
// operator< (const list&, const list&)
NON_MEMBER_2 (op_less, ccont, ccont),
//////////////////////////////////////////////////////////////
// operator!= (const list&, const list&)
NON_MEMBER_2 (op_not_equal, ccont, ccont),
//////////////////////////////////////////////////////////////
// operator> (const list&, const list&)
NON_MEMBER_2 (op_greater, ccont, ccont),
//////////////////////////////////////////////////////////////
// operator>= (const list&, const list&)
NON_MEMBER_2 (op_greater_equal, ccont, ccont),
//////////////////////////////////////////////////////////////
// operator<= (const list&, const list&)
NON_MEMBER_2 (op_less_equal, ccont, ccont)
};
// clean up helper macros used above
#include <rw_sigdefs.h>
};
/**************************************************************************/
template <class InputIter1, class InputIter2>
inline bool
_rw_equal (InputIter1 first1, InputIter1 last1, InputIter2 first2)
{
for (; first1 != last1 && *first1 == *first2; ++first1, ++first2) ;
return first1 == last1;
}
// encapsulates the state of a list object
// used in exception safety tests to determine changes to the state
// after a modifying operation throws an exception
template <class List>
struct ListState
{
typedef typename List::const_iterator ListCIter;
typedef typename List::const_pointer ListCPtr;
_RWSTD_SIZE_T size_;
ListCIter* iters_;
ListCPtr* ptrs_;
ListState (List const & lst) : size_ (lst.size ()), iters_ (0), ptrs_ (0) {
iters_ = new ListCIter [size_];
ptrs_ = new ListCPtr [size_];
_RWSTD_SIZE_T index = 0;
for (ListCIter it = lst.begin (), end = lst.end ();
it != end; ++it, ++index) {
iters_ [index] = it;
ptrs_ [index] = &*it;
}
}
~ListState () {
delete [] iters_;
delete [] ptrs_;
}
// invokes rw_assert() to verify that two states are the same
void assert_equal (const ListState& state, int line,
int case_line, const char* when) const {
const bool equal = size_ == state.size_
&& _rw_equal (iters_, iters_ + size_, state.iters_)
&& _rw_equal (ptrs_, ptrs_ + size_, state.ptrs_);
rw_assert (equal, 0, case_line,
"line %d: %{$FUNCALL}: object state unexpectedly changed "
"after %s", line, when);
}
};
/**************************************************************************/
#endif // RW_23_LIST_H_INCLUDED

File diff suppressed because it is too large Load Diff

151
extern/stdcxx/4.2.1/tests/include/any.h vendored Normal file
View File

@@ -0,0 +1,151 @@
// -*- C++ -*-
/***************************************************************************
*
* any.h - definition of utility class rw_any_t
*
* $Id: any.h 590052 2007-10-30 12:44:14Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 2006 Rogue Wave Software.
*
**************************************************************************/
#ifndef RW_ANY_H_INCLUDED
#define RW_ANY_H_INCLUDED
#include <testdefs.h>
class _TEST_EXPORT rw_any_t
{
public:
#ifndef _RWSTD_NO_BOOL
rw_any_t (bool);
#endif // _RWSTD_NO_BOOL
rw_any_t (char);
rw_any_t (signed char);
rw_any_t (unsigned char);
rw_any_t (signed short);
rw_any_t (unsigned short);
rw_any_t (signed int);
rw_any_t (unsigned int);
rw_any_t (signed long);
rw_any_t (unsigned long);
#ifdef _RWSTD_LONG_LONG
rw_any_t (signed _RWSTD_LONG_LONG);
rw_any_t (unsigned _RWSTD_LONG_LONG);
#endif // _RWSTD_LONG_LONG
rw_any_t (float);
rw_any_t (double);
#ifndef _RWSTD_NO_LONG_DOUBLE
rw_any_t (long double);
#endif // _RWSTD_NO_LONG_DOUBLE
rw_any_t (void*);
rw_any_t (volatile void*);
rw_any_t (const void*);
rw_any_t (const volatile void*);
rw_any_t (char*);
rw_any_t (const char*);
rw_any_t (volatile char*);
rw_any_t (const volatile char*);
#ifndef _RWSTD_NO_NATIVE_WCHAR_T
rw_any_t (wchar_t);
#endif // _RWSTD_NO_NATIVE_WCHAR_T
#ifndef _RWSTD_NO_WCHAR_T
rw_any_t (wchar_t*);
rw_any_t (const wchar_t*);
rw_any_t (volatile wchar_t*);
rw_any_t (const volatile wchar_t*);
#endif // _RWSTD_NO_WCHAR_T
rw_any_t (const rw_any_t&);
~rw_any_t ();
rw_any_t& operator= (const rw_any_t&);
const char* tostr (const char* = 0);
const char* type_name () const;
enum type_id_t {
t_none,
t_bool, t_schar, t_uchar, t_char,
t_sshrt, t_ushrt, t_sint, t_uint, t_slong, t_ulong,
t_sllong, t_ullong,
t_flt, t_dbl, t_ldbl,
t_wchar,
t_pvoid, t_c_pvoid, t_v_pvoid, t_cv_pvoid,
t_str, t_c_str, t_v_str, t_cv_str,
t_wstr, t_c_wstr, t_v_wstr, t_cv_wstr
};
private:
union uval_t {
#ifndef _RWSTD_NO_LONG_DOUBLE
long double ldbl_;
#endif // _RWSTD_NO_LONG_DOUBLE
const volatile void *pvoid_;
double dbl_;
#ifdef _RWSTD_LONG_LONG
signed _RWSTD_LONG_LONG sllong_;
unsigned _RWSTD_LONG_LONG ullong_;
#endif // _RWSTD_LONG_LONG
float flt_;
#ifndef _RWSTD_NO_NATIVE_WCHAR_T
wchar_t wchar_;
#endif // _RWSTD_NO_NATIVE_WCHAR_T
signed long slong_;
unsigned long ulong_;
signed int sint_;
unsigned int uint_;
signed short sshrt_;
unsigned short ushrt_;
signed char schar_;
unsigned char uchar_;
char char_;
#ifndef _RWSTD_NO_BOOL
bool bool_;
#endif // _RWSTD_NO_BOOL
} val_;
char *str_;
type_id_t tid_;
};
#define TOSTR(x) rw_any_t (x).tostr ()
#endif // RW_ANY_H_INCLUDED

View File

@@ -0,0 +1,144 @@
/***************************************************************************
*
* cmdopt.h - declarations of helper functions for the processing
* of command line options
*
* $Id: cmdopt.h 550991 2007-06-26 23:58:07Z sebor $
*
************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 1994-2006 Rogue Wave Software.
*
**************************************************************************/
#ifndef RW_CMDOPT_H_INCLUDED
#define RW_CMDOPT_H_INCLUDED
#include <testdefs.h> // for test config macros
/**
* Appends a set of command line options and their handlers to the global
* list of command line option handlers for the current process.
*
* @param optspec A string of command line option specifiers describing
* the names and parameters of the command line options and their
* handlers. The string has the following syntax:
*
* <optspec> ::= <opt> [ ':' | '=' | '#' ]
* [ @N | @* | '!' ]
* [ <opts> ]
* <opt> ::= <sopt> [ '|' <lopt>]
* ::= '|' <lopt>
* <sopt> ::= char
* <lopt> ::= '-' char char*
* <char> ::= 'A' - 'Z', 'a'-'z', '0' - '9', '_'
*
* Each command line option may have a short name, a long name,
* or both. When referenced (either on the command line or in
* the environment), the name of command line option is
* introduced by a hyphen ('-').
*
* A short option name (<sopt>) consits of a single alphanumeric
* character or an underscore ('_').
*
* A long name (<lopt>) starts with a hyphen ('-') followed by
* one or more aphanumeric characters or underscores.
*
* The name of the command line option is followd by one or more
* special characters with the following meaning:
*
* ':' the option takes an optional argument
* '=' the option takes a required argument that must immediately
* follow the equals sign
* '#' the handler for this option is not a function but rather
* a pointer to an signed integer that rw_runopts() sets to
* a non-zero value if the option appears on the command line
* @N the option handler will be invoked for the first N
* occurrences of the option name on the command line
* @* the option handler will be invoked for every occurrence
* of the option name on the command line
* ! the option handler will be invoked only if the option name
* does not appear on the command line
*
* @param ... A list of zero or more command line option handlers whose
* type is either int (*)(int, char**) or int*, the latter
* corresponding to options denoted with the '#' special character.
*
* @return On success, returns the number of command line options
* currently defined for the process, negative value on error.
*/
_TEST_EXPORT int
rw_setopts (const char *optspec, ...);
/**
* Processes the set of command line options and arguments specified by
* the function arguments (usually the same arguments as those passed to
* main()).
*
* @param argc The number of non-zero elements of the argv vector.
* @param argv An array of pointers to command line options and arguments
* whose the last element, argv [argc], has the value 0.
*
* @return Returns the status of last evaluated command line option handler.
*/
_TEST_EXPORT int
rw_runopts (int argc, char *argv[]);
/**
* Processes the set of command line options and arguments specified by
* the function argument (usually the value of an environment variable).
*
* @param argvstr A character string of command line options and arguments
* separated by one or more spaces.
*
* @return Returns the status of last evaluated command line option handler.
*/
_TEST_EXPORT int
rw_runopts (const char *argvstr);
/**
* Determines whether a feature is enabled.
*
* @param name The name of a feature.
*
* @return Returns a non-zero value if the named feature is enabled,
* otherwise 0.
*/
_TEST_EXPORT int
rw_enabled (const char *name);
/**
* Determines whether a case (or line) is enabled.
*
* @param name The case (or line) number
*
* @return Returns a non-zero value if the case (line) is enabled,
* otherwise 0.
*/
_TEST_EXPORT int
rw_enabled (int line);
#endif // RW_CMDOPT_H_INCLUDED

View File

@@ -0,0 +1,179 @@
/************************************************************************
*
* driver.h - testsuite driver declarations
*
* $Id: driver.h 648752 2008-04-16 17:01:56Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 1994-2005 Rogue Wave Software.
*
**************************************************************************/
#ifndef RW_DRIVER_H_INCLUDED
#define RW_DRIVER_H_INCLUDED
#include <testdefs.h> // for test config macros
/**
* Initializes the test driver, passes program arguments to it, processes
* command line arguments, any arguments specified in the environment
* variable RWSTD_TESTOPTS, and if successful, invokes the program-supplied
* callback function.
*
* @param argc The number of non-null elements in the argv array.
* @param argv A null-terminated array of command line arguments.
* If (argc == 0) the argument may be null.
* @param filename The name of the source file name, typically
* the __FILE__ macro. The argument may be null.
* @param clause The clause exercised by the program, such as
* lib.basic.string. The argument may be null.
* @param comment An optional comment describing in more detail
* the functionality of the program. The argument may be null.
* @param testfun A pointer to a callback function to call by the
* driver after successful initialization. The argument must
* not be null.
* @param optspec An optional character string describing command
* line options accepted by the program. The argument may
* be null.
* @param ... Optional list of handlers of command line options
* corresponding to the optspec.
*
* @return If initialization is successful, returns the value returned
* by the callback function. Otherwise, returns the non-zero
* value returned by the last initialization function or
* command line option handler.
*
* After the driver has been initialzied the user-supplied callback function
* may call any of the driver diagnostic functions to record and perhaps also
* issue diagnostic messages of varying severity.
*
* There are 10 levels of severity with 0 being the lowest and 9 the highest.
* Diagnostics of all levels of severity come in two states: active and
* inactive. All diagnostics are recorded but normally only active diagnostics
* of severity 4 or above are issued. It is possible to cause diagnostics of
* lower severity levels to be issued via a command line option to the driver.
* Choosing to issue severity 0 diagnostics has the effect of issuing inactive
* diagnostics.
*
* After the callback function returns the driver displays a summary detailing
* the number of recorded diagnostics in each of the two states (active and
* inactive).
*
*/
_TEST_EXPORT int
rw_test (int argc,
char* argv[],
const char* filename,
const char* clause,
const char* comment,
int (*testfun)(int, char**),
const char* optspec,
...);
/**
* Records and optionally issues a diagnostic of the highest severity 9.
*
* @param expr A zero value denoting an active diagnostic or any non-zero
* vaue denoting an inactive diagnostic.
* @param filename An optional name of the file invoking the function.
* The argument may be null.
* @param line When positive, denotes the line number of the location
* relevant to the diagnostic. Negative values are ignored.
* @param fmtspec A printf format specifier (with extensions) used
* to format the text of the diagnostic.
* @param ... Optional list of values to format.
*
* @return Returns the value of expr passed to it.
*
* Every diagnostic is recorded but only active diagnostics may be issued,
* depending on the setting of the diagnosable severity. The value of the
* first argument determines whether a diagnostc is active or inactive.
* Unlike the remaining diagnostic functions, rw_fatal doesn't return to
* the caller when expr is 0 (i.e., when the diagnostic is active).
* Instead, it causes the driver the exit the process with the staus equal
* to 9, the severity of the diagnostic.
*/
_TEST_EXPORT int
rw_fatal (int expr,
const char* filename,
int line,
const char* fmtspec,
...);
/**
* Records and optionally issues a diagnostic of severity 8.
*
* @see #rw_fatal
*/
_TEST_EXPORT int
rw_error (int, const char*, int, const char*, ...);
/**
* Records and optionally issues a diagnostic of severity 7.
*
* @see #rw_fatal
*/
_TEST_EXPORT int
rw_assert (int, const char*, int, const char*, ...);
/**
* Records and optionally issues a diagnostic of severity 5.
*
* @see #rw_fatal
*/
_TEST_EXPORT int
rw_warn (int, const char*, int, const char*, ...);
/**
* Records and optionally issues a diagnostic of severity 2.
*
* @see #rw_fatal
*/
_TEST_EXPORT int
rw_note (int, const char*, int, const char*, ...);
/**
* Records and optionally issues a diagnostic of severity 1.
*
* @see #rw_fatal
*/
_TEST_EXPORT int
rw_info (int, const char*, int, const char*, ...);
/**
* Enable/disable the specified diagnostic.
*
* @param fun Diagnostic function to enable or disable. Must be one of
* rw_fatal, rw_error, rw_assert, rw_warn, rw_note or rw_info.
* @param enable Flag to indicate that the diagnostic function should
* be enabled or disabled.
* @return Returns the previous state of the diagnostic. If the first
* parameter is not an acceptable input, will return false.
*
* Example:
* rw_enable (rw_error, false); // disable all rw_error diagnostics
* rw_enable (rw_error); // enable all rw_error diagnostics
*/
_TEST_EXPORT bool
rw_enable (int (*fun) (int, const char*, int, const char*, ...),
bool enable = true);
#endif // RW_DRIVER_H_INCLUDED

View File

@@ -0,0 +1,45 @@
/************************************************************************
*
* environ.h - declarations of testsuite helpers
*
* $Id: environ.h 550991 2007-06-26 23:58:07Z sebor $
*
************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 1994-2006 Rogue Wave Software.
*
**************************************************************************/
#ifndef RW_ENVIRON_H_INCLUDED
#define RW_ENVIRON_H_INCLUDED
#include <testdefs.h>
// rw_putenv is a wrapper for the C standard library putenv function
// when called with the first argument of 0, rw_putenv defines any
// environment variables specified in the RW_PUTENV environment
// variable (e.g., RW_PUTENV=:foo=1:bar=2 will cause the variables
// foo=1 and bar=2 to be defined in the environment)
_TEST_EXPORT int
rw_putenv (const char*, int = -1);
#endif // RW_ENVIRON_H_INCLUDED

107
extern/stdcxx/4.2.1/tests/include/file.h vendored Normal file
View File

@@ -0,0 +1,107 @@
/************************************************************************
*
* file.h - common file I/O definitions
*
* $Id: file.h 423332 2006-07-19 01:40:24Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 2004-2006 Rogue Wave Software.
*
**************************************************************************/
#ifndef RW_FILE_H_INCLUDED
#define RW_FILE_H_INCLUDED
#include <testdefs.h> // for test config macros
#ifndef _MSC_VER
// POSIX special files:
// http://www.opengroup.org/onlinepubs/007904975/basedefs/xbd_chap10.html
# define DEV_CONSOLE "/dev/console"
# define DEV_NULL "/dev/null"
# define DEV_TTY "/dev/tty"
#else // if defined (_MSC_VER)
# define DEV_CONSOLE "CON:"
# define DEV_NULL "NUL:"
# define DEV_TTY "CON:"
#endif // _MSC_VER
#if _RWSTD_PATH_SEP == '/'
# define SLASH "/"
# define SHELL_MV "mv "
# define SHELL_RM_F "rm -f "
# define SHELL_RM_RF "rm -rf "
#else
# define SLASH "\\"
# define SHELL_MV "move /Y "
# define SHELL_RM_F "del /F "
# define SHELL_RM_RF "rmdir /Q /S "
#endif
// writes chars using symbolic names from the Portable Character Set (PCS)
// or using the <U00XX> notations for narrow characters outside that set
// if teh second argument is 0, writes out the CHARMAP section of the locale
// definition file for the Portable Character Set (in POSIX-compliant format)
_TEST_EXPORT void
pcs_write (void*, const char*);
// creates a unique temporary file name as if by calling tmpnam()
// but avoiding various platform-specific quirks (such as HP-UX
// failure when _REENTRANT is #defined or GNU glibc warnings)
_TEST_EXPORT
const char* rw_tmpnam (char*);
// tries to open file named by the first argument and, if successful,
// allocates a block of storage sufficiently large to hold the file's
// entire contents, as determined by the stat() function; it then reads
// the contents of the file into the block of storage, returning a pointer
// to the block; if the second argument is non-0, sets the pointed-to value
// to the number of bytes read
// as a special case, when the first argument is 0 and the second is not,
// the function takes the third argument as a pointer to the buffer that
// it will use to read the contents of files into in subsequent calls,
// provided the buffer is large enough
_TEST_EXPORT void*
rw_fread (const char*,
_RWSTD_SIZE_T* = 0 /* size in bytes */,
const char* = "r" /* stdio open mode */);
// if the second argument is non-0, writes N bytes starting at that
// location into the file named by the first argument; N is taken
// from the value pointed to by the third argument, if non-0, or
// as the result of calling strlen() on the buffer pointed to by
// the second argument; if the second argument is 0, the function
// removes the named file; returns the number of bytes written
_TEST_EXPORT _RWSTD_SIZE_T
rw_fwrite (const char*,
const void*,
_RWSTD_SIZE_T = ~0 /* size in bytes */,
const char* = "w" /* stdio open mode */ );
_TEST_EXPORT int
rw_nextfd (int*);
#endif // RW_FILE_H_INCLUDED

View File

@@ -0,0 +1,51 @@
/************************************************************************
*
* alarm.h - declaration of rw_alarm() and other helpers
*
* $Id: rw_alarm.h 550991 2007-06-26 23:58:07Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 1994-2006 Rogue Wave Software.
*
**************************************************************************/
#ifndef RW_ALARM_H_INCLUDED
#define RW_ALARM_H_INCLUDED
#include <testdefs.h>
extern "C" {
typedef void rw_signal_handler_t (int);
extern _TEST_EXPORT rw_signal_handler_t* const rw_sig_dfl;
extern _TEST_EXPORT rw_signal_handler_t* const rw_sig_ign;
extern _TEST_EXPORT rw_signal_handler_t* const rw_sig_hold;
extern _TEST_EXPORT rw_signal_handler_t* const rw_sig_restore;
}
_TEST_EXPORT unsigned
rw_alarm (unsigned int, rw_signal_handler_t* = 0);
#endif // RW_ALARM_H_INCLUDED

View File

@@ -0,0 +1,56 @@
/************************************************************************
*
* rw_alloc.h - definitions of rw_alloc and rw_free
*
* $Id: rw_alloc.h
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#ifndef RW_ALLOC_H_INCLUDED
#define RW_ALLOC_H_INCLUDED
#include <testdefs.h> // for test config macros
enum {
RW_PROT_NONE = 0,
RW_PROT_READ = 1 << 0,
RW_PROT_WRITE = 1 << 1,
RW_PROT_RDWR = RW_PROT_READ | RW_PROT_WRITE,
RW_PROT_BELOW = 1 << 3
};
// if flags == -1 memory will be allocated by malloc();
// if flags != -1 memory will be allocated by system call and
// additional guard page with PAGE_NOACCESS protection will be allocated
// if RW_PROT_BELOW & flags != 0 then guard page will be located right
// before the user data, otherwise - right after the user data
// if RWSTD_ALLOC_FLAGS environment variable is defined and != 0
// and flags == -1, then rw_alloc will use value of RWSTD_ALLOC_FLAGS
// instead of flags variable
_TEST_EXPORT void*
rw_alloc(_RWSTD_SIZE_T, int /*flags*/ = -1);
// free the memory block, allocated by rw_alloc()
_TEST_EXPORT void
rw_free(void*);
#endif // RW_ALLOC_H_INCLUDED

View File

@@ -0,0 +1,292 @@
/**************************************************************************
*
* rw_allocator.h - user-defined allocator type
*
* $Id: rw_allocator.h 550991 2007-06-26 23:58:07Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 2006 Rogue Wave Software.
*
**************************************************************************/
#ifndef RW_ALLOCATOR_INCLUDED
#define RW_ALLOCATOR_INCLUDED
#include <testdefs.h>
_RWSTD_NAMESPACE (std) {
// declare to avoid dragging in all of <memory>
// (yes, it is undefined for programs to do that)
template <class T>
class allocator;
} // namespace std
struct _TEST_EXPORT SharedAlloc
{
// identifies each member function of a standard allocator class
enum MemFun {
m_ctor, // ordinary constructor
m_cpy_ctor, // copy constructor
m_cvt_ctor, // converting (template) constructor
m_cpy_assign, // ordinary assignment operator
m_cvt_assign, // converting (template) assignment operator
m_dtor, // destructor
m_allocate, m_deallocate,
m_construct, m_destroy,
m_address, m_max_size,
n_funs
};
// constructs an allocator object managing a memory pool
// of the specified size (bytes and blocks)
SharedAlloc (_RWSTD_SIZE_T /* max_bytes */ = _RWSTD_SIZE_MAX,
_RWSTD_SIZE_T /* max_blocks */ = _RWSTD_SIZE_MAX);
virtual ~SharedAlloc ();
// attempts to allocate storage for nelems objects of elemsize
// bytes each and returns a pointer to the allocated storage
// on success; throws std::bad_alloc on failure
virtual void*
allocate (_RWSTD_SIZE_T /* nelems */,
_RWSTD_SIZE_T /* elemsize */,
const void* /* hint */);
// deallocates storage at ptr allocated by a call to allocate
// for nelems objects of elemsize bytes each
virtual void
deallocate (void* /* ptr */,
_RWSTD_SIZE_T /* nelems */,
_RWSTD_SIZE_T /* elemsize */);
// returns the maximum number of objects of elemsize each
// that can be allocated from the pool managed by *this
virtual _RWSTD_SIZE_T
max_size (_RWSTD_SIZE_T /* elemsize */ = 1);
// records a call to the allocator member function fun and
// throws an exception derived from std::bad_alloc if the
// number of calls to the member function reaches the limit
// specified by throw_at_calls_
virtual void
funcall (MemFun /* fun */, const SharedAlloc* = 0);
// gets or sets a pointer to the global allocator object
static SharedAlloc*
instance (SharedAlloc* = 0);
// returns a unique id of this allocator object
int id () const { return id_; }
// resets the n_calls_ array to all zeros
void reset_call_counters ();
// returns the name of the member function
static const char* func_name (MemFun);
_RWSTD_SIZE_T max_bytes_; // memory pool size in bytes
_RWSTD_SIZE_T max_blocks_; // memory pool size in blocks
_RWSTD_SIZE_T n_bytes_; // number of allocated bytes
_RWSTD_SIZE_T n_blocks_; // number of allocated blocks
_RWSTD_SIZE_T n_refs_; // number of references
// counter of the number of calls to each allocator member function
// made throughout the lifetime of this object
_RWSTD_SIZE_T n_calls_ [n_funs];
// counter of the number of exceptions thrown by each member function
// throughout the lifetime of this object
_RWSTD_SIZE_T n_throws_ [n_funs];
// member function counter value that, when reached, will cause
// an exception derived from std::bad_alloc to be thrown
_RWSTD_SIZE_T throw_at_calls_ [n_funs];
private:
int id_;
};
// allocator types for easy specialization
template <class T>
struct AllocTypes
{
typedef _RWSTD_SIZE_T size_type;
typedef _RWSTD_PTRDIFF_T difference_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
};
template <class T, class Types = AllocTypes<T> >
struct UserAlloc
{
// private:
SharedAlloc* pal_;
public:
typedef T value_type;
typedef typename Types::size_type size_type;
typedef typename Types::difference_type difference_type;
typedef typename Types::pointer pointer;
typedef typename Types::const_pointer const_pointer;
typedef typename Types::reference reference;
typedef typename Types::const_reference const_reference;
UserAlloc (SharedAlloc *pal = 0) _THROWS (())
: pal_ (pal ? pal : SharedAlloc::instance ()) {
RW_ASSERT (0 != pal_);
pal_->funcall (pal_->m_ctor);
}
UserAlloc (const UserAlloc &rhs) _THROWS (())
: pal_ (rhs.pal_) {
RW_ASSERT (0 != pal_);
pal_->funcall (pal_->m_cpy_ctor);
}
template <class U>
UserAlloc (const UserAlloc<U> &rhs) _THROWS (())
: pal_ (rhs.pal_) {
RW_ASSERT (0 != pal_);
pal_->funcall (pal_->m_cvt_ctor);
}
template <class U>
void operator= (const UserAlloc<U> &rhs) {
pal_->funcall (pal_->m_cvt_assign, rhs.pal_);
pal_ = rhs.pal_;
}
template <class U>
struct rebind { typedef UserAlloc<U> other; };
void operator= (const UserAlloc &rhs) {
pal_->funcall (pal_->m_cpy_assign, rhs.pal_);
pal_ = rhs.pal_;
}
~UserAlloc () {
pal_->funcall (pal_->m_dtor);
}
pointer allocate (size_type nelems, const void *hint = 0) {
void* const ptr = pal_->allocate (nelems, sizeof (value_type), hint);
return _RWSTD_STATIC_CAST (pointer, ptr);
}
void deallocate (pointer ptr, size_type nelems) {
pal_->deallocate (ptr, nelems, sizeof (value_type));
}
void construct (pointer ptr, const_reference val) {
pal_->funcall (pal_->m_construct);
new (ptr) value_type (val);
}
void destroy (pointer ptr) {
pal_->funcall (pal_->m_destroy);
ptr->~T ();
}
pointer address (reference ref) const {
pal_->funcall (pal_->m_address);
return &ref;
}
const_pointer address (const_reference ref) const {
pal_->funcall (pal_->m_address);
return &ref;
}
size_type max_size () const _THROWS (()) {
return pal_->max_size (sizeof (value_type));
}
bool operator== (const UserAlloc &rhs) const {
return pal_->id () == rhs.pal_->id ();
}
bool operator!= (const UserAlloc &rhs) const {
return !operator== (rhs);
}
};
// when (line <= 0) establishes a new check point for memory leaks
// by storing the number and size of blocks of storage currently
// allocated by operator new and by the SharedAlloc object pointed
// to by palloc (when non-zero)
// when (line > 0) reports the difference between the the number
// and size of blocks of storage allocated at the last checkpoint
// and the values specified by expect_blocks and expect_bytes
_TEST_EXPORT void
rw_check_leaks (const SharedAlloc* /* palloc */ = 0,
int /* line */ = 0,
_RWSTD_SIZE_T /* expect_blocks */ = 0,
_RWSTD_SIZE_T /* expect_bytes */ = _RWSTD_SIZE_MAX);
// when (line <= 0) establishes a new check point for memory leaks
// by storing the number and size of blocks of storage currently
// allocated by operator new
// when (line > 0) reports the difference between the the number
// and size of blocks of storage allocated at the last checkpoint
// and the values specified by expect_blocks and expect_bytes
template <class charT>
inline void
rw_check_leaks (const std::allocator<charT>& /* unused */,
int line = 0,
_RWSTD_SIZE_T expect_blocks = 0,
_RWSTD_SIZE_T expect_bytes = _RWSTD_SIZE_MAX)
{
// can't track memory leaks here
rw_check_leaks ((SharedAlloc*)0, line, expect_blocks, expect_bytes);
}
// when (line <= 0) establishes a new check point for memory leaks
// by storing the number and size of blocks of storage currently
// allocated by operator new and by the user-defined allocator
// specified by the first argument
// when (line > 0) reports the difference between the the number
// and size of blocks of storage allocated at the last checkpoint
// and the values specified by expect_blocks and expect_bytes
template <class charT, class Types>
inline void
rw_check_leaks (const UserAlloc<charT, Types> &alloc,
int line = 0,
_RWSTD_SIZE_T expect_blocks = 0,
_RWSTD_SIZE_T expect_bytes = _RWSTD_SIZE_MAX)
{
// track memory leaks via SharedAlloc
rw_check_leaks (alloc.pal_, line, expect_blocks, expect_bytes);
}
#endif // RW_ALLOCATOR_INCLUDED

View File

@@ -0,0 +1,94 @@
/************************************************************************
*
* rw_braceexp.h - declarations of testsuite helpers
*
* $Id: rw_braceexp.h 648752 2008-04-16 17:01:56Z faridz $
*
************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#ifndef RW_BRACEEXP_H_INCLUDED
#define RW_BRACEEXP_H_INCLUDED
#include <testdefs.h>
// rw_brace_expand() performs brace expansion similar to the csh shell.
// the base grammar for the brace expansion is supposed to be..
//
// string ::= <brace-expr> | [ <chars> ]
// brace-expr ::= <string> '{' <brace-list> | <brace-sequ> '}' <string> |
// <string>
// brace-list ::= <string> ',' <brace-list> | <string>
// brace-sequ ::= <upper> '.' '.' <upper> |
// <lower> '.' '.' <lower> |
// <integer> '.' '.' <integer>
// chars ::= <pcs-char> <string> | <pcs-char>
// integer ::= ['+' | '-'] <digits>
// upper ::= pcs-char 'a-z'
// lower ::= pcs-char 'A-Z'
// digit ::= pcs-char '0-9'
// digits ::= <digit> <digits> | <digit>
// pcs-char ::= character in the Portable Character Set
//
// many examples can be found in the test 0.braceexp.cpp.
//
//
// this function will attempt to expand `sz' bytes of the brace expression
// `brace_expr' into `n' bytes of the output buffer `s', seperating each
// expansion with a single seperator character `sep'. if the output buffer
// `s' is is null, or the number of bytes `n' is insufficient to contain
// all expansions of `brace_expr', an appropriately sized buffer will be
// allocated with malloc(). a pointer to the output buffer that is used
// will be returned. if the pointer returned is not equal to the user
// supplied input buffer `s', then the caller is expected to free() the
// returned pointer.
//
// this function can return null if the brace expansion could not be
// processed. this can happen if, for example, the brace expression string
// contains an unmatched unescaped open brace. the function can also fail
// and return null if a memory allocation request fails.
//
_TEST_EXPORT char*
rw_brace_expand (const char* brace_expr, _RWSTD_SIZE_T sz,
char* s, _RWSTD_SIZE_T n, char sep);
//
// this function is similar to rw_brace_expand, except that the input
// string `shell_expr' is tokenized on whitespace, and each non-whitespace
// token is expanded seperately. this function will fail if an attempt to
// brace expand one of the tokens fails, regardless of the reason for that
// failure.
//
// the caller may need to free() the returned pointer. please see comments
// above for details.
//
// this function only does tokenization and brace expansion at this time.
// at some point it may make sense to add environment variable expansion.
//
_TEST_EXPORT char*
rw_shell_expand (const char* shell_expr, _RWSTD_SIZE_T sz,
char* s, _RWSTD_SIZE_T n, char sep);
#endif // RW_BRACEEXP_H_INCLUDED

View File

@@ -0,0 +1,512 @@
/**************************************************************************
*
* rw_char.h - defines a User Defined Character type and its traits
*
* $Id: rw_char.h 448928 2006-09-22 13:43:18Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 2004-2006 Rogue Wave Software.
*
**************************************************************************/
#ifndef RW_CHAR_INCLUDED
#define RW_CHAR_INCLUDED
// avoid dependencies on any library headers
// to prevent the pollution of the namespace(s)
#include <rw/_traits.h>
#include <testdefs.h>
struct UserChar // user-defined character type (must be POD)
{
#if !defined (_RWSTD_NO_LONG_DOUBLE) \
&& !defined (__SUNPRO_CC) || __SUNPRO_CC > 0x540
long double f; // exercise correct alignment
#else
// cannot use long double with SunPro due to a compiler
// bug that prevents assignments of UserChar() (PR #28328)
double f;
#endif // _RWSTD_NO_LONG_DOUBLE
unsigned char c; // underlying character representation
static UserChar eos () {
// use UserChar::eos() instead of UserChar() to work around broken
// compilers (e.g., MSVC 6) that do not zero out POD structs
// on default construction
const UserChar tmp = { 0, 0 };
return tmp;
}
// definition of a POD-struct (9, p4):
// A POD-struct is an aggregate class that has no non-static data
// members of type pointer to member, non-POD-struct, non-POD-union
// (or array of such types) or reference, and has no user-defined
// copy assign-ment operator and no user-defined destructor.
// definition of an aggregate (8.5.1, p1):
// An aggregate is an array or a class (clause 9) with no user-declared
// constructors (12.1), no private or protected non-static data members
// (clause 11), no base classes (clause 10), and no virtual functions
// (10.3).
};
inline UserChar make_char (char c, UserChar*)
{
const UserChar ch = { 0.0, c };
return ch;
}
inline char make_char (char c, char*)
{
return c;
}
#ifndef _RWSTD_NO_WCHAR_T
inline wchar_t make_char (char c, wchar_t*)
{
typedef unsigned char UChar;
return wchar_t (UChar (c));
}
#endif // _RWSTD_NO_WCHAR_T
///////////////////////////////////////////////////////////////////////////
// 21.1.2, p2 of C++ 03:
//
// typedef INT_T int_type;
//
// -2- Requires: For a certain character container type char_type, a related
// container type INT_T shall be a type or class which can represent all
// of the valid characters converted from the corresponding char_type
// values, as well as an end-of-file value, eof(). The type int_type
// represents a character container type which can hold end-of-file to
// be used as a return type of the iostream class member functions.224)
// ____________
// Footnote 224: If eof() can be held in char_type then some iostreams
// operations may give surprising results.
class UserInt
{
void* ptr_; // to check validity
int i_; // underlying int representation
// valid values are 0 through 256 with 256 representing EOF
public:
// default ctor creates a valid object but assigns it an invalid
// value so that the only legal operations on it are assignment
// and copy
UserInt (): ptr_ (&i_ /* valid */), i_ (-1 /* invalid */) { /* empty */ }
UserInt (const UserInt &rhs)
: ptr_ (&i_), i_ (rhs.i_) {
// verify rhs is valid
// const_cast used to avoid MSVC 7.0 error C2446:
// '==' : no conversion from 'const int *' to 'void *const '
RW_ASSERT (_RWSTD_CONST_CAST (const void*, rhs.ptr_) == &rhs.i_);
RW_ASSERT (-1 <= rhs.i_ && rhs.i_ < 257); // i may be invalid
}
// (almost) assignable; i.e., returns void instead of UserInt&
// for extra robustness
void operator= (const UserInt &rhs) {
RW_ASSERT (ptr_ == &i_); // verify *this is valid
// verify rhs is valid
RW_ASSERT (_RWSTD_CONST_CAST (const void*, rhs.ptr_) == &rhs.i_);
RW_ASSERT (-1 <= i_ && i_ < 257); // i may be invalid
RW_ASSERT (-1 < rhs.i_ && rhs.i_ < 257); // rhs.i must ve valid
i_ = rhs.i_;
}
static UserInt eof () {
UserInt tmp;
tmp.i_ = 256; // EOF
return tmp;
}
static UserInt from_char (const UserChar &c) {
UserInt tmp;
tmp.i_ = int (c.c);
return tmp;
}
UserChar to_char () const {
// working around an Intel C++ 9.1 bug #380635
/* const */ UserChar tmp /* = { 0, i_ }*/;
tmp.f = 0;
tmp.c = (unsigned char)(i_);
return tmp;
}
~UserInt () {
RW_ASSERT (ptr_ == &i_); // verify *this is valid
RW_ASSERT (-1 <= i_ == i_ < 257); // i may be invalid
i_ = _RWSTD_INT_MIN; // invalidate
ptr_ = &ptr_; // invalidate
}
bool equal (const UserInt &rhs) const {
// verify *this is valid
RW_ASSERT (_RWSTD_CONST_CAST (const void*, ptr_) == &i_);
// verify rhs is valid
RW_ASSERT (_RWSTD_CONST_CAST (const void*, rhs.ptr_) == &rhs.i_);
RW_ASSERT (-1 < i_ && i_ < 257); // i must ve valid
RW_ASSERT (-1 < rhs.i_ && rhs.i_ < 257); // rhs.i must be valid
return i_ == rhs.i_;
}
};
// user-defined character traits template
// (declared but not defined)
template <class charT>
struct UserTraits;
struct TraitsMemFunc
{
enum {
assign, eq, lt, compare, length, find, copy, move,
assign2, not_eof, to_char_type, to_int_type, eq_int_type,
eof,
n_funs
};
};
// required specialization on char
_RWSTD_SPECIALIZED_CLASS
struct _TEST_EXPORT UserTraits<char>: std::char_traits<char>
{
typedef std::char_traits<char> Base;
typedef Base::char_type char_type;
typedef Base::int_type int_type;
typedef TraitsMemFunc MemFun;
// avoid any dependency on the library
typedef int off_type; // std::streamoff
typedef int state_type; // std::mbstate_t
typedef std::fpos<state_type> pos_type; // std::fpos<state_type>
static void
assign (char_type&, const char_type&);
static bool
eq (const char_type&, const char_type&);
static bool
lt (const char_type&, const char_type&);
static int
compare (const char_type*, const char_type*, _RWSTD_SIZE_T);
static _RWSTD_SIZE_T
length (const char_type*);
static const char_type*
find (const char_type*, _RWSTD_SIZE_T, const char_type&);
static char_type*
copy (char_type*, const char_type*, _RWSTD_SIZE_T);
static char_type*
move (char_type*, const char_type*, _RWSTD_SIZE_T);
static char_type*
assign (char_type*, _RWSTD_SIZE_T, char_type);
static int_type
not_eof (const int_type&);
static char_type
to_char_type (const int_type&);
static int_type
to_int_type (const char_type&);
static bool
eq_int_type (const int_type&, const int_type&);
static int_type
eof ();
static _RWSTD_SIZE_T n_calls_ [];
static int_type eof_;
private:
// not defined to detect bad assumptions made by the library
UserTraits ();
~UserTraits ();
void operator= (UserTraits&);
};
#ifndef _RWSTD_NO_WCHAR_T
// required specialization on wchar_t
_RWSTD_SPECIALIZED_CLASS
struct _TEST_EXPORT UserTraits<wchar_t>: std::char_traits<wchar_t>
{
typedef std::char_traits<wchar_t> Base;
typedef Base::char_type char_type;
typedef Base::int_type int_type;
typedef TraitsMemFunc MemFun;
// avoid any dependency on the library
typedef int off_type; // std::streamoff
typedef int state_type; // std::mbstate_t
typedef std::fpos<state_type> pos_type; // std::fpos<state_type>
static void
assign (char_type&, const char_type&);
static bool
eq (const char_type&, const char_type&);
static bool
lt (const char_type&, const char_type&);
static int
compare (const char_type*, const char_type*, _RWSTD_SIZE_T);
static _RWSTD_SIZE_T
length (const char_type*);
static const char_type*
find (const char_type*, _RWSTD_SIZE_T, const char_type&);
static char_type*
copy (char_type*, const char_type*, _RWSTD_SIZE_T);
static char_type*
move (char_type*, const char_type*, _RWSTD_SIZE_T);
static char_type*
assign (char_type*, _RWSTD_SIZE_T, char_type);
static int_type
not_eof (const int_type&);
static char_type
to_char_type (const int_type&);
static int_type
to_int_type (const char_type&);
static bool
eq_int_type (const int_type&, const int_type&);
static int_type
eof ();
static _RWSTD_SIZE_T n_calls_ [];
static int_type eof_;
private:
// not defined to detect bad assumptions made by the library
UserTraits ();
~UserTraits ();
void operator= (UserTraits&);
};
#endif // _RWSTD_NO_WCHAR_T
_RWSTD_SPECIALIZED_CLASS
struct _TEST_EXPORT UserTraits<UserChar> // user-defined character traits
{
typedef TraitsMemFunc MemFun;
typedef UserChar char_type;
typedef UserInt int_type;
// avoid any dependency on the library
typedef int off_type; // std::streamoff
typedef int state_type; // std::mbstate_t
typedef std::fpos<state_type> pos_type; // std::fpos<state_type>
// accesses to the char_type::f member may trigger a SIGBUS
// on some architectures (e.g., PA or SPARC) if the member
// isn't appropriately aligned
static void assign (char_type&, const char_type&);
static bool eq (const char_type&, const char_type&);
static bool lt (const char_type&, const char_type&);
static int
compare (const char_type*, const char_type*, _RWSTD_SIZE_T);
static _RWSTD_SIZE_T length (const char_type*);
static const char_type*
find (const char_type*, _RWSTD_SIZE_T, const char_type&);
static char_type*
copy (char_type*, const char_type*, _RWSTD_SIZE_T);
static char_type*
move (char_type*, const char_type*, _RWSTD_SIZE_T);
static char_type*
assign (char_type*, _RWSTD_SIZE_T, char_type);
static int_type not_eof (const int_type&);
static char_type to_char_type (const int_type&);
static int_type to_int_type (const char_type&);
static bool eq_int_type (const int_type&, const int_type&);
static int_type eof ();
static _RWSTD_SIZE_T n_calls_ [];
private:
// not defined to detect bad assumptions made by the library
UserTraits ();
~UserTraits ();
void operator= (UserTraits&);
};
// rw_widen() widens successive elements of src into the buffer dst
// when (dst != 0) the last character in the buffer is guaranteed to be NUL,
// regardless of the value of str [len]
// when (len == SIZE_MAX && src != 0), computes len as if by evaluating
// len = strlen(src)
// when (src == 0 && len < SIZE_MAX), initializes the first len elements
// of dst to NUL (i.e., such a call is the equivalent of calling
// memset(dst, 0, len * sizeof *dst))
// returns dst
_TEST_EXPORT char*
rw_widen (char* /* dst */,
const char* /* src */,
_RWSTD_SIZE_T /* len */ = _RWSTD_SIZE_MAX);
// rw_expand() interprets string src as a sequence of directives and
// widens the result of their processing into the provided buffer dst
// when (dst != 0), otherwise into a dynamically allocated buffer of
// sufficient size
// each directive consists of a character C, optionally followed by
// the '@' sign followed by a non-negative decimal number N; the result
// of the processing of a directive is N consecutive copies of the
// character C where (N = 1) when the '@' is absent
// when (dst_len != 0) the function sets *dst_len to the number of
// produced characters not counting the terminating NUL
// the function returns the dynamically allocated buffer; the caller
// must deallocate the buffer using the delete expression
_TEST_EXPORT char*
rw_expand (char* /* dst */,
const char* /* src */,
_RWSTD_SIZE_T /* src_len */ = _RWSTD_SIZE_MAX,
_RWSTD_SIZE_T* /* dst_len */ = 0);
// rw_narrow() narrows successive elements of src into the buffer dst
// (see rw_widen() for details)
_TEST_EXPORT char*
rw_narrow (char* /* dst */,
const char* /* src */,
_RWSTD_SIZE_T /* len */ = _RWSTD_SIZE_MAX);
// rw_match() compares up to len successive elements of s1 and s2 for
// equality until it finds a pair that do not compare equal or until
// len comparisons has been made
// if (len == SIZE_MAX) is true elements are compared until the first
// mismatch is found or until the NUL character is encountered
// returns the number of matching elements
_TEST_EXPORT _RWSTD_SIZE_T
rw_match (const char* /* s1 */,
const char* /* s2 */,
_RWSTD_SIZE_T /* len */ = _RWSTD_SIZE_MAX);
#ifndef _RWSTD_WCHAR_T
_TEST_EXPORT wchar_t*
rw_widen (wchar_t*, const char*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
_TEST_EXPORT wchar_t*
rw_expand (wchar_t* /* dst */,
const char* /* src */,
_RWSTD_SIZE_T /* src_len */ = _RWSTD_SIZE_MAX,
_RWSTD_SIZE_T* /* dst_len */ = 0);
_TEST_EXPORT char*
rw_narrow (char*, const wchar_t*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
_TEST_EXPORT _RWSTD_SIZE_T
rw_match (const char*, const wchar_t*,
_RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
#endif // _RWSTD_WCHAR_T
_TEST_EXPORT UserChar*
rw_widen (UserChar*, const char*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
_TEST_EXPORT UserChar*
rw_expand (UserChar* /* dst */,
const char* /* src */,
_RWSTD_SIZE_T /* src_len */ = _RWSTD_SIZE_MAX,
_RWSTD_SIZE_T* /* dst_len */ = 0);
_TEST_EXPORT char*
rw_narrow (char*, const UserChar*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
_TEST_EXPORT _RWSTD_SIZE_T
rw_match (const char*, const UserChar*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
// accessors to n_calls array, if present
template <class charT>
inline _RWSTD_SIZE_T*
rw_get_call_counters (std::char_traits<charT>*, charT*)
{
return 0;
}
template <class charT>
inline _RWSTD_SIZE_T*
rw_get_call_counters (UserTraits<charT>*, charT*)
{
return UserTraits<charT>::n_calls_;
}
static const struct _TEST_EXPORT UserCharFmatInit {
UserCharFmatInit ();
} _rw_user_char_fmat_init;
#endif // RW_CHAR_INCLUDED

View File

@@ -0,0 +1,354 @@
/**************************************************************************
*
* rw_ctype.h - defines a User Defined ctype facet
*
* $Id: rw_ctype.h 590052 2007-10-30 12:44:14Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#ifndef RW_CTYPE_H_INCLUDED
#define RW_CTYPE_H_INCLUDED
#include <locale> // for ctype, locale
#include <rw_char.h> // for UserChar
#include <testdefs.h>
struct _TEST_EXPORT UserCtypeBase: std::ctype_base
{
enum MemFunc {
mf_is,
mf_is_range,
mf_scan_is,
mf_scan_not,
mf_toupper,
mf_toupper_range,
mf_tolower,
mf_tolower_range,
mf_widen,
mf_widen_range,
mf_narrow,
mf_narrow_range,
n_funs
};
struct Exception {
virtual ~Exception ();
virtual const char* what () const = 0;
};
// name of the character type ("char", "wchar_t", "UserChar")
const char* const cname_;
// array of masks corresponding to each of the characters in chars
// the first negative element in chars denotes the last element
const int* masks_;
const int* chars_;
// arrays of correspondning uppercase and lowercase characters
const int* upper_;
const int* lower_;
// arrays of corresponding narrow and wide characters
const int* narrow_;
const int* wide_;
// counter of the number of calls to all member functions
// made throughout the lifetime of this object
_RWSTD_SIZE_T n_all_calls_;
// counter of the number of calls to each member function
// made throughout the lifetime of this object
_RWSTD_SIZE_T n_calls_ [n_funs];
// counter of the number of exceptions thrown by each member
// function throughout the lifetime of this object
_RWSTD_SIZE_T n_throws_ [n_funs];
// member function counter value that, when reached, will
// cause an exception to be thrown
_RWSTD_SIZE_T throw_at_calls_ [n_funs];
// value of a character that, when encountered, will cause
// an exception to be thrown
int throw_char_;
// when true the facet throws an exception when it encounters
// an invalid character (unless otherwise specified)
bool throw_on_invalid_;
protected:
UserCtypeBase (const char*);
private:
UserCtypeBase (const UserCtypeBase&); // not CopyConstructible
void operator= (const UserCtypeBase&); // not Assignable
};
template <class _CharT>
class UserCtype;
_RWSTD_SPECIALIZED_CLASS
class _TEST_EXPORT UserCtype<char>
: public std::ctype<char>, public UserCtypeBase
{
typedef std::ctype<char_type> Base;
public:
explicit
UserCtype (_RWSTD_SIZE_T = 0);
explicit
UserCtype (const int*, const int*, _RWSTD_SIZE_T = 0);
protected:
virtual char_type
do_toupper (char_type) const;
virtual const char_type*
do_toupper (char_type*, const char_type*) const;
virtual char_type
do_tolower (char_type) const;
virtual const char_type*
do_tolower (char_type*, const char_type*) const;
virtual char_type
do_widen (char) const;
virtual const char*
do_widen (const char*, const char*, char_type*) const;
virtual char
do_narrow (char_type, char) const;
virtual const char_type*
do_narrow (const char_type*, const char_type*, char, char*) const;
};
#ifndef _RWSTD_NO_WCHAR_T
_RWSTD_SPECIALIZED_CLASS
class _TEST_EXPORT UserCtype<wchar_t>
: public std::ctype<wchar_t>, public UserCtypeBase
{
typedef std::ctype<char_type> Base;
public:
explicit
UserCtype (_RWSTD_SIZE_T = 0);
explicit
UserCtype (const int*, const int*, _RWSTD_SIZE_T = 0);
protected:
virtual bool
do_is (mask, char_type) const;
virtual const char_type*
do_is (const char_type*, const char_type*, mask*) const;
virtual const char_type*
do_scan_is (mask, const char_type*, const char_type*) const;
virtual const char_type*
do_scan_not (mask, const char_type*, const char_type*) const;
virtual char_type
do_toupper (char_type) const;
virtual const char_type*
do_toupper (char_type*, const char_type*) const;
virtual char_type
do_tolower (char_type) const;
virtual const char_type*
do_tolower (char_type*, const char_type*) const;
virtual char_type
do_widen (char) const;
virtual const char*
do_widen (const char*, const char*, char_type*) const;
virtual char
do_narrow (char_type, char) const;
virtual const char_type*
do_narrow (const char_type*, const char_type*, char, char*) const;
};
#endif // _RWSTD_NO_WCHAR_T
_RWSTD_NAMESPACE (std) {
_RWSTD_SPECIALIZED_CLASS
class _TEST_EXPORT ctype<UserChar>
: public std::locale::facet, public UserCtypeBase
{
typedef std::locale::facet Base;
public:
typedef UserChar char_type;
explicit
ctype (_RWSTD_SIZE_T = 0);
explicit
ctype (const int*, const int*, _RWSTD_SIZE_T = 0);
bool
is (mask m, char_type c) const {
return do_is (m, c);
}
const char_type*
is (const char_type* lo, const char_type *hi, mask *vec) const {
return do_is (lo, hi, vec);
}
const char_type*
scan_is (mask m, const char_type *lo, const char_type *hi) const {
return do_scan_is ( m, lo, hi);
}
const char_type*
scan_not (mask m, const char_type *lo, const char_type *hi) const {
return do_scan_not (m, lo, hi);
}
char_type
(toupper)(char_type c) const {
return do_toupper (c);
}
const char_type*
(toupper)(char_type *lo, const char_type *hi) const {
return do_toupper (lo, hi);
}
char_type
(tolower)(char_type c) const {
return do_tolower (c);
}
const char_type*
(tolower)(char_type *lo, const char_type *hi) const {
return do_tolower (lo, hi);
}
char_type
widen (char c) const {
return do_widen (c);
}
const char*
widen (const char *lo, const char *hi, char_type *to) const {
return do_widen (lo, hi, to);
}
char
narrow (char_type c, char dfault) const {
return do_narrow (c, dfault);
}
const char_type*
narrow (const char_type *lo, const char_type *hi,
char dfault, char *to) const {
return do_narrow (lo, hi, dfault, to);
}
static std::locale::id id;
protected:
virtual bool
do_is (mask, char_type) const;
virtual const char_type*
do_is (const char_type*, const char_type*, mask*) const;
virtual const char_type*
do_scan_is (mask, const char_type*, const char_type*) const;
virtual const char_type*
do_scan_not (mask, const char_type*, const char_type*) const;
virtual char_type
do_toupper (char_type) const;
virtual const char_type*
do_toupper (char_type*, const char_type*) const;
virtual char_type
do_tolower (char_type c) const;
virtual const char_type*
do_tolower (char_type*, const char_type*) const;
virtual char_type
do_widen (char) const;
virtual const char*
do_widen (const char*, const char*, char_type*) const;
virtual char
do_narrow (char_type, char dfault) const;
virtual const char_type*
do_narrow (const char_type*, const char_type*, char, char*) const;
};
} // namespace std
_RWSTD_SPECIALIZED_CLASS
class _TEST_EXPORT UserCtype<UserChar>
: public std::ctype<UserChar>
{
typedef std::ctype<UserChar> Base;
public:
typedef UserChar char_type;
explicit
UserCtype (_RWSTD_SIZE_T = 0);
explicit
UserCtype (const int*, const int*, _RWSTD_SIZE_T = 0);
};
#endif // RW_CTYPE_H_INCLUDED

View File

@@ -0,0 +1,62 @@
/************************************************************************
*
* rw_exception.h - defines a test driver exception
*
* $Id: rw_exception.h 590052 2007-10-30 12:44:14Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 2004-2006 Rogue Wave Software.
*
**************************************************************************/
#ifndef RW_EXCEPTION_H_INCLUDED
#define RW_EXCEPTION_H_INCLUDED
#include <testdefs.h>
enum ExceptionId
{
ex_unknown = 0,
// custom exceptions, i.e. not derived for std::exception
ex_stream = 1,
ex_custom = 7,
// exceptions derived from std::exception
ex_bad_alloc = 8,
ex_std = (7 << 3)
};
struct _TEST_EXPORT Exception
{
const ExceptionId id_;
Exception (ExceptionId id) : id_ (id) {}
virtual ~Exception ();
virtual const char* what () const = 0;
};
_TEST_EXPORT void
rw_throw (ExceptionId exid, const char *file, int line,
const char *function, const char *fmt, ...);
#endif // RW_EXCEPTION_H_INCLUDED

View File

@@ -0,0 +1,44 @@
/************************************************************************
*
* rw_fnmatch.h - declarations of testsuite helpers
*
* $Id: rw_fnmatch.h 648752 2008-04-16 17:01:56Z faridz $
*
************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#ifndef RW_FNMATCH_H_INCLUDED
#define RW_FNMATCH_H_INCLUDED
#include <testdefs.h>
// rw_fnmatch() matches patterns as described in the Shell and Utilities
// volume of IEEE Std 1003.1-2001, Section 2.13.1, Patterns Matching
// a Single Character, and Section 2.13.2, Patterns Matching Multiple
// Characters. It checks the string specified by the string argument
// to see if it matches the pattern specified by the pattern argument.
_TEST_EXPORT int
rw_fnmatch (const char*, const char*, int);
#endif // RW_FNMATCH_H_INCLUDED

View File

@@ -0,0 +1,142 @@
/************************************************************************
*
* rw_locale.h - declarations of locale testsuite helpers
*
* $Id: rw_locale.h 648752 2008-04-16 17:01:56Z faridz $
*
************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 2001-2007 Rogue Wave Software, Inc.
*
**************************************************************************/
#ifndef RW_LOCALE_H_INCLUDED
#define RW_LOCALE_H_INCLUDED
#include <testdefs.h>
#define _UNUSED_CAT 69
// get a list of all native locales that match the cannonical
// locale name query strings
_TEST_EXPORT char*
rw_locale_query (int = _UNUSED_CAT, const char* = 0, _RWSTD_SIZE_T = 0);
// this function will likely be deprecated!
_TEST_EXPORT char*
rw_locales (int = _UNUSED_CAT, const char* = 0, bool = true);
// invokes the locale utility with the arguments specified by 'arg',
// redirecting its output to the file named by 'fname' if non-null
// returns the exit status of the utility
_TEST_EXPORT int
rw_locale (const char* /* args */, const char* /* fname */);
#define LOCALE_ROOT_ENVAR "RWSTD_LOCALE_ROOT"
// creates a temporary directory and defines the RWSTD_LOCALE_ROOT
// environment variable to the name of the directory; the directory
// will be automatically removed on program exit as if by calling
// atexit()
// if the environment variable RW_PUTENV is defined, defines any
// additional environment variable(s) specified by it (by calling
// rw_putenv(0))
// returns the absolute pathname of the directory
_TEST_EXPORT const char*
rw_set_locale_root ();
// invokes localedef to create a locale database named by the last argument,
// if non-0, or in a directory specified by the RWSTD_LOCALE_ROOT environment
// variable otherwise, if it is defined, otherwise in the current working
// directory
// returns the name of the locale; successive calls to the function may
// change the contents of the character array pointed to by the pointer
// returned from prior calls
_TEST_EXPORT const char*
rw_localedef (const char*, const char*, const char*, const char*);
// stores up to 'size' wide characters valid in the current locale
// in consecutive elements of the 'wbuf' buffer; if 'nbytes' is
// non-zero only wide characters with multibyte sequences of the
// specified length will be stored (as determined by mblen())
// returns the number of elements stored
_TEST_EXPORT _RWSTD_SIZE_T
rw_get_wchars (wchar_t* /* wbuf */,
_RWSTD_SIZE_T /* size */,
int /* nbytes */ = 0);
// an array of multibyte characters 1 to MB_LEN_MAX bytes in length
typedef char
rw_mbchar_array_t [_RWSTD_MB_LEN_MAX][_RWSTD_MB_LEN_MAX];
// fills consecutive elements of the `mb_chars' array with multibyte
// characters between 1 and MB_CUR_MAX bytes long for the currently
// set locale
// returns the number of elements populated (normally, MB_CUR_MAX)
_TEST_EXPORT _RWSTD_SIZE_T
rw_get_mb_chars (rw_mbchar_array_t /* mb_chars */);
// finds the multibyte locale with the largest MB_CUR_MAX value and
// fills consecutive elements of the `mb_chars' array with multibyte
// characters between 1 and MB_CUR_MAX bytes long for such a locale
_TEST_EXPORT const char*
rw_find_mb_locale (_RWSTD_SIZE_T* /* mb_cur_max */,
rw_mbchar_array_t /* mb_chars */);
// invokes localedef with charmap and locale def to create a locale database
// in a directory specified by the RWSTD_LOCALE_ROOT environment
// variable, if it is defined, otherwise in the current working
// directory
// returns the name of the locale
_TEST_EXPORT const char*
rw_create_locale (const char* /* charmap */, const char* /* locale */);
// NUL-separated list of locale names specified by the --locales
// command line option (set by the rw_opt_setlocales handler)
_TEST_EXPORT extern const char* const&
rw_opt_locales;
// callback function invoked in response to the --locales=<locale-list>
// command line option to set the rw_opt_locales global variable to the
// NUL-separated list of locale names to exercise
_TEST_EXPORT int
rw_opt_setlocales (int, char*[]);
// creates message file and invokes gencat to create message catalog
// then removes the message file
// catalog is a '\0' separated list of strings, each of which representing
// a single message, and with a blank line separating one set from another
// returns 0 in success
_TEST_EXPORT int
rw_create_catalog (const char * /* catname */, const char * /* catalog */);
#endif // RW_LOCALE_H_INCLUDED

View File

@@ -0,0 +1,202 @@
/************************************************************************
*
* rw_new.h - definitions of replacement operator new and delete
*
* $Id: rw_new.h 590052 2007-10-30 12:44:14Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 2004-2006 Rogue Wave Software.
*
**************************************************************************/
#ifndef RW_NEW_H_INCLUDED
#define RW_NEW_H_INCLUDED
// this file must be #included in at most one translation unit in a program
// (replacement operators new and delete must be defined in at most one
// translation unit in order not to violate the ODR)
#include <new> // for bad_alloc
#include <testdefs.h> // for test config macros
struct rwt_free_store
{
// cumulative number of all calls to the ordinary operator new
// and the array form of the operator, respectively, regardless
// of whether they exited successfully or by throwing an exception
_RWSTD_SIZE_T new_calls_ [2];
// cumulative number of calls to the ordinary operator delete
// and the array form of the operator, respectively, regardless
// of whether they exited successfully or by throwing an exception
_RWSTD_SIZE_T delete_calls_ [2];
// cumulative number of calls to the ordinary operator delete
// and the array form of the operator, respectively, with the
// argument of 0
_RWSTD_SIZE_T delete_0_calls_ [2];
// number of blocks currently allocated by the ordinary operator new,
// and the array form of the operator, respectively
_RWSTD_SIZE_T blocks_ [2];
// number of bytes currently allocated by the ordinary operator new,
// and the array form of the operator, respectively
_RWSTD_SIZE_T bytes_ [2];
// the maximum number of blocks allocated so far by the ordinary
// operator new, and the array form of the operator, respectively
_RWSTD_SIZE_T max_blocks_ [2];
// the maximum total amount of storage allocated so far by the ordinary
// operator new, and the array form of the operator, respectively
_RWSTD_SIZE_T max_bytes_ [2];
// the size of the largest block allocated so far by the ordinary
// operator new, and the array form of the operator, respectively
_RWSTD_SIZE_T max_block_size_ [2];
// pointer to a value which, when equal to new_calls_ [i],
// the ordinary operator new (for i == 0) or the array form
// of the operator (for i == 1), respectively, will throw
// a std::bad_alloc exception
_RWSTD_SIZE_T* throw_at_calls_ [2];
// pointer to a value which, when less than or equal to blocks_ [i]
// during the next call to the ordinary operator new (for i == 0) or
// the array form of the operator (for i == 1), respectively, will
// throw a std::bad_alloc exception
_RWSTD_SIZE_T* throw_at_blocks_ [2];
// pointer to a value which, when less than or equal to bytes_ [i]
// during the next call to the ordinary operator new (for i == 0) or
// the array form of the operator (for i == 1), respectively, will
// throw a std::bad_alloc exception
_RWSTD_SIZE_T* throw_at_bytes_ [2];
// pointer to a value which, when equal to the next block's sequence
// number operator new will break or abort
_RWSTD_SIZE_T* break_at_seqno_;
};
// returns a pointer to the global rwt_free_store object
// with a non-zero argument sets the global pointer to the rwt_free_store
// object to the value of the argument
_TEST_EXPORT rwt_free_store*
rwt_get_free_store (rwt_free_store*);
// computes the difference between two states of the free store
// returns 0 when no difference exists, otherwise a pointer to
// a rwt_free_store structure describing the differences
// when both arguments are 0, returns the difference between
// the last checkpoint and the current states of the free store,
// and establishes a new checkpoint
// when the first argument is 0, returns the difference between
// the last checkpoint and the current states of the free store
// when the second argument is 0, returns the difference between
// the state specified by the first argument and the current state
// of the free store
_TEST_EXPORT rwt_free_store*
rwt_checkpoint (const rwt_free_store*, const rwt_free_store*);
// returns the number of blocks allocated and not freed since
// the checkpoint specified by the second argument
// when the second argument is 0, returns the number of blocks
// allocated and not freed since the last established checkpoint
// and establishes a new checkpoint
_TEST_EXPORT _RWSTD_SIZE_T
rwt_check_leaks (_RWSTD_SIZE_T*, const rwt_free_store*);
// define replacement operator new and delete to keep track
// of allocated memory and allow for exceptions to be thrown
_TEST_EXPORT void* operator_new (_RWSTD_SIZE_T, bool);
_TEST_EXPORT void operator_delete (void*, bool);
# ifndef _RWSTD_BAD_ALLOC
// #define if not #defined by <new> (SunPro #includes its
// own <new> regardless of the preprocessor search path)
# define _RWSTD_BAD_ALLOC _STD::bad_alloc
# endif // _RWSTD_BAD_ALLOC
struct _TEST_EXPORT MyNewInit
{
MyNewInit ();
~MyNewInit ();
private:
// not defined
MyNewInit (const MyNewInit&);
void operator= (const MyNewInit&);
};
// keeps track of dynamic intiatlization
static MyNewInit mynew_init_tracker;
# ifndef _RWSTD_TEST_SRC
# ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
// prevent defining the replacement operator
// when compiling in the test suite framework
void* operator new (_RWSTD_SIZE_T n) _THROWS ((_RWSTD_BAD_ALLOC))
{
return operator_new (n, false);
}
void operator delete (void *ptr) _THROWS (())
{
operator_delete (ptr, false);
}
# if !defined (_RWSTD_NO_OPERATOR_NEW_ARRAY) \
|| defined (_RWSTD_NO_EXT_OPERATOR_NEW)
// replaceable only if we don't provide a definition in <new>
void* operator new[] (_RWSTD_SIZE_T n) _THROWS ((_RWSTD_BAD_ALLOC))
{
return operator_new (n, true);
}
# endif // !_RWSTD_NO_OPERATOR_NEW_ARRAY || _RWSTD_NO_EXT_OPERATOR_NEW
# if !defined (_RWSTD_NO_OPERATOR_DELETE_ARRAY) \
|| defined (_RWSTD_NO_EXT_OPERATOR_NEW)
// replaceable only if we don't provide a definition in <new>
void operator delete[] (void *ptr) _THROWS (())
{
operator_delete (ptr, true);
}
# endif // !_NO_OPERATOR_DELETE_ARRAY || _NO_EXT_OPERATOR_NEW
# endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE
# endif // !_RWSTD_TEST_SRC
#endif // RW_NEW_H_INCLUDED

View File

@@ -0,0 +1,163 @@
/************************************************************************
*
* printf.h - declarations of the rw_printf family of functions
*
* $Id: rw_printf.h 550991 2007-06-26 23:58:07Z sebor $
*
************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 1994-2006 Rogue Wave Software.
*
**************************************************************************/
#ifndef RW_PRINTF_H_INCLUDED
#define RW_PRINTF_H_INCLUDED
#include <testdefs.h>
struct rw_file;
// the equivalent of stdout and stderr
extern _TEST_EXPORT rw_file* const rw_stdout;
extern _TEST_EXPORT rw_file* const rw_stderr;
/************************************************************************
* Formatted file output.
************************************************************************/
/**
* Prints to rw_stdout.
*/
_TEST_EXPORT int
rw_printf (const char*, ...);
/**
* Prints to a file.
*/
_TEST_EXPORT int
rw_fprintf (rw_file*, const char*, ...);
/************************************************************************
* Formatted string output.
************************************************************************/
/**
* Prints to a character buffer.
*/
_TEST_EXPORT int
rw_sprintf (char*, const char*, ...);
/**
* Prints to a character buffer of given size.
*/
_TEST_EXPORT int
rw_snprintf (char*, _RWSTD_SIZE_T, const char*, ...);
/************************************************************************
* Formatted string output into a dynamically allocated buffer.
************************************************************************/
/**
* Prints to a dynamically allocated character buffer.
*
* @param fmt Format specifier.
*
* @return On success, returns a pointer to the dynamically allocated
* character buffer. Otherwise, returns 0.
*/
_TEST_EXPORT char*
rw_sprintfa (const char* fmt, ...);
/**
* Prints to a dynamically allocated character buffer.
*
* @param buf A pointer to character buffer where the function should
* store its output.
* @param bufise The size of the character buffer in bytes.
*
* @return On success, if the size of the supplied buffer was sufficient
* to format all characters including the terminating NUL, returns
* buf. Otherwise, if the size of the supplied buffer was not
* sufficient, returns a pointer to the newly allocated character
* buffer of sufficient size. Returns 0 on failure.
*/
_TEST_EXPORT char*
rw_snprintfa (char *buf, _RWSTD_SIZE_T bufsize, const char* fmt, ...);
/**
* Prints to a dynamically allocated character buffer of sufficient size.
* Provided for portability with the BSD and GNU C libraries:
*
* http://www.freebsd.org/cgi/man.cgi?query=asprintf
* http://www.openbsd.org/cgi-bin/man.cgi?query=asprintf
* http://netbsd.gw.com/cgi-bin/man-cgi?asprintf++NetBSD-current
* http://www.gnu.org/software/libc/manual/html_node/Dynamic-Output.html
*
* @param pbuf Pointer to a pointer to character set by the caller to
* to address of the inital character buffer, or 0 of no such
* buffer exists. The function sets the pointer to a the address
* of the dynamically allocated character buffer, or leaves it
* unchanged if it doesn't allocate any buffer.
* @param pbufsize Pointer to a size_t set by the caller to the size of
* the inital character buffer. The function sets the value pointed
* to by this argument to the size of the dynamically allocated
* character buffer, or leaves it unchanged if it doesn't allocate
* any buffer.
* @param fmt Format specifier.
* The format specifier string has the same syntax as C99 sprintf
* (see 7.19.6.1 of ISO/IEC 9899:1999) with the following extensions:
*
* %n$ where n is a integer (see IEEE Std 1003.1)
* %m the value of strerror(errno)
*
* %{?} if clause (extracts an int)
* %{:} else clause
* %{;} end of if/else clause
*
* %{Ac} quoted array of narrow characters
* %{*Ac} quoted array of characters of width '*' each
* where '*' is an int argument extracted from
* the argument list
* %{#s} quoted narrow character string
* %{#ls} quoted wide character string
* %{$envvar} value of an environment variable envvar
* %{f} function pointer
* %{K} signal name (such as "SIGABRT")
* %{M} member pointer
* %{#m} name of the errno constant (such as "EINVAL")
* %{n} buffer size
* %{S} pointer to std::string
* %{lS} pointer to std::wstring
* %{tm} pointer to struct tm
* %{InJ} where n is one of { 8, 16, 32, 64 }
* and J is one of { d, o, x, X }
*
* @return On success, returns the number of characters formatted into
* the buffer, otherwise -1.
*/
_TEST_EXPORT int
rw_asnprintf (char** pbuf, _RWSTD_SIZE_T *pbufsize, const char *fmt, ...);
#endif // RW_PRINTF_H_INCLUDED

View File

@@ -0,0 +1,82 @@
/************************************************************************
*
* rw_process.h - declarations of testsuite process helpers
*
* $Id: rw_process.h 472469 2006-11-08 12:27:17Z faridz $
*
************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#ifndef RW_PROCESS_H_INCLUDED
#define RW_PROCESS_H_INCLUDED
#include <testdefs.h>
typedef _RWSTD_SSIZE_T rw_pid_t;
_TEST_EXPORT int
rw_system (const char*, ...);
// returns pid of the created process or -1 on error
// (in which case errno is set to an appropriate value)
_TEST_EXPORT rw_pid_t
rw_process_create (const char*, ...);
// note: argv[0] should be equal to path
// returns pid of the created process or -1 on error
// (in which case errno is set to an appropriate value)
_TEST_EXPORT rw_pid_t
rw_process_create (const char* /*path*/, char* const /*argv*/[]);
// result is a pointer to a buffer where the result code
// of the specified process will be stored, or NULL
//
// the function suspends execution of the current process
// until a child has exited or specified timeout is reached
//
// returns:
// pid of the specified process if it has exited
// 0 when process still active
// -1 on error (in which case errno is set to an appropriate value)
//
// timeout is timeout interval in seconds.
// if timeout > 0 the function returns if the interval elapses
// if timeout == 0 the function returns immediately
// if timeout < 0 the function's time-out interval never elapses
//
// errors:
// ECHILD: no specified process exists
_TEST_EXPORT rw_pid_t
rw_waitpid (rw_pid_t /*pid*/, int* /*result*/, int /*timeout*/ = -1);
// returns:
// 0 when process terminated successfully
// 1 when signal was sent to the child process, but child process
// not terminated within 1 second interval
// -1 on error (in which case errno is set to an appropriate value)
// errors:
// ESRCH: the pid does not exist
// EPERM: the calling process does not have permission
// to terminate the specified process
_TEST_EXPORT int
rw_process_kill (rw_pid_t, int = -1);
#endif // RW_PROCESS_H_INCLUDED

View File

@@ -0,0 +1,71 @@
/************************************************************************
*
* rw_rand.h - declarations of testsuite random number generators
*
* $Id: rw_rand.h 453816 2006-10-07 00:12:43Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 2005-2006 Rogue Wave Software.
*
**************************************************************************/
#ifndef RW_RAND_H_INCLUDED
#define RW_RAND_H_INCLUDED
#include <rw/_defs.h> // for libstd config macros
#include <testdefs.h> // for test config macros
// seeds the 32-bit random number generator
// if the seed is equal UINT32_MAX picks a random value to seed
// the generator with
_TEST_EXPORT void
rw_seed32 (_RWSTD_UINT32_T);
// returns a 32-bit random number in the range [0, limit)
// if limit is non-zero, otherwise in the range [0, UINT32_MAX)
_TEST_EXPORT _RWSTD_UINT32_T
rw_rand32 (_RWSTD_UINT32_T = 0);
#ifdef _RWSTD_UINT64_T
// seeds the 64-bit random number generator
// if the seed is equal UINT64_MAX picks a random value to seed
// the generator with
_TEST_EXPORT void
rw_seed64 (_RWSTD_UINT64_T);
// returns a 64-bit random number in the range [0, limit)
// if limit is non-zero, otherwise in the range [0, UINT64_MAX)
_TEST_EXPORT _RWSTD_UINT64_T
rw_rand64 (_RWSTD_UINT64_T = 0);
# if 32 == _RWSTD_INT_SIZE
# define rw_seed(limit) rw_seed32 (limit)
# define rw_rand(limit) rw_rand32 (limit)
# else // if 32 != _RWSTD_INT_SIZE
# define rw_seed(limit) rw_seed64 (limit)
# define rw_rand(limit) rw_rand64 (limit)
# endif // 32 == _RWSTD_INT_SIZE
#else // if !defined (_RWSTD_UINT64_T)
# define rw_seed(limit) rw_seed32 (limit)
# define rw_rand(limit) rw_rand32 (limit)
#endif // _RWSTD_UINT64_T
#endif // RW_RAND_H_INCLUDED

View File

@@ -0,0 +1,115 @@
/************************************************************************
*
* rw_sigdefs.h - definitions of helpers macros to define member and
* non-member functions overload id's
*
* $Id: rw_sigdefs.h 509962 2007-02-21 10:38:19Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#ifndef RW_SIGDEFS_H_INCLUDED
#define RW_SIGDEFS_H_INCLUDED
// FCAT() concatenates prefix, underscrore, and suffix
#define _FCAT(a, b) a ## b
#define FCAT(a, b) _FCAT (a ## _, b)
// FID_N() constructs the name for an overload of a container function
#define FID_0(f) FCAT (f, void)
#define FID_1(f, a) FCAT (f, a)
#define FID_2(f, a, b) FID_1 (FCAT (f, a), b)
#define FID_3(f, a, b, c) FID_2 (FCAT (f, a), b, c)
#define FID_4(f, a, b, c, d) FID_3 (FCAT (f, a), b, c, d)
#define FID_5(f, a, b, c, d, e) FID_4 (FCAT (f, a), b, c, d, e)
// ARG() creates a bitmap of an argument type at the given position
#define ARG(a, N) ((arg_ ## a << (N * arg_bits)) << fid_bits)
// SIG_N() creates an argument bitmap for the given function signature
#define SIG_0(f) fid_ ## f
#define SIG_1(f, a) SIG_0 (f) | ARG (a, 0)
#define SIG_2(f, a, b) SIG_1 (f, a) | ARG (b, 1)
#define SIG_3(f, a, b, c) SIG_2 (f, a, b) | ARG (c, 2)
#define SIG_4(f, a, b, c, d) SIG_3 (f, a, b, c) | ARG (d, 3)
#define SIG_5(f, a, b, c, d, e) SIG_4 (f, a, b, c, d) | ARG (e, 4)
#define SIG_6(f, a, b, c, d, e, g) SIG_5 (f, a, b, c, d, e) | ARG (g, 5)
// convenience macro to define member function overload id's
// where the first argument encodes the constness of the member
// function (or the lack thereof)
#define MEMBER_0(f, self) \
FID_0 (f) = SIG_1 (f, self) | bit_member
#define MEMBER_1(f, self, a) \
FID_1 (f, a) = SIG_2 (f, self, a) | bit_member
#define MEMBER_2(f, self, a, b) \
FID_2 (f, a, b) = SIG_3 (f, self, a, b) | bit_member
#define MEMBER_3(f, self, a, b, c) \
FID_3 (f, a, b, c) = SIG_4 (f, self, a, b, c) | bit_member
#define MEMBER_4(f, self, a, b, c, d) \
FID_4 (f, a, b, c, d) = SIG_5 (f, self, a, b, c, d) | bit_member
#define MEMBER_5(f, self, a, b, c, d, e) \
FID_5 (f, a, b, c, d, e) = SIG_6 (f, self, a, b, c, d, e) | bit_member
// convenience macro to define non-member function overload id's
#define NON_MEMBER_0(f) \
FID_0 (f) = SIG_0 (f)
#define NON_MEMBER_1(f, a) \
FID_1 (f, a) = SIG_1 (f, a)
#define NON_MEMBER_2(f, a, b) \
FID_2 (f, a, b) = SIG_2 (f, a, b)
#define NON_MEMBER_3(f, a, b, c) \
FID_3 (f, a, b, c) = SIG_3 (f, a, b, c)
#define NON_MEMBER_4(f, a, b, c, d) \
FID_4 (f, a, b, c, d) = SIG_4 (f, a, b, c, d)
#define NON_MEMBER_5(f, a, b, c, d, e) \
FID_5 (f, a, b, c, d, e) = SIG_5 (f, a, b, c, d, e)
#else // #ifdef RW_SIGDEFS_H_INCLUDED
// clean up helper macros used above
#undef _FCAT
#undef FCAT
#undef FID_0
#undef FID_1
#undef FID_2
#undef FID_3
#undef FID_4
#undef FID_5
#undef ARG
#undef SIG_0
#undef SIG_1
#undef SIG_2
#undef SIG_3
#undef SIG_4
#undef SIG_5
#undef MEMBER_0
#undef MEMBER_1
#undef MEMBER_2
#undef MEMBER_3
#undef MEMBER_4
#undef MEMBER_5
#undef RW_SIGDEFS_H_INCLUDED
#endif // RW_SIGDEFS_H_INCLUDED

View File

@@ -0,0 +1,509 @@
/************************************************************************
*
* rw_streambuf.h - definition of the MyStreambuf class template
*
* $Id: rw_streambuf.h 590052 2007-10-30 12:44:14Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 2004-2006 Rogue Wave Software.
*
**************************************************************************/
#ifndef RW_STREAMBUF_H_INCLUDED
#define RW_STREAMBUF_H_INCLUDED
#include <cstring> // for memset()
#include <streambuf> // for basic_streambuf
#include <testdefs.h>
#include <rw_char.h> // for make_char()
#include <rw_exception.h> // for rw_throw()
enum MemFun {
// bitmask with a bit for each virtual member function
None = 0,
Setbuf = 0x0001,
Seekoff = 0x0002,
Seekpos = 0x0004,
Showmanyc = 0x0008,
Xsgetn = 0x0010,
Underflow = 0x0020,
Uflow = 0x0040,
Overflow = 0x0080,
Pbackfail = 0x0100,
Xsputn = 0x0200,
Sync = 0x0400,
// bit OR-ed with MemFun bits
Throw = 0x1000,
Failure = 0x2000
};
static const char* const streambuf_func_names[] = {
"setbuf", "seekoff", "seekpos", "showmanyc", "xsgetn", "underflow",
"uflow", "overflow", "pbackfail", "xsputn", "sync"
};
template <class charT, class Traits>
struct MyStreambuf: std::basic_streambuf<charT, Traits>
{
typedef charT char_type;
typedef Traits traits_type;
typedef std::basic_streambuf<char_type, traits_type> Base;
typedef typename Base::int_type int_type;
typedef typename Base::off_type off_type;
typedef typename Base::pos_type pos_type;
MyStreambuf (std::streamsize, int, int);
MyStreambuf (const char*, std::streamsize, int, int);
~MyStreambuf () {
delete[] buf_;
}
// public interface to base class protected members
char_type* pubeback () const {
return this->eback ();
}
char_type* pubgptr () const {
return this->gptr ();
}
char_type* pubegptr () const {
return this->egptr ();
}
char_type* pubpbase () const {
return this->pbase ();
}
char_type* pubpptr () const {
return this->pptr ();
}
char_type* pubepptr () const {
return this->epptr ();
}
void pubsetg (charT *beg, charT *cur, charT *end) {
this->setg (beg, cur, end);
}
void pubsetp (charT *beg, charT *cur, charT *end) {
this->setp (beg, end);
this->pbump (cur - beg);
}
private:
// overridden protected virtual functions
virtual Base* setbuf (char_type*, std::streamsize) {
return test (Setbuf) ? this : 0;
}
virtual pos_type
seekoff (off_type, std::ios_base::seekdir, std::ios_base::openmode) {
test (Seekoff);
return pos_type (off_type (-1));
}
virtual pos_type
seekpos (pos_type, std::ios_base::openmode) {
test (Seekpos);
return pos_type (off_type (-1));
}
virtual std::streamsize showmanyc () {
test (Showmanyc);
return 0;
}
virtual std::streamsize xsgetn (char_type*, std::streamsize) {
test (Xsgetn);
return 0;
}
virtual int_type underflow ();
virtual int_type uflow ();
virtual int_type
overflow (int_type = traits_type::eof ());
virtual int_type
pbackfail (int_type = traits_type::eof ());
virtual std::streamsize
xsputn (const char_type *buf, std::streamsize bufsize) {
if (!test (Xsputn))
return 0;
return Base::xsputn (buf, bufsize);
}
virtual int sync () {
test (Sync);
return 0;
}
public:
int ncalls (MemFun) const;
int memfun_inx (MemFun) const;
char_type *buf_;
std::streamsize bufsize_;
int throw_set_; // functions that should throw
int fail_set_; // functions that should fail
MemFun threw_; // which function threw
MemFun failed_; // which function failed
int fail_when_; // call number on which to fail
int throw_when_ [11]; // call number on which to throw for each func
int allthrows_; // total number of thrown exceptions
// max size of the pending input sequence
static std::streamsize in_pending_;
// max size of the pending output sequence
static std::streamsize out_pending_;
private:
bool test (MemFun) const;
int ncalls_ [11]; // number of calls made to each function
int allcalls_; // total number of calls
};
template <class charT, class Traits>
std::streamsize MyStreambuf<charT, Traits>::
in_pending_ = 1;
template <class charT, class Traits>
std::streamsize MyStreambuf<charT, Traits>::
out_pending_ = 1;
template <class charT, class Traits>
MyStreambuf<charT, Traits>::
MyStreambuf (std::streamsize bufsize, int fail_set, int when)
: Base (), buf_ (0), bufsize_ (bufsize),
throw_set_ (0), fail_set_ (0), threw_ (None), failed_ (None),
fail_when_ (when), allthrows_ (0), allcalls_ (0)
{
// reset the member function call counters
std::memset (ncalls_, 0, sizeof ncalls_);
// reset the member function throw counters
std::memset (throw_when_, 0, sizeof throw_when_);
// allocate a (possibly wide) character buffer for output
buf_ = new charT [bufsize_];
// invalidate the contents of the buffer
traits_type::assign (buf_, bufsize_, make_char ('\xfe', buf_));
// set the put area to 0 size to force a call to overflow()
// on the first write attempt to the buffer
this->setp (buf_, buf_);
// set the fail and throw flags
if (fail_set & Throw) {
throw_set_ = fail_set & ~Throw;
for (unsigned i = 0; i < 11; ++i)
if (throw_set_ & (1U << i))
throw_when_ [i] = when;
}
else {
fail_set_ = fail_set;
}
}
template <class charT, class Traits>
MyStreambuf<charT, Traits>::
MyStreambuf (const char *buf, std::streamsize bufsize, int fail_set, int when)
: Base (), buf_ (0), bufsize_ (bufsize),
throw_set_ (0), fail_set_ (0), threw_ (None), failed_ (None),
fail_when_ (when), allthrows_ (0), allcalls_ (0)
{
// reset the member function call counters
std::memset (ncalls_, 0, sizeof ncalls_);
// reset the member function throw counters
std::memset (throw_when_, 0, sizeof throw_when_);
// as a convenience, if `bufsize == -1' compute the size
// from the length of `buf'
if (std::streamsize (-1) == bufsize_)
bufsize_ = std::streamsize (std::char_traits<char>::length (buf)) + 1;
// allocate a (possibly wide) character buffer to copy
// (and widen) the contents of `buf' into
buf_ = new charT [bufsize_ + 1];
for (std::streamsize inx = 0; inx != bufsize_; ++inx) {
typedef unsigned char UChar;
buf_ [inx] = make_char (buf [inx], buf_);
}
// zero out the (non-dereferenceable) element just past the end
// so that the buffer can be printed out as an ordinary string
buf_ [bufsize_] = charT ();
// set the get area to 0 size to force a call to underflow()
// on the first read attempt from the buffer
this->setg (buf_, buf_, buf_);
// set the fail and throw flags
if (fail_set & Throw) {
throw_set_ = fail_set & ~Throw;
for (unsigned i = 0; i < 11; ++i)
if (throw_set_ & (1U << i))
throw_when_ [i] = when;
}
else {
fail_set_ = fail_set;
}
}
template <class charT, class Traits>
typename MyStreambuf<charT, Traits>::int_type
MyStreambuf<charT, Traits>::
underflow ()
{
if (!test (Underflow))
return traits_type::eof ();
if (this->egptr () - this->gptr () > 0) {
this->gbump (1);
return traits_type::to_int_type (*this->gptr ());
}
if (this->egptr () < buf_ + bufsize_) {
// increase the pending input sequence by no more than
// the lesser of the available buffer space and `in_pending_'
std::streamsize pending = buf_ + bufsize_ - this->egptr ();
if (pending > in_pending_)
pending = in_pending_;
this->setg (this->eback (), this->gptr (), this->egptr () + pending);
return traits_type::to_int_type (*this->gptr ());
}
failed_ = Underflow;
return traits_type::eof ();
}
template <class charT, class Traits>
typename MyStreambuf<charT, Traits>::int_type
MyStreambuf<charT, Traits>::
overflow (int_type c /* = traits_type::eof () */)
{
if (!test (Overflow))
return traits_type::eof ();
if (this->epptr () - this->pptr () > 0) {
traits_type::assign (*this->pptr (), traits_type::to_char_type (c));
this->pbump (1);
return traits_type::not_eof (c);
}
if (this->epptr () < buf_ + bufsize_) {
// increase the pending output sequence by no more than
// the lesser of the available buffer space and `out_pending_'
std::streamsize pending = buf_ + bufsize_ - this->epptr ();
if (pending > out_pending_)
pending = out_pending_;
const std::streamsize pptr_off = this->pptr () - this->pbase ();
this->setp (this->pbase (), this->epptr () + pending);
this->pbump (pptr_off);
traits_type::assign (*this->pptr (), traits_type::to_char_type (c));
this->pbump (1);
return traits_type::not_eof (c);
}
failed_ = Overflow;
return traits_type::eof ();
}
template <class charT, class Traits>
typename MyStreambuf<charT, Traits>::int_type
MyStreambuf<charT, Traits>::
pbackfail (int_type c /* = traits_type::eof () */)
{
if (!test (Pbackfail))
return traits_type::eof ();
if (this->gptr () == buf_) {
failed_ = Pbackfail;
return traits_type::eof ();
}
this->setg (this->gptr () - 1, this->gptr () - 1, this->gptr ());
const int_type last = traits_type::to_int_type (*this->gptr ());
if (!traits_type::eq_int_type (c, traits_type::eof ()))
traits_type::assign (*this->gptr (), traits_type::to_char_type (c));
return last;
}
template <class charT, class Traits>
typename MyStreambuf<charT, Traits>::int_type
MyStreambuf<charT, Traits>::
uflow ()
{
if (!test (Uflow))
return traits_type::eof ();
if (this->egptr () - this->gptr () > 0) {
this->gbump (1);
return traits_type::to_int_type (*this->gptr ());
}
if (this->egptr () < buf_ + bufsize_) {
// increase the pending input sequence by no more than
// the lesser of the available buffer space and `in_pending_'
std::streamsize pending = buf_ + bufsize_ - this->egptr ();
if (pending > in_pending_)
pending = in_pending_;
this->setg (this->eback (), this->gptr (), this->egptr () + pending);
return traits_type::to_int_type (*this->gptr ());
}
failed_ = Uflow;
return traits_type::eof ();
}
template <class charT, class Traits>
int
MyStreambuf<charT, Traits>::
memfun_inx (MemFun which) const
{
int inx = -1;
for (unsigned i = 0; i < sizeof (which) * _RWSTD_CHAR_BIT; ++i) {
if (which & (1U << i)) {
if (inx < 0)
inx = i;
else
return -1;
}
}
return inx;
}
template <class charT, class Traits>
int
MyStreambuf<charT, Traits>::
ncalls (MemFun which) const
{
int inx = memfun_inx (which);
if (0 <= inx)
return ncalls_ [inx];
return -1;
}
template <class charT, class Traits>
bool
MyStreambuf<charT, Traits>::
test (MemFun which) const
{
MyStreambuf* const self = _RWSTD_CONST_CAST (MyStreambuf*, this);
int inx = memfun_inx (which);
if (-1 == inx)
return true;
// increment the counter tracking the number of calls made
// to each member function; do so regardless of whether
// an exception will be thrown below
self->ncalls_ [inx] ++;
self->allcalls_ ++;
const int callno = self->ncalls_ [inx];
#ifndef _RWSTD_NO_EXCEPTIONS
// if the call counter is equal to the `fail_when_' watermark
// and `shich' is set in the `throw_set_' bitmask, throw an
// exception with the value of the member id
if (callno == throw_when_ [inx] && throw_set_ & which) {
self->threw_ = which;
self->allthrows_++;
rw_throw (ex_stream, __FILE__, __LINE__,
streambuf_func_names [inx],
"%s", "test exception");
}
#else // if defined (_RWSTD_NO_EXCEPTIONS)
if (callno == throw_when_ [inx] && throw_set_ & which) {
self->threw_ = which;
return false;
}
#endif // _RWSTD_NO_EXCEPTIONS
// ...otherwise check if the member should succeed or fail
// and return true or false, respectively
const bool success = !(fail_set_ & which) || callno != fail_when_;
if (!success)
self->failed_ = which;
return success;
}
#endif // RW_STREAMBUF_H_INCLUDED

View File

@@ -0,0 +1,84 @@
/************************************************************************
*
* rwthread.h - declarations for testsuite thread helpers
*
* $Id: rw_thread.h 580483 2007-09-28 20:55:52Z sebor $
*
************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 2005-2006 Rogue Wave Software.
*
**************************************************************************/
#ifndef RW_RWTHREAD_H_INCLUDED
#define RW_RWTHREAD_H_INCLUDED
#include <testdefs.h>
extern "C" {
struct rw_thread_attr_t;
struct rw_thread_t
{
long threadno; // 0-based unique thread number
long id; // thread id
void* handle; // thread handle
};
// same as POSIX pthread_create()
_TEST_EXPORT int
rw_thread_create (rw_thread_t*,
rw_thread_attr_t*,
void* (*)(void*),
void*);
// same as POSIX pthread_join()
_TEST_EXPORT int
rw_thread_join (rw_thread_t, void**);
// create a pool of nthreads, passing each a successive element
// of argarray as argument (if non-null) and filling the tidarray
// array with their id's; if (tidarray == 0), waits for all
// threads to join and fills the aragarray with the result
// returned from each thread
// if (nthreads == SIZE_MAX), sets nthreads to the positive result
// of rw_get_processors() plus 1, or to 2 otherwise
// returns 0 on success, or a non-zero value indicating the thread
// number that failed to create on error
_TEST_EXPORT int
rw_thread_pool (rw_thread_t* /* tidarray */,
_RWSTD_SIZE_T /* nthreads */,
rw_thread_attr_t* /* attr */,
void* (*)(void*) /* thr_proc */,
void** /* argarray */);
// returns the number of logical processors/cores on the system,
// or -1 on error
_TEST_EXPORT int
rw_get_cpus ();
} // extern "C"
#endif // RW_RWTHREAD_H_INCLUDED

View File

@@ -0,0 +1,329 @@
/***************************************************************************
*
* rw_value.h - defines a User Defined Class type and User Defined POD type
*
* $Id: rw_value.h 510970 2007-02-23 14:57:45Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 1994-2005 Rogue Wave Software.
*
**************************************************************************/
#ifndef RW_VALUE_H_INCLUDED
#define RW_VALUE_H_INCLUDED
#include <testdefs.h>
#include <alg_test.h> // for conv_to_bool
/**************************************************************************/
struct UserData
{
int val_; // object's value
};
/**************************************************************************/
struct _TEST_EXPORT UserPOD
{
UserData data_;
static UserPOD
from_char (char c)
{
UserPOD x;
x.data_.val_ = c;
return x;
}
// construct an array of objects of type UserPOD each initialized
// from the corresponding element of the character array
// when the last argument is true and the character array
// is not sorted in ascending order the function fails by
// returning 0
static UserPOD*
from_char (const char*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX,
bool = false);
// returns a pointer to the first element in the sequence of UserClass
// whose value is not equal to the corresponding element of
// the character string or 0 when no such element exists
static const UserPOD* mismatch (const UserPOD*, const char*,
_RWSTD_SIZE_T /* len */ = _RWSTD_SIZE_MAX);
};
/**************************************************************************/
// objects of class UserClass maintain a count of their instances in existence,
// the number of defaut and copy ctor calls, assignment operators, and
// the number of calls to operator==() and operator<()
struct _TEST_EXPORT UserClass
{
UserData data_;
const int id_; // a unique non-zero id of the object
int origin_; // id of the original object that this
// is a (perhaps indirect) copy of (id_
// when this is the original)
int src_id_; // id of the object that this is a direct
// copy of (id_ when this the original)
// number of times the object has been copied into another object,
// regardless of whether the operation threw an exception or not
_RWSTD_SIZE_T n_copy_ctor_;
// number of times the object's assignment operator has been invoked,
// regardless of whether the operation threw an exception or not
_RWSTD_SIZE_T n_op_assign_;
// number of times the object's operator+=() has been invoked,
// regardless of whether the operation threw an exception or not
_RWSTD_SIZE_T n_op_plus_assign_;
// number of times the object's operator-=() has been invoked,
// regardless of whether the operation threw an exception or not
_RWSTD_SIZE_T n_op_minus_assign_;
// number of times the object's operator*=() has been invoked,
// regardless of whether the operation threw an exception or not
_RWSTD_SIZE_T n_op_times_assign_;
// number of times the object's operator/=() has been invoked,
// regardless of whether the operation threw an exception or not
_RWSTD_SIZE_T n_op_div_assign_;
// number of times the object's operator== was invoked
// regardless of whether the operation threw an exception
_RWSTD_SIZE_T n_op_eq_;
// number of times the object's operator< was invoked
// regardless of whether the operation threw an exception
_RWSTD_SIZE_T n_op_lt_;
static _RWSTD_SIZE_T count_; // number of objects in existence (>= 0)
static int id_gen_; // generates a unique non-zero id
static int (*gen_)(); // extern "C++" int (*)()
static _RWSTD_SIZE_T n_total_def_ctor_; // number of default ctor calls
static _RWSTD_SIZE_T n_total_copy_ctor_; // ... copy ctors ...
static _RWSTD_SIZE_T n_total_dtor_; // ... dtors ...
static _RWSTD_SIZE_T n_total_op_assign_; // ... assignment operators ...
static _RWSTD_SIZE_T n_total_op_plus_assign_; // ... operator+=
static _RWSTD_SIZE_T n_total_op_minus_assign_; // ... operator-=
static _RWSTD_SIZE_T n_total_op_times_assign_; // ... operator*=
static _RWSTD_SIZE_T n_total_op_div_assign_; // ... operator/=
static _RWSTD_SIZE_T n_total_op_eq_; // ... equality operators ...
static _RWSTD_SIZE_T n_total_op_lt_; // ... operators <= ...
// classes thrown from the respective functions
struct Exception { int id_; };
struct DefCtor: Exception { };
struct CopyCtor: Exception { };
struct Dtor: Exception { };
struct OpAssign: Exception { };
struct OpPlusAssign: Exception { };
struct OpMinusAssign: Exception { };
struct OpTimesAssign: Exception { };
struct OpDivAssign: Exception { };
struct OpEq: Exception { };
struct OpLt: Exception { };
// throw object's `id' wrapped in the appropriate struct when the
// corresponding n_total_xxx_ counter reaches the value pointed to
// by the respective pointer below
static _RWSTD_SIZE_T* def_ctor_throw_ptr_;
static _RWSTD_SIZE_T* copy_ctor_throw_ptr_;
static _RWSTD_SIZE_T* dtor_throw_ptr_;
static _RWSTD_SIZE_T* op_assign_throw_ptr_;
static _RWSTD_SIZE_T* op_plus_assign_throw_ptr_;
static _RWSTD_SIZE_T* op_minus_assign_throw_ptr_;
static _RWSTD_SIZE_T* op_times_assign_throw_ptr_;
static _RWSTD_SIZE_T* op_div_assign_throw_ptr_;
static _RWSTD_SIZE_T* op_eq_throw_ptr_;
static _RWSTD_SIZE_T* op_lt_throw_ptr_;
// objects to which the pointers above initally point
static _RWSTD_SIZE_T def_ctor_throw_count_;
static _RWSTD_SIZE_T copy_ctor_throw_count_;
static _RWSTD_SIZE_T dtor_throw_count_;
static _RWSTD_SIZE_T op_assign_throw_count_;
static _RWSTD_SIZE_T op_plus_assign_throw_count_;
static _RWSTD_SIZE_T op_minus_assign_throw_count_;
static _RWSTD_SIZE_T op_times_assign_throw_count_;
static _RWSTD_SIZE_T op_div_assign_throw_count_;
static _RWSTD_SIZE_T op_eq_throw_count_;
static _RWSTD_SIZE_T op_lt_throw_count_;
UserClass ();
UserClass (const UserClass&);
~UserClass ();
UserClass& operator= (const UserClass&);
UserClass& operator+= (const UserClass&);
UserClass& operator-= (const UserClass&);
UserClass& operator*= (const UserClass&);
UserClass& operator/= (const UserClass&);
bool operator== (const UserClass&) const;
bool operator< (const UserClass&) const;
// the following operators are not declared or defined in order
// to detect any unwarranted assumptions made in algorithms
// bool operator!= (const UserClass &rhs) const;
// bool operator> (const UserClass &rhs) const;
// bool operator>= (const UserClass &rhs) const;
// bool operator<= (const UserClass &rhs) const;
// UserClass operator- () const;
// UserClass operator+ () const;
bool
is_count (_RWSTD_SIZE_T copy_ctor,
_RWSTD_SIZE_T op_assign,
_RWSTD_SIZE_T op_eq,
_RWSTD_SIZE_T op_lt) const;
static bool
is_total (_RWSTD_SIZE_T count,
_RWSTD_SIZE_T n_def_ctor,
_RWSTD_SIZE_T n_copy_ctor,
_RWSTD_SIZE_T n_op_assign,
_RWSTD_SIZE_T n_op_eq,
_RWSTD_SIZE_T n_op_lt);
// returns a pointer to the first element in the sequence whose value
// is less than the value of the immediately preceding element, or 0
// when no such element exists
static const UserClass*
first_less (const UserClass*, _RWSTD_SIZE_T);
static void reset_totals ();
static UserClass
from_char (char c)
{
UserClass x;
x.data_.val_ = c;
return x;
}
// construct an array of objects of type UserClass each initialized
// from the corresponding element of the character array
// when the last argument is true and the character array
// is not sorted in ascending order the function fails by
// returning 0
static UserClass*
from_char (const char*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX,
bool = false);
// returns -1 when less, 0 when same, or +1 when the array
// of UserClass objects is greater than the character string
static int compare (const UserClass*, const char*,
_RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
static int compare (const char*, const UserClass*,
_RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
// returns -1 when less, 0 when same, or +1 when the first
// array of UserClass objects is greater than the second array
static int compare (const UserClass*, const UserClass*, _RWSTD_SIZE_T);
// returns a pointer to the first element in the sequence of UserClass
// whose value is not equal to the corresponding element of
// the character string or 0 when no such element exists
static const UserClass* mismatch (const UserClass*, const char*,
_RWSTD_SIZE_T);
struct Less;
private:
enum assign_op {
op_assign, op_plus_assign, op_minus_assign,
op_times_assign, op_div_assign
};
void assign (assign_op, const UserClass&);
};
/**************************************************************************/
struct _TEST_EXPORT UnaryPredicate
{
// total number of times operator() was invoked
static _RWSTD_SIZE_T n_total_op_fcall_;
UnaryPredicate ();
UnaryPredicate (const UnaryPredicate&);
UnaryPredicate& operator= (const UnaryPredicate&);
virtual ~UnaryPredicate ();
virtual conv_to_bool operator()(const UserClass&) const;
};
struct _TEST_EXPORT BinaryPredicate
{
// total number of times operator() was invoked
static _RWSTD_SIZE_T n_total_op_fcall_;
enum binary_op {
op_equals,
op_not_equals,
op_less,
op_less_equal,
op_greater,
op_greater_equal
};
BinaryPredicate (binary_op);
virtual ~BinaryPredicate ();
virtual conv_to_bool operator()(const UserClass&,
const UserClass&) /* non-const */;
private:
// not assignable
void operator= (const BinaryPredicate&);
binary_op op_;
};
struct UserClass::Less: BinaryPredicate
{
// dummy arguments provided to prevent the class from being
// default constructible and implicit conversion from int
Less (int /* dummy */, int /* dummy */)
: BinaryPredicate (BinaryPredicate::op_less) { /* no-op */ }
};
static const struct _TEST_EXPORT UserClassFmatInit {
UserClassFmatInit ();
} _rw_user_class_fmat_init;
#endif // RW_VALUE_H_INCLUDED

View File

@@ -0,0 +1,176 @@
/************************************************************************
*
* testdefs.h - common testsuite definitions
*
* $Id: testdefs.h 580483 2007-09-28 20:55:52Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
* Copyright 2005-2006 The Apache Software Foundation or its licensors,
* as applicable.
*
* Copyright 2003-2007 Rogue Wave Software, Inc.
*
**************************************************************************/
#ifndef RW_TESTDEFS_H_INCLUDED
#define RW_TESTDEFS_H_INCLUDED
#include <rw/_defs.h>
#ifdef _RWSTD_TEST_SRC
// #undef-ine the Compaq C++ macro #defined in response to
// the -std strict_ansi_errors compiler option in order to
// allow C++ extensions (such POSIX names) to be declared
// by C++ libc headers when building the test driver
# undef __PURE_CNAME
#endif // _RWSTD_TEST_SRC
#if (defined (_WIN32) || defined (_WIN64)) \
&& (defined (RWDLL) || defined (_RWSHARED))
# ifndef _RWSTD_TEST_SRC
// using a shared lib, import names
# define _TEST_EXPORT __declspec (dllimport)
# else
// building a shared (test) lib, export names
# define _TEST_EXPORT __declspec (dllexport)
# endif // _RWSTD_LIB_SRC
#else
# define _TEST_EXPORT
#endif // archive/shared library
#if defined (_RWSTD_NO_NAMESPACE) && !defined std
# define std /* empty */
#endif // _RWSTD_NO_NAMESPACE && !std
#if defined (_RWSTD_NO_TYPENAME) && !defined (typename)
# define typename /* ignore */
#endif // _RWSTD_NO_TYPENAME && !typename
#if defined (_RWSTD_NO_EXCEPTIONS)
# ifndef try
# define try if (0); else
# endif // try
# ifdef catch
# define catch void foo; while (0)
# endif
# define RW_CATCH_ALL(ignore) while (0)
#else // if !defined (_RWSTD_NO_EXCEPTIONS)
# define RW_CATCH_ALL(dot_dot_dot) catch (dot_dot_dot)
#endif // _RWSTD_NO_EXCEPTIONS
// give the for-init-variable a local scope
#ifdef _RWSTD_NO_FOR_LOCAL_SCOPE
# define for if (0); else for
#endif // _RWSTD_NO_FOR_LOCAL_SCOPE
// convenience macro for exception specification on function pointers
#ifndef _RWSTD_NO_PTR_EXCEPTION_SPEC
#define _PTR_THROWS(spec) _THROWS (spec)
#else // if defined (_RWSTD_NO_PTR_EXCEPTION_SPEC)
// throw specs on pointers to functions not implemented...
#define _PTR_THROWS(ignore)
#endif // _RWSTD_NO_PTR_EXCEPTION_SPEC
// _RWSTD_PRI{d,i,o,u,x}MAX: macros corresponding to those described
// in 7.8.1 of C99; each of them expands to a character string literal
// containing a conversion specifier, possibly modified by a length
// modifier, suitable for use within the format argument of a formatted
// input/output function when converting the corresponding integer type
#if _RWSTD_LONG_SIZE < _RWSTD_LLONG_SIZE
// using LLONG_SIZE instead of ULLONG_MAX in the preprocessor
// conditional above to work around a gcc 3.2 bug (PR #28595)
# define _RWSTD_PRIdMAX _RWSTD_LLONG_PRINTF_PREFIX "d"
# define _RWSTD_PRIiMAX _RWSTD_LLONG_PRINTF_PREFIX "i"
# define _RWSTD_PRIoMAX _RWSTD_LLONG_PRINTF_PREFIX "o"
# define _RWSTD_PRIuMAX _RWSTD_LLONG_PRINTF_PREFIX "u"
# define _RWSTD_PRIxMAX _RWSTD_LLONG_PRINTF_PREFIX "x"
#elif _RWSTD_INT_SIZE < _RWSTD_LONG_SIZE
# define _RWSTD_PRIdMAX "ld"
# define _RWSTD_PRIiMAX "li"
# define _RWSTD_PRIoMAX "lo"
# define _RWSTD_PRIuMAX "lu"
# define _RWSTD_PRIxMAX "lx"
#else
# define _RWSTD_PRIdMAX "d"
# define _RWSTD_PRIiMAX "i"
# define _RWSTD_PRIoMAX "o"
# define _RWSTD_PRIuMAX "u"
# define _RWSTD_PRIxMAX "x"
#endif
// _RWSTD_PRIz: expands to a conversion specifier corresponding
// to "%z" (i.e., C99 size_t specifier)
#if _RWSTD_SIZE_MAX == _RWSTD_UINT_MAX
// sizeof (size_t) == sizeof (unsigned int)
# define _RWSTD_PRIz ""
#elif _RWSTD_SIZE_MAX == _RWSTD_ULONG_MAX
// sizeof (size_t) == sizeof (unsigned long)
# define _RWSTD_PRIz "l"
#elif _RWSTD_SIZE_MAX == _RWSTD_ULLONG_MAX
// sizeof (size_t) == sizeof (unsigned long long)
# define _RWSTD_PRIz _RWSTD_LLONG_PRINTF_PREFIX ""
#else
// assume sizeof (size_t) == sizeof (unsigned)
# define _RWSTD_PRIz ""
#endif
// test assertion
#ifndef _RWSTD_NO_PRETTY_FUNCTION
// gcc, HP aCC, and Intel C++ all support __PRETTY_FUNCTION__
# define RW_ASSERT(expr) \
((expr) ? (void)0 : _RW::__rw_assert_fail (#expr, __FILE__, __LINE__, \
__PRETTY_FUNCTION__))
#elif !defined (_RWSTD_NO_FUNC)
// C99 specifies the __func__ special identifier
# define RW_ASSERT(expr) \
((expr) ? (void)0 : _RW::__rw_assert_fail (#expr, __FILE__, __LINE__, \
__func__))
#elif defined (__FUNCSIG__)
// MSVC macro
# define RW_ASSERT(expr) \
((expr) ? (void)0 : _RW::__rw_assert_fail (#expr, __FILE__, __LINE__, \
__FUNCSIG__))
#else // if _RWSTD_NO_PRETTY_FUNCTION && _RWSTD_NO_FUNC
# define RW_ASSERT(expr) \
((expr) ? (void)0 : _RW::__rw_assert_fail (#expr, __FILE__, __LINE__, 0))
#endif // _RWSTD_NO_PRETTY_FUNCTION, _RWSTD_NO_FUNC
// convenience macro to get number of elements in a c style array
#define RW_COUNT_OF(x) (sizeof(x) / sizeof(*x))
#if defined (__INTEL_COMPILER) && __INTEL_COMPILER <= 1000
// disable warning #279: controlling expression is constant
// issued for the commonly used RW_ASSERT(!"not implemented")
# pragma warning (disable: 279)
#endif // Intel C++ 10.0 and prior
#endif // RW_TESTDEFS_H_INCLUDED

View File

@@ -0,0 +1,186 @@
/************************************************************************
*
* valcmp.h - declarations of the rw_valcmp() family of helper functions
*
* $Id: valcmp.h 550991 2007-06-26 23:58:07Z sebor $
*
************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 1994-2006 Rogue Wave Software.
*
**************************************************************************/
#ifndef RW_VALCMP_H_INCLUDED
#define RW_VALCMP_H_INCLUDED
#include <testdefs.h>
#define CMP_NULTERM 1 /* the first 0 terminates processing */
#define CMP_RETOFF 2 /* return offset of the first mismatch */
#define CMP_NOCASE 4 /* case-insensitive character comparison */
#define CMP_FP 8 /* safe floating pointing comparison */
_TEST_EXPORT int
rw_valcmp (const void*, const void*,
_RWSTD_SIZE_T, _RWSTD_SIZE_T, _RWSTD_SIZE_T, int);
/**
* Compares the contents of two arrays of objects of integral types,
* possibly of different sizes, for equality, in a strncmp/memcmp
* way.
*
* @param buf1 Pointer to an array of 0 or more objects of integral type.
* @param buf2 Pointer to an array of 0 or more objects of integral type.
* @param nelems The maximum number of elements to compare.
* @param flags Bitmap of flags that determine how the objects are
* compared.
* @return Returns -1, 0, or +1, depending on whether the first array
* is less than, equal to, or greater than the second array.
*/
template <class T, class U>
inline int
rw_valcmp (const T* buf1,
const U* buf2,
_RWSTD_SIZE_T nelems,
int flags = 0)
{
return rw_valcmp (buf1, buf2, nelems, sizeof (T), sizeof (U), flags);
}
/**************************************************************************/
// compares up to a maximum number of characters from the two strings
// posisbly including any embedded NULs (when the cmp_nul bit is set)
// and returns -1, 0, or +1 if the first string compares less, equal,
// or greater, respectively, than the second string, or the offset+1
// of the first mismatched character (when the cmp_off bit is set)
// or 0 otherwise
//
// rw_strncmp(s1, s2) is equivalent to a call to strcmp(s1, s2) when
// the type of s1 and s2 is char*, wcscmp(s1, s2) when the type is
// wchar_t*
//
// rw_strncmp(s1, s2, n) with (n != ~0U) is equivalent to a call to
// strncmp(s1, s2, n) or wcsncmp(s1, s2, n), respectively
//
// rw_strncmp(s1, s2, n, cmp_nul) with (n != ~0U) is equivalent to
// a call to memcmp(s1, s2, n) or wmemcmp(s1, s2, n), respectively
_TEST_EXPORT int
rw_strncmp (const char*, const char*,
_RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
#ifndef _RWSTD_NO_WCHAR_T
_TEST_EXPORT int
rw_strncmp (const char*, const wchar_t*,
_RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
_TEST_EXPORT int
rw_strncmp (const wchar_t*, const char*,
_RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
_TEST_EXPORT int
rw_strncmp (const wchar_t*, const wchar_t*,
_RWSTD_SIZE_T = _RWSTD_SIZE_MAX, int = CMP_NULTERM);
#endif // _RWSTD_NO_WCHAR_T
/**
* Compares two floating point numbers for equality.
*
* @param x The left hand side of the comparison.
* @param y The right hand side of the comparison.
*
* @return Returns a negative value, 0, or a positive value, depending
* on whether the first number is less than, equal to, or greater
* than the second number. The magnitude of the returned value
* indicates the number of distinct values representable in
* the type of the number between the two arguments.
*/
_TEST_EXPORT int
rw_fltcmp (float x, float y);
/**
* @see rw_fltcmp.
*/
_TEST_EXPORT int
rw_dblcmp (double x, double y);
#ifndef _RWSTD_NO_LONG_DOUBLE
/**
* @see rw_fltcmp.
*/
_TEST_EXPORT int
rw_ldblcmp (long double x, long double y);
#endif // _RWSTD_NO_LONG_DOUBLE
/**************************************************************************/
/**
* Compares two values of the same type for equality.
*
* @param x The left hand side of the comparison.
* @param y The right hand side of the comparison.
*
* @return Returns 1 if the the values are the same, 0 otherwise.
*/
template <class T>
inline int rw_equal (T x, T y)
{
return x == y;
}
/**
* @see rw_equal.
*/
inline int rw_equal (float x, float y)
{
return 0 == rw_fltcmp (x, y);
}
/**
* @see rw_equal.
*/
inline int rw_equal (double x, double y)
{
return 0 == rw_dblcmp (x, y);
}
#ifndef _RWSTD_NO_LONG_DOUBLE
/**
* @see rw_equal.
*/
inline int rw_equal (long double x, long double y)
{
return 0 == rw_ldblcmp (x, y);
}
#endif // _RWSTD_NO_LONG_DOUBLE
#endif // RW_VALCMP_H_INCLUDED