Author: sebor
Date: Tue Jan 24 18:04:22 2006
New Revision: 372077
URL: http://svn.apache.org/viewcvs?rev=372077&view=rev
Log:
2006-01-24 Martin Sebor <[EMAIL PROTECTED]>
* 25.replace.cpp (<cstdarg>, <cstdlib>, <printf.h>): Removed needless
#include directives.
(ToString): Removed.
(test_remove): Made sure the xsrc pointer is always dereferenceable
by allocating one more element than necessary under all circumstances.
Replaced %p formatting with the more descriptive offset from the
beginning of the sequence.
Removed the uses of the ToString template and used the %{X=...}
directive to directly format arrays of objects of type X.
Used the %#c extension to format characters to avoid producing
non-printable output (and format such characters using traditional
C escape sequences).
* 25.reverse.cpp: Same.
* 25.remove.cpp: Same.
* 25.rotate.cpp: Same.
Modified:
incubator/stdcxx/trunk/tests/algorithms/25.remove.cpp
incubator/stdcxx/trunk/tests/algorithms/25.replace.cpp
incubator/stdcxx/trunk/tests/algorithms/25.reverse.cpp
incubator/stdcxx/trunk/tests/algorithms/25.rotate.cpp
Modified: incubator/stdcxx/trunk/tests/algorithms/25.remove.cpp
URL:
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/algorithms/25.remove.cpp?rev=372077&r1=372076&r2=372077&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/algorithms/25.remove.cpp (original)
+++ incubator/stdcxx/trunk/tests/algorithms/25.remove.cpp Tue Jan 24 18:04:22
2006
@@ -20,13 +20,10 @@
**************************************************************************/
#include <algorithm> // for remove(), remove_copy(), ...
-#include <cstdarg> // va_list
-#include <cstdlib> // for free(), size_t
#include <cstring> // for strlen()
#include <alg_test.h>
-#include <driver.h> // for rw_test()
-#include <printf.h> // for rw_asnprintf()
+#include <driver.h> // for rw_test()
/**************************************************************************/
@@ -68,61 +65,6 @@
/**************************************************************************/
-const char nul_char = '\0';
-
-
-template <class T>
-class ToString
-{
-public:
- ToString (const T *first, const T *last, int pos, bool use_id = false)
- : str_ (0) {
-
- std::size_t buf_sz = 0;
-
- if (first > last) {
- rw_asnprintf (&str_, &buf_sz, "%s", "bad range");
- return;
- }
-
- char* res = (char*)&nul_char;
- char* tmp = 0;
-
- for (const T *cur = first; cur != last; ++cur) {
- rw_asnprintf (&tmp, &buf_sz,
- "%s%{?}>%{;}%{?}%d:%{;}%{lc}%{?}<%{;}",
- res,
- cur - first == pos, // '>'
- use_id, cur->id_, // "<id>:"
- cur->val_, // <val>
- cur - first == pos); // '<'
-
- if (res != &nul_char)
- std::free (res);
-
- res = tmp;
- tmp = 0;
- }
-
- str_ = res;
- }
-
- ~ToString () {
- if (str_ != &nul_char)
- std::free (str_);
- }
-
- operator const char* () const {
- return str_;
- }
-
-private:
-
- char* str_;
-};
-
-/**************************************************************************/
-
// names of tested functions
const char* const fnames[] = { "remove", "remove_copy" };
const char* const fnames_if[] = { "remove_if", "remove_copy_if" };
@@ -200,7 +142,7 @@
const std::size_t nsrc = std::strlen (src);
// construct a sequence of `nsrc' elements to pass to remove
- T* const xsrc = T::from_char (src, nsrc);
+ T* const xsrc = T::from_char (src, nsrc + 1);
// construct an element to remove
T to_remove;
@@ -218,7 +160,7 @@
make_iter (xsrc + nsrc, xsrc, xsrc + nsrc, Iterator ());
// zero out predicate counters
- T::n_total_op_eq_ = 0;
+ T::n_total_op_eq_ = 0;
// call remove() or remove_if()
const Iterator end = tag.use_predicate
@@ -232,9 +174,9 @@
// verify that the returned iterator is set as expected
bool success = end.cur_ == first.cur_ + (nsrc - nrem);
rw_assert (success, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') == %p, "
- "got %p", __LINE__, fname, itname, src, val,
- first.cur_ + (nsrc - nrem), end.cur_);
+ "line %d: %s<%s>(\"%s\", ..., %#c) == first + %zu, got %zd",
+ __LINE__, fname, itname, src, val,
+ nsrc - nrem, end.cur_ - xsrc);
// verify that the value to be removed does not appear
// anywhere in the range [first, end) : p 25.2.7.2
@@ -246,11 +188,10 @@
}
rw_assert (success, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') ==> \"%s\"; "
- "expected element value '%c'",
+ "line %d: %s<%s>(\"%s\", ..., %#c) ==> "
+ "\"%{X=*.*}\"; expected element value %#c",
__LINE__, fname, itname, src, val,
- (const char*) ToString<T>(xsrc, xsrc + nsrc, i),
- UChar (src [i]));
+ int (nsrc), int (i), xsrc, src [i]);
// verify that the algorithm is stable: the relative order of the elements
// that are not removed remains unchanged : p 25.2.7.4
@@ -262,10 +203,10 @@
}
rw_assert (success, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') ==> \"%s\"; "
- "unstable at offset %d element ids: %d and %d",
+ "line %d: %s<%s>(\"%s\", ..., %#c) ==> \"%{X=#*.*}\"; "
+ "unstable at offset %zu element ids: %d and %d",
__LINE__, fname, itname, src, val,
- (const char*) ToString<T>(xsrc, xsrc + nsrc, i - 1, true),
+ int (nsrc), int (i - 1), xsrc,
i - 1, xsrc [i - 1].id_, xsrc [i].id_);
// verify that the values of elements in the range [end, last)
@@ -278,23 +219,22 @@
}
rw_assert (success, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') ==> \"%s\"; "
- "expected element value '%c'",
+ "line %d: %s<%s>(\"%s\", ..., %#c) ==> "
+ "\"%{X=*.*}\"; expected element value %#c",
__LINE__, fname, itname, src, val,
- (const char*) ToString<T>(xsrc, xsrc + nsrc, i),
- UChar (val));
+ int (nsrc), int (i), xsrc, val);
// verify the number of applications of the predicate: p 25.2.7.5
if (tag.use_predicate) {
rw_assert (pred.funcalls_ == nsrc, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') called "
+ "line %d: %s<%s>(\"%s\", ..., %#c) called "
"Predicate::operator() %zu times, %zu expected",
__LINE__, fname, itname, src, val,
pred.funcalls_, nsrc);
}
else {
rw_assert (T::n_total_op_eq_ == nsrc, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') called "
+ "line %d: %s<%s>(\"%s\", ..., %#c) called "
"T::operator< %zu times, %zu expected",
__LINE__, fname, itname, src, val,
T::n_total_op_eq_, nsrc);
@@ -327,9 +267,7 @@
const Predicate pred (to_remove, 0);
const Iterator first = make_iter (xsrc, xsrc, xsrc + nsrc, it);
-
const Iterator last = make_iter (xsrc + nsrc, xsrc, xsrc + nsrc, it);
-
const OutputIterator result = make_iter (xdst, xdst, xdst + nsrc, dummy);
// zero out predicate counters
@@ -346,9 +284,8 @@
// verify that the returned iterator is set as expected p 25.2.7.8
bool success = end.cur_ == result.cur_ + (nsrc - nrem);
rw_assert (success, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') == %p, "
- "got %p", __LINE__, fname, itname, src, val,
- first.cur_ + (nsrc - nrem), end.cur_);
+ "line %d: %s<%s>(\"%s\", ..., %#c) == first + %zu, got %zd",
+ __LINE__, fname, itname, src, val, nsrc - nrem, end.cur_ -
xsrc);
// verify that the value to be removed does not appear anywhere
// in the range [result, end)
@@ -360,11 +297,11 @@
}
rw_assert (success, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') ==> \"%s\"; "
- "expected element value '%c'",
+ "line %d: %s<%s>(\"%s\", ..., %#c) ==> "
+ "\"%{X=*.*}\"; expected element value %#c",
__LINE__, fname, itname, src, val,
- (const char*) ToString<T>(xdst, xdst + nsrc - nrem, i),
- UChar (src [i]));
+ int (nsrc - nrem), int (i), xdst,
+ src [i]);
// verify that the algorithm is stable: the relative order of the elements
// that are not removed remains unchanged : p 25.2.7.10
@@ -376,23 +313,23 @@
}
rw_assert (success, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') ==> \"%s\"; "
- "unstable at offset %d: element ids: %d and %d",
+ "line %d: %s<%s>(\"%s\", ..., %#c) ==> "
+ "\"%{X=#*.*}\"; unstable at offset %zu: element ids: %d and %d",
__LINE__, fname, itname, src, val,
- (const char*)ToString<T>(xdst, xdst + nsrc - nrem, i-1, true),
+ int (nsrc - nrem), int (i - 1), xdst,
i - 1, xdst [i - 1].id_, xdst [i].id_);
// verify the number of applications of the predicate p 25.2.7.9
if (tag.use_predicate) {
rw_assert (pred.funcalls_ == nsrc, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') called "
+ "line %d: %s<%s>(\"%s\", ..., %#c) called "
"Predicate::operator() %zu times, %zu expected",
__LINE__, fname, itname, src, val,
pred.funcalls_, nsrc);
}
else {
rw_assert (T::n_total_op_eq_ == nsrc, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') called "
+ "line %d: %s<%s>(\"%s\", ..., %#c) called "
"T::operator< %zu times, %zu expected",
__LINE__, fname, itname, src, val,
T::n_total_op_eq_, nsrc);
@@ -415,16 +352,16 @@
if (tag.fname_inx) { // remove_copy(), remove_copy_if()
rw_info (0, 0, 0,
- "std::%s (%s, %s, %s, %s)",
+ "std::%s (%s, %2$s, %s, %s)",
tag.use_predicate ? "remove_copy_if" : "remove_copy",
- it1name, it1name, it2name,
+ it1name, it2name,
tag.use_predicate ? "UnaryPredicate" : "const T&");
}
else { // remove, remove_if()
rw_info (0, 0, 0,
- "std::%s (%s, %s, %s)",
+ "std::%s (%s, %2$s, %s)",
tag.use_predicate ? "remove_if" : "remove",
- it1name, it1name,
+ it1name,
tag.use_predicate ? "UnaryPredicate" : "const T&");
}
@@ -482,11 +419,11 @@
void test_remove (const T*, const Predicate* pred, Tag tag)
{
rw_info (0, 0, 0,
- "template <class ForwardIterator, class T> "
- "std::%s (ForwardIterator, ForwardIterator, "
- "%s)",
- tag.use_predicate ? "remove_if" : "remove",
- tag.use_predicate ? "Predicate" : "const T&");
+ "template <class %s, class T> "
+ "std::%s (%1$s, %1$s, %s)",
+ "ForwardIterator",
+ tag.use_predicate ? "remove_if" : "remove",
+ tag.use_predicate ? "Predicate" : "const T&");
if (rw_opt_no_fwd_iter) {
rw_note (0, __FILE__, __LINE__, "ForwardIterator test disabled");
@@ -621,7 +558,7 @@
const RemoveCopyTag remove_copy_if_tag = { true };
if (rw_opt_no_remove_copy) {
- rw_note (0, __FILE__, __LINE__, "std::remove_copy test disabled");
+ rw_note (0, __FILE__, __LINE__, "std::remove_copy test disabled");
}
else {
const EqualityPredicate<T>* const pred = (EqualityPredicate<T>*) 0;
@@ -629,7 +566,7 @@
}
if (rw_opt_no_remove_copy_if) {
- rw_note (0, __FILE__, __LINE__, "std::remove_copy_if test disabled");
+ rw_note (0, __FILE__, __LINE__, "std::remove_copy_if test disabled");
}
else {
const EqualityPredicate<T>* const pred = (EqualityPredicate<T>*) 1;
Modified: incubator/stdcxx/trunk/tests/algorithms/25.replace.cpp
URL:
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/algorithms/25.replace.cpp?rev=372077&r1=372076&r2=372077&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/algorithms/25.replace.cpp (original)
+++ incubator/stdcxx/trunk/tests/algorithms/25.replace.cpp Tue Jan 24 18:04:22
2006
@@ -20,12 +20,10 @@
**************************************************************************/
#include <algorithm> // for replace(), replace_copy()
-#include <cstring> // for strlen()
-#include <cstdlib> // for free(), size_t
+#include <cstring> // for size_t, strlen()
#include <alg_test.h>
#include <driver.h> // for rw_test()
-#include <printf.h> // for rw_asnprintf()
/**************************************************************************/
@@ -92,62 +90,6 @@
return 0;
}
-typedef unsigned char UChar;
-
-/**************************************************************************/
-
-const char nul_char = '\0';
-
-template <class T>
-class ToString
-{
-public:
- ToString (const T *first, const T *last, int pos, bool use_id = false)
- : str_ (0) {
-
- std::size_t buf_sz = 0;
-
- if (first > last) {
- rw_asnprintf (&str_, &buf_sz, "%s", "bad range");
- return;
- }
-
- char* res = (char*)&nul_char;
- char* tmp = 0;
-
- for (const T *cur = first; cur != last; ++cur) {
- rw_asnprintf (&tmp, &buf_sz,
- "%s%{?}>%{;}%{?}%d:%{;}%{lc}%{?}<%{;}",
- res,
- cur - first == pos, // '>'
- use_id, cur->id_, // "<id>:"
- cur->val_, // <val>
- cur - first == pos); // '<'
-
- if (res != &nul_char)
- std::free (res);
-
- res = tmp;
- tmp = 0;
- }
-
- str_ = res;
- }
-
- ~ToString () {
- if (str_ != &nul_char)
- std::free (str_);
- }
-
- operator const char* () const {
- return str_;
- }
-
-private:
-
- char* str_;
-};
-
/**************************************************************************/
// predicate used as an argument to replace_if() and replace_copy_if()
@@ -247,11 +189,10 @@
}
rw_assert (success, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c', '%c') ==> \"%s\"; "
- "unexpected element value %c",
+ "line %d: %s<%s>(\"%s\", ..., %#c, %#c) ==> "
+ "\"%{X=*.*}\"; unexpected element value %#c",
__LINE__, fname, itname, src, val, new_val,
- (const char*) ToString<T>(xsrc, xsrc_end, i),
- src [i]);
+ int (nsrc), int (i), xsrc, src [i]);
// check the id (not just the value) of the matching element
// to make sure it has really been replaced
@@ -267,25 +208,25 @@
}
rw_assert (success, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c', '%c') ==> \"%s\"; "
- "failed to replace element %zu: "
+ "line %d: %s<%s>(\"%s\", ..., %#c, %#c) ==> "
+ "\"%{X=#*.*}\"; failed to replace element %zu: "
"origin %d (%d, %d), expected %d (%d)",
__LINE__, fname, itname, src, val, new_val,
- (const char*)ToString<T>(xsrc, xsrc_end, i),
+ int (nsrc), int (i), xsrc,
i, xsrc [i].origin_, xsrc [i].id_, xsrc [i].src_id_,
replace_with.origin_, replace_with.id_);
// verify the number of applications of the predicate: p 25.2.4.3
if (tag.use_predicate) {
rw_assert (pred.funcalls_ == nsrc, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') called "
+ "line %d: %s<%s>(\"%s\", ..., %#c) called "
"Predicate::operator() %zu times, %zu expected",
__LINE__, fname, itname, src, val,
pred.funcalls_, nsrc);
}
else {
rw_assert (T::n_total_op_eq_ == nsrc, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') called "
+ "line %d: %s<%s>(\"%s\", ..., %#c) called "
"T::operator< %zu times, %zu expected",
__LINE__, fname, itname, src, val,
T::n_total_op_eq_, nsrc);
@@ -346,25 +287,25 @@
// verify that the returned iterator is set as expected
rw_assert (end.cur_ == result.cur_ + nsrc, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') == %p, "
- "got %p", __LINE__, fname, itname, src, val,
- first.cur_ + nsrc, end.cur_);
+ "line %d: %s<%s>(\"%s\", ..., %#c) == result + %zu, got %td",
+ __LINE__, fname, itname, src, val, nsrc, end.cur_ - xdst);
// verify that the value to be replaced does not appear anywhere
// in the range [result, end)
bool success = true;
std::size_t i = 0;
for ( ; i != nsrc; ++i) {
+ typedef unsigned char UChar;
success = UChar (val) != xdst [i].val_;
if (!success)
break;
}
rw_assert (success, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') ==> \"%s\"; "
- "unexpected element value %c",
+ "line %d: %s<%s>(\"%s\", ..., %#c) ==> "
+ "\"%{X=*.*}\"; unexpected element value %#c",
__LINE__, fname, itname, src, val,
- (const char*)ToString<T>(xdst, xdst_end, i), src [i]);
+ int (nsrc), int (i), xdst, src [i]);
// check the id (not just the value) of the matching element
// to make sure it has really been copied
@@ -379,25 +320,25 @@
}
rw_assert (success, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c', '%c') ==> \"%s\"; "
- "failed to copy and replace element %zu: "
+ "line %d: %s<%s>(\"%s\", ..., %#c, %#c) ==> "
+ "\"%{X=*.*}\"; failed to copy and replace element %zu: "
"origin %d (%d, %d), expected %d (%d)",
__LINE__, fname, itname, src, val, new_val,
- (const char*)ToString<T>(xdst, xdst_end, i),
+ int (nsrc), int (i), xdst,
i, xdst [i].origin_, xdst [i].id_, xdst [i].src_id_,
replace_with.origin_, replace_with.id_);
// verify the number of applications of the predicate: p 25.2.4.7
if (tag.use_predicate) {
rw_assert (pred.funcalls_ == nsrc, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') called "
+ "line %d: %s<%s>(\"%s\", ..., %#c) called "
"Predicate::operator() %zu times, %zu expected",
__LINE__, fname, itname, src, val,
pred.funcalls_, nsrc);
}
else {
rw_assert (T::n_total_op_eq_ == nsrc, 0, line,
- "line %d: %s<%s>(\"%s\", ..., '%c') called "
+ "line %d: %s<%s>(\"%s\", ..., %#c) called "
"T::operator< %zu times, %zu expected",
__LINE__, fname, itname, src, val,
T::n_total_op_eq_, nsrc);
Modified: incubator/stdcxx/trunk/tests/algorithms/25.reverse.cpp
URL:
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/algorithms/25.reverse.cpp?rev=372077&r1=372076&r2=372077&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/algorithms/25.reverse.cpp (original)
+++ incubator/stdcxx/trunk/tests/algorithms/25.reverse.cpp Tue Jan 24 18:04:22
2006
@@ -20,12 +20,10 @@
**************************************************************************/
#include <algorithm> // for reverse, reverse_copy
-#include <cstring> // for strlen
-#include <cstdlib> // for size_t, free
+#include <cstring> // for size_t, strlen()
#include <alg_test.h>
#include <driver.h> // for rw_test()
-#include <printf.h> // for rw_asnprintf()
/**************************************************************************/
@@ -70,63 +68,6 @@
return 0;
}
-
-typedef unsigned char UChar;
-
-/**************************************************************************/
-
-const char nul_char = '\0';
-
-template <class T>
-class ToString
-{
-public:
- ToString (const T *first, const T *last, int pos, bool use_id = false)
- : str_ (0) {
-
- std::size_t buf_sz = 0;
-
- if (first > last) {
- rw_asnprintf (&str_, &buf_sz, "%s", "bad range");
- return;
- }
-
- char* res = (char*)&nul_char;
- char* tmp = 0;
-
- for (const T *cur = first; cur != last; ++cur) {
- rw_asnprintf (&tmp, &buf_sz,
- "%s%{?}>%{;}%{?}%d:%{;}%{lc}%{?}<%{;}",
- res,
- cur - first == pos, // '>'
- use_id, cur->id_, // "<id>:"
- cur->val_, // <val>
- cur - first == pos); // '<'
-
- if (res != &nul_char)
- std::free (res);
-
- res = tmp;
- tmp = 0;
- }
-
- str_ = res;
- }
-
- ~ToString () {
- if (str_ != &nul_char)
- std::free (str_);
- }
-
- operator const char* () const {
- return str_;
- }
-
-private:
-
- char* str_;
-};
-
/**************************************************************************/
unsigned iter_swap_calls;
@@ -193,22 +134,24 @@
// done by swapping elements i.e., not simply by copying them over
for ( ; i != nsrc; ++i) {
+ typedef unsigned char UChar;
+
success = UChar (src [i]) == xsrc [nsrc - i - 1].val_;
if (!success)
break;
}
rw_assert (success, 0, line,
- "line %d: %s<%s>(%s, ...) ==> %s; "
- "unexpected element value %c at %zu",
+ "line %d: %s<%s>(\"%s\", ...) ==> "
+ "\"%{X=*.*}\"; unexpected element value %#c at offset %zu",
__LINE__, fname, itname, src,
- (const char*)ToString<T>(xsrc, xsrc + nsrc, i),
+ int (nsrc), int (i), xsrc,
xsrc [nsrc - i - 1].val_, i);
const std::size_t iter_swap_expect = nsrc / 2;
success = iter_swap_calls == iter_swap_expect;
rw_assert (success, 0, line,
- "line %d: %s<%s>(%s, ...); called iter_swap() "
+ "line %d: %s<%s>(\"%s\", ...); called iter_swap() "
"%zu times, %zu expected",
__LINE__, fname, itname, src,
iter_swap_calls, iter_swap_expect);
@@ -245,29 +188,30 @@
// verify that the returned iterator is set as expected
bool success = end.cur_ == result.cur_ + nsrc;
rw_assert (success, 0, line,
- "line %d: %s<%s>(\"%s\", ...) == %p, "
- "got %p", __LINE__, fname, itname, src,
- first.cur_ + nsrc, end.cur_);
+ "line %d: %s<%s>(\"%s\", ...) == result + %zu, got %td",
+ __LINE__, fname, itname, src, nsrc, end.cur_ - xdst);
// verify that the sequence was correctly reversed
std::size_t i = 0;
for ( ; i != nsrc; ++i) {
+ typedef unsigned char UChar;
+
success = UChar (src [i]) == xdst [nsrc - i - 1].val_;
if (!success)
break;
}
rw_assert (success, 0, line,
- "line %d: %s<%s>(%s, ...) ==> %s "
- "unexpected element value %c at %zu",
+ "line %d: %s<%s>(\"%s\", ...) ==> "
+ "\"%{X=*.*}\"; unexpected element value %#c at offset %zu",
__LINE__, fname, itname, src,
- (const char*) ToString<T> (xsrc, xsrc + nsrc, i),
+ int (nsrc), int (i), xsrc,
xdst [nsrc - i - 1].val_, i);
success = T::n_total_op_assign_ - last_n_op_assign == nsrc;
rw_assert (success, 0, line,
- "line %d: %s<%s>(%s, ...); called operator=() "
+ "line %d: %s<%s>(\"%s\", ...); called operator=() "
"%zu times, %zu expected",
__LINE__, fname, itname, src,
T::n_total_op_assign_ - last_n_op_assign, nsrc);
Modified: incubator/stdcxx/trunk/tests/algorithms/25.rotate.cpp
URL:
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/algorithms/25.rotate.cpp?rev=372077&r1=372076&r2=372077&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/algorithms/25.rotate.cpp (original)
+++ incubator/stdcxx/trunk/tests/algorithms/25.rotate.cpp Tue Jan 24 18:04:22
2006
@@ -20,12 +20,11 @@
**************************************************************************/
#include <algorithm> // for rotate, rotate_copy
-#include <cstring> // for strlen
-#include <cstdlib> // for size_t, free
+#include <cstring> // for size_t, strlen()
#include <alg_test.h>
#include <driver.h> // for rw_test()
-#include <printf.h> // for rw_asnprintf()
+
_RWSTD_NAMESPACE (std) {
@@ -72,62 +71,6 @@
}
-typedef unsigned char UChar;
-
-/**************************************************************************/
-
-const char nul_char = '\0';
-
-template <class T>
-class ToString
-{
-public:
- ToString (const T *first, const T *last, int pos, bool use_id = false)
- : str_ (0) {
-
- std::size_t buf_sz = 0;
-
- if (first > last) {
- rw_asnprintf (&str_, &buf_sz, "%s", "bad range");
- return;
- }
-
- char* res = (char*)&nul_char;
- char* tmp = 0;
-
- for (const T *cur = first; cur != last; ++cur) {
- rw_asnprintf (&tmp, &buf_sz,
- "%s%{?}>%{;}%{?}%d:%{;}%{lc}%{?}<%{;}",
- res,
- cur - first == pos, // '>'
- use_id, cur->id_, // "<id>:"
- cur->val_, // <val>
- cur - first == pos); // '<'
-
- if (res != &nul_char)
- std::free (res);
-
- res = tmp;
- tmp = 0;
- }
-
- str_ = res;
- }
-
- ~ToString () {
- if (str_ != &nul_char)
- std::free (str_);
- }
-
- operator const char* () const {
- return str_;
- }
-
-private:
-
- char* str_;
-};
-
/**************************************************************************/
unsigned iter_swap_calls;
@@ -210,17 +153,19 @@
for ( ; i != nsrc; ++i) {
xpos = (i + (nsrc - midnsrc)) % nsrc;
+
+ typedef unsigned char UChar;
+
success = UChar (src [i]) == xsrc [xpos].val_;
if (!success)
break;
}
rw_assert (success, 0, line,
- "line %d: %s<%s>(\"%s\", %zu, ...) ==> %s; "
- "unexpected element value %c at %zu",
+ "line %d: %s<%s>(\"%s\", %zu, ...) ==> "
+ "\"%{X=*.*}\"; unexpected element value %#c at %zu",
__LINE__, fname, itname, src, midnsrc,
- (const char*) ToString<T> (xsrc, xsrc + nsrc, i),
- xsrc [xpos].val_, i);
+ int (nsrc), int (i), xsrc, xsrc [xpos].val_, i);
success = iter_swap_calls <= nsrc;
rw_assert (success, 0, line,
@@ -264,10 +209,9 @@
// verify that the returned iterator is set as expected
bool success = end.cur_ == result.cur_ + nsrc;
rw_assert (success, 0, line,
- "line %d: %s<%s, %s>(\"%s\", %zu, ...) == %p, "
- "got %p", __LINE__, fname,
- it1name, it2name, src, midnsrc,
- first.cur_ + nsrc, end.cur_);
+ "line %d: %s<%s, %s>(\"%s\", %zu, ...) == result + %zu, got
%td",
+ __LINE__, fname, it1name, it2name, src, midnsrc,
+ nsrc, end.cur_ - xdst);
// verify that the sequence was correctly rotated
std::size_t i = 0;
@@ -275,17 +219,19 @@
for ( ; i != nsrc; ++i) {
xpos = (i + (nsrc - midnsrc)) % nsrc;
+
+ typedef unsigned char UChar;
+
success = UChar (src [i]) == xdst [xpos].val_;
if (!success)
break;
}
rw_assert (success, 0, line,
- "line %d: %s<%s, %s>(\"%s\", %zu, ...) ==> %s "
- "unexpected element value %c at %zu",
+ "line %d: %s<%s, %s>(\"%s\", %zu, ...) ==> "
+ "\"%{X=*.*}\"; unexpected element value %#c at %zu",
__LINE__, fname, it1name, it2name, src, midnsrc,
- (const char*) ToString<T> (xsrc, xsrc + nsrc, i),
- xdst [xpos].val_, i);
+ int (nsrc), int (i), xsrc, xdst [xpos].val_, i);
success = T::n_total_op_assign_ - last_n_op_assign == nsrc;
rw_assert (success, 0, line,