stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ant...@apache.org
Subject svn commit: r414235 - in /incubator/stdcxx/trunk/tests: src/21.strings.cpp strings/21.string.cons.cpp
Date Wed, 14 Jun 2006 13:11:31 GMT
Author: antonp
Date: Wed Jun 14 06:11:31 2006
New Revision: 414235

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

	* 21.strings.cpp (_rw_setvars): ctor_range and ctor_range_alloc 
	cases joined with append_range and assign_range
	* 21.string.cons.cpp: Ctor replaced with Cons according to 
	the naming conventions.
	(ConsRange, ConsRangeOverload): New class templates to abstract out 
	the invocation of the ctor member template and its overloads.
	(test_cons): Added RangeBase& argument and eliminated
	test_cons_range (obviated by the addition of the argument).
	(test_cons): Dispatched to the appropriate specialization
	based on the iterator id (if any).

Modified:
    incubator/stdcxx/trunk/tests/src/21.strings.cpp
    incubator/stdcxx/trunk/tests/strings/21.string.cons.cpp

Modified: incubator/stdcxx/trunk/tests/src/21.strings.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/21.strings.cpp?rev=414235&r1=414234&r2=414235&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/21.strings.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/21.strings.cpp Wed Jun 14 06:11:31 2006
@@ -661,17 +661,6 @@
 
     case StringIds::append_range:
     case StringIds::assign_range:
-        rw_asnprintf (&buf, &bufsize, "%{+}<%{$Iterator:-Iterator}>("
-                      "%{?}begin()%{:}%{$Iterator:-Iterator}(%{#*s})%{;}"
-                      "%{?} + %zu%{;}, "
-                      "%{?}begin()%{:}%{$Iterator:-Iterator}(...)%{;}"
-                      "%{?} + %zu%{;}"
-                      "%{?}, const allocator_type&%{;})",
-                      self, int (arg_len), arg,
-                      0 != pcase->off2, pcase->off2,
-                      self, 0 != range2_end, range2_end, use_alloc);
-        break;
-
     case StringIds::ctor_range:
     case StringIds::ctor_range_alloc:
         rw_asnprintf (&buf, &bufsize, "%{+}<%{$Iterator:-Iterator}>("
@@ -681,8 +670,8 @@
                       "%{?} + %zu%{;}"
                       "%{?}, const allocator_type&%{;})",
                       self, int (arg_len), arg,
-                      0 != pcase->off, pcase->off,
-                      self, 0 != range1_end, range1_end, use_alloc);
+                      0 != pcase->off2, pcase->off2,
+                      self, 0 != range2_end, range2_end, use_alloc);
         break;
 
     case StringIds::insert_size_cptr:

Modified: incubator/stdcxx/trunk/tests/strings/21.string.cons.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/strings/21.string.cons.cpp?rev=414235&r1=414234&r2=414235&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.cons.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.cons.cpp Wed Jun 14 06:11:31 2006
@@ -33,7 +33,7 @@
 /**************************************************************************/
 
 // for convenience and brevity
-#define Ctor(sig)               StringIds::ctor_ ## sig
+#define Cons(sig)               StringIds::ctor_ ## sig
 #define OpSet(sig)              StringIds::op_set_ ## sig
 
 static const char* const exceptions[] = {
@@ -277,7 +277,7 @@
 
 #undef TEST
 #define TEST(arg, off, size, res, bthrow) {         \
-        __LINE__, off, size, -1, -1, -1,            \
+        __LINE__, -1, -1, off, size, -1,            \
         0, 0, arg, sizeof arg - 1,                  \
         res, sizeof res - 1, bthrow                 \
     }
@@ -317,8 +317,8 @@
     TEST ("x@3695",    10, 2284, "x@2284",    0),
     TEST ("x@4096",     0, 4096, "x@4096",    0),     
 
-    TEST ("abc",        5,  3, "abc",         1), 
-    TEST ("x@4096",  4106,  3, "xxx",         1), 
+    TEST ("abc",        5,  3,   "",          1), 
+    TEST ("x@4096",  4106,  3,   "",          1), 
 
     TEST ("last test",  0,  9, "last test",   0)
 };
@@ -527,95 +527,93 @@
     TEST ("",       't',  "t") 
 };
 
-
 /**************************************************************************/
 
-template <class charT, class Traits, class Allocator, class Iterator>
-void test_ctor_range (const StringTestCaseData<charT> &tdata,
-                      Traits*, Allocator*, const Iterator &it)
-{
-    typedef std::basic_string <charT, Traits, Allocator> String;
-    typedef typename String::iterator                    StringIter;
-
-    const StringTestCase &tcase = tdata.tcase_;
-
-    const char* const itname =
-        tcase.arg ? type_name (it, (charT*)0) : "basic_string::iterator";
-
-    // construct the string argument 
-    /* const */ String arg (tdata.arg_, tdata.arglen_);
-
-    std::size_t off1 = std::size_t (tcase.off) < tdata.arglen_ ?
-             std::size_t (tcase.off) : tdata.arglen_;
-
-    std::size_t ext1 = off1 + tcase.size < tdata.arglen_ ?
-             std::size_t (tcase.size) : tdata.arglen_ - off1;
+// invokes specializations of the member function template
+// on the required iterator categories
+template <class String, class Iterator>
+struct ConsRange: RangeBase<String> {
+
+    typedef typename String::iterator       StringIter;
+    typedef typename String::value_type     StringChar;
+    typedef typename String::allocator_type StringAlloc;
+
+    ConsRange () { }
+
+    virtual String&
+    operator() (String&, const StringTestCaseData<StringChar>& tdata) const
{
+
+        const StringChar* const beg = tdata.arg_ + tdata.off2_;
+        const StringChar* const end = beg + tdata.ext2_;
+
+        const Iterator first (beg, beg, end);
+        const Iterator last  (end, beg, end);
+
+        if (Cons (range_alloc) == tdata.func_.which_) {
+            StringAlloc alloc;
+            String* tmp = new String (first, last, alloc);
+            return *tmp;
+        }
 
-    // create a pair of iterators into the string object being modified
-    const StringIter it_first (arg.begin () + off1);
-    const StringIter it_last  (it_first + ext1);
-
-    const String str (it_first, it_last);
-
-    // detrmine whether the produced sequence matches the exepceted result
-    const std::size_t match = rw_match (tcase.res, str.data (), tcase.nres);
-
-    rw_assert (match == tdata.reslen_, 0, tcase.line,
-               "line %d. %{$FUNCALL} expected %{#*s}, got %{/*.*Gs}, "
-               "difference at offset %zu for %s",
-               __LINE__, int (tcase.nres), tcase.res,
-               int (sizeof (charT)), int (str.size ()), str.c_str (),
-               match, itname);
-}
+        String* tmp = new String (first, last);
+        return *tmp;
+    }
+};
 
 /**************************************************************************/
 
-template <class charT, class Traits, class Allocator>
-void test_ctor_range (const StringTestCaseData<charT> &tdata,
-                      Traits*, Allocator*)
+// invokes possible overloads of the member function template
+// on common RandomAccessIterator types
+template <class String, class Iterator>
+struct ConsRangeOverload: RangeBase<String>
 {
-    if (tdata.tcase_.bthrow) {
-        return;
-    }
-
-    test_ctor_range (tdata, (Traits*)0, (Allocator*)0, 
-                     InputIter<charT>(0, 0, 0));
-
-    test_ctor_range (tdata, (Traits*)0, (Allocator*)0,
-                     ConstFwdIter<charT>(0, 0, 0));
-
-    test_ctor_range (tdata, (Traits*)0, (Allocator*)0,
-                     ConstBidirIter<charT>(0, 0, 0));
+    typedef typename String::iterator       StringIter;
+    typedef typename String::value_type     StringChar;
+    typedef typename String::allocator_type StringAlloc;
+
+    ConsRangeOverload () { }
+
+    virtual String&
+    operator() (String& str_arg, 
+                const StringTestCaseData<StringChar>& tdata) const {
+
+        const std::size_t off = tdata.off2_;
+        const std::size_t ext = tdata.ext2_;
+
+        const Iterator first (begin (str_arg, (Iterator*)0) + off);
+        const Iterator last (first + ext);
+
+        if (Cons (range_alloc) == tdata.func_.which_) {
+            StringAlloc alloc;
+            String* tmp = new String (first, last, alloc);
+            return *tmp;
+        }
 
-    test_ctor_range (tdata, (Traits*)0, (Allocator*)0,
-                     ConstRandomAccessIter<charT>(0, 0, 0));
-}
+        String* tmp = new String (first, last);
+        return *tmp;
+    }
+};
 
 /**************************************************************************/
 
 template <class charT, class Traits, class Allocator>
-void test_ctor (charT*, Traits*, Allocator*,
-                const StringTestCaseData<charT> &tdata)
+void test_cons (charT*, Traits*, Allocator*, const RangeBase<
+                    std::basic_string <charT, Traits, Allocator> > &rng,
+                const StringTestCaseData<charT>                    &tdata)
 {
     typedef std::basic_string <charT, Traits, Allocator> String;
 
     const StringFunc     &func  = tdata.func_;
     const StringTestCase &tcase = tdata.tcase_;
 
-    if (Ctor (range) == func.which_) {
-        // special processing for the ctor() template member
-        // function to exercise all iterator categories
-        test_ctor_range (tdata, (Traits*)0, (Allocator*)0);
-        return;
-    }
-
     // construct the argument string 
-    const String arg (tdata.arg_, tdata.arglen_);
+    /* const */ String arg (tdata.arg_, tdata.arglen_);
 
     // offset and extent function arguments
-    // offset and extent function arguments
-    const std::size_t arg_off  = std::size_t (tcase.off);
-    const std::size_t arg_size = std::size_t (tcase.size);
+    const std::size_t arg_off  = -1 != tcase.off ? 
+        std::size_t (tcase.off) : std::size_t (tcase.off2);
+    const std::size_t arg_size = -1 != tcase.size ? 
+        std::size_t (tcase.size) : std::size_t (tcase.size2);
 
     // string function argument
     const charT* const arg_ptr = arg.c_str ();
@@ -629,7 +627,8 @@
 
 #ifndef _RWSTD_NO_EXCEPTIONS
 
-    if (1 == tcase.bthrow)
+    if (1 == tcase.bthrow && Cons (range) != func.which_ 
+                          && Cons (range_alloc) != func.which_)
         expected = exceptions [1];      // out_of_range
     else if (2 == tcase.bthrow)
         expected = exceptions [2];      // length_error
@@ -650,54 +649,62 @@
     try {
         switch (func.which_) {
 
-        case Ctor (void):
+        case Cons (void):
             ret_ptr = new String ();
             break;
 
-        case Ctor (alloc):
+        case Cons (alloc):
             ret_ptr = new String (arg_alc);
             break;
 
-        case Ctor (cptr):
+        case Cons (cptr):
             ret_ptr = new String (arg_ptr);
             break;
 
-        case Ctor (cptr_alloc):
+        case Cons (cptr_alloc):
             ret_ptr = new String (arg_ptr, arg_alc);
             break;
 
-        case Ctor (cstr):
+        case Cons (cstr):
             ret_ptr = new String (arg_str);
             break;
 
-        case Ctor (cptr_size):
+        case Cons (cptr_size):
             ret_ptr = new String (arg_ptr, arg_size);
             break;
 
-        case Ctor (cptr_size_alloc):
+        case Cons (cptr_size_alloc):
             ret_ptr = new String (arg_ptr, arg_size, arg_alc);
             break;
 
-        case Ctor (cstr_size):
+        case Cons (cstr_size):
             ret_ptr = new String (arg_str, arg_off);
             break;
 
-        case Ctor (cstr_size_size):
+        case Cons (cstr_size_size):
             ret_ptr = new String (arg_str, arg_off, arg_size);
             break;
 
-        case Ctor (cstr_size_size_alloc):
+        case Cons (cstr_size_size_alloc):
             ret_ptr = new String (arg_str, arg_off, arg_size, arg_alc);
             break;
 
-        case Ctor (size_val):
+        case Cons (size_val):
             ret_ptr = new String (tcase.size, arg_val);
             break;
 
-        case Ctor (size_val_alloc):
+        case Cons (size_val_alloc):
             ret_ptr = new String (tcase.size, arg_val, arg_alc);
             break;
 
+        case Cons (range):
+            ret_ptr = &rng (arg, tdata);
+            break;
+
+        case Cons (range_alloc):
+            ret_ptr = &rng (arg, tdata);
+            break;
+
         default:
             RW_ASSERT (!"logic error: unknown constructor overload");
         }
@@ -721,7 +728,7 @@
                        tdata.reslen_, cwidth, int (ret_ptr->size ()), 
                        ret_ptr->data (), ret_ptr->size ());
 
-            if (Ctor (void) != func.which_) {
+            if (Cons (void) != func.which_) {
                 // verify the capacity of the resulting string
                 rw_assert (ret_ptr->size () <= ret_ptr->capacity (), 0, 
                            tcase.line, "line %d. %{$FUNCALL} expected "
@@ -1020,10 +1027,67 @@
 void test_cons (charT*, Traits*, Allocator*,
                 const StringTestCaseData<charT> &tdata)
 {
-    if (StringIds::fid_op_set == (tdata.func_.which_ & StringIds::fid_mask))
+    typedef std::basic_string<charT, Traits, Allocator> String;
+
+    if (StringIds::fid_op_set == (tdata.func_.which_ & StringIds::fid_mask)) {
         test_op_set ((charT*)0, (Traits*)0, (Allocator*)0, tdata);
-    else
-        test_ctor ((charT*)0, (Traits*)0, (Allocator*)0, tdata);
+        return;
+    }
+
+    if (tdata.func_.which_ == Cons (range) 
+        || tdata.func_.which_ == Cons (range_alloc)) {
+
+        switch (tdata.func_.iter_id_) {
+
+        // exercise possible overloads of the member function template
+        // on common RandomAccessIterator types
+#undef TEST
+#define TEST(Iterator) do {                                                 \
+        typedef typename String::Iterator Iter;                             \
+        static const                                                        \
+        ConsRangeOverload<String, Iter> rng;                                \
+        test_cons ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata);       \
+    } while (0)
+
+        case StringIds::Pointer: TEST (pointer); break;
+        case StringIds::ConstPointer: TEST (const_pointer); break;
+        case StringIds::Iterator: TEST (iterator); break;
+        case StringIds::ConstIterator: TEST (const_iterator); break;
+
+            // disabled for now
+        case StringIds::ReverseIterator:
+            // TEST (reverse_iterator);
+            break;
+
+        case StringIds::ConstReverseIterator:
+            // TEST (const_reverse_iterator);
+            break;
+
+        // exercise specializations of the member function template
+        // on the required iterator categories
+
+#undef TEST
+#define TEST(Iterator) do {                                                 \
+        typedef Iterator<charT> Iter;                                       \
+        static const                                                        \
+        ConsRange<String, Iter> rng;                                        \
+        test_cons ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata);       \
+    } while (0)
+
+        case StringIds::Input: TEST (InputIter); break;
+        case StringIds::Forward: TEST (ConstFwdIter); break;
+        case StringIds::Bidir: TEST (ConstBidirIter); break;
+        case StringIds::Random: TEST (ConstRandomAccessIter); break;
+
+        default:
+            rw_error (0, 0, __LINE__, "bad iterator id");
+        }
+    }
+    else {
+        // exercise ordinary overloads of the member function
+        static const RangeBase<String> rng;
+        test_cons ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata);
+    }
 }
 
 /**************************************************************************/
@@ -1037,7 +1101,7 @@
 
 #undef TEST
 #define TEST(sig) {                                             \
-        Ctor (sig), sig ## _test_cases,                         \
+        Cons (sig), sig ## _test_cases,                         \
         sizeof sig ## _test_cases / sizeof *sig ## _test_cases  \
     }
 



Mime
View raw message