stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r396375 [1/2] - 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.replace.cpp
Date Mon, 24 Apr 2006 01:58:17 GMT
Author: sebor
Date: Sun Apr 23 18:58:16 2006
New Revision: 396375

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

	* 21.strings.h (UnknownChar, UnknownTraits, UnknownAllocator): Added.
	(sig_void): Defined to 1 instead of 0 to distinguish an "unknown"
	value from a known one.
	(MemberId): New member indentifying a set of overloads of a given
	member function of basic_string.
	(SignatureId): Renamed from MemberFunction and defined partly in
	terms of MemberId constants.
	(Function): New struct uniquely identifying a specific overload of
	a given member function of a particular specialization of basic_string.
	(setvars): Renamed from format, changed signature and semantics and
	made private.
	(run_test): New function to run all test cases defined by a test.
	* 21.strings.cpp (setvars): Defined the environment variables CLASS,
	FUNC, FUNCSIG, and FUNCALL to the name of the specialization of the
	class template, the name of the member function, and the name of the
	overload of the member function, respectively, and optionally, the
	call to the member function with argument expanded.
	(run_test): Runs all test cases specified by each test.
	* 21.string.append.cpp: Simplified by using the above.
	(MemFun): Defined to StringMembers::Function.
	(tests): Made static local and removed function signatures obviated
	by the above changes.
	* 21.string.assign.cpp: Same.
	* 21.string.replace.cpp: 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.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=396375&r1=396374&r2=396375&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/include/21.strings.h (original)
+++ incubator/stdcxx/trunk/tests/include/21.strings.h Sun Apr 23 18:58:16 2006
@@ -1,6 +1,6 @@
 /************************************************************************
  *
- * 21_strings.h - definitions of helpers used in clause 21 tests
+ * 21.strings.h - definitions of helpers used in clause 21 tests
  *
  * $Id$
  *
@@ -35,113 +35,175 @@
 struct _TEST_EXPORT StringMembers {
 
     // identifiers for the charT template argument
-    enum charT  { Char, WChar, UChar };
+    enum charT  { UnknownChar = 0, Char, WChar, UChar };
 
     // identifiers for  the Traits template argument
-    enum Traits { DefaultTraits, UserTraits };
+    enum Traits { UnknownTraits = 0, DefaultTraits, UserTraits };
 
     // identifiers for  the Allocator template argument
-    enum Allocator { DefaultAllocator, UserAllocator };
+    enum Allocator { UnknownAllocator = 0, DefaultAllocator, UserAllocator };
 
-    // identifiers for all overloads of each member function
-    enum MemberFunction {
+    enum SignatureId {
+        // (void)
+        sig_void = 1,
+        // (const value_type*)
+        sig_ptr,
+        // (const basic_string&)
+        sig_str,
+        // (size_type)
+        sig_size,
+        // (const value_type*, size_type)
+        sig_ptr_size,
+        // (const basic_string&, size_type, size_type)
+        sig_str_size_size,
+        // (size_type, const value_type*, size_type)
+        sig_size_ptr_size,
+        // (size_type, const basic_string&, size_type, size_type)
+        sig_size_str_size_size,
+        // (size_type, value_type)
+        sig_size_val,
+        // (size_type, const basic_string&)
+        sig_size_str,
+        // (size_type, size_type)
+        sig_size_size,
+        // (size_type, size_type, const value_type*)
+        sig_size_size_ptr,
+        // (size_type, size_type, const basic_string&)
+        sig_size_size_str,
+        // (size_type, size_type, value_type)
+        sig_size_size_val,
+        // (size_type, size_type, const value_type*, size_type)
+        sig_size_size_ptr_size,
+        // (size_type, size_type, const value_type*, size_type, size_type)
+        sig_size_size_str_size_size,
+        // (size_type, size_type, size_type, value_type)
+        sig_size_size_size_val,
+        // (InputIterator, InputIterator)
+        sig_range,
+        // (iterator, value_type)
+        sig_iter_val,
+        // (iterator, size_type, value_type)
+        sig_iter_size_val,
+        // (iterator, InputIterator, InputIterator)
+        sig_iter_range,
+        // (iterator, iterator, const value_type*)
+        sig_iter_iter_ptr,
+        // (iterator, iterator, const basic_string&)
+        sig_iter_iter_str,
+        // (iterator, iterator, const value_type*, size_type)
+        sig_iter_iter_ptr_size,
+        // (iterator, iterator, size_type, value_type)
+        sig_iter_iter_size_val,
+        // (iterator, iterator, InputIterator, InputIterator)
+        sig_iter_iter_range,
+
+        //
+        sig_last
+    };
 
+    enum MemberId {
+        mem_append  = 1 << 5,
+        mem_assign  = 1 << 6,
+        mem_erase   = 1 << 7,
+        mem_insert  = 1 << 8,
+        mem_replace = 1 << 9,
+        mem_mask    =
+            mem_append | mem_assign | mem_erase | mem_insert | mem_replace
+    };
+
+    // unique identifiers for all overloads of each member function
+    enum OverloadId {
+        UnknownOverload = 0,
         //////////////////////////////////////////////////////////////
-        append,
-        append_first = append,
         // append (const value_type*)
-        append_ptr = append_first,
+        append_ptr = mem_append + sig_ptr,
         // append (const basic_string&)
-        append_str,
+        append_str = mem_append + sig_str,
         // append (const value_type*, size_type)
-        append_ptr_size,
+        append_ptr_size = mem_append + sig_ptr_size,
         // append (const basic_string&, size_type, size_type)
-        append_str_off_size,
+        append_str_size_size = mem_append + sig_str_size_size,
         // append (size_type, value_type)
-        append_size_val,
+        append_size_val = mem_append + sig_size_val,
         // append (InputIterator, InputIterator)
-        append_range,
-        append_last,
+        append_range = mem_append + sig_range,
 
         //////////////////////////////////////////////////////////////
-        assign_first = append_last,
         // assign (const value_type*)
-        assign_ptr = assign_first,
+        assign_ptr = mem_assign + sig_ptr,
         // assign (const basic_string&)
-        assign_str,
+        assign_str = mem_assign + sig_str,
         // assign (const value_type*, size_type)
-        assign_ptr_size,
+        assign_ptr_size = mem_assign + sig_ptr_size,
         // assign (const basic_string&, size_type, size_type)
-        assign_str_off_size,
+        assign_str_size_size = mem_assign + sig_str_size_size,
         // assign (size_type, value_type)
-        assign_size_val,
+        assign_size_val = mem_assign + sig_size_val,
         // assign (InputIterator, InputIterator)
-        assign_range,
-        assign_last,
+        assign_range = mem_assign + sig_range,
+
+        //////////////////////////////////////////////////////////////
+        // erase ()
+        erase_void = mem_erase + sig_void,
+        // erase (size_type)
+        erase_size = mem_erase + sig_size,
+        // erase (size_type, size_type)
+        erase_size_size = mem_erase + sig_size_size,
 
         //////////////////////////////////////////////////////////////
-        insert_first = assign_last,
         // insert (size_type, const value_type*)
-        insert_off_ptr = insert_first,
+        insert_size_ptr = mem_insert + sig_size_val,
         // insert (size_type, const basic_string&)
-        insert_off_str,
+        insert_size_str = mem_insert + sig_size_str,
         // insert (size_type, const value_type*, size_type)
-        insert_off_ptr_size,
+        insert_size_ptr_size = mem_insert + sig_size_ptr_size,
         // insert (size_type, basic_string&, size_type, size_type)
-        insert_off_str_off_size,
+        insert_size_str_size_size = mem_insert + sig_size_str_size_size,
         // insert (size_type, size_type, value_type)
-        insert_off_size_val,
+        insert_size_size_val = mem_insert + sig_size_size_val,
         // insert (iterator, value_type)
-        insert_val,
+        insert_val = mem_insert + sig_iter_val,
         // insert (iterator, size_type, value_type)
-        insert_size_val,
+        insert_size_val = mem_insert + sig_iter_size_val,
         // insert (iterator p, InputIterator, InputIterator)
-        insert_range,
-        insert_last,
+        insert_range = mem_insert + sig_iter_range,
 
         //////////////////////////////////////////////////////////////
-        replace_first = insert_last,
         // (size_type, size_type, const value_type*)
-        replace_off_size_ptr = replace_first,
+        replace_size_size_ptr = mem_replace + sig_size_size_ptr,
         // (size_type, size_type, basic_string&)
-        replace_off_size_str,
-        // (size_type1, size_type, const value_type*, size_type)
-        replace_off_size_ptr_size,
+        replace_size_size_str = mem_replace + sig_size_size_str,
+        // (size_type, size_type, const value_type*, size_type)
+        replace_size_size_ptr_size = mem_replace + sig_size_size_ptr_size,
         // (size_type, size_type, const basic_string&, size_type, size_type)
-        replace_off_size_str_off_size,
+        replace_size_size_str_size_size =
+            mem_replace + sig_size_size_str_size_size,
         // (size_type, size_type, size_type, value_type)
-        replace_off_size_size_val,
+        replace_size_size_size_val = mem_replace + sig_size_size_size_val,
         // (iterator, iterator, const value_type*)
-        replace_ptr,
+        replace_iter_iter_ptr = mem_replace + sig_iter_iter_ptr,
         // (iterator, iterator, const basic_string&)
-        replace_str,
+        replace_iter_iter_str = mem_replace + sig_iter_iter_str,
         // (iterator, iterator, const value_type*, size_type)
-        replace_ptr_size,
+        replace_iter_iter_ptr_size = mem_replace + sig_iter_iter_ptr_size,
         // (iterator, iterator, size_type, value_type)
-        replace_size_val,
+        replace_iter_iter_size_val = mem_replace + sig_iter_iter_size_val,
         // (iterator, iterator, InputIterator, InputIterator)
-        replace_range,
-        replace_last
+        replace_iter_iter_range = mem_replace + sig_iter_iter_range
     };
 
-    enum {
-        // number of member function overloads
-        append_overloads = append_last - append_first,
-        // number of member function overloads
-        assign_overloads = assign_last - assign_first,
-        // number of member function overloads
-        insert_overloads = insert_last - insert_first,
-        // number of member function overloads
-        replace_overloads = replace_last - replace_first,
-        // total number of member functions
-        member_functions =   append_overloads + assign_overloads
-                           + insert_overloads + replace_overloads
+    struct Function {
+        charT      char_id_;
+        Traits     traits_id_;
+        Allocator  alloc_id_;
+        OverloadId which_;
     };
 
     // describes a single test case for any overload
-    // of any member function
+    // of any member function (the same test case can
+    // be used to exercise more than one overload of
+    // the same member function)
     struct TestCase {
-        MemberFunction which;     // member function to call
         int            line;      // test case line number
 
         int            off;       // offset (position argument)
@@ -167,22 +229,21 @@
     // describes a set of test cases for a single overload
     // of a member function
     struct Test {
-        const TestCase *cases;        // test cases to exercise
+        OverloadId      which;        // member function overload to exercise
+        const TestCase *cases;        // test cases to exercise overload withh
         _RWSTD_SIZE_T   case_count;   // number of test cases
-        const char     *funsig;       // function signature
     };
 
-    // dynamically allocates and formats a string describing
-    // the call to the member function, including the values
-    // of its arguments, specfified by its arguments
-    static char*
-    format (charT, Traits, Allocator, const TestCase&);
+    typedef void TestFun (const Function&, const TestCase&);
+
+    static void
+    run_test (TestFun*, const Test*, _RWSTD_SIZE_T);
 
     // array of integers to use for command line option
     // processing (to disable individual overloads of all
     // member functions)
     static int
-    opt_memfun_disabled [member_functions];
+    opt_memfun_disabled [sig_last];
 
     static int opt_no_user_char;          // for --no-user_char
     static int opt_no_char_traits;        // for --no-char_traits
@@ -190,7 +251,24 @@
 
     static int opt_no_exceptions;         // for --no-exceptions
     static int opt_no_exception_safety;   // for --no-exception-safety
+
+private:
+
+    // sets the {CLASS}, {FUNC}, {FUNCSIG}, and optionally {FUNCALL}
+    // environment variables as follows:
+    // CLASS:   the name of basic_string specialization
+    // FUNC:    the name of the basic_string member function
+    // FUNCSIG: the name and signature of a specific overload
+    //          of the basic_string member function
+    // FUNCALL: a string describing the call to the basic_string member
+    //          function with function with function arguments expanded
+    //          (as specified by the TestCase argument)
+    static void
+    setvars (const Function &fun, const TestCase* = 0);
+
 };
 
+#define Disabled(which)   \
+    StringMembers::opt_memfun_disabled [which & ~StringMembers::mem_mask]
 
 #endif   // RW_21_STRINGS_H_INCLUDED

Modified: incubator/stdcxx/trunk/tests/src/21.strings.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/21.strings.cpp?rev=396375&r1=396374&r2=396375&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/21.strings.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/21.strings.cpp Sun Apr 23 18:58:16 2006
@@ -29,9 +29,15 @@
 #define _RWSTD_TEST_SRC
 
 #include <21.strings.h>
+
+#include <cmdopt.h>       // for rw_enabled()
+#include <driver.h>       // for rw_info()
+#include <environ.h>      // for rw_putenv()
 #include <rw_printf.h>    // for rw_asnprintf()
 
+#include <stdarg.h>       // for va_arg, ...
 #include <stddef.h>       // for size_t
+#include <stdlib.h>       // for free()
 
 /**************************************************************************/
 
@@ -39,21 +45,18 @@
     "char", "wchar_t", "UserChar"
 };
 
+
 static const char* const traits_names[] = {
     "char_traits", "UserTraits"
 };
 
+
 static const char* const allocator_names[] = {
     "allocator", "UserAllocator"
 };
 
-static const char* const function_names[] = {
-    "append", "assign", "erase", "insert", "replace"
-};
-
-
 int StringMembers::
-opt_memfun_disabled [StringMembers::member_functions];
+opt_memfun_disabled [StringMembers::sig_last];
 
 int StringMembers::
 opt_no_user_char;
@@ -71,168 +74,300 @@
 opt_no_exception_safety;
 
 
-char* StringMembers::
-format (charT cid, Traits tid, Allocator aid, const TestCase &tcase)
+void StringMembers::
+setvars (const Function &fun, const TestCase *pcase /* = 0 */)
 {
     char*  buf     = 0;
     size_t bufsize = 0;
 
-    const bool self = 0 == tcase.arg;
+    if (0 == pcase) {
+        // set the {CLASS}, {FUNC}, and {FUNCSIG} environment variables
+        // to the name of the specialization of the template, the name
+        // of the member function, and the name of the overload of the
+        // member function, respectively, when no test case is given
+
+        if (   DefaultTraits == fun.traits_id_
+            && (Char == fun.char_id_ || WChar == fun.char_id_)) {
+            // format std::string and std::wstring
+            rw_asnprintf (&buf, &bufsize,
+                          "std::%{?}w%{;}string", WChar == fun.char_id_);
+        }
+        else {
+            // format std::basic_string specializations other than
+            // std::string and std::wstring, leaving out the name
+            // of the default allocator for brevity
+            rw_asnprintf (&buf, &bufsize,
+                          "std::basic_string<%s, %s<%1$s>%{?}, %s<%1$s>%{;}>",
+                          char_names [fun.char_id_ - 1],
+                          traits_names [fun.traits_id_ - 1],
+                          DefaultAllocator != fun.alloc_id_,
+                          allocator_names [fun.alloc_id_ - 1]);
+        }
+
+        // set the {CLASS} variable to the name of the specialization
+        // of basic_string
+        rw_putenv ("CLASS=");
+        rw_fprintf (0, "%{$CLASS:=*}", buf);
+
+        // determine the member function name
+        const char* fname = 0;
+
+        if (fun.which_ & mem_append)
+            fname = "append";
+        else if (fun.which_ & mem_assign)
+            fname = "assign";
+        else if (fun.which_ & mem_erase)
+            fname ="erase";
+        else if (fun.which_ & mem_insert)
+            fname ="insert";
+        else if (fun.which_ & mem_replace)
+            fname ="replace";
+
+        free (buf);
+        buf     = 0;
+        bufsize = 0;
+
+        // set the {FUNC} variable to the unqualified name
+        // of the member function
+        rw_asnprintf (&buf, &bufsize, "%s", fname);
+
+        rw_putenv ("FUNC=");
+        rw_fprintf (0, "%{$FUNC:=*}", buf);
+
+        static const char* const signatures[] = {
+            "void",
+            "const value_type*",
+            "const basic_string&",
+            "size_type",
+            "const value_type*, size_type",
+            "const basic_string&, size_type, size_type",
+            "size_type, const value_type*, size_type",
+            "size_type, const basic_string&, size_type, size_type",
+            "size_type, value_type",
+            "size_type, const basic_string&",
+            "size_type, size_type",
+            "size_type, size_type, const value_type*",
+            "size_type, size_type, const basic_string&",
+            "size_type, size_type, value_type",
+            "size_type, size_type, const value_type*, size_type",
+            "size_type, size_type, const value_type*, size_type, size_type",
+            "size_type, size_type, size_type, value_type",
+            "InputIterator, InputIterator",
+            "iterator, value_type",
+            "iterator, size_type, value_type",
+            "iterator, InputIterator, InputIterator",
+            "iterator, iterator, const value_type*",
+            "iterator, iterator, const basic_string&",
+            "iterator, iterator, const value_type*, size_type",
+            "iterator, iterator, size_type, value_type",
+            "iterator, iterator, InputIterator, InputIterator",
+        };
 
-    if (DefaultTraits == tid && (Char == cid || WChar == cid)) {
-        // format std::string and std::wstring
-        rw_asnprintf (&buf, &bufsize,
-                      "std::%{?}w%{;}string (%{?}%{#*s}%{;}).",
-                      WChar == cid,
-                      tcase.str != 0, int (tcase.str_len), tcase.str);
-    }
-    else {
-        // format std::basic_string specializations other than
-        // std::string and std::wstring, leaving out the name
-        // of the default allocator for brevity
+        // append the function signature
         rw_asnprintf (&buf, &bufsize,
-                      "std::basic_string<%s, %s<%1$s>%{?}, %s<%1$s>%{;}>"
-                      "(%{?}%{#*s}%{;}).",
-                      char_names [cid],
-                      traits_names [tid],
-                      DefaultAllocator != aid, allocator_names [aid],
-                      tcase.str != 0, int (tcase.str_len), tcase.str);
+                      "%{+} (%s)", signatures [fun.which_ & ~mem_mask]);
+
+        rw_putenv ("FUNCSIG=");
+        rw_fprintf (0, "%{$FUNCSIG:=*}", buf);
+        free (buf);
+
+        return;
     }
 
-    const char* fname = 0;
+    // do the function call arguments reference *this?
+    const bool self = 0 == pcase->arg;
 
-    if (append_first <= tcase.which && tcase.which < append_last)
-        fname = "append";
-    else if (assign_first <= tcase.which && tcase.which < assign_last)
-        fname = "assign";
-    else if (insert_first <= tcase.which && tcase.which < insert_last)
-        fname ="insert";
-    else if (replace_first <= tcase.which && tcase.which < replace_last)
-        fname ="replace";
+    // append the ctor argument(s) and the member function name
+    rw_asnprintf (&buf, &bufsize,
+                  "%{$CLASS} (%{?}%{#*s}%{;}).%{$FUNC} ",
+                  pcase->str != 0, int (pcase->str_len), pcase->str);
 
-    switch (tcase.which) {
+    // format and append member function arguments
+    switch (fun.which_) {
     case append_ptr:
     case assign_ptr:
         rw_asnprintf (&buf, &bufsize,
-                      "%{+}%s (%{?}%{#*s}%{;}%{?}this->c_str ()%{;})",
-                      fname, !self, int (tcase.arg_len), tcase.arg, self);
+                      "%{+}(%{?}%{#*s}%{;}%{?}this->c_str ()%{;})",
+                      !self, int (pcase->arg_len), pcase->arg, self);
         break;
 
     case append_str:
     case assign_str:
         rw_asnprintf (&buf, &bufsize,
-                      "%{+}%s (%{?}string (%{#*s})%{;}%{?}*this%{;})",
-                      fname, !self, int (tcase.arg_len), tcase.arg, self);
+                      "%{+}(%{?}string (%{#*s})%{;}%{?}*this%{;})",
+                      !self, int (pcase->arg_len), pcase->arg, self);
         break;
 
     case append_ptr_size:
     case assign_ptr_size:
-        rw_asnprintf (&buf, &bufsize, "%{+}%s ("
+        rw_asnprintf (&buf, &bufsize, "%{+}("
                       "%{?}%{#*s}%{;}%{?}this->c_str ()%{;}, %zu)",
-                      fname, !self, int (tcase.arg_len), tcase.arg,
-                      self, tcase.size);
+                      !self, int (pcase->arg_len), pcase->arg,
+                      self, pcase->size);
         break;
 
-    case append_str_off_size:
-    case assign_str_off_size:
-        rw_asnprintf (&buf, &bufsize, "%{+}%s ("
+    case append_str_size_size:
+    case assign_str_size_size:
+        rw_asnprintf (&buf, &bufsize, "%{+}("
                       "%{?}string (%{#*s})%{;}%{?}*this%{;}, %zu, %zu)",
-                      fname, !self, int (tcase.arg_len), tcase.arg, self,
-                      tcase.off, tcase.size);
+                      !self, int (pcase->arg_len), pcase->arg, self,
+                      pcase->off, pcase->size);
         break;
 
     case append_size_val:
     case assign_size_val:
         rw_asnprintf (&buf, &bufsize,
-                      "%{+} %s (%zu, %#c)", tcase.size, tcase.val);
+                      "%{+} %s (%zu, %#c)", pcase->size, pcase->val);
         break;
 
     case append_range:
     case assign_range:
-        rw_asnprintf (&buf, &bufsize, "%{+}%s ("
+        rw_asnprintf (&buf, &bufsize, "%{+}("
                       "%{?}%{#*s}%{;}%{?}this->%{;}begin() + %zu, "
                       "%{?}%{#*s}%{;}%{?}this->%{;}.begin() + %zu)",
-                      fname, !self, int (tcase.arg_len), tcase.arg,
-                      self, tcase.off, !self, int (tcase.arg_len), tcase.arg,
-                      self, tcase.off + tcase.size);
+                      !self, int (pcase->arg_len), pcase->arg,
+                      self, pcase->off, !self, int (pcase->arg_len), pcase->arg,
+                      self, pcase->off + pcase->size);
         break;
 
-    case replace_off_size_ptr:
-        rw_asnprintf (&buf, &bufsize, "%{+}%s ("
+    case replace_size_size_ptr:
+        rw_asnprintf (&buf, &bufsize, "%{+}("
                       "%zu, %zu, %{?}%{#*s}%{;}%{?}this->c_str ()%{;})",
-                      fname, tcase.off, tcase.size, !self, 
-                      int (tcase.arg_len), tcase.arg, self);
+                      pcase->off, pcase->size, !self, 
+                      int (pcase->arg_len), pcase->arg, self);
         break;
 
-    case replace_off_size_str:
-        rw_asnprintf (&buf, &bufsize, "%{+}%s ("
+    case replace_size_size_str:
+        rw_asnprintf (&buf, &bufsize, "%{+}("
                       "%zu, %zu, %{?}string (%{#*s})%{;}%{?}*this%{;})",
-                      fname, tcase.off, tcase.size, !self, 
-                      int (tcase.arg_len), tcase.arg, self);
+                      pcase->off, pcase->size, !self, 
+                      int (pcase->arg_len), pcase->arg, self);
         break;
 
-    case replace_off_size_ptr_size:
-        rw_asnprintf (&buf, &bufsize, "%{+}%s ("
+    case replace_size_size_ptr_size:
+        rw_asnprintf (&buf, &bufsize, "%{+}("
                       "%zu, %zu, %{?}%{#*s}%{;}%{?}this->c_str ()%{;}, %zu)", 
-                      fname, tcase.off, tcase.size, !self, 
-                      int (tcase.arg_len), tcase.arg, self, tcase.size2);
+                      pcase->off, pcase->size, !self, 
+                      int (pcase->arg_len), pcase->arg, self, pcase->size2);
         break;
 
-    case replace_off_size_str_off_size:
-        rw_asnprintf (&buf, &bufsize, "%{+}%s (%zu, %zu, "
+    case replace_size_size_str_size_size:
+        rw_asnprintf (&buf, &bufsize, "%{+}(%zu, %zu, "
                       "%{?}string (%{#*s})%{;}%{?}*this%{;}, %zu, %zu)",
-                      fname, tcase.off, tcase.size, !self, 
-                      int (tcase.arg_len), tcase.arg, self, 
-                      tcase.off2, tcase.size2);
+                      pcase->off, pcase->size, !self, 
+                      int (pcase->arg_len), pcase->arg, self, 
+                      pcase->off2, pcase->size2);
         break;
 
-    case replace_off_size_size_val:
+    case replace_size_size_size_val:
         rw_asnprintf (&buf, &bufsize, 
-                      "%{+}%s (%zu, %zu, %zu, %#c)",
-                      fname, tcase.off, tcase.size, tcase.size2, tcase.val);
+                      "%{+}(%zu, %zu, %zu, %#c)",
+                      pcase->off, pcase->size, pcase->size2, pcase->val);
         break;
 
-    case replace_ptr:
-        rw_asnprintf (&buf, &bufsize, "%{+}%s (begin() + %zu, begin() + %zu, "
+    case replace_iter_iter_ptr:
+        rw_asnprintf (&buf, &bufsize, "%{+}(begin() + %zu, begin() + %zu, "
                       "%{?}%{#*s}%{;}%{?}this->c_str ()%{;})",
-                      fname, tcase.off, tcase.off + tcase.size, 
-                      !self, int (tcase.arg_len), tcase.arg, self);
+                      pcase->off, pcase->off + pcase->size, 
+                      !self, int (pcase->arg_len), pcase->arg, self);
         break;
 
-    case replace_str:
-        rw_asnprintf (&buf, &bufsize, "%{+}%s (begin() + %zu, begin() + %zu, " 
+    case replace_iter_iter_str:
+        rw_asnprintf (&buf, &bufsize, "%{+}(begin() + %zu, begin() + %zu, " 
                       "%{?}string (%{#*s})%{;}%{?}*this%{;})",
-                      fname, tcase.off, tcase.off + tcase.size, 
-                      !self, int (tcase.arg_len), tcase.arg, self);
+                      pcase->off, pcase->off + pcase->size, 
+                      !self, int (pcase->arg_len), pcase->arg, self);
         break;
 
-    case replace_ptr_size:
-        rw_asnprintf (&buf, &bufsize, "%{+}%s (begin() + %zu, begin() + %zu, " 
+    case replace_iter_iter_ptr_size:
+        rw_asnprintf (&buf, &bufsize, "%{+}(begin() + %zu, begin() + %zu, " 
                       "%{?}%{#*s}%{;}%{?}this->c_str ()%{;}, %zu)", 
-                      fname, tcase.off, tcase.off + tcase.size, !self, 
-                      int (tcase.arg_len), tcase.arg, self, tcase.size2);
+                      pcase->off, pcase->off + pcase->size, !self, 
+                      int (pcase->arg_len), pcase->arg, self, pcase->size2);
         break;
 
-    case replace_size_val:
+    case replace_iter_iter_size_val:
         rw_asnprintf (&buf, &bufsize, 
-                      "%{+}%s (begin() + %zu, begin() + %zu, %zu, %#c)",
-                      fname, tcase.off, tcase.off + tcase.size, 
-                      tcase.size2, tcase.val);
+                      "%{+}(begin() + %zu, begin() + %zu, %zu, %#c)",
+                      pcase->off, pcase->off + pcase->size, 
+                      pcase->size2, pcase->val);
         break;
 
-    case replace_range:
-        rw_asnprintf (&buf, &bufsize, "%{+}%s (begin() + %zu, begin() + %zu, "
+    case replace_iter_iter_range:
+        rw_asnprintf (&buf, &bufsize, "%{+}(begin() + %zu, begin() + %zu, "
                       "%{?}%{#*s}%{;}%{?}this->%{;}begin() + %zu, "
                       "%{?}%{#*s}%{;}%{?}this->%{;}begin() + %zu)", 
-                      fname, tcase.off, tcase.off + tcase.size, !self, 
-                      int (tcase.arg_len), tcase.arg, self, tcase.off2, !self, 
-                      int (tcase.arg_len), tcase.arg, self, 
-                      tcase.off2 + tcase.size2);
+                      pcase->off, pcase->off + pcase->size, !self, 
+                      int (pcase->arg_len), pcase->arg, self, pcase->off2,
+                      !self, int (pcase->arg_len), pcase->arg, self, 
+                      pcase->off2 + pcase->size2);
         break;
 
     default:
         RW_ASSERT (!"test logic error: unknown overload");
     }
 
-    return buf;
+    rw_putenv ("FUNCALL=");
+    rw_fprintf (0, "%{$FUNCALL:=*}", buf);
+    free (buf);
+}
+
+
+void StringMembers::
+run_test (TestFun *test_callback, const Test *tests, size_t test_count)
+{
+    const charT char_types[] = {
+        Char, WChar, UChar,
+        UnknownChar
+        
+    };
+
+    const Traits traits_types[] = {
+        DefaultTraits, UserTraits,
+        UnknownTraits,
+    };
+
+    const Allocator alloc_types[] = {
+        DefaultAllocator,
+        UnknownAllocator
+    };
+
+    for (size_t i = 0; char_types [i]; ++i) {
+
+        for (size_t j = 0; traits_types [j]; ++j) {
+
+            for (size_t k = 0; alloc_types [k]; ++k) {
+
+                for (size_t m = 0; m != test_count; ++m) {
+
+                    const Function memfun = {
+                        char_types [i],
+                        traits_types [j],
+                        alloc_types [k],
+                        tests [m].which
+                    };
+
+                    // set the {CLASS}, {FUNC}, and {FUNCSIG} environment
+                    // variable to the name of the basic_string specializaton
+                    // and its member function being exercised
+                    setvars (memfun);
+
+                    rw_info (0, 0, 0, "%{$CLASS}::%{$FUNCSIG}");
+
+                    for (size_t n = 0; n != tests [m].case_count; ++n)
+                        if (rw_enabled (tests [m].cases [n].line)) {
+
+                            // set the {FUNCALL} environment variable
+                            setvars (memfun, tests [m].cases + n);
+
+                            test_callback (memfun, tests [m].cases [n]);
+                        }
+                        else
+                            rw_note (0, 0, 0,
+                                     "test on line %d disabled",
+                                     tests [m].cases [n].line);
+                }
+            }
+        }
+    }
 }

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=396375&r1=396374&r2=396375&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.append.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.append.cpp Sun Apr 23 18:58:16 2006
@@ -46,33 +46,12 @@
 #endif   // _RWSTD_NO_REPLACEABLE_NEW_DELETE
 
 
-#define AppendOverload   StringMembers::MemberFunction
+#define AppendOverload   StringMembers::OverloadId
 #define Append(which)    StringMembers::append_ ## which
-#define Disabled(which)  StringMembers::opt_memfun_disabled [which]
 
 typedef StringMembers::TestCase TestCase;
 typedef StringMembers::Test     Test;
-
-/**************************************************************************/
-
-struct MemFun
-{
-    typedef StringMembers::charT  charT;
-    typedef StringMembers::Traits Traits;
-
-    MemFun (charT cid, const char *cname,
-          Traits tid, const char *tname)
-        : cid_ (cid), tid_ (tid),
-          cname_ (cname), tname_ (tname), aname_ ("allocator"),
-          fname_ ("append") { /* empty */ }
-
-    charT       cid_;     // character type id (char or wchar_t)
-    Traits      tid_;     // traits type id (default or user-defined)
-    const char *cname_;   // character type name
-    const char *tname_;   // traits name
-    const char *aname_;   // allocator name
-    const char *fname_;   // function name
-};
+typedef StringMembers::Function MemFun;
 
 /**************************************************************************/
 
@@ -95,7 +74,7 @@
 
 #undef TEST
 #define TEST(str, arg, res, bthrow) {                           \
-        Append (ptr), __LINE__, -1, -1, -1, -1, -1,             \
+        __LINE__, -1, -1, -1, -1, -1,                           \
         str, sizeof str - 1,                                    \
         arg, sizeof arg - 1, res, sizeof res - 1, bthrow        \
     }
@@ -157,7 +136,7 @@
 
 #undef TEST
 #define TEST(s, arg, res, bthrow) {                             \
-        Append (str), __LINE__, -1, -1, -1, -1, -1,             \
+        __LINE__, -1, -1, -1, -1, -1,                           \
         s, sizeof s - 1,                                        \
         arg, sizeof arg - 1, res, sizeof res - 1, bthrow        \
     }
@@ -220,7 +199,7 @@
 
 #undef TEST
 #define TEST(str, arg, size, res, bthrow) {                     \
-        Append (ptr_size), __LINE__, -1, size, -1, -1, -1,      \
+        __LINE__, -1, size, -1, -1, -1,                         \
         str, sizeof str - 1,                                    \
         arg, sizeof arg - 1, res, sizeof res - 1, bthrow        \
     }
@@ -285,11 +264,11 @@
 range_test_cases [] = {
 
 // range_test_cases serves a double duty
-#define str_off_size_test_cases range_test_cases
+#define str_size_size_test_cases range_test_cases
 
 #undef TEST
 #define TEST(str, arg, off, size, res, bthrow) {                \
-        Append (str_off_size), __LINE__, off, size, -1, -1, -1, \
+        __LINE__, off, size, -1, -1, -1,                        \
         str, sizeof str - 1,                                    \
         arg, sizeof arg - 1, res, sizeof res - 1, bthrow        \
     }
@@ -366,10 +345,10 @@
 size_val_test_cases [] = {
 
 #undef TEST
-#define TEST(str, size, val, res, bthrow) {                     \
-        Append (size_val), __LINE__, -1, size, -1, -1, val,     \
-        str, sizeof str - 1,                                    \
-        0, 0, res, sizeof res - 1, bthrow                       \
+#define TEST(str, size, val, res, bthrow) {     \
+        __LINE__, -1, size, -1, -1, val,        \
+        str, sizeof str - 1,                    \
+        0, 0, res, sizeof res - 1, bthrow       \
     }
 
     //    +-------------------------------------- controlled sequence
@@ -421,30 +400,10 @@
 
 /**************************************************************************/
 
-static const StringMembers::Test
-tests [] = {
-
-#undef TEST
-#define TEST(tag, sig) {                                        \
-        tag ## _test_cases,                                     \
-        sizeof tag ## _test_cases / sizeof *tag ## _test_cases, \
-        "append " sig                                           \
-    }
-
-    TEST (ptr,          "(const value_type*)"),
-    TEST (str,          "(const basic_string&)"),
-    TEST (ptr_size,     "(const value_type*, size_type)"),
-    TEST (str_off_size, "(const basic_string&, size_type, size_type)"),
-    TEST (size_val,     "(size_type, value_type)"),
-    TEST (range,        "(InputIterator, InputIterator)")
-};
-
-/**************************************************************************/
-
 template <class charT, class Traits>
 void test_exceptions (charT, Traits*,
-                      const TestCase &cs,
-                      const char     *funcall)
+                      AppendOverload  which,
+                      const TestCase &cs)
 {
     typedef std::basic_string <charT, Traits,
                                std::allocator<charT> > TestString;
@@ -486,22 +445,22 @@
 #endif   // _RWSTD_NO_EXCEPTIONS
 
         _TRY {
-            if (Append (ptr) == cs.which)
+            if (Append (ptr) == which)
                 s_str.append (cs.arg ? wsrc : s_str.c_str ());
 
-            else if (Append (str) == cs.which)
+            else if (Append (str) == which)
                 s_str.append (cs.arg ? s_arg : s_str);
 
-            else if (Append (ptr_size) == cs.which)
+            else if (Append (ptr_size) == which)
                 s_str.append (cs.arg ? wsrc : s_str.c_str (), cs.size);
 
-            else if (Append (str_off_size) == cs.which)
+            else if (Append (str_size_size) == which)
                 s_str.append (cs.arg ? s_arg : s_str, cs.off, cs.size);
 
-            else if (Append (size_val) == cs.which)
+            else if (Append (size_val) == which)
                 s_str.append (cs.size, make_char (char (cs.val), (charT*)0));
 
-            else if (Append (range) == cs.which)
+            else if (Append (range) == which)
                 s_str.append (s_arg.begin (), s_arg.end ());
 
             break;
@@ -514,20 +473,20 @@
             // doesn't cause a change in the state of the vector
 
             rw_assert (s_str.size () == size, 0, cs.line,
-                       "line %d: %s: size unexpectedly changed "
+                       "line %d: %{$FUNCALL}: size unexpectedly changed "
                        "from %zu to %zu after an exception",
-                       __LINE__, funcall, size, s_str.size ());
+                       __LINE__, size, s_str.size ());
 
             rw_assert (s_str.capacity () == capacity, 0, cs.line,
-                       "line %d: %s: capacity unexpectedly "
+                       "line %d: %{$FUNCALL}: capacity unexpectedly "
                        "changed from %zu to %zu after an exception",
-                       __LINE__, funcall, capacity, s_str.capacity ());
+                       __LINE__, capacity, s_str.capacity ());
 
 
             rw_assert (s_str.begin () == begin, 0, cs.line,
-                       "line %d: %s: begin() unexpectedly "
+                       "line %d: %{$FUNCALL}: begin() unexpectedly "
                        "changed from after an exception by %d",
-                       __LINE__, funcall, s_str.begin () - begin);
+                       __LINE__, s_str.begin () - begin);
 
 
             // increment to allow this call to operator new to succeed
@@ -547,8 +506,8 @@
     rw_assert (   *pst->throw_at_calls_ [0] == std::size_t (-1)
                || throw_after,
                0, cs.line,
-               "line %d: %s: failed to throw an expected exception",
-               __LINE__, funcall);
+               "line %d: %{$FUNCALL}: failed to throw an expected exception",
+               __LINE__);
 
 #  endif   // _RWSTD_NO_REPLACEABLE_NEW_DELETE
 #else   // if defined (_RWSTD_NO_EXCEPTIONS)
@@ -573,8 +532,7 @@
                         charT* wsrc,
                         Traits*,
                         const Iterator &it,
-                        const TestCase &cs,
-                        const char     *funcall)
+                        const TestCase &cs)
 {
     typedef std::basic_string <charT, Traits,
                                std::allocator<charT> > String;
@@ -610,9 +568,9 @@
     const std::size_t match = rw_match (cs.res, s_str.c_str(), cs.res_len);
 
     rw_assert (match == cs.res_len, 0, cs.line,
-               "line %d. %s expected %{#*s}, got %{/*.*Gs}, "
+               "line %d. %{$FUNCALL} expected %{#*s}, got %{/*.*Gs}, "
                "difference at off %zu for %s",
-               __LINE__, funcall, int (cs.res_len), cs.res,
+               __LINE__, int (cs.res_len), cs.res,
                int (sizeof (charT)), int (s_str.size ()), s_str.c_str (),
                match, itname);
 }
@@ -623,14 +581,13 @@
 void test_append_range (charT* wstr,
                         charT* wsrc,
                         Traits*,
-                        const TestCase &cs,
-                        const char     *funcall)
+                        const TestCase &cs)
 {
     if (cs.bthrow)  // this method doesn't throw
         return;
 
     test_append_range (wstr, wsrc, (Traits*)0,
-                       InputIter<charT>(0, 0, 0), cs, funcall);
+                       InputIter<charT>(0, 0, 0), cs);
 
     // there is no need to call test_append_range
     // for other iterators in this case
@@ -638,21 +595,21 @@
         return;
 
     test_append_range (wstr, wsrc, (Traits*)0,
-                       ConstFwdIter<charT>(0, 0, 0), cs, funcall);
+                       ConstFwdIter<charT>(0, 0, 0), cs);
 
     test_append_range (wstr, wsrc, (Traits*)0,
-                       ConstBidirIter<charT>(0, 0, 0), cs, funcall);
+                       ConstBidirIter<charT>(0, 0, 0), cs);
 
     test_append_range (wstr, wsrc, (Traits*)0,
-                       ConstRandomAccessIter<charT>(0, 0, 0), cs, funcall);
+                       ConstRandomAccessIter<charT>(0, 0, 0), cs);
 }
 
 /**************************************************************************/
 
 template <class charT, class Traits>
 void test_append (charT, Traits*,
-                  const TestCase &cs,
-                  const char     *funcall)
+                  AppendOverload  which,
+                  const TestCase &cs)
 {
     typedef std::basic_string <charT, Traits,
                                std::allocator<charT> > TestString;
@@ -665,8 +622,8 @@
     rw_widen (wsrc, cs.arg, cs.arg_len);
 
     // special processing for append_range to exercise all iterators
-    if (Append (range) == cs.which) {
-        test_append_range (wstr, wsrc, (Traits*)0, cs, funcall);
+    if (Append (range) == which) {
+        test_append_range (wstr, wsrc, (Traits*)0, cs);
         return;
     }
 
@@ -679,7 +636,7 @@
 
     // is some exception expected ?
     const char* expected = 0;
-    if (1 == cs.bthrow && Append (str_off_size) == cs.which)
+    if (1 == cs.bthrow && Append (str_size_size) == which)
         expected = exp_exceptions [1];
     if (2 == cs.bthrow)
         expected = exp_exceptions [2];
@@ -695,7 +652,7 @@
 
 #endif   // _RWSTD_NO_EXCEPTIONS
 
-    switch (cs.which) {
+    switch (which) {
     case Append (ptr): {
         TestString& s_res = s_str.append (cs.arg ? wsrc : s_str.c_str ());
         res_off = &s_res - &s_str;
@@ -715,7 +672,7 @@
         break;
     }
 
-    case Append (str_off_size): {
+    case Append (str_size_size): {
         TestString& s_res =
             s_str.append (cs.arg ? s_arg : s_str, cs.off, cs.size);
         res_off = &s_res - &s_str;
@@ -735,13 +692,13 @@
 
     // verify the returned value
     rw_assert (0 == res_off, 0, cs.line,
-               "line %d. %s returned invalid reference, offset is %zu",
-               __LINE__, funcall, res_off);
+               "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,
-               "line %d. %s expected %{#*s} with length %zu, got %{/*.*Gs} "
-               "with length %zu", __LINE__, funcall, int (cs.res_len),
+               "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 ());
 
@@ -749,9 +706,9 @@
     const std::size_t match = rw_match (cs.res, s_str.c_str(), cs.res_len);
 
     rw_assert (match == cs.res_len, 0, cs.line,
-               "line %d. %s expected %{#*s}, got %{/*.*Gs}, "
+               "line %d. %{$FUNCALL} expected %{#*s}, got %{/*.*Gs}, "
                "difference at off %zu",
-               __LINE__, funcall, int (cs.res_len), cs.res,
+               __LINE__, int (cs.res_len), cs.res,
                int (sizeof (charT)), int (s_str.size ()), s_str.c_str (),
                match);
 
@@ -773,32 +730,27 @@
 #endif   // _RWSTD_NO_EXCEPTIONS
 
     rw_assert (caught == expected, 0, cs.line,
-               "line %d. %s %{?}expected %s, caught %s"
+               "line %d. %{$FUNCALL} %{?}expected %s, caught %s"
                "%{:}unexpectedly caught %s%{;}",
-               __LINE__, funcall, 0 != expected, expected, caught, caught);
+               __LINE__, 0 != expected, expected, caught, caught);
 }
 
 /**************************************************************************/
 
 static void
-test_append (const MemFun *pfid,
-             const TestCase& cs, bool exc_safety_test)
+test_append (const MemFun &memfun, const TestCase& tcase)
 {
-    // format the description of the function call including
-    // the values of arguments for use in diagnostics
-    char* const funcall =
-        StringMembers::format (pfid->cid_, pfid->tid_,
-                               StringMembers::DefaultAllocator,
-                               cs);
+    // exercise exception safety?
+    const bool exception_safety = -1 == tcase.bthrow;
 
 #undef TEST
-#define TEST(charT, Traits)	                                          \
-    exc_safety_test ?                                                     \
-        test_exceptions (charT (), (Traits*)0, cs, funcall) \
-      : test_append (charT (), (Traits*)0, cs, funcall)
+#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 == pfid->tid_) {
-        if (StringMembers::Char == pfid->cid_)
+    if (StringMembers::DefaultTraits == memfun.traits_id_) {
+        if (StringMembers::Char == memfun.char_id_)
             TEST (char, std::char_traits<char>);
 
 #ifndef _RWSTD_NO_WCHAR_T
@@ -808,101 +760,17 @@
 
     }
     else {
-       if (StringMembers::Char == pfid->cid_)
+       if (StringMembers::Char == memfun.char_id_)
            TEST (char, UserTraits<char>);
 
 #ifndef _RWSTD_NO_WCHAR_T
-       else if (StringMembers::WChar == pfid->cid_)
+       else if (StringMembers::WChar == memfun.char_id_)
            TEST (wchar_t, UserTraits<wchar_t>);
 #endif   // _RWSTD_NO_WCHAR_T
 
        else
            TEST (UserChar, UserTraits<UserChar>);
     }
-
-    std::free (funcall);
-}
-
-/**************************************************************************/
-
-static void
-test_append (const MemFun *pfid, const Test& test)
-{
-    rw_info (0, 0, 0, "std::basic_string<%s, %s<%1$s>, %s<%1$s>>::%s",
-             pfid->cname_, pfid->tname_, pfid->aname_, test.funsig);
-
-    if (StringMembers::opt_no_exception_safety)
-        rw_note (0, 0, 0,
-                 "std::basic_string<%s, %s<%1$s>, %s<%1$s>>::"
-                 "%s exception safety test disabled",
-                 pfid->cname_, pfid->tname_, pfid->aname_, test.funsig);
-
-#ifdef _RWSTD_NO_REPLACEABLE_NEW_DELETE
-
-    else
-        rw_warn (0, 0, __LINE__,
-                 "%s exception safety test: no replacable new and delete",
-                 test.funsig);
-
-#endif  //_RWSTD_NO_REPLACEABLE_NEW_DELETE
-
-    for (std::size_t i = 0; i != test.case_count; ++i) {
-
-        if (!rw_enabled (test.cases [i].line)) {
-            rw_note (0, 0, __LINE__,
-                     "test on line %d disabled", test.cases [i].line);
-            continue;
-        }
-
-        // do not exercise exceptions if they were disabled
-        if (   0 != StringMembers::opt_no_exceptions
-            && 0 != test.cases [i].bthrow)
-            continue;
-
-        // do not exercise exception safety if they were disabled
-        if (   0 != StringMembers::opt_no_exception_safety
-            && -1 == test.cases [i].bthrow)
-            continue;
-
-        test_append (pfid, test.cases [i], -1 == test.cases [i].bthrow);
-    }
-}
-
-
-/**************************************************************************/
-
-static void
-run_test (const MemFun *pfid)
-{
-    if (   StringMembers::UserTraits == pfid->tid_
-        && StringMembers::opt_no_user_traits) {
-        rw_note (1 < StringMembers::opt_no_user_traits++, 0, 0,
-                 "user defined traits test disabled");
-    }
-    else if (   StringMembers::DefaultTraits == pfid->tid_
-             && StringMembers::opt_no_char_traits) {
-        rw_note (1 < StringMembers::opt_no_char_traits++, 0, 0,
-                 "char_traits test disabled");
-    }
-    else {
-
-        if (StringMembers::opt_no_exceptions)
-            rw_note (1 < StringMembers::opt_no_exceptions++, 0, 0,
-                     "string::append exceptions tests disabled");
-
-        static const std::size_t ntests = sizeof tests / sizeof *tests;
-
-        for (std::size_t i = 0; i < ntests; i++) {
-
-            if (Disabled (tests [i].cases [0].which))
-                rw_note (0, 0, 0,
-                         "std::basic_string<%s, %s<%1$s>, %s<%1$s>>::"
-                         "%s test disabled", pfid->cname_, pfid->tname_,
-                         pfid->aname_, tests [i].funsig);
-            else
-                test_append (pfid, tests [i]);
-        }
-    }
 }
 
 /**************************************************************************/
@@ -915,54 +783,28 @@
             LSTR [i] = 'x';
     }
 
-    if (rw_enabled ("char")) {
-
-        MemFun fid (StringMembers::Char, "char",
-                    StringMembers::DefaultTraits, 0);
-
-        fid.tname_ = "char_traits";
-
-        run_test (&fid);
-
-        fid.tid_   = StringMembers::UserTraits;
-        fid.tname_ = "UserTraits";
-
-        run_test (&fid);
-    }
-    else
-        rw_note (0, 0, 0, "string::append char tests disabled");
-
-    if (rw_enabled ("wchar_t")) {
-
-        MemFun fid (StringMembers::WChar, "wchar_t",
-                    StringMembers::DefaultTraits, 0);
-
-        fid.tname_ = "char_traits";
-
-        run_test (&fid);
+    static const StringMembers::Test
+    tests [] = {
 
-        fid.tid_   = StringMembers::UserTraits;
-        fid.tname_ = "UserTraits";
-
-        run_test (&fid);
+#undef TEST
+#define TEST(tag) {                                             \
+        StringMembers::append_ ## tag,                          \
+        tag ## _test_cases,                                     \
+        sizeof tag ## _test_cases / sizeof *tag ## _test_cases  \
     }
-    else
-        rw_note (0, 0, 0, "string::append wchar tests disabled");
 
-    if (StringMembers::opt_no_user_char) {
-        rw_note (0, 0, 0, "user defined chars test disabled");
-    }
-    else {
-        MemFun fid (StringMembers::UChar, "UserChar",
-                    StringMembers::UserTraits, 0);
-        fid.tname_ = "UserTraits";
-        run_test (&fid);
-    }
+        TEST (ptr),
+        TEST (str),
+        TEST (ptr_size),
+        TEST (str_size_size),
+        TEST (size_val),
+        TEST (range)
+    };
 
-    // silence a bogus EDG eccp remark #550-D:
-    // variable "exp_exceptions" was set but never used
-    _RWSTD_UNUSED (exp_exceptions);
+    const std::size_t test_count = sizeof tests / sizeof *tests;
 
+    StringMembers::run_test (test_append, tests, test_count);
+    
     return 0;
 }
 
@@ -983,7 +825,7 @@
                     "|-no-append-ptr# "
                     "|-no-append-str# "
                     "|-no-append-ptr-size# "
-                    "|-no-append-str-off-size# "
+                    "|-no-append-str-size-size# "
                     "|-no-append-size-val# "
                     "|-no-append-range#",
 
@@ -996,7 +838,7 @@
                     &Disabled (Append (ptr)),
                     &Disabled (Append (str)),
                     &Disabled (Append (ptr_size)),
-                    &Disabled (Append (str_off_size)),
+                    &Disabled (Append (str_size_size)),
                     &Disabled (Append (size_val)),
                     &Disabled (Append (range)),
                     // sentinel

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=396375&r1=396374&r2=396375&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp Sun Apr 23 18:58:16 2006
@@ -46,33 +46,12 @@
 #endif   // _RWSTD_NO_REPLACEABLE_NEW_DELETE
 
 
-#define AssignOverload   StringMembers::MemberFunction
+#define AssignOverload   StringMembers::OverloadId
 #define Assign(which)    StringMembers::assign_ ## which
-#define Disabled(which)  StringMembers::opt_memfun_disabled [which]
 
 typedef StringMembers::TestCase TestCase;
 typedef StringMembers::Test     Test;
-
-/**************************************************************************/
-
-struct MemFun
-{
-    typedef StringMembers::charT  charT;
-    typedef StringMembers::Traits Traits;
-
-    MemFun (charT cid, const char *cname,
-          Traits tid, const char *tname)
-        : cid_ (cid), tid_ (tid),
-          cname_ (cname), tname_ (tname), aname_ ("allocator"),
-          fname_ ("assign") { /* empty */ }
-
-    charT       cid_;     // character type id (char or wchar_t)
-    Traits      tid_;     // traits type id (default or user-defined)
-    const char *cname_;   // character type name
-    const char *tname_;   // traits name
-    const char *aname_;   // allocator name
-    const char *fname_;   // function name
-};
+typedef StringMembers::Function MemFun;
 
 /**************************************************************************/
 
@@ -95,7 +74,7 @@
 
 #undef TEST
 #define TEST(str, arg, res, bthrow) {                           \
-        Assign (ptr), __LINE__, -1, -1, -1, -1, -1,             \
+        __LINE__, -1, -1, -1, -1, -1,                           \
         str, sizeof str - 1,                                    \
         arg, sizeof arg - 1, res, sizeof res - 1, bthrow        \
     }
@@ -151,7 +130,7 @@
 
 #undef TEST
 #define TEST(s, arg, res, bthrow) {                             \
-        Assign (str), __LINE__, -1, -1, -1, -1, -1,             \
+        __LINE__, -1, -1, -1, -1, -1,                           \
         s, sizeof s - 1,                                        \
         arg, sizeof arg - 1, res, sizeof res - 1, bthrow        \
     }
@@ -213,7 +192,7 @@
 
 #undef TEST
 #define TEST(str, arg, size, res, bthrow) {                     \
-        Assign (ptr_size), __LINE__, -1, size, -1, -1, -1,      \
+        __LINE__, -1, size, -1, -1, -1,                         \
         str, sizeof str - 1,                                    \
         arg, sizeof arg - 1, res, sizeof res - 1, bthrow        \
     }
@@ -284,11 +263,11 @@
 range_test_cases [] = {
 
 // range_test_cases serves a double duty
-#define str_off_size_test_cases range_test_cases
+#define str_size_size_test_cases range_test_cases
 
 #undef TEST
 #define TEST(str, arg, off, size, res, bthrow) {                \
-        Assign (range), __LINE__, off, size, -1, -1, -1,        \
+        __LINE__, off, size, -1, -1, -1,                        \
         str, sizeof str - 1,                                    \
         arg, sizeof arg - 1, res, sizeof res - 1, bthrow        \
     }
@@ -369,10 +348,10 @@
 size_val_test_cases [] = {
 
 #undef TEST
-#define TEST(str, size, val, res, bthrow) {                     \
-        Assign (size_val), __LINE__, -1, size, -1, -1, val,     \
-        str, sizeof str - 1,                                    \
-        0, 0, res, sizeof res - 1, bthrow                       \
+#define TEST(str, size, val, res, bthrow) {     \
+        __LINE__, -1, size, -1, -1, val,        \
+        str, sizeof str - 1,                    \
+        0, 0, res, sizeof res - 1, bthrow       \
     }
 
     //    +----------------------------------------- controlled sequence
@@ -421,30 +400,10 @@
 
 /**************************************************************************/
 
-static const StringMembers::Test
-tests [] = {
-
-#undef TEST
-#define TEST(tag, sig) {                                        \
-        tag ## _test_cases,                                     \
-        sizeof tag ## _test_cases / sizeof *tag ## _test_cases, \
-        "assign " sig                                           \
-    }
-
-    TEST (ptr,          "(const value_type*)"),
-    TEST (str,          "(const basic_string&)"),
-    TEST (ptr_size,     "(const value_type*, size_type)"),
-    TEST (str_off_size, "(const basic_string&, size_type, size_type)"),
-    TEST (size_val,     "(size_type, value_type)"),
-    TEST (range,        "(InputIterator, InputIterator)")
-};
-
-/**************************************************************************/
-
 template <class charT, class Traits>
 void test_exceptions (charT, Traits*,
-                      const TestCase &cs,
-                      const char     *funcall)
+                      AssignOverload  which,
+                      const TestCase &cs)
 {
     typedef std::allocator<charT>                        Allocator;
     typedef std::basic_string <charT, Traits, Allocator> TestString;
@@ -490,7 +449,7 @@
 #endif   // _RWSTD_NO_EXCEPTIONS
 
         _TRY {
-            switch (cs.which) {
+            switch (which) {
             case Assign (ptr):
                 s_str.assign (arg_ptr);
                 break;
@@ -503,7 +462,7 @@
                 s_str.assign (arg_ptr, cs.size);
                 break;
 
-            case Assign (str_off_size):
+            case Assign (str_size_size):
                 s_str.assign (arg_str, cs.off, cs.size);
                 break;
 
@@ -532,20 +491,20 @@
             // doesn't cause a change in the state of the vector
 
             rw_assert (s_str.size () == size, 0, cs.line,
-                       "line %d: %s: size unexpectedly changed "
+                       "line %d: %{$FUNCALL}: size unexpectedly changed "
                        "from %zu to %zu after an exception",
-                       __LINE__, funcall, size, s_str.size ());
+                       __LINE__, size, s_str.size ());
 
             rw_assert (s_str.capacity () == capacity, 0, cs.line,
-                       "line %d: %s: capacity unexpectedly "
+                       "line %d: %{$FUNCALL}: capacity unexpectedly "
                        "changed from %zu to %zu after an exception",
-                       __LINE__, funcall, capacity, s_str.capacity ());
+                       __LINE__, capacity, s_str.capacity ());
 
 
             rw_assert (s_str.begin () == begin, 0, cs.line,
-                       "line %d: %s: begin() unexpectedly "
+                       "line %d: %{$FUNCALL}: begin() unexpectedly "
                        "changed from after an exception by %d",
-                       __LINE__, funcall, s_str.begin () - begin);
+                       __LINE__, s_str.begin () - begin);
 
 
             // increment to allow this call to operator new to succeed
@@ -565,8 +524,8 @@
     rw_assert (   *pst->throw_at_calls_ [0] == std::size_t (-1)
                || throw_after,
                0, cs.line,
-               "line %d: %s: failed to throw an expected exception",
-               __LINE__, funcall);
+               "line %d: %{$FUNCALL}: failed to throw an expected exception",
+               __LINE__);
 
 #  endif   // _RWSTD_NO_REPLACEABLE_NEW_DELETE
 #else   // if defined (_RWSTD_NO_EXCEPTIONS)
@@ -592,8 +551,7 @@
                         charT          *wsrc,
                         Traits*,
                         const Iterator &it,
-                        const TestCase &cs,
-                        const char     *funcall)
+                        const TestCase &cs)
 {
     typedef std::allocator<charT>                        Allocator;
     typedef std::basic_string <charT, Traits, Allocator> String;
@@ -628,9 +586,9 @@
     const std::size_t match = rw_match (cs.res, s_str.c_str(), cs.res_len);
 
     rw_assert (match == cs.res_len, 0, cs.line,
-               "line %d. %s expected %{#*s}, got %{/*.*Gs}, "
+               "line %d. %{$FUNCALL} expected %{#*s}, got %{/*.*Gs}, "
                "difference at off %zu for %s",
-               __LINE__, funcall, int (cs.res_len), cs.res,
+               __LINE__, int (cs.res_len), cs.res,
                int (sizeof (charT)), int (s_str.size ()), s_str.c_str (),
                match, itname);
 }
@@ -641,14 +599,13 @@
 void test_assign_range (charT          *wstr,
                         charT          *wsrc,
                         Traits*,
-                        const TestCase &cs,
-                        const char     *funcall)
+                        const TestCase &cs)
 {
     if (cs.bthrow)  // this method doesn't throw
         return;
 
     test_assign_range (wstr, wsrc, (Traits*)0,
-                       InputIter<charT>(0, 0, 0), cs, funcall);
+                       InputIter<charT>(0, 0, 0), cs);
 
     // there is no need to call test_assign_range
     // for other iterators in this case
@@ -656,21 +613,21 @@
         return;
 
     test_assign_range (wstr, wsrc, (Traits*)0,
-                       ConstFwdIter<charT>(0, 0, 0), cs, funcall);
+                       ConstFwdIter<charT>(0, 0, 0), cs);
 
     test_assign_range (wstr, wsrc, (Traits*)0,
-                       ConstBidirIter<charT>(0, 0, 0), cs, funcall);
+                       ConstBidirIter<charT>(0, 0, 0), cs);
 
     test_assign_range (wstr, wsrc, (Traits*)0,
-                       ConstRandomAccessIter<charT>(0, 0, 0), cs, funcall);
+                       ConstRandomAccessIter<charT>(0, 0, 0), cs);
 }
 
 /**************************************************************************/
 
 template <class charT, class Traits>
 void test_assign (charT, Traits*,
-                  const TestCase       &cs,
-                  const char           *funcall)
+                  AssignOverload  which,
+                  const TestCase &cs)
 {
     typedef std::allocator<charT>                        Allocator;
     typedef std::basic_string <charT, Traits, Allocator> TestString;
@@ -683,8 +640,8 @@
     rw_widen (wsrc, cs.arg, cs.arg_len);
 
     // special processing for assign_range to exercise all iterators
-    if (Assign (range) == cs.which) {
-        test_assign_range (wstr, wsrc, (Traits*)0, cs, funcall);
+    if (Assign (range) == which) {
+        test_assign_range (wstr, wsrc, (Traits*)0, cs);
         return;
     }
 
@@ -705,7 +662,7 @@
 
     // is some exception expected ?
     const char* expected = 0;
-    if (1 == cs.bthrow && Assign (str_off_size) == cs.which)
+    if (1 == cs.bthrow && Assign (str_size_size) == which)
         expected = exp_exceptions [1];
     if (2 == cs.bthrow)
         expected = exp_exceptions [2];
@@ -721,7 +678,7 @@
 
 #endif   // _RWSTD_NO_EXCEPTIONS
 
-    switch (cs.which) {
+    switch (which) {
     case Assign (ptr):
         res_ptr = &s_str.assign (arg_ptr);
         break;
@@ -734,7 +691,7 @@
         res_ptr = &s_str.assign (arg_ptr, size);
         break;
 
-    case Assign (str_off_size):
+    case Assign (str_size_size):
         res_ptr = &s_str.assign (arg_str, cs.off, size);
         break;
 
@@ -752,13 +709,13 @@
 
     // verify the returned value
     rw_assert (0 == res_off, 0, cs.line,
-               "line %d. %s returned invalid reference, offset is %zu",
-               __LINE__, funcall, res_off);
+               "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,
-               "line %d. %s expected %{#*s} with length %zu, got %{/*.*Gs} "
-               "with length %zu", __LINE__, funcall, int (cs.res_len),
+               "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 ());
 
@@ -766,9 +723,9 @@
     const std::size_t match = rw_match (cs.res, s_str.c_str(), cs.res_len);
 
     rw_assert (match == cs.res_len, 0, cs.line,
-               "line %d. %s expected %{#*s}, got %{/*.*Gs}, "
+               "line %d. %{$FUNCALL}: expected %{#*s}, got %{/*.*Gs}, "
                "difference at off %zu",
-               __LINE__, funcall, int (cs.res_len), cs.res,
+               __LINE__, int (cs.res_len), cs.res,
                int (sizeof (charT)), int (s_str.size ()), s_str.c_str (),
                match);
 
@@ -790,31 +747,27 @@
 #endif   // _RWSTD_NO_EXCEPTIONS
 
     rw_assert (caught == expected, 0, cs.line,
-               "line %d. %s %{?}expected %s, caught %s"
+               "line %d. %{$FUNCALL}: %{?}expected %s, caught %s"
                "%{:}unexpectedly caught %s%{;}",
-               __LINE__, funcall, 0 != expected, expected, caught, caught);
+               __LINE__, 0 != expected, expected, caught, caught);
 }
 
 /**************************************************************************/
 
 static void
-test_assign (const MemFun *pfid, const TestCase& cs, bool exc_safety_test)
+test_assign (const MemFun &memfun, const TestCase& tcase)
 {
-    // format the description of the function call including
-    // the values of arguments for use in diagnostics
-    char* const funcall =
-        StringMembers::format (pfid->cid_, pfid->tid_,
-                               StringMembers::DefaultAllocator,
-                               cs);
+    // exercise exception safety?
+    const bool exception_safety = -1 == tcase.bthrow;
 
 #undef TEST
-#define TEST(charT, Traits)                                     \
-    exc_safety_test ?                                           \
-        test_exceptions (charT (), (Traits*)0, cs, funcall)     \
-      : test_assign (charT (), (Traits*)0, cs, funcall)
+#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 == pfid->tid_) {
-        if (StringMembers::Char == pfid->cid_)
+    if (StringMembers::DefaultTraits == memfun.traits_id_) {
+        if (StringMembers::Char == memfun.char_id_)
             TEST (char, std::char_traits<char>);
 
 #ifndef _RWSTD_NO_WCHAR_T
@@ -824,101 +777,17 @@
 
     }
     else {
-       if (StringMembers::Char == pfid->cid_)
+       if (StringMembers::Char == memfun.char_id_)
            TEST (char, UserTraits<char>);
 
 #ifndef _RWSTD_NO_WCHAR_T
-       else if (StringMembers::WChar == pfid->cid_)
+       else if (StringMembers::WChar == memfun.char_id_)
            TEST (wchar_t, UserTraits<wchar_t>);
 #endif   // _RWSTD_NO_WCHAR_T
 
        else
            TEST (UserChar, UserTraits<UserChar>);
     }
-
-    std::free (funcall);
-}
-
-/**************************************************************************/
-
-static void
-test_assign (const MemFun *pfid, const Test& test)
-{
-    rw_info (0, 0, 0, "std::basic_string<%s, %s<%1$s>, %s<%1$s>>::%s",
-             pfid->cname_, pfid->tname_, pfid->aname_, test.funsig);
-
-    if (StringMembers::opt_no_exception_safety)
-        rw_note (0, 0, 0,
-                 "std::basic_string<%s, %s<%1$s>, %s<%1$s>>::"
-                 "%s exception safety test disabled",
-                 pfid->cname_, pfid->tname_, pfid->aname_, test.funsig);
-
-#ifdef _RWSTD_NO_REPLACEABLE_NEW_DELETE
-
-    else
-        rw_warn (0, 0, __LINE__,
-                 "%s exception safety test: no replacable new and delete",
-                 test.funsig);
-
-#endif  //_RWSTD_NO_REPLACEABLE_NEW_DELETE
-
-    for (std::size_t i = 0; i != test.case_count; ++i) {
-
-        if (!rw_enabled (test.cases [i].line)) {
-            rw_note (0, 0, __LINE__,
-                     "test on line %d disabled", test.cases [i].line);
-            continue;
-        }
-
-        // do not exercise exceptions if they were disabled
-        if (   0 != StringMembers::opt_no_exceptions
-            && 0 != test.cases [i].bthrow)
-            continue;
-
-        // do not exercise exception safety if they were disabled
-        if (   0 != StringMembers::opt_no_exception_safety
-            && -1 == test.cases [i].bthrow)
-            continue;
-
-        test_assign (pfid, test.cases [i], -1 == test.cases [i].bthrow);
-    }
-}
-
-
-/**************************************************************************/
-
-static void
-run_test (const MemFun *pfid)
-{
-    if (   StringMembers::UserTraits == pfid->tid_
-        && StringMembers::opt_no_user_traits) {
-        rw_note (1 < StringMembers::opt_no_user_traits++, 0, 0,
-                 "user defined traits test disabled");
-    }
-    else if (   StringMembers::DefaultTraits == pfid->tid_
-             && StringMembers::opt_no_char_traits) {
-        rw_note (1 < StringMembers::opt_no_char_traits++, 0, 0,
-                 "char_traits test disabled");
-    }
-    else {
-
-        if (StringMembers::opt_no_exceptions)
-            rw_note (1 < StringMembers::opt_no_exceptions++, 0, 0,
-                     "string::assign exceptions tests disabled");
-
-        static const std::size_t ntests = sizeof tests / sizeof *tests;
-
-        for (std::size_t i = 0; i < ntests; i++) {
-
-            if (Disabled (tests [i].cases [0].which))
-                rw_note (0, 0, 0,
-                         "std::basic_string<%s, %s<%1$s>, %s<%1$s>>::"
-                         "%s test disabled", pfid->cname_, pfid->tname_,
-                         pfid->aname_, tests [i].funsig);
-            else
-                test_assign (pfid, tests [i]);
-        }
-    }
 }
 
 /**************************************************************************/
@@ -932,53 +801,27 @@
             LSTR [i] = 'x';
     }
 
-    if (rw_enabled ("char")) {
-
-        MemFun fid (StringMembers::Char, "char",
-                    StringMembers::DefaultTraits, 0);
-
-        fid.tname_ = "char_traits";
+    static const StringMembers::Test
+    tests [] = {
 
-        run_test (&fid);
-
-        fid.tid_   = StringMembers::UserTraits;
-        fid.tname_ = "UserTraits";
-
-        run_test (&fid);
+#undef TEST
+#define TEST(tag) {                                             \
+        StringMembers::assign_ ## tag,                          \
+        tag ## _test_cases,                                     \
+        sizeof tag ## _test_cases / sizeof *tag ## _test_cases  \
     }
-    else
-        rw_note (0, 0, 0, "string::assign char tests disabled");
-
-    if (rw_enabled ("wchar_t")) {
-
-        MemFun fid (StringMembers::WChar, "wchar_t",
-                    StringMembers::DefaultTraits, 0);
-
-        fid.tname_ = "char_traits";
 
-        run_test (&fid);
+        TEST (ptr),
+        TEST (str),
+        TEST (ptr_size),
+        TEST (str_size_size),
+        TEST (size_val),
+        TEST (range)
+    };
 
-        fid.tid_   = StringMembers::UserTraits;
-        fid.tname_ = "UserTraits";
-
-        run_test (&fid);
-    }
-    else
-        rw_note (0, 0, 0, "string::assign wchar tests disabled");
-
-    if (StringMembers::opt_no_user_char) {
-        rw_note (0, 0, 0, "user defined chars test disabled");
-    }
-    else {
-        MemFun fid (StringMembers::UChar, "UserChar",
-                    StringMembers::UserTraits, 0);
-        fid.tname_ = "UserTraits";
-        run_test (&fid);
-    }
+    const std::size_t test_count = sizeof tests / sizeof *tests;
 
-    // silence a bogus EDG eccp remark #550-D:
-    // variable "exp_exceptions" was set but never used
-    _RWSTD_UNUSED (exp_exceptions);
+    StringMembers::run_test (test_assign, tests, test_count);
 
     return 0;
 }
@@ -1000,7 +843,7 @@
                     "|-no-assign-ptr# "
                     "|-no-assign-str# "
                     "|-no-assign-ptr-size# "
-                    "|-no-assign-str-off-size# "
+                    "|-no-assign-str-size-size# "
                     "|-no-assign-size-val# "
                     "|-no-assign-range#",
 
@@ -1013,7 +856,7 @@
                     &Disabled (Assign (ptr)),
                     &Disabled (Assign (str)),
                     &Disabled (Assign (ptr_size)),
-                    &Disabled (Assign (str_off_size)),
+                    &Disabled (Assign (str_size_size)),
                     &Disabled (Assign (size_val)),
                     &Disabled (Assign (range)),
                     // sentinel



Mime
View raw message