Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 71883 invoked from network); 25 Apr 2006 15:14:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 25 Apr 2006 15:14:46 -0000 Received: (qmail 19965 invoked by uid 500); 25 Apr 2006 15:14:35 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 19892 invoked by uid 500); 25 Apr 2006 15:14:34 -0000 Mailing-List: contact stdcxx-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-dev@incubator.apache.org Received: (qmail 19808 invoked by uid 99); 25 Apr 2006 15:14:34 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Apr 2006 08:14:34 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of AntonP@moscow.vdiweb.com designates 195.210.189.132 as permitted sender) Received: from [195.210.189.132] (HELO exmsk.moscow.vdiweb.com) (195.210.189.132) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Apr 2006 08:14:32 -0700 Received: from [10.11.0.132] ([10.11.0.132]) by exmsk.moscow.vdiweb.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 25 Apr 2006 19:14:05 +0400 Message-ID: <444E3CDF.6060806@moscow.vdiweb.com> Date: Tue, 25 Apr 2006 19:14:39 +0400 From: Anton Pevtsov User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040514 X-Accept-Language: en-us, en MIME-Version: 1.0 To: stdcxx-dev@incubator.apache.org Subject: Re: Re: svn commit: r396754 - /incubator/stdcxx/trunk/tests/strings/21.string.append.cpp Content-Type: multipart/mixed; boundary="------------060409030407060603050104" X-OriginalArrivalTime: 25 Apr 2006 15:14:05.0533 (UTC) FILETIME=[E47CF0D0:01C6687A] X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --------------060409030407060603050104 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit The updated version of the replace test (diff file) is attached. There is a limit in 100Kb length of the mail, so I send this test separately. 2006-04-25 Anton Pevtsov * 21.string.replace.cpp (exceptions): Added elements and renamed from exp_exceptions for clarity. (size_size_ptr_test_cases, size_size_str_test_cases, etc): Merged with equal iterator version arrays. (test_exceptions): Merged the body of the function into the test_assign function and removed the declaration of the former. (test_replace): Exercised both the function exception safety and the behavior of the function under normal conditions. Thanks, Anton Pevtsov PS. What's happened with the repository? I cann't access it... -----Original Message----- From: Martin Sebor [mailto:sebor@roguewave.com] Sent: Tuesday, April 25, 2006 05:47 To: stdcxx-dev@incubator.apache.org Subject: Re: svn commit: r396754 - /incubator/stdcxx/trunk/tests/strings/21.string.append.cpp sebor@apache.org wrote: >> Author: sebor >> Date: Mon Apr 24 18:32:10 2006 >> New Revision: 396754 >> >> URL: http://svn.apache.org/viewcvs?rev=396754&view=rev >> Log: >> 2006-04-24 Martin Sebor >> >> * 21.string.append.cpp (exceptions): Added elements and renamed >> from exp_exceptions for clarity. >> (test_exceptions): Merged the body of the function into the >> test_append function and removed the declaration of the former. >> (test_append_range): Constified locals wherever appropriate >> and introduced new helper variables to simplify expressions. >> (test_append): Exercised both the function exception safety >> and the behavior of the function under normal conditions. > > Hey Anton, this change eliminates code duplication between the test_exceptions() and test_append() functions. Could you please incorporate it into all new tests? Also, when you have a chance, it would be good to go back to the existing tests and do the same thing there as well. Btw., after this change the test fails 6 assertions, all on line 336, one for each specialization of the test template (see below). I'm having trouble understanding that test case. What is the meaning of the expected result (the TestCase::res member) being null? (I don't think the case was being handled in the test prior to the change which is why I suspect the test had been passing.) # ASSERTION (S7) (4 lines): # TEXT: line 609. std::string ({ 'x' }).append (*this, 0, 0) expected (null), length 3, got { 'x' }, length 4095 # CLAUSE: lib.string.append # LINE: 336 Martin PS Btw., shouldn't this test fail for the same reason as the replace test does, i.e., because of STDCXX-170: http://issues.apache.org/jira/browse/STDCXX-170 --------------060409030407060603050104 Content-Type: text/plain; name="21.strings.replace.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="21.strings.replace.diff" Index: 21.string.replace.cpp =================================================================== --- 21.string.replace.cpp (revision 396882) +++ 21.string.replace.cpp (working copy) @@ -43,6 +43,10 @@ // disabled for compilers such as IBM VAC++ or MSVC // that can't reliably replace the operators # include + +#else +# include + #endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE #define ReplaceOverload StringMembers::OverloadId @@ -63,109 +67,22 @@ static const std::size_t long_string_len = 4096; static char long_string [long_string_len]; -static const char* const exp_exceptions[] = - { "unknown exception", "out_of_range", "length_error" }; - -/**************************************************************************/ - -// used to exercise -// replace (size_type, size_type, const value_type*) -static const TestCase -size_size_ptr_test_cases [] = { - -#undef TEST -#define TEST(str, off, size, arg, res, bthrow) { \ - __LINE__, off, size, -1, -1, -1, \ - str, sizeof str - 1, \ - arg, sizeof arg - 1, res, sizeof res - 1, bthrow \ - } - - // +------------------------------------------ controlled sequence - // | +----------------------------- replace() pos1 argument - // | | +-------------------------- replace() n1 argument - // | | | +----------------------- sequence to be inserted - // | | | | +----------- expected result sequence - // | | | | | +-- exception info - // | | | | | | 0 - no exception - // | | | | | | 1,2 - out_of_range - // | | | | | | 3 - length_error - // | | | | | | -1 - exc. safety - // | | | | | | - // | | | | | +-------+ - // V V V V V V - TEST ("ab", 0, 0, "c", "cab", 0), - - TEST ("", 0, 0, "", "", 0), - TEST ("", 0, 0, "abc", "abc", 0), - - TEST ("ab", 0, 2, "", "", 0), - TEST ("ab", 0, 1, "", "b", 0), - - TEST ("\0", 0, 1, "", "", 0), - TEST ("\0", 0, 1, "a", "a", 0), - TEST ("\0", 0, 1, "\0\0", "", 0), - - TEST ("ah", 0, 1, "bcdefg", "bcdefgh", 0), - TEST ("ah", 1, 1, "bcdefg", "abcdefg", 0), - TEST ("ah", 0, 2, "bcdefg", "bcdefg", 0), - - TEST ("abc", 0, 2, "cc", "ccc", 0), - TEST ("abc", 1, 2, "cc", "acc", 0), - - TEST ("abc", 0, 3, "defgh", "defgh", 0), - TEST ("abc", 2, 1, "defgh", "abdefgh", 0), - TEST ("abc", 2, 1, "de\0gh", "abde", 0), - TEST ("abc", 2, 1, "", "ab", 0), - TEST ("abc", 1, 1, "defgh", "adefghc", 0), - - TEST ("abc", 0, 0, "ee", "eeabc", 0), - TEST ("abc", 0, 0, "\0\0e\0", "abc", 0), - TEST ("abc", 2, 0, "ee", "abeec", 0), - TEST ("abc", 1, 0, "ee", "aeebc", 0), - TEST ("abc", 1, 0, "e\0\0", "aebc", 0), - - TEST ("a\0b\0\0c", 0, 3, "", "\0\0c", 0), - TEST ("a\0b\0\0c", 0, 3, "\0e", "\0\0c", 0), - - TEST ("\0ab\0\0c", 0, 0, "e\0", "e\0ab\0\0c", 0), - TEST ("a\0b\0c\0", 6, 0, "e\0", "a\0b\0c\0e", 0), - TEST ("\0ab\0\0c", 5, 0, "e\0", "\0ab\0\0ec", 0), - - TEST (LSTR, 0, LLEN - 1, "ab", "ab", 0), - TEST (LSTR, 1, LLEN - 2, "ab", "xab", 0), - TEST (LSTR, 0, LLEN - 2, "ab", "abx", 0), - TEST (LSTR, 1, LLEN - 3, "", "xx", 0), - - TEST ("", 0, 0, LSTR, LSTR, 0), - TEST ("a", 0, 1, LSTR, LSTR, 0), - TEST (LSTR, 0, LLEN - 1, LSTR, LSTR, 0), - TEST ("\0ab\0\0c", 0, 6, LSTR, LSTR, 0), - - TEST ("", 0, 0, 0, "", 0), - TEST ("abc", 0, 3, 0, "abc", 0), - TEST ("abc", 1, 1, 0, "aabcc", 0), - TEST ("a\0b\0c\0", 2, 3, 0, "a\0a\0", 0), - TEST ("a\0b\0c\0", 0, 0, 0, "aa\0b\0c\0", 0), - TEST ("a\0b\0c\0", 6, 0, 0, "a\0b\0c\0a", 0), - TEST ("\0ab\0c\0", 3, 3, 0, "\0ab", 0), - TEST (LSTR, 0, LLEN - 1, 0, LSTR, 0), - - TEST ("\0", 2, 0, "", "\0", 1), - TEST ("a", 10, 0, "", "a", 1), - TEST (LSTR, LLEN + 10, 0, "", LSTR, 1), - - TEST ("", 0, 0, LSTR, LSTR, -1), - - TEST ("last", 4, 0, "test", "lasttest", 0) +static const char* const exceptions[] = { + "unknown exception", "out_of_range", "length_error", + "bad_alloc", "exception" }; /**************************************************************************/ // used to exercise +// replace (size_type, size_type, const value_type*) // replace (iterator, iterator, const value_type*) static const TestCase iter_iter_ptr_test_cases [] = { +// iter_iter_ptr_test_cases serves a double duty +#define size_size_ptr_test_cases iter_iter_ptr_test_cases + #undef TEST #define TEST(str, off, size, arg, res, bthrow) { \ __LINE__, off, size, -1, -1, -1, \ @@ -256,108 +173,13 @@ // used to exercise // replace (size_type, size_type, const basic_string&) -static const TestCase -size_size_str_test_cases [] = { - -#undef TEST -#define TEST(str, off, size, arg, res, bthrow) { \ - __LINE__, off, size, -1, -1, -1, \ - str, sizeof str - 1, \ - arg, sizeof arg - 1, res, sizeof res - 1, bthrow \ - } - - // +------------------------------------------ controlled sequence - // | +----------------------------- replace() pos1 argument - // | | +-------------------------- replace() n1 argument - // | | | +----------------------- sequence to be inserted - // | | | | +----------- expected result sequence - // | | | | | +-- exception info - // | | | | | | 0 - no exception - // | | | | | | 1,2 - out_of_range - // | | | | | | 3 - length_error - // | | | | | | -1 - exc. safety - // | | | | | | - // | | | | | +-----------+ - // V V V V V V - TEST ("ab", 0, 0, "c", "cab", 0), - - TEST ("", 0, 0, "", "", 0), - TEST ("", 0, 0, "\0", "\0", 0), - TEST ("", 0, 0, "abc", "abc", 0), - - TEST ("ab", 0, 2, "", "", 0), - TEST ("ab", 0, 1, "", "b", 0), - TEST ("ab", 1, 1, "\0", "a\0", 0), - - TEST ("\0", 0, 1, "", "", 0), - TEST ("\0", 0, 1, "a", "a", 0), - TEST ("\0", 0, 1, "\0\0", "\0\0", 0), - - TEST ("ah", 0, 1, "bcdefg", "bcdefgh", 0), - TEST ("ah", 1, 1, "bcdefg", "abcdefg", 0), - TEST ("ah", 0, 2, "bcdefg", "bcdefg", 0), - - TEST ("abc", 0, 2, "cc", "ccc", 0), - TEST ("abc", 1, 2, "cc", "acc", 0), - - TEST ("abc", 0, 3, "defgh", "defgh", 0), - TEST ("abc", 2, 1, "defgh", "abdefgh", 0), - TEST ("abc", 2, 1, "de\0gh", "abde\0gh", 0), - TEST ("abc", 2, 1, "", "ab", 0), - TEST ("abc", 1, 1, "defgh", "adefghc", 0), - - TEST ("abc", 0, 0, "ee", "eeabc", 0), - TEST ("abc", 0, 0, "\0\0e\0", "\0\0e\0abc", 0), - TEST ("abc", 2, 0, "ee", "abeec", 0), - TEST ("abc", 1, 0, "ee", "aeebc", 0), - TEST ("abc", 1, 0, "e\0\0", "ae\0\0bc", 0), - - TEST ("a\0b\0\0c", 0, 3, "", "\0\0c", 0), - TEST ("a\0b\0\0c", 0, 3, "\0e", "\0e\0\0c", 0), - - TEST ("a\0b\0\0c", 2, 3, "\0e", "a\0\0ec", 0), - TEST ("a\0b\0\0c", 0, 3, "\0\0e\0", "\0\0e\0\0\0c", 0), - TEST ("\0ab\0\0c", 1, 2, "\0e\0\0", "\0\0e\0\0\0\0c", 0), - - TEST ("\0ab\0\0c", 0, 0, "\0e", "\0e\0ab\0\0c", 0), - TEST ("a\0b\0c\0", 6, 0, "e\0", "a\0b\0c\0e\0", 0), - TEST ("\0ab\0\0c", 5, 0, "\0e", "\0ab\0\0\0ec", 0), - - TEST (LSTR, 0, LLEN - 1, "ab", "ab", 0), - TEST (LSTR, 1, LLEN - 2, "ab", "xab", 0), - TEST (LSTR, 0, LLEN - 2, "ab", "abx", 0), - TEST (LSTR, 1, LLEN - 3, "", "xx", 0), - TEST (LSTR, 1, LLEN - 4, "\0\0", "x\0\0xx", 0), - - TEST ("", 0, 0, LSTR, LSTR, 0), - TEST ("a", 0, 1, LSTR, LSTR, 0), - TEST (LSTR, 0, LLEN - 1, LSTR, LSTR, 0), - TEST ("\0ab\0\0c", 0, 6, LSTR, LSTR, 0), - - TEST ("abc", 0, 3, 0, "abc", 0), - TEST ("abc", 1, 1, 0, "aabcc", 0), - TEST ("a\0b\0c\0", 2, 3, 0, "a\0a\0b\0c\0\0", 0), - TEST ("a\0b\0c\0", 0, 0, 0, "a\0b\0c\0a\0b\0c\0",0), - TEST ("a\0b\0c\0", 6, 0, 0, "a\0b\0c\0a\0b\0c\0",0), - TEST ("\0ab\0c\0", 3, 3, 0, "\0ab\0ab\0c\0", 0), - TEST (LSTR, 0, LLEN - 1, 0, LSTR, 0), - - TEST ("\0", 2, 0, "", "\0", 1), - TEST ("a", 10, 0, "", "a", 1), - TEST (LSTR, LLEN + 10, 0, "", LSTR, 1), - - TEST ("", 0, 0, LSTR, LSTR, -1), - - TEST ("last", 4, 0, "test", "lasttest", 0) -}; - -/**************************************************************************/ - -// used to exercise // replace (iterator, iterator, const basic_string&) static const TestCase iter_iter_str_test_cases [] = { +// iter_iter_str_test_cases serves a double duty +#define size_size_str_test_cases iter_iter_str_test_cases + #undef TEST #define TEST(s, off, size, arg, res, bthrow) { \ __LINE__, off, size, -1, -1, -1, \ @@ -454,103 +276,13 @@ // used to exercise // replace (size_type, size_type, const value_type*, size_type) -static const TestCase -size_size_ptr_size_test_cases [] = { - -#undef TEST -#define TEST(str, off, size, arg, count, res, bthrow) { \ - __LINE__, off, size, -1, count, -1, \ - str, sizeof str - 1, \ - arg, sizeof arg - 1, res, sizeof res - 1, bthrow \ - } - - // +------------------------------------------ controlled sequence - // | +----------------------------- replace() pos1 argument - // | | +-------------------------- replace() n1 argument - // | | | +----------------------- sequence to be inserted - // | | | | +---------- replace() n2 argument - // | | | | | +------- expected result sequence - // | | | | | | +-- exception info - // | | | | | | | 0 - no exception - // | | | | | | | 1,2 - out_of_range - // | | | | | | | 3 - length_error - // | | | | | | | -1 - exc. safety - // | | | | | | | - // | | | | | | +------------+ - // V V V V V V V - TEST ("ab", 0, 0, "c", 1, "cab", 0), - - TEST ("", 0, 0, "", 0, "", 0), - TEST ("", 0, 0, "abc", 3, "abc", 0), - - TEST ("ab", 0, 2, "", 0, "", 0), - TEST ("ab", 0, 1, "", 0, "b", 0), - - TEST ("\0", 0, 1, "", 0, "", 0), - TEST ("\0", 0, 1, "a", 1, "a", 0), - TEST ("\0", 0, 1, "\0\0", 2, "\0\0", 0), - - TEST ("ah", 0, 1, "bcdefg", 3, "bcdh", 0), - TEST ("ah", 1, 1, "bcdefg", 3, "abcd", 0), - TEST ("ah", 0, 2, "bcdefg", 5, "bcdef", 0), - - TEST ("abc", 0, 2, "cc", 2, "ccc", 0), - TEST ("abc", 1, 2, "cc", 2, "acc", 0), - TEST ("abc", 2, 1, "defgh", 1, "abd", 0), - TEST ("abc", 2, 1, "de\0gh", 3, "abde\0", 0), - TEST ("abc", 2, 1, "", 0, "ab", 0), - - TEST ("abc", 0, 0, "ee", 2, "eeabc", 0), - TEST ("abc", 0, 0, "\0\0e\0", 4, "\0\0e\0abc", 0), - TEST ("abc", 2, 0, "ee", 2, "abeec", 0), - TEST ("abc", 1, 0, "ee", 1, "aebc", 0), - - TEST ("a\0b\0\0c", 0, 3, "", 0, "\0\0c", 0), - TEST ("a\0b\0\0c", 0, 3, "e\0", 2, "e\0\0\0c", 0), - TEST ("a\0b\0\0c", 2, 3, "e\0", 1, "a\0ec", 0), - TEST ("a\0b\0\0c", 2, 3, "\0e", 2, "a\0\0ec", 0), - TEST ("\0ab\0\0c", 2, 3, "\0e", 2, "\0a\0ec", 0), - TEST ("a\0b\0\0c", 0, 6, "e\0", 2, "e\0", 0), - - TEST (LSTR, 1, LLEN - 1, "\0", 1, "x\0", 0), - TEST (LSTR, 0, LLEN - 1, "ab", 2, "ab", 0), - TEST (LSTR, 1, LLEN - 2, "ab", 1, "xa", 0), - TEST (LSTR, 0, LLEN - 2, "ab", 2, "abx", 0), - TEST (LSTR, 1, LLEN - 3, "", 0, "xx", 0), - TEST (LSTR, 1, LLEN - 4, "\0\0", 2, "x\0\0xx", 0), - - TEST ("a", 0, 1, LSTR, LLEN - 1, LSTR, 0), - TEST (LSTR, 0, LLEN - 1, LSTR, LLEN - 1, LSTR, 0), - TEST (LSTR, 0, LPAR - 1, LSTR, LPAR - 1, LSTR, 0), - - TEST (LSTR, LPAR - 1, LPAR, LSTR, LPAR, LSTR, 0), - - TEST ("abc", 0, 3, 0, 2, "ab", 0), - TEST ("abc", 1, 1, 0, 3, "aabcc", 0), - TEST ("a\0b\0c\0", 2, 3, 0, 6, "a\0a\0b\0c\0\0", 0), - TEST ("a\0b\0c\0", 0, 0, 0, 4, "a\0b\0a\0b\0c\0", 0), - TEST ("\0ab\0c\0", 6, 0, 0, 1, "\0ab\0c\0\0", 0), - TEST ("\0ab\0c\0", 3, 3, 0, 2, "\0ab\0a", 0), - TEST (LSTR, 0, LLEN - 1, 0, LLEN - 1, LSTR, 0), - TEST (LSTR, 0, LLEN - 1, 0, 1, "x", 0), - - TEST ("\0", 2, 0, "", 0, "\0", 1), - TEST ("a", 10, 0, "", 0, "a", 1), - TEST (LSTR, LLEN + 10, 0, "", 0, LSTR, 1), - - TEST ("a", 0, 1, LSTR, LLEN - 1, LSTR, -1), - - TEST ("last", 4, 0, "test", 4, "lasttest", 0) -}; - - -/**************************************************************************/ - -// used to exercise // replace (iterator, iterator, const value_type*, size_type) static const TestCase iter_iter_ptr_size_test_cases [] = { +// iter_iter_range_test_cases serves a double duty +#define size_size_ptr_size_test_cases iter_iter_ptr_size_test_cases + #undef TEST #define TEST(str, off, size, arg, count, res, bthrow) { \ __LINE__, off, size, -1, count, -1, \ @@ -640,128 +372,14 @@ /**************************************************************************/ // used to exercise -// replace (size_type, size_type, const basic_string&, size_type, size_type) -static const TestCase -size_size_str_size_size_test_cases [] = { - -#undef TEST -#define TEST(str, off, size, arg, off2, size2, res, bthrow) { \ - __LINE__, off, size, off2, size2, -1, \ - str, sizeof str - 1, \ - arg, sizeof arg - 1, res, sizeof res - 1, bthrow \ - } - - // +------------------------------------------ controlled sequence - // | +----------------------------- replace() pos argument - // | | +-------------------------- replace() n1 argument - // | | | +----------------------- sequence to be inserted - // | | | | +---------- replace() pos2 argument - // | | | | | +------- replace() n2 argument - // | | | | | | +---- expected result sequence - // | | | | | | | +- exception info - // | | | | | | | | 0 - no exception - // | | | | | | | | 1,2 - out_of_range - // | | | | | | | | 3 - length_error - // | | | | | | | | -1 - exc. safety - // | | | | | | | | - // | | | | | | | +----------------+ - // V V V V V V V V - - TEST ("ab", 0, 0, "c", 0, 1, "cab", 0), - - TEST ("", 0, 0, "", 0, 0, "", 0), - TEST ("", 0, 0, "abc", 0, 3, "abc", 0), - - TEST ("ab", 0, 2, "", 0, 0, "", 0), - TEST ("ab", 0, 1, "", 0, 0, "b", 0), - - TEST ("\0", 0, 1, "", 0, 0, "", 0), - TEST ("\0", 0, 1, "a", 0, 1, "a", 0), - TEST ("\0", 0, 1, "\0\0", 1, 1, "\0", 0), - TEST ("\0", 0, 1, "\0\0", 0, 2, "\0\0", 0), - - TEST ("ah", 0, 1, "bcdefg", 0, 3, "bcdh", 0), - TEST ("ah", 1, 1, "bcdefg", 0, 3, "abcd", 0), - TEST ("ah", 0, 1, "bcdefg", 1, 3, "cdeh", 0), - TEST ("ah", 1, 1, "bcdefg", 1, 3, "acde", 0), - TEST ("ah", 0, 1, "bcdefg", 0, 6, "bcdefgh", 0), - TEST ("ah", 1, 1, "bcdefg", 0, 6, "abcdefg", 0), - - TEST ("abc", 0, 2, "cc", 0, 2, "ccc", 0), - TEST ("abc", 1, 2, "cc", 0, 2, "acc", 0), - - TEST ("abc", 0, 3, "d", 0, 1, "d", 0), - TEST ("abc", 0, 3, "def", 0, 3, "def", 0), - TEST ("abc", 0, 3, "defgh", 0, 5, "defgh", 0), - TEST ("abc", 2, 1, "defgh", 4, 1, "abh", 0), - TEST ("abc", 2, 1, "de\0gh", 2, 1, "ab\0", 0), - TEST ("abc", 2, 1, "", 0, 0, "ab", 0), - - TEST ("abc", 1, 1, "defgh", 1, 2, "aefc", 0), - TEST ("abc", 0, 0, "ee", 0, 2, "eeabc", 0), - TEST ("abc", 0, 0, "\0\0e\0", 0, 4, "\0\0e\0abc", 0), - TEST ("abc", 2, 0, "ee", 0, 2, "abeec", 0), - TEST ("abc", 2, 1, "\0e\0\0", 0, 4, "ab\0e\0\0", 0), - TEST ("abc", 1, 0, "ee", 0, 2, "aeebc", 0), - TEST ("abc", 1, 0, "\0e\0\0", 0, 4, "a\0e\0\0bc", 0), - - TEST ("a\0b\0\0c", 0, 3, "", 0, 0, "\0\0c", 0), - TEST ("\0ab\0\0c", 0, 3, "", 0, 0, "\0\0c", 0), - TEST ("a\0b\0\0c", 0, 3, "\0e", 0, 2, "\0e\0\0c", 0), - - TEST ("a\0b\0\0c", 2, 3, "\0e", 0, 2, "a\0\0ec", 0), - TEST ("a\0b\0\0c", 2, 3, "\0e", 1, 1, "a\0ec", 0), - TEST ("\0ab\0\0c", 2, 3, "\0e", 0, 2, "\0a\0ec", 0), - TEST ("\0ab\0\0c", 2, 3, "\0e\0\0", 1, 3, "\0ae\0\0c", 0), - - TEST ("a\0b\0\0c", 0, 6, "\0e", 0, 2, "\0e", 0), - TEST ("a\0b\0\0c", 0, 6, "\0e", 0, 1, "\0", 0), - - TEST ("\0ab\0\0c", 0, 0, "\0e", 0, 2, "\0e\0ab\0\0c", 0), - TEST ("a\0b\0c\0", 6, 0, "e\0", 0, 2, "a\0b\0c\0e\0", 0), - TEST ("\0ab\0\0c", 5, 0, "\0e", 0, 2, "\0ab\0\0\0ec", 0), - - TEST (LSTR, 0, LLEN - 1, "ab", 0, 2, "ab", 0), - TEST (LSTR, 1, LLEN - 2, "ab", 0, 2, "xab", 0), - TEST (LSTR, 0, LLEN - 2, "ab", 0, 2, "abx", 0), - TEST (LSTR, 1, LLEN - 3, "", 0, 0, "xx", 0), - TEST (LSTR, 1, LLEN - 4, "\0\0", 0, 2, "x\0\0xx", 0), - - TEST ("a", 0, 1, LSTR, 0, LLEN - 1, LSTR, 0), - TEST (LSTR, 0, LLEN - 1, LSTR, 0, LLEN - 1, LSTR, 0), - TEST (LSTR, 0, LPAR - 1, LSTR, 0, LPAR - 1, LSTR, 0), - - TEST (LSTR, LPAR - 1, LPAR, LSTR, 0, LPAR, LSTR, 0), - - TEST ("abc", 0, 0, 0, 1, 1, "babc", 0), - TEST ("abc", 2, 0, 0, 0, 2, "ababc", 0), - TEST ("a\0bc\0\0", 0, 0, 0, 4, 2, "\0\0a\0bc\0\0", 0), - TEST ("a\0bc\0\0", 6, 0, 0, 1, 3, "a\0bc\0\0\0bc", 0), - TEST ("abcdef", 0, 0, 0, 1, 2, "bcabcdef", 0), - - TEST ("\0", 2, 0, "", 0, 0, "\0", 1), - TEST ("\0", 0, 0, "\0", 2, 0, "", 2), - - TEST ("a", 10, 0, "", 0, 0, "a", 1), - TEST ("a", 0, 0, "a", 10, 0, "", 2), - - TEST (LSTR, LLEN + 10, 0, "", 0, 0, LSTR, 1), - TEST (LSTR, 0, 0, LSTR, LLEN + 10, 0, "", 2), - - TEST ("a", 0, 1, LSTR, 0, LLEN - 1, LSTR, -1), - TEST (LSTR, 0, 0, LSTR, 0, LPAR - 1, 0, -1), - - TEST ("last", 4, 0, "test", 0, 4, "lasttest", 0) -}; - - -/**************************************************************************/ - -// used to exercise +// replace (size_type , size_type , basic_string& s, size_type , size_type ) // replace (iterator, Iterator, InputIterator, InputIterator) static const TestCase iter_iter_range_test_cases [] = { +// iter_iter_range_test_cases serves a double duty +#define size_size_str_size_size_test_cases iter_iter_range_test_cases + #undef TEST #define TEST(str, off, size, arg, off2, size2, res, bthrow) { \ __LINE__, off, size, off2, size2, -1, \ @@ -867,7 +485,6 @@ TEST (LSTR, 0, 0, LSTR, LLEN + 10, 0, "", 2), TEST ("a", 0, 1, LSTR, 0, LLEN - 1, LSTR, -1), - TEST (LSTR, 0, 0, LSTR, 0, LPAR - 1, 0, -1), TEST ("last", 4, 0, "test", 0, 4, "lasttest", 0) }; @@ -876,102 +493,13 @@ // used to exercise // replace (size_type, size_type, value_type, size_type) -static const TestCase -size_size_size_val_test_cases [] = { - -#undef TEST -#define TEST(str, off, size, count, val, res, bthrow) { \ - __LINE__, off, size, -1, count, val, \ - str, sizeof str - 1, 0, 0, res, sizeof res - 1, bthrow \ - } - - // +------------------------------------------ controlled sequence - // | +----------------------------- replace() pos1 argument - // | | +-------------------------- replace() n1 argument - // | | | +----------------------- replace() count argument - // | | | | +------------------- character to be inserted - // | | | | | +-------------- expected result sequence - // | | | | | | +------- exception info - // | | | | | | | 0 - no exception - // | | | | | | | 1,2 - out_of_range - // | | | | | | | 3 - length_error - // | | | | | | | -1 - exc. safety - // | | | | | | | - // | | | | | | +--------+ - // V V V V V V V - TEST ("ab", 0, 0, 1, 'c', "cab", 0), - - TEST ("", 0, 0, 0, 'c', "", 0), - TEST ("", 0, 0, 3, 'c', "ccc", 0), - - TEST ("ab", 0, 2, 0, 'c', "", 0), - TEST ("ab", 0, 1, 0, 'c', "b", 0), - - TEST ("\0", 0, 1, 0, ' ', "", 0), - TEST ("\0", 0, 1, 1, 'a', "a", 0), - TEST ("\0", 0, 1, 1, '\0', "\0", 0), - TEST ("\0", 0, 1, 2, '\0', "\0\0", 0), - - TEST ("ah", 0, 1, 1, 'c', "ch", 0), - TEST ("ah", 1, 1, 1, 'c', "ac", 0), - TEST ("ah", 0, 1, 4, 'c', "cccch", 0), - TEST ("ah", 1, 1, 4, 'c', "acccc", 0), - - TEST ("abc", 0, 2, 2, 'c', "ccc", 0), - TEST ("abc", 1, 2, 2, 'c', "acc", 0), - - TEST ("abc", 0, 3, 1, 'c', "c", 0), - TEST ("abc", 0, 3, 5, 'c', "ccccc", 0), - TEST ("abc", 2, 1, 1, 'c', "abc", 0), - TEST ("abc", 2, 1, 0, 'c', "ab", 0), - - TEST ("abc", 1, 1, 5, 'c', "acccccc", 0), - TEST ("abc", 0, 0, 2, 'c', "ccabc", 0), - TEST ("abc", 0, 0, 3, '\0', "\0\0\0abc", 0), - TEST ("abc", 2, 0, 2, 'e', "abeec", 0), - TEST ("abc", 2, 0, 3, '\0', "ab\0\0\0c", 0), - TEST ("abc", 1, 0, 1, '\0', "a\0bc", 0), - - TEST ("a\0b\0\0c", 0, 3, 1, '\0', "\0\0\0c", 0), - TEST ("a\0b\0\0c", 2, 3, 2, '\0', "a\0\0\0c", 0), - TEST ("a\0b\0\0c", 2, 2, 1, '\0', "a\0\0\0c", 0), - TEST ("\0ab\0\0c", 2, 3, 0, '\0', "\0ac", 0), - TEST ("\0ab\0\0c", 2, 1, 2, '\0', "\0a\0\0\0\0c", 0), - - TEST ("a\0b\0\0c", 0, 6, 2, '\0', "\0\0", 0), - - TEST ("\0ab\0\0c", 0, 0, 2, '\0', "\0\0\0ab\0\0c", 0), - TEST ("a\0b\0c\0", 6, 0, 2, '\0', "a\0b\0c\0\0\0", 0), - TEST ("\0ab\0\0c", 5, 0, 1, '\0', "\0ab\0\0\0c", 0), - - TEST (LSTR, 0, LLEN - 1, 2, 'a', "aa", 0), - TEST (LSTR, 1, LLEN - 2, 2, 'a', "xaa", 0), - TEST (LSTR, 0, LLEN - 2, 2, 'a', "aax", 0), - TEST (LSTR, 1, LLEN - 3, 0, 'a', "xx", 0), - TEST (LSTR, 1, LLEN - 4, 1, '\0', "x\0xx", 0), - - TEST ("a", 0, 1, LLEN - 1, 'x', LSTR, 0), - TEST (LSTR, 0, LLEN - 1, LLEN - 1, 'x', LSTR, 0), - TEST (LSTR, 0, LPAR - 1, LPAR - 1, 'x', LSTR, 0), - - TEST (LSTR, LPAR - 1, LPAR, LPAR, 'x', LSTR, 0), - - TEST ("\0", 2, 0, 0, ' ', "\0", 1), - TEST ("a", 10, 0, 0, ' ', "a", 1), - TEST (LSTR, LLEN + 10, 0, 0, ' ', LSTR, 1), - - TEST ("a", 0, 1, LLEN - 1, 'x', LSTR, -1), - - TEST ("last", 4, 0, 4, 't', "lasttttt", 0) -}; - -/**************************************************************************/ - -// used to exercise // replace (iterator, iterator, size_type, value_type) static const TestCase iter_iter_size_val_test_cases [] = { +// iter_iter_size_val_test_cases serves a double duty +#define size_size_size_val_test_cases iter_iter_size_val_test_cases + #undef TEST #define TEST(str, off, size, count, val, res, bthrow) { \ __LINE__, off, size, -1, count, val, \ @@ -1059,163 +587,8 @@ TEST ("last", 4, 0, 4, 't', "lasttttt", 0) }; - /**************************************************************************/ -template -void test_exceptions (charT, Traits*, - ReplaceOverload which, - const TestCase &tcase) -{ - typedef std::allocator Allocator; - typedef std::basic_string TestString; - typedef typename TestString::iterator StringIter; - typedef typename TestString::const_iterator ConstStringIter; - - const bool use_iters = Replace (iter_iter_ptr) <= which; - - static charT wstr [LLEN]; - static charT warg [LLEN]; - - rw_widen (wstr, tcase.str, tcase.str_len); - rw_widen (warg, tcase.arg, tcase.arg_len); - - /* const */ TestString s_str (wstr, tcase.str_len); - const TestString s_arg (warg, tcase.arg_len); - - const int first = use_iters ? tcase.off : tcase.str_len + 1; - const int last = use_iters ? tcase.off + tcase.size : tcase.str_len + 1; - - const StringIter it_first (std::size_t (first) >= s_str.size () ? - s_str.end () : s_str.begin () + first); - const StringIter it_last (std::size_t (last) >= s_str.size () ? - s_str.end () : s_str.begin () + last); - - 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); - - std::size_t throw_after = 0; - - const std::size_t size = s_str.size (); - const std::size_t capacity = s_str.capacity (); - const ConstStringIter begin = s_str.begin (); - -#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE - - rwt_free_store* const pst = rwt_get_free_store (0); - -#endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE - - // iterate for`n=throw_after' starting at the next call to operator - // new, forcing each call to throw an exception, until the insertion - // finally succeeds (i.e, no exception is thrown) - for ( ; ; ) { - -#ifndef _RWSTD_NO_EXCEPTIONS -# ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE - - *pst->throw_at_calls_ [0] = pst->new_calls_ [0] + throw_after + 1; - -# endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE -#endif // _RWSTD_NO_EXCEPTIONS - - _TRY { - if (Replace (size_size_ptr) == which) - s_str.replace (tcase.off, tcase.size, arg_ptr); - - else if (Replace (size_size_str) == which) - s_str.replace (tcase.off, tcase.size, arg_str); - - else if (Replace (size_size_ptr_size) == which) - s_str.replace (tcase.off, tcase.size, arg_ptr, tcase.size2); - - else if (Replace (size_size_str_size_size) == which) - s_str.replace (tcase.off, tcase.size, arg_str, - tcase.off2, tcase.size2); - - else if (Replace (size_size_size_val) == which) - s_str.replace (tcase.off, tcase.size, tcase.size2, arg_val); - - else if (Replace (iter_iter_ptr) == which) - s_str.replace (it_first, it_last, arg_ptr); - - else if (Replace (iter_iter_str) == which) - s_str.replace (it_first, it_last, arg_str); - - else if (Replace (iter_iter_ptr_size) == which) - s_str.replace (it_first, it_last, arg_ptr, tcase.size2); - - else if (Replace (iter_iter_size_val) == which) - s_str.replace (it_first, it_last, tcase.size2, arg_val); - - else if (Replace (iter_iter_range) == which) - s_str.replace (it_first, it_last, s_arg.begin(), s_arg.end()); - - break; - } - _CATCH (...) { - -#ifndef _RWSTD_NO_EXCEPTIONS - - // verify that an exception thrown during allocation - // doesn't cause a change in the state of the vector - - 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, 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, tcase.line, - "line %d: %{$FUNCALL}: begin() unexpectedly " - "changed from after an exception by %d", - __LINE__, s_str.begin () - begin); - - - // increment to allow this call to operator new to succeed - // and force the next one to fail, and try to insert again - ++throw_after; - -#endif // _RWSTD_NO_EXCEPTIONS - - } // catch - } // for - -#ifndef _RWSTD_NO_EXCEPTIONS -# ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE - - // verify that if exceptions are enabled and when capacity changes - // at least one exception is thrown - rw_assert ( *pst->throw_at_calls_ [0] == std::size_t (-1) - || throw_after, - 0, tcase.line, - "line %d: %{$FUNCALL}: failed to throw an expected exception", - __LINE__); - -# endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE -#else // if defined (_RWSTD_NO_EXCEPTIONS) - - _RWSTD_UNUSED (size); - _RWSTD_UNUSED (capacity); - _RWSTD_UNUSED (throw_after); - -#endif // _RWSTD_NO_EXCEPTIONS - -#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE - - *pst->throw_at_calls_ [0] = std::size_t (-1); - -#endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE -} - -/**************************************************************************/ - template void test_replace_range (const charT* wstr, const charT* warg, @@ -1249,7 +622,7 @@ const charT* const warg_beg = warg + off_first2; const charT* const warg_end = warg + off_last2; - const Iterator first (warg_beg, warg_beg, warg_end); + const Iterator first (warg_beg, warg_beg, warg_end); const Iterator last (warg_end, warg + tcase.off2, warg_end); s_str.replace (it_first, it_last, first, last); @@ -1313,12 +686,8 @@ typedef std::allocator Allocator; typedef std::basic_string TestString; typedef typename TestString::iterator StringIter; + typedef typename TestString::const_iterator ConstStringIter; - if (-1 == tcase.bthrow) { - test_exceptions (charT (), (Traits*)0, which, tcase); - return; - } - const bool use_iters = Replace (iter_iter_ptr) <= which; static charT wstr [LLEN]; @@ -1337,6 +706,8 @@ const TestString s_arg (warg, tcase.arg_len); std::size_t res_off = 0; + std::size_t throw_after = 0; + int first = use_iters ? tcase.off : tcase.str_len + 1; int last = use_iters ? tcase.off + tcase.size : tcase.str_len + 1; std::size_t size = tcase.size2 >= 0 ? tcase.size2 : s_str.max_size () + 1; @@ -1346,136 +717,260 @@ StringIter it_last (std::size_t (last) >= s_str.size () ? s_str.end () : s_str.begin () + last); + const std::size_t ssize = s_str.size (); + const std::size_t capacity = s_str.capacity (); + const ConstStringIter begin = s_str.begin (); + // string function argument 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); - // address of returned reference - const TestString* res_ptr = 0; +#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE + rwt_free_store* const pst = rwt_get_free_store (0); + +#endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE + + // iterate for`n=throw_after' starting at the next call to operator + // new, forcing each call to throw an exception, until the appendion + // finally succeeds (i.e, no exception is thrown) + for ( ; ; ) { + #ifndef _RWSTD_NO_EXCEPTIONS +# ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE - // is some exception expected ? - const char* expected = 0; - if (1 == tcase.bthrow && !use_iters) - expected = exp_exceptions [1]; - if (2 == tcase.bthrow && Replace (size_size_str_size_size) == which) - expected = exp_exceptions [1]; - if (3 == tcase.bthrow && !use_iters) - expected = exp_exceptions [2]; + if (-1 == tcase.bthrow) + *pst->throw_at_calls_ [0] = pst->new_calls_ [0] + throw_after + 1; - const char* caught = 0; +# endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE +#endif // _RWSTD_NO_EXCEPTIONS - try { +#ifndef _RWSTD_NO_EXCEPTIONS + // is some exception expected ? + const char* expected = 0; + if (1 == tcase.bthrow && !use_iters) + expected = exceptions [1]; // out_of_range + if (2 == tcase.bthrow && Replace (size_size_str_size_size) == which) + expected = exceptions [1]; // out_of_range + if (3 == tcase.bthrow && !use_iters) + expected = exceptions [2]; // length_error + if (-1 == tcase.bthrow) + expected = exceptions [3]; // bad_alloc + + const char* caught = 0; + #else // if defined (_RWSTD_NO_EXCEPTIONS) - if (tcase.bthrow) - return; + if (tcase.bthrow) + return; #endif // _RWSTD_NO_EXCEPTIONS - switch (which) { - case Replace (size_size_ptr): { - res_ptr = &s_str.replace (tcase.off, tcase.size, arg_ptr); - break; - } + try { + switch (which) { + case Replace (size_size_ptr): { + const TestString& s_res = + s_str.replace (tcase.off, tcase.size, arg_ptr); + res_off = &s_res - &s_str; + break; + } - case Replace (size_size_str): { - res_ptr = &s_str.replace (tcase.off, tcase.size, arg_str); - break; - } + case Replace (size_size_str): { + const TestString& s_res = + s_str.replace (tcase.off, tcase.size, arg_str); + res_off = &s_res - &s_str; + break; + } - case Replace (size_size_ptr_size): { - res_ptr = &s_str.replace (tcase.off, tcase.size, arg_ptr, size); - break; - } + case Replace (size_size_ptr_size): { + const TestString& s_res = + s_str.replace (tcase.off, tcase.size, arg_ptr, size); + res_off = &s_res - &s_str; + break; + } - case Replace (size_size_str_size_size): { - res_ptr = &s_str.replace (tcase.off, tcase.size, arg_str, - tcase.off2, size); - break; - } + case Replace (size_size_str_size_size): { + const TestString& s_res = + s_str.replace (tcase.off, tcase.size, arg_str, + tcase.off2, size); + res_off = &s_res - &s_str; + break; + } - case Replace (size_size_size_val): { - res_ptr = &s_str.replace (tcase.off, tcase.size, size, arg_val); - break; - } + case Replace (size_size_size_val): { + const TestString& s_res = + s_str.replace (tcase.off, tcase.size, size, arg_val); + res_off = &s_res - &s_str; + break; + } - case Replace (iter_iter_ptr): { - res_ptr = &s_str.replace (it_first, it_last, arg_ptr); - break; - } + case Replace (iter_iter_ptr): { + const TestString& s_res = + s_str.replace (it_first, it_last, arg_ptr); + res_off = &s_res - &s_str; + break; + } - case Replace (iter_iter_str): { - res_ptr = &s_str.replace (it_first, it_last, arg_str); - break; - } + case Replace (iter_iter_str): { + const TestString& s_res = + s_str.replace (it_first, it_last, arg_str); + res_off = &s_res - &s_str; + break; + } - case Replace (iter_iter_ptr_size): { - res_ptr = &s_str.replace (it_first, it_last, arg_ptr, size); - break; - } + case Replace (iter_iter_ptr_size): { + const TestString& s_res = + s_str.replace (it_first, it_last, arg_ptr, size); + res_off = &s_res - &s_str; + break; + } - case Replace (iter_iter_size_val): { - res_ptr = &s_str.replace (it_first, it_last, size, arg_val); - break; - } + case Replace (iter_iter_size_val): { + const TestString& s_res = + s_str.replace (it_first, it_last, size, arg_val); + res_off = &s_res - &s_str; + break; + } - default: - RW_ASSERT ("test logic error: unknown replace overload"); - return; - } + default: + RW_ASSERT ("test logic error: unknown replace overload"); + return; + } - res_off = res_ptr - &s_str; + // verify the returned value + rw_assert (0 == res_off, 0, tcase.line, + "line %d. %{$FUNCALL} returned invalid reference, " + "offset is %zu", __LINE__, res_off); - // verify the returned value - 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 (tcase.res_len == s_str.size (), 0, tcase.line, + "line %d. %{$FUNCALL} expected %{#*s} with length" + "%zu, got %{/*.*Gs} with length %zu", + __LINE__, int (tcase.res_len), tcase.res, + tcase.res_len, int (sizeof (charT)), + int (s_str.size ()), s_str.c_str (), s_str.size ()); - // verfiy that strings length are equal - 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 (tcase.res_len), - tcase.res, tcase.res_len, int (sizeof (charT)), - int (s_str.size ()), - s_str.c_str (), 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 (tcase.res, s_str.c_str(), tcase.res_len); - // verfiy that replace results match expected result - const std::size_t match = - rw_match (tcase.res, s_str.c_str(), tcase.res_len); + rw_assert (match == tcase.res_len, 0, tcase.line, + "line %d. %{$FUNCALL} expected %{#*s}, " + "got %{/*.*Gs}, difference at offset %zu", + __LINE__, int (tcase.res_len), tcase.res, + int (sizeof (charT)), int (s_str.size ()), + s_str.c_str (), match); + } + } - rw_assert (match == tcase.res_len, 0, tcase.line, - "line %d. %{$FUNCALL} expected %{#*s}, got %{/*.*Gs}, " - "difference at offset %zu", - __LINE__, int (tcase.res_len), tcase.res, - int (sizeof (charT)), int (s_str.size ()), s_str.c_str (), - match); - #ifndef _RWSTD_NO_EXCEPTIONS + catch (const std::out_of_range &ex) { + caught = exceptions [1]; + 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::length_error &ex) { + caught = exceptions [2]; + 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 == 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, 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, tcase.line, + "line %d. %{$FUNCALL} %{?}expected %s,%{:}" + "unexpectedly%{;} caught %s", + __LINE__, 0 != expected, expected, caught); + } + +#else // if defined (_RWSTD_NO_EXCEPTIONS) + + _RWSTD_UNUSED (should_throw); + +#endif // _RWSTD_NO_EXCEPTIONS + + if (caught) { + // verify that an exception thrown during allocation + // didn't cause a change in the state of the object + + rw_assert (s_str.size () == ssize, 0, tcase.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, 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, tcase.line, + "line %d: %{$FUNCALL}: begin() unexpectedly " + "changed from after an exception by %d", + __LINE__, s_str.begin () - begin); + + 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 + ++throw_after; + continue; + } + } + 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); + } + + break; } - catch (std::out_of_range) { - caught = exp_exceptions[1]; - } - catch (std::length_error) { - caught = exp_exceptions[2]; - } - catch (...) { - caught = exp_exceptions[0]; - } +#ifndef _RWSTD_NO_EXCEPTIONS +# ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE + + // verify that if exceptions are enabled and when capacity changes + // at least one exception is thrown + rw_assert ( *pst->throw_at_calls_ [0] == std::size_t (-1) + || throw_after, + 0, tcase.line, + "line %d: %{$FUNCALL}: failed to throw an expected exception", + __LINE__); + + *pst->throw_at_calls_ [0] = std::size_t (-1); + +# endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE #else // if defined (_RWSTD_NO_EXCEPTIONS) - _RWSTD_UNUSED (should_throw); + + _RWSTD_UNUSED (size); + _RWSTD_UNUSED (capacity); + _RWSTD_UNUSED (throw_after); + #endif // _RWSTD_NO_EXCEPTIONS - rw_assert (caught == expected, 0, tcase.line, - "line %d. %{$FUNCALL} %{?}expected %s, caught %s" - "%{:}unexpectedly caught %s%{;}", __LINE__, - 0 != expected, expected, caught, caught); } /**************************************************************************/ --------------060409030407060603050104--