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 [2/3] - /incubator/stdcxx/trunk/tests/strings/
Modified: incubator/stdcxx/trunk/tests/strings/21.string.find.first.not.of.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.find.first.not.of.cpp?rev=406581&r1=406580&r2=406581&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.find.first.not.of.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.find.first.not.of.cpp Mon May 15 01:14:29 2006
@@ -32,22 +32,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 FindFirstNotOf(which) StringMembers::find_first_not_of_ ## which
+/**************************************************************************/
+
+// for convenience and brevity
+#define NPOS _RWSTD_SIZE_MAX
+#define FindFirstNotOf(which) StringMembers::find_first_not_of_ ## 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"
@@ -57,12 +54,15 @@
// used to exercise
// find_first_not_of (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
@@ -107,16 +107,16 @@
TEST ("bbb", "aaaaaaaaba", NPOS),
TEST ("aab", "aaaaaaaaaa", 2),
- TEST (LSTR, "", 0),
- TEST (LSTR, "a", 0),
- TEST (LSTR, "x", NPOS),
- TEST (LSTR, "axa", NPOS),
- TEST ("abc", LSTR, 0),
- TEST ("xabc", LSTR, 1),
+ TEST ("x@4096", "", 0),
+ TEST ("x@4096", "a", 0),
+ TEST ("x@4096", "x", NPOS),
+ TEST ("x@4096", "axa", NPOS),
+ TEST ("abc", "x@4096", 0),
+ TEST ("xabc", "x@4096", 1),
TEST ("abcdefghij", 0, NPOS),
TEST ("\0cb\0\0ge", 0, 0),
- TEST (LSTR, 0, NPOS),
+ TEST ("x@4096", 0, NPOS),
TEST ("last test", "test", 0)
};
@@ -125,12 +125,15 @@
// used to exercise
// find_first_not_of (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
@@ -178,16 +181,16 @@
TEST ("bbb", "aaaaaaaaba", NPOS),
TEST ("aab", "aaaaaaaaaa", 2),
- TEST (LSTR, "", 0),
- TEST (LSTR, "a", 0),
- TEST (LSTR, "x", NPOS),
- TEST (LSTR, "axa", NPOS),
- TEST ("abc", LSTR, 0),
- TEST ("xabc", LSTR, 1),
+ TEST ("x@4096", "", 0),
+ TEST ("x@4096", "a", 0),
+ TEST ("x@4096", "x", NPOS),
+ TEST ("x@4096", "axa", NPOS),
+ TEST ("abc", "x@4096", 0),
+ TEST ("xabc", "x@4096", 1),
TEST ("abcdefghij", 0, NPOS),
TEST ("\0cb\0\0ge", 0, NPOS),
- TEST (LSTR, 0, NPOS),
+ TEST ("x@4096", 0, NPOS),
TEST ("last test", "test", 0)
};
@@ -196,12 +199,15 @@
// used to exercise
// find_first_not_of (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
@@ -255,22 +261,23 @@
TEST ("bac", "aaaaaaaaba", 0, 2),
TEST ("baa", "aaaaaaaaaa", 0, 0),
- TEST (LSTR, "", 0, 0),
- TEST (LSTR, "a", 0, 0),
- TEST (LSTR, "x", 0, NPOS),
- TEST (LSTR, "xxx", 10, NPOS),
- TEST (LSTR, "axa", 10, NPOS),
- TEST ("abc", LSTR, 2, 2),
- TEST ("xxxxxxxxxx", LSTR, 0, NPOS),
-
- TEST (LSTR, "xxx", LLEN - 4, NPOS),
- TEST (LSTR, "xxx", LLEN - 1, NPOS),
+ TEST ("x@4096", "", 0, 0),
+ TEST ("x@4096", "a", 0, 0),
+ TEST ("x@4096", "x", 0, NPOS),
+ TEST ("x@4096", "xxx", 10, NPOS),
+ TEST ("x@4096", "axa", 10, NPOS),
+ TEST ("abc", "x@4096", 2, 2),
+ TEST ("xxxxxxxxxx", "x@4096", 0, NPOS),
+
+ TEST ("x@4096", "xxx", 4094, NPOS),
+ TEST ("x@4096", "xxx", 4095, NPOS),
+ TEST ("x@2048axxx", "x", 1, 2048),
TEST ("abcdefghij", 0, 0, NPOS),
TEST ("abcdefghij", 0, 1, NPOS),
TEST ("\0cb\0\0ge", 0, 5, 5),
- TEST (LSTR, 0, 0, NPOS),
- TEST (LSTR, 0, 7, NPOS),
+ TEST ("x@4096", 0, 0, NPOS),
+ TEST ("x@4096", 0, 7, NPOS),
TEST ("", "", 1, NPOS),
TEST ("abcdefghij", "abc", 10, NPOS),
@@ -283,12 +290,15 @@
// used to exercise
// find_first_not_of (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
@@ -362,20 +372,20 @@
TEST ("bab", "baaaaaaaaa", 0, 0, 0, 0),
TEST ("bab", "ccccccccba", 1, 10, NPOS, 0),
- TEST (LSTR, "", 0, 0, 0, 0),
- TEST (LSTR, "a", 0, 1, 0, 0),
- TEST (LSTR, "x", 0, 1, NPOS, 0),
- TEST (LSTR, "xxx", 10, 3, NPOS, 0),
- TEST (LSTR, "axx", 10, 1, 10, 0),
- TEST (LSTR, "xxa", 10, 0, 10, 0),
- TEST (LSTR, "xxa", 10, 1, NPOS, 0),
- TEST ("abc", LSTR, 2, 10, 2, 0),
- TEST ("xxxxxxxxxx", LSTR, 0, LLEN - 1, NPOS, 0),
- TEST ("xxxxxxxxxx", LSTR, 2, 4, NPOS, 0),
- TEST ("xxxxxxxxxa", LSTR, 0, 4, 9, 0),
+ TEST ("x@4096", "", 0, 0, 0, 0),
+ TEST ("x@4096", "a", 0, 1, 0, 0),
+ TEST ("x@4096", "x", 0, 1, NPOS, 0),
+ TEST ("x@4096", "xxx", 10, 3, NPOS, 0),
+ TEST ("x@4096", "axx", 10, 1, 10, 0),
+ TEST ("x@4096", "xxa", 10, 0, 10, 0),
+ TEST ("x@4096", "xxa", 10, 1, NPOS, 0),
+ TEST ("abc", "x@4096", 2, 10, 2, 0),
+ TEST ("xxxxxxxxxx", "x@4096", 0, 4096, NPOS, 0),
+ TEST ("xxxxxxxxxx", "x@4096", 2, 4, NPOS, 0),
+ TEST ("xxxxxxxxxa", "x@4096", 0, 4, 9, 0),
- TEST (LSTR, "xxx", LLEN - 4, 3, NPOS, 0),
- TEST (LSTR, "xxx", LLEN - 3, 0, LLEN - 3, 0),
+ TEST ("x@4096", "xxx", 4094, 3, NPOS, 0),
+ TEST ("x@4096", "xxx", 4093, 0, 4093, 0),
TEST ("abcdefghij", 0, 0, 10, NPOS, 0),
TEST ("abcdefghij", 0, 1, 9, 9, 0),
@@ -384,9 +394,9 @@
TEST ("\0cb\0\0ge", 0, 5, 5, 5, 0),
TEST ("\0cb\0\0cb", 0, 3, 5, NPOS, 0),
TEST ("\0cb\0ge\0", 0, 6, 1, NPOS, 0),
- TEST (LSTR, 0, 0, LLEN - 1, NPOS, 0),
- TEST (LSTR, 0, LLEN - 1, LLEN - 1, NPOS, 0),
- TEST (LSTR, 0, LLEN - 2, 1, NPOS, 0),
+ TEST ("x@4096", 0, 0, 4096, NPOS, 0),
+ TEST ("x@4096", 0, 4096, 4096, NPOS, 0),
+ TEST ("x@4096", 0, 4095, 1, NPOS, 0),
TEST ("", "", 1, 0, NPOS, 0),
TEST ("abcdefghij", "abc", 10, 3, NPOS, 0),
@@ -396,8 +406,8 @@
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),
+ TEST ("x@4096", "xxx", 0, -1, 0, 1),
+ TEST ("abcdefghij", "x@4096", 0, -1, 0, 1),
#endif // _RWSTD_NO_EXCEPTIONS
@@ -408,12 +418,15 @@
// used to exercise
// find_first_not_of (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
@@ -470,22 +483,23 @@
TEST ("bac", "aaaaaaaaba", 0, 2),
TEST ("baa", "aaaaaaaaaa", 0, 0),
- TEST (LSTR, "", 0, 0),
- TEST (LSTR, "a", 0, 0),
- TEST (LSTR, "x", 0, NPOS),
- TEST (LSTR, "xxx", 10, NPOS),
- TEST (LSTR, "axa", 10, NPOS),
- TEST ("abc", LSTR, 2, 2),
- TEST ("xxxxxxxxxx", LSTR, 0, NPOS),
-
- TEST (LSTR, "xxx", LLEN - 4, NPOS),
- TEST (LSTR, "xxx", LLEN - 1, NPOS),
+ TEST ("x@4096", "", 0, 0),
+ TEST ("x@4096", "a", 0, 0),
+ TEST ("x@4096", "x", 0, NPOS),
+ TEST ("x@4096", "xxx", 10, NPOS),
+ TEST ("x@4096", "axa", 10, NPOS),
+ TEST ("abc", "x@4096", 2, 2),
+ TEST ("xxxxxxxxxx", "x@4096", 0, NPOS),
+
+ TEST ("x@4096", "xxx", 4094, NPOS),
+ TEST ("x@4096", "xxx", 4096, NPOS),
+ TEST ("x@2048axxx", "xxx", 10, 2048),
TEST ("abcdefghij", 0, 0, NPOS),
TEST ("abcdefghij", 0, 1, NPOS),
TEST ("\0cb\0\0ge", 0, 5, NPOS),
- TEST (LSTR, 0, 0, NPOS),
- TEST (LSTR, 0, 7, NPOS),
+ TEST ("x@4096", 0, 0, NPOS),
+ TEST ("x@4096", 0, 7, NPOS),
TEST ("", "", 1, NPOS),
TEST ("abcdefghij", "abc", 10, NPOS),
@@ -498,12 +512,15 @@
// used to exercise
// find_first_not_of (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
@@ -527,9 +544,9 @@
TEST ("\0ecb\0\0g", 'a', 0),
TEST ("\0cbge\0\0", '\0', 1),
- TEST (LSTR, 'x', NPOS),
- TEST (LSTR, '\0', 0),
- TEST (LSTR, 'a', 0),
+ TEST ("x@4096", 'x', NPOS),
+ TEST ("x@4096", '\0', 0),
+ TEST ("x@4096", 'a', 0),
TEST ("last test", 't', 0)
};
@@ -538,12 +555,15 @@
// used to exercise
// find_first_not_of (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
@@ -574,12 +594,13 @@
TEST ("\0\0\0cbge", '\0', 0, 3),
TEST ("\0cbge\0\0", '\0', 9, NPOS),
- TEST (LSTR, 'x', 0, NPOS),
- TEST (LSTR, 'x', 5, NPOS),
- TEST (LSTR, '\0', 0, 0),
- TEST (LSTR, 'a', 3, 3),
- TEST (LSTR, 'x', LLEN - 1, NPOS),
- TEST (LSTR, 'x', LLEN - 2, NPOS),
+ TEST ("x@4096", 'x', 0, NPOS),
+ TEST ("x@4096", 'x', 5, NPOS),
+ TEST ("x@4096", '\0', 0, 0),
+ TEST ("x@4096", 'a', 3, 3),
+ TEST ("x@4096", 'x', 4096, NPOS),
+ TEST ("x@4096", 'x', 4095, NPOS),
+ TEST ("x@2048axxx", 'x', 1, 2048),
TEST ("last test", 't', 0, 0)
};
@@ -592,27 +613,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;
- const std::size_t ssize = s_str.size ();
- const std::size_t capacity = s_str.capacity ();
- const ConstStringIter begin = s_str.begin ();
+ 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));
+
+ 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;
@@ -636,27 +672,27 @@
try {
switch (which) {
case FindFirstNotOf (ptr): {
- res = s_str.find_first_not_of (ptr_arg);
+ res = s_str.find_first_not_of (arg_ptr);
break;
}
case FindFirstNotOf (str): {
- res = s_str.find_first_not_of (str_arg);
+ res = s_str.find_first_not_of (arg_str);
break;
}
case FindFirstNotOf (ptr_size): {
- res = s_str.find_first_not_of (ptr_arg, cs.off);
+ res = s_str.find_first_not_of (arg_ptr, cs.off);
break;
}
case FindFirstNotOf (ptr_size_size): {
- res = s_str.find_first_not_of (ptr_arg, cs.off, size);
+ res = s_str.find_first_not_of (arg_ptr, cs.off, size);
break;
}
case FindFirstNotOf (str_size): {
- res = s_str.find_first_not_of (str_arg, cs.off);
+ res = s_str.find_first_not_of (arg_str, cs.off);
break;
}
@@ -680,7 +716,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
@@ -707,24 +743,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,
@@ -732,13 +757,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.find.first.of.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.find.first.of.cpp?rev=406581&r1=406580&r2=406581&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.find.first.of.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.find.first.of.cpp Mon May 15 01:14:29 2006
@@ -32,22 +32,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 FindFirstOf(which) StringMembers::find_first_of_ ## which
+/**************************************************************************/
+
+// for convenience and brevity
+#define NPOS _RWSTD_SIZE_MAX
+#define FindFirstOf(which) StringMembers::find_first_of_ ## 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"
@@ -57,12 +54,15 @@
// used to exercise
// find_first_of (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
@@ -111,16 +111,17 @@
TEST ("bbb", "aaaaaaaaba", 0),
TEST ("bbb", "aaaaaaaaaa", NPOS),
- TEST (LSTR, "", NPOS),
- TEST (LSTR, "a", NPOS),
- TEST (LSTR, "x", 0),
- TEST (LSTR, "axa", 0),
- TEST ("abc", LSTR, NPOS),
- TEST ("axbc", LSTR, 1),
+ TEST ("x@4096", "", NPOS),
+ TEST ("x@4096", "a", NPOS),
+ TEST ("x@4096", "x", 0),
+ TEST ("x@4096", "axa", 0),
+ TEST ("abc", "x@4096", NPOS),
+ TEST ("axbc", "x@4096", 1),
+ TEST ("x@2048axxx", "y@4096a", 2048),
TEST ("abcdefghij", 0, 0),
TEST ("\0cb\0\0ge", 0, NPOS),
- TEST (LSTR, 0, 0),
+ TEST ("x@4096", 0, 0),
TEST ("last test", "test", 2)
};
@@ -129,12 +130,15 @@
// used to exercise
// find_first_of (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,16 +190,17 @@
TEST ("bbb", "aaaaaaaaba", 0),
TEST ("bbb", "aaaaaaaaaa", NPOS),
- TEST (LSTR, "", NPOS),
- TEST (LSTR, "a", NPOS),
- TEST (LSTR, "x", 0),
- TEST (LSTR, "axa", 0),
- TEST ("abc", LSTR, NPOS),
- TEST ("axbc", LSTR, 1),
+ TEST ("x@4096", "", NPOS),
+ TEST ("x@4096", "a", NPOS),
+ TEST ("x@4096", "x", 0),
+ TEST ("x@4096", "axa", 0),
+ TEST ("abc", "x@4096", NPOS),
+ TEST ("axbc", "x@4096", 1),
+ TEST ("x@2048axxx", "y@4096a", 2048),
TEST ("abcdefghij", 0, 0),
TEST ("\0cb\0\0ge", 0, 0),
- TEST (LSTR, 0, 0),
+ TEST ("x@4096", 0, 0),
TEST ("last test", "test", 2)
};
@@ -204,12 +209,15 @@
// used to exercise
// find_first_of (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
@@ -267,22 +275,23 @@
TEST ("bab", "aaaaaaaaba", 0, 0),
TEST ("bbb", "aaaaaaaaaa", 0, NPOS),
- TEST (LSTR, "", 0, NPOS),
- TEST (LSTR, "a", 0, NPOS),
- TEST (LSTR, "x", 0, 0),
- TEST (LSTR, "xxx", 10, 10),
- TEST (LSTR, "axa", 10, 10),
- TEST ("abc", LSTR, 2, NPOS),
- TEST ("xxxxxxxxxx", LSTR, 0, 0),
+ TEST ("x@4096", "", 0, NPOS),
+ TEST ("x@4096", "a", 0, NPOS),
+ TEST ("x@4096", "x", 0, 0),
+ TEST ("x@4096", "xxx", 10, 10),
+ TEST ("x@4096", "axa", 10, 10),
+ TEST ("abc", "x@4096", 2, NPOS),
+ TEST ("xxxxxxxxxx", "x@4096", 0, 0),
+ TEST ("x@2048axxx", "y@4096a", 10, 2048),
- TEST (LSTR, "xxx", LLEN - 4, LLEN - 4),
- TEST (LSTR, "xxx", LLEN - 1, NPOS),
+ TEST ("x@4096", "xxx", 4093, 4093),
+ TEST ("x@4096", "xxx", 4096, NPOS),
TEST ("abcdefghij", 0, 0, 0),
TEST ("abcdefghij", 0, 1, 1),
TEST ("\0cb\0\0ge", 0, 5, NPOS),
- TEST (LSTR, 0, 0, 0),
- TEST (LSTR, 0, 7, 7),
+ TEST ("x@4096", 0, 0, 0),
+ TEST ("x@4096", 0, 7, 7),
TEST ("", "", 1, NPOS),
TEST ("abcdefghij", "abc", 10, NPOS),
@@ -295,12 +304,15 @@
// used to exercise
// find_first_of (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
@@ -369,41 +381,38 @@
TEST ("bab", "aaaaaaaaba", 0, 0, NPOS, 0),
TEST ("bab", "ccccccccba", 1, 10, 1, 0),
- TEST (LSTR, "", 0, 0, NPOS, 0),
- TEST (LSTR, "a", 0, 1, NPOS, 0),
- TEST (LSTR, "x", 0, 1, 0, 0),
- TEST (LSTR, "xxx", 10, 3, 10, 0),
- TEST (LSTR, "axx", 10, 1, NPOS, 0),
- TEST (LSTR, "xxa", 10, 0, NPOS, 0),
- TEST ("abc", LSTR, 2, 10, NPOS, 0),
- TEST ("xxxxxxxxxx", LSTR, 0, LLEN - 1, 0, 0),
- TEST ("xxxxxxxxxx", LSTR, 2, 4, 2, 0),
-
- TEST (LSTR, "xxx", LLEN - 4, 3, LLEN - 4, 0),
- TEST (LSTR, "xxx", LLEN - 3, 0, NPOS, 0),
- TEST (LSTR, "xxx", LLEN - 2, 1, LLEN - 2, 0),
+ TEST ("x@4096", "", 0, 0, NPOS, 0),
+ TEST ("x@4096", "a", 0, 1, NPOS, 0),
+ TEST ("x@4096", "x", 0, 1, 0, 0),
+ TEST ("x@4096", "xxx", 10, 3, 10, 0),
+ TEST ("x@4096", "axx", 10, 1, NPOS, 0),
+ TEST ("x@4096", "xxa", 10, 0, NPOS, 0),
+ TEST ("abc", "x@4096", 2, 10, NPOS, 0),
+ TEST ("xxxxxxxxxx", "x@4096", 0, 4096, 0, 0),
+ TEST ("xxxxxxxxxx", "x@4096", 2, 4, 2, 0),
+ TEST ("x@2048axyx", "y@4096a", 10, 4097, 2048, 0),
+
+ TEST ("x@4096", "xxx", 4093, 3, 4093, 0),
+ TEST ("x@4096", "xxx", 4094, 0, NPOS, 0),
+ TEST ("x@4096", "xxx", 4095, 1, 4095, 0),
TEST ("abcdefghij", 0, 0, 9, 0, 0),
TEST ("abcdefghij", 0, 1, 9, 1, 0),
TEST ("\0cb\0\0ge", 0, 5, 7, 5, 0),
TEST ("\0cb\0\0ge", 0, 5, 5, NPOS, 0),
TEST ("\0cb\0ge\0", 0, 6, 1, 6, 0),
- TEST (LSTR, 0, 0, LLEN - 1, 0, 0),
- TEST (LSTR, 0, LLEN - 1, LLEN - 1, NPOS, 0),
- TEST (LSTR, 0, LLEN - 2, 1, LLEN - 2, 0),
+ TEST ("x@4096", 0, 0, 4096, 0, 0),
+ TEST ("x@4096", 0, 4096, 4096, NPOS, 0),
+ TEST ("x@4096", 0, 4095, 1, 4095, 0),
TEST ("", "", 1, 0, NPOS, 0),
TEST ("abcdefghij", "abc", 10, 3, NPOS, 0),
TEST ("abcdefghij", "cba", 10, 1, NPOS, 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", 0, 4, 2, 0)
};
@@ -412,12 +421,15 @@
// used to exercise
// find_first_of (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
@@ -477,23 +489,24 @@
TEST ("bab", "aaaaaaaaba", 0, 0),
TEST ("bbb", "aaaaaaaaaa", 0, NPOS),
- TEST (LSTR, "", 0, NPOS),
- TEST (LSTR, "a", 0, NPOS),
- TEST (LSTR, "x", 0, 0),
- TEST (LSTR, "xxx", 10, 10),
- TEST (LSTR, "axa", 10, 10),
- TEST ("abc", LSTR, 2, NPOS),
- TEST ("xxxxxxxxxx", LSTR, 0, 0),
+ TEST ("x@4096", "", 0, NPOS),
+ TEST ("x@4096", "a", 0, NPOS),
+ TEST ("x@4096", "x", 0, 0),
+ TEST ("x@4096", "xxx", 10, 10),
+ TEST ("x@4096", "axa", 10, 10),
+ TEST ("abc", "x@4096", 2, NPOS),
+ TEST ("xxxxxxxxxx", "x@4096", 0, 0),
+ TEST ("x@2048axxx", "y@4096a", 10, 2048),
- TEST (LSTR, "xxx", LLEN - 4, LLEN - 4),
- TEST (LSTR, "xxx", LLEN - 1, NPOS),
+ TEST ("x@4096", "xxx", 4093, 4093),
+ TEST ("x@4096", "xxx", 4096, NPOS),
TEST ("abcdefghij", 0, 0, 0),
TEST ("abcdefghij", 0, 1, 1),
TEST ("\0cb\0\0ge", 0, 5, 5),
TEST ("\0cb\0\0ge", 0, 4, 4),
- TEST (LSTR, 0, 0, 0),
- TEST (LSTR, 0, 7, 7),
+ TEST ("x@4096", 0, 0, 0),
+ TEST ("x@4096", 0, 7, 7),
TEST ("", "", 1, NPOS),
TEST ("abcdefghij", "abc", 10, NPOS),
@@ -506,12 +519,15 @@
// used to exercise
// find_first_of (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
@@ -535,9 +551,10 @@
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 ("x@2048axxx", 'a', 2048),
TEST ("last test", 't', 3)
};
@@ -546,12 +563,15 @@
// used to exercise
// find_first_of (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
@@ -584,12 +604,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@4096", 'a', 3, NPOS),
+ TEST ("x@4096", 'x', 4096, NPOS),
+ TEST ("x@4096", 'x', 4095, 4095),
+ TEST ("x@2048axxx", 'a', 10, 2048),
TEST ("last test", 't', 0, 3)
};
@@ -602,27 +623,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;
@@ -646,27 +682,27 @@
try {
switch (which) {
case FindFirstOf (ptr): {
- res = s_str.find_first_of (ptr_arg);
+ res = s_str.find_first_of (arg_ptr);
break;
}
case FindFirstOf (str): {
- res = s_str.find_first_of (str_arg);
+ res = s_str.find_first_of (arg_str);
break;
}
case FindFirstOf (ptr_size): {
- res = s_str.find_first_of (ptr_arg, cs.off);
+ res = s_str.find_first_of (arg_ptr, cs.off);
break;
}
case FindFirstOf (ptr_size_size): {
- res = s_str.find_first_of (ptr_arg, cs.off, size);
+ res = s_str.find_first_of (arg_ptr, cs.off, size);
break;
}
case FindFirstOf (str_size): {
- res = s_str.find_first_of (str_arg, cs.off);
+ res = s_str.find_first_of (arg_str, cs.off);
break;
}
@@ -690,7 +726,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
@@ -717,24 +753,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,
@@ -742,13 +767,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.find.last.not.of.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.find.last.not.of.cpp?rev=406581&r1=406580&r2=406581&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.find.last.not.of.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.find.last.not.of.cpp Mon May 15 01:14:29 2006
@@ -32,22 +32,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 FindLastNotOf(which) StringMembers::find_last_not_of_ ## which
+/**************************************************************************/
+
+// for convenience and brevity
+#define NPOS _RWSTD_SIZE_MAX
+#define FindLastNotOf(which) StringMembers::find_last_not_of_ ## 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"
@@ -57,12 +54,15 @@
// used to exercise
// find_last_not_of (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
@@ -106,17 +106,18 @@
TEST ("bbb", "aaaaaaaaaa", 2),
TEST ("abcdefghij", "jihgfedcba", NPOS),
- TEST (LSTR, "", LLEN - 2),
- TEST (LSTR, "a", LLEN - 2),
- TEST (LSTR, "x", NPOS),
- TEST (LSTR, "xxx", NPOS),
- TEST (LSTR, "aax", NPOS),
- TEST ("abc", LSTR, 2),
- TEST ("xxxxxxxxxx", LSTR, NPOS),
+ TEST ("x@4096", "", 4095),
+ TEST ("x@4096", "a", 4095),
+ TEST ("x@4096", "x", NPOS),
+ TEST ("x@4096", "xxx", NPOS),
+ TEST ("x@4096", "aax", NPOS),
+ TEST ("abc", "x@4096", 2),
+ TEST ("xxxxxxxxxx", "x@4096", NPOS),
+ TEST ("xxax@2048", "x@4096", 2),
TEST ("abcdefghij", 0, NPOS),
TEST ("\0cb\0\0ge", 0, 6),
- TEST (LSTR, 0, NPOS),
+ TEST ("x@4096", 0, NPOS),
TEST ("last test", "test", 4)
};
@@ -125,12 +126,15 @@
// used to exercise
// find_last_not_of (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
@@ -176,17 +180,18 @@
TEST ("bbb", "aaaaaaaaaa", 2),
TEST ("abcdefghij", "jihgfedcba", NPOS),
- TEST (LSTR, "", LLEN - 2),
- TEST (LSTR, "a", LLEN - 2),
- TEST (LSTR, "x", NPOS),
- TEST (LSTR, "xxx", NPOS),
- TEST (LSTR, "aax", NPOS),
- TEST ("abc", LSTR, 2),
- TEST ("xxxxxxxxxx", LSTR, NPOS),
+ TEST ("x@4096", "", 4095),
+ TEST ("x@4096", "a", 4095),
+ TEST ("x@4096", "x", NPOS),
+ TEST ("x@4096", "xxx", NPOS),
+ TEST ("x@4096", "aax", NPOS),
+ TEST ("abc", "x@4096", 2),
+ TEST ("xxxxxxxxxx", "x@4096", NPOS),
+ TEST ("xxax@2048", "x@4096", 2),
TEST ("abcdefghij", 0, NPOS),
TEST ("\0cb\0\0ge", 0, NPOS),
- TEST (LSTR, 0, NPOS),
+ TEST ("x@4096", 0, NPOS),
TEST ("last test", "test", 4)
};
@@ -195,12 +200,15 @@
// used to exercise
// find_last_not_of (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
@@ -258,25 +266,26 @@
TEST ("cab", "aaaaaaaaba", 0, 0),
TEST ("bbb", "aaaaaaaaaa", 3, 2),
- TEST (LSTR, "", LLEN - 1, LLEN - 2),
- TEST (LSTR, "a", LLEN - 1, LLEN - 2),
- TEST (LSTR, "x", LLEN - 1, NPOS),
- TEST (LSTR, "xxx", LLEN - 2, NPOS),
- TEST (LSTR, "xxx", 0, NPOS),
- TEST (LSTR, "xxx", LLEN - 10, NPOS),
- TEST (LSTR, "aax", LLEN - 10, NPOS),
- TEST ("abc", LSTR, 2, 2),
- TEST ("xxxxxxxxxx", LSTR, 6, NPOS),
- TEST ("xxxxaxxxxx", LSTR, 9, 4),
-
- TEST (LSTR, "xxx", 3, NPOS),
- TEST (LSTR, "xxx", 2, NPOS),
+ TEST ("x@4096", "", 4096, 4095),
+ TEST ("x@4096", "a", 4096, 4095),
+ TEST ("x@4096", "x", 4096, NPOS),
+ TEST ("x@4096", "xxx", 4095, NPOS),
+ TEST ("x@4096", "xxx", 0, NPOS),
+ TEST ("x@4096", "xxx", 4087, NPOS),
+ TEST ("x@4096", "aax", 4087, NPOS),
+ TEST ("abc", "x@4096", 2, 2),
+ TEST ("xxxxxxxxxx", "x@4096", 6, NPOS),
+ TEST ("xxxxaxxxxx", "x@4096", 9, 4),
+
+ TEST ("x@4096", "xxx", 3, NPOS),
+ TEST ("x@4096", "xxx", 2, NPOS),
+ TEST ("xxax@2048", "x@4096", 2052, 2),
TEST ("abcdefghij", 0, 0, NPOS),
TEST ("abcdefghij", 0, 9, NPOS),
TEST ("\0cb\0\0ge", 0, 5, 5),
- TEST (LSTR, 0, 0, NPOS),
- TEST (LSTR, 0, 1, NPOS),
+ TEST ("x@4096", 0, 0, NPOS),
+ TEST ("x@4096", 0, 1, NPOS),
TEST ("", "", 1, NPOS),
TEST ("defghijabc", "abc", 15, 6),
@@ -289,12 +298,15 @@
// used to exercise
// find_last_not_of (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, NPOS, -1, -1, str, sizeof str - 1, arg, \
- sizeof arg - 1, 0, res, bthrow }
+#define TEST(str, arg, off, size, res, bthrow) \
+ { __LINE__, off, size, NPOS, -1, -1, \
+ str, sizeof str - 1, arg, \
+ sizeof arg - 1, 0, res, bthrow \
+ }
// +----------------------------------- controlled sequence
// | +---------------------- sequence to be found
@@ -371,53 +383,53 @@
TEST ("abcdefghij", "jihgfedcba", 9, 10, NPOS, 0),
TEST ("abcdefghij", "jihgfedcba", 9, 9, 0, 0),
- TEST (LSTR, "", LLEN - 1, 0, LLEN - 2, 0),
- TEST (LSTR, "a", LLEN - 1, 1, LLEN - 2, 0),
- TEST (LSTR, "x", LLEN - 1, 1, NPOS, 0),
- TEST (LSTR, "xxx", LLEN - 9, 3, NPOS, 0),
- TEST (LSTR, "aax", LLEN - 9, 2, LLEN - 9, 0),
- TEST ("abc", LSTR, 2, 10, 2, 0),
- TEST ("xxxxxxxxxx", LSTR, 9, LLEN - 1, NPOS, 0),
- TEST ("xxxxxxxxxx", LSTR, 2, 4, NPOS, 0),
-
- TEST (LSTR, "xxx", LLEN - 4, 3, NPOS, 0),
- TEST (LSTR, "xxx", LLEN - 3, 0, LLEN - 3, 0),
+ TEST ("x@4096", "", 4096, 0, 4095, 0),
+ TEST ("x@4096", "a", 4096, 1, 4095, 0),
+ TEST ("x@4096", "x", 4096, 1, NPOS, 0),
+ TEST ("x@4096", "xxx", 4088, 3, NPOS, 0),
+ TEST ("x@4096", "aax", 4088, 2, 4088, 0),
+ TEST ("abc", "x@4096", 2, 10, 2, 0),
+ TEST ("xxxxxxxxxx", "x@4096", 9, 4096, NPOS, 0),
+ TEST ("xxxxxxxxxx", "x@4096", 2, 4, NPOS, 0),
+
+ TEST ("x@4096", "xxx", 4093, 3, NPOS, 0),
+ TEST ("x@4096", "xxx", 4094, 0, 4094, 0),
+ TEST ("xxax@2048", "x@4096a", 2052, 4096, 2, 0),
TEST ("abcdefghij", 0, 9, 10, NPOS, 0),
TEST ("abcdefghij", 0, 8, 6, 8, 0),
TEST ("\0cb\0\0ge", 0, 5, 7, NPOS, 0),
TEST ("\0cb\0ge\0", 0, 6, 1, 5, 0),
TEST ("\0c\0eg\0c", 0, 6, 2, 4, 0),
- TEST (LSTR, 0, 0, LLEN - 1, NPOS, 0),
- TEST (LSTR, 0, 1, LLEN - 1, NPOS, 0),
- TEST (LSTR, 0, LLEN - 6, 0, LLEN - 6, 0),
+ TEST ("x@4096", 0, 0, 4096, NPOS, 0),
+ TEST ("x@4096", 0, 1, 4096, NPOS, 0),
+ TEST ("x@4096", 0, 4091, 0, 4091, 0),
TEST ("", "", 1, 0, NPOS, 0),
TEST ("defghijabc", "abc", 15, 3, 6, 0),
TEST ("defghijabc", "cba", 15, 1, 8, 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, 4, 0)
+ TEST ("last test", "test", 9, 4, 4, 0)
};
/**************************************************************************/
// used to exercise
// find_last_not_of (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
@@ -477,25 +489,26 @@
TEST ("cab", "aaaaaaaaba", 0, 0),
TEST ("bbb", "aaaaaaaaaa", 3, 2),
- TEST (LSTR, "", LLEN - 1, LLEN - 2),
- TEST (LSTR, "a", LLEN - 1, LLEN - 2),
- TEST (LSTR, "x", LLEN - 1, NPOS),
- TEST (LSTR, "xxx", LLEN - 2, NPOS),
- TEST (LSTR, "xxx", 0, NPOS),
- TEST (LSTR, "xxx", LLEN - 10, NPOS),
- TEST (LSTR, "aax", LLEN - 10, NPOS),
- TEST ("abc", LSTR, 2, 2),
- TEST ("xxxxxxxxxx", LSTR, 6, NPOS),
- TEST ("xxxxaxxxxx", LSTR, 9, 4),
+ TEST ("x@4096", "", 4096, 4095),
+ TEST ("x@4096", "a", 4096, 4095),
+ TEST ("x@4096", "x", 4096, NPOS),
+ TEST ("x@4096", "xxx", 4095, NPOS),
+ TEST ("x@4096", "xxx", 0, NPOS),
+ TEST ("x@4096", "xxx", 4087, NPOS),
+ TEST ("x@4096", "aax", 4087, NPOS),
+ TEST ("abc", "x@4096", 2, 2),
+ TEST ("xxxxxxxxxx", "x@4096", 6, NPOS),
+ TEST ("xxxxaxxxxx", "x@4096", 9, 4),
+ TEST ("xxax@2048", "x@4096", 2050, 2),
- TEST (LSTR, "xxx", 3, NPOS),
- TEST (LSTR, "xxx", 2, NPOS),
+ TEST ("x@4096", "xxx", 3, NPOS),
+ TEST ("x@4096", "xxx", 2, NPOS),
TEST ("abcdefghij", 0, 0, NPOS),
TEST ("abcdefghij", 0, 9, NPOS),
TEST ("\0cb\0\0ge", 0, 5, NPOS),
- TEST (LSTR, 0, 0, NPOS),
- TEST (LSTR, 0, 1, NPOS),
+ TEST ("x@4096", 0, 0, NPOS),
+ TEST ("x@4096", 0, 1, NPOS),
TEST ("", "", 1, NPOS),
TEST ("defghijabc", "abc", 15, 6),
@@ -508,12 +521,15 @@
// used to exercise
// find_last_not_of (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
@@ -539,9 +555,10 @@
TEST ("aaaaaaaaaa", 'a', NPOS),
TEST ("\0aaaaaaaa", 'a', 0),
- TEST (LSTR, 'x', NPOS),
- TEST (LSTR, '\0', LLEN - 2),
- TEST (LSTR, 'a', LLEN - 2),
+ TEST ("x@4096", 'x', NPOS),
+ TEST ("x@4096", '\0', 4095),
+ TEST ("x@4096", 'a', 4095),
+ TEST ("xxax@2048", 'x', 2),
TEST ("last test", 't', 7)
};
@@ -550,12 +567,15 @@
// used to exercise
// find_last_not_of (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
@@ -587,11 +607,12 @@
TEST ("aaaaaaaaaa", 'a', 6, NPOS),
TEST ("\0aaaaaaaa", 'a', 6, 0),
- TEST (LSTR, 'x', 0, NPOS),
- TEST (LSTR, 'x', LLEN - 1, NPOS),
- TEST (LSTR, '\0', LLEN - 1, LLEN - 2),
- TEST (LSTR, 'a', LLEN - 3, LLEN - 3),
- TEST (LSTR, 'x', LLEN + 9, NPOS),
+ TEST ("x@4096", 'x', 0, NPOS),
+ TEST ("x@4096", 'x', 4096, NPOS),
+ TEST ("x@4096", '\0', 4096, 4095),
+ TEST ("x@4096", 'a', 4094, 4094),
+ TEST ("x@4096", 'x', 4106, NPOS),
+ TEST ("xxax@2048", 'x', 2050, 2),
TEST ("last test", 't', 9, 7)
};
@@ -604,27 +625,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);
- const std::size_t ssize = s_str.size ();
- const std::size_t capacity = s_str.capacity ();
- const ConstStringIter begin = s_str.begin ();
+ if (wstr != wstr_buf)
+ delete[] wstr;
- const charT* const ptr_arg = cs.arg ? warg : s_str.c_str ();
- const TestString& str_arg = cs.arg ? s_arg : s_str;
+ 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));
+
+ std::size_t res = 0;
+ std::size_t exp_res = NPOS != cs.nres ? cs.nres : String::npos;
+
+ 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;
@@ -648,27 +684,27 @@
try {
switch (which) {
case FindLastNotOf (ptr): {
- res = s_str.find_last_not_of (ptr_arg);
+ res = s_str.find_last_not_of (arg_ptr);
break;
}
case FindLastNotOf (str): {
- res = s_str.find_last_not_of (str_arg);
+ res = s_str.find_last_not_of (arg_str);
break;
}
case FindLastNotOf (ptr_size): {
- res = s_str.find_last_not_of (ptr_arg, cs.off);
+ res = s_str.find_last_not_of (arg_ptr, cs.off);
break;
}
case FindLastNotOf (ptr_size_size): {
- res = s_str.find_last_not_of (ptr_arg, cs.off, size);
+ res = s_str.find_last_not_of (arg_ptr, cs.off, size);
break;
}
case FindLastNotOf (str_size): {
- res = s_str.find_last_not_of (str_arg, cs.off);
+ res = s_str.find_last_not_of (arg_str, cs.off);
break;
}
@@ -692,7 +728,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
@@ -719,24 +755,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,
@@ -744,13 +769,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.find.last.of.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.find.last.of.cpp?rev=406581&r1=406580&r2=406581&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.find.last.of.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.find.last.of.cpp Mon May 15 01:14:29 2006
@@ -32,22 +32,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 FindLastOf(which) StringMembers::find_last_of_ ## which
+/**************************************************************************/
+
+// for convenience and brevity
+#define NPOS _RWSTD_SIZE_MAX
+#define FindLastOf(which) StringMembers::find_last_of_ ## 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"
@@ -57,12 +54,15 @@
// used to exercise
// find_last_of (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
@@ -111,17 +111,18 @@
TEST ("bbb", "aaaaaaaaba", 2),
TEST ("bbb", "aaaaaaaaaa", NPOS),
- TEST (LSTR, "", NPOS),
- TEST (LSTR, "a", NPOS),
- TEST (LSTR, "x", LLEN - 2),
- TEST (LSTR, "xxx", LLEN - 2),
- TEST (LSTR, "aax", LLEN - 2),
- TEST ("abc", LSTR, NPOS),
- TEST ("xxxxxxxxxx", LSTR, 9),
+ TEST ("x@4096", "", NPOS),
+ TEST ("x@4096", "a", NPOS),
+ TEST ("x@4096", "x", 4095),
+ TEST ("x@4096", "xxx", 4095),
+ TEST ("x@4096", "aax", 4095),
+ TEST ("abc", "x@4096", NPOS),
+ TEST ("xxxxxxxxxx", "x@4096", 9),
+ TEST ("xxax@2048", "y@4096a", 2),
TEST ("abcdefghij", 0, 9),
TEST ("\0cb\0\0ge", 0, NPOS),
- TEST (LSTR, 0, LLEN - 2),
+ TEST ("x@4096", 0, 4095),
TEST ("last test", "test", 8)
};
@@ -130,12 +131,15 @@
// used to exercise
// find_last_of (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
@@ -185,17 +189,18 @@
TEST ("bbb", "aaaaaaaaba", 2),
TEST ("bbb", "aaaaaaaaaa", NPOS),
- TEST (LSTR, "", NPOS),
- TEST (LSTR, "a", NPOS),
- TEST (LSTR, "x", LLEN - 2),
- TEST (LSTR, "xxx", LLEN - 2),
- TEST (LSTR, "aax", LLEN - 2),
- TEST ("abc", LSTR, NPOS),
- TEST ("xxxxxxxxxx", LSTR, 9),
+ TEST ("x@4096", "", NPOS),
+ TEST ("x@4096", "a", NPOS),
+ TEST ("x@4096", "x", 4095),
+ TEST ("x@4096", "xxx", 4095),
+ TEST ("x@4096", "aax", 4095),
+ TEST ("abc", "x@4096", NPOS),
+ TEST ("xxxxxxxxxx", "x@4096", 9),
+ TEST ("xxax@2048", "y@4096a", 2),
TEST ("abcdefghij", 0, 9),
TEST ("\0cb\0\0ge", 0, 6),
- TEST (LSTR, 0, LLEN - 2),
+ TEST ("x@4096", 0, 4095),
TEST ("last test", "test", 8)
};
@@ -204,12 +209,15 @@
// used to exercise
// find_last_of (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, NPOS, -1, -1, -1, str, sizeof str - 1, arg, \
- sizeof arg - 1, 0, res, 0 }
+#define TEST(str, arg, off, res) \
+ { __LINE__, off, NPOS, -1, -1, -1, \
+ str, sizeof str - 1, arg, \
+ sizeof arg - 1, 0, res, 0 \
+ }
// +-------------------------------------- controlled sequence
// | +------------------------- sequence to be found
@@ -272,24 +280,25 @@
TEST ("bab", "aaaaaaaaba", 0, 0),
TEST ("bbb", "aaaaaaaaaa", 3, NPOS),
- TEST (LSTR, "", LLEN - 1, NPOS),
- TEST (LSTR, "a", LLEN - 1, NPOS),
- TEST (LSTR, "x", LLEN - 1, LLEN - 2),
- TEST (LSTR, "xxx", LLEN - 2, LLEN - 2),
- TEST (LSTR, "xxx", 0, 0),
- TEST (LSTR, "xxx", LLEN - 10, LLEN - 10),
- TEST (LSTR, "aax", LLEN - 10, LLEN - 10),
- TEST ("abc", LSTR, 2, NPOS),
- TEST ("xxxxxxxxxx", LSTR, 6, 6),
+ TEST ("x@4096", "", 4096, NPOS),
+ TEST ("x@4096", "a", 4096, NPOS),
+ TEST ("x@4096", "x", 4096, 4095),
+ TEST ("x@4096", "xxx", 4095, 4095),
+ TEST ("x@4096", "xxx", 0, 0),
+ TEST ("x@4096", "xxx", 4087, 4087),
+ TEST ("x@4096", "aax", 4087, 4087),
+ TEST ("abc", "x@4096", 2, NPOS),
+ TEST ("xxxxxxxxxx", "x@4096", 6, 6),
+ TEST ("xxax@2048", "y@4096a", 2050, 2),
- 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, 9, 9),
TEST ("\0cb\0\0ge", 0, 5, NPOS),
- TEST (LSTR, 0, 0, 0),
- TEST (LSTR, 0, 1, 1),
+ TEST ("x@4096", 0, 0, 0),
+ TEST ("x@4096", 0, 1, 1),
TEST ("", "", 1, NPOS),
TEST ("abcdefghij", "abc", 10, 2),
@@ -302,12 +311,15 @@
// used to exercise
// find_last_of (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
@@ -380,41 +392,38 @@
TEST ("bab", "aaaaaaaaba", 0, 0, NPOS, 0),
TEST ("bab", "ccccccccba", 1, 10, 1, 0),
- TEST (LSTR, "", LLEN - 1, 0, NPOS, 0),
- TEST (LSTR, "a", LLEN - 1, 1, NPOS, 0),
- TEST (LSTR, "x", LLEN - 1, 1, LLEN - 2, 0),
- TEST (LSTR, "xxx", LLEN - 9, 3, LLEN - 9, 0),
- TEST (LSTR, "axa", LLEN - 9, 3, LLEN - 9, 0),
- TEST ("abc", LSTR, 2, 10, NPOS, 0),
- TEST ("xxxxxxxxxx", LSTR, 0, LLEN - 1, 0, 0),
- TEST ("xxxxxxxxxx", LSTR, 2, 4, 2, 0),
-
- TEST (LSTR, "xxx", LLEN - 4, 3, LLEN - 4, 0),
- TEST (LSTR, "xxx", LLEN - 3, 3, LLEN - 3, 0),
- TEST (LSTR, "xxx", LLEN - 3, 2, LLEN - 3, 0),
+ TEST ("x@4096", "", 4096, 0, NPOS, 0),
+ TEST ("x@4096", "a", 4096, 1, NPOS, 0),
+ TEST ("x@4096", "x", 4096, 1, 4095, 0),
+ TEST ("x@4096", "xxx", 4088, 3, 4088, 0),
+ TEST ("x@4096", "axa", 4088, 3, 4088, 0),
+ TEST ("abc", "x@4096", 2, 10, NPOS, 0),
+ TEST ("xxxxxxxxxx", "x@4096", 0,4096, 0, 0),
+ TEST ("xxxxxxxxxx", "x@4096", 2, 4, 2, 0),
+ TEST ("xxax@2048", "y@4096a", 2050,4097, 2, 0),
+
+ TEST ("x@4096", "xxx", 4093, 3, 4093, 0),
+ TEST ("x@4096", "xxx", 4094, 3, 4094, 0),
+ TEST ("x@4096", "xxx", 4094, 2, 4094, 0),
TEST ("abcdefghij", 0, 0, 9, 0, 0),
TEST ("abcdefghij", 0, 8, 9, 8, 0),
TEST ("\0cb\0\0ge", 0, 5, 7, 5, 0),
TEST ("\0cb\0ge\0", 0, 6, 1, 6, 0),
TEST ("\0c\0e\0cg", 0, 6, 2, 5, 0),
- TEST (LSTR, 0, 0, LLEN - 1, 0, 0),
- TEST (LSTR, 0, 1, LLEN - 1, 1, 0),
- TEST (LSTR, 0, 5, LLEN - 6, 5, 0),
- TEST (LSTR, 0, LLEN - 6, 1, LLEN - 6, 0),
+ TEST ("x@4096", 0, 0, 4096, 0, 0),
+ TEST ("x@4096", 0, 1, 4096, 1, 0),
+ TEST ("x@4096", 0, 5, 4091, 5, 0),
+ TEST ("x@4096", 0, 4091, 1, 4091, 0),
TEST ("", "", 1, 0, NPOS, 0),
TEST ("abcdefghij", "abc", 10, 3, 2, 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, 8, 0)
};
@@ -423,12 +432,15 @@
// used to exercise
// find_last_of (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
@@ -491,24 +503,25 @@
TEST ("bab", "aaaaaaaaba", 0, 0),
TEST ("bbb", "aaaaaaaaaa", 3, NPOS),
- TEST (LSTR, "", LLEN - 1, NPOS),
- TEST (LSTR, "a", LLEN - 1, NPOS),
- TEST (LSTR, "x", LLEN - 1, LLEN - 2),
- TEST (LSTR, "xxx", LLEN - 2, LLEN - 2),
- TEST (LSTR, "xxx", 0, 0),
- TEST (LSTR, "xxx", LLEN - 10, LLEN - 10),
- TEST (LSTR, "aax", LLEN - 10, LLEN - 10),
- TEST ("abc", LSTR, 2, NPOS),
- TEST ("xxxxxxxxxx", LSTR, 6, 6),
+ TEST ("x@4096", "", 4096, NPOS),
+ TEST ("x@4096", "a", 4096, NPOS),
+ TEST ("x@4096", "x", 4096, 4095),
+ TEST ("x@4096", "xxx", 4095, 4095),
+ TEST ("x@4096", "xxx", 0, 0),
+ TEST ("x@4096", "xxx", 4087, 4087),
+ TEST ("x@4096", "aax", 4087, 4087),
+ TEST ("abc", "x@4096", 2, NPOS),
+ TEST ("xxxxxxxxxx", "x@4096", 6, 6),
+ TEST ("xxax@2048", "y@4096a", 2050, 2),
- 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, 9, 9),
TEST ("\0cb\0\0ge", 0, 5, 5),
- TEST (LSTR, 0, 0, 0),
- TEST (LSTR, 0, 1, 1),
+ TEST ("x@4096", 0, 0, 0),
+ TEST ("x@4096", 0, 1, 1),
TEST ("", "", 1, NPOS),
TEST ("abcdefghij", "abc", 10, 2),
@@ -521,12 +534,15 @@
// used to exercise
// find_last_of (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
@@ -550,9 +566,10 @@
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 ("xxax@2048", 'a', 2),
TEST ("last test", 't', 8)
};
@@ -561,12 +578,15 @@
// used to exercise
// find_last_of (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
@@ -599,13 +619,14 @@
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 ("xxax@2048", 'a', 2050, 2),
TEST ("last test", 't', 9, 8)
};
@@ -618,27 +639,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;
@@ -662,27 +698,27 @@
try {
switch (which) {
case FindLastOf (ptr): {
- res = s_str.find_last_of (ptr_arg);
+ res = s_str.find_last_of (arg_ptr);
break;
}
case FindLastOf (str): {
- res = s_str.find_last_of (str_arg);
+ res = s_str.find_last_of (arg_str);
break;
}
case FindLastOf (ptr_size): {
- res = s_str.find_last_of (ptr_arg, cs.off);
+ res = s_str.find_last_of (arg_ptr, cs.off);
break;
}
case FindLastOf (ptr_size_size): {
- res = s_str.find_last_of (ptr_arg, cs.off, size);
+ res = s_str.find_last_of (arg_ptr, cs.off, size);
break;
}
case FindLastOf (str_size): {
- res = s_str.find_last_of (str_arg, cs.off);
+ res = s_str.find_last_of (arg_str, cs.off);
break;
}
@@ -706,7 +742,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
@@ -733,24 +769,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,
@@ -758,13 +783,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
}
/**************************************************************************/