stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ant...@apache.org
Subject svn commit: r414577 - in /incubator/stdcxx/trunk/tests: src/21.strings.cpp strings/21.string.append.cpp strings/21.string.assign.cpp strings/21.string.cons.cpp strings/21.string.insert.cpp strings/21.string.replace.cpp
Date Thu, 15 Jun 2006 13:30:40 GMT
Author: antonp
Date: Thu Jun 15 06:30:39 2006
New Revision: 414577

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

	* 21.strings.cpp (_rw_reverse_results): new helper function to 
	reverse the substring in the resulting sequence
	(_rw_dispatch): updated to reverse the resulting substring for
	the reverse iterators via call to the helper function.
	* 21.string.append.cpp (AppendRangeOverload): Added special
	processing for the reverse iterators.
	(test_append): reverse iterators tests enabled, range classes
	variables renamed for the convenience.
	* 21.string.assign.cpp: Same
	* 21.string.cons.cpp: Same
	* 21.string.insert.cpp: Same
	* 21.string.replace.cpp: Same

Modified:
    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.cons.cpp
    incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp
    incubator/stdcxx/trunk/tests/strings/21.string.replace.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=414577&r1=414576&r2=414577&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/21.strings.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/21.strings.cpp Thu Jun 15 06:30:39 2006
@@ -987,6 +987,40 @@
 
 /**************************************************************************/
 
+// helper function to reverse substring in the resulting sequence
+static
+StringTestCase _rw_reverse_results (const StringTestCase &tsrc,
+                                    _RWSTD_SIZE_T off, _RWSTD_SIZE_T ext)
+{
+    // expand expected results
+    char *new_res = 0;
+    _RWSTD_SIZE_T res_len = 0;
+    new_res = rw_expand (new_res, tsrc.res, tsrc.nres, &res_len);
+
+    // reverse them
+    _RWSTD_SIZE_T res_off = off;
+    _RWSTD_SIZE_T res_ext = (ext < res_len ? ext : res_len) - 1;
+
+    char* beg = new_res + res_off;
+    char* end = beg + res_ext;
+
+    for (; beg < end; ++beg, --end) {
+        char tmp = *beg;
+        *beg = *end;
+        *end = tmp;
+    }
+
+    // form new test case
+    StringTestCase new_case = { 
+        tsrc.line, tsrc.off, tsrc.size, tsrc.off2,
+        tsrc.size2, tsrc.val, tsrc.str, tsrc.str_len, 
+        tsrc.arg, tsrc.arg_len, new_res, res_len, tsrc.bthrow 
+    };
+
+    return new_case;
+}
+
+
 template <class charT, class Traits, class Allocator>
 void
 _rw_dispatch (charT*, Traits*, Allocator*,
@@ -1001,9 +1035,34 @@
 
     TestFunc* const tfunc = _RWSTD_REINTERPRET_CAST (TestFunc*, farray [inx]);
 
+    bool reverse_iter = StringIds::ReverseIterator == func.iter_id_ 
+        || StringIds::ConstReverseIterator == func.iter_id_;
+
     const Data tdata (func, tcase);
 
-    tfunc ((charT*)0, (Traits*)0, (Allocator*)0, tdata);
+    // special processing for the reverse iterators
+    if (reverse_iter) {
+
+        _RWSTD_SIZE_T func_id = tdata.func_.which_ & StringIds::fid_mask;
+        bool like_ctor = StringIds::fid_ctor == func_id 
+            || StringIds::fid_assign == func_id;
+
+        // ctor and assign require the full string reverse
+        _RWSTD_SIZE_T off = like_ctor ? 0 : tdata.off1_;
+        _RWSTD_SIZE_T ext = like_ctor ? tdata.reslen_ : tdata.ext2_;
+
+        StringTestCase rev_tcase = _rw_reverse_results (tcase, off, ext);
+
+        const Data rev_tdata (func, rev_tcase);
+
+        tfunc ((charT*)0, (Traits*)0, (Allocator*)0, rev_tdata);
+
+        // clean up allocated memory, if any
+        if (0 != rev_tcase.res) 
+            delete[] rev_tcase.res;
+    }
+    else
+        tfunc ((charT*)0, (Traits*)0, (Allocator*)0, tdata);
 }
 
 

Modified: incubator/stdcxx/trunk/tests/strings/21.string.append.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/strings/21.string.append.cpp?rev=414577&r1=414576&r2=414577&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.append.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.append.cpp Thu Jun 15 06:30:39 2006
@@ -534,7 +534,13 @@
 
         const StringTestCase &tcase = tdata.tcase_;
 
-        const std::size_t off = tdata.off2_;
+        bool reverse_iter = StringIds::ReverseIterator == tdata.func_.iter_id_
+            || StringIds::ConstReverseIterator == tdata.func_.iter_id_;
+
+        const std::size_t srclen_ = tcase.arg ? tdata.arglen_ : str.size ();
+
+        const std::size_t off = 
+            reverse_iter ? srclen_ - tdata.off2_ - tdata.ext2_ : tdata.off2_;
         const std::size_t ext = tdata.ext2_;
 
         if (0 == tcase.arg) {
@@ -838,8 +844,8 @@
 #define TEST(Iterator) do {                                                 \
         typedef typename String::Iterator Iter;                             \
         static const                                                        \
-        AppendRangeOverload<String, Iter> app;                              \
-        test_append ((charT*)0, (Traits*)0, (Allocator*)0, app, tdata);     \
+        AppendRangeOverload<String, Iter> rng;                              \
+        test_append ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata);     \
     } while (0)
 
         case StringIds::Pointer: TEST (pointer); break;
@@ -847,13 +853,8 @@
         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);
+        case StringIds::ReverseIterator: TEST (reverse_iterator); break;
+        case StringIds::ConstReverseIterator: TEST (const_reverse_iterator);
             break;
 
         // exercise specializations of the member function template
@@ -863,8 +864,8 @@
 #define TEST(Iterator) do {                                                 \
         typedef Iterator<charT> Iter;                                       \
         static const                                                        \
-        AppendRange<String, Iter> app;                                      \
-        test_append ((charT*)0, (Traits*)0, (Allocator*)0, app, tdata);     \
+        AppendRange<String, Iter> rng;                                      \
+        test_append ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata);     \
     } while (0)
 
         case StringIds::Input: TEST (InputIter); break;
@@ -878,8 +879,8 @@
     }
     else {
         // exercise ordinary overloads of the member function
-        static const RangeBase<String > app;
-        test_append ((charT*)0, (Traits*)0, (Allocator*)0, app, tdata);
+        static const RangeBase<String > rng;
+        test_append ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata);
     }
 }
 

Modified: incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp?rev=414577&r1=414576&r2=414577&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp Thu Jun 15 06:30:39 2006
@@ -480,7 +480,13 @@
 
         const StringTestCase &tcase = tdata.tcase_;
 
-        const std::size_t off = tdata.off2_;
+        bool reverse_iter = StringIds::ReverseIterator == tdata.func_.iter_id_
+            || StringIds::ConstReverseIterator == tdata.func_.iter_id_;
+
+        const std::size_t srclen_ = tcase.arg ? tdata.arglen_ : str.size ();
+
+        const std::size_t off = 
+            reverse_iter ? srclen_ - tdata.off2_ - tdata.ext2_ : tdata.off2_;
         const std::size_t ext = tdata.ext2_;
 
         if (0 == tcase.arg) {
@@ -791,8 +797,8 @@
 #define TEST(Iterator) do {                                                 \
         typedef typename String::Iterator Iter;                             \
         static const                                                        \
-        AssignRangeOverload<String, Iter> app;                              \
-        test_assign ((charT*)0, (Traits*)0, (Allocator*)0, app, tdata);     \
+        AssignRangeOverload<String, Iter> rng;                              \
+        test_assign ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata);     \
     } while (0)
 
         case StringIds::Pointer: TEST (pointer); break;
@@ -800,13 +806,8 @@
         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);
+        case StringIds::ReverseIterator: TEST (reverse_iterator); break;
+        case StringIds::ConstReverseIterator: TEST (const_reverse_iterator);
             break;
 
         // exercise specializations of the member function template
@@ -816,8 +817,8 @@
 #define TEST(Iterator) do {                                                 \
         typedef Iterator<charT> Iter;                                       \
         static const                                                        \
-        AssignRange<String, Iter> app;                                      \
-        test_assign ((charT*)0, (Traits*)0, (Allocator*)0, app, tdata);     \
+        AssignRange<String, Iter> rng;                                      \
+        test_assign ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata);     \
     } while (0)
 
         case StringIds::Input: TEST (InputIter); break;
@@ -831,8 +832,8 @@
     }
     else {
         // exercise ordinary overloads of the member function
-        static const RangeBase<String> app;
-        test_assign ((charT*)0, (Traits*)0, (Allocator*)0, app, tdata);
+        static const RangeBase<String> rng;
+        test_assign ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata);
     }
 }
 

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=414577&r1=414576&r2=414577&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.cons.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.cons.cpp Thu Jun 15 06:30:39 2006
@@ -577,7 +577,11 @@
     operator() (String& str_arg, 
                 const StringTestCaseData<StringChar>& tdata) const {
 
-        const std::size_t off = tdata.off2_;
+        bool reverse_iter = StringIds::ReverseIterator == tdata.func_.iter_id_
+            || StringIds::ConstReverseIterator == tdata.func_.iter_id_;
+
+        const std::size_t off = reverse_iter ? 
+            tdata.arglen_ - tdata.off2_ - tdata.ext2_ : tdata.off2_;
         const std::size_t ext = tdata.ext2_;
 
         const Iterator first (begin (str_arg, (Iterator*)0) + off);
@@ -1054,13 +1058,8 @@
         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);
+        case StringIds::ReverseIterator: TEST (reverse_iterator); break;
+        case StringIds::ConstReverseIterator: TEST (const_reverse_iterator);
             break;
 
         // exercise specializations of the member function template

Modified: incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp?rev=414577&r1=414576&r2=414577&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp Thu Jun 15 06:30:39 2006
@@ -603,7 +603,13 @@
         // create a pair of iterators into the string object being modified
         const StringIter first1 (str.begin () + tdata.off1_);
 
-        const std::size_t off = tdata.off2_;
+        bool reverse_iter = StringIds::ReverseIterator == tdata.func_.iter_id_
+            || StringIds::ConstReverseIterator == tdata.func_.iter_id_;
+
+        const std::size_t srclen_ = tcase.arg ? tdata.arglen_ : str.size ();
+
+        const std::size_t off = 
+            reverse_iter ? srclen_ - tdata.off2_ - tdata.ext2_ : tdata.off2_;
         const std::size_t ext = tdata.ext2_;
 
         if (0 == tcase.arg) {
@@ -936,8 +942,8 @@
 #define TEST(Iterator) do {                                                 \
         typedef typename String::Iterator Iter;                             \
         static const                                                        \
-        InsertRangeOverload<String, Iter> rep;                              \
-        test_insert ((charT*)0, (Traits*)0, (Allocator*)0, rep, tdata);     \
+        InsertRangeOverload<String, Iter> rng;                              \
+        test_insert ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata);     \
     } while (0)
 
         case StringIds::Pointer: TEST (pointer); break;
@@ -945,13 +951,8 @@
         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);
+        case StringIds::ReverseIterator: TEST (reverse_iterator); break;
+        case StringIds::ConstReverseIterator: TEST (const_reverse_iterator);
             break;
 
         // exercise specializations of the member function template
@@ -960,8 +961,8 @@
 #define TEST(Iterator) do {                                                 \
         typedef Iterator<charT> Iter;                                       \
         static const                                                        \
-        InsertRange<String, Iter> rep;                                      \
-        test_insert ((charT*)0, (Traits*)0, (Allocator*)0, rep, tdata);     \
+        InsertRange<String, Iter> rng;                                      \
+        test_insert ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata);     \
     } while (0)
 
         case StringIds::Input: TEST (InputIter); break;
@@ -975,8 +976,8 @@
     }
     else {
         // exercise ordinary overloads of the member function
-        static const RangeBase<String> rep;
-        test_insert ((charT*)0, (Traits*)0, (Allocator*)0, rep, tdata);
+        static const RangeBase<String> rng;
+        test_insert ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata);
     }
 }
 

Modified: incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp?rev=414577&r1=414576&r2=414577&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp Thu Jun 15 06:30:39 2006
@@ -774,7 +774,13 @@
         const StringIter first1 (str.begin () + tdata.off1_);
         const StringIter last1  (first1 + tdata.ext1_);
 
-        const std::size_t off = tdata.off2_;
+        bool reverse_iter = StringIds::ReverseIterator == tdata.func_.iter_id_
+            || StringIds::ConstReverseIterator == tdata.func_.iter_id_;
+
+        const std::size_t srclen_ = tcase.arg ? tdata.arglen_ : str.size ();
+
+        const std::size_t off = 
+            reverse_iter ? srclen_ - tdata.off2_ - tdata.ext2_ : tdata.off2_;
         const std::size_t ext = tdata.ext2_;
 
         if (0 == tcase.arg) {
@@ -800,7 +806,7 @@
 
 template <class charT, class Traits, class Allocator>
 void test_replace (charT*, Traits*, Allocator*, const RangeBase<
-                       std::basic_string <charT, Traits, Allocator> > &rep,
+                       std::basic_string <charT, Traits, Allocator> > &rng,
                    const StringTestCaseData<charT>                    &tdata)
 {
     typedef std::basic_string <charT, Traits, Allocator> String;
@@ -943,7 +949,7 @@
                 break;
 
             case Replace (iter_iter_range):
-                ret_ptr = &rep (str, tdata);
+                ret_ptr = &rng (str, tdata);
                 break;
 
             default:
@@ -1114,8 +1120,8 @@
 #define TEST(Iterator) do {                                                 \
         typedef typename String::Iterator Iter;                             \
         static const                                                        \
-        ReplaceRangeOverload<String, Iter> rep;                             \
-        test_replace ((charT*)0, (Traits*)0, (Allocator*)0, rep, tdata);    \
+        ReplaceRangeOverload<String, Iter> rng;                             \
+        test_replace ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata);    \
     } while (0)
 
         case StringIds::Pointer: TEST (pointer); break;
@@ -1123,13 +1129,8 @@
         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);
+        case StringIds::ReverseIterator: TEST (reverse_iterator); break;
+        case StringIds::ConstReverseIterator: TEST (const_reverse_iterator); 
             break;
 
         // exercise specializations of the member function template
@@ -1138,8 +1139,8 @@
 #define TEST(Iterator) do {                                                 \
         typedef Iterator<charT> Iter;                                       \
         static const                                                        \
-        ReplaceRange<String, Iter> rep;                                     \
-        test_replace ((charT*)0, (Traits*)0, (Allocator*)0, rep, tdata);    \
+        ReplaceRange<String, Iter> rng;                                     \
+        test_replace ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata);    \
     } while (0)
 
         case StringIds::Input: TEST (InputIter); break;
@@ -1153,8 +1154,8 @@
     }
     else {
         // exercise ordinary overloads of the member function
-        static const RangeBase<String> rep;
-        test_replace ((charT*)0, (Traits*)0, (Allocator*)0, rep, tdata);
+        static const RangeBase<String> rng;
+        test_replace ((charT*)0, (Traits*)0, (Allocator*)0, rng, tdata);
     }
 }
 



Mime
View raw message