You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by se...@apache.org on 2006/05/05 01:16:43 UTC
svn commit: r399884 - in /incubator/stdcxx/trunk/tests: include/21.strings.h
src/21.strings.cpp strings/21.string.append.cpp
strings/21.string.assign.cpp strings/21.string.insert.cpp
strings/21.string.op.plus.equal.cpp strings/21.string.replace.cpp
Author: sebor
Date: Thu May 4 16:16:42 2006
New Revision: 399884
URL: http://svn.apache.org/viewcvs?rev=399884&view=rev
Log:
2006-05-04 Martin Sebor <se...@roguewave.com>
* 21.strings.h (StringState, rw_get_string_stat): New.
* 21.strings.cpp (StringState::assert_equal): Defined.
* 21.string.append.cpp (test_append): Used StringState to simplify
the detection ond reporting of exception safety violations.
* 21.string.assign.cpp (test_assign): Same.
* 21.string.insert.cpp (test_insert): Same.
* 21.string.plus_equal (test_op_plus_eq): Same.
* 21.string.replace (test_replace): Same.
Modified:
incubator/stdcxx/trunk/tests/include/21.strings.h
incubator/stdcxx/trunk/tests/src/21.strings.cpp
incubator/stdcxx/trunk/tests/strings/21.string.append.cpp
incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp
incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp
incubator/stdcxx/trunk/tests/strings/21.string.op.plus.equal.cpp
incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp
Modified: incubator/stdcxx/trunk/tests/include/21.strings.h
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/include/21.strings.h?rev=399884&r1=399883&r2=399884&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/include/21.strings.h (original)
+++ incubator/stdcxx/trunk/tests/include/21.strings.h Thu May 4 16:16:42 2006
@@ -397,6 +397,34 @@
long_string [long_string_len];
};
+
+// 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 StringState
+{
+ const void* data_;
+ _RWSTD_SIZE_T size_;
+ _RWSTD_SIZE_T capacity_;
+
+ // invokes rw_assert() to verify that two states are the same
+ void 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;
+}
+
+
#define Disabled(which) \
StringMembers::opt_memfun_disabled [which & ~StringMembers::mem_mask]
Modified: incubator/stdcxx/trunk/tests/src/21.strings.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/21.strings.cpp?rev=399884&r1=399883&r2=399884&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/21.strings.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/21.strings.cpp Thu May 4 16:16:42 2006
@@ -97,6 +97,27 @@
/**************************************************************************/
+void StringState::
+assert_equal (const StringState &state, int line, int case_line,
+ const char *when) const
+{
+ const int equal =
+ data_ == state.data_
+ && size_ == state.size_
+ && capacity_ == state.capacity_;
+
+ rw_assert (equal, 0, case_line,
+ "line %d: %{$FUNCALL}: object state unexpectedly changed "
+ "from { %#p, %zu, %zu } to { %#p, %zu, %zu } (data, size, "
+ "capacity) after %s",
+ line, data_, size_, capacity_,
+ state.data_, state.size_, state.capacity_,
+ when);
+}
+
+
+/**************************************************************************/
+
// coputes integral base-2 logarithm of its argument
static size_t
_rw_ilog2 (size_t n)
Modified: incubator/stdcxx/trunk/tests/strings/21.string.append.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.append.cpp?rev=399884&r1=399883&r2=399884&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.append.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.append.cpp Thu May 4 16:16:42 2006
@@ -64,9 +64,10 @@
/**************************************************************************/
-// used to exercise
-// append (const charT* s)
-static const TestCase ptr_test_cases [] = {
+// exercises:
+// append (const value_type*)
+static const TestCase
+ptr_test_cases [] = {
#undef TEST
#define TEST(str, arg, res, bthrow) { \
@@ -125,9 +126,10 @@
/**************************************************************************/
-// used to exercise
-// append (const basic_string& str)
-static const TestCase str_test_cases [] = {
+// exercises:
+// append (const basic_string&)
+static const TestCase
+str_test_cases [] = {
#undef TEST
#define TEST(s, arg, res, bthrow) { \
@@ -187,9 +189,10 @@
/**************************************************************************/
-// used to exercise
-// append (const charT* s, size_type n)
-static const TestCase ptr_size_test_cases [] = {
+// exercises:
+// append (const value_type*, size_type)
+static const TestCase
+ptr_size_test_cases [] = {
#undef TEST
#define TEST(str, arg, size, res, bthrow) { \
@@ -251,10 +254,11 @@
/**************************************************************************/
-// used to exercise
-// append (const basic_string& str, size_type off, size_type n)
-// append (InputIterator first, InputIterator last)
-static const TestCase range_test_cases [] = {
+// exercises:
+// append (const basic_string&, size_type, size_type)
+// append (InputIterator, InputIterator)
+static const TestCase
+range_test_cases [] = {
// range_test_cases serves a double duty
#define str_size_size_test_cases range_test_cases
@@ -332,9 +336,10 @@
/**************************************************************************/
-// used to exercise
-// append (charT c, size_type n)
-static const TestCase size_val_test_cases [] = {
+// exercises:
+// append (value_type, size_type)
+static const TestCase
+size_val_test_cases [] = {
#undef TEST
#define TEST(str, size, val, res, bthrow) { \
@@ -502,22 +507,21 @@
const TestString s_arg (wsrc, tcase.arg_len);
std::size_t res_off = 0;
- std::size_t throw_after = 0;
- const std::size_t size = s_str.size ();
- const std::size_t capacity = s_str.capacity ();
- const ConstStringIter begin = s_str.begin ();
+ // save the state of the string object before the call
+ // to detect wxception safety violations (changes to
+ // the state of the object after an exception)
+ const StringState str_state (rw_get_string_state (s_str));
const charT* const ptr_arg = tcase.arg ? wsrc : s_str.c_str ();
const TestString& str_arg = tcase.arg ? s_arg : s_str;
std::size_t total_length_calls = 0;
std::size_t n_length_calls = 0;
- std::size_t* rg_calls =
- rw_get_call_counters ((typename TestString::traits_type*)0,
- (typename TestString::value_type*)0);
+ std::size_t* const rg_calls = rw_get_call_counters ((Traits*)0, (charT*)0);
+
if (rg_calls)
- total_length_calls = rg_calls[UTMemFun::length];
+ total_length_calls = rg_calls [UTMemFun::length];
#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
@@ -525,10 +529,11 @@
#endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE
- // iterate for`n=throw_after' starting at the next call to operator
- // new, forcing each call to throw an exception, until the appendion
- // finally succeeds (i.e, no exception is thrown)
- for ( ; ; ) {
+ // iterate for`throw_after' starting at the next call to operator new,
+ // forcing each call to throw an exception, until the function finally
+ // succeeds (i.e, no exception is thrown)
+ std::size_t throw_after;
+ for (throw_after = 0; ; ++throw_after) {
#ifndef _RWSTD_NO_EXCEPTIONS
# ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
@@ -566,7 +571,7 @@
const TestString& s_res = s_str.append (ptr_arg);
res_off = &s_res - &s_str;
if (rg_calls)
- n_length_calls = rg_calls[UTMemFun::length];
+ n_length_calls = rg_calls [UTMemFun::length];
break;
}
@@ -679,27 +684,13 @@
if (caught) {
// verify that an exception thrown during allocation
// didn't cause a change in the state of the object
-
- rw_assert (s_str.size () == size, 0, tcase.line,
- "line %d: %{$FUNCALL}: size unexpectedly changed "
- "from %zu to %zu after an exception",
- __LINE__, size, s_str.size ());
-
- rw_assert (s_str.capacity () == capacity, 0, tcase.line,
- "line %d: %{$FUNCALL}: capacity unexpectedly "
- "changed from %zu to %zu after an exception",
- __LINE__, capacity, s_str.capacity ());
-
- rw_assert (s_str.begin () == begin, 0, tcase.line,
- "line %d: %{$FUNCALL}: begin() unexpectedly "
- "changed from after an exception by %d",
- __LINE__, s_str.begin () - begin);
+ str_state.assert_equal (rw_get_string_state (s_str),
+ __LINE__, tcase.line, caught);
if (-1 == tcase.bthrow) {
- // increment to allow this call to operator new to succeed
- // and force the next one to fail, and try calling the same
- // function again
- ++throw_after;
+ // allow this call to operator new to succeed and try
+ // to make the next one to fail during the next call
+ // to the same function again
continue;
}
}
Modified: incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp?rev=399884&r1=399883&r2=399884&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp Thu May 4 16:16:42 2006
@@ -65,7 +65,8 @@
// used to exercise:
// assign (const value_type*)
-static const TestCase ptr_test_cases [] = {
+static const TestCase
+ptr_test_cases [] = {
#undef TEST
#define TEST(str, arg, res, bthrow) { \
@@ -120,7 +121,8 @@
// used to exercise:
// assign (const basic_string&)
-static const TestCase str_test_cases [] = {
+static const TestCase
+str_test_cases [] = {
#undef TEST
#define TEST(s, arg, res, bthrow) { \
@@ -181,7 +183,8 @@
// used to exercise:
// assign (const value_type*, size_type)
-static const TestCase ptr_size_test_cases [] = {
+static const TestCase
+ptr_size_test_cases [] = {
#undef TEST
#define TEST(str, arg, size, res, bthrow) { \
@@ -252,7 +255,8 @@
// used to exercise:
// assign (const basic_string&, size_type, size_type)
// assign (InputIterator, InputIterator)
-static const TestCase range_test_cases [] = {
+static const TestCase
+range_test_cases [] = {
// range_test_cases serves a double duty
#define str_size_size_test_cases range_test_cases
@@ -336,7 +340,8 @@
// used to exercise:
// assign (size_type, value_type)
-static const TestCase size_val_test_cases [] = {
+static const TestCase
+size_val_test_cases [] = {
#undef TEST
#define TEST(str, size, val, res, bthrow) { \
@@ -501,12 +506,12 @@
const TestString s_arg (wsrc, tcase.arg_len);
std::size_t res_off = 0;
- std::size_t throw_after = 0;
std::size_t size = tcase.size >= 0 ? tcase.size : s_str.max_size () + 1;
- const std::size_t ssize = s_str.size ();
- const std::size_t capacity = s_str.capacity ();
- const ConstStringIter begin = s_str.begin ();
+ // save the state of the string object before the call
+ // to detect wxception safety violations (changes to
+ // the state of the object after an exception)
+ const StringState str_state (rw_get_string_state (s_str));
// first function argument
const charT* const arg_ptr = tcase.arg ? wsrc : s_str.c_str ();
@@ -514,11 +519,10 @@
std::size_t total_length_calls = 0;
std::size_t n_length_calls = 0;
- std::size_t* rg_calls =
- rw_get_call_counters ((typename TestString::traits_type*)0,
- (typename TestString::value_type*)0);
+ std::size_t* const rg_calls = rw_get_call_counters ((Traits*)0, (charT*)0);
+
if (rg_calls)
- total_length_calls = rg_calls[UTMemFun::length];
+ total_length_calls = rg_calls [UTMemFun::length];
#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
@@ -526,10 +530,11 @@
#endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE
- // iterate for`n=throw_after' starting at the next call to operator
- // new, forcing each call to throw an exception, until the appendion
- // finally succeeds (i.e, no exception is thrown)
- for ( ; ; ) {
+ // iterate for`throw_after' starting at the next call to operator new,
+ // forcing each call to throw an exception, until the function finally
+ // succeeds (i.e, no exception is thrown)
+ std::size_t throw_after;
+ for (throw_after = 0; ; ++throw_after) {
#ifndef _RWSTD_NO_EXCEPTIONS
# ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
@@ -566,7 +571,7 @@
const TestString& s_res = s_str.assign (arg_ptr);
res_off = &s_res - &s_str;
if (rg_calls)
- n_length_calls = rg_calls[UTMemFun::length];
+ n_length_calls = rg_calls [UTMemFun::length];
break;
}
@@ -680,27 +685,13 @@
if (caught) {
// verify that an exception thrown during allocation
// didn't cause a change in the state of the object
-
- rw_assert (s_str.size () == ssize, 0, tcase.line,
- "line %d: %{$FUNCALL}: size unexpectedly changed "
- "from %zu to %zu after an exception",
- __LINE__, ssize, s_str.size ());
-
- rw_assert (s_str.capacity () == capacity, 0, tcase.line,
- "line %d: %{$FUNCALL}: capacity unexpectedly "
- "changed from %zu to %zu after an exception",
- __LINE__, capacity, s_str.capacity ());
-
- rw_assert (s_str.begin () == begin, 0, tcase.line,
- "line %d: %{$FUNCALL}: begin() unexpectedly "
- "changed from after an exception by %d",
- __LINE__, s_str.begin () - begin);
+ str_state.assert_equal (rw_get_string_state (s_str),
+ __LINE__, tcase.line, caught);
if (-1 == tcase.bthrow) {
- // increment to allow this call to operator new to succeed
- // and force the next one to fail, and try calling the same
- // function again
- ++throw_after;
+ // allow this call to operator new to succeed and try
+ // to make the next one to fail during the next call
+ // to the same function again
continue;
}
}
Modified: incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp?rev=399884&r1=399883&r2=399884&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp Thu May 4 16:16:42 2006
@@ -65,7 +65,8 @@
// used to exercise
// insert (size_type pos, const charT* s)
-static const TestCase size_ptr_test_cases [] = {
+static const TestCase
+size_ptr_test_cases [] = {
#undef TEST
#define TEST(str, off, arg, res, bthrow) { \
@@ -133,7 +134,8 @@
// used to exercise
// insert (size_type pos, const basic_string& str)
-static const TestCase size_str_test_cases [] = {
+static const TestCase
+size_str_test_cases [] = {
#undef TEST
#define TEST(str, off, arg, res, bthrow) { \
@@ -201,7 +203,8 @@
// exrcises
// insert (size_type off, basic_string& str, size_type off2, size_type n)
// insert (iterator p, InputIterator first, InputIterator last)
-static const TestCase range_test_cases [] = {
+static const TestCase
+range_test_cases [] = {
// range_test_cases serves a double duty
#define size_str_size_size_test_cases range_test_cases
@@ -288,7 +291,8 @@
// used to exercise
// insert (size_type pos, const charT* s, size_type n)
-static const TestCase size_ptr_size_test_cases [] = {
+static const TestCase
+size_ptr_size_test_cases [] = {
#undef TEST
#define TEST(str, off, arg, size2, res, bthrow) { \
@@ -357,7 +361,8 @@
// exrecises
// insert (size_type pos, size_type n, charT c)
// insert (iterator p, size_type n, charT c)
-static const TestCase size_val_test_cases [] = {
+static const TestCase
+size_val_test_cases [] = {
// size_val_test_cases serves a double duty
#define size_size_val_test_cases size_val_test_cases
@@ -422,7 +427,8 @@
// used to exercise
// insert (iterator p, charT c)
-static const TestCase val_test_cases [] = {
+static const TestCase
+val_test_cases [] = {
#undef TEST
#define TEST(str, off, val, res, bthrow) \
@@ -580,16 +586,16 @@
return;
}
- TestString s_str (wstr, tcase.str_len);
- TestString s_arg (warg, tcase.arg_len);
+ /* const */ TestString s_str (wstr, tcase.str_len);
+ const TestString s_arg (warg, tcase.arg_len);
+
+ // save the state of the string object before the call
+ // to detect wxception safety violations (changes to
+ // the state of the object after an exception)
+ const StringState str_state (rw_get_string_state (s_str));
std::size_t res_off = 0;
std::size_t exp_off = Insert (val) == which ? tcase.off : 0;
- std::size_t throw_after = 0;
-
- const std::size_t size = s_str.size ();
- const std::size_t capacity = s_str.capacity ();
- const ConstStringIter begin = s_str.begin ();
const charT* const arg_ptr = tcase.arg ? warg : s_str.c_str ();
const TestString& arg_str = tcase.arg ? s_arg : s_str;
@@ -597,11 +603,10 @@
std::size_t total_length_calls = 0;
std::size_t n_length_calls = 0;
- std::size_t* rg_calls =
- rw_get_call_counters ((typename TestString::traits_type*)0,
- (typename TestString::value_type*)0);
+ std::size_t* const rg_calls = rw_get_call_counters ((Traits*)0, (charT*)0);
+
if (rg_calls)
- total_length_calls = rg_calls[UTMemFun::length];
+ total_length_calls = rg_calls [UTMemFun::length];
#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
@@ -609,10 +614,11 @@
#endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE
- // iterate for`n=throw_after' starting at the next call to operator
- // new, forcing each call to throw an exception, until the appendion
- // finally succeeds (i.e, no exception is thrown)
- for ( ; ; ) {
+ // iterate for`throw_after' starting at the next call to operator new,
+ // forcing each call to throw an exception, until the function finally
+ // succeeds (i.e, no exception is thrown)
+ std::size_t throw_after;
+ for (throw_after = 0; ; ++throw_after) {
#ifndef _RWSTD_NO_EXCEPTIONS
# ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
@@ -646,7 +652,7 @@
const TestString& s_res = s_str.insert (tcase.off, arg_ptr);
res_off = &s_res - &s_str;
if (rg_calls)
- n_length_calls = rg_calls[UTMemFun::length];
+ n_length_calls = rg_calls [UTMemFun::length];
break;
}
@@ -776,27 +782,13 @@
if (caught) {
// verify that an exception thrown during allocation
// didn't cause a change in the state of the object
-
- rw_assert (s_str.size () == size, 0, tcase.line,
- "line %d: %{$FUNCALL}: size unexpectedly changed "
- "from %zu to %zu after an exception",
- __LINE__, size, s_str.size ());
-
- rw_assert (s_str.capacity () == capacity, 0, tcase.line,
- "line %d: %{$FUNCALL}: capacity unexpectedly "
- "changed from %zu to %zu after an exception",
- __LINE__, capacity, s_str.capacity ());
-
- rw_assert (s_str.begin () == begin, 0, tcase.line,
- "line %d: %{$FUNCALL}: begin() unexpectedly "
- "changed from after an exception by %d",
- __LINE__, s_str.begin () - begin);
+ str_state.assert_equal (rw_get_string_state (s_str),
+ __LINE__, tcase.line, caught);
if (-1 == tcase.bthrow) {
- // increment to allow this call to operator new to succeed
- // and force the next one to fail, and try calling the same
- // function again
- ++throw_after;
+ // allow this call to operator new to succeed and try
+ // to make the next one to fail during the next call
+ // to the same function again
continue;
}
}
Modified: incubator/stdcxx/trunk/tests/strings/21.string.op.plus.equal.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.op.plus.equal.cpp?rev=399884&r1=399883&r2=399884&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.op.plus.equal.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.op.plus.equal.cpp Thu May 4 16:16:42 2006
@@ -62,7 +62,8 @@
// used to exercise
// operator += (const charT* s)
-static const TestCase ptr_test_cases [] = {
+static const TestCase
+ptr_test_cases [] = {
#undef TEST
#define TEST(str, src, res, bthrow) \
@@ -120,7 +121,8 @@
// used to exercise
// operator += (const basic_string& str)
-static const TestCase str_test_cases [] = {
+static const TestCase
+str_test_cases [] = {
#undef TEST
#define TEST(str, src, res, bthrow) \
@@ -179,7 +181,8 @@
// used to exercise
// operator+= (value_type c)
-static const TestCase val_test_cases [] = {
+static const TestCase
+val_test_cases [] = {
#undef TEST
#define TEST(str, val, res, bthrow) \
@@ -234,15 +237,15 @@
rw_widen (wstr, tcase.str, tcase.str_len);
rw_widen (warg, tcase.arg, tcase.arg_len);
- TestString s_str (wstr, tcase.str_len);
- TestString s_arg (warg, tcase.arg_len);
+ /* const */ TestString s_str (wstr, tcase.str_len);
+ const TestString s_arg (warg, tcase.arg_len);
- std::size_t res_off = 0;
- std::size_t throw_after = 0;
+ // save the state of the string object before the call
+ // to detect wxception safety violations (changes to
+ // the state of the object after an exception)
+ const StringState str_state (rw_get_string_state (s_str));
- const std::size_t size = s_str.size ();
- const std::size_t capacity = s_str.capacity ();
- const ConstStringIter begin = s_str.begin ();
+ std::size_t res_off = 0;
const charT* const arg_ptr = tcase.arg ? warg : s_str.c_str ();
const TestString& arg_str = tcase.arg ? s_arg : s_str;
@@ -250,11 +253,10 @@
std::size_t total_length_calls = 0;
std::size_t n_length_calls = 0;
- std::size_t* rg_calls =
- rw_get_call_counters ((typename TestString::traits_type*)0,
- (typename TestString::value_type*)0);
+ std::size_t* const rg_calls = rw_get_call_counters ((Traits*)0, (charT*)0);
+
if (rg_calls)
- total_length_calls = rg_calls[UTMemFun::length];
+ total_length_calls = rg_calls [UTMemFun::length];
#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
@@ -262,10 +264,11 @@
#endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE
- // iterate for`n=throw_after' starting at the next call to operator
- // new, forcing each call to throw an exception, until the appendion
- // finally succeeds (i.e, no exception is thrown)
- for ( ; ; ) {
+ // iterate for`throw_after' starting at the next call to operator new,
+ // forcing each call to throw an exception, until the function finally
+ // succeeds (i.e, no exception is thrown)
+ std::size_t throw_after;
+ for (throw_after = 0; ; ++throw_after) {
#ifndef _RWSTD_NO_EXCEPTIONS
# ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
@@ -300,7 +303,7 @@
const TestString& s_res = s_str += arg_ptr;
res_off = &s_res - &s_str;
if (rg_calls)
- n_length_calls = rg_calls[UTMemFun::length];
+ n_length_calls = rg_calls [UTMemFun::length];
break;
}
@@ -393,27 +396,13 @@
if (caught) {
// verify that an exception thrown during allocation
// didn't cause a change in the state of the object
-
- rw_assert (s_str.size () == size, 0, tcase.line,
- "line %d: %{$FUNCALL}: size unexpectedly changed "
- "from %zu to %zu after an exception",
- __LINE__, size, s_str.size ());
-
- rw_assert (s_str.capacity () == capacity, 0, tcase.line,
- "line %d: %{$FUNCALL}: capacity unexpectedly "
- "changed from %zu to %zu after an exception",
- __LINE__, capacity, s_str.capacity ());
-
- rw_assert (s_str.begin () == begin, 0, tcase.line,
- "line %d: %{$FUNCALL}: begin() unexpectedly "
- "changed from after an exception by %d",
- __LINE__, s_str.begin () - begin);
+ str_state.assert_equal (rw_get_string_state (s_str),
+ __LINE__, tcase.line, caught);
if (-1 == tcase.bthrow) {
- // increment to allow this call to operator new to succeed
- // and force the next one to fail, and try calling the same
- // function again
- ++throw_after;
+ // allow this call to operator new to succeed and try
+ // to make the next one to fail during the next call
+ // to the same function again
continue;
}
}
Modified: incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp?rev=399884&r1=399883&r2=399884&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp Thu May 4 16:16:42 2006
@@ -703,8 +703,12 @@
/* const */ TestString s_str (wstr, tcase.str_len);
const TestString s_arg (warg, tcase.arg_len);
+ // save the state of the string object before the call
+ // to detect wxception safety violations (changes to
+ // the state of the object after an exception)
+ const StringState str_state (rw_get_string_state (s_str));
+
std::size_t res_off = 0;
- std::size_t throw_after = 0;
int first = use_iters ? tcase.off : tcase.str_len + 1;
int last = use_iters ? tcase.off + tcase.size : tcase.str_len + 1;
@@ -715,10 +719,6 @@
StringIter it_last (std::size_t (last) >= s_str.size () ?
s_str.end () : s_str.begin () + last);
- const std::size_t ssize = s_str.size ();
- const std::size_t capacity = s_str.capacity ();
- const ConstStringIter begin = s_str.begin ();
-
// string function argument
const charT* const arg_ptr = tcase.arg ? warg : s_str.c_str ();
const TestString& arg_str = tcase.arg ? s_arg : s_str;
@@ -726,11 +726,10 @@
std::size_t total_length_calls = 0;
std::size_t n_length_calls = 0;
- std::size_t* rg_calls =
- rw_get_call_counters ((typename TestString::traits_type*)0,
- (typename TestString::value_type*)0);
+ std::size_t* const rg_calls = rw_get_call_counters ((Traits*)0, (charT*)0);
+
if (rg_calls)
- total_length_calls = rg_calls[UTMemFun::length];
+ total_length_calls = rg_calls [UTMemFun::length];
#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
@@ -738,10 +737,11 @@
#endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE
- // iterate for`n=throw_after' starting at the next call to operator
- // new, forcing each call to throw an exception, until the appendion
- // finally succeeds (i.e, no exception is thrown)
- for ( ; ; ) {
+ // iterate for`throw_after' starting at the next call to operator new,
+ // forcing each call to throw an exception, until the function finally
+ // succeeds (i.e, no exception is thrown)
+ std::size_t throw_after;
+ for (throw_after = 0; ; ++throw_after) {
#ifndef _RWSTD_NO_EXCEPTIONS
# ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
@@ -781,7 +781,7 @@
s_str.replace (tcase.off, tcase.size, arg_ptr);
res_off = &s_res - &s_str;
if (rg_calls)
- n_length_calls = rg_calls[UTMemFun::length];
+ n_length_calls = rg_calls [UTMemFun::length];
break;
}
@@ -819,7 +819,7 @@
s_str.replace (it_first, it_last, arg_ptr);
res_off = &s_res - &s_str;
if (rg_calls)
- n_length_calls = rg_calls[UTMemFun::length];
+ n_length_calls = rg_calls [UTMemFun::length];
break;
}
@@ -931,27 +931,13 @@
if (caught) {
// verify that an exception thrown during allocation
// didn't cause a change in the state of the object
-
- rw_assert (s_str.size () == ssize, 0, tcase.line,
- "line %d: %{$FUNCALL}: size unexpectedly changed "
- "from %zu to %zu after an exception",
- __LINE__, ssize, s_str.size ());
-
- rw_assert (s_str.capacity () == capacity, 0, tcase.line,
- "line %d: %{$FUNCALL}: capacity unexpectedly "
- "changed from %zu to %zu after an exception",
- __LINE__, capacity, s_str.capacity ());
-
- rw_assert (s_str.begin () == begin, 0, tcase.line,
- "line %d: %{$FUNCALL}: begin() unexpectedly "
- "changed from after an exception by %d",
- __LINE__, s_str.begin () - begin);
+ str_state.assert_equal (rw_get_string_state (s_str),
+ __LINE__, tcase.line, caught);
if (-1 == tcase.bthrow) {
- // increment to allow this call to operator new to succeed
- // and force the next one to fail, and try calling the same
- // function again
- ++throw_after;
+ // allow this call to operator new to succeed and try
+ // to make the next one to fail during the next call
+ // to the same function again
continue;
}
}