stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r396720 [1/2] - in /incubator/stdcxx/trunk/tests: include/21.strings.h strings/21.string.append.cpp strings/21.string.assign.cpp strings/21.string.insert.cpp strings/21.string.replace.cpp
Date Mon, 24 Apr 2006 23:22:33 GMT
Author: sebor
Date: Mon Apr 24 16:22:31 2006
New Revision: 396720

URL: http://svn.apache.org/viewcvs?rev=396720&view=rev
Log:
2006-04-24  Martin Sebor  <sebor@roguewave.com>

	* 21.strings.h (DEFINE_TEST_DISPATCH): New helper macro
	to define the same boilerplate "test dispatch" function
	in each test.
	* 21.string.append.cpp (DEFINE_TEST_DISPATCH): Used and
	simplified.
	Renamed the cs function argument to tcase (for test case)
	for clarity.
	(<memory>): Removed the inclusion of an unneeded header.
	* 21.string.assign.cpp: Same.
	* 21.string.insert.cpp: Same.
	* 21.string.replace.cpp: Same.

Modified:
    incubator/stdcxx/trunk/tests/include/21.strings.h
    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.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=396720&r1=396719&r2=396720&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/include/21.strings.h (original)
+++ incubator/stdcxx/trunk/tests/include/21.strings.h Mon Apr 24 16:22:31 2006
@@ -271,4 +271,54 @@
 #define Disabled(which)   \
     StringMembers::opt_memfun_disabled [which & ~StringMembers::mem_mask]
 
+#ifndef _RWSTD_NO_WCHAR_T
+#  define TEST_DISPATCH(fname, memfun, tcase)                   \
+    if (StringMembers::DefaultTraits == memfun.traits_id_) {    \
+        if (StringMembers::Char == memfun.char_id_)             \
+            fname (char (), (std::char_traits<char>*)0,         \
+                   memfun.which_, tcase);                       \
+        else                                                    \
+            fname (wchar_t (), (std::char_traits<wchar_t>*)0,   \
+                   memfun.which_, tcase);                       \
+    }                                                           \
+    else {                                                      \
+       if (StringMembers::Char == memfun.char_id_)              \
+           fname (char (), (UserTraits<char>*)0,                \
+                  memfun.which_, tcase);                        \
+       else if (StringMembers::WChar == memfun.char_id_)        \
+           fname (wchar_t (), (UserTraits<wchar_t>*)0,          \
+                  memfun.which_, tcase);                        \
+       else                                                     \
+           fname (UserChar (), (UserTraits<UserChar>*)0,        \
+                  memfun.which_, tcase);                        \
+    }                                                           \
+    (void)0
+
+#else   // if defined (_RWSTD_NO_WCHAR_T)
+#  define TEST_DISPATCH(fname, memfun, tcase)                   \
+    if (StringMembers::DefaultTraits == memfun.traits_id_) {    \
+        if (StringMembers::Char == memfun.char_id_)             \
+            fname (char (), (std::char_traits<char>*)0,         \
+                   memfun.which_, tcase);                       \
+    }                                                           \
+    else {                                                      \
+       if (StringMembers::Char == memfun.char_id_)              \
+           fname (char (), (UserTraits<char>*)0,                \
+                  memfun.which_, tcase);                        \
+       else if (StringMembers::UChar == memfun.char_id_)        \
+           fname (UserChar (), (UserTraits<UserChar>*)0,        \
+                  memfun.which_, tcase);                        \
+    }                                                           \
+    (void)0
+
+#endif   // _RWSTD_NO_WCHAR_T
+
+
+#define DEFINE_TEST_DISPATCH(fname)                             \
+    static void                                                 \
+    fname (const MemFun &memfun, const TestCase &tcase) {       \
+        TEST_DISPATCH (fname, memfun, tcase);                   \
+    } typedef void rw_unused_typedef
+    
+
 #endif   // RW_21_STRINGS_H_INCLUDED

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=396720&r1=396719&r2=396720&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.append.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.append.cpp Mon Apr 24 16:22:31 2006
@@ -25,17 +25,16 @@
  *
  **************************************************************************/
 
-#include <memory>       // for placement operator new()
 #include <string>       // for string
-#include <cstdlib>      // for free(), size_t
 #include <stdexcept>    // for out_of_range, length_error
 
+#include <cstddef>      // for size_t
+
+#include <alg_test.h>   // for InputIter<>
 #include <cmdopt.h>     // for rw_enabled()
 #include <driver.h>     // for rw_test()
-
-#include <rw_printf.h>  // for rw_asnprintf()
 #include <rw_char.h>    // for rw_widen()
-#include <alg_test.h>   // for InputIter<>
+#include <rw_printf.h>  // for rw_asnprintf()
 
 #include <21.strings.h>
 
@@ -403,7 +402,7 @@
 template <class charT, class Traits>
 void test_exceptions (charT, Traits*,
                       AppendOverload  which,
-                      const TestCase &cs)
+                      const TestCase &tcase)
 {
     typedef std::basic_string <charT, Traits,
                                std::allocator<charT> > TestString;
@@ -413,11 +412,11 @@
     static charT wstr [LLEN];
     static charT wsrc [LLEN];
 
-    rw_widen (wstr, cs.str, cs.str_len);
-    rw_widen (wsrc, cs.arg, cs.arg_len);
+    rw_widen (wstr, tcase.str, tcase.str_len);
+    rw_widen (wsrc, tcase.arg, tcase.arg_len);
 
-    TestString s_str (wstr, cs.str_len);
-    TestString s_arg (wsrc, cs.arg_len);
+    TestString s_str (wstr, tcase.str_len);
+    TestString s_arg (wsrc, tcase.arg_len);
 
     std::size_t throw_after = 0;
 
@@ -446,19 +445,19 @@
 
         _TRY {
             if (Append (ptr) == which)
-                s_str.append (cs.arg ? wsrc : s_str.c_str ());
+                s_str.append (tcase.arg ? wsrc : s_str.c_str ());
 
             else if (Append (str) == which)
-                s_str.append (cs.arg ? s_arg : s_str);
+                s_str.append (tcase.arg ? s_arg : s_str);
 
             else if (Append (ptr_size) == which)
-                s_str.append (cs.arg ? wsrc : s_str.c_str (), cs.size);
+                s_str.append (tcase.arg ? wsrc : s_str.c_str (), tcase.size);
 
             else if (Append (str_size_size) == which)
-                s_str.append (cs.arg ? s_arg : s_str, cs.off, cs.size);
+                s_str.append (tcase.arg ? s_arg : s_str, tcase.off, tcase.size);
 
             else if (Append (size_val) == which)
-                s_str.append (cs.size, make_char (char (cs.val), (charT*)0));
+                s_str.append (tcase.size, make_char (char (tcase.val), (charT*)0));
 
             else if (Append (range) == which)
                 s_str.append (s_arg.begin (), s_arg.end ());
@@ -472,18 +471,18 @@
             // verify that an exception thrown during allocation
             // doesn't cause a change in the state of the vector
 
-            rw_assert (s_str.size () == size, 0, cs.line,
+            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, cs.line,
+            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, cs.line,
+            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);
@@ -505,7 +504,7 @@
     // at least one exception is thrown
     rw_assert (   *pst->throw_at_calls_ [0] == std::size_t (-1)
                || throw_after,
-               0, cs.line,
+               0, tcase.line,
                "line %d: %{$FUNCALL}: failed to throw an expected exception",
                __LINE__);
 
@@ -528,36 +527,36 @@
 /**************************************************************************/
 
 template <class charT, class Traits, class Iterator>
-void test_append_range (charT* wstr,
-                        charT* wsrc,
+void test_append_range (charT          *wstr,
+                        charT          *wsrc,
                         Traits*,
                         const Iterator &it,
-                        const TestCase &cs)
+                        const TestCase &tcase)
 {
     typedef std::basic_string <charT, Traits,
                                std::allocator<charT> > String;
     typedef typename String::iterator StringIter;
 
     const char* const itname =
-        cs.arg ? type_name (it, (charT*)0) : "basic_string::iterator";
+        tcase.arg ? type_name (it, (charT*)0) : "basic_string::iterator";
 
-    String s_str (wstr, cs.str_len);
-    String s_arg (wsrc, cs.arg_len);
+    String s_str (wstr, tcase.str_len);
+    String s_arg (wsrc, tcase.arg_len);
 
-    std::size_t off_last = cs.off + cs.size;
+    std::size_t off_last = tcase.off + tcase.size;
 
-    if (cs.arg) {
+    if (tcase.arg) {
         off_last = off_last > s_arg.size () ? s_arg.size () : off_last;
 
-        const Iterator first = make_iter (wsrc + cs.off,
-            wsrc + cs.off, wsrc + off_last, Iterator (0, 0, 0));
+        const Iterator first = make_iter (wsrc + tcase.off,
+            wsrc + tcase.off, wsrc + off_last, Iterator (0, 0, 0));
         const Iterator last  = make_iter (wsrc + off_last,
-            wsrc + cs.off, wsrc + off_last, Iterator (0, 0, 0));
+            wsrc + tcase.off, wsrc + off_last, Iterator (0, 0, 0));
 
         s_str.append (first, last);
     }
     else {
-        StringIter first (s_str.begin () + cs.off);
+        StringIter first (s_str.begin () + tcase.off);
         StringIter last  (off_last > s_str.size () ?
             s_str.end ()
           : s_str.begin () + off_last);
@@ -565,12 +564,12 @@
         s_str.append (first, last);
     }
 
-    const std::size_t match = rw_match (cs.res, s_str.c_str(), cs.res_len);
+    const std::size_t match = rw_match (tcase.res, s_str.c_str(), tcase.res_len);
 
-    rw_assert (match == cs.res_len, 0, cs.line,
+    rw_assert (match == tcase.res_len, 0, tcase.line,
                "line %d. %{$FUNCALL} expected %{#*s}, got %{/*.*Gs}, "
                "difference at off %zu for %s",
-               __LINE__, int (cs.res_len), cs.res,
+               __LINE__, int (tcase.res_len), tcase.res,
                int (sizeof (charT)), int (s_str.size ()), s_str.c_str (),
                match, itname);
 }
@@ -581,27 +580,27 @@
 void test_append_range (charT* wstr,
                         charT* wsrc,
                         Traits*,
-                        const TestCase &cs)
+                        const TestCase &tcase)
 {
-    if (cs.bthrow)  // this method doesn't throw
+    if (tcase.bthrow)  // this method doesn't throw
         return;
 
     test_append_range (wstr, wsrc, (Traits*)0,
-                       InputIter<charT>(0, 0, 0), cs);
+                       InputIter<charT>(0, 0, 0), tcase);
 
     // there is no need to call test_append_range
     // for other iterators in this case
-    if (0 == cs.arg)
+    if (0 == tcase.arg)
         return;
 
     test_append_range (wstr, wsrc, (Traits*)0,
-                       ConstFwdIter<charT>(0, 0, 0), cs);
+                       ConstFwdIter<charT>(0, 0, 0), tcase);
 
     test_append_range (wstr, wsrc, (Traits*)0,
-                       ConstBidirIter<charT>(0, 0, 0), cs);
+                       ConstBidirIter<charT>(0, 0, 0), tcase);
 
     test_append_range (wstr, wsrc, (Traits*)0,
-                       ConstRandomAccessIter<charT>(0, 0, 0), cs);
+                       ConstRandomAccessIter<charT>(0, 0, 0), tcase);
 }
 
 /**************************************************************************/
@@ -609,26 +608,31 @@
 template <class charT, class Traits>
 void test_append (charT, Traits*,
                   AppendOverload  which,
-                  const TestCase &cs)
+                  const TestCase &tcase)
 {
-    typedef std::basic_string <charT, Traits,
-                               std::allocator<charT> > TestString;
-    typedef typename TestString::iterator StringIter;
+    typedef std::allocator<charT>                        Allocator;
+    typedef std::basic_string <charT, Traits, Allocator> TestString;
+    typedef typename TestString::iterator                StringIter;
+
+    if (-1 == tcase.bthrow) {
+        test_exceptions (charT (), (Traits*)0, which, tcase);
+        return;
+    }
 
     static charT wstr [LLEN];
     static charT wsrc [LLEN];
 
-    rw_widen (wstr, cs.str, cs.str_len);
-    rw_widen (wsrc, cs.arg, cs.arg_len);
+    rw_widen (wstr, tcase.str, tcase.str_len);
+    rw_widen (wsrc, tcase.arg, tcase.arg_len);
 
     // special processing for append_range to exercise all iterators
     if (Append (range) == which) {
-        test_append_range (wstr, wsrc, (Traits*)0, cs);
+        test_append_range (wstr, wsrc, (Traits*)0, tcase);
         return;
     }
 
-    TestString s_str (wstr, cs.str_len);
-    TestString s_arg (wsrc, cs.arg_len);
+    TestString s_str (wstr, tcase.str_len);
+    TestString s_arg (wsrc, tcase.arg_len);
 
     std::size_t res_off = 0;
 
@@ -636,9 +640,9 @@
 
     // is some exception expected ?
     const char* expected = 0;
-    if (1 == cs.bthrow && Append (str_size_size) == which)
+    if (1 == tcase.bthrow && Append (str_size_size) == which)
         expected = exp_exceptions [1];
-    if (2 == cs.bthrow)
+    if (2 == tcase.bthrow)
         expected = exp_exceptions [2];
 
     const char* caught = 0;
@@ -647,41 +651,41 @@
 
 #else   // if defined (_RWSTD_NO_EXCEPTIONS)
 
-    if (cs.bthrow)
+    if (tcase.bthrow)
         return;
 
 #endif   // _RWSTD_NO_EXCEPTIONS
 
     switch (which) {
     case Append (ptr): {
-        TestString& s_res = s_str.append (cs.arg ? wsrc : s_str.c_str ());
+        TestString& s_res = s_str.append (tcase.arg ? wsrc : s_str.c_str ());
         res_off = &s_res - &s_str;
         break;
     }
 
     case Append (str): {
-        TestString& s_res = s_str.append (cs.arg ? s_arg : s_str);
+        TestString& s_res = s_str.append (tcase.arg ? s_arg : s_str);
         res_off = &s_res - &s_str;
         break;
     }
 
     case Append (ptr_size): {
         TestString& s_res =
-            s_str.append (cs.arg ? wsrc : s_str.c_str (), cs.size);
+            s_str.append (tcase.arg ? wsrc : s_str.c_str (), tcase.size);
         res_off = &s_res - &s_str;
         break;
     }
 
     case Append (str_size_size): {
         TestString& s_res =
-            s_str.append (cs.arg ? s_arg : s_str, cs.off, cs.size);
+            s_str.append (tcase.arg ? s_arg : s_str, tcase.off, tcase.size);
         res_off = &s_res - &s_str;
         break;
     }
 
     case Append (size_val): {
         TestString& s_res =
-            s_str.append (cs.size, make_char (char (cs.val), (charT*)0));
+            s_str.append (tcase.size, make_char (char (tcase.val), (charT*)0));
         res_off = &s_res - &s_str;
         break;
     }
@@ -691,24 +695,25 @@
     }
 
     // verify the returned value
-    rw_assert (0 == res_off, 0, cs.line,
+    rw_assert (0 == res_off, 0, tcase.line,
                "line %d. %{$FUNCALL} returned invalid reference, offset is %zu",
                __LINE__, res_off);
 
     // verfiy that strings length are equal
-    rw_assert (cs.res_len == s_str.size (), 0, cs.line,
+    rw_assert (tcase.res_len == s_str.size (), 0, tcase.line,
                "line %d. %{$FUNCALL} expected %{#*s} with length %zu, "
-               "got %{/*.*Gs} with length %zu", __LINE__, int (cs.res_len),
-               cs.res, cs.res_len, int (sizeof (charT)), int (s_str.size ()),
-               s_str.c_str (), s_str.size ());
+               "got %{/*.*Gs} with length %zu", __LINE__, int (tcase.res_len),
+               tcase.res, tcase.res_len, int (sizeof (charT)),
+               int (s_str.size ()), s_str.c_str (), s_str.size ());
 
     // verfiy that append results match expected result
-    const std::size_t match = rw_match (cs.res, s_str.c_str(), cs.res_len);
+    const std::size_t match =
+        rw_match (tcase.res, s_str.c_str(), tcase.res_len);
 
-    rw_assert (match == cs.res_len, 0, cs.line,
+    rw_assert (match == tcase.res_len, 0, tcase.line,
                "line %d. %{$FUNCALL} expected %{#*s}, got %{/*.*Gs}, "
                "difference at off %zu",
-               __LINE__, int (cs.res_len), cs.res,
+               __LINE__, int (tcase.res_len), tcase.res,
                int (sizeof (charT)), int (s_str.size ()), s_str.c_str (),
                match);
 
@@ -729,7 +734,7 @@
     _RWSTD_UNUSED (should_throw);
 #endif   // _RWSTD_NO_EXCEPTIONS
 
-    rw_assert (caught == expected, 0, cs.line,
+    rw_assert (caught == expected, 0, tcase.line,
                "line %d. %{$FUNCALL} %{?}expected %s, caught %s"
                "%{:}unexpectedly caught %s%{;}",
                __LINE__, 0 != expected, expected, caught, caught);
@@ -737,43 +742,7 @@
 
 /**************************************************************************/
 
-static void
-test_append (const MemFun &memfun, const TestCase& tcase)
-{
-    // exercise exception safety?
-    const bool exception_safety = -1 == tcase.bthrow;
-
-#undef TEST
-#define TEST(charT, Traits)                                             \
-    exception_safety ?                                                  \
-        test_exceptions (charT (), (Traits*)0, memfun.which_, tcase)    \
-      : test_append (charT (), (Traits*)0, memfun.which_, tcase)
-
-    if (StringMembers::DefaultTraits == memfun.traits_id_) {
-        if (StringMembers::Char == memfun.char_id_)
-            TEST (char, std::char_traits<char>);
-
-#ifndef _RWSTD_NO_WCHAR_T
-    else
-        TEST (wchar_t, std::char_traits<wchar_t>);
-#endif   // _RWSTD_NO_WCHAR_T
-
-    }
-    else {
-       if (StringMembers::Char == memfun.char_id_)
-           TEST (char, UserTraits<char>);
-
-#ifndef _RWSTD_NO_WCHAR_T
-       else if (StringMembers::WChar == memfun.char_id_)
-           TEST (wchar_t, UserTraits<wchar_t>);
-#endif   // _RWSTD_NO_WCHAR_T
-
-       else
-           TEST (UserChar, UserTraits<UserChar>);
-    }
-}
-
-/**************************************************************************/
+DEFINE_TEST_DISPATCH (test_append);
 
 int run_test (int, char*[])
 {

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=396720&r1=396719&r2=396720&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp Mon Apr 24 16:22:31 2006
@@ -27,7 +27,7 @@
 
 #include <memory>       // for placement operator new()
 #include <string>       // for string
-#include <cstdlib>      // for free(), size_t
+#include <cstddef>      // for size_t
 #include <stdexcept>    // for out_of_range, length_error
 
 #include <cmdopt.h>     // for rw_enabled()
@@ -403,7 +403,7 @@
 template <class charT, class Traits>
 void test_exceptions (charT, Traits*,
                       AssignOverload  which,
-                      const TestCase &cs)
+                      const TestCase &tcase)
 {
     typedef std::allocator<charT>                        Allocator;
     typedef std::basic_string <charT, Traits, Allocator> TestString;
@@ -413,11 +413,11 @@
     static charT wstr [LLEN];
     static charT wsrc [LLEN];
 
-    rw_widen (wstr, cs.str, cs.str_len);
-    rw_widen (wsrc, cs.arg, cs.arg_len);
+    rw_widen (wstr, tcase.str, tcase.str_len);
+    rw_widen (wsrc, tcase.arg, tcase.arg_len);
 
-    /* const */ TestString s_str (wstr, cs.str_len);
-    const       TestString s_arg (wsrc, cs.arg_len);
+    /* const */ TestString s_str (wstr, tcase.str_len);
+    const       TestString s_arg (wsrc, tcase.arg_len);
 
     std::size_t throw_after = 0;
 
@@ -431,9 +431,9 @@
 
 #endif   // _RWSTD_NO_REPLACEABLE_NEW_DELETE
 
-    const charT* const arg_ptr = cs.arg ? wsrc : s_str.c_str ();
-    const TestString&  arg_str = cs.arg ? s_arg : s_str;
-    const charT        arg_val = make_char (char (cs.val), (charT*)0);
+    const charT* const arg_ptr = tcase.arg ? wsrc : s_str.c_str ();
+    const TestString&  arg_str = tcase.arg ? s_arg : s_str;
+    const charT        arg_val = make_char (char (tcase.val), (charT*)0);
 
     // iterate for`n=throw_after' starting at the next call to operator
     // new, forcing each call to throw an exception, until the assignion
@@ -459,15 +459,15 @@
                 break;
 
             case Assign (ptr_size):
-                s_str.assign (arg_ptr, cs.size);
+                s_str.assign (arg_ptr, tcase.size);
                 break;
 
             case Assign (str_size_size):
-                s_str.assign (arg_str, cs.off, cs.size);
+                s_str.assign (arg_str, tcase.off, tcase.size);
                 break;
 
             case Assign (size_val):
-                s_str.assign (cs.size, arg_val);
+                s_str.assign (tcase.size, arg_val);
                 break;
 
             case Assign (range): {
@@ -490,18 +490,18 @@
             // verify that an exception thrown during allocation
             // doesn't cause a change in the state of the vector
 
-            rw_assert (s_str.size () == size, 0, cs.line,
+            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, cs.line,
+            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, cs.line,
+            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);
@@ -523,7 +523,7 @@
     // at least one exception is thrown
     rw_assert (   *pst->throw_at_calls_ [0] == std::size_t (-1)
                || throw_after,
-               0, cs.line,
+               0, tcase.line,
                "line %d: %{$FUNCALL}: failed to throw an expected exception",
                __LINE__);
 
@@ -551,31 +551,33 @@
                         charT          *wsrc,
                         Traits*,
                         const Iterator &it,
-                        const TestCase &cs)
+                        const TestCase &tcase)
 {
     typedef std::allocator<charT>                        Allocator;
     typedef std::basic_string <charT, Traits, Allocator> String;
 
     const char* const itname =
-        cs.arg ? type_name (it, (charT*)0) : "basic_string::iterator";
+        tcase.arg ? type_name (it, (charT*)0) : "basic_string::iterator";
 
-    /* const */ String s_str (wstr, cs.str_len);
-    const       String s_arg (wsrc, cs.arg_len);
+    /* const */ String s_str (wstr, tcase.str_len);
+    const       String s_arg (wsrc, tcase.arg_len);
 
-    std::size_t off_last = cs.off + cs.size;
+    std::size_t off_last = tcase.off + tcase.size;
 
-    if (cs.arg) {
+    if (tcase.arg) {
         off_last = off_last > s_arg.size () ? s_arg.size () : off_last;
 
-        const Iterator first (wsrc + cs.off,   wsrc + cs.off, wsrc + off_last);
-        const Iterator last  (wsrc + off_last, wsrc + cs.off, wsrc + off_last);
+        const Iterator
+            first (wsrc + tcase.off, wsrc + tcase.off, wsrc + off_last);
+        const Iterator
+            last  (wsrc + off_last, wsrc + tcase.off, wsrc + off_last);
 
         s_str.assign (first, last);
     }
     else {
         typedef typename String::iterator StringIter;
 
-        const StringIter first (s_str.begin () + cs.off);
+        const StringIter first (s_str.begin () + tcase.off);
         const StringIter last  (off_last > s_str.size () ?
             s_str.end ()
           : s_str.begin () + off_last);
@@ -583,12 +585,13 @@
         s_str.assign (first, last);
     }
 
-    const std::size_t match = rw_match (cs.res, s_str.c_str(), cs.res_len);
+    const std::size_t match =
+        rw_match (tcase.res, s_str.c_str(), tcase.res_len);
 
-    rw_assert (match == cs.res_len, 0, cs.line,
+    rw_assert (match == tcase.res_len, 0, tcase.line,
                "line %d. %{$FUNCALL} expected %{#*s}, got %{/*.*Gs}, "
                "difference at off %zu for %s",
-               __LINE__, int (cs.res_len), cs.res,
+               __LINE__, int (tcase.res_len), tcase.res,
                int (sizeof (charT)), int (s_str.size ()), s_str.c_str (),
                match, itname);
 }
@@ -599,27 +602,27 @@
 void test_assign_range (charT          *wstr,
                         charT          *wsrc,
                         Traits*,
-                        const TestCase &cs)
+                        const TestCase &tcase)
 {
-    if (cs.bthrow)  // this method doesn't throw
+    if (tcase.bthrow)  // this method doesn't throw
         return;
 
     test_assign_range (wstr, wsrc, (Traits*)0,
-                       InputIter<charT>(0, 0, 0), cs);
+                       InputIter<charT>(0, 0, 0), tcase);
 
     // there is no need to call test_assign_range
     // for other iterators in this case
-    if (0 == cs.arg)
+    if (0 == tcase.arg)
         return;
 
     test_assign_range (wstr, wsrc, (Traits*)0,
-                       ConstFwdIter<charT>(0, 0, 0), cs);
+                       ConstFwdIter<charT>(0, 0, 0), tcase);
 
     test_assign_range (wstr, wsrc, (Traits*)0,
-                       ConstBidirIter<charT>(0, 0, 0), cs);
+                       ConstBidirIter<charT>(0, 0, 0), tcase);
 
     test_assign_range (wstr, wsrc, (Traits*)0,
-                       ConstRandomAccessIter<charT>(0, 0, 0), cs);
+                       ConstRandomAccessIter<charT>(0, 0, 0), tcase);
 }
 
 /**************************************************************************/
@@ -627,33 +630,38 @@
 template <class charT, class Traits>
 void test_assign (charT, Traits*,
                   AssignOverload  which,
-                  const TestCase &cs)
+                  const TestCase &tcase)
 {
     typedef std::allocator<charT>                        Allocator;
     typedef std::basic_string <charT, Traits, Allocator> TestString;
     typedef typename TestString::iterator                StringIter;
 
+    if (-1 == tcase.bthrow) {
+        test_exceptions (charT (), (Traits*)0, which, tcase);
+        return;
+    }
+
     static charT wstr [LLEN];
     static charT wsrc [LLEN];
 
-    rw_widen (wstr, cs.str, cs.str_len);
-    rw_widen (wsrc, cs.arg, cs.arg_len);
+    rw_widen (wstr, tcase.str, tcase.str_len);
+    rw_widen (wsrc, tcase.arg, tcase.arg_len);
 
     // special processing for assign_range to exercise all iterators
     if (Assign (range) == which) {
-        test_assign_range (wstr, wsrc, (Traits*)0, cs);
+        test_assign_range (wstr, wsrc, (Traits*)0, tcase);
         return;
     }
 
-    /* const */ TestString s_str (wstr, cs.str_len);
-    const       TestString s_arg (wsrc, cs.arg_len);
+    /* const */ TestString s_str (wstr, tcase.str_len);
+    const       TestString s_arg (wsrc, tcase.arg_len);
 
     std::size_t res_off = 0;
-    std::size_t size = cs.size >= 0 ? cs.size : s_str.max_size () + 1;
+    std::size_t size = tcase.size >= 0 ? tcase.size : s_str.max_size () + 1;
 
     // first function argument
-    const charT* const arg_ptr = cs.arg ? wsrc : s_str.c_str ();
-    const TestString&  arg_str = cs.arg ? s_arg : s_str;
+    const charT* const arg_ptr = tcase.arg ? wsrc : s_str.c_str ();
+    const TestString&  arg_str = tcase.arg ? s_arg : s_str;
 
     // address of returned reference
     const TestString* res_ptr = 0;
@@ -662,9 +670,9 @@
 
     // is some exception expected ?
     const char* expected = 0;
-    if (1 == cs.bthrow && Assign (str_size_size) == which)
+    if (1 == tcase.bthrow && Assign (str_size_size) == which)
         expected = exp_exceptions [1];
-    if (2 == cs.bthrow)
+    if (2 == tcase.bthrow)
         expected = exp_exceptions [2];
 
     const char* caught = 0;
@@ -673,7 +681,7 @@
 
 #else   // if defined (_RWSTD_NO_EXCEPTIONS)
 
-    if (cs.bthrow)
+    if (tcase.bthrow)
         return;
 
 #endif   // _RWSTD_NO_EXCEPTIONS
@@ -692,11 +700,11 @@
         break;
 
     case Assign (str_size_size):
-        res_ptr = &s_str.assign (arg_str, cs.off, size);
+        res_ptr = &s_str.assign (arg_str, tcase.off, size);
         break;
 
     case Assign (size_val): {
-        const charT val = make_char (char (cs.val), (charT*)0);
+        const charT val = make_char (char (tcase.val), (charT*)0);
         res_ptr = &s_str.assign (size, val);
         break;
     }
@@ -708,24 +716,25 @@
     res_off = res_ptr - &s_str;
 
     // verify the returned value
-    rw_assert (0 == res_off, 0, cs.line,
+    rw_assert (0 == res_off, 0, tcase.line,
                "line %d. %{$FUNCALL} returned invalid reference, offset is %zu",
                __LINE__, res_off);
 
     // verfiy that strings length are equal
-    rw_assert (cs.res_len == s_str.size (), 0, cs.line,
+    rw_assert (tcase.res_len == s_str.size (), 0, tcase.line,
                "line %d. %{$FUNCALL}: expected %{#*s} with length %zu, "
-               "got %{/*.*Gs} with length %zu", __LINE__, int (cs.res_len),
-               cs.res, cs.res_len, int (sizeof (charT)), int (s_str.size ()),
-               s_str.c_str (), s_str.size ());
+               "got %{/*.*Gs} with length %zu", __LINE__, int (tcase.res_len),
+               tcase.res, tcase.res_len, int (sizeof (charT)),
+               int (s_str.size ()), s_str.c_str (), s_str.size ());
 
     // verfiy that assign results match expected result
-    const std::size_t match = rw_match (cs.res, s_str.c_str(), cs.res_len);
+    const std::size_t match =
+        rw_match (tcase.res, s_str.c_str(), tcase.res_len);
 
-    rw_assert (match == cs.res_len, 0, cs.line,
+    rw_assert (match == tcase.res_len, 0, tcase.line,
                "line %d. %{$FUNCALL}: expected %{#*s}, got %{/*.*Gs}, "
                "difference at off %zu",
-               __LINE__, int (cs.res_len), cs.res,
+               __LINE__, int (tcase.res_len), tcase.res,
                int (sizeof (charT)), int (s_str.size ()), s_str.c_str (),
                match);
 
@@ -746,7 +755,7 @@
     _RWSTD_UNUSED (should_throw);
 #endif   // _RWSTD_NO_EXCEPTIONS
 
-    rw_assert (caught == expected, 0, cs.line,
+    rw_assert (caught == expected, 0, tcase.line,
                "line %d. %{$FUNCALL}: %{?}expected %s, caught %s"
                "%{:}unexpectedly caught %s%{;}",
                __LINE__, 0 != expected, expected, caught, caught);
@@ -754,43 +763,7 @@
 
 /**************************************************************************/
 
-static void
-test_assign (const MemFun &memfun, const TestCase& tcase)
-{
-    // exercise exception safety?
-    const bool exception_safety = -1 == tcase.bthrow;
-
-#undef TEST
-#define TEST(charT, Traits)                                             \
-    exception_safety ?                                                  \
-        test_exceptions (charT (), (Traits*)0, memfun.which_, tcase)    \
-      : test_assign (charT (), (Traits*)0, memfun.which_, tcase)
-
-    if (StringMembers::DefaultTraits == memfun.traits_id_) {
-        if (StringMembers::Char == memfun.char_id_)
-            TEST (char, std::char_traits<char>);
-
-#ifndef _RWSTD_NO_WCHAR_T
-    else
-        TEST (wchar_t, std::char_traits<wchar_t>);
-#endif   // _RWSTD_NO_WCHAR_T
-
-    }
-    else {
-       if (StringMembers::Char == memfun.char_id_)
-           TEST (char, UserTraits<char>);
-
-#ifndef _RWSTD_NO_WCHAR_T
-       else if (StringMembers::WChar == memfun.char_id_)
-           TEST (wchar_t, UserTraits<wchar_t>);
-#endif   // _RWSTD_NO_WCHAR_T
-
-       else
-           TEST (UserChar, UserTraits<UserChar>);
-    }
-}
-
-/**************************************************************************/
+DEFINE_TEST_DISPATCH (test_assign);
 
 static int
 run_test (int, char*[])



Mime
View raw message