Return-Path: Delivered-To: apmail-incubator-stdcxx-commits-archive@www.apache.org Received: (qmail 11571 invoked from network); 9 Aug 2006 01:12:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 9 Aug 2006 01:12:28 -0000 Received: (qmail 3981 invoked by uid 500); 9 Aug 2006 01:12:28 -0000 Delivered-To: apmail-incubator-stdcxx-commits-archive@incubator.apache.org Received: (qmail 3959 invoked by uid 500); 9 Aug 2006 01:12:28 -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 3948 invoked by uid 99); 9 Aug 2006 01:12:27 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Aug 2006 18:12:27 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Aug 2006 18:12:27 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 068FD1A981A; Tue, 8 Aug 2006 18:12:07 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r429911 - /incubator/stdcxx/trunk/tests/localization/22.locale.messages.cpp Date: Wed, 09 Aug 2006 01:12:06 -0000 To: stdcxx-commits@incubator.apache.org From: sebor@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060809011207.068FD1A981A@eris.apache.org> 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 Aug 8 18:12:06 2006 New Revision: 429911 URL: http://svn.apache.org/viewvc?rev=429911&view=rev Log: 2006-08-08 Martin Sebor * messages.cpp (test_has_facet): Exercised the behavior of has_facet and use_facet with messages_byname (in addition to the base class). (test_use_nls_path): Handled getcwd() errors, called open_catalog instead of invoking messages::open() directly. (open_catalog, test_open_close, test_use_codecvt): Added missing argument to rw_assert(). (stress_test): Asserted a precondition. Modified: incubator/stdcxx/trunk/tests/localization/22.locale.messages.cpp Modified: incubator/stdcxx/trunk/tests/localization/22.locale.messages.cpp URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/localization/22.locale.messages.cpp?rev=429911&r1=429910&r2=429911&view=diff ============================================================================== --- incubator/stdcxx/trunk/tests/localization/22.locale.messages.cpp (original) +++ incubator/stdcxx/trunk/tests/localization/22.locale.messages.cpp Tue Aug 8 18:12:06 2006 @@ -2,7 +2,7 @@ * * 22.locale.messages.cpp - tests exercising the std::messages facet * - * $Id: //stdlib/dev/tests/stdlib/locale/messages.cpp#43 $ + * $Id: //stdlib/dev/tests/stdlib/locale/messages.cpp#45 $ * *************************************************************************** * @@ -353,25 +353,71 @@ template void test_has_facet (const char *loc_name, const char *cname) { - const std::locale loc (loc_name); + // construct a copy of the named locale or default + // when no name is specified + const std::locale loc = + loc_name ? std::locale (loc_name) : std::locale (); typedef std::messages Messages; - const bool facet_exists = std::has_facet (loc); + // verify that the facet exists in the locale + bool facet_exists = std::has_facet(loc); rw_assert (facet_exists, 0, __LINE__, - "has_facet >(locale(%#s)) == true", - cname, loc_name); + "has_facet >(locale(%{?}%#s%{;})) == true", + cname, 0 != loc_name, loc_name); try { + // verify that use facet doesn't throw an exception std::use_facet(loc); } #ifndef _RWSTD_NO_EXCEPTIONS catch (std::exception &ex) { rw_assert (0, 0, __LINE__, - "use_fact >(locale(%#s)) unexpectedly threw " - "exception(%#s)", cname, loc_name, ex.what ()); + "use_fact >(locale(%{?}%#s%{;})) " + "unexpectedly threw exception(%#s)", + cname, 0 != loc_name, loc_name, ex.what ()); + } + catch (...) { + rw_assert (0, 0, __LINE__, + "use_fact >(locale(%{?}%#s%{;})) " + "unexpectedly threw an unknown exception", + cname, 0 != loc_name, loc_name); + } + + typedef std::messages_byname MessagesByname; + + const bool byname = loc_name + && std::strcmp (loc_name, "C") && std::strcmp (loc_name, "POSIX"); + + facet_exists = std::has_facet(loc); + + rw_assert (byname == facet_exists, 0, __LINE__, + "has_fact >(locale(%{?}%#s%{;})) == %b", + cname, 0 != loc_name, loc_name); + + try { + // verify that use facet throws an exception only + // for the default and "C" locales + std::use_facet(loc); + + rw_assert (byname, 0, __LINE__, + "use_fact >(locale(%{?}%#s%{;})) " + "failed to throw", + cname, 0 != loc_name, loc_name); + } + catch (std::exception &ex) { + rw_assert (!byname, 0, __LINE__, + "use_fact >(locale(%{?}%#s%{;})) " + "unexpectedly threw exception(%#s)", + cname, 0 != loc_name, loc_name, ex.what ()); + } + catch (...) { + rw_assert (0, 0, __LINE__, + "use_fact >(locale(%{?}%#s%{;})) " + "unexpectedly threw an unknown exception", + cname, 0 != loc_name, loc_name); } #endif // _RWSTD_NO_EXCEPTIONS @@ -393,9 +439,9 @@ cat = (msgs.open)(cat_name, loc); rw_assert (!expect_exception, 0, line, - "messages<%s>::open(%#s, locale(%#s)) failed " + "messages<%s>::open(%#s, locale(%#s)) ==> %d: failed " "to throw an expected exception", - cname, cat_name, loc.name ().c_str ()); + cname, cat_name, loc.name ().c_str (), cat); } #ifndef _RWSTD_NO_EXCEPTIONS @@ -433,7 +479,8 @@ rw_assert (!expect_exception, 0, line, "messages<%s>::close(%d) failed " - "to throw an expected exception", cname); + "to throw an expected exception", + cname, cat); } #ifndef _RWSTD_NO_EXCEPTIONS @@ -490,7 +537,7 @@ 0, __LINE__, "std::messages<%s>::close() leaked %d file descriptor(s) " "(or descriptor mismatch)", - fdcount [1] - fdcount [0]); + cname, fdcount [1] - fdcount [0]); } /***************************************************************************/ @@ -606,7 +653,7 @@ if (!rw_error (-1 < cat, 0, __LINE__, "messages<%s>::open(%#s, locale(%#s)) >= -1, got %d", - CAT_NAME, loc.name ().c_str (), cat)) + cname, CAT_NAME, loc.name ().c_str (), cat)) return; cvt.check_state_ = true; @@ -653,9 +700,13 @@ void test_use_nls_path (const char *cname) { // get working directory - char cwd[2048]; - getcwd(cwd, 2048); - char *nlspath = new char[std::strlen(cwd) + 512]; + char cwd [2048]; + cwd [0] = '\0'; + if (!rw_error (0 != getcwd (cwd, 2048), 0, __LINE__, + "getcwd(%#p, %u) failed: %{#m} (%m)", cwd, 2048)) + return; + + char* const nlspath = new char [std::strlen (cwd) + 512]; // create NLSPATH string std::sprintf (nlspath, "NLSPATH=%s/%%N.cat", cwd); @@ -666,7 +717,8 @@ const std::messages& msgs = std::use_facet >(loc); - const std::messages_base::catalog cat = (msgs.open)(NLS_CAT_NAME, loc); + const std::messages_base::catalog cat = + open_catalog (msgs, NLS_CAT_NAME, loc, false, "char", __LINE__); if (-1 == cat) { @@ -689,6 +741,9 @@ template void stress_test (const char *cname) { + // NLSPATH must be defined + RW_ASSERT (0 != std::getenv ("NLSPATH")); + char catalog_names [24][24]; std::messages_base::catalog cats[24]; @@ -793,7 +848,14 @@ { if (rw_note (0 <= opt_has_facet, 0, __LINE__, "has_facet > tests disabled", cname)) { + + // exercise has_facet and use_facet in the default locale + test_has_facet(0, cname); + + // exercise has_facet and use_facet in locale("C") test_has_facet("C", cname); + + // exercise has_facet and use_facet in a named locale test_has_facet(locname, cname); }