You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by se...@apache.org on 2006/04/25 21:51:32 UTC
svn commit: r396965 - in /incubator/stdcxx/trunk/tests: include/21.strings.h
src/21.strings.cpp strings/21.string.append.cpp
strings/21.string.assign.cpp strings/21.string.insert.cpp
strings/21.string.op.plus.equal.cpp strings/21.string.replace.cpp
Author: sebor
Date: Tue Apr 25 12:51:28 2006
New Revision: 396965
URL: http://svn.apache.org/viewcvs?rev=396965&view=rev
Log:
2006-04-25 Martin Sebor <se...@roguewave.com>
* 21.strings.h (long_string, long_string_len): New static members.
* 21.strings.cpp (char_names, traits_names, alloc_names): Moved
from file scope to run_test.
(run_test): Initialized long_string.
* 21.string.append.cpp (run_test): Removed initialization
of long_string, used the static member declared in 21.strings.h.
(AppendOverload): Replaced/renamed macro with OverloadId typedef.
* 21.string.assign.cpp: Same.
* 21.string.insert.cpp: Same.
* 21.string.plus_equal.cpp: Same.
* 21.string.replace.cpp: Same.
Modified:
incubator/stdcxx/trunk/tests/include/21.strings.h
incubator/stdcxx/trunk/tests/src/21.strings.cpp
incubator/stdcxx/trunk/tests/strings/21.string.append.cpp
incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp
incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp
incubator/stdcxx/trunk/tests/strings/21.string.op.plus.equal.cpp
incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp
Modified: incubator/stdcxx/trunk/tests/include/21.strings.h
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/include/21.strings.h?rev=396965&r1=396964&r2=396965&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/include/21.strings.h (original)
+++ incubator/stdcxx/trunk/tests/include/21.strings.h Tue Apr 25 12:51:28 2006
@@ -250,6 +250,11 @@
static void
run_test (TestFun*, const Test*, _RWSTD_SIZE_T);
+ enum { long_string_len = 4096 };
+
+ static char
+ long_string [long_string_len];
+
// array of integers to use for command line option
// processing (to disable individual overloads of all
// member functions)
Modified: incubator/stdcxx/trunk/tests/src/21.strings.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/21.strings.cpp?rev=396965&r1=396964&r2=396965&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/21.strings.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/21.strings.cpp Tue Apr 25 12:51:28 2006
@@ -41,19 +41,8 @@
/**************************************************************************/
-static const char* const char_names[] = {
- "char", "wchar_t", "UserChar"
-};
-
-
-static const char* const traits_names[] = {
- "char_traits", "UserTraits"
-};
-
-
-static const char* const allocator_names[] = {
- "allocator", "UserAllocator"
-};
+char StringMembers::
+long_string [StringMembers::long_string_len];
int StringMembers::
opt_memfun_disabled [StringMembers::sig_last];
@@ -77,6 +66,20 @@
void StringMembers::
setvars (const Function &fun, const TestCase *pcase /* = 0 */)
{
+ static const char* const char_names[] = {
+ "char", "wchar_t", "UserChar"
+ };
+
+
+ static const char* const traits_names[] = {
+ "char_traits", "UserTraits"
+ };
+
+
+ static const char* const allocator_names[] = {
+ "allocator", "UserAllocator"
+ };
+
char* buf = 0;
size_t bufsize = 0;
@@ -386,17 +389,23 @@
void StringMembers::
run_test (TestFun *test_callback, const Test *tests, size_t test_count)
{
- const charT char_types[] = {
+ if ('\0' == long_string [0]) {
+ // initialize long_string
+ for (size_t i = 0; i != sizeof long_string - 1; ++i)
+ long_string [i] = 'x';
+ }
+
+ static const charT char_types[] = {
Char, WChar, UChar,
UnknownChar
};
- const Traits traits_types[] = {
+ static const Traits traits_types[] = {
DefaultTraits, UserTraits,
UnknownTraits,
};
- const Allocator alloc_types[] = {
+ static const Allocator alloc_types[] = {
DefaultAllocator,
UnknownAllocator
};
Modified: incubator/stdcxx/trunk/tests/strings/21.string.append.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.append.cpp?rev=396965&r1=396964&r2=396965&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.append.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.append.cpp Tue Apr 25 12:51:28 2006
@@ -41,29 +41,24 @@
#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
// disabled for compilers such as IBM VAC++ or MSVC
// that can't reliably replace the operators
-# include <rw_new.h>
-
+# include <rw_new.h> // for bad_alloc, replacement operator new
#else
-# include <new>
-
+# include <new> // for bad_alloc
#endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE
-#define AppendOverload StringMembers::OverloadId
#define Append(which) StringMembers::append_ ## which
-typedef StringMembers::TestCase TestCase;
-typedef StringMembers::Test Test;
-typedef StringMembers::Function MemFun;
+typedef StringMembers::OverloadId OverloadId;
+typedef StringMembers::TestCase TestCase;
+typedef StringMembers::Test Test;
+typedef StringMembers::Function MemFun;
/**************************************************************************/
// for convenience and brevity
-#define LSTR long_string
-#define LLEN long_string_len
-
-static const std::size_t long_string_len = 4096;
-static char long_string [long_string_len];
+#define LSTR StringMembers::long_string
+#define LLEN StringMembers::long_string_len
static const char* const exceptions[] = {
"unknown exception", "out_of_range", "length_error",
@@ -489,7 +484,7 @@
template <class charT, class Traits>
void test_append (charT, Traits*,
- AppendOverload which,
+ OverloadId which,
const TestCase &tcase)
{
typedef std::allocator<charT> Allocator;
@@ -598,7 +593,7 @@
}
default:
- RW_ASSERT (!"test logic error: unknown append overload");
+ RW_ASSERT (!"logic error: unknown append overload");
}
// verify the returned value
@@ -741,12 +736,6 @@
int run_test (int, char*[])
{
- if ('\0' == LSTR [0]) {
- // initialize LSTR
- for (std::size_t i = 0; i != sizeof LSTR - 1; ++i)
- LSTR [i] = 'x';
- }
-
static const StringMembers::Test
tests [] = {
Modified: incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp?rev=396965&r1=396964&r2=396965&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.assign.cpp Tue Apr 25 12:51:28 2006
@@ -30,23 +30,21 @@
#include <cstddef> // for size_t
#include <stdexcept> // for out_of_range, length_error
+#include <alg_test.h> // for InputIter<>
#include <cmdopt.h> // for rw_enabled()
#include <driver.h> // for rw_test()
-#include <rw_printf.h> // for rw_asnprintf()
#include <rw_char.h> // for rw_widen()
-#include <alg_test.h> // for InputIter<>
+#include <rw_printf.h> // for rw_asnprintf()
#include <21.strings.h>
#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
// disabled for compilers such as IBM VAC++ or MSVC
// that can't reliably replace the operators
-# include <rw_new.h>
-
+# include <rw_new.h> // for bad_alloc, replacement operator new
#else
-# include <new>
-
+# include <new> // for bad_alloc
#endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE
@@ -60,11 +58,8 @@
/**************************************************************************/
// for convenience and brevity
-#define LSTR long_string
-#define LLEN long_string_len
-
-static const std::size_t long_string_len = 4096;
-static char long_string [long_string_len];
+#define LSTR StringMembers::long_string
+#define LLEN StringMembers::long_string_len
static const char* const exceptions[] = {
"unknown exception", "out_of_range", "length_error",
@@ -745,12 +740,6 @@
static int
run_test (int, char*[])
{
- if ('\0' == LSTR [0]) {
- // initialize LSTR
- for (std::size_t i = 0; i != sizeof LSTR - 1; ++i)
- LSTR [i] = 'x';
- }
-
static const StringMembers::Test
tests [] = {
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=396965&r1=396964&r2=396965&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.insert.cpp Tue Apr 25 12:51:28 2006
@@ -42,29 +42,23 @@
#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
// disabled for compilers such as IBM VAC++ or MSVC
// that can't reliably replace the operators
-# include <rw_new.h>
-
+# include <rw_new.h> // for bad_alloc, replacement operator new
#else
-# include <new>
-
+# include <new> // for bad_alloc
#endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE
-#define InsertOverload StringMembers::OverloadId
#define Insert(which) StringMembers::insert_ ## which
-typedef StringMembers::TestCase TestCase;
-typedef StringMembers::Test Test;
-typedef StringMembers::Function MemFun;
-
+typedef StringMembers::OverloadId OverloadId;
+typedef StringMembers::TestCase TestCase;
+typedef StringMembers::Test Test;
+typedef StringMembers::Function MemFun;
/**************************************************************************/
// for convenience and brevity
-#define LSTR long_string
-#define LLEN long_string_len
-
-static const std::size_t long_string_len = 4096;
-static char long_string [long_string_len];
+#define LSTR StringMembers::long_string
+#define LLEN StringMembers::long_string_len
static const char* const exceptions[] = {
"unknown exception", "out_of_range", "length_error",
@@ -567,7 +561,7 @@
template <class charT, class Traits>
void test_insert (charT, Traits*,
- InsertOverload which,
+ OverloadId which,
const TestCase &tcase)
{
typedef std::allocator<charT> Allocator;
@@ -690,7 +684,7 @@
}
default:
- RW_ASSERT ("test logic error: unknown insert overload");
+ RW_ASSERT (!"logic error: unknown insert overload");
return;
}
@@ -837,12 +831,6 @@
static int
run_test (int, char*[])
{
- if ('\0' == LSTR [0]) {
- // initialize LSTR
- for (std::size_t i = 0; i != sizeof LSTR - 1; ++i)
- LSTR [i] = 'x';
- }
-
static const StringMembers::Test
tests [] = {
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=396965&r1=396964&r2=396965&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 Tue Apr 25 12:51:28 2006
@@ -29,12 +29,11 @@
#include <cstdlib> // for free(), size_t
#include <stdexcept> // for out_of_range, length_error
+#include <alg_test.h> // for InputIter
#include <cmdopt.h> // for rw_enabled()
#include <driver.h> // for rw_test()
-
#include <rw_printf.h> // for rw_asnprintf()
#include <rw_char.h> // for rw_widen()
-#include <alg_test.h> // for InputIter<>
#include <21.strings.h>
@@ -44,21 +43,18 @@
# include <new> // for bad_alloc
#endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE
-#define OpPlusEqOverload StringMembers::OverloadId
#define OpPlusEq(which) StringMembers::op_plus_eq_ ## which
-typedef StringMembers::TestCase TestCase;
-typedef StringMembers::Test Test;
-typedef StringMembers::Function MemFun;
+typedef StringMembers::OverloadId OverloadId;
+typedef StringMembers::TestCase TestCase;
+typedef StringMembers::Test Test;
+typedef StringMembers::Function MemFun;
/**************************************************************************/
// for convenience and brevity
-#define LSTR long_string
-#define LLEN long_string_len
-
-static const std::size_t long_string_len = 4096;
-static char long_string [long_string_len];
+#define LSTR StringMembers::long_string
+#define LLEN StringMembers::long_string_len
static const char* const exceptions[] = {
"unknown exception", "out_of_range", "length_error",
@@ -226,8 +222,8 @@
template <class charT, class Traits>
void test_op_plus_eq (charT, Traits*,
- OpPlusEqOverload which,
- const TestCase &cs)
+ OverloadId which,
+ const TestCase &tcase)
{
typedef std::allocator<charT> Allocator;
typedef std::basic_string <charT, Traits, Allocator> TestString;
@@ -237,11 +233,11 @@
static charT wstr [LLEN];
static charT warg [LLEN];
- rw_widen (wstr, cs.str, cs.str_len);
- rw_widen (warg, cs.arg, cs.arg_len);
+ rw_widen (wstr, tcase.str, tcase.str_len);
+ rw_widen (warg, tcase.arg, tcase.arg_len);
- TestString s_str (wstr, cs.str_len);
- TestString s_arg (warg, cs.arg_len);
+ TestString s_str (wstr, tcase.str_len);
+ TestString s_arg (warg, tcase.arg_len);
std::size_t res_off = 0;
std::size_t throw_after = 0;
@@ -250,9 +246,9 @@
const std::size_t capacity = s_str.capacity ();
const ConstStringIter begin = s_str.begin ();
- const charT* const arg_ptr = cs.arg ? warg : s_str.c_str ();
- const TestString& arg_str = cs.arg ? s_arg : s_str;
- const charT arg_val = make_char (char (cs.val), (charT*)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 arg_val = make_char (char (tcase.val), (charT*)0);
#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
@@ -268,7 +264,7 @@
#ifndef _RWSTD_NO_EXCEPTIONS
# ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
- if (-1 == cs.bthrow)
+ if (-1 == tcase.bthrow)
*pst->throw_at_calls_ [0] = pst->new_calls_ [0] + throw_after + 1;
# endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE
@@ -278,16 +274,16 @@
// is some exception expected ?
const char* expected = 0;
- if (1 == cs.bthrow)
+ if (1 == tcase.bthrow)
expected = exceptions [2]; // length_error
- if (-1 == cs.bthrow)
+ if (-1 == tcase.bthrow)
expected = exceptions [3]; // bad_alloc
const char* caught = 0;
#else // if defined (_RWSTD_NO_EXCEPTIONS)
- if (cs.bthrow)
+ if (tcase.bthrow)
return;
#endif // _RWSTD_NO_EXCEPTIONS
@@ -318,29 +314,29 @@
}
// verify the returned value
- rw_assert (0 == res_off, 0, cs.line,
+ rw_assert (0 == res_off, 0, tcase.line,
"line %d. %{$FUNCALL} returned invalid reference, "
"offset is %zu", __LINE__, res_off);
// verfiy that strings length are equal
- rw_assert (cs.res_len == s_str.size (), 0, cs.line,
+ rw_assert (tcase.res_len == s_str.size (), 0, tcase.line,
"line %d. %{$FUNCALL} expected %{#*s} "
"with length %zu, got %{/*.*Gs} with length %zu",
- __LINE__, int (cs.res_len), cs.res, cs.res_len,
+ __LINE__, int (tcase.res_len), tcase.res, tcase.res_len,
int (sizeof (charT)), int (s_str.size ()),
s_str.c_str (), s_str.size ());
- if (cs.res_len == s_str.size ()) {
+ if (tcase.res_len == s_str.size ()) {
// if the result length matches the expected length
// (and only then), also verify that the modified
// string matches the expected result
const std::size_t match =
- rw_match (cs.res, s_str.c_str(), cs.res_len);
+ rw_match (tcase.res, s_str.c_str(), tcase.res_len);
- rw_assert (match == cs.res_len, 0, cs.line,
+ rw_assert (match == tcase.res_len, 0, tcase.line,
"line %d. %{$FUNCALL} expected %{#*s}, "
"got %{/*.*Gs}, difference at offset %zu",
- __LINE__, int (cs.res_len), cs.res,
+ __LINE__, int (tcase.res_len), tcase.res,
int (sizeof (charT)), int (s_str.size ()),
s_str.c_str (), match);
}
@@ -350,28 +346,28 @@
catch (const std::length_error &ex) {
caught = exceptions [2];
- rw_assert (caught == expected, 0, cs.line,
+ rw_assert (caught == expected, 0, tcase.line,
"line %d. %{$FUNCALL} %{?}expected %s,%{:}"
"unexpectedly%{;} caught std::%s(%#s)",
__LINE__, 0 != expected, expected, caught, ex.what ());
}
catch (const std::bad_alloc &ex) {
caught = exceptions [3];
- rw_assert (-1 == cs.bthrow, 0, cs.line,
+ rw_assert (-1 == tcase.bthrow, 0, tcase.line,
"line %d. %{$FUNCALL} %{?}expected %s,%{:}"
"unexpectedly%{;} caught std::%s(%#s)",
__LINE__, 0 != expected, expected, caught, ex.what ());
}
catch (const std::exception &ex) {
caught = exceptions [4];
- rw_assert (0, 0, cs.line,
+ rw_assert (0, 0, tcase.line,
"line %d. %{$FUNCALL} %{?}expected %s,%{:}"
"unexpectedly%{;} caught std::%s(%#s)",
__LINE__, 0 != expected, expected, caught, ex.what ());
}
catch (...) {
caught = exceptions [0];
- rw_assert (0, 0, cs.line,
+ rw_assert (0, 0, tcase.line,
"line %d. %{$FUNCALL} %{?}expected %s,%{:}"
"unexpectedly%{;} caught %s",
__LINE__, 0 != expected, expected, caught);
@@ -387,22 +383,22 @@
// verify that an exception thrown during allocation
// didn't cause a change in the state of the object
- rw_assert (s_str.size () == size, 0, cs.line,
+ rw_assert (s_str.size () == size, 0, tcase.line,
"line %d: %{$FUNCALL}: size unexpectedly changed "
"from %zu to %zu after an exception",
__LINE__, size, s_str.size ());
- rw_assert (s_str.capacity () == capacity, 0, cs.line,
+ rw_assert (s_str.capacity () == capacity, 0, tcase.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,
+ rw_assert (s_str.begin () == begin, 0, tcase.line,
"line %d: %{$FUNCALL}: begin() unexpectedly "
"changed from after an exception by %d",
__LINE__, s_str.begin () - begin);
- if (-1 == cs.bthrow) {
+ if (-1 == tcase.bthrow) {
// increment to allow this call to operator new to succeed
// and force the next one to fail, and try calling the same
// function again
@@ -410,8 +406,8 @@
continue;
}
}
- else if (-1 != cs.bthrow) {
- rw_assert (caught == expected, 0, cs.line,
+ else if (-1 != tcase.bthrow) {
+ rw_assert (caught == expected, 0, tcase.line,
"line %d. %{$FUNCALL} %{?}expected %s, caught %s"
"%{:}unexpectedly caught %s%{;}",
__LINE__, 0 != expected, expected, caught, caught);
@@ -427,7 +423,7 @@
// at least one exception is thrown
rw_assert ( *pst->throw_at_calls_ [0] == std::size_t (-1)
|| throw_after,
- 0, cs.line,
+ 0, tcase.line,
"line %d: %{$FUNCALL}: failed to throw an expected exception",
__LINE__);
@@ -451,12 +447,6 @@
static int
run_test (int, char*[])
{
- if ('\0' == LSTR [0]) {
- // initialize LSTR
- for (std::size_t i = 0; i != sizeof LSTR - 1; ++i)
- LSTR [i] = 'x';
- }
-
static const StringMembers::Test
tests [] = {
@@ -484,7 +474,8 @@
{
return rw_test (argc, argv, __FILE__,
"lib.string.op+=",
- 0 /* no comment */, run_test,
+ 0 /* no comment */,
+ run_test,
"|-no-char_traits# "
"|-no-user_traits# "
"|-no-user_char# "
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=396965&r1=396964&r2=396965&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp (original)
+++ incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp Tue Apr 25 12:51:28 2006
@@ -42,30 +42,26 @@
#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
// disabled for compilers such as IBM VAC++ or MSVC
// that can't reliably replace the operators
-# include <rw_new.h>
-
+# include <rw_new.h> // for bad_alloc, replacement operator new
#else
-# include <new>
-
+# include <new> // for bad_alloc
#endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE
-#define ReplaceOverload StringMembers::OverloadId
#define Replace(which) StringMembers::replace_ ## which
-typedef StringMembers::TestCase TestCase;
-typedef StringMembers::Test Test;
-typedef StringMembers::Function MemFun;
+typedef StringMembers::OverloadId OverloadId;
+typedef StringMembers::TestCase TestCase;
+typedef StringMembers::Test Test;
+typedef StringMembers::Function MemFun;
/**************************************************************************/
// for convenience and brevity
-#define LSTR long_string
-#define LLEN long_string_len
+#define LSTR StringMembers::long_string
+#define LLEN StringMembers::long_string_len
// one half of the long_string length
-#define LPAR LLEN / 2
+#define LPAR (LLEN / 2)
-static const std::size_t long_string_len = 4096;
-static char long_string [long_string_len];
static const char* const exceptions[] = {
"unknown exception", "out_of_range", "length_error",
@@ -680,7 +676,7 @@
template <class charT, class Traits>
void test_replace (charT, Traits*,
- ReplaceOverload which,
+ OverloadId which,
const TestCase &tcase)
{
typedef std::allocator<charT> Allocator;
@@ -835,7 +831,7 @@
}
default:
- RW_ASSERT ("test logic error: unknown replace overload");
+ RW_ASSERT (!"logic error: unknown replace overload");
return;
}
@@ -980,12 +976,6 @@
static int
run_test (int, char*[])
{
- if ('\0' == LSTR [0]) {
- // initialize LSTR
- for (std::size_t i = 0; i != sizeof LSTR - 1; ++i)
- LSTR [i] = 'x';
- }
-
static const StringMembers::Test
tests [] = {
@@ -1020,7 +1010,8 @@
{
return rw_test (argc, argv, __FILE__,
"lib.string.replace",
- 0 /* no comment */, run_test,
+ 0 /* no comment */,
+ run_test,
"|-no-char_traits# "
"|-no-user_traits# "
"|-no-user_char# "