You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by an...@apache.org on 2006/05/15 10:14:32 UTC
svn commit: r406581 [3/3] - /incubator/stdcxx/trunk/tests/strings/
Modified: incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp?rev=406581&r1=406580&r2=406581&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp Mon May 15 01:14:29 2006
@@ -27,21 +27,17 @@
#include <string> // for string
#include <stdexcept> // for out_of_range, length_error
-
#include <cstddef> // for size_t
#include <21.strings.h> // for StringMembers
#include <alg_test.h> // for InputIter
#include <driver.h> // for rw_test()
-#include <rw_char.h> // for rw_widen()
+#include <rw_char.h> // for rw_expand()
#include <rw_new.h> // for bad_alloc, replacement operator new
/**************************************************************************/
// for convenience and brevity
-
-#define LSTR StringMembers::long_string
-#define LLEN StringMembers::long_string_len
#define Insert(which) StringMembers::insert_ ## which
typedef StringMembers::OverloadId OverloadId;
@@ -57,7 +53,7 @@
/**************************************************************************/
// used to exercise
-// insert (size_type pos, const charT* s)
+// insert (size_type, const value_type*)
static const TestCase
size_ptr_test_cases [] = {
@@ -110,15 +106,18 @@
TEST ("abc", 2, 0, "ababcc", 0),
TEST ("a\0bc\0\0", 0, 0, "aa\0bc\0\0", 0),
TEST ("a\0bc\0\0", 6, 0, "a\0bc\0\0a", 0),
+ TEST ("x@4096", 5, 0, "x@8192", 0),
- TEST ("", 0, LSTR, LSTR, 0),
- TEST (LSTR, 0, "", LSTR, 0),
+ TEST ("", 0, "x@4096", "x@4096", 0),
+ TEST ("x@4096", 0, "", "x@4096", 0),
+ TEST ("x@4096", 2, "a@100", "xxa@100x@4094", 0),
+ TEST ("a@102", 2, "x@4096", "aax@4096a@100", 0),
TEST ("\0", 2, "", "", 1),
TEST ("a", 2, "", "", 1),
- TEST (LSTR,LLEN + 10, "", "", 1),
+ TEST ("x@4096", 4106, "", "", 1),
- TEST ("", 0, LSTR, LSTR, -1),
+ TEST ("", 0, "x@4096", "x@4096", -1),
TEST ("last", 4, "test", "lasttest", 0)
};
@@ -126,7 +125,7 @@
/**************************************************************************/
// used to exercise
-// insert (size_type pos, const basic_string& str)
+// insert (size_type, const basic_string&)
static const TestCase
size_str_test_cases [] = {
@@ -178,15 +177,18 @@
TEST ("abc", 2, 0, "ababcc", 0),
TEST ("a\0bc\0\0", 0, 0, "a\0bc\0\0a\0bc\0\0", 0),
TEST ("a\0bc\0\0", 6, 0, "a\0bc\0\0a\0bc\0\0", 0),
+ TEST ("x@4096", 5, 0, "x@8192", 0),
- TEST ("", 0, LSTR, LSTR, 0),
- TEST (LSTR, 0, "", LSTR, 0),
+ TEST ("", 0, "x@4096", "x@4096", 0),
+ TEST ("x@4096", 0, "", "x@4096", 0),
+ TEST ("x@4096", 2, "a@100", "xxa@100x@4094", 0),
+ TEST ("a@102", 2, "x@4096", "aax@4096a@100", 0),
TEST ("\0", 2, "", "", 1),
TEST ("a", 2, "", "", 1),
- TEST (LSTR,LLEN + 10, "", "", 1),
+ TEST ("x@4096", 4106, "", "", 1),
- TEST ("", 0, LSTR, LSTR, -1),
+ TEST ("", 0, "x@4096", "x@4096", -1),
TEST ("last", 4, "test", "lasttest", 0)
};
@@ -194,8 +196,8 @@
/**************************************************************************/
// exrcises
-// insert (size_type off, basic_string& str, size_type off2, size_type n)
-// insert (iterator p, InputIterator first, InputIterator last)
+// insert (size_type, basic_string&, size_type, size_type)
+// insert (iterator, InputIterator, InputIterator)
static const TestCase
range_test_cases [] = {
@@ -263,8 +265,14 @@
TEST ("a\0bc\0\0", 6, 0, 1, 3, "a\0bc\0\0\0bc", 0),
TEST ("abcdef", 0, 0, 1, 2, "bcabcdef", 0),
- TEST ("", 0, LSTR, 0, LLEN, LSTR, 0),
- TEST (LSTR, 0, "", 0, 0, LSTR, 0),
+ TEST ("", 0, "x@4096", 0, 4096, "x@4096", 0),
+ TEST ("x@4096", 0, "", 0, 0, "x@4096", 0),
+ TEST ("a@1000", 0, "b@1000", 0, 999, "b@999a@1000", 0),
+ TEST ("a@1000", 1, "b@1001", 0, 1000, "ab@1000a@999", 0),
+ TEST ("a@1000", 2, "b@1002", 0, 1001, "aab@1001a@998", 0),
+ TEST ("a@1000", 998, "b@1000", 1, 999, "a@998b@999aa", 0),
+ TEST ("a@1000", 999, "b@1001", 2, 1000, "a@999b@999a", 0),
+ TEST ("a@1000", 2, "b@1002", 999, 1001, "aabbba@998", 0),
TEST ("\0", 2, "", 0, 0, "", 1),
TEST ("", 0, "\0", 2, 0, "", 2),
@@ -272,10 +280,10 @@
TEST ("a", 2, "", 0, 0, "", 1),
TEST ("", 0, "a", 2, 0, "", 2),
- TEST (LSTR,LLEN + 10, "", 0, 0, "", 1),
- TEST ("", 0, LSTR,LLEN + 10, 0, "", 2),
+ TEST ("x@4096", 4106, "", 0, 0, "", 1),
+ TEST ("", 0, "x@4096", 4106, 0, "", 2),
- TEST ("", 0, LSTR, 0, LLEN - 1, LSTR, -1),
+ TEST ("", 0, "x@4096", 0, 4096, "x@4096", -1),
TEST ("last", 4, "test", 0, 4, "lasttest", 0)
};
@@ -283,7 +291,7 @@
/**************************************************************************/
// used to exercise
-// insert (size_type pos, const charT* s, size_type n)
+// insert (size_type, const value_type*, size_type)
static const TestCase
size_ptr_size_test_cases [] = {
@@ -336,15 +344,24 @@
TEST ("abc", 2, 0, 2, "ababc", 0),
TEST ("\0abc\0\0", 0, 0, 1, "\0\0abc\0\0", 0),
TEST ("a\0bc\0\0", 6, 0, 3, "a\0bc\0\0a\0b", 0),
+ TEST ("a@4096", 0, 0, 1111, "a@5207", 0),
+ TEST ("b@4096", 1, 0, 2222, "b@6318", 0),
+
+ TEST ("x@4096", 1, "\0", 1, "x\0x@4095", 0),
+ TEST ("x@4096", 0, "\0", 1, "\0x@4096", 0),
+ TEST ("x@4096", 4096, "\0", 1, "x@4096\0", 0),
+ TEST ("x@4096", 0, "ab", 2, "abx@4096", 0),
+ TEST ("x@4096", 4095, "ab", 1, "x@4095ax", 0),
+ TEST ("x@4096", 4094, "\0\0", 2, "x@4094\0\0xx", 0),
- TEST ("", 0, LSTR, LLEN - 1, LSTR, 0),
- TEST (LSTR, 0, "", 0, LSTR, 0),
+ TEST ("", 0, "x@4096", 4096, "x@4096", 0),
+ TEST ("x@4096", 0, "", 0, "x@4096", 0),
TEST ("\0", 2, "", 0, "", 1),
TEST ("a", 2, "", 0, "", 1),
- TEST (LSTR,LLEN + 10, "", 0, "", 1),
+ TEST ("x@4096", 4106, "", 0, "", 1),
- TEST ("", 0, LSTR, LLEN - 1, LSTR, -1),
+ TEST ("", 0, "x@4096", 4095, "x@4095", -1),
TEST ("last", 4, "test", 4, "lasttest", 0)
};
@@ -352,8 +369,8 @@
/**************************************************************************/
// exrecises
-// insert (size_type pos, size_type n, charT c)
-// insert (iterator p, size_type n, charT c)
+// insert (size_type, size_type, value_type)
+// insert (iterator, size_type, value_type)
static const TestCase
size_val_test_cases [] = {
@@ -408,10 +425,18 @@
TEST ("\0ab\0\0c", 0, 3, '\0', "\0\0\0\0ab\0\0c", 0),
TEST ("a\0bc\0\0", 6, 2, 'a', "a\0bc\0\0aa", 0),
- TEST ("", 0, LLEN - 1, 'x', LSTR, 0),
- TEST (LSTR, 0, 0, 'x', LSTR, 0),
+ TEST ("", 0, 4106, 'x', "x@4106", 0),
+ TEST ("x@4096", 0, 2, 'a', "aax@4096", 0),
- TEST ("", 0, LLEN - 1, 'x', LSTR, -1),
+ TEST ("x@4096", 0, 2, 'a', "aax@4096", 0),
+ TEST ("x@4096", 1, 2, 'a', "xaax@4095", 0),
+ TEST ("x@4096", 1, 1, '\0', "x\0x@4095", 0),
+
+ TEST ("a", 0, 4095, 'x', "x@4095a", 0),
+ TEST ("x@4096", 0, 2047, 'b', "b@2047x@4096", 0),
+ TEST ("x@4096", 2047, 2048, 'x', "x@6144", 0),
+
+ TEST ("", 0, 4106, 'x', "x@4106", -1),
TEST ("last", 4, 4, 't', "lasttttt", 0)
};
@@ -419,7 +444,7 @@
/**************************************************************************/
// used to exercise
-// insert (iterator p, charT c)
+// insert (iterator, value_type)
static const TestCase
val_test_cases [] = {
@@ -459,21 +484,23 @@
TEST ("\0ab\0\0c", 0, '\0', "\0\0ab\0\0c", 0),
TEST ("a\0bc\0\0", 6, 'a', "a\0bc\0\0a", 0),
-#undef TEST
-#define TEST(str, len, off, val, res, bthrow) \
- { __LINE__, off, -1, -1, -1, val, str, len, 0, \
- 0, res, sizeof res - 1, bthrow }
+ TEST ("x@4096", 0, 'a', "ax@4096", 0),
+ TEST ("x@4096", 1, 'a', "xax@4095", 0),
+ TEST ("x@4096", 1, '\0', "x\0x@4095", 0),
- TEST (LSTR + 1, LLEN - 2, 0, 'x', LSTR, -1),
+ TEST ("x@4095", 0, 'x', "x@4096", -1),
- TEST ("last", 4, 4, 't', "lastt", 0)
+ TEST ("last", 4, 't', "lastt", 0)
};
/**************************************************************************/
template <class charT, class Traits, class Iterator>
-void test_insert_range (charT* wstr,
- charT* warg,
+void test_insert_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)
@@ -485,36 +512,52 @@
const char* const itname =
tcase.arg ? type_name (it, (charT*)0) : "basic_string::iterator";
- String s_str (wstr, tcase.str_len);
- String s_arg (warg, tcase.arg_len);
+ // 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 first range into the string object being modified
+ const std::size_t off1 =
+ std::size_t (tcase.off) < size1 ? std::size_t (tcase.off) : 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 off2 =
+ std::size_t (tcase.off2) < size2 ? std::size_t (tcase.off2) : size2;
+ const std::size_t ext2 =
+ off2 + tcase.size2 < size2 ? std::size_t (tcase.size2) : size2 - off2;
- std::size_t off_last = tcase.off2 + tcase.size2;
-
- StringIter iter (s_str.begin () + tcase.off);
+ // create an iterator into the string object being modified
+ StringIter iter (s_str.begin () + off1);
if (tcase.arg) {
- off_last = off_last > s_arg.size () ? s_arg.size () : off_last;
+ const charT* const beg = warg + off2;
+ const charT* const end = beg + ext2;
- const Iterator first = make_iter (warg + tcase.off2,
- warg + tcase.off2, warg + off_last, Iterator (0, 0, 0));
- const Iterator last = make_iter (warg + off_last,
- warg + tcase.off2, warg + off_last, Iterator (0, 0, 0));
+ const Iterator first (beg, beg, end);
+ const Iterator last (end, beg, end);
s_str.insert (iter, first, last);
}
else {
- const StringIter first (s_str.begin () + tcase.off2);
- const StringIter last (off_last > s_str.size () ?
- s_str.end ()
- : s_str.begin () + off_last);
+ // self-referential modification (inserting a range
+ // of elements with a subrange of its own elements)
+ const StringIter first (s_str.begin () + off2);
+ const StringIter last (first + ext2);
s_str.insert (iter, 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 pos %zu for %s",
__LINE__, int (tcase.nres), tcase.res,
@@ -525,15 +568,18 @@
/**************************************************************************/
template <class charT, class Traits>
-void test_insert_range (charT* wstr,
- charT* warg,
+void test_insert_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_insert_range (wstr, warg, (Traits*)0,
+ test_insert_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0,
InputIter<charT>(0, 0, 0), tcase);
// there is no need to call test_insert_range
@@ -541,13 +587,13 @@
if (0 == tcase.arg)
return;
- test_insert_range (wstr, warg, (Traits*)0,
+ test_insert_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0,
ConstFwdIter<charT>(0, 0, 0), tcase);
- test_insert_range (wstr, warg, (Traits*)0,
+ test_insert_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0,
ConstBidirIter<charT>(0, 0, 0), tcase);
- test_insert_range (wstr, warg, (Traits*)0,
+ test_insert_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0,
ConstRandomAccessIter<charT>(0, 0, 0), tcase);
}
@@ -559,26 +605,52 @@
const TestCase &tcase)
{
typedef std::allocator<charT> Allocator;
- typedef std::basic_string <charT, Traits, Allocator> TestString;
- typedef typename TestString::iterator StringIter;
- typedef typename TestString::const_iterator ConstStringIter;
+ typedef std::basic_string <charT, Traits, Allocator> String;
+ typedef typename String::iterator StringIter;
+ typedef typename UserTraits<charT>::MemFun UTMemFun;
+
+ static const std::size_t BUFSIZE = 256;
+
+ static charT wstr_buf [BUFSIZE];
+ static charT warg_buf [BUFSIZE];
- typedef typename UserTraits<charT>::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 warg [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 (warg, 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 insert_range to exercise all iterators
if (Insert (range) == which) {
- test_insert_range (wstr, warg, (Traits*)0, tcase);
+ test_insert_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 (warg, tcase.arg_len);
+ /* 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;
// save the state of the string object before the call
// to detect wxception safety violations (changes to
@@ -588,8 +660,14 @@
std::size_t res_off = 0;
std::size_t exp_off = Insert (val) == which ? tcase.off : 0;
- const charT* const arg_ptr = tcase.arg ? warg : s_str.c_str ();
- const TestString& arg_str = tcase.arg ? s_arg : s_str;
+ // 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 (tcase.off) < size1 ? std::size_t (tcase.off) : size1;
+
+ 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 total_length_calls = 0;
@@ -628,15 +706,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 Insert (size_ptr): {
- const TestString& s_res = s_str.insert (tcase.off, arg_ptr);
+ const String& s_res = s_str.insert (tcase.off, arg_ptr);
res_off = &s_res - &s_str;
if (rg_calls)
n_length_calls = rg_calls [UTMemFun::length];
@@ -644,40 +726,40 @@
}
case Insert (size_str): {
- const TestString& s_res = s_str.insert (tcase.off, arg_str);
+ const String& s_res = s_str.insert (tcase.off, arg_str);
res_off = &s_res - &s_str;
break;
}
case Insert (size_ptr_size): {
- const TestString& s_res =
+ const String& s_res =
s_str.insert (tcase.off, arg_ptr, tcase.size2);
res_off = &s_res - &s_str;
break;
}
case Insert (size_str_size_size): {
- const TestString& s_res =
+ const String& s_res =
s_str.insert (tcase.off, arg_str, tcase.off2, tcase.size2);
res_off = &s_res - &s_str;
break;
}
case Insert (size_size_val): {
- const TestString& s_res =
+ const String& s_res =
s_str.insert (tcase.off, tcase.size2, arg_val);
res_off = &s_res - &s_str;
break;
}
case Insert (size_val): {
- StringIter it (s_str.begin () + tcase.off);
+ StringIter it (s_str.begin () + off1);
s_str.insert (it, tcase.size2, arg_val);
break;
}
case Insert (val): {
- StringIter it (s_str.begin () + tcase.off);
+ StringIter it (s_str.begin () + off1);
StringIter res_it = s_str.insert (it, arg_val);
res_off = res_it - s_str.begin ();
break;
@@ -696,21 +778,21 @@
Insert (val) != which, 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 offset %zu",
__LINE__, int (tcase.nres), tcase.res,
@@ -802,6 +884,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.op.plus.equal.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.op.plus.equal.cpp?rev=406581&r1=406580&r2=406581&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.op.plus.equal.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.op.plus.equal.cpp Mon May 15 01:14:29 2006
@@ -33,14 +33,12 @@
#include <21.strings.h> // for StringMembers
#include <alg_test.h> // for InputIter
#include <driver.h> // for rw_test()
-#include <rw_char.h> // for rw_widen()
+#include <rw_char.h> // for rw_expand()
#include <rw_new.h> // for bad_alloc, replacement operator new
/**************************************************************************/
// for convenience and brevity
-#define LSTR StringMembers::long_string
-#define LLEN StringMembers::long_string_len
#define OpPlusEq(which) StringMembers::op_plus_eq_ ## which
typedef StringMembers::OverloadId OverloadId;
@@ -98,16 +96,18 @@
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@2048", "y@2048", "x@2048y@2048", 0),
TEST ("", 0, "", 0),
TEST ("abc", 0, "abcabc", 0),
TEST ("a\0\0bc", 0, "a\0\0bca", 0),
TEST ("\0\0abc", 0, "\0\0abc", 0),
TEST ("abc\0\0", 0, "abc\0\0abc", 0),
+ TEST ("x@2048", 0, "x@4096", 0),
- TEST ("", LSTR, LSTR, -1),
+ TEST ("", "x@4096", "x@4096", -1),
TEST ("last", "test", "lasttest", 0)
};
@@ -158,16 +158,18 @@
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@2048", "y@2048", "x@2048y@2048", 0),
TEST ("", 0, "", 0),
TEST ("abc", 0, "abcabc", 0),
TEST ("a\0\0bc", 0, "a\0\0bca\0\0bc", 0),
TEST ("\0\0abc", 0, "\0\0abc\0\0abc", 0),
TEST ("abc\0\0", 0, "abc\0\0abc\0\0", 0),
+ TEST ("x@2048", 0, "x@4096", 0),
- TEST ("", LSTR, LSTR, -1),
+ TEST ("", "x@4096", "x@4096", -1),
TEST ("last", "test", "lasttest", 0)
};
@@ -220,20 +222,38 @@
const TestCase &tcase)
{
typedef std::allocator<charT> Allocator;
- typedef std::basic_string <charT, Traits, Allocator> TestString;
- typedef typename TestString::iterator StringIter;
- typedef typename TestString::const_iterator ConstStringIter;
+ typedef std::basic_string <charT, Traits, Allocator> String;
+ typedef typename String::iterator StringIter;
+ typedef typename UserTraits<charT>::MemFun UTMemFun;
- typedef typename UserTraits<charT>::MemFun UTMemFun;
+ static const std::size_t BUFSIZE = 256;
- static charT wstr [LLEN];
- static charT warg [LLEN];
+ static charT wstr_buf [BUFSIZE];
+ static charT warg_buf [BUFSIZE];
- rw_widen (wstr, tcase.str, tcase.str_len);
- rw_widen (warg, tcase.arg, tcase.arg_len);
+ std::size_t str_len = sizeof wstr_buf / sizeof *wstr_buf;
+ std::size_t arg_len = sizeof warg_buf / sizeof *warg_buf;
- /* const */ TestString s_str (wstr, tcase.str_len);
- const TestString s_arg (warg, 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);
+
+ // 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;
// save the state of the string object before the call
// to detect wxception safety violations (changes to
@@ -242,8 +262,8 @@
std::size_t res_off = 0;
- 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;
const charT arg_val = make_char (char (tcase.val), (charT*)0);
std::size_t total_length_calls = 0;
@@ -276,15 +296,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 OpPlusEq (ptr): {
- const TestString& s_res = s_str += arg_ptr;
+ const String& s_res = s_str += arg_ptr;
res_off = &s_res - &s_str;
if (rg_calls)
n_length_calls = rg_calls [UTMemFun::length];
@@ -292,13 +316,13 @@
}
case OpPlusEq (str): {
- const TestString& s_res = s_str += arg_str;
+ const String& s_res = s_str += arg_str;
res_off = &s_res - &s_str;
break;
}
case OpPlusEq (val): {
- const TestString& s_res = s_str += arg_val;
+ const String& s_res = s_str += arg_val;
res_off = &s_res - &s_str;
break;
}
@@ -314,21 +338,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,
+ __LINE__, 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 offset %zu",
__LINE__, int (tcase.nres), tcase.res,
@@ -413,6 +437,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.replace.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp?rev=406581&r1=406580&r2=406581&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp Mon May 15 01:14:29 2006
@@ -261,7 +261,7 @@
static const TestCase
iter_iter_ptr_size_test_cases [] = {
-// iter_iter_range_test_cases serves a double duty
+// iter_iter_ptr_size_test_cases serves a double duty
#define size_size_ptr_size_test_cases iter_iter_ptr_size_test_cases
#undef TEST
@@ -486,7 +486,8 @@
TEST ("a@1", 0, 0, "b@0", 0, -1, "a", 0),
TEST ("a@1", 0, 0, "b@1", 0, -1, "ba", 0),
TEST ("a@2", 0, 0, "b@2", 0, -1, "bbaa", 0),
- TEST ("a@1000", 0, 0, "b@1000", 0, -1, "b@1000a@1000", 0),
+
+ TEST ("a@1000", 0, 0, "b@1000", 0, -1, "b@1000a@1000", 0),
TEST ("a@1000", 0, 1, "b@1001", 0, -1, "b@1001a@999", 0),
TEST ("a@1000", 0, 2, "b@1002", 0, -1, "b@1002a@998", 0),
TEST ("a@1000", 1, 998, "b@1003", 0, -1, "ab@1003a", 0),
@@ -664,6 +665,7 @@
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)
@@ -723,7 +725,7 @@
// 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 == 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,
@@ -738,6 +740,7 @@
std::size_t wstr_len,
const charT *warg,
std::size_t warg_len,
+ std::size_t res_len,
Traits*,
const TestCase &tcase)
{
@@ -748,7 +751,7 @@
// exercise InputIterator *or* string::iterator (i.e., self
// referential modification), depending on the value of tcase.arg
- test_replace_range (wstr, wstr_len, warg, warg_len, (Traits*)0,
+ test_replace_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0,
InputIter<charT>(0, 0, 0), tcase);
if (0 == tcase.arg) {
@@ -756,13 +759,13 @@
return;
}
- test_replace_range (wstr, wstr_len, warg, warg_len, (Traits*)0,
+ test_replace_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0,
ConstFwdIter<charT>(0, 0, 0), tcase);
- test_replace_range (wstr, wstr_len, warg, warg_len, (Traits*)0,
+ test_replace_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0,
ConstBidirIter<charT>(0, 0, 0), tcase);
- test_replace_range (wstr, wstr_len, warg, warg_len, (Traits*)0,
+ test_replace_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0,
ConstRandomAccessIter<charT>(0, 0, 0), tcase);
}
@@ -789,9 +792,14 @@
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 replace_range to exercise all iterators
if (Replace (iter_iter_range) == which) {
- test_replace_range (wstr, str_len, warg, arg_len, (Traits*)0, tcase);
+ test_replace_range (wstr, str_len, warg, arg_len,
+ res_len, (Traits*)0, tcase);
if (wstr != wstr_buf)
delete[] wstr;
@@ -799,6 +807,9 @@
if (warg != warg_buf)
delete[] warg;
+ if (wres != wres_buf)
+ delete[] wres;
+
return;
}
@@ -816,10 +827,6 @@
wstr = 0;
warg = 0;
- 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);
-
// 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)
@@ -898,6 +905,7 @@
delete[] wres;
return;
+ }
#endif // _RWSTD_NO_EXCEPTIONS
@@ -976,7 +984,7 @@
// (and only then), also verify that the modified
// string matches the expected result
const std::size_t match =
- rw_match (tcase.res, str.c_str (), res_len);
+ rw_match (tcase.res, str.c_str (), tcase.nres);
rw_assert (match == res_len, 0, tcase.line,
"line %d. %{$FUNCALL} expected %{/*.*Gs}, "
Modified: incubator/stdcxx/trunk/tests/strings/21.string.rfind.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.rfind.cpp?rev=406581&r1=406580&r2=406581&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.rfind.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.rfind.cpp Mon May 15 01:14:29 2006
@@ -31,22 +31,19 @@
#include <21.strings.h> // for StringMembers
#include <driver.h> // for rw_test()
-#include <rw_char.h> // for rw_widen()
+#include <rw_char.h> // for rw_expand()
-#define RFind(which) StringMembers::rfind_ ## which
+/**************************************************************************/
+
+// for convenience and brevity
+#define NPOS _RWSTD_SIZE_MAX
+#define RFind(which) StringMembers::rfind_ ## which
typedef StringMembers::OverloadId OverloadId;
typedef StringMembers::TestCase TestCase;
typedef StringMembers::Test Test;
typedef StringMembers::Function MemFun;
-/**************************************************************************/
-
-// for convenience and brevity
-#define NPOS _RWSTD_SIZE_MAX
-#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"
@@ -56,12 +53,15 @@
// used to exercise
// rfind (const value_type*)
-static const TestCase ptr_test_cases [] = {
+static const TestCase
+ptr_test_cases [] = {
#undef TEST
-#define TEST(str, arg, res) \
- { __LINE__, -1, -1, -1, -1, -1, str, sizeof str - 1, arg, \
- sizeof arg - 1, 0, res, 0 }
+#define TEST(str, arg, res) \
+ { __LINE__, -1, -1, -1, -1, -1, \
+ str, sizeof str - 1, arg, \
+ sizeof arg - 1, 0, res, 0 \
+ }
// +----------------------------------- controlled sequence
// | +--------------------- sequence to be found
@@ -109,17 +109,17 @@
TEST ("aaaaaaaaaa", "aaaaaaaaa", 1),
TEST ("aaaaaaaaa", "aaaaaaaaaa", NPOS),
- TEST (LSTR, "", LLEN - 1),
- TEST (LSTR, "a", NPOS),
- TEST (LSTR, "x", LLEN - 2),
- TEST (LSTR, "xxx", LLEN - 4),
- TEST (LSTR, "xxa", NPOS),
- TEST ("abc", LSTR, NPOS),
- TEST ("xxxxxxxxxx", LSTR, NPOS),
+ TEST ("x@4096", "", 4096),
+ TEST ("x@4096", "a", NPOS),
+ TEST ("x@4096", "x", 4095),
+ TEST ("x@4096", "xxx", 4093),
+ TEST ("x@4096", "xxa", NPOS),
+ TEST ("abc", "x@4096", NPOS),
+ TEST ("xxxxxxxxxx", "x@4096", NPOS),
TEST ("abcdefghij", 0, 0),
TEST ("\0cb\0\0ge", 0, 7),
- TEST (LSTR, 0, 0),
+ TEST ("x@4096", 0, 0),
TEST ("last test", "test", 5)
};
@@ -128,12 +128,15 @@
// used to exercise
// rfind (const basic_string&)
-static const TestCase str_test_cases [] = {
+static const TestCase
+str_test_cases [] = {
#undef TEST
-#define TEST(str, arg, res) \
- { __LINE__, -1, -1, -1, -1, -1, str, sizeof str - 1, arg, \
- sizeof arg - 1, 0, res, 0 }
+#define TEST(str, arg, res) \
+ { __LINE__, -1, -1, -1, -1, -1, \
+ str, sizeof str - 1, arg, \
+ sizeof arg - 1, 0, res, 0 \
+ }
// +------------------------------------ controlled sequence
// | +---------------------- sequence to be found
@@ -186,17 +189,17 @@
TEST ("aaaaaaaaaa", "aaaaaaaaa", 1),
TEST ("aaaaaaaaa", "aaaaaaaaaa", NPOS),
- TEST (LSTR, "", LLEN - 1),
- TEST (LSTR, "a", NPOS),
- TEST (LSTR, "x", LLEN - 2),
- TEST (LSTR, "xxx", LLEN - 4),
- TEST (LSTR, "xxa", NPOS),
- TEST ("abc", LSTR, NPOS),
- TEST ("xxxxxxxxxx", LSTR, NPOS),
+ TEST ("x@4096", "", 4096),
+ TEST ("x@4096", "a", NPOS),
+ TEST ("x@4096", "x", 4095),
+ TEST ("x@4096", "xxx", 4093),
+ 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)
};
@@ -205,12 +208,15 @@
// used to exercise
// rfind (const value_type*, size_type)
-static const TestCase ptr_size_test_cases [] = {
+static const TestCase
+ptr_size_test_cases [] = {
#undef TEST
-#define TEST(str, arg, off, res) \
- { __LINE__, off, -1, -1, -1, -1, str, sizeof str - 1, arg, \
- sizeof arg - 1, 0, res, 0 }
+#define TEST(str, arg, off, res) \
+ { __LINE__, off, -1, -1, -1, -1, \
+ str, sizeof str - 1, arg, \
+ sizeof arg - 1, 0, res, 0 \
+ }
// +-------------------------------------- controlled sequence
// | +------------------------- sequence to be found
@@ -272,24 +278,24 @@
TEST ("aaaaaaaaaa", "aaaaaaaaa", 7, 1),
TEST ("aaaaaaaaa", "aaaaaaaaaa", 8, NPOS),
- TEST (LSTR, "", LLEN - 1, LLEN - 1),
- TEST (LSTR, "a", 0, NPOS),
- TEST (LSTR, "x", LLEN - 1, LLEN - 2),
- TEST (LSTR, "xxx", LLEN - 2, LLEN - 4),
- TEST (LSTR, "xxx", 0, 0),
- TEST (LSTR, "xxx", LLEN - 10, LLEN - 10),
- TEST (LSTR, "xxa", LLEN - 10, NPOS),
- TEST ("abc", LSTR, 2, NPOS),
- TEST ("xxxxxxxxxx", LSTR, 6, NPOS),
+ TEST ("x@4096", "", 4096, 4096),
+ TEST ("x@4096", "a", 0, NPOS),
+ TEST ("x@4096", "x", 4096, 4095),
+ TEST ("x@4096", "xxx", 4095, 4093),
+ TEST ("x@4096", "xxx", 0, 0),
+ TEST ("x@4096", "xxx", 4087, 4087),
+ TEST ("x@4096", "xxa", 4087, NPOS),
+ TEST ("abc", "x@4096", 2, NPOS),
+ TEST ("xxxxxxxxxx", "x@4096", 6, NPOS),
- TEST (LSTR, "xxx", 3, 3),
- TEST (LSTR, "xxx", 2, 2),
+ TEST ("x@4096", "xxx", 3, 3),
+ TEST ("x@4096", "xxx", 2, 2),
TEST ("abcdefghij", 0, 0, 0),
TEST ("abcdefghij", 0, 1, 0),
TEST ("\0cb\0\0ge", 0, 5, 5),
- TEST (LSTR, 0, 0, 0),
- TEST (LSTR, 0, 1, 0),
+ TEST ("x@4096", 0, 0, 0),
+ TEST ("x@4096", 0, 1, 0),
TEST ("", "", 1, 0),
TEST ("abcdefghij", "abc", 10, 0),
@@ -302,12 +308,15 @@
// used to exercise
// rfind (const value_type*, size_type, size_type)
-static const TestCase ptr_size_size_test_cases [] = {
+static const TestCase
+ptr_size_size_test_cases [] = {
#undef TEST
-#define TEST(str, arg, off, size, res, bthrow) \
- { __LINE__, off, size, -1, -1, -1, str, sizeof str - 1, arg, \
- sizeof arg - 1, 0, res, bthrow }
+#define TEST(str, arg, off, size, res, bthrow) \
+ { __LINE__, off, size, -1, -1, -1, \
+ str, sizeof str - 1, arg, \
+ sizeof arg - 1, 0, res, bthrow \
+ }
// +--------------------------------------- controlled sequence
// | +-------------------------- sequence to be found
@@ -382,40 +391,36 @@
TEST ("aaaaaaaaa", "aaaaaaaaaa", 9, 10, NPOS, 0),
TEST ("aaaaaaaaa", "aaaaaaaaaa", 8, 7, 2, 0),
- TEST (LSTR, "", LLEN - 1, 0, LLEN - 1, 0),
- TEST (LSTR, "a", LLEN - 1, 1, NPOS, 0),
- TEST (LSTR, "x", LLEN - 1, 1, LLEN - 2, 0),
- TEST (LSTR, "xxx", LLEN - 10, 3, LLEN - 10, 0),
- TEST (LSTR, "xxa", LLEN - 10, 3, NPOS, 0),
- TEST (LSTR, "xxa", LLEN - 1, 2, LLEN - 3, 0),
- TEST ("abc", LSTR, 2, 10, NPOS, 0),
- TEST ("xxxxxxxxxx", LSTR, 0, LLEN - 1, NPOS, 0),
- TEST ("xxxxxxxxxx", LSTR, 2, 4, 2, 0),
-
- TEST (LSTR, "xxx", LLEN - 4, 3, LLEN - 4, 0),
- TEST (LSTR, "xxx", LLEN - 3, 3, LLEN - 4, 0),
- TEST (LSTR, "xxx", LLEN - 3, 2, LLEN - 3, 0),
+ TEST ("x@4096", "", 4096, 0, 4096, 0),
+ TEST ("x@4096", "a", 4096, 1, NPOS, 0),
+ TEST ("x@4096", "x", 4096, 1, 4095, 0),
+ TEST ("x@4096", "xxx", 4087, 3, 4087, 0),
+ TEST ("x@4096", "xxa", 4087, 3, NPOS, 0),
+ TEST ("x@4096", "xxa", 4096, 2, 4094, 0),
+ TEST ("abc", "x@4096", 2, 10, NPOS, 0),
+ TEST ("xxxxxxxxxx", "x@4096", 0, 4096, NPOS, 0),
+ TEST ("xxxxxxxxxx", "x@4096", 2, 4, 2, 0),
+
+ TEST ("x@4096", "xxx", 4093, 3, 4093, 0),
+ TEST ("x@4096", "xxx", 4094, 3, 4093, 0),
+ TEST ("x@4096", "xxx", 4094, 2, 4094, 0),
TEST ("abcdefghij", 0, 0, 9, 0, 0),
TEST ("abcdefghij", 0, 1, 9, 0, 0),
TEST ("\0cb\0\0ge", 0, 5, 7, 0, 0),
TEST ("\0cb\0ge\0", 0, 6, 1, 6, 0),
- TEST (LSTR, 0, 0, LLEN - 1, 0, 0),
- TEST (LSTR, 0, 1, LLEN - 1, 0, 0),
- TEST (LSTR, 0, 5, LLEN - 6, 5, 0),
+ TEST ("x@4096", 0, 0, 4096, 0, 0),
+ TEST ("x@4096", 0, 1, 4096, 0, 0),
+ TEST ("x@4096", 0, 5, 4091, 5, 0),
TEST ("", "", 1, 0, 0, 0),
TEST ("abcdefghij", "abc", 10, 3, 0, 0),
TEST ("abcdefghij", "cba", 10, 1, 2, 0),
-#ifndef _RWSTD_NO_EXCEPTIONS
-
TEST ("", "cba", 0, -1, 0, 1),
TEST ("abcdefghij", "cba", 0, -1, 0, 1),
- TEST (LSTR, "xxx", 0, -1, 0, 1),
- TEST ("abcdefghij", LSTR, 0, -1, 0, 1),
-
-#endif // _RWSTD_NO_EXCEPTIONS
+ TEST ("x@4096", "xxx", 0, -1, 0, 1),
+ TEST ("abcdefghij", "x@4096", 0, -1, 0, 1),
TEST ("last test", "test", 9, 4, 5, 0)
};
@@ -424,12 +429,15 @@
// used to exercise
// rfind (const basic_string&, size_type)
-static const TestCase str_size_test_cases [] = {
+static const TestCase
+str_size_test_cases [] = {
#undef TEST
-#define TEST(str, arg, off, res) \
- { __LINE__, off, -1, -1, -1, -1, str, sizeof str - 1, arg, \
- sizeof arg - 1, 0, res, 0 }
+#define TEST(str, arg, off, res) \
+ { __LINE__, off, -1, -1, -1, -1, \
+ str, sizeof str - 1, arg, \
+ sizeof arg - 1, 0, res, 0 \
+ }
// +--------------------------------------- controlled sequence
// | +------------------------- sequence to be found
@@ -488,22 +496,22 @@
TEST ("aaaaaaaaaa", "aaaaaaaaa", 0, 0),
TEST ("aaaaaaaaa", "aaaaaaaaaa", 8, NPOS),
- TEST (LSTR, "", LLEN - 1, LLEN - 1),
- TEST (LSTR, "a", LLEN - 1, NPOS),
- TEST (LSTR, "x", LLEN - 1, LLEN - 2),
- TEST (LSTR, "xxx", LLEN - 10, LLEN - 10),
- TEST (LSTR, "xxa", LLEN - 10, NPOS),
- TEST ("abc", LSTR, 2, NPOS),
- TEST ("xxxxxxxxxx", LSTR, LLEN - 1, NPOS),
+ TEST ("x@4096", "", 4096, 4096),
+ TEST ("x@4096", "a", 4096, NPOS),
+ TEST ("x@4096", "x", 4096, 4095),
+ TEST ("x@4096", "xxx", 4087, 4087),
+ TEST ("x@4096", "xxa", 4087, NPOS),
+ TEST ("abc", "x@4096", 2, NPOS),
+ TEST ("xxxxxxxxxx", "x@4096", 4096, NPOS),
- TEST (LSTR, "xxx", LLEN - 1, LLEN - 4),
- TEST (LSTR, "xxx", LLEN - 6, LLEN - 6),
+ TEST ("x@4096", "xxx", 4096, 4093),
+ TEST ("x@4096", "xxx", 4091, 4091),
TEST ("abcdefghij", 0, 9, 0),
TEST ("abcdefghij", 0, 1, 0),
TEST ("\0cb\0\0ge", 0, 5, 0),
- TEST (LSTR, 0, 0, 0),
- TEST (LSTR, 0, 1, 0),
+ TEST ("x@4096", 0, 0, 0),
+ TEST ("x@4096", 0, 1, 0),
TEST ("", "", 1, 0),
TEST ("abcdefghij", "abc", 10, 0),
@@ -516,12 +524,15 @@
// used to exercise
// rfind (value_type)
-static const TestCase val_test_cases [] = {
+static const TestCase
+val_test_cases [] = {
#undef TEST
-#define TEST(str, val, res) \
- { __LINE__, -1, -1, -1, -1, val, str, sizeof str - 1, \
- 0, 0, 0, res, 0 }
+#define TEST(str, val, res) \
+ { __LINE__, -1, -1, -1, -1, val, \
+ str, sizeof str - 1, \
+ 0, 0, 0, res, 0 \
+ }
// +----------------------------- controlled sequence
// | +-------------- character to be found
@@ -545,9 +556,9 @@
TEST ("\0cbge\0\0", 'b', 2),
TEST ("\0cbge\0\0", 'a', NPOS),
- TEST (LSTR, 'x', LLEN - 2),
- TEST (LSTR, '\0', NPOS),
- TEST (LSTR, 'a', NPOS),
+ TEST ("x@4096", 'x', 4095),
+ TEST ("x@4096", '\0', NPOS),
+ TEST ("x@4096", 'a', NPOS),
TEST ("last test", 't', 8)
};
@@ -556,12 +567,15 @@
// used to exercise
// rfind (value_type, size_type)
-static const TestCase val_size_test_cases [] = {
+static const TestCase
+val_size_test_cases [] = {
#undef TEST
-#define TEST(str, val, off, res) \
- { __LINE__, off, -1, -1, -1, val, str, sizeof str - 1, \
- 0, 0, 0, res, 0 }
+#define TEST(str, val, off, res) \
+ { __LINE__, off, -1, -1, -1, val, \
+ str, sizeof str - 1, \
+ 0, 0, 0, res, 0 \
+ }
// +------------------------------ controlled sequence
// | +--------------- character to be found
@@ -594,13 +608,13 @@
TEST ("\0bgeb\0\0", 'b', 5, 4),
TEST ("\0cbge\0\0", 'a', 6, NPOS),
- TEST (LSTR, 'x', 0, 0),
- TEST (LSTR, 'x', 5, 5),
- TEST (LSTR, 'x', LLEN - 1, LLEN - 2),
- TEST (LSTR, '\0', LLEN - 1, NPOS),
- TEST (LSTR, 'a', LLEN - 3, NPOS),
- TEST (LSTR, 'x', LLEN - 2, LLEN - 2),
- TEST (LSTR, 'x', LLEN + 9, LLEN - 2),
+ TEST ("x@4096", 'x', 0, 0),
+ TEST ("x@4096", 'x', 5, 5),
+ TEST ("x@4096", 'x', 4096, 4095),
+ TEST ("x@4096", '\0', 4096, NPOS),
+ TEST ("x@4096", 'a', 4094, NPOS),
+ TEST ("x@4096", 'x', 4095, 4095),
+ TEST ("x@4096", 'x', 4106, 4095),
TEST ("last test", 't', 9, 8)
};
@@ -613,27 +627,42 @@
const TestCase &cs)
{
typedef std::allocator<charT> Allocator;
- typedef std::basic_string <charT, Traits, Allocator> TestString;
- typedef typename TestString::const_iterator ConstStringIter;
+ typedef std::basic_string <charT, Traits, Allocator> String;
- static charT wstr [LLEN];
- static charT warg [LLEN];
+ static const std::size_t BUFSIZE = 256;
- rw_widen (wstr, cs.str, cs.str_len);
- rw_widen (warg, cs.arg, cs.arg_len);
+ static charT wstr_buf [BUFSIZE];
+ static charT warg_buf [BUFSIZE];
- const TestString s_str (wstr, cs.str_len);
- const TestString s_arg (warg, cs.arg_len);
+ std::size_t str_len = sizeof wstr_buf / sizeof *wstr_buf;
+ std::size_t arg_len = sizeof warg_buf / sizeof *warg_buf;
- std::size_t res = 0;
- std::size_t exp_res = NPOS != cs.nres ? cs.nres : TestString::npos;
+ charT* wstr = rw_expand (wstr_buf, cs.str, cs.str_len, &str_len);
+ charT* warg = rw_expand (warg_buf, cs.arg, cs.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);
+
+ if (wstr != wstr_buf)
+ delete[] wstr;
+
+ if (warg != warg_buf)
+ delete[] warg;
+
+ wstr = 0;
+ warg = 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 std::size_t ssize = s_str.size ();
- const std::size_t capacity = s_str.capacity ();
- const ConstStringIter begin = s_str.begin ();
+ std::size_t res = 0;
+ std::size_t exp_res = NPOS != cs.nres ? cs.nres : String::npos;
- const charT* const ptr_arg = cs.arg ? warg : s_str.c_str ();
- const TestString& str_arg = cs.arg ? s_arg : s_str;
+ const charT* const arg_ptr = cs.arg ? s_arg.c_str () : s_str.c_str ();
+ const String& arg_str = cs.arg ? s_arg : s_str;
const charT arg_val = make_char (char (cs.val), (charT*)0);
std::size_t size = cs.size >= 0 ? cs.size : s_arg.max_size () + 1;
@@ -657,27 +686,27 @@
try {
switch (which) {
case RFind (ptr): {
- res = s_str.rfind (ptr_arg);
+ res = s_str.rfind (arg_ptr);
break;
}
case RFind (str): {
- res = s_str.rfind (str_arg);
+ res = s_str.rfind (arg_str);
break;
}
case RFind (ptr_size): {
- res = s_str.rfind (ptr_arg, cs.off);
+ res = s_str.rfind (arg_ptr, cs.off);
break;
}
case RFind (ptr_size_size): {
- res = s_str.rfind (ptr_arg, cs.off, size);
+ res = s_str.rfind (arg_ptr, cs.off, size);
break;
}
case RFind (str_size): {
- res = s_str.rfind (str_arg, cs.off);
+ res = s_str.rfind (arg_str, cs.off);
break;
}
@@ -701,7 +730,7 @@
"line %d. %{$FUNCALL} == %{?}%zu%{;}%{?}npos%{;}, "
"got %{?}%zu%{;}%{?}npos%{;}",
__LINE__, NPOS != cs.nres, exp_res, NPOS == cs.nres,
- TestString::npos != res, res, TestString::npos == res);
+ String::npos != res, res, String::npos == res);
}
#ifndef _RWSTD_NO_EXCEPTIONS
@@ -728,24 +757,13 @@
__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 () == ssize, 0, cs.line,
- "line %d: %{$FUNCALL}: size unexpectedly changed "
- "from %zu to %zu after an exception",
- __LINE__, ssize, 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 () == begin, 0, cs.line,
- "line %d: %{$FUNCALL}: begin() unexpectedly "
- "changed from after an exception by %d",
- __LINE__, s_str.begin () - begin);
+ 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 (-1 != cs.bthrow) {
rw_assert (caught == expected, 0, cs.line,
@@ -753,13 +771,6 @@
"%{:}unexpectedly caught %s%{;}",
__LINE__, 0 != expected, expected, caught, caught);
}
-
-#else // if defined (_RWSTD_NO_EXCEPTIONS)
-
- _RWSTD_UNUSED (ssize);
- _RWSTD_UNUSED (capacity);
-
-#endif // _RWSTD_NO_EXCEPTIONS
}
/**************************************************************************/
Modified: incubator/stdcxx/trunk/tests/strings/21.string.substr.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.substr.cpp?rev=406581&r1=406580&r2=406581&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.substr.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.substr.cpp Mon May 15 01:14:29 2006
@@ -31,13 +31,11 @@
#include <21.strings.h> // for StringMembers
#include <driver.h> // for rw_test()
-#include <rw_char.h> // for rw_widen()
+#include <rw_char.h> // for rw_expand()
/**************************************************************************/
// for convenience and brevity
-#define LSTR StringMembers::long_string
-#define LLEN StringMembers::long_string_len
#define Substr(which) StringMembers::substr_ ## which
typedef StringMembers::OverloadId OverloadId;
@@ -77,7 +75,7 @@
TEST ("\0\0abcd\0", "\0\0abcd\0"),
TEST ("\0\0ab\0\0", "\0\0ab\0\0"),
- TEST (LSTR, LSTR),
+ TEST ("x@4096", "x@4096"),
TEST ("last", "last")
};
@@ -124,14 +122,16 @@
TEST ("\0\0ab\0\0", 4, "\0\0", 0),
TEST ("\0\0ab\0\0", 6, "", 0),
- TEST (LSTR, 0, LSTR, 0),
- TEST (LSTR, LLEN - 3, "xx", 0),
- TEST (LSTR, LLEN - 9, "xxxxxxxx", 0),
- TEST (LSTR, LLEN - 1, "", 0),
+ TEST ("x@4096", 0, "x@4096", 0),
+ TEST ("x@4096", 4094, "xx", 0),
+ TEST ("x@4096", 4088, "xxxxxxxx", 0),
+ TEST ("x@4096", 4096, "", 0),
+ TEST ("abx@4096", 2, "x@4096", 0),
+ TEST ("x@4096ab", 2048, "x@2048ab", 0),
TEST ("\0", 2, "", 1),
TEST ("a", 10, "", 1),
- TEST (LSTR, LLEN + 10, "", 1),
+ TEST ("x@4096", 4106, "", 1),
TEST ("last", 0, "last", 0)
};
@@ -192,16 +192,17 @@
TEST ("\0\0ab\0\0", 2, 3, "ab\0", 0),
TEST ("\0\0ab\0\0", 6, 6, "", 0),
- TEST (LSTR, 0, LLEN - 1, LSTR, 0),
- TEST (LSTR, LLEN - 2, LLEN - 1, "x", 0),
- TEST (LSTR, LLEN - 9, 2, "xx", 0),
- TEST (LSTR, LLEN - 4, 5, "xxx", 0),
- TEST (LSTR, LLEN - 9, 8, "xxxxxxxx", 0),
- TEST (LSTR, LLEN - 1, 1, "", 0),
+ TEST ("x@4096", 0, 4096, "x@4096", 0),
+ TEST ("x@4096", 4095, 4096, "x", 0),
+ TEST ("x@4096", 4088, 2, "xx", 0),
+ TEST ("x@4096", 4093, 5, "xxx", 0),
+ TEST ("x@4096", 4088, 8, "xxxxxxxx", 0),
+ TEST ("x@4096", 4096, 1, "", 0),
+ TEST ("ax@4096b", 1, 4094, "x@4094", 0),
TEST ("\0", 2, 0, "", 1),
TEST ("a", 10, 0, "", 1),
- TEST (LSTR, LLEN + 10, 0, "", 1),
+ TEST ("x@4096", 4106, 0, "", 1),
TEST ("last", 0, 4, "last", 0)
};
@@ -214,16 +215,28 @@
const TestCase &cs)
{
typedef std::allocator<charT> Allocator;
- typedef std::basic_string <charT, Traits, Allocator> TestString;
- typedef typename TestString::const_iterator ConstStringIter;
+ typedef std::basic_string <charT, Traits, Allocator> String;
- static charT wstr [LLEN];
+ static const std::size_t BUFSIZE = 256;
- // construct string
- rw_widen (wstr, cs.str, cs.str_len);
- const TestString str (wstr, 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);
- TestString s_res;
+ 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);
+
+ // construct the string object
+ const String str (wstr, str_len);
+
+ if (wstr != wstr_buf)
+ delete[] wstr;
+
+ wstr = 0;
+
+
+ String s_res;
// save the state of the string object before the call
// to detect wxception safety violations (changes to
@@ -236,6 +249,15 @@
const char* const expected = cs.bthrow ? exceptions [1] : 0;
const char* caught = 0;
+#else
+
+ if (cs.bthrow) {
+ if (wres != wres_buf)
+ delete[] wres;
+
+ return;
+ }
+
#endif // _RWSTD_NO_EXCEPTIONS
try {
@@ -258,21 +280,21 @@
}
// verfiy that strings length are equal
- rw_assert (cs.nres == s_res.size (), 0, cs.line,
+ rw_assert (res_len == s_res.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_res.size ()), s_res.c_str (), s_res.size ());
- if (cs.nres == s_res.size ()) {
+ if (res_len == s_res.size ()) {
// if the result length matches the expected length
// (and only then), also verify that the resulted
// string matches the expected result
const std::size_t match =
rw_match (cs.res, s_res.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,
@@ -313,6 +335,9 @@
}
#endif // _RWSTD_NO_EXCEPTIONS
+
+ if (wres != wres_buf)
+ delete[] wres;
}
/**************************************************************************/