stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ant...@apache.org
Subject svn commit: r409585 - in /incubator/stdcxx/trunk/tests/strings: 21.string.append.cpp 21.string.assign.cpp 21.string.insert.cpp 21.string.op.plus.equal.cpp 21.string.replace.cpp
Date Fri, 26 May 2006 08:23:43 GMT
Author: antonp
Date: Fri May 26 01:23:42 2006
New Revision: 409585

URL: http://svn.apache.org/viewvc?rev=409585&view=rev
Log:
2006-05-26  Anton Pevtsov  <antonp@moscow.vdiweb.com>

	* 21.string.replace.cpp (test_replace): Updated the expected_throw 
	value calculating mechanism.
	* 21.string.append.cpp (test cases): Changed the meaning of
	(tcase.bthrow == 0) to enable the testing of exception safety,
	and used -1 to disable.
	(Test, MemFun): Removed unused typedefs.
	(test_replace): Renamed throw_after to throw_count to better
	reflect the purpose of the variable
	Set UserAlloc::allocate() to throw bad_alloc analogously to
	operator new.
	Exercised exception safety in each test case by default (i.e.,
	when tcase.bthrow == 0).
	* 21.string.assign.cpp: Same
	* 21.string.insert.cpp: Same
	* 21.string.op.plus.equal.cpp: Same

Modified:
    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/strings/21.string.append.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/strings/21.string.append.cpp?rev=409585&r1=409584&r2=409585&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.append.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.append.cpp Fri May 26 01:23:42 2006
@@ -105,8 +105,6 @@
     TEST ("\0\0abc",    0,            "\0\0abc",              0),
     TEST ("abc\0\0",    0,            "abc\0\0abc",           0),
 
-    TEST ("",           "x@4096",     "x@4096",              -1),
-
     TEST ("last",       "test",       "lasttest",             0)
 };
 
@@ -169,8 +167,6 @@
     TEST ("\0\0abc",    0,            "\0\0abc\0\0abc",       0),
     TEST ("abc\0\0",    0,            "abc\0\0abc\0\0",       0),
 
-    TEST ("",           "x@4096",     "x@4096",              -1),
-
     TEST ("last",       "test",       "lasttest",             0)
 };
 
@@ -236,8 +232,6 @@
     TEST ("",          "x@4096", 4096,  "x@4096",         0),
     TEST ("x@4096",    "",          0,  "x@4096",         0),
 
-    TEST ("",          "x@4096", 4096,  "x@4096",        -1),
-
     TEST ("last",      "test",      4, "lasttest",        0)
 };
 
@@ -322,8 +316,6 @@
     TEST ("",          "a",         2, 0,  "",                1),
     TEST ("",          "x@4096", 4106, 0,  "",                1),
 
-    TEST ("x@4096",    0,           0, 0,  "x@4096",         -1),
-
     TEST ("last",      "test",      0, 4, "lasttest",         0)
 };
 
@@ -383,8 +375,6 @@
     TEST ("",       4096, 'x', "x@4096",           0),
     TEST ("x@4096",    0, 'x', "x@4096",           0),
 
-    TEST ("",       4096, 'x', "x@4096",          -1),
-
     TEST ("last",      4, 't', "lasttttt",         0)
 };
 
@@ -599,12 +589,13 @@
         total_length_calls = rg_calls [UTMemFun::length];
 
     rwt_free_store* const pst = rwt_get_free_store (0);
+    SharedAlloc*    const pal = SharedAlloc::instance ();
 
     // 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) {
+    std::size_t throw_count;
+    for (throw_count = 0; ; ++throw_count) {
 
         // (name of) expected and caught exception
         const char* expected = 0;
@@ -616,9 +607,17 @@
             expected = exceptions [1];   // out_of_range
         else if (2 == tcase.bthrow)
             expected = exceptions [2];   // length_error
-        else if (-1 == tcase.bthrow) {
-            expected = exceptions [3];   // bad_alloc
-            *pst->throw_at_calls_ [0] = pst->new_calls_ [0] + throw_after + 1;
+        else if (0 == tcase.bthrow) {
+            // by default excercise the exception safety of the function
+            // by iteratively inducing an exception at each call to operator
+            // new or Allocator::allocate() until the call succeeds
+            expected = exceptions [3];      // bad_alloc
+            *pst->throw_at_calls_ [0] = pst->new_calls_ [0] + throw_count + 1;
+            pal->throw_at_calls_ [pal->m_allocate] =
+                pal->throw_at_calls_ [pal->m_allocate] + throw_count + 1;
+        }
+        else {
+            // exceptions disabled for this test case
         }
 
 #else   // if defined (_RWSTD_NO_EXCEPTIONS)
@@ -635,6 +634,9 @@
         // pointer to the returned reference
         const String* ret_ptr = 0;
 
+        // start checking for memory leaks
+        rw_check_leaks (str.get_allocator ());
+
         try {
 
             switch (func.which_) {
@@ -729,7 +731,7 @@
         }
         catch (const std::bad_alloc &ex) {
             caught = exceptions [3];
-            rw_assert (-1 == tcase.bthrow, 0, tcase.line,
+            rw_assert (0 == tcase.bthrow, 0, tcase.line,
                        "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
                        "unexpectedly%{;} caught std::%s(%#s)",
                        __LINE__, 0 != expected, expected, caught, ex.what ());
@@ -751,20 +753,25 @@
 
 #endif   // _RWSTD_NO_EXCEPTIONS
 
+        // FIXME: verify the number of blocks the function call
+        // is expected to allocate and detect any memory leaks
+        rw_check_leaks (str.get_allocator (), tcase.line,
+                        std::size_t (-1), std::size_t (-1));
+
         if (caught) {
             // verify that an exception thrown during allocation
             // didn't cause a change in the state of the object
             str_state.assert_equal (rw_get_string_state (str),
                                     __LINE__, tcase.line, caught);
 
-            if (-1 == tcase.bthrow) {
+            if (0 == tcase.bthrow) {
                 // 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;
             }
         }
-        else if (-1 != tcase.bthrow) {
+        else if (0 < tcase.bthrow) {
             rw_assert (caught == expected, 0, tcase.line,
                        "line %d. %{$FUNCALL} %{?}expected %s, caught %s"
                        "%{:}unexpectedly caught %s%{;}",
@@ -778,15 +785,25 @@
 
     // verify that if exceptions are enabled and when capacity changes
     // at least one exception is thrown
-    rw_assert (   *pst->throw_at_calls_ [0] == std::size_t (-1)
-               || throw_after,
-               0, tcase.line,
-               "line %d: %{$FUNCALL}: failed to throw an expected exception",
-               __LINE__);
+    const std::size_t expect_throws = str_state.capacity_ < str.capacity ();
+
+#else   // if defined (_RWSTD_NO_REPLACEABLE_NEW_DELETE)
+
+    const std::size_t expect_throws = 
+        (StringIds::UserAlloc == func.alloc_id_) 
+      ? str_state.capacity_ < str.capacity (): 0;
 
 #endif   // _RWSTD_NO_REPLACEABLE_NEW_DELETE
 
-    *pst->throw_at_calls_ [0] = std::size_t (-1);
+    rw_assert (expect_throws == throw_count, 0, tcase.line,
+               "line %d: %{$FUNCALL}: expected exactly 1 %s exception "
+               "while changing capacity from %zu to %zu, got %zu",
+               __LINE__, exceptions [3],
+               str_state.capacity_, str.capacity (), throw_count);
+
+    // disable bad_alloc exceptions
+    *pst->throw_at_calls_ [0] = 0;
+    pal->throw_at_calls_ [pal->m_allocate] = 0;
 
     if (wres != wres_buf)
         delete[] wres;

Modified: incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp?rev=409585&r1=409584&r2=409585&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp Fri May 26 01:23:42 2006
@@ -99,8 +99,6 @@
     TEST ("abc\0\0",    0,            "abc",           0),
     TEST ("x@4096",     0,            "x@4096",        0),
 
-    TEST ("",           "x@4096",     "x@4096",       -1),
-
     TEST ("last",       "test",       "test",          0)
 };
 
@@ -236,7 +234,6 @@
     TEST ("a@4096",    "b@4096", 2048,  "b@2048",     0),
 
     TEST ("",          "",         -1,  "",           2),
-    TEST ("",          "x@4096", 4096,  "x@4096",    -1),
 
     TEST ("last",      "test",      4, "test",        0)
 };
@@ -325,8 +322,6 @@
     TEST ("",          "a",         2, 0,  "",           1),
     TEST ("",          "x@4096", 4106, 0,  "",           1),
 
-    TEST ("",          "x@4096",    0, 4096, "x@4096",  -1),
-
     TEST ("last",      "test",      0, 4, "test",        0)
 };
 
@@ -383,7 +378,6 @@
     TEST ("x@4096",    0, 'x',  "",             0),
 
     TEST ("",         -1, 'x',  "",             2),
-    TEST ("",       4096, 'x',  "x@4096",      -1),
 
     TEST ("last",      4, 't',  "tttt",         0)
 };
@@ -562,12 +556,13 @@
         total_length_calls = rg_calls [UTMemFun::length];
 
     rwt_free_store* const pst = rwt_get_free_store (0);
+    SharedAlloc*    const pal = SharedAlloc::instance ();
 
     // 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) {
+    std::size_t throw_count;
+    for (throw_count = 0; ; ++throw_count) {
 
         // (name of) expected and caught exception
         const char* expected = 0;
@@ -579,9 +574,17 @@
             expected = exceptions [1];   // out_of_range
         else if (2 == tcase.bthrow)
             expected = exceptions [2];   // length_error
-        else if (-1 == tcase.bthrow) {
-            expected = exceptions [3];   // bad_alloc
-            *pst->throw_at_calls_ [0] = pst->new_calls_ [0] + throw_after + 1;
+        else if (0 == tcase.bthrow) {
+            // by default excercise the exception safety of the function
+            // by iteratively inducing an exception at each call to operator
+            // new or Allocator::allocate() until the call succeeds
+            expected = exceptions [3];      // bad_alloc
+            *pst->throw_at_calls_ [0] = pst->new_calls_ [0] + throw_count + 1;
+            pal->throw_at_calls_ [pal->m_allocate] =
+                pal->throw_at_calls_ [pal->m_allocate] + throw_count + 1;
+        }
+        else {
+            // exceptions disabled for this test case
         }
 
 #else   // if defined (_RWSTD_NO_EXCEPTIONS)
@@ -598,6 +601,9 @@
         // pointer to the returned reference
         const String* ret_ptr = 0;
 
+        // start checking for memory leaks
+        rw_check_leaks (str.get_allocator ());
+
         try {
             switch (func.which_) {
 
@@ -688,7 +694,7 @@
         }
         catch (const std::bad_alloc &ex) {
             caught = exceptions [3];
-            rw_assert (-1 == tcase.bthrow, 0, tcase.line,
+            rw_assert (0 == tcase.bthrow, 0, tcase.line,
                        "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
                        "unexpectedly%{;} caught std::%s(%#s)",
                        __LINE__, 0 != expected, expected, caught, ex.what ());
@@ -710,20 +716,25 @@
 
 #endif   // _RWSTD_NO_EXCEPTIONS
 
+        // FIXME: verify the number of blocks the function call
+        // is expected to allocate and detect any memory leaks
+        rw_check_leaks (str.get_allocator (), tcase.line,
+                        std::size_t (-1), std::size_t (-1));
+
         if (caught) {
             // verify that an exception thrown during allocation
             // didn't cause a change in the state of the object
             str_state.assert_equal (rw_get_string_state (str),
                                     __LINE__, tcase.line, caught);
 
-            if (-1 == tcase.bthrow) {
+            if (0 == tcase.bthrow) {
                 // 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;
             }
         }
-        else if (-1 != tcase.bthrow) {
+        else if (0 < tcase.bthrow) {
             rw_assert (caught == expected, 0, tcase.line,
                        "line %d. %{$FUNCALL} %{?}expected %s, caught %s"
                        "%{:}unexpectedly caught %s%{;}",
@@ -733,24 +744,42 @@
         break;
     }
 
-#ifndef _RWSTD_NO_EXCEPTIONS
-#  ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
+    std::size_t expect_throws = 0;
+
+#ifndef _RWSTD_NO_STRING_REF_COUNT
+    if (Assign (cstr) != func.which_) {
+#endif
+
+#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
 
     // verify that if exceptions are enabled and when capacity changes
     // at least one exception is thrown
-    rw_assert (   *pst->throw_at_calls_ [0] == std::size_t (-1)
-               || throw_after,
-               0, tcase.line,
-               "line %d: %{$FUNCALL}: failed to throw an expected exception",
-               __LINE__);
+    expect_throws = str_state.capacity_ < str.capacity ();
 
-#  endif   // _RWSTD_NO_REPLACEABLE_NEW_DELETE
-#endif   // _RWSTD_NO_EXCEPTIONS
+#else   // if defined (_RWSTD_NO_REPLACEABLE_NEW_DELETE)
 
-    *pst->throw_at_calls_ [0] = std::size_t (-1);
+    expect_throws = (StringIds::UserAlloc == func.alloc_id_) 
+        ? str_state.capacity_ < str.capacity (): 0;
+
+#endif   // _RWSTD_NO_REPLACEABLE_NEW_DELETE
+
+#ifndef _RWSTD_NO_STRING_REF_COUNT
+    }
+#endif
+
+    rw_assert (expect_throws == throw_count, 0, tcase.line,
+               "line %d: %{$FUNCALL}: expected exactly 1 %s exception "
+               "while changing capacity from %zu to %zu, got %zu",
+               __LINE__, exceptions [3],
+               str_state.capacity_, str.capacity (), throw_count);
+
+    // disable bad_alloc exceptions
+    *pst->throw_at_calls_ [0] = 0;
+    pal->throw_at_calls_ [pal->m_allocate] = 0;
 
     if (wres != wres_buf)
         delete[] wres;
+
 }
 
 /**************************************************************************/

Modified: incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp?rev=409585&r1=409584&r2=409585&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp Fri May 26 01:23:42 2006
@@ -113,8 +113,6 @@
     TEST ("a",         2, "",         "",                   1),
     TEST ("x@4096", 4106, "",         "",                   1),
 
-    TEST ("",          0, "x@4096",   "x@4096",            -1),
-
     TEST ("last",      4, "test",     "lasttest",           0)
 };
 
@@ -184,8 +182,6 @@
     TEST ("a",         2, "",         "",                   1),
     TEST ("x@4096", 4106, "",         "",                   1),
 
-    TEST ("",          0, "x@4096",   "x@4096",            -1),
-
     TEST ("last",      4, "test",     "lasttest",           0)
 };
 
@@ -279,8 +275,6 @@
     TEST ("x@4096", 4106, "",          0, 0,  "",                1),
     TEST ("",          0, "x@4096", 4106, 0,  "",                2),
 
-    TEST ("",          0, "x@4096",    0, 4096, "x@4096",       -1),
-
     TEST ("last",      4, "test",      0, 4,  "lasttest",        0)
 };
 
@@ -357,8 +351,6 @@
     TEST ("a",         2, "",          0,  "",               1),
     TEST ("x@4096", 4106, "",          0,  "",               1),
 
-    TEST ("",          0, "x@4096", 4095,  "x@4095",        -1),
-
     TEST ("last",      4, "test",      4,  "lasttest",       0)
 };
 
@@ -432,8 +424,6 @@
     TEST ("x@4096",    0, 2047, 'b', "b@2047x@4096",  0),
     TEST ("x@4096", 2047, 2048, 'x', "x@6144",        0),
 
-    TEST ("",          0, 4106, 'x', "x@4106",       -1),
-
     TEST ("last",      4, 4, 't',  "lasttttt",        0)
 };
 
@@ -484,8 +474,6 @@
     TEST ("x@4096",    1,  'a',  "xax@4095",    0),
     TEST ("x@4096",    1, '\0',  "x\0x@4095",   0),
 
-    TEST ("x@4095",    0,  'x', "x@4096",      -1),
-
     TEST ("last",      4,  't', "lastt",        0)
 };
 
@@ -674,12 +662,13 @@
         total_length_calls = rg_calls [UTMemFun::length];
 
     rwt_free_store* const pst = rwt_get_free_store (0);
+    SharedAlloc*    const pal = SharedAlloc::instance ();
 
     // 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) {
+    std::size_t throw_count;
+    for (throw_count = 0; ; ++throw_count) {
 
         // (name of) expected and caught exception
         const char* expected = 0;
@@ -697,9 +686,17 @@
             expected = exceptions [1];      // out_of_range
         else if (3 == tcase.bthrow && !use_iters)
             expected = exceptions [2];      // length_error
-        else if (-1 == tcase.bthrow) {
+        else if (0 == tcase.bthrow) {
+            // by default excercise the exception safety of the function
+            // by iteratively inducing an exception at each call to operator
+            // new or Allocator::allocate() until the call succeeds
             expected = exceptions [3];      // bad_alloc
-            *pst->throw_at_calls_ [0] = pst->new_calls_ [0] + throw_after + 1;
+            *pst->throw_at_calls_ [0] = pst->new_calls_ [0] + throw_count + 1;
+            pal->throw_at_calls_ [pal->m_allocate] =
+                pal->throw_at_calls_ [pal->m_allocate] + throw_count + 1;
+        }
+        else {
+            // exceptions disabled for this test case
         }
 
 #else   // if defined (_RWSTD_NO_EXCEPTIONS)
@@ -716,6 +713,9 @@
         // pointer to the returned reference
         const String* ret_ptr = 0;
 
+        // start checking for memory leaks
+        rw_check_leaks (str.get_allocator ());
+
         try {
             switch (func.which_) {
 
@@ -823,7 +823,7 @@
         }
         catch (const std::bad_alloc &ex) {
             caught = exceptions [3];
-            rw_assert (-1 == tcase.bthrow, 0, tcase.line,
+            rw_assert (0 == tcase.bthrow, 0, tcase.line,
                        "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
                        "unexpectedly%{;} caught std::%s(%#s)",
                        __LINE__, 0 != expected, expected, caught, ex.what ());
@@ -845,20 +845,25 @@
 
 #endif   // _RWSTD_NO_EXCEPTIONS
 
+        // FIXME: verify the number of blocks the function call
+        // is expected to allocate and detect any memory leaks
+        rw_check_leaks (str.get_allocator (), tcase.line,
+                        std::size_t (-1), std::size_t (-1));
+
         if (caught) {
             // verify that an exception thrown during allocation
             // didn't cause a change in the state of the object
             str_state.assert_equal (rw_get_string_state (str),
                                     __LINE__, tcase.line, caught);
 
-            if (-1 == tcase.bthrow) {
+            if (0 == tcase.bthrow) {
                 // 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;
             }
         }
-        else if (-1 != tcase.bthrow) {
+        else if (0 < tcase.bthrow) {
             rw_assert (caught == expected, 0, tcase.line,
                        "line %d. %{$FUNCALL} %{?}expected %s, caught %s"
                        "%{:}unexpectedly caught %s%{;}",
@@ -872,15 +877,25 @@
 
     // verify that if exceptions are enabled and when capacity changes
     // at least one exception is thrown
-    rw_assert (   *pst->throw_at_calls_ [0] == std::size_t (-1)
-               || throw_after,
-               0, tcase.line,
-               "line %d: %{$FUNCALL}: failed to throw an expected exception",
-               __LINE__);
+    const std::size_t expect_throws = str_state.capacity_ < str.capacity ();
+
+#else   // if defined (_RWSTD_NO_REPLACEABLE_NEW_DELETE)
+
+    const std::size_t expect_throws = 
+        (StringIds::UserAlloc == func.alloc_id_) 
+      ? str_state.capacity_ < str.capacity (): 0;
 
 #endif   // _RWSTD_NO_REPLACEABLE_NEW_DELETE
 
-    *pst->throw_at_calls_ [0] = std::size_t (-1);
+    rw_assert (expect_throws == throw_count, 0, tcase.line,
+               "line %d: %{$FUNCALL}: expected exactly 1 %s exception "
+               "while changing capacity from %zu to %zu, got %zu",
+               __LINE__, exceptions [3],
+               str_state.capacity_, str.capacity (), throw_count);
+
+    // disable bad_alloc exceptions
+    *pst->throw_at_calls_ [0] = 0;
+    pal->throw_at_calls_ [pal->m_allocate] = 0;
 
     if (wres != wres_buf)
         delete[] wres;

Modified: incubator/stdcxx/trunk/tests/strings/21.string.op.plus.equal.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/strings/21.string.op.plus.equal.cpp?rev=409585&r1=409584&r2=409585&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 Fri May 26 01:23:42 2006
@@ -65,7 +65,6 @@
     //    |             |             |        +---- exception info
     //    |             |             |        |         0 - no exception
     //    |             |             |        |         1 - length_error
-    //    |             |             |        |        -1 - exc. safety
     //    |             |             |        |
     //    |             |             |        +--------------+
     //    V             V             V                       V
@@ -103,8 +102,6 @@
     TEST ("abc\0\0",    0,            "abc\0\0abc",           0),
     TEST ("x@2048",     0,            "x@4096",               0),
 
-    TEST ("",           "x@4096",     "x@4096",              -1),
-
     TEST ("last",       "test",       "lasttest",             0)
 };
 
@@ -126,7 +123,6 @@
     //    |             |             |        +---- exception info
     //    |             |             |        |         0 - no exception
     //    |             |             |        |         1 - length_error
-    //    |             |             |        |        -1 - exc. safety
     //    |             |             |        |
     //    |             |             |        +--------------+
     //    V             V             V                       V
@@ -165,8 +161,6 @@
     TEST ("abc\0\0",    0,            "abc\0\0abc\0\0",       0),
     TEST ("x@2048",     0,            "x@4096",               0),
 
-    TEST ("",           "x@4096",     "x@4096",              -1),
-
     TEST ("last",       "test",       "lasttest",             0)
 };
 
@@ -188,7 +182,6 @@
     //    |            |   |           +----- exception info
     //    |            |   |           |        0 - no exception
     //    |            |   |           |        1 - length_error
-    //    |            |   |           |       -1 - exc. safety
     //    |            |   |           |
     //    |            |   |           +----+
     //    V            V   V                V
@@ -267,12 +260,13 @@
         total_length_calls = rg_calls [UTMemFun::length];
 
     rwt_free_store* const pst = rwt_get_free_store (0);
+    SharedAlloc*    const pal = SharedAlloc::instance ();
 
     // 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) {
+    std::size_t throw_count;
+    for (throw_count = 0; ; ++throw_count) {
 
         // (name of) expected and caught exception
         const char* expected = 0;
@@ -282,9 +276,17 @@
 
         if (1 == tcase.bthrow)
             expected = exceptions [2];      // length_error
-        else if (-1 == tcase.bthrow) {
+        else if (0 == tcase.bthrow) {
+            // by default excercise the exception safety of the function
+            // by iteratively inducing an exception at each call to operator
+            // new or Allocator::allocate() until the call succeeds
             expected = exceptions [3];      // bad_alloc
-            *pst->throw_at_calls_ [0] = pst->new_calls_ [0] + throw_after + 1;
+            *pst->throw_at_calls_ [0] = pst->new_calls_ [0] + throw_count + 1;
+            pal->throw_at_calls_ [pal->m_allocate] =
+                pal->throw_at_calls_ [pal->m_allocate] + throw_count + 1;
+        }
+        else {
+            // exceptions disabled for this test case
         }
 
 #else   // if defined (_RWSTD_NO_EXCEPTIONS)
@@ -298,6 +300,9 @@
 
 #endif   // _RWSTD_NO_EXCEPTIONS
 
+        // start checking for memory leaks
+        rw_check_leaks (str.get_allocator ());
+
         try {
 
             // pointer to the returned reference
@@ -376,7 +381,7 @@
         }
         catch (const std::bad_alloc &ex) {
             caught = exceptions [3];
-            rw_assert (-1 == tcase.bthrow, 0, tcase.line,
+            rw_assert (0 == tcase.bthrow, 0, tcase.line,
                        "line %d. %{$FUNCALL} %{?}expected %s,%{:}"
                        "unexpectedly%{;} caught std::%s(%#s)",
                        __LINE__, 0 != expected, expected, caught, ex.what ());
@@ -398,20 +403,25 @@
 
 #endif   // _RWSTD_NO_EXCEPTIONS
 
+        // FIXME: verify the number of blocks the function call
+        // is expected to allocate and detect any memory leaks
+        rw_check_leaks (str.get_allocator (), tcase.line,
+                        std::size_t (-1), std::size_t (-1));
+
         if (caught) {
             // verify that an exception thrown during allocation
             // didn't cause a change in the state of the object
             str_state.assert_equal (rw_get_string_state (str),
                                     __LINE__, tcase.line, caught);
 
-            if (-1 == tcase.bthrow) {
+            if (0 == tcase.bthrow) {
                 // 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;
             }
         }
-        else if (-1 != tcase.bthrow) {
+        else if (0 < tcase.bthrow) {
             rw_assert (caught == expected, 0, tcase.line,
                        "line %d. %{$FUNCALL} %{?}expected %s, caught %s"
                        "%{:}unexpectedly caught %s%{;}",
@@ -425,15 +435,25 @@
 
     // verify that if exceptions are enabled and when capacity changes
     // at least one exception is thrown
-    rw_assert (   *pst->throw_at_calls_ [0] == std::size_t (-1)
-               || throw_after,
-               0, tcase.line,
-               "line %d: %{$FUNCALL}: failed to throw an expected exception",
-               __LINE__);
+    const std::size_t expect_throws = str_state.capacity_ < str.capacity ();
+
+#else   // if defined (_RWSTD_NO_REPLACEABLE_NEW_DELETE)
+
+    const std::size_t expect_throws = 
+        (StringIds::UserAlloc == func.alloc_id_) 
+      ? str_state.capacity_ < str.capacity (): 0;
 
 #endif   // _RWSTD_NO_REPLACEABLE_NEW_DELETE
 
-    *pst->throw_at_calls_ [0] = std::size_t (-1);
+    rw_assert (expect_throws == throw_count, 0, tcase.line,
+               "line %d: %{$FUNCALL}: expected exactly 1 %s exception "
+               "while changing capacity from %zu to %zu, got %zu",
+               __LINE__, exceptions [3],
+               str_state.capacity_, str.capacity (), throw_count);
+
+    // disable bad_alloc exceptions
+    *pst->throw_at_calls_ [0] = 0;
+    pal->throw_at_calls_ [pal->m_allocate] = 0;
 
     if (wres != wres_buf)
         delete[] wres;

Modified: incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp?rev=409585&r1=409584&r2=409585&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp Fri May 26 01:23:42 2006
@@ -1094,7 +1094,9 @@
 
 #else   // if defined (_RWSTD_NO_REPLACEABLE_NEW_DELETE)
 
-    const std::size_t expect_throws = 0;
+    const std::size_t expect_throws = 
+        (StringIds::UserAlloc == func.alloc_id_) 
+      ? str_state.capacity_ < str.capacity (): 0;
 
 #endif   // _RWSTD_NO_REPLACEABLE_NEW_DELETE
 



Mime
View raw message