Martin Sebor wrote:
<>> Whoops, I just realized that I introduced these off-by-one errors
<>during the replacement of LLEN with the directive.
[...]
<>> Anton, could you please modify the rest of the tests to use these new
<>directives and the rw_expand() function instead of LSTR and rw_widen()?
Unfortunately, with your changes the replace test just fails on Windows.
The attached diff files contains my attempt to fix the problem.
The change log:
2006-05-10 Anton Pevtsov <[EMAIL PROTECTED]>
* char.cpp (rw_match): Fixed the bug with the expanded string
length.
* 21.string.replace.cpp (test_replace_range): Added res_len
paramter, fixed bug with incorrect expected result string
length.
(test_replace): Updated cal to test_replace_range, fixed bug
with agruments for the rw_match call.
I updated rw_match functions and the call to them in the replace test.
Now it works on Linux and works better on Windows.
But on Windows I still have problems with the end of a string (somewhere
in the test driver): it looks like there is no '\0' symbol there, but it
is expected.
I saw the same problem with empty strings for other tests, so I'll
investigate it.
It would be great if you take a look on the replace test on Windows.
What do you think about this?
I'll update the rest of the tests immediately after the fix of these
problems, ok?
<>
Martin Sebor wrote:
<>> PS FWIW, I've also fixed STDCXX-170 in my local tree but I'm not quite
<>ready to commit the (extensive) changes.
Great!
Thanks,
Anton Pevtsov
<>-----Original Message-----
From: Martin Sebor [mailto:[EMAIL PROTECTED]
Sent: Tuesday, May 09, 2006 05:28
To: [email protected]
Subject: Re: svn commit: r405254 -
/incubator/stdcxx/trunk/tests/strings/21.string.replace.cpp
[EMAIL PROTECTED] wrote:
Author: sebor
Date: Mon May 8 18:08:00 2006
New Revision: 405254
URL: http://svn.apache.org/viewcvs?rev=405254&view=rev
Log:
2006-05-08 Martin Sebor <[EMAIL PROTECTED]>
* replace.cpp: Replaced LSTR, LLEN, and LPAR in test cases with
strings containing the '<char>@<count>' directive(s). Corrected
errors in expected results involving said strings revealed by
the use of the more flexible/reliable directives.
Whoops, I just realized that I introduced these off-by-one errors during
the replacement of LLEN with the directive.
Anyway, the directive is much more flexible than working with the
hardcoded long string in that it allows us to encode an arbitrarily long
string consisting of arbitrary characters for each test case.
For example, we can easily express long complex strings such as:
{ "abc", 'd' repeats 1234 times, "efg", 'h' repeats 5678 times } by
encoding them as follows:
"[EMAIL PROTECTED]@5678".
Anton, could you please modify the rest of the tests to use these new
directives and the rw_expand() function instead of LSTR and rw_widen()?
Once we've converted them I would like to get rid of the long strings
and either remove rw_widen() or change it to behave like rw_expand().
Added more
test cases exercising self-referential modification.
(test_replace_range): Added arguments, simplified, documented.
(test_replace): Used the new rw_expand() instead of rw_widen(),
added (and disabled for now) checking for memory leaks.
Once I get memory leak detection working in the replace test we will
also need to change the rest of the tests to exercise the same.
Thanks!
Martin
PS FWIW, I've also fixed STDCXX-170 in my local tree but I'm not quite
ready to commit the (extensive) changes.
http://issues.apache.org/jira/browse/STDCXX-170
Index: char.cpp
===================================================================
--- char.cpp (revision 405653)
+++ char.cpp (working copy)
@@ -430,8 +430,10 @@
// see if the first string contains '@' and might need
// to be expanded (see rw_expand() for details)
if ( _RWSTD_SIZE_MAX == len && strchr (s1, '@')
- || _RWSTD_SIZE_MAX != len && memchr (s1, '@', len))
+ || _RWSTD_SIZE_MAX != len && memchr (s1, '@', len)) {
s1 = rw_expand (s1_buf, s1, len, &s1_len);
+ len = s1_len;
+ }
size_t n = 0;
@@ -562,8 +564,10 @@
// see if the first string contains '@' and might need
// to be expanded (see rw_expand() for details)
if ( _RWSTD_SIZE_MAX == len && strchr (s1, '@')
- || _RWSTD_SIZE_MAX != len && memchr (s1, '@', len))
+ || _RWSTD_SIZE_MAX != len && memchr (s1, '@', len)) {
s1 = rw_expand (s1_buf, s1, len, &s1_len);
+ len = s1_len;
+ }
typedef unsigned char UChar;
@@ -695,8 +699,10 @@
// see if the first string contains '@' and might need
// to be expanded (see rw_expand() for details)
if ( _RWSTD_SIZE_MAX == len && strchr (s1, '@')
- || _RWSTD_SIZE_MAX != len && memchr (s1, '@', len))
+ || _RWSTD_SIZE_MAX != len && memchr (s1, '@', len)) {
s1 = rw_expand (s1_buf, s1, len, &s1_len);
+ len = s1_len;
+ }
typedef unsigned char UChar;
Index: 21.string.replace.cpp
===================================================================
--- 21.string.replace.cpp (revision 405653)
+++ 21.string.replace.cpp (working copy)
@@ -261,7 +261,7 @@
static const TestCase
iter_iter_ptr_size_test_cases [] = {
-// iter_iter_range_test_cases serves a double duty
+// iter_iter_ptr_size_test_cases serves a double duty
#define size_size_ptr_size_test_cases iter_iter_ptr_size_test_cases
#undef TEST
@@ -486,7 +486,8 @@
TEST ("[EMAIL PROTECTED]", 0, 0, "[EMAIL PROTECTED]", 0, -1,
"a", 0),
TEST ("[EMAIL PROTECTED]", 0, 0, "[EMAIL PROTECTED]", 0, -1,
"ba", 0),
TEST ("[EMAIL PROTECTED]", 0, 0, "[EMAIL PROTECTED]", 0, -1,
"bbaa", 0),
- TEST ("[EMAIL PROTECTED]", 0, 0, "[EMAIL PROTECTED]", 0, -1,
"[EMAIL PROTECTED]@1000", 0),
+
+ TEST ("[EMAIL PROTECTED]", 0, 0, "[EMAIL PROTECTED]", 0, -1,
"[EMAIL PROTECTED]@1000", 0),
TEST ("[EMAIL PROTECTED]", 0, 1, "[EMAIL PROTECTED]", 0, -1,
"[EMAIL PROTECTED]@999", 0),
TEST ("[EMAIL PROTECTED]", 0, 2, "[EMAIL PROTECTED]", 0, -1,
"[EMAIL PROTECTED]@998", 0),
TEST ("[EMAIL PROTECTED]", 1, 998, "[EMAIL PROTECTED]", 0, -1,
"[EMAIL PROTECTED]", 0),
@@ -664,6 +665,7 @@
std::size_t wstr_len,
const charT* warg,
std::size_t warg_len,
+ std::size_t res_len,
Traits*,
const Iterator &it,
const TestCase &tcase)
@@ -723,7 +725,7 @@
// detrmine whether the produced sequence matches the exepceted result
const std::size_t match = rw_match (tcase.res, str.data (), tcase.nres);
- rw_assert (match == tcase.nres, 0, tcase.line,
+ rw_assert (match == res_len, 0, tcase.line,
"line %d. %{$FUNCALL} expected %{#*s}, got %{/*.*Gs}, "
"difference at offset %zu for %s",
__LINE__, int (tcase.nres), tcase.res,
@@ -738,6 +740,7 @@
std::size_t wstr_len,
const charT *warg,
std::size_t warg_len,
+ std::size_t res_len,
Traits*,
const TestCase &tcase)
{
@@ -748,7 +751,7 @@
// exercise InputIterator *or* string::iterator (i.e., self
// referential modification), depending on the value of tcase.arg
- test_replace_range (wstr, wstr_len, warg, warg_len, (Traits*)0,
+ test_replace_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0,
InputIter<charT>(0, 0, 0), tcase);
if (0 == tcase.arg) {
@@ -756,13 +759,13 @@
return;
}
- test_replace_range (wstr, wstr_len, warg, warg_len, (Traits*)0,
+ test_replace_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0,
ConstFwdIter<charT>(0, 0, 0), tcase);
- test_replace_range (wstr, wstr_len, warg, warg_len, (Traits*)0,
+ test_replace_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0,
ConstBidirIter<charT>(0, 0, 0), tcase);
- test_replace_range (wstr, wstr_len, warg, warg_len, (Traits*)0,
+ test_replace_range (wstr, wstr_len, warg, warg_len, res_len, (Traits*)0,
ConstRandomAccessIter<charT>(0, 0, 0), tcase);
}
@@ -789,9 +792,14 @@
charT* wstr = rw_expand (wstr_buf, tcase.str, tcase.str_len, &str_len);
charT* warg = rw_expand (warg_buf, tcase.arg, tcase.arg_len, &arg_len);
+ static charT wres_buf [BUFSIZE];
+ std::size_t res_len = sizeof wres_buf / sizeof *wres_buf;
+ charT* wres = rw_expand (wres_buf, tcase.res, tcase.nres, &res_len);
+
// special processing for replace_range to exercise all iterators
if (Replace (iter_iter_range) == which) {
- test_replace_range (wstr, str_len, warg, arg_len, (Traits*)0, tcase);
+ test_replace_range (wstr, str_len, warg, arg_len,
+ res_len, (Traits*)0, tcase);
if (wstr != wstr_buf)
delete[] wstr;
@@ -799,6 +807,9 @@
if (warg != warg_buf)
delete[] warg;
+ if (wres != wres_buf)
+ delete[] wres;
+
return;
}
@@ -816,10 +827,6 @@
wstr = 0;
warg = 0;
- static charT wres_buf [BUFSIZE];
- std::size_t res_len = sizeof wres_buf / sizeof *wres_buf;
- charT* wres = rw_expand (wres_buf, tcase.res, tcase.nres, &res_len);
-
// save the state of the string object before the call
// to detect wxception safety violations (changes to
// the state of the object after an exception)
@@ -898,6 +905,7 @@
delete[] wres;
return;
+ }
#endif // _RWSTD_NO_EXCEPTIONS
@@ -976,7 +984,7 @@
// (and only then), also verify that the modified
// string matches the expected result
const std::size_t match =
- rw_match (tcase.res, str.c_str (), res_len);
+ rw_match (tcase.res, str.c_str (), tcase.nres);
rw_assert (match == res_len, 0, tcase.line,
"line %d. %{$FUNCALL} expected %{/*.*Gs}, "