From stdcxx-commits-return-517-apmail-incubator-stdcxx-commits-archive=incubator.apache.org@incubator.apache.org Tue Mar 07 20:56:25 2006 Return-Path: Delivered-To: apmail-incubator-stdcxx-commits-archive@www.apache.org Received: (qmail 30767 invoked from network); 7 Mar 2006 20:56:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 7 Mar 2006 20:56:25 -0000 Received: (qmail 17302 invoked by uid 500); 7 Mar 2006 20:56:25 -0000 Delivered-To: apmail-incubator-stdcxx-commits-archive@incubator.apache.org Received: (qmail 17282 invoked by uid 500); 7 Mar 2006 20:56:25 -0000 Mailing-List: contact stdcxx-commits-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-commits@incubator.apache.org Received: (qmail 17271 invoked by uid 500); 7 Mar 2006 20:56:24 -0000 Delivered-To: apmail-incubator-stdcxx-cvs@incubator.apache.org Received: (qmail 17268 invoked by uid 99); 7 Mar 2006 20:56:24 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Mar 2006 12:56:24 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 07 Mar 2006 12:56:23 -0800 Received: (qmail 30641 invoked by uid 65534); 7 Mar 2006 20:56:03 -0000 Message-ID: <20060307205603.30638.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r384007 - /incubator/stdcxx/trunk/tests/strings/21.string.capacity.cpp Date: Tue, 07 Mar 2006 20:56:03 -0000 To: stdcxx-cvs@incubator.apache.org From: sebor@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: sebor Date: Tue Mar 7 12:56:01 2006 New Revision: 384007 URL: http://svn.apache.org/viewcvs?rev=384007&view=rev Log: 2006-03-07 Anton Pevstov * 21.string.capacity.cpp: Handled embedded NUL characters correctly. Added test cases and comments. Modified: incubator/stdcxx/trunk/tests/strings/21.string.capacity.cpp Modified: incubator/stdcxx/trunk/tests/strings/21.string.capacity.cpp URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/strings/21.string.capacity.cpp?rev=384007&r1=384006&r2=384007&view=diff ============================================================================== --- incubator/stdcxx/trunk/tests/strings/21.string.capacity.cpp (original) +++ incubator/stdcxx/trunk/tests/strings/21.string.capacity.cpp Tue Mar 7 12:56:01 2006 @@ -86,20 +86,16 @@ /**************************************************************************/ template -void widen (charT *buf, const char *str) +void widen (charT *buf, const char *str, const std::size_t str_len) { typedef unsigned char UChar; - buf [0] = '\0'; + buf[0] = charT (UChar ('\0')); + RW_ASSERT (str_len < sizeof long_string); if (str) { - for (const char *pc = str; ; ++pc) { - buf [pc - str] = charT (UChar (*pc)); - if ('\0' == *pc) { - RW_ASSERT (std::size_t (pc - str) < sizeof long_string); - break; - } - } + for (std::size_t i = 0; i < str_len; i++) + buf[i] = charT (UChar (str[i])); } } @@ -160,7 +156,7 @@ // check the results static charT wstr_tmp [long_string_len]; - widen (wstr_tmp, str); + widen (wstr_tmp, str, str_len); std::size_t ubound = nparam < str_len ? nparam : str_len; bool success = true; @@ -239,9 +235,9 @@ // widen the source sequence into the (possibly wide) character buffer static charT wstr [long_string_len]; - 0 == str ? widen (wstr, "a") : widen (wstr, str); + widen (wstr, str, str_len); - TestString str_ob (wstr); + TestString str_ob (wstr, str_len); TestString str_def; TestString* const pstr = 0 != str ? &str_ob : &str_def; @@ -299,11 +295,11 @@ break; } -#define CALLFMAT \ - "line %d. basic_string<%s, %s<%2$s>, %s<%2$s>>(%{?}%{#*S}%{;})" \ +#define CALLFMAT \ + "line %d. basic_string<%s, %s<%2$s>, %s<%2$s>>(%{?}%{#*S}%{;})" \ ".%s(%{?}%zu%{;})" -#define CALLARGS \ +#define CALLARGS \ __LINE__, pfid->cname_, pfid->tname_, pfid->aname_, \ 0 != str, int (sizeof (charT)), pstr, pfid->fname_, \ MemFun::reserve == pfid->mfun_, nparam @@ -320,7 +316,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); @@ -440,23 +436,34 @@ test_string_capacity (pfid, __LINE__, str, sizeof str - 1, \ 0, 0, size, false) - TEST (0, 0); - TEST ("", 0); - - TEST ("\0", 0); - TEST ("a", 1); - TEST (" ", 1); - TEST ("ab", 2); - TEST ("bc", 2); - - TEST ("test string", 11); - TEST ("Test String", 11); - - TEST ("t\000 s", 1); - TEST ("Test\0string", 4); - TEST ("Test\000string", 4); + // +--------------------------------------- controlled sequence + // | +---------------------- expected result + // | | + // | | + // V V + TEST (0, 0); + TEST ("", 0); + + TEST ("\0", 1); + TEST ("a", 1); + TEST (" ", 1); + TEST ("ab", 2); + TEST ("bc", 2); + + TEST ("test string", 11); + TEST ("Test String", 11); + + TEST ("t\0 s", 4); + TEST ("Test\0string", 11); + + TEST ("\0a\0b", 4); + TEST ("a\0\0b", 4); + TEST ("a\0\0\0b", 5); + TEST ("a\0\0b\0", 5); + TEST ("a\0b\0\0c", 6); + TEST ("a\0b\0c\0\0", 7); - TEST (long_string, long_string_len - 1); + TEST (long_string, long_string_len - 1); } /**************************************************************************/ @@ -473,30 +480,44 @@ test_string_capacity (pfid, __LINE__, str, len, nparam, \ cparam, 0, ex_throw) - TEST ("\0", 0, 0, 'a', false); - TEST ("\0", 0, 10, 'a', false); - - TEST ("a", 1, 1, 'a', false); - TEST ("a", 1, 0, 'a', false); - TEST ("a", 1, 10, 'a', false); - - TEST ("ab", 2, 2, 'a', false); - TEST ("ab", 2, 1, 'a', false); - TEST ("ab", 2, 10, 'a', false); + // +--------------------------------------- controlled sequence + // | +----------------------- controlled sequence length + // | | +-- resize() integer argument + // | | | +-- resize() char argument + // | | | | +--exception expected? + // | | | | | + // V V V V V + TEST ("\0", 0, 0, 'a', false); + TEST ("\0", 0, 10, 'a', false); + + TEST ("a", 1, 1, 'a', false); + TEST ("a", 1, 0, 'a', false); + TEST ("a", 1, 10, 'a', false); + + TEST ("ab", 2, 2, 'a', false); + TEST ("ab", 2, 1, 'a', false); + TEST ("ab", 2, 10, 'a', false); + + TEST ("t\0 s", 4, 6, 'a', false); + TEST ("Test\0string", 11, 100, 'a', false); + + TEST ("a\0\0\0b", 5, 10, 'a', false); + TEST ("a\0\0\0b", 5, 10, '\0', false); - TEST ("t\000 s", 1, 6, 'a', false); - TEST ("Test\0string", 4, 100, 'a', false); + TEST ("a\0b\0c\0\0", 7, 10, 'a', false); + TEST ("a\0b\0c\0\0", 7, 10, '\0', false); - TEST ("bc", 2, long_string_len - 1, 'a', false); + TEST ("bc", 2, long_string_len - 1, 'a', false); - TEST (long_string, long_string_len - 1, 10, 'a', false); + TEST (long_string, long_string_len - 1, 10, 'a', false); TEST (long_string, long_string_len - 1, long_string_len - 1, 'a', false); #ifndef _RWSTD_NO_EXCEPTIONS if (_RWSTD_SIZE_MAX > pfid->max_size_) { + TEST ("\0", 1, pfid->max_size_ + 1, 'a', true); - TEST ("a", 1, pfid->max_size_ + 1, 'a', true); + TEST ("a" , 1, pfid->max_size_ + 1, 'a', true); TEST (long_string, long_string_len - 1, pfid->max_size_ + 1, 'a', true); } @@ -512,28 +533,35 @@ test_string_capacity (pfid, __LINE__, str, sizeof str - 1, \ nparam, -1, 0, ex_throw) - TEST ("\0", 0, false); - TEST ("\0", 10, false); - - TEST ("a", 1, false); - TEST ("a", 0, false); - TEST ("a", 10, false); - - TEST ("ab", 2, false); - TEST ("ab", 1, false); - TEST ("ab", 10, false); + // +---------------------------------------- controlled sequence + // | +-------------------------- resize() integer argument + // | | +-- exception expected? + // | | | + // V V V + TEST ("\0", 0, false); + TEST ("\0", 10, false); + + TEST ("a", 1, false); + TEST ("a", 0, false); + TEST ("a", 10, false); + + TEST ("ab", 2, false); + TEST ("ab", 1, false); + TEST ("ab", 10, false); - TEST ("bc", long_string_len - 1, false); + TEST ("bc", long_string_len - 1, false); - TEST (long_string, 10, false); - TEST (long_string, long_string_len - 1, false); + TEST (long_string, 10, false); + TEST (long_string, long_string_len - 1, false); #ifndef _RWSTD_NO_EXCEPTIONS if (_RWSTD_SIZE_MAX > pfid->max_size_) { - TEST ("\0", pfid->max_size_ + 1, true); - TEST ("a", pfid->max_size_ + 1, true); - TEST (long_string, pfid->max_size_ + 1, true); + + TEST ("\0", pfid->max_size_ + 1, true); + TEST ("a", pfid->max_size_ + 1, true); + TEST (long_string, pfid->max_size_ + 1, true); + } #endif // _RWSTD_NO_EXCEPTIONS @@ -548,29 +576,37 @@ pfid->cname_, pfid->tname_, pfid->aname_); #undef TEST -#define TEST(str, size) \ - test_string_capacity (pfid, __LINE__, str, sizeof str - 1, \ +#define TEST(str, size) \ + test_string_capacity (pfid, __LINE__, str, sizeof str - 1, \ 0, 0, size, false) - TEST (0, 0); - TEST ("", 0); - - TEST ("\0", 0); - TEST ("a", 1); - TEST (" ", 1); - TEST ("ab", 2); - TEST ("bc", 2); - - TEST ("test string", 11); - TEST ("Test String", 11); - - TEST ("t\000 s", 1); - TEST ("Test\0string", 4); - TEST ("Test\000string", 4); - - TEST (long_string, long_string_len - 1); + // +--------------------------------------- controlled sequence + // | +---------------------- expected result + // | | + // | | + // V V + TEST (0, 0); + TEST ("", 0); + + TEST ("\0", 1); + TEST ("a", 1); + TEST (" ", 1); + TEST ("ab", 2); + TEST ("bc", 2); + + TEST ("Test String", 11); + + TEST ("t\0 s", 4); + TEST ("Test\0string", 11); + + TEST ("\0a\0b", 4); + TEST ("a\0\0b", 4); + TEST ("a\0\0\0b", 5); + TEST ("a\0\0b\0", 5); + TEST ("a\0b\0\0c", 6); + TEST ("a\0b\0c\0\0", 7); -#undef TEST + TEST (long_string, long_string_len - 1); } /**************************************************************************/ @@ -581,8 +617,9 @@ "std::basic_string<%s, %s<%1$s>, %s<%1$s>>::reserve (size_type)", pfid->cname_, pfid->tname_, pfid->aname_); -#define TEST(str, nparam, ex_throw) \ - test_string_capacity (pfid, __LINE__, str, sizeof str - 1, \ +#undef TEST +#define TEST(str, nparam, ex_throw) \ + test_string_capacity (pfid, __LINE__, str, sizeof str - 1, \ nparam, 0, 0, ex_throw) // +--------------------------------------- controlled sequence @@ -604,8 +641,12 @@ TEST ("abcd", 10, false); TEST ("abcd", long_string_len - 1, false); - TEST ("t\000 s", 1, false); + TEST ("t\0 s", 1, false); TEST ("Test\0string", 4, false); + TEST ("a\0\0b", 2, false); + TEST ("a\0\0b", 10, false); + TEST ("a\0b\0c\0\0", 4, false); + TEST ("a\0b\0c\0\0", 10, false); TEST (long_string, 10, false); TEST (long_string, long_string_len - 1, false); @@ -634,16 +675,25 @@ test_string_capacity (pfid, __LINE__, str, sizeof str - 1, \ 0, 0, size, false) - TEST (0, 0); - TEST ("\0", 0); + // +--------------------------------------- controlled sequence + // | +---------------------- expected result + // | | + // | | + // V V + TEST (0, 0); + TEST ("\0", 0); - TEST ("a", 128); - TEST ("abcd", 128); + TEST ("a", 128); + TEST ("abcd", 128); - TEST ("t\000 s", 128); + TEST ("t\0 s", 128); TEST ("Test\0string", 128); - TEST (long_string, long_string_len - 1); + TEST ("\0a\0b", 128); + TEST ("a\0\0\0b", 128); + TEST ("a\0b\0c\0\0", 128); + + TEST (long_string, long_string_len - 1); } /**************************************************************************/ @@ -682,9 +732,13 @@ TEST ("ab"); TEST ("abcde"); - TEST ("t\000 s"); + TEST ("t\0 s"); TEST ("Test\0string"); + TEST ("\0a\0b"); + TEST ("a\0\0\0b"); + TEST ("a\0b\0c\0\0"); + TEST (long_string); } @@ -698,23 +752,25 @@ pfid->mfun_ = MemFun::empty; #undef TEST -#define TEST(str, res) \ +#define TEST(str) \ test_string_capacity (pfid, __LINE__, str, sizeof str - 1, \ - 0, 0, res, false) + 0, 0, 0, false) - TEST (0, 1); - TEST ("\0", 1); - TEST ("a", 0); - TEST ("ab", 0); - TEST ("abcde", 0); - - TEST ("\000 s", 1); - TEST ("t\000 s", 0); - TEST ("Test\0string", 0); + TEST (0); + TEST ("\0"); + TEST ("a"); + TEST ("ab"); + TEST ("abcde"); - TEST (long_string, 0); + TEST ("\0 s"); + TEST ("t\0 s"); + TEST ("Test\0string"); -#undef TEST + TEST ("\0a\0b"); + TEST ("a\0\0\0b"); + TEST ("a\0b\0c\0\0"); + + TEST (long_string); } /**************************************************************************/ @@ -762,7 +818,7 @@ TEST (capacity); TEST (max_size); TEST (clear); - TEST (empty); + TEST (empty); } } @@ -822,7 +878,8 @@ { return rw_test (argc, argv, __FILE__, "lib.string.capacity", - 0 /* no comment */, run_test, + 0 /* no comment */, + run_test, "|-no-size# " "|-no-resize# " "|-no-length# "