34template <
class Exception>
37#ifndef _RWSTD_NO_EXCEPTIONS
94#if !defined (_RWSTD_NO_NAMESPACE) && !defined (_RWSTD_NO_HONOR_STD)
96# define TEST_NAMESPACE_DEF(T) void T ()
98# define TEST_NAMESPACE_DEF(ignore) (void)0
102#ifndef _RWSTD_NO_PTR_EXCEPTION_SPEC
103# define _PTR_THROWS(spec) _THROWS (spec)
106# define _PTR_THROWS(ignore)
113 typedef std::T T ## _type; \
114 TEST_NAMESPACE_DEF (T); \
116 std::T obj_ ## T ("std::" _RWSTD_STR (T)); \
120 std::T& (std::T::*p_assign_ ## T)(const std::T&) \
121 _PTR_THROWS(()) = &std::T::operator=; \
122 _RWSTD_UNUSED (p_assign_ ## T); \
124 const char* (std::T::*p_what_ ## T)() const \
125 _PTR_THROWS(()) = &std::T::what; \
126 _RWSTD_UNUSED (p_what_ ## T); \
128 result = result << 1 | cmp (obj_ ## T.what (), \
129 "std::" _RWSTD_STR (T))
141static int test_exception_defs ()
162 const char s[40] =
"";
185template <
class Exception>
188#ifndef _RWSTD_NO_EXCEPTIONS
199 "caught by const reference; %s::what() == %#s",
204 "threw %s, caught an unknown exception",
str);
216 "caught by value; %s::what() == %#s",
221 "threw %s, caught an unknown exception",
str);
235 "caught copy by value; %s::what() == %#s",
240 "threw %s, caught an unknown exception",
str);
252 "caught by non-const reference to base; %s::what() == %#s",
257 "threw %s, caught an unknown exception",
str);
275 "caught rethrown by value; %s::what() == %#s",
str,
str);
279 "threw %s, caught an unknown exception",
str);
291 "caught by value; %s::what() == %#s",
302 "caught rethrown copy by value; %s::what() == %#s",
307 "threw %s, caught an unknown exception",
str);
329 const char*
const names[] = {
330 "logic_error",
"domain_error",
"invalid_argument",
"length_error",
331 "out_of_range",
"runtime_error",
"range_error",
"overflow_error",
336 const int failures = test_exception_defs ();
338 for (
unsigned i = 0;
i !=
sizeof names /
sizeof *names; ++
i) {
339 rw_assert (!(failures & (1 <<
i)), 0, __LINE__,
340 "std::%s::%s (const std::string&) postcondition",
352 char long_str [0x10000];
353 for (
unsigned i = 0;
i !=
sizeof long_str - 1; ++
i)
356 long_str [
sizeof long_str - 1] =
'\0';
363 void *
p = ::operator
new (
sizeof long_str);
364 ::operator
delete (
p);
367#ifdef _RWSTD_NO_REPLACEABLE_NEW_DELETE
373 "replacement ::operator new(std::size_t = %u) failed "
374 "to throw when called directly from a program: this "
375 "is an expected failure on this platform",
381 "replacement ::operator new(std::size_t = %u) "
382 "unexpectdly failed to throw when called directly "
398 void*
const p = _RW::__rw_allocate (
sizeof long_str, 0);
399 _RW::__rw_deallocate (
p, 0);
402#ifdef _RWSTD_NO_REPLACEABLE_NEW_DELETE
408 "replacement ::operator new(std::size_t = %u) failed "
409 "to throw when called from the library: this is an "
410 "expected failure on this platform",
416 "replacement ::operator new(std::size_t = %u) "
417 "unexpectdly failed to throw when called from "
430#define TEST_EX_SPEC(T) do { \
432 *pst->throw_at_calls_ [0] = std::size_t (-1); \
433 *pst->throw_at_calls_ [1] = std::size_t (-1); \
435 test_throw ((std:: T*)0, "std::" #T); \
437 *pst->throw_at_calls_ [0] = pst->new_calls_ [0] + 1; \
438 *pst->throw_at_calls_ [1] = pst->new_calls_ [1] + 1; \
442 const int threw = test_ex_spec ((std::T*)0, long_str); \
443 rw_assert (threw == new_throws, 0, __LINE__, \
444 "attempthing to construct a std::" #T " %s an exception", \
445 new_throws ? "failed to rethrow" : "unexpectedly threw"); \
464int main (
int argc,
char* argv [])
466 return rw_test (argc, argv, __FILE__,
467 "lib.std.exceptions",
int test_ex_spec(Exception *, const char *str)
void is_explicit(const std::logic_error &)
int test_throw(Exception *, const char *str)
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define _RWSTD_REINTERPRET_CAST(T, x)
#define _RWSTD_UNUSED(arg)
_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,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_warn(int, const char *, int, const char *,...)
_TEST_EXPORT rwt_free_store * rwt_get_free_store(rwt_free_store *)
bogus_exception(const std::string &)
bogus_exception(const char *)
_RWSTD_SIZE_T * throw_at_calls_[2]
_RWSTD_SIZE_T new_calls_[2]