Return-Path: Delivered-To: apmail-incubator-stdcxx-commits-archive@www.apache.org Received: (qmail 41914 invoked from network); 15 May 2006 08:15:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 15 May 2006 08:15:10 -0000 Received: (qmail 93803 invoked by uid 500); 15 May 2006 08:15:06 -0000 Delivered-To: apmail-incubator-stdcxx-commits-archive@incubator.apache.org Received: (qmail 93762 invoked by uid 500); 15 May 2006 08:15:06 -0000 Mailing-List: contact stdcxx-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-commits@incubator.apache.org Received: (qmail 93726 invoked by uid 99); 15 May 2006 08:15:06 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 May 2006 01:15:06 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 15 May 2006 01:15:01 -0700 Received: (qmail 41561 invoked by uid 65534); 15 May 2006 08:14:40 -0000 Message-ID: <20060515081440.41560.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r406581 [1/3] - /incubator/stdcxx/trunk/tests/strings/ Date: Mon, 15 May 2006 08:14:32 -0000 To: stdcxx-commits@incubator.apache.org From: antonp@apache.org X-Mailer: svnmailer-1.0.8 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: antonp Date: Mon May 15 01:14:29 2006 New Revision: 406581 URL: http://svn.apache.org/viewcvs?rev=406581&view=rev Log: 2006-05-15 Anton Pevtsov * 21.string.copy.cpp: Converted to simplified format (MemFun, run_test): removed as obsolete (test_copy): Updated to use test driver features. * 21.string.replace.cpp (test_replace_range): Added res_len paramter, fixed bug with incorrect expected result string length. (test_replace): Updated cal to test_replace_range, fixed bug with agruments for the rw_match call. * 21.string.append.cpp: Replaced LSTR, LLEN, and LPAR in test cases with strings containing the '@' directive(s). Corrected errors in expected results involving said strings revealed by the use of the more flexible/reliable directives. * 21.string.assing.cpp: Same * 21.string.compare.cpp: Same * 21.string.copy.cpp: Same * 21.string.erase.cpp: Same * 21.string.find.cpp: Same * 21.string.find.first.not.of.cpp: Same * 21.string.find.first.of.cpp: Same * 21.string.find.last.not.of.cpp: Same * 21.string.find.last.of.cpp: Same * 21.string.insert.cpp: Same * 21.string.op.plus.equal.cpp: Same * 21.string.rfind.cpp: Same * 21.string.substr.cpp: Same Modified: incubator/stdcxx/trunk/tests/strings/21.string.append.cpp incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp incubator/stdcxx/trunk/tests/strings/21.string.compare.cpp incubator/stdcxx/trunk/tests/strings/21.string.copy.cpp incubator/stdcxx/trunk/tests/strings/21.string.erase.cpp incubator/stdcxx/trunk/tests/strings/21.string.find.cpp incubator/stdcxx/trunk/tests/strings/21.string.find.first.not.of.cpp incubator/stdcxx/trunk/tests/strings/21.string.find.first.of.cpp incubator/stdcxx/trunk/tests/strings/21.string.find.last.not.of.cpp incubator/stdcxx/trunk/tests/strings/21.string.find.last.of.cpp incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp incubator/stdcxx/trunk/tests/strings/21.string.op.plus.equal.cpp incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp incubator/stdcxx/trunk/tests/strings/21.string.rfind.cpp incubator/stdcxx/trunk/tests/strings/21.string.substr.cpp 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=406581&r1=406580&r2=406581&view=diff ============================================================================== --- incubator/stdcxx/trunk/tests/strings/21.string.append.cpp (original) +++ incubator/stdcxx/trunk/tests/strings/21.string.append.cpp Mon May 15 01:14:29 2006 @@ -27,21 +27,17 @@ #include // for string #include // for out_of_range, length_error - #include // for size_t #include <21.strings.h> // for StringMembers #include // for InputIter #include // for rw_test() -#include // for rw_widen() +#include // for rw_expand() #include // for bad_alloc, replacement operator new - /**************************************************************************/ // for convenience and brevity -#define LSTR StringMembers::long_string -#define LLEN StringMembers::long_string_len #define Append(which) StringMembers::append_ ## which typedef StringMembers::OverloadId OverloadId; @@ -103,8 +99,9 @@ TEST ("\0ab\0\0c", "e\0", "\0ab\0\0ce", 0), TEST ("abcdefghij", "abcdefghij", "abcdefghijabcdefghij", 0), - TEST ("", LSTR, LSTR, 0), - TEST (LSTR, "", LSTR, 0), + TEST ("", "x@4096", "x@4096", 0), + TEST ("x@4096", "", "x@4096", 0), + TEST ("x@4096", "x@4096", "x@8192", 0), TEST ("", 0, "", 0), TEST ("abc", 0, "abcabc", 0), @@ -112,7 +109,7 @@ TEST ("\0\0abc", 0, "\0\0abc", 0), TEST ("abc\0\0", 0, "abc\0\0abc", 0), - TEST ("", LSTR, LSTR, -1), + TEST ("", "x@4096", "x@4096", -1), TEST ("last", "test", "lasttest", 0) }; @@ -166,8 +163,9 @@ TEST ("ab\0\0c\0", "\0e", "ab\0\0c\0\0e", 0), TEST ("abcdefghij", "abcdefghij", "abcdefghijabcdefghij", 0), - TEST ("", LSTR, LSTR, 0), - TEST (LSTR, "", LSTR, 0), + TEST ("", "x@4096", "x@4096", 0), + TEST ("x@4096", "", "x@4096", 0), + TEST ("x@4096", "x@4096", "x@8192", 0), TEST ("", 0, "", 0), TEST ("abc", 0, "abcabc", 0), @@ -175,7 +173,7 @@ TEST ("\0\0abc", 0, "\0\0abc\0\0abc", 0), TEST ("abc\0\0", 0, "abc\0\0abc\0\0", 0), - TEST ("", LSTR, LSTR, -1), + TEST ("", "x@4096", "x@4096", -1), TEST ("last", "test", "lasttest", 0) }; @@ -236,11 +234,13 @@ TEST ("a\0bc", 0, 2, "a\0bca\0", 0), TEST ("\0abc\0\0", 0, 1, "\0abc\0\0\0", 0), TEST ("a\0bc\0\0", 0, 3, "a\0bc\0\0a\0b", 0), + TEST ("a@4096", 0, 1111, "a@5207", 0), + TEST ("b@4096", 0, 2222, "b@6318", 0), - TEST ("", LSTR, LLEN - 1, LSTR, 0), - TEST (LSTR, "", 0, LSTR, 0), + TEST ("", "x@4096", 4096, "x@4096", 0), + TEST ("x@4096", "", 0, "x@4096", 0), - TEST ("", LSTR, LLEN - 1, LSTR, -1), + TEST ("", "x@4096", 4096, "x@4096", -1), TEST ("last", "test", 4, "lasttest", 0) }; @@ -315,14 +315,18 @@ TEST ("a\0bc\0\0", 0, 3, 9, "a\0bc\0\0c\0\0", 0), TEST ("abcdef", 0, 1, 2, "abcdefbc", 0), - TEST ("", LSTR, 0, LLEN, LSTR, 0), - TEST (LSTR, "", 0, 0, LSTR, 0), + TEST ("a@1000", "b@1000", 0, 999, "a@1000b@999", 0), + TEST ("a@1000", "b@1001", 0, 1000, "a@1000b@1000", 0), + TEST ("a@1000", "b@1002", 0, 102, "a@1000b@102", 0), + TEST ("", "x@4096", 0, 4096, "x@4096", 0), + TEST ("x@4096", "", 0, 0, "x@4096", 0), + TEST ("x@4096", "a@4096", 100, 10, "x@4096a@10", 0), TEST ("", "\0", 2, 0, "", 1), TEST ("", "a", 2, 0, "", 1), - TEST ("", LSTR,LLEN + 10, 0, "", 1), + TEST ("", "x@4096", 4106, 0, "", 1), - TEST (LSTR, 0, 0, 0, LSTR, -1), + TEST ("x@4096", 0, 0, 0, "x@4096", -1), TEST ("last", "test", 0, 4, "lasttest", 0) }; @@ -380,10 +384,10 @@ TEST ("\0ab\0\0c", 3, '\0', "\0ab\0\0c\0\0\0", 0), TEST ("a\0bc\0\0", 2, 'a', "a\0bc\0\0aa", 0), - TEST ("", LLEN - 1, 'x', LSTR, 0), - TEST (LSTR, 0, 'x', LSTR, 0), + TEST ("", 4096, 'x', "x@4096", 0), + TEST ("x@4096", 0, 'x', "x@4096", 0), - TEST ("", LLEN - 1, 'x', LSTR, -1), + TEST ("", 4096, 'x', "x@4096", -1), TEST ("last", 4, 't', "lasttttt", 0) }; @@ -391,8 +395,11 @@ /**************************************************************************/ template -void test_append_range (charT *wstr, - charT *wsrc, +void test_append_range (const charT *wstr, + std::size_t wstr_len, + const charT *warg, + std::size_t warg_len, + std::size_t res_len, Traits*, const Iterator &it, const TestCase &tcase) @@ -404,17 +411,25 @@ const char* const itname = tcase.arg ? type_name (it, (charT*)0) : "basic_string::iterator"; - /* const */ String s_str (wstr, tcase.str_len); - const String s_arg (wsrc, tcase.arg_len); - - std::size_t off_last = tcase.off + tcase.size; + // compute the size of the controlled sequence and the size + // of the sequence denoted by the argument keeping in mind + // that the latter may refer to the former + const std::size_t size1 = wstr_len; + const std::size_t size2 = tcase.arg ? warg_len : size1; + + // construct the string object to be modified + String s_str (wstr, size1); + + // compute the offset and the extent (the number of elements) + // of the second range into the argument of the function call + const std::size_t off = + std::size_t (tcase.off) < size2 ? std::size_t (tcase.off) : size2; + const std::size_t ext = + off + tcase.size < size2 ? std::size_t (tcase.size) : size2 - off; if (tcase.arg) { - if (off_last > s_arg.size ()) - off_last = s_arg.size (); - - const charT* const beg = wsrc + tcase.off; - const charT* const end = wsrc + off_last; + const charT* const beg = warg + off; + const charT* const end = beg + ext; const Iterator first (beg, beg, end); const Iterator last (end, beg, end); @@ -422,18 +437,18 @@ s_str.append (first, last); } else { - const StringIter first (s_str.begin () + tcase.off); - const StringIter last (s_str.size () < off_last ? - s_str.end () - : s_str.begin () + off_last); + // self-referential modification (appending a range + // of elements with a subrange of its own elements) + const StringIter first (s_str.begin () + off); + const StringIter last (first + ext); s_str.append (first, last); } - const std::size_t match = - rw_match (tcase.res, s_str.c_str(), tcase.nres); + // detrmine whether the produced sequence matches the exepceted result + const std::size_t match = rw_match (tcase.res, s_str.data (), tcase.nres); - rw_assert (match == tcase.nres, 0, tcase.line, + rw_assert (match == res_len, 0, tcase.line, "line %d. %{$FUNCALL} expected %{#*s}, got %{/*.*Gs}, " "difference at offset %zu for %s", __LINE__, int (tcase.nres), tcase.res, @@ -444,15 +459,18 @@ /**************************************************************************/ template -void test_append_range (charT* wstr, - charT* wsrc, +void test_append_range (const charT *wstr, + std::size_t wstr_len, + const charT *warg, + std::size_t warg_len, + std::size_t res_len, Traits*, const TestCase &tcase) { if (tcase.bthrow) // this method doesn't throw return; - test_append_range (wstr, wsrc, (Traits*)0, + test_append_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0, InputIter(0, 0, 0), tcase); // there is no need to call test_append_range @@ -460,13 +478,13 @@ if (0 == tcase.arg) return; - test_append_range (wstr, wsrc, (Traits*)0, + test_append_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0, ConstFwdIter(0, 0, 0), tcase); - test_append_range (wstr, wsrc, (Traits*)0, + test_append_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0, ConstBidirIter(0, 0, 0), tcase); - test_append_range (wstr, wsrc, (Traits*)0, + test_append_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0, ConstRandomAccessIter(0, 0, 0), tcase); } @@ -478,36 +496,64 @@ const TestCase &tcase) { typedef std::allocator Allocator; - typedef std::basic_string TestString; - typedef typename TestString::iterator StringIter; - typedef typename TestString::const_iterator ConstStringIter; + typedef std::basic_string String; + typedef typename String::iterator StringIter; + typedef typename UserTraits::MemFun UTMemFun; + + static const std::size_t BUFSIZE = 256; - typedef typename UserTraits::MemFun UTMemFun; + static charT wstr_buf [BUFSIZE]; + static charT warg_buf [BUFSIZE]; - static charT wstr [LLEN]; - static charT wsrc [LLEN]; + std::size_t str_len = sizeof wstr_buf / sizeof *wstr_buf; + std::size_t arg_len = sizeof warg_buf / sizeof *warg_buf; - rw_widen (wstr, tcase.str, tcase.str_len); - rw_widen (wsrc, tcase.arg, tcase.arg_len); + charT* wstr = rw_expand (wstr_buf, tcase.str, tcase.str_len, &str_len); + charT* warg = rw_expand (warg_buf, tcase.arg, tcase.arg_len, &arg_len); + + static charT wres_buf [BUFSIZE]; + std::size_t res_len = sizeof wres_buf / sizeof *wres_buf; + charT* wres = rw_expand (wres_buf, tcase.res, tcase.nres, &res_len); // special processing for append_range to exercise all iterators if (Append (range) == which) { - test_append_range (wstr, wsrc, (Traits*)0, tcase); + test_append_range (wstr, str_len, warg, arg_len, + res_len, (Traits*)0, tcase); + if (wstr != wstr_buf) + delete[] wstr; + + if (warg != warg_buf) + delete[] warg; + + if (wres != wres_buf) + delete[] wres; + return; } - /* const */ TestString s_str (wstr, tcase.str_len); - const TestString s_arg (wsrc, tcase.arg_len); + // construct the string object to be modified + // and the (possibly unused) argument string + /* const */ String s_str (wstr, str_len); + const String s_arg (warg, arg_len); + + if (wstr != wstr_buf) + delete[] wstr; + + if (warg != warg_buf) + delete[] warg; + + wstr = 0; + warg = 0; - std::size_t res_off = 0; + std::size_t res_off = 0; // save the state of the string object before the call // to detect wxception safety violations (changes to // the state of the object after an exception) const StringState str_state (rw_get_string_state (s_str)); - const charT* const ptr_arg = tcase.arg ? wsrc : s_str.c_str (); - const TestString& str_arg = tcase.arg ? s_arg : s_str; + const charT* const ptr_arg = tcase.arg ? s_arg.c_str () : s_str.c_str (); + const String& str_arg = tcase.arg ? s_arg : s_str; std::size_t total_length_calls = 0; std::size_t n_length_calls = 0; @@ -541,8 +587,12 @@ #else // if defined (_RWSTD_NO_EXCEPTIONS) - if (tcase.bthrow) - return; + if (tcase.bthrow) { + if (wres != wres_buf) + delete[] wres; + + return; + } #endif // _RWSTD_NO_EXCEPTIONS @@ -550,7 +600,7 @@ switch (which) { case Append (ptr): { - const TestString& s_res = s_str.append (ptr_arg); + const String& s_res = s_str.append (ptr_arg); res_off = &s_res - &s_str; if (rg_calls) n_length_calls = rg_calls [UTMemFun::length]; @@ -558,19 +608,19 @@ } case Append (str): { - const TestString& s_res = s_str.append (str_arg); + const String& s_res = s_str.append (str_arg); res_off = &s_res - &s_str; break; } case Append (ptr_size): { - const TestString& s_res = s_str.append (ptr_arg, tcase.size); + const String& s_res = s_str.append (ptr_arg, tcase.size); res_off = &s_res - &s_str; break; } case Append (str_size_size): { - const TestString& s_res = + const String& s_res = s_str.append (str_arg, tcase.off, tcase.size); res_off = &s_res - &s_str; break; @@ -578,7 +628,7 @@ case Append (size_val): { const charT ch (make_char (char (tcase.val), (charT*)0)); - const TestString& s_res = s_str.append (tcase.size, ch); + const String& s_res = s_str.append (tcase.size, ch); res_off = &s_res - &s_str; break; } @@ -593,21 +643,21 @@ "offset is %zu", __LINE__, res_off); // verify that strings are of equal length - rw_assert (tcase.nres == s_str.size (), 0, tcase.line, + rw_assert (res_len == s_str.size (), 0, tcase.line, "line %d. %{$FUNCALL} expected %{#*s}, " "length %zu, got %{/*.*Gs}, length %zu", __LINE__, int (tcase.nres), tcase.res, - tcase.nres, int (sizeof (charT)), + res_len, int (sizeof (charT)), int (s_str.size ()), s_str.c_str (), s_str.size ()); - if (tcase.nres == s_str.size ()) { + if (res_len == s_str.size ()) { // if the result length matches the expected length // (and only then), also verify that the modified // string matches the expected result const std::size_t match = - rw_match (tcase.res, s_str.c_str(), tcase.nres); + rw_match (tcase.res, s_str.c_str (), tcase.nres); - rw_assert (match == tcase.nres, 0, tcase.line, + rw_assert (match == res_len, 0, tcase.line, "line %d. %{$FUNCALL} expected %{#*s}, " "got %{/*.*Gs}, difference at offset %zu", __LINE__, int (tcase.nres), tcase.res, @@ -699,6 +749,9 @@ #endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE *pst->throw_at_calls_ [0] = std::size_t (-1); + + if (wres != wres_buf) + delete[] wres; } /**************************************************************************/ 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=406581&r1=406580&r2=406581&view=diff ============================================================================== --- incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp (original) +++ incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp Mon May 15 01:14:29 2006 @@ -32,15 +32,12 @@ #include <21.strings.h> // for StringMembers #include // for InputIter #include // for rw_test() -#include // for rw_widen() +#include // for rw_expand() #include // for bad_alloc, replacement operator new /**************************************************************************/ // for convenience and brevity - -#define LSTR StringMembers::long_string -#define LLEN StringMembers::long_string_len #define Assign(which) StringMembers::assign_ ## which typedef StringMembers::OverloadId AssignOverload; @@ -96,16 +93,18 @@ TEST ("a\0b\0\0c", "e\0", "e", 0), TEST ("\0ab\0\0c", "e\0", "e", 0), - TEST ("", LSTR, LSTR, 0), - TEST (LSTR, "", "", 0), + TEST ("", "x@4096", "x@4096", 0), + TEST ("x@4096", "", "", 0), + TEST ("a@4096", "b@4096", "b@4096", 0), TEST ("", 0, "", 0), TEST ("abc", 0, "abc", 0), TEST ("a\0\0bc", 0, "a", 0), TEST ("\0\0abc", 0, "", 0), TEST ("abc\0\0", 0, "abc", 0), + TEST ("x@4096", 0, "x@4096", 0), - TEST ("", LSTR, LSTR, -1), + TEST ("", "x@4096", "x@4096", -1), TEST ("last", "test", "test", 0) }; @@ -160,14 +159,16 @@ TEST ("e\0\0", "\0ab\0\0c", "\0ab\0\0c", 0), TEST ("\0e", "ab\0\0c\0", "ab\0\0c\0", 0), - TEST ("", LSTR, LSTR, 0), - TEST (LSTR, "", "", 0), + TEST ("", "x@4096", "x@4096", 0), + TEST ("x@4096", "", "", 0), + TEST ("a@4096", "b@4096", "b@4096", 0), TEST ("", 0, "", 0), TEST ("abc", 0, "abc", 0), TEST ("a\0\0bc", 0, "a\0\0bc", 0), TEST ("\0\0abc", 0, "\0\0abc", 0), TEST ("abc\0\0", 0, "abc\0\0", 0), + TEST ("x@4096", 0, "x@4096", 0), TEST ("last", "test", "test", 0) }; @@ -230,15 +231,17 @@ TEST ("\0abc\0\0", 0, 1, "\0", 0), TEST ("a\0bc\0\0", 0, 3, "a\0b", 0), TEST ("a\0bc\0\0", 0, 6, "a\0bc\0\0", 0), + TEST ("x@4096", 0, 2048, "x@2048", 0), - TEST ("", LSTR, LLEN - 1, LSTR, 0), - TEST ("abcd", LSTR, 0, "", 0), - TEST (LSTR, LSTR, 0, "", 0), - TEST (LSTR, LSTR, 1, "x", 0), - TEST (LSTR, "", 0, "", 0), + TEST ("", "x@4096", 4096, "x@4096", 0), + TEST ("abcd", "x@4096", 0, "", 0), + TEST ("x@4096", "x@4096", 0, "", 0), + TEST ("x@4096", "x@4096", 1, "x", 0), + TEST ("x@4096", "", 0, "", 0), + TEST ("a@4096", "b@4096", 2048, "b@2048", 0), TEST ("", "", -1, "", 2), - TEST ("", LSTR, LLEN - 1, LSTR, -1), + TEST ("", "x@4096", 4096, "x@4096", -1), TEST ("last", "test", 4, "test", 0) }; @@ -313,18 +316,21 @@ TEST ("a\0bc\0\0", 0, 1, 3, "\0bc", 0), TEST ("a\0bc\0\0", 0, 0, 9, "a\0bc\0\0", 0), TEST ("abcdef", 0, 1, 2, "bc", 0), + TEST ("x@4096", 0, 1, 2, "xx", 0), - TEST (LSTR, "", 0, 0, "", 0), - TEST ("", LSTR, 9, 2, "xx", 0), - TEST ("", LSTR, 9, 0, "", 0), - TEST ("abc", LSTR, 2, 1, "x", 0), - TEST (LSTR, LSTR, 2, 3, "xxx", 0), - TEST ("", LSTR, 0, LLEN, LSTR, 0), + TEST ("x@4096", "", 0, 0, "", 0), + TEST ("", "x@4096", 9, 2, "xx", 0), + TEST ("", "x@4096", 9, 0, "", 0), + TEST ("abc", "x@4096", 2, 1, "x", 0), + TEST ("x@4096", "x@4096", 2, 3, "xxx", 0), + TEST ("", "x@4096", 0, 4096, "x@4096", 0), + TEST ("", "x@4096", 100, 2000, "x@2000", 0), TEST ("", "\0", 2, 0, "", 1), TEST ("", "a", 2, 0, "", 1), - TEST ("", LSTR,LLEN + 10, 0, "", 1), - TEST ("", LSTR, 0, LLEN - 1, LSTR, -1), + TEST ("", "x@4096", 4106, 0, "", 1), + + TEST ("", "x@4096", 0, 4096, "x@4096", -1), TEST ("last", "test", 0, 4, "test", 0) }; @@ -378,11 +384,11 @@ TEST ("\0ab\0\0c", 3, '\0', "\0\0\0", 0), TEST ("a\0bc\0\0", 2, 'a', "aa", 0), - TEST ("", LLEN - 1, 'x', LSTR, 0), - TEST (LSTR, 0, 'x', "", 0), + TEST ("", 4096, 'x', "x@4096", 0), + TEST ("x@4096", 0, 'x', "", 0), TEST ("", -1, 'x', "", 2), - TEST ("", LLEN - 1, 'x', LSTR, -1), + TEST ("", 4096, 'x', "x@4096", -1), TEST ("last", 4, 't', "tttt", 0) }; @@ -390,8 +396,11 @@ /**************************************************************************/ template -void test_assign_range (charT *wstr, - charT *wsrc, +void test_assign_range (const charT *wstr, + std::size_t wstr_len, + const charT *warg, + std::size_t warg_len, + std::size_t res_len, Traits*, const Iterator &it, const TestCase &tcase) @@ -403,36 +412,44 @@ const char* const itname = tcase.arg ? type_name (it, (charT*)0) : "basic_string::iterator"; - /* const */ String s_str (wstr, tcase.str_len); - const String s_arg (wsrc, tcase.arg_len); - - std::size_t off_last = tcase.off + tcase.size; + // compute the size of the controlled sequence and the size + // of the sequence denoted by the argument keeping in mind + // that the latter may refer to the former + const std::size_t size1 = wstr_len; + const std::size_t size2 = tcase.arg ? warg_len : size1; + + // construct the string object to be modified + String s_str (wstr, size1); + + // compute the offset and the extent (the number of elements) + // of the second range into the argument of the function call + const std::size_t off = + std::size_t (tcase.off) < size2 ? std::size_t (tcase.off) : size2; + const std::size_t ext = + off + tcase.size < size2 ? std::size_t (tcase.size) : size2 - off; if (tcase.arg) { - if (off_last > s_arg.size ()) - off_last = s_arg.size (); + const charT* const beg = warg + off; + const charT* const end = beg + ext; - const Iterator - first (wsrc + tcase.off, wsrc + tcase.off, wsrc + off_last); - const Iterator - last (wsrc + off_last, wsrc + tcase.off, wsrc + off_last); + const Iterator first (beg, beg, end); + const Iterator last (end, beg, end); s_str.assign (first, last); } else { - - const StringIter first (s_str.begin () + tcase.off); - const StringIter last (off_last > s_str.size () ? - s_str.end () - : s_str.begin () + off_last); + // self-referential modification (appending a range + // of elements with a subrange of its own elements) + const StringIter first (s_str.begin () + off); + const StringIter last (first + ext); s_str.assign (first, last); } - const std::size_t match = - rw_match (tcase.res, s_str.c_str(), tcase.nres); + // detrmine whether the produced sequence matches the exepceted result + const std::size_t match = rw_match (tcase.res, s_str.data (), tcase.nres); - rw_assert (match == tcase.nres, 0, tcase.line, + rw_assert (match == res_len, 0, tcase.line, "line %d. %{$FUNCALL} expected %{#*s}, got %{/*.*Gs}, " "difference at off %zu for %s", __LINE__, int (tcase.nres), tcase.res, @@ -443,15 +460,18 @@ /**************************************************************************/ template -void test_assign_range (charT *wstr, - charT *wsrc, +void test_assign_range (const charT *wstr, + std::size_t wstr_len, + const charT *warg, + std::size_t warg_len, + std::size_t res_len, Traits*, const TestCase &tcase) { if (tcase.bthrow) // this method doesn't throw return; - test_assign_range (wstr, wsrc, (Traits*)0, + test_assign_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0, InputIter(0, 0, 0), tcase); // there is no need to call test_assign_range @@ -459,13 +479,13 @@ if (0 == tcase.arg) return; - test_assign_range (wstr, wsrc, (Traits*)0, + test_assign_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0, ConstFwdIter(0, 0, 0), tcase); - test_assign_range (wstr, wsrc, (Traits*)0, + test_assign_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0, ConstBidirIter(0, 0, 0), tcase); - test_assign_range (wstr, wsrc, (Traits*)0, + test_assign_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0, ConstRandomAccessIter(0, 0, 0), tcase); } @@ -477,26 +497,55 @@ const TestCase &tcase) { typedef std::allocator Allocator; - typedef std::basic_string TestString; - typedef typename TestString::iterator StringIter; - typedef typename TestString::const_iterator ConstStringIter; + typedef std::basic_string String; + typedef typename String::iterator StringIter; + typedef typename UserTraits::MemFun UTMemFun; + + static const std::size_t BUFSIZE = 256; + + static charT wstr_buf [BUFSIZE]; + static charT warg_buf [BUFSIZE]; - typedef typename UserTraits::MemFun UTMemFun; + std::size_t str_len = sizeof wstr_buf / sizeof *wstr_buf; + std::size_t arg_len = sizeof warg_buf / sizeof *warg_buf; - static charT wstr [LLEN]; - static charT wsrc [LLEN]; + charT* wstr = rw_expand (wstr_buf, tcase.str, tcase.str_len, &str_len); + charT* warg = rw_expand (warg_buf, tcase.arg, tcase.arg_len, &arg_len); - rw_widen (wstr, tcase.str, tcase.str_len); - rw_widen (wsrc, tcase.arg, tcase.arg_len); + static charT wres_buf [BUFSIZE]; + std::size_t res_len = sizeof wres_buf / sizeof *wres_buf; + charT* wres = rw_expand (wres_buf, tcase.res, tcase.nres, &res_len); // special processing for assign_range to exercise all iterators if (Assign (range) == which) { - test_assign_range (wstr, wsrc, (Traits*)0, tcase); + test_assign_range (wstr, str_len, warg, arg_len, + res_len, (Traits*)0, tcase); + + if (wstr != wstr_buf) + delete[] wstr; + + if (warg != warg_buf) + delete[] warg; + + if (wres != wres_buf) + delete[] wres; + return; } - /* const */ TestString s_str (wstr, tcase.str_len); - const TestString s_arg (wsrc, tcase.arg_len); + // construct the string object to be modified + // and the (possibly unused) argument string + /* const */ String s_str (wstr, str_len); + const String s_arg (warg, arg_len); + + if (wstr != wstr_buf) + delete[] wstr; + + if (warg != warg_buf) + delete[] warg; + + wstr = 0; + warg = 0; std::size_t res_off = 0; std::size_t size = tcase.size >= 0 ? tcase.size : s_str.max_size () + 1; @@ -507,8 +556,8 @@ const StringState str_state (rw_get_string_state (s_str)); // first function argument - const charT* const arg_ptr = tcase.arg ? wsrc : s_str.c_str (); - const TestString& arg_str = tcase.arg ? s_arg : s_str; + const charT* const arg_ptr = tcase.arg ? s_arg.c_str () : s_str.c_str (); + const String& arg_str = tcase.arg ? s_arg : s_str; std::size_t total_length_calls = 0; std::size_t n_length_calls = 0; @@ -542,15 +591,19 @@ #else // if defined (_RWSTD_NO_EXCEPTIONS) - if (tcase.bthrow) - return; + if (tcase.bthrow) { + if (wres != wres_buf) + delete[] wres; + + return; + } #endif // _RWSTD_NO_EXCEPTIONS try { switch (which) { case Assign (ptr): { - const TestString& s_res = s_str.assign (arg_ptr); + const String& s_res = s_str.assign (arg_ptr); res_off = &s_res - &s_str; if (rg_calls) n_length_calls = rg_calls [UTMemFun::length]; @@ -558,19 +611,19 @@ } case Assign (str): { - const TestString& s_res = s_str.assign (arg_str); + const String& s_res = s_str.assign (arg_str); res_off = &s_res - &s_str; break; } case Assign (ptr_size): { - const TestString& s_res = s_str.assign (arg_ptr, size); + const String& s_res = s_str.assign (arg_ptr, size); res_off = &s_res - &s_str; break; } case Assign (str_size_size): { - const TestString& s_res = + const String& s_res = s_str.assign (arg_str, tcase.off, size); res_off = &s_res - &s_str; break; @@ -578,7 +631,7 @@ case Assign (size_val): { const charT val = make_char (char (tcase.val), (charT*)0); - const TestString& s_res = s_str.assign (size, val); + const String& s_res = s_str.assign (size, val); res_off = &s_res - &s_str; break; } @@ -594,21 +647,21 @@ "offset is %zu", __LINE__, res_off); // verfiy that strings length are equal - rw_assert (tcase.nres == s_str.size (), 0, tcase.line, + rw_assert (res_len == s_str.size (), 0, tcase.line, "line %d. %{$FUNCALL}: expected %{#*s} with length " "%zu, got %{/*.*Gs} with length %zu", __LINE__, - int (tcase.nres), tcase.res, tcase.nres, + int (tcase.nres), tcase.res, res_len, int (sizeof (charT)), int (s_str.size ()), s_str.c_str (), s_str.size ()); - if (tcase.nres == s_str.size ()) { + if (res_len == s_str.size ()) { // if the result length matches the expected length // (and only then), also verify that the modified // string matches the expected result const std::size_t match = rw_match (tcase.res, s_str.c_str(), tcase.nres); - rw_assert (match == tcase.nres, 0, tcase.line, + rw_assert (match == res_len, 0, tcase.line, "line %d. %{$FUNCALL}: expected %{#*s}, " "got %{/*.*Gs}, difference at off %zu", __LINE__, int (tcase.nres), tcase.res, @@ -702,6 +755,9 @@ #endif // _RWSTD_NO_EXCEPTIONS *pst->throw_at_calls_ [0] = std::size_t (-1); + + if (wres != wres_buf) + delete[] wres; } /**************************************************************************/ Modified: incubator/stdcxx/trunk/tests/strings/21.string.compare.cpp URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.compare.cpp?rev=406581&r1=406580&r2=406581&view=diff ============================================================================== --- incubator/stdcxx/trunk/tests/strings/21.string.compare.cpp (original) +++ incubator/stdcxx/trunk/tests/strings/21.string.compare.cpp Mon May 15 01:14:29 2006 @@ -31,14 +31,12 @@ #include <21.strings.h> // for StringMembers #include // for rw_assert() -#include // for rw_widen() +#include // for rw_expand() /**************************************************************************/ // for convenience and brevity #define NPOS _RWSTD_SIZE_MAX -#define LSTR StringMembers::long_string -#define LLEN StringMembers::long_string_len #define Compare(which) StringMembers::compare_ ## which typedef StringMembers::OverloadId OverloadId; @@ -111,11 +109,15 @@ TEST ("ab\0", "abc\0\0\0", NPOS, 0), TEST ("\0ab", "e\0ab\0\0c", NPOS, 0), - TEST (LSTR, LSTR, 0, 0), - TEST ("xx", LSTR, NPOS, 0), - TEST (LSTR, "xxxxxx", 1, 0), - TEST ("a\0b", LSTR, NPOS, 0), - TEST (LSTR, "a\0b", 1, 0), + TEST ("x@4096", "x@4096", 0, 0), + TEST ("xx", "x@4096", NPOS, 0), + TEST ("x@4096", "xxxxxx", 1, 0), + TEST ("a\0b", "x@4096", NPOS, 0), + TEST ("x@4096", "a\0b", 1, 0), + + TEST ("a@2048b@2048", "a@2048b@2047", 1, 0), + TEST ("a@2048b@2048", "a@2048b@2047c", NPOS, 0), + TEST ("a@2048cb@2047", "a@2048cb@2047", 0, 0), TEST ("last", "last", 0, 0) }; @@ -182,11 +184,15 @@ TEST ("bb\0", "ab\0\0\0c", 1, 0), TEST ("\0ac", "\0abe\0\0c", 1, 0), - TEST (LSTR, LSTR, 0, 0), - TEST ("xx", LSTR, NPOS, 0), - TEST (LSTR, "xxxxxx", 1, 0), - TEST ("a\0b", LSTR, NPOS, 0), - TEST (LSTR, "a\0b", 1, 0), + TEST ("x@4096", "x@4096", 0, 0), + TEST ("xx", "x@4096", NPOS, 0), + TEST ("x@4096", "xxxxxx", 1, 0), + TEST ("a\0b", "x@4096", NPOS, 0), + TEST ("x@4096", "a\0b", 1, 0), + + TEST ("a@2048b@2048", "a@2048b@2047", 1, 0), + TEST ("a@2048b@2048", "a@2048b@2047c", NPOS, 0), + TEST ("a@2048cb@2047", "a@2048cb@2047", 0, 0), TEST ("last", "last", 0, 0) }; @@ -267,19 +273,19 @@ TEST ("\0eb", 0, 5, "e\0ab\0\0c", NPOS, 0), TEST ("\0eb", 1, 5, "e\0ab\0\0c", 1, 0), - TEST (LSTR, 0, LLEN - 1, LSTR, 0, 0), - TEST (LSTR, 1, LLEN - 1, LSTR, NPOS, 0), - TEST ("xx", 0, 2, LSTR, NPOS, 0), - TEST (LSTR, 0, LLEN - 1, "xxxxx", 1, 0), - TEST (LSTR, 2, 5, "xxxxx", 0, 0), - TEST (LSTR, 5, 2, "xxxxx", NPOS, 0), - TEST ("a\0x", 0, 3, LSTR, NPOS, 0), - TEST (LSTR, 0, 10, "x\0b", 1, 0), - TEST (LSTR, 0, 1, "x\0b", 0, 0), + TEST ("x@4096", 0, 4096, "x@4096", 0, 0), + TEST ("x@4096", 1, 4096, "x@4096", NPOS, 0), + TEST ("xx", 0, 2, "x@4096", NPOS, 0), + TEST ("x@4096", 0, 4096, "xxxxx", 1, 0), + TEST ("x@4096", 2, 5, "xxxxx", 0, 0), + TEST ("x@4096", 5, 2, "xxxxx", NPOS, 0), + TEST ("a\0x", 0, 3, "x@4096", NPOS, 0), + TEST ("x@4096", 0, 10, "x\0b", 1, 0), + TEST ("x@4096", 0, 1, "x\0b", 0, 0), TEST ("\0", 2, 0, "", 1, 1), TEST ("a", 10, 0, "", 1, 1), - TEST (LSTR, LLEN + 10, 0, "", 1, 1), + TEST ("x@4096", 4106, 0, "", 1, 1), TEST ("last", 0, 4, "last", 0, 0) }; @@ -372,19 +378,20 @@ TEST ("abc\0\0\0", 2, 5, "abc\0\0", 1, 0), TEST ("e\0ag\0\0c", 3, 6, "e\0ab\0\0c", 1, 0), - TEST (LSTR, 0, LLEN - 1, LSTR, 0, 0), - TEST (LSTR, 1, LLEN - 1, LSTR, NPOS, 0), - TEST ("xx", 0, 2, LSTR, NPOS, 0), - TEST (LSTR, 0, LLEN - 1, "xxxxx", 1, 0), - TEST (LSTR, 2, 5, "xxxxx", 0, 0), - TEST (LSTR, 5, 2, "xxxxx", NPOS, 0), - TEST ("a\0x", 0, 3, LSTR, NPOS, 0), - TEST (LSTR, 0, 10, "x\0b", 1, 0), - TEST (LSTR, 0, 1, "x\0b", NPOS, 0), + TEST ("x@4096", 0, 4096, "x@4096", 0, 0), + TEST ("x@4096", 1, 4096, "x@4096", NPOS, 0), + TEST ("xx", 0, 2, "x@4096", NPOS, 0), + TEST ("x@4096", 0, 4096, "xxxxx", 1, 0), + TEST ("x@4096", 2, 5, "xxxxx", 0, 0), + TEST ("x@4096", 5, 2, "xxxxx", NPOS, 0), + TEST ("a\0x", 0, 3, "x@4096", NPOS, 0), + TEST ("x@4096", 0, 10, "x\0b", 1, 0), + TEST ("x@4096", 0, 1, "x\0b", NPOS, 0), + TEST ("a@4096\0", 4096, 1, "\0", 0, 0), TEST ("\0", 2, 0, "", 1, 1), TEST ("a", 10, 0, "", 1, 1), - TEST (LSTR, LLEN + 10, 0, "", 1, 1), + TEST ("x@4096", 4106, 0, "", 1, 1), TEST ("last", 0, 4, "last", 0, 0) }; @@ -496,21 +503,23 @@ TEST ("e\0ag\0\0c", 3, 6, "e\0ab\0\0c", 7, 1, 0), TEST ("abc\0\0\0", 2, 5, "c\0\0ab", 4, NPOS, 0), - TEST (LSTR, 0, LLEN - 1, LSTR, LLEN - 1, 0, 0), - TEST (LSTR, 1, LLEN - 1, LSTR, LLEN - 1, NPOS, 0), - TEST (LSTR, 1, LLEN - 1, LSTR, LLEN - 4, 1, 0), - TEST ("xx", 0, 2, LSTR, LLEN - 4, NPOS, 0), - TEST (LSTR, 0, LLEN - 1, "xxxxx", 5, 1, 0), - TEST (LSTR, LLEN - 6, 5, "xxxxx", 5, 0, 0), - TEST (LSTR, 2, 5, "xxxxx", 5, 0, 0), - TEST (LSTR, 5, 2, "xxxxx", 3, NPOS, 0), - TEST ("a\0x", 0, 3, LSTR, 10, NPOS, 0), - TEST (LSTR, 0, 10, "x\0b", 2, 1, 0), - TEST (LSTR, 0, 1, "x\0b", 2, NPOS, 0), + TEST ("x@4096", 0, 4096, "x@4096", 4096, 0, 0), + TEST ("x@4096", 1, 4096, "x@4096", 4096, NPOS, 0), + TEST ("x@4096", 1, 4096, "x@4096", 4092, 1, 0), + TEST ("xx", 0, 2, "x@4096", 4092, NPOS, 0), + TEST ("x@4096", 0, 4096, "xxxxx", 5, 1, 0), + TEST ("x@4096", 4090, 5, "xxxxx", 5, 0, 0), + TEST ("x@4096", 2, 5, "xxxxx", 5, 0, 0), + TEST ("x@4096", 5, 2, "xxxxx", 3, NPOS, 0), + TEST ("a\0x", 0, 3, "x@4096", 10, NPOS, 0), + TEST ("x@4096", 0, 10, "x\0b", 2, 1, 0), + TEST ("x@4096", 0, 1, "x\0b", 2, NPOS, 0), + + TEST ("a@4096\0", 4096, 1, "\0b", 1, 0, 0), TEST ("\0", 2, 0, "", 0, 1, 1), TEST ("a", 10, 0, "", 0, 1, 1), - TEST (LSTR, LLEN + 10, 0, "", 0, 1, 1), + TEST ("x@4096", 4106, 0, "", 0, 1, 1), TEST ("last", 0, 4, "last", 4, 0, 0) }; @@ -656,31 +665,31 @@ TEST ("e\0ag\0\0c", 3, 6, "e\0ab\0\0c", 0, 7, 1, 0), TEST ("abc\0\0\0", 2, 5, "c\0\0ab", 0, 4, NPOS, 0), - TEST (LSTR, 0, LLEN - 1, LSTR, 0, LLEN - 1, 0, 0), - TEST (LSTR, 1, LLEN - 1, LSTR, 0, LLEN - 1, NPOS, 0), - TEST (LSTR, 1, LLEN - 1, LSTR, 0, LLEN - 4, 1, 0), - TEST (LSTR, 1, LLEN - 6, LSTR, 2, LLEN - 6, 0, 0), - TEST (LSTR, 1, LLEN + 6, LSTR, 2, LLEN + 6, 1, 0), - TEST ("xx", 0, 2, LSTR, 0, LLEN - 4, NPOS, 0), - TEST ("xx", 0, 2, LSTR, LLEN - 6, - 2, 0, 0), - TEST (LSTR, 0, LLEN - 1, "xxxxx", 0, 5, 1, 0), - TEST (LSTR, LLEN - 6, 5, "xxxxx", 0, 5, 0, 0), - TEST (LSTR, 2, 5, "xxxxx", 0, 5, 0, 0), - TEST (LSTR, 5, 2, "xxxxx", 0, 3, NPOS, 0), - TEST ("a\0x", 0, 3, LSTR, 0, 10, NPOS, 0), - TEST ("a\0x", 2, 1, LSTR, LLEN - 2, - 1, 0, 0), - TEST (LSTR, 0, 10, "x\0b", 0, 2, 1, 0), - TEST (LSTR, 0, 1, "x\0b", 0, 2, NPOS, 0), + TEST ("x@4096", 0, 4096, "x@4096", 0, 4096, 0, 0), + TEST ("x@4096", 1, 4096, "x@4096", 0, 4096, NPOS, 0), + TEST ("x@4096", 1, 4096, "x@4096", 0, 4092, 1, 0), + TEST ("x@4096", 1, 4090, "x@4096", 2, 4090, 0, 0), + TEST ("x@4096", 1, 4102, "x@4096", 2, 4102, 1, 0), + TEST ("xx", 0, 2, "x@4096", 0, 4092, NPOS, 0), + TEST ("xx", 0, 2, "x@4096", 4090, 2, 0, 0), + TEST ("x@4096", 0, 4096, "xxxxx", 0, 5, 1, 0), + TEST ("x@4096", 4090, 5, "xxxxx", 0, 5, 0, 0), + TEST ("x@4096", 2, 5, "xxxxx", 0, 5, 0, 0), + TEST ("x@4096", 5, 2, "xxxxx", 0, 3, NPOS, 0), + TEST ("a\0x", 0, 3, "x@4096", 0, 10, NPOS, 0), + TEST ("a\0x", 2, 1, "x@4096", 4095, 1, 0, 0), + TEST ("x@4096", 0, 10, "x\0b", 0, 2, 1, 0), + TEST ("x@4096", 0, 1, "x\0b", 0, 2, NPOS, 0), + + TEST ("a@4096\0", 4096, 1, "b\0", 1, 1, 0, 0), TEST ("\0", 2, 0, "", 0, 0, 1, 1), TEST ("a", 10, 0, "", 0, 0, 1, 1), - TEST (LSTR, LLEN + 10, 0, "", 0, 0, 1, 1), + TEST ("x@4096", 4106, 0, "", 0, 0, 1, 1), TEST ("", 0, 0, "\0", 2, 0, 1, 2), TEST ("", 0, 0, "a", 10, 0, 1, 2), - TEST ("", 0, 0, LSTR, LLEN + 10, 0, 1, 2), + TEST ("", 0, 0, "x@4096", 4106, 0, 1, 2), TEST ("last", 0, 4, "last", 0, 4, 0, 0) }; @@ -693,19 +702,33 @@ const TestCase &tcase) { typedef std::allocator Allocator; - typedef std::basic_string TestString; - typedef typename TestString::const_iterator ConstStringIter; + typedef std::basic_string String; + typedef typename UserTraits::MemFun UTMemFun; + + static const std::size_t BUFSIZE = 256; + + static charT wstr_buf [BUFSIZE]; + static charT warg_buf [BUFSIZE]; + + std::size_t str_len = sizeof wstr_buf / sizeof *wstr_buf; + std::size_t arg_len = sizeof warg_buf / sizeof *warg_buf; + + charT* wstr = rw_expand (wstr_buf, tcase.str, tcase.str_len, &str_len); + charT* warg = rw_expand (warg_buf, tcase.arg, tcase.arg_len, &arg_len); - typedef typename UserTraits::MemFun UTMemFun; + // construct the string object to be modified + // and the (possibly unused) argument string + /* const */ String s_str (wstr, str_len); + const String s_arg (warg, arg_len); - static charT wstr [LLEN]; - static charT warg [LLEN]; + if (wstr != wstr_buf) + delete[] wstr; - rw_widen (wstr, tcase.str, tcase.str_len); - rw_widen (warg, tcase.arg, tcase.arg_len); + if (warg != warg_buf) + delete[] warg; - /* const */ TestString s_str (wstr, tcase.str_len); - const TestString s_arg (warg, tcase.arg_len); + wstr = 0; + warg = 0; // save the state of the string object before the call // to detect wxception safety violations (changes to @@ -715,8 +738,8 @@ int res = 0; // string function argument - const charT* const arg_ptr = tcase.arg ? warg : s_str.c_str (); - const TestString& arg_str = tcase.arg ? s_arg : s_str; + const charT* const arg_ptr = tcase.arg ? s_arg.c_str () : s_str.c_str (); + const String& arg_str = tcase.arg ? s_arg : s_str; std::size_t total_compare_calls = 0; std::size_t n_compare_calls = 0; Modified: incubator/stdcxx/trunk/tests/strings/21.string.copy.cpp URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.copy.cpp?rev=406581&r1=406580&r2=406581&view=diff ============================================================================== --- incubator/stdcxx/trunk/tests/strings/21.string.copy.cpp (original) +++ incubator/stdcxx/trunk/tests/strings/21.string.copy.cpp Mon May 15 01:14:29 2006 @@ -31,15 +31,13 @@ #include <21.strings.h> // for StringMembers #include // for rw_assert() -#include // for rw_widen() +#include // for rw_expand() /**************************************************************************/ // for convenience and brevity #define NPOS _RWSTD_SIZE_MAX -#define LSTR StringMembers::long_string -#define LLEN StringMembers::long_string_len #define Copy(which) StringMembers::copy_ ## which typedef StringMembers::OverloadId OverloadId; @@ -91,7 +89,9 @@ TEST ("\0ab\0\0\0c\0", 5, "\0ab\0\0"), TEST ("\0\0ab\0\0c\0", 6, "\0\0ab\0\0"), - TEST ("last", 4, "last") + TEST ("x@4096", 4096, "x@4096"), + + TEST ("last", 4, "last") }; /**************************************************************************/ @@ -147,13 +147,13 @@ TEST ("\0\0ab\0\0c\0", 6, 0, "\0\0ab\0\0", 0), TEST ("\0\0ab\0\0c\0", 4, 1, "\0ab\0", 0), - TEST (LSTR, LLEN - 1, 0, LSTR, 0), - TEST (LSTR, 2, 1, "xx", 0), - TEST (LSTR, LLEN - 1, LLEN - 2, "x", 0), - - TEST ("\0", 0, 2, "", 1), - TEST ("a", 0, 10, "", 1), - TEST (LSTR, 0, LLEN + 10, "", 1), + TEST ("x@4096", 4096, 0, "x@4096", 0), + TEST ("x@4096", 2, 1, "xx", 0), + TEST ("x@4096", 4096, 4095, "x", 0), + + TEST ("\0", 0, 2, "", 1), + TEST ("a", 0, 10, "", 1), + TEST ("x@4096", 0, 4106, "", 1), TEST ("last", 4, 0, "last", 0) }; @@ -166,16 +166,28 @@ const TestCase &tcase) { typedef std::allocator Allocator; - typedef std::basic_string TestString; + typedef std::basic_string String; + + static const std::size_t BUFSIZE = 256; + + static charT wstr_buf [BUFSIZE]; + std::size_t str_len = sizeof wstr_buf / sizeof *wstr_buf; + charT* wstr = rw_expand (wstr_buf, tcase.str, tcase.str_len, &str_len); + + static charT wres_buf [BUFSIZE]; + std::size_t res_len = sizeof wres_buf / sizeof *wres_buf; + charT* wres = rw_expand (wres_buf, tcase.res, tcase.nres, &res_len); - static charT wstr [LLEN]; + // construct the string object + const String str (wstr, str_len); - // construct strings - rw_widen (wstr, tcase.str, tcase.str_len); - const TestString str (wstr, tcase.str_len); + if (wstr != wstr_buf) + delete[] wstr; + + wstr = 0; const std::size_t min_len = - tcase.str_len < std::size_t (tcase.size) ? tcase.str_len : tcase.size; + str_len < std::size_t (tcase.size) ? str_len : tcase.size; std::size_t res = 0; @@ -199,8 +211,12 @@ #else // if defined (_RWSTD_NO_EXCEPTIONS) - if (tcase.bthrow) + if (tcase.bthrow) { + if (wres != wres_buf) + delete[] wres; + return; + } #endif // _RWSTD_NO_EXCEPTIONS @@ -221,12 +237,12 @@ } // verify the returned value - rw_assert (res == tcase.nres, 0, tcase.line, + rw_assert (res == res_len, 0, tcase.line, "line %d. %{$FUNCALL} == %zu, got %zu", - __LINE__, tcase.nres, res); + __LINE__, res_len, res); const std::size_t match = rw_match (tcase.res, s_res, tcase.nres); - bool success = match == tcase.nres; + bool success = match == res_len; rw_assert (success, 0, tcase.line, "line %d. %{$FUNCALL} expected %{#*s}, " @@ -278,6 +294,9 @@ } #endif // _RWSTD_NO_EXCEPTIONS + + if (wres != wres_buf) + delete[] wres; delete[] s_res; } Modified: incubator/stdcxx/trunk/tests/strings/21.string.erase.cpp URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.erase.cpp?rev=406581&r1=406580&r2=406581&view=diff ============================================================================== --- incubator/stdcxx/trunk/tests/strings/21.string.erase.cpp (original) +++ incubator/stdcxx/trunk/tests/strings/21.string.erase.cpp Mon May 15 01:14:29 2006 @@ -31,16 +31,12 @@ #include <21.strings.h> // for StringMembers #include // for rw_test() -#include // for rw_widen() +#include // for rw_expand() +#include // for bad_alloc, replacement operator new -#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE - // disabled for compilers such as IBM VAC++ or MSVC - // that can't reliably replace the operators -# include // for bad_alloc, replacement operator new -#else -# include // for bad_alloc -#endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE +/**************************************************************************/ +// for convenience and brevity #define Erase(which) StringMembers::erase_ ## which typedef StringMembers::OverloadId OverloadId; @@ -48,12 +44,6 @@ typedef StringMembers::Test Test; typedef StringMembers::Function MemFun; -/**************************************************************************/ - -// for convenience and brevity -#define LSTR StringMembers::long_string -#define LLEN StringMembers::long_string_len - static const char* const exceptions[] = { "unknown exception", "out_of_range", "length_error", "bad_alloc", "exception" @@ -84,7 +74,7 @@ TEST ("a\0b\0\0c", ""), TEST ("a\0bc\0\0", ""), - TEST (LSTR, ""), + TEST ("x@4096", ""), TEST ("last", "") }; @@ -138,12 +128,13 @@ TEST ("a", 3, "a", 1), TEST ("t\0 s", 5, "t\0 s", 1), TEST ("ab\0c\0\0", 10, "ab\0c\0\0", 1), - TEST (LSTR, LLEN + 10, LSTR, 1), + TEST ("x@4096", 4106, "x@4096", 1), - TEST (LSTR, 0, "", 0), - TEST (LSTR, 1, "x", 0), - TEST (LSTR, 4, "xxxx", 0), - TEST (LSTR, LLEN - 1, LSTR, 0), + TEST ("x@4096", 0, "", 0), + TEST ("x@4096", 1, "x", 0), + TEST ("x@4096", 4, "xxxx", 0), + TEST ("x@4096", 4096, "x@4096", 0), + TEST ("x@2048y@2048", 2048,"x@2048", 0), TEST ("last test", 4, "last", 0) }; @@ -217,18 +208,19 @@ TEST ("a", 0, 3, "", 0), TEST ("t\0 s", 0, 9, "", 0), TEST ("ab\0c\0\0", 0, 10, "", 0), - TEST (LSTR, 0, LLEN + 9, "", 0), + TEST ("x@4096", 0, 4105, "", 0), TEST ("a", 3, 1, "a", 1), TEST ("t\0 s", 5, 1, "t\0 s", 1), TEST ("ab\0c\0\0", 10, 1, "ab\0c\0\0", 1), - TEST (LSTR, LLEN + 10, 1, LSTR, 1), + TEST ("x@4096", 4106, 1, "x@4096", 1), - TEST (LSTR, 0, LLEN - 1, "", 0), - TEST (LSTR, 1, LLEN - 2, "x", 0), - TEST (LSTR, 4, LLEN - 5, "xxxx", 0), - TEST (LSTR, 4, LLEN - 7, "xxxxxx", 0), - TEST (LSTR, LLEN - 1, LLEN - 1, LSTR, 0), + TEST ("x@4096", 0, 4096, "", 0), + TEST ("x@4096", 1, 4095, "x", 0), + TEST ("x@4096", 4, 4092, "xxxx", 0), + TEST ("x@4096", 4, 4090, "xxxxxx", 0), + TEST ("x@4096", 4096, 4096, "x@4096", 0), + TEST ("x@2048y@2048", 1, 4094, "xy", 0), TEST ("last test", 4, 1, "lasttest", 0) }; @@ -274,17 +266,12 @@ TEST ("\0ab\0\0c", 2, "\0a\0\0c"), TEST ("ab\0c\0\0", 5, "ab\0c\0"), -#undef TEST -#define TEST(str, off, res, res_len) { \ - __LINE__, off, -1, -1, -1, -1, str, sizeof str - 1, \ - 0, 0, res, res_len, 0 } - - TEST (LSTR, LLEN - 2, (LSTR + 1), LLEN - 2), - TEST (LSTR, LLEN - 9, (LSTR + 1), LLEN - 2), - TEST (LSTR, 0, (LSTR + 1), LLEN - 2), - TEST (LSTR, 9, (LSTR + 1), LLEN - 2), + TEST ("x@4096y", 4096, "x@4096"), + TEST ("x@4096", 4088, "x@4095"), + TEST ("ax@4096", 0, "x@4096"), + TEST ("x@4096", 9, "x@4095"), - TEST ("last test", 4, "lasttest", 8) + TEST ("last test", 4, "lasttest") }; /**************************************************************************/ @@ -296,34 +283,60 @@ const TestCase &cs) { typedef std::allocator Allocator; - typedef std::basic_string TestString; - typedef typename TestString::iterator StringIter; - typedef typename TestString::const_iterator ConstStringIter; + typedef std::basic_string String; + typedef typename String::iterator StringIter; + typedef typename String::const_iterator ConstStringIter; const bool use_iters = Erase (iter) <= which; if (use_iters && cs.bthrow) return; - static charT wstr [LLEN]; + static const std::size_t BUFSIZE = 256; - rw_widen (wstr, cs.str, cs.str_len); + static charT wstr_buf [BUFSIZE]; + std::size_t str_len = sizeof wstr_buf / sizeof *wstr_buf; + charT* wstr = rw_expand (wstr_buf, cs.str, cs.str_len, &str_len); + + static charT wres_buf [BUFSIZE]; + std::size_t res_len = sizeof wres_buf / sizeof *wres_buf; + charT* wres = rw_expand (wres_buf, cs.res, cs.nres, &res_len); + + static char wres_charbuf [BUFSIZE]; + char* res_char = 0; + if (use_iters) { + std::size_t res_charlen = sizeof wres_charbuf / sizeof *wres_charbuf; + res_char = rw_expand (wres_charbuf, cs.res, cs.nres, &res_charlen); + } - TestString s_str (wstr, cs.str_len); + // construct the string object to be modified + // and the (possibly unused) argument string + /* const */ String s_str (wstr, str_len); + + if (wstr != wstr_buf) + delete[] wstr; + + wstr = 0; + + // save the state of the string object before the call + // to detect wxception safety violations (changes to + // the state of the object after an exception) + const StringState str_state (rw_get_string_state (s_str)); std::size_t res_off = 0; StringIter res_iter = s_str.begin (); - int first = use_iters ? cs.off : cs.str_len + 1; - int last = use_iters ? cs.off + cs.size : cs.str_len + 1; - - StringIter it_first (std::size_t (first) >= s_str.size () ? - s_str.end () : s_str.begin () + first); - StringIter it_last (std::size_t (last) >= s_str.size () ? - s_str.end () : s_str.begin () + last); - - const std::size_t size = s_str.size (); - const std::size_t capacity = s_str.capacity (); - const ConstStringIter sbegin = s_str.begin (); + // compute the offset and the extent (the number of elements) + // of the first range into the string object being modified + const std::size_t size1 = str_len; + const std::size_t off1 = + std::size_t (cs.off) < size1 ? std::size_t (cs.off) : size1; + const std::size_t ext1 = + off1 + cs.size < size1 ? cs.size : size1 - off1; + + // create a pair of iterators into the string object being + // modified (used only by the iterator overloads) + const StringIter it_first (s_str.begin () + off1); + const StringIter it_last (it_first + ext1); #ifndef _RWSTD_NO_EXCEPTIONS @@ -336,26 +349,30 @@ #else // if defined (_RWSTD_NO_EXCEPTIONS) - if (cs.bthrow) + if (cs.bthrow) { + if (wres != wres_buf) + delete[] wres; + return; + } #endif // _RWSTD_NO_EXCEPTIONS try { switch (which) { case Erase (void): { - const TestString& s_res = s_str.erase (); + const String& s_res = s_str.erase (); res_off = &s_res - &s_str; break; } case Erase (size): { - const TestString& s_res = s_str.erase (cs.off); + const String& s_res = s_str.erase (cs.off); res_off = &s_res - &s_str; break; } case Erase (size_size): { - const TestString& s_res = s_str.erase (cs.off, cs.size); + const String& s_res = s_str.erase (cs.off, cs.size); res_off = &s_res - &s_str; break; } @@ -391,35 +408,35 @@ "difference with begin is %td", __LINE__, res_iter - begin); - if (std::size_t (cs.off) >= cs.nres) { + if (std::size_t (cs.off) >= res_len) { rw_assert (res_iter == end, 0, cs.line, "line %d. %{$FUNCALL} != end()", __LINE__); } else { const std::size_t match = - rw_match (cs.res + cs.off, &(*res_iter), 1); + rw_match (res_char + cs.off, &(*res_iter), 1); rw_assert (1 == match, 0, cs.line, - "line %d. %{$FUNCALL} == %#c, got %#c", - __LINE__, cs.res[cs.off], *res_iter); + "line %d. %{$FUNCALL} == %{#c}, got %{#c}", + __LINE__, res_char[cs.off], *res_iter); } } // verfiy that strings length are equal - rw_assert (cs.nres == s_str.size (), 0, cs.line, + rw_assert (res_len == s_str.size (), 0, cs.line, "line %d. %{$FUNCALL} expected %{#*s} with length " "%zu, got %{/*.*Gs} with length %zu", __LINE__, int (cs.nres), cs.res, - cs.nres, int (sizeof (charT)), + res_len, int (sizeof (charT)), int (s_str.size ()), s_str.c_str (), s_str.size ()); - if (cs.nres == s_str.size ()) { + if (res_len == s_str.size ()) { // if the result length matches the expected length // (and only then), also verify that the modified // string matches the expected result const std::size_t match = rw_match (cs.res, s_str.c_str(), cs.nres); - rw_assert (match == cs.nres, 0, cs.line, + rw_assert (match == res_len, 0, cs.line, "line %d. %{$FUNCALL} expected %{#*s}, " "got %{/*.*Gs}, difference at offset %zu", __LINE__, int (cs.nres), cs.res, @@ -452,32 +469,20 @@ __LINE__, 0 != expected, expected, caught); } - if (caught) { - // verify that an exception thrown during allocation - // didn't cause a change in the state of the object +#endif // _RWSTD_NO_EXCEPTIONS - rw_assert (s_str.size () == size, 0, cs.line, - "line %d: %{$FUNCALL}: size unexpectedly changed " - "from %zu to %zu after an exception", - __LINE__, size, s_str.size ()); - - rw_assert (s_str.capacity () == capacity, 0, cs.line, - "line %d: %{$FUNCALL}: capacity unexpectedly " - "changed from %zu to %zu after an exception", - __LINE__, capacity, s_str.capacity ()); - - rw_assert (s_str.begin () == sbegin, 0, cs.line, - "line %d: %{$FUNCALL}: begin() unexpectedly " - "changed from after an exception by %d", - __LINE__, s_str.begin () - sbegin); + if (caught) { + // verify that an exception thrown during allocation + // didn't cause a change in the state of the object + str_state.assert_equal (rw_get_string_state (s_str), + __LINE__, cs.line, caught); } -#else // if defined (_RWSTD_NO_EXCEPTIONS) + if (res_char != wres_charbuf) + delete[] res_char; - _RWSTD_UNUSED (size); - _RWSTD_UNUSED (capacity); - -#endif // _RWSTD_NO_EXCEPTIONS + if (wres != wres_buf) + delete[] wres; } /**************************************************************************/ Modified: incubator/stdcxx/trunk/tests/strings/21.string.find.cpp URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.find.cpp?rev=406581&r1=406580&r2=406581&view=diff ============================================================================== --- incubator/stdcxx/trunk/tests/strings/21.string.find.cpp (original) +++ incubator/stdcxx/trunk/tests/strings/21.string.find.cpp Mon May 15 01:14:29 2006 @@ -31,15 +31,12 @@ #include <21.strings.h> // for StringMembers #include // for rw_assert() -#include // for rw_widen() +#include // for rw_expand() /**************************************************************************/ // for convenience and brevity - #define NPOS _RWSTD_SIZE_MAX -#define LSTR StringMembers::long_string -#define LLEN StringMembers::long_string_len #define Find(which) StringMembers::find_ ## which typedef StringMembers::OverloadId OverloadId; @@ -117,17 +114,17 @@ TEST ("aaaaaaaaaa", "aaaaaaaaa", 0), TEST ("aaaaaaaaa", "aaaaaaaaaa", NPOS), - TEST (LSTR, "", 0), - TEST (LSTR, "a", NPOS), - TEST (LSTR, "x", 0), - TEST (LSTR, "xxx", 0), - TEST (LSTR, "xxa", NPOS), - TEST ("abc", LSTR, NPOS), - TEST ("xxxxxxxxxx", LSTR, NPOS), + TEST ("x@4096", "", 0), + TEST ("x@4096", "a", NPOS), + TEST ("x@4096", "x", 0), + TEST ("x@4096", "xxx", 0), + TEST ("x@4096", "xxa", NPOS), + TEST ("abc", "x@4096", NPOS), + TEST ("xxxxxxxxxx", "x@4096", NPOS), TEST ("abcdefghij", 0, 0), TEST ("\0cb\0\0ge", 0, 0), - TEST (LSTR, 0, 0), + TEST ("x@4096", 0, 0), TEST ("last test", "test", 5) }; @@ -202,17 +199,17 @@ TEST ("aaaaaaaaaa", "aaaaaaaaa", 0), TEST ("aaaaaaaaa", "aaaaaaaaaa", NPOS), - TEST (LSTR, "", 0), - TEST (LSTR, "a", NPOS), - TEST (LSTR, "x", 0), - TEST (LSTR, "xxx", 0), - TEST (LSTR, "xxa", NPOS), - TEST ("abc", LSTR, NPOS), - TEST ("xxxxxxxxxx", LSTR, NPOS), + TEST ("x@4096", "", 0), + TEST ("x@4096", "a", NPOS), + TEST ("x@4096", "x", 0), + TEST ("x@4096", "xxx", 0), + TEST ("x@4096", "xxa", NPOS), + TEST ("abc", "x@4096", NPOS), + TEST ("xxxxxxxxxx", "x@4096", NPOS), TEST ("abcdefghij", 0, 0), TEST ("\0cb\0\0ge", 0, 0), - TEST (LSTR, 0, 0), + TEST ("x@4096", 0, 0), TEST ("last test", "test", 5) }; @@ -293,22 +290,22 @@ TEST ("aaaaaaaaaa", "aaaaaaaaa", 2, NPOS), TEST ("aaaaaaaaa", "aaaaaaaaaa", 0, NPOS), - TEST (LSTR, "", 0, 0), - TEST (LSTR, "a", 0, NPOS), - TEST (LSTR, "x", 0, 0), - TEST (LSTR, "xxx", 10, 10), - TEST (LSTR, "xxa", 10, NPOS), - TEST ("abc", LSTR, 2, NPOS), - TEST ("xxxxxxxxxx", LSTR, 0, NPOS), + TEST ("x@4096", "", 0, 0), + TEST ("x@4096", "a", 0, NPOS), + TEST ("x@4096", "x", 0, 0), + TEST ("x@4096", "xxx", 10, 10), + TEST ("x@4096", "xxa", 10, NPOS), + TEST ("abc", "x@4096", 2, NPOS), + TEST ("xxxxxxxxxx", "x@4096", 0, NPOS), - TEST (LSTR, "xxx", LLEN - 4, LLEN - 4), - TEST (LSTR, "xxx", LLEN - 3, NPOS), + TEST ("x@4096", "xxx", 4092, 4092), + TEST ("x@4096", "xxx", 4094, NPOS), TEST ("abcdefghij", 0, 0, 0), TEST ("abcdefghij", 0, 1, NPOS), TEST ("\0cb\0\0ge", 0, 5, 5), - TEST (LSTR, 0, 0, 0), - TEST (LSTR, 0, 1, NPOS), + TEST ("x@4096", 0, 0, 0), + TEST ("x@4096", 0, 1, NPOS), TEST ("", "", 1, NPOS), TEST ("abcdefghij", "abc", 10, NPOS), @@ -410,27 +407,27 @@ TEST ("aaaaaaaaa", "aaaaaaaaaa", 0, 10, NPOS), TEST ("aaaaaaaaa", "aaaaaaaaaa", 0, 7, 0), - TEST (LSTR, "", 0, 0, 0), - TEST (LSTR, "a", 0, 1, NPOS), - TEST (LSTR, "x", 0, 1, 0), - TEST (LSTR, "xxx", 10, 3, 10), - TEST (LSTR, "xxa", 10, 3, NPOS), - TEST (LSTR, "xxa", 10, 2, 10), - TEST ("abc", LSTR, 2, 10, NPOS), - TEST ("xxxxxxxxxx", LSTR, 0, LLEN - 1, NPOS), - TEST ("xxxxxxxxxx", LSTR, 2, 4, 2), - - TEST (LSTR, "xxx", LLEN - 4, 3, LLEN - 4), - TEST (LSTR, "xxx", LLEN - 3, 3, NPOS), - TEST (LSTR, "xxx", LLEN - 3, 2, LLEN - 3), - - TEST ("abcdefghij", 0, 0, 9, 0), - TEST ("abcdefghij", 0, 1, 9, NPOS), - TEST ("\0cb\0\0ge", 0, 5, 7, NPOS), - TEST ("\0cb\0ge\0", 0, 6, 1, 6), - TEST (LSTR, 0, 0, LLEN - 1, 0), - TEST (LSTR, 0, 1, LLEN - 1, NPOS), - TEST (LSTR, 0, 5, LLEN - 6, 5), + TEST ("x@4096", "", 0, 0, 0), + TEST ("x@4096", "a", 0, 1, NPOS), + TEST ("x@4096", "x", 0, 1, 0), + TEST ("x@4096", "xxx", 10, 3, 10), + TEST ("x@4096", "xxa", 10, 3, NPOS), + TEST ("x@4096", "xxa", 10, 2, 10), + TEST ("abc", "x@4096", 2, 10, NPOS), + TEST ("xxxxxxxxxx", "x@4096", 0, 4096, NPOS), + TEST ("xxxxxxxxxx", "x@4096", 2, 4, 2), + + TEST ("x@4096", "xxx", 4093, 3, 4093), + TEST ("x@4096", "xxx", 4094, 3, NPOS), + TEST ("x@4096", "xxx", 4094, 2, 4094), + + TEST ("abcdefghij", 0, 0, 9, 0), + TEST ("abcdefghij", 0, 1, 9, NPOS), + TEST ("\0cb\0\0ge", 0, 5, 7, NPOS), + TEST ("\0cb\0ge\0", 0, 6, 1, 6), + TEST ("x@4096", 0, 0, 4096, 0), + TEST ("x@4096", 0, 1, 4096, NPOS), + TEST ("x@4096", 0, 5, 4091, 5), TEST ("", "", 1, 0, NPOS), TEST ("abcdefghij", "abc", 10, 3, NPOS), @@ -439,8 +436,8 @@ // excercise strictly undefined behavior TEST ("", "cba", 0, -1, NPOS), TEST ("abcdefghij", "cba", 0, -1, NPOS), - TEST (LSTR, "xxx", 0, -1, NPOS), - TEST ("abcdefghij", LSTR, 0, -1, NPOS), + TEST ("x@4096", "xxx", 0, -1, NPOS), + TEST ("abcdefghij", "x@4096", 0, -1, NPOS), TEST ("last test", "test", 0, 4, 5) }; @@ -517,23 +514,23 @@ TEST ("aaaaaaaaaa", "aaaaaaaaa", 2, NPOS), TEST ("aaaaaaaaa", "aaaaaaaaaa", 0, NPOS), - TEST (LSTR, "", 0, 0), - TEST (LSTR, "a", 0, NPOS), - TEST (LSTR, "x", 0, 0), - TEST (LSTR, "xxx", 10, 10), - TEST (LSTR, "xxa", 10, NPOS), - TEST ("abc", LSTR, 2, NPOS), - TEST ("xxxxxxxxxx", LSTR, 0, NPOS), + TEST ("x@4096", "", 0, 0), + TEST ("x@4096", "a", 0, NPOS), + TEST ("x@4096", "x", 0, 0), + TEST ("x@4096", "xxx", 10, 10), + TEST ("x@4096", "xxa", 10, NPOS), + TEST ("abc", "x@4096", 2, NPOS), + TEST ("xxxxxxxxxx", "x@4096", 0, NPOS), - TEST (LSTR, "xxx", LLEN - 4, LLEN - 4), - TEST (LSTR, "xxx", LLEN - 3, NPOS), + TEST ("x@4096", "xxx", 4093, 4093), + TEST ("x@4096", "xxx", 4094, NPOS), TEST ("abcdefghij", 0, 0, 0), TEST ("abcdefghij", 0, 1, NPOS), TEST ("\0cb\0\0ge", 0, 5, NPOS), TEST ("\0cb\0\0ge", 0, 0, 0), - TEST (LSTR, 0, 0, 0), - TEST (LSTR, 0, 1, NPOS), + TEST ("x@4096", 0, 0, 0), + TEST ("x@4096", 0, 1, NPOS), TEST ("", "", 1, NPOS), TEST ("abcdefghij", "abc", 10, NPOS), @@ -577,9 +574,9 @@ TEST ("\0cbge\0\0", 'b', 2), TEST ("\0cbge\0\0", 'a', NPOS), - TEST (LSTR, 'x', 0), - TEST (LSTR, '\0', NPOS), - TEST (LSTR, 'a', NPOS), + TEST ("x@4096", 'x', 0), + TEST ("x@4096", '\0', NPOS), + TEST ("x@4096", 'a', NPOS), TEST ("last test", 't', 3) }; @@ -628,12 +625,13 @@ TEST ("\0bgeb\0\0", 'b', 2, 4), TEST ("\0cbge\0\0", 'a', 1, NPOS), - TEST (LSTR, 'x', 0, 0), - TEST (LSTR, 'x', 5, 5), - TEST (LSTR, '\0', 0, NPOS), - TEST (LSTR, 'a', 3, NPOS), - TEST (LSTR, 'x', LLEN - 1, NPOS), - TEST (LSTR, 'x', LLEN - 2, LLEN - 2), + TEST ("x@4096", 'x', 0, 0), + TEST ("x@4096", 'x', 5, 5), + TEST ("x@4096", '\0', 0, NPOS), + TEST ("x@2048\0xxx",'\0', 0, 2048), + TEST ("x@4096", 'a', 3, NPOS), + TEST ("x@4096", 'x', 4096, NPOS), + TEST ("x@4096", 'x', 4095, 4095), TEST ("last test", 't', 0, 3) }; @@ -646,17 +644,31 @@ const TestCase &tcase) { typedef std::allocator Allocator; - typedef std::basic_string TestString; - typedef typename TestString::const_iterator ConstStringIter; + typedef std::basic_string String; + + static const std::size_t BUFSIZE = 256; + + static charT wstr_buf [BUFSIZE]; + static charT warg_buf [BUFSIZE]; + + std::size_t str_len = sizeof wstr_buf / sizeof *wstr_buf; + std::size_t arg_len = sizeof warg_buf / sizeof *warg_buf; + + charT* wstr = rw_expand (wstr_buf, tcase.str, tcase.str_len, &str_len); + charT* warg = rw_expand (warg_buf, tcase.arg, tcase.arg_len, &arg_len); + + // construct the string object and the argument string + const String s_str (wstr, str_len); + const String s_arg (warg, arg_len); - static charT wstr [LLEN]; - static charT warg [LLEN]; + if (wstr != wstr_buf) + delete[] wstr; - rw_widen (wstr, tcase.str, tcase.str_len); - rw_widen (warg, tcase.arg, tcase.arg_len); + if (warg != warg_buf) + delete[] warg; - const TestString s_str (wstr, tcase.str_len); - const TestString s_arg (warg, tcase.arg_len); + wstr = 0; + warg = 0; // save the state of the string object before the call // to detect wxception safety violations (changes to @@ -664,10 +676,11 @@ const StringState str_state (rw_get_string_state (s_str)); std::size_t res = 0; - std::size_t exp_res = NPOS != tcase.nres ? tcase.nres : TestString::npos; + std::size_t exp_res = NPOS != tcase.nres ? tcase.nres : String::npos; - const charT* const ptr_arg = tcase.arg ? warg : s_str.c_str (); - const TestString& str_arg = tcase.arg ? s_arg : s_str; + // string function argument + const charT* const arg_ptr = tcase.arg ? s_arg.c_str () : s_str.c_str (); + const String& arg_str = tcase.arg ? s_arg : s_str; const charT arg_val = make_char (char (tcase.val), (charT*)0); std::size_t size = tcase.size >= 0 ? tcase.size : s_arg.max_size () + 1; @@ -688,27 +701,27 @@ try { switch (which) { case Find (ptr): { - res = s_str.find (ptr_arg); + res = s_str.find (arg_ptr); break; } case Find (str): { - res = s_str.find (str_arg); + res = s_str.find (arg_str); break; } case Find (ptr_size): { - res = s_str.find (ptr_arg, tcase.off); + res = s_str.find (arg_ptr, tcase.off); break; } case Find (ptr_size_size): { - res = s_str.find (ptr_arg, tcase.off, size); + res = s_str.find (arg_ptr, tcase.off, size); break; } case Find (str_size): { - res = s_str.find (str_arg, tcase.off); + res = s_str.find (arg_str, tcase.off); break; } @@ -732,7 +745,7 @@ "line %d. %{$FUNCALL} == %{?}%zu%{;}%{?}npos%{;}, " "got %{?}%zu%{;}%{?}npos%{;}", __LINE__, NPOS != tcase.nres, exp_res, NPOS == tcase.nres, - TestString::npos != res, res, TestString::npos == res); + String::npos != res, res, String::npos == res); } #ifndef _RWSTD_NO_EXCEPTIONS