Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 83684 invoked from network); 21 Mar 2006 02:22:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Mar 2006 02:22:36 -0000 Received: (qmail 97955 invoked by uid 500); 21 Mar 2006 02:22:36 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 97935 invoked by uid 500); 21 Mar 2006 02:22:36 -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 97924 invoked by uid 99); 21 Mar 2006 02:22:35 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Mar 2006 18:22:35 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [208.30.140.160] (HELO moroha.quovadx.com) (208.30.140.160) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Mar 2006 18:22:33 -0800 Received: from bco-exchange.bco.roguewave.com (bco-exchange.bco.roguewave.com [172.19.31.48]) by moroha.quovadx.com (8.13.4/8.13.4) with ESMTP id k2L2Lu6n009255 for ; Tue, 21 Mar 2006 02:21:56 GMT Received: from [10.70.3.113] (10.70.3.113 [10.70.3.113]) by bco-exchange.bco.roguewave.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2657.72) id F5YGR678; Mon, 20 Mar 2006 19:20:38 -0700 Message-ID: <441F646A.9030405@roguewave.com> Date: Mon, 20 Mar 2006 19:26:50 -0700 From: Martin Sebor User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050920 X-Accept-Language: en-us, en MIME-Version: 1.0 To: stdcxx-dev@incubator.apache.org Subject: Re: test for 21.string.copy References: <441ED32E.1040001@moscow.vdiweb.com> In-Reply-To: <441ED32E.1040001@moscow.vdiweb.com> Content-Type: multipart/mixed; boundary="------------080803000204010906000306" X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --------------080803000204010906000306 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Anton Pevtsov wrote: > The attached file contains the test for lib.string.copy. I made a few changes -- see the attached diff. exp_exceptions[] was missing element[2] (dereferenced later in the test). I added it. I introduced the LSTR and LLEN convenience macros to make it easier to refer to long_string and long_string_len. I made TestCase::str and TestCase::res const to avoid having to cast away the constness of string literals used to define the array and silence gcc warnings about the same. I made the MemFun pointer argument const since pointed-to object is not modified by any of the functions. I replaced the s_empty object with a constant eos character for simplicity. I also added const wherever possible. Making all objects that aren't modified makes code easier to understand. Let's use const wherever possible. I added a few assertions to assert test preconditions. Please use the RW_ASSERT() to assert any assumptions made in all tests :) I initialized the destination buffer to all garbage. Could you make sure the test verifies that the tested function doesn't write past the end of the provided buffer (by checking for the garbage value)? Finally, I removed the extraneous "test disabled" text from the rw_info() statements (probably copy-and-paste mistakes :) With the patch applied and the suggested changes to test for the potential corruption of the destination buffer, please go ahead and commit the test. Thanks Martin PS I added rw_narrow() overloads that you could use to display the contents of the (wide) destination buffer until we have the formatting directive implemented (I'm working on it). Also, I noticed some strange long --trace output in a few cases that doesn't look right to me (see below). Could you look into it to see what's going on? (Is it because we're not using the right formatting directive?) # ITRACE_ASSERTION (S0) (4 lines): # TEXT: line 215. std::basic_string, allocator>({ 'x' }).copy ("\0", 4095) expected "\0\0\0x\0\0\0x\ 0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0 ... \0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0", got "\0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\ ... 0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0x\0\0\0 x\0\0\0" # CLAUSE: lib.string.copy # LINE: 133 --------------080803000204010906000306 Content-Type: text/plain; name="21.string.erase.cpp.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="21.string.erase.cpp.diff" --- /nfs/b20/sebor/tmp/21.erase.cpp Sat Mar 11 17:13:28 2006 +++ /build/sebor/stdcxx/tests/strings/21.string.erase.cpp Sat Mar 11 17:50:12 2006 @@ -2,7 +2,7 @@ * * erase.cpp - string test exercising [lib.string::erase] * - * $Id: + * $Id: 21.string.erase.cpp 385224 2006-03-12 00:49:26Z sebor $ * *************************************************************************** * @@ -94,7 +94,7 @@ charT* pwres = 0 == str ? 0 : wres; - TestString str_ob(wstr, str_len); + TestString str_ob (wstr, str_len); TestString str_def; TestString* pstr = 0 != str ? &str_ob : &str_def; @@ -150,7 +150,7 @@ if (pos < 0 || cnt < 0 || should_throw) return; - typename TestString::iterator it_first (pstr->begin() + pos); + typename TestString::iterator it_first (pstr->begin () + pos); typename TestString::iterator it_last (std::size_t (last) == str_len ? pstr->end() : pstr->begin() + last); @@ -162,13 +162,15 @@ return; } -#define CALLFMAT \ - "line %d. basic_string<%s, %s<%2$s>, %s<%2$s>>(%#s)." \ - "erase (%{?}%{?}%d%{;}%{?}, %d%{;}%{;}" \ +#define CALLFMAT \ + "line %d. basic_string<%s, %s<%2$s>, %s<%2$s>>(" \ + "%{?}%{#*s}%{;}" \ + ").erase (%{?}%{?}%d%{;}%{?}, %d%{;}%{;}" \ "%{?}begin + %td%{?}, begin + %td%{;}%{;}) " -#define CALLARGS \ - __LINE__, pfid->cname_, pfid->tname_, pfid->aname_, wstr, \ +#define CALLARGS \ + __LINE__, pfid->cname_, pfid->tname_, pfid->aname_, \ + 0 != str, int (str_len), str, \ 4 > which, 2 == which || 3 == which, f_arg, 3 == which, s_arg, \ 4 <= which, f_arg, 5 == which, s_arg @@ -175,8 +177,7 @@ #ifndef _RWSTD_NO_EXCEPTIONS } - catch (std::out_of_range e) { - _RWSTD_UNUSED (e); + catch (std::out_of_range) { caught = expected; } catch (...) { @@ -184,7 +185,7 @@ } rw_assert (caught == expected, 0, line, - CALLFMAT " %{?}expected %s, caught %s" + CALLFMAT "%{?}expected %s, caught %s" "%{:}unexpectedly caught %s%{;}", CALLARGS, 0 != expected, expected, caught, caught); @@ -195,9 +196,9 @@ _RWSTD_UNUSED (should_throw); #endif // _RWSTD_NO_EXCEPTIONS - std::string::size_type res_sz = pstr->size(); - const typename TestString::iterator begin = pstr->begin(); - const typename TestString::iterator end = pstr->end(); + const typename TestString::size_type res_sz = pstr->size(); + const typename TestString::iterator begin = pstr->begin(); + const typename TestString::iterator end = pstr->end(); // verify the returned value if (which < 4) { @@ -216,7 +217,7 @@ if (idx == sz) { rw_assert (it_res == end, 0, line, - CALLFMAT " != end()", CALLARGS); + CALLFMAT "!= end()", CALLARGS); } else { success = TestString::traits_type::eq (*it_res, wstr[idx]); @@ -230,7 +231,7 @@ std::size_t exp_len = pos >= 0 ? cnt == -1 ? pos : res_len : 0; bool success = exp_len == res_sz; rw_assert (success, 0, line, - CALLFMAT " : size() == %zu, expected %zu", + CALLFMAT ": size() == %zu, expected %zu", CALLARGS, res_sz, exp_len); if (0 == res_sz) @@ -238,7 +239,7 @@ success = !TestString::traits_type::compare (pstr->c_str(), pwres, res_sz); rw_assert (success, 0, line, - CALLFMAT " : got %{#*S}, expected {%#s}", + CALLFMAT ": got %{#*S}, expected %{#s}", CALLARGS, int (sizeof (charT)), pstr, res); } @@ -245,20 +246,21 @@ /**************************************************************************/ -void test_erase (MemFun *pfid, - int line, - int which, - const char *str, - std::size_t str_len, - int pos, - int npos, - const char *res, - std::size_t res_len, - bool should_throw) +static void +test_erase (MemFun *pfid, + int line, + int which, + const char *str, + std::size_t str_len, + int pos, + int npos, + const char *res, + std::size_t res_len, + bool should_throw) { #undef TEST -#define TEST(charT, Traits) \ - test_erase (charT (), (Traits*)0, pfid, line, which, \ +#define TEST(charT, Traits) \ + test_erase (charT (), (Traits*)0, pfid, line, which, \ str, str_len, pos, npos, res, res_len, should_throw) if (!rw_enabled (line)) { @@ -292,7 +294,8 @@ /**************************************************************************/ -void test_erase (MemFun *pfid, int which) +static void +test_erase (MemFun *pfid, int which) { rw_info (0, 0, 0, "std::basic_string<%s, %s<%1$s>, %s<%1$s>>::" "erase (%{?}%{?}size_type pos%{;}%{?}, size_type n%{;}%{;}" @@ -335,17 +338,17 @@ TEST ("abc", 1, 2, "a", false); TEST ("abc", 0, 3, "", false); - TEST ("t\000 s", 0, 1, "\0 s", false); - TEST ("t\000 s", 1, 1, "t s", false); - TEST ("t\000 s", 2, 2, "t\0", false); - TEST ("t\000 s", 1, 2, "ts", false); - TEST ("t\000 s", 0, 2, " s", false); - TEST ("t\000 s", 0, 4, "", false); - TEST ("t\000 s", -1, -1, "", false); + TEST ("t\0 s", 0, 1, "\0 s", false); + TEST ("t\0 s", 1, 1, "t s", false); + TEST ("t\0 s", 2, 2, "t\0", false); + TEST ("t\0 s", 1, 2, "ts", false); + TEST ("t\0 s", 0, 2, " s", false); + TEST ("t\0 s", 0, 4, "", false); + TEST ("t\0 s", -1, -1, "", false); - TEST ("t\000 s", 0, -2, "\0 s", false); - TEST ("t\000 s", 1, -2, "t s", false); - TEST ("t\000 s", 2, -2, "t\0s", false); + TEST ("t\0 s", 0, -2, "\0 s", false); + TEST ("t\0 s", 1, -2, "t s", false); + TEST ("t\0 s", 2, -2, "t\0s", false); TEST ("\0a\0b", 0, 3, "b", false); TEST ("\0a\0b", 1, 1, "\0\0b", false); @@ -446,7 +449,8 @@ /**************************************************************************/ -int run_test (int, char*[]) +static int +run_test (int, char*[]) { if ('\0' == long_string [0]) { // initialize long_string @@ -505,7 +509,8 @@ { return rw_test (argc, argv, __FILE__, "lib.string.erase", - 0 /* no comment */, run_test, + 0 /* no comment */, + run_test, "|-no-char_traits# " "|-no-user_traits# ", "|-no-user_chars", --------------080803000204010906000306--