stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r551428 - in /incubator/stdcxx/trunk/tests: include/ localization/ src/
Date Thu, 28 Jun 2007 01:50:18 GMT
Author: sebor
Date: Wed Jun 27 18:50:17 2007
New Revision: 551428

URL: http://svn.apache.org/viewvc?view=rev&rev=551428
Log:
2007-06-27  Martin Sebor  <sebor@roguewave.com>

	* rw_locale.h (rw_opt_locales): New constant pointing to a
	NUL-separated list of locale names specified by the --locales
	command line option (set by the rw_opt_setlocales handler).
	(rw_opt_setlocales): Callback function invoked in response to
	the --locales=<locale-list> command line option to set the
	rw_opt_locales global variable to a NUL-separated list of
	locale names to exercise.
	* locale.cpp (<cstdio>): Avoided #including C++ header (the C
	header is sufficient and preferable).
	(rw_create_locale): Removed std:: qualification from C library
	names.
	(_rw_locale_names): Static global helper.
	(rw_opt_locales): Defined and initialized to refer to the above.
	(rw_opt_setlocale): Defined.
	* 22.locale.moneypunct.mt.cpp (run_test): Used rw_opt_locales.
	(rw_opt_setlocales): Removed definition.
	* 22.locale.time.put.mt.cpp (rw_opt_nthreads): Initialzed to 1,
	and overwrote in main() with the result of rw_get_cpus() when
	thread safety is being exercised.
	(run_test): Used rw_opt_locales.
	(main): Used rw_opt_setlocales to handle the --locales option.
	* 22.locale.num.put.mt.cpp: Same.
	* 22.locale.numpunct.mt.cpp: Same.
	* 22.locale.money.put.mt.cpp: Same.

Modified:
    incubator/stdcxx/trunk/tests/include/rw_locale.h
    incubator/stdcxx/trunk/tests/localization/22.locale.money.put.mt.cpp
    incubator/stdcxx/trunk/tests/localization/22.locale.moneypunct.mt.cpp
    incubator/stdcxx/trunk/tests/localization/22.locale.num.put.mt.cpp
    incubator/stdcxx/trunk/tests/localization/22.locale.numpunct.mt.cpp
    incubator/stdcxx/trunk/tests/localization/22.locale.time.put.mt.cpp
    incubator/stdcxx/trunk/tests/src/locale.cpp

Modified: incubator/stdcxx/trunk/tests/include/rw_locale.h
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/include/rw_locale.h?view=diff&rev=551428&r1=551427&r2=551428
==============================================================================
--- incubator/stdcxx/trunk/tests/include/rw_locale.h (original)
+++ incubator/stdcxx/trunk/tests/include/rw_locale.h Wed Jun 27 18:50:17 2007
@@ -1,27 +1,28 @@
 /************************************************************************
  *
- * localedef.h - declarations of locale testsuite helpers
+ * rw_locale.h - declarations of locale testsuite helpers
  *
  * $Id$
  *
  ************************************************************************
  *
- * Copyright 2005-2006 The Apache Software Foundation or its licensors,
- * as applicable.
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
  *
- * Copyright 2001-2006 Rogue Wave Software.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 2001-2006 Rogue Wave Software.
  * 
  **************************************************************************/
 
@@ -91,5 +92,17 @@
 _TEST_EXPORT const char*
 rw_create_locale (const char *charmap, const char *locale);
 
+
+// NUL-separated list of locale names specified by the --locales
+// command line option (set by the rw_opt_setlocales handler)
+_TEST_EXPORT extern const char* const&
+rw_opt_locales;
+
+
+// callback function invoked in response to the --locales=<locale-list>
+// command line option to set the rw_opt_locales global variable to the
+// NUL-separated list of locale names to exercise
+_TEST_EXPORT int
+rw_opt_setlocales (int, char*[]);
 
 #endif   // RW_LOCALE_H_INCLUDED

Modified: incubator/stdcxx/trunk/tests/localization/22.locale.money.put.mt.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/localization/22.locale.money.put.mt.cpp?view=diff&rev=551428&r1=551427&r2=551428
==============================================================================
--- incubator/stdcxx/trunk/tests/localization/22.locale.money.put.mt.cpp (original)
+++ incubator/stdcxx/trunk/tests/localization/22.locale.money.put.mt.cpp Wed Jun 27 18:50:17
2007
@@ -40,13 +40,9 @@
 // maximum number of threads allowed by the command line interface
 #define MAX_THREADS   32
 
-
-#ifdef _RWSTD_REENTRANT
-int rw_opt_nthreads = 4;
-#else   // if !defined (_RWSTD_REENTRANT)
-// in non-threaded builds use just one thread
+// default number of threads (will be adjusted to the number
+// of processors/cores later)
 int rw_opt_nthreads = 1;
-#endif   // _RWSTD_REENTRANT
 
 // the number of times each thread should iterate (unless specified
 // otherwise on the command line)
@@ -142,7 +138,7 @@
 
             const std::ostreambuf_iterator<char> iter (&sb);
 
-            switch (PutId (i % put_max)) {
+            switch (i % put_max) {
             case put_ldbl:
                 mp.put (iter, intl, io, ' ', ldval);
                 break;
@@ -169,7 +165,7 @@
 
             const std::ostreambuf_iterator<wchar_t> iter (&wb);
 
-            switch (PutId (i % put_max)) {
+            switch (i % put_max) {
             case put_ldbl:
                 mp.put (iter, intl, io, ' ', ldval);
                 break;
@@ -198,11 +194,13 @@
 static int
 run_test (int, char**)
 {
-    char* const locale_list = rw_locales ();
+    // find all installed locales for which setlocale(LC_ALL) succeeds
+    const char* const locale_list =
+        rw_opt_locales ? rw_opt_locales : rw_locales (_RWSTD_LC_ALL);
 
     const std::size_t maxinx = sizeof locales / sizeof *locales;
 
-    for (char *name = locale_list; *name; name += std::strlen (name) + 1) {
+    for (const char *name = locale_list; *name; name += std::strlen (name) +1) {
         locales [nlocales++] = name;
 
         if (nlocales == maxinx)
@@ -271,12 +269,21 @@
 
 int main (int argc, char *argv[])
 {
+#ifdef _RWSTD_REENTRANT
+
+    // set nthreads to the number of processors by default
+    rw_opt_nthreads = rw_get_cpus ();
+
+#endif   // _RWSTD_REENTRANT
+
     return rw_test (argc, argv, __FILE__,
                     "lib.locale.money.put",
                     "thread safety", run_test,
-                    "|-nloops#0 "       // must be non-negative
-                    "|-nthreads#0-*",   // must be in [0, MAX_THREADS]
+                    "|-nloops#0 "        // must be non-negative
+                    "|-nthreads#0-* "    // must be in [0, MAX_THREADS]
+                    "|-locales=",        // must be provided
                     &rw_opt_nloops,
                     int (MAX_THREADS),
-                    &rw_opt_nthreads);
+                    &rw_opt_nthreads,
+                    &rw_opt_setlocales);
 }

Modified: incubator/stdcxx/trunk/tests/localization/22.locale.moneypunct.mt.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/localization/22.locale.moneypunct.mt.cpp?view=diff&rev=551428&r1=551427&r2=551428
==============================================================================
--- incubator/stdcxx/trunk/tests/localization/22.locale.moneypunct.mt.cpp (original)
+++ incubator/stdcxx/trunk/tests/localization/22.locale.moneypunct.mt.cpp Wed Jun 27 18:50:17
2007
@@ -252,15 +252,11 @@
 
 /**************************************************************************/
 
-static char*
-rw_opt_locales;
-
-
 static int
 run_test (int, char**)
 {
     // find all installed locales for which setlocale(LC_ALL) succeeds
-    char* const locale_list =
+    const char* const locale_list =
         rw_opt_locales ? rw_opt_locales : rw_locales (_RWSTD_LC_ALL);
 
     // array of locale names to use for testing
@@ -269,7 +265,7 @@
     const std::size_t maxinx = sizeof locales / sizeof *locales;
 
     // iterate over locales, initializing a global punct_data array
-    for (char *name = locale_list; *name; name += std::strlen (name) + 1) {
+    for (const char *name = locale_list; *name; name += std::strlen (name) +1) {
 
         std::locale loc;
 
@@ -464,37 +460,6 @@
 
 /**************************************************************************/
 
-static int
-rw_opt_setlocales (int argc, char* argv[])
-{
-    RW_ASSERT (0 < argc && argv [0]);
-
-    rw_opt_locales = std::strchr (argv [0], '=');
-
-    if (rw_opt_locales) {
-
-        const std::size_t len = std::strlen (++rw_opt_locales);
-        char* const locale_names = new char [len + 2];
-
-        locale_names [len + 1] = '\0';
-
-        std::memcpy (locale_names, rw_opt_locales, len);
-
-        rw_opt_locales = locale_names;
-
-        for (char *next = rw_opt_locales; ; ) {
-            next = std::strpbrk (next, ", ");
-            if (next)
-                *next++ = '\0';
-            else
-                break;
-        }
-    }
-
-    return 0;
-}
-
-
 int main (int argc, char *argv[])
 {
 #ifdef _RWSTD_REENTRANT
@@ -508,7 +473,7 @@
                     "lib.locale.moneypunct",
                     "thread safety", run_test,
                     "|-nloops#0 "       // must be non-negative
-                    "|-nthreads#0-*"    // must be in [0, MAX_THREADS]
+                    "|-nthreads#0-* "   // must be in [0, MAX_THREADS]
                     "|-locales=",       // must be provided
                     &rw_opt_nloops,
                     int (MAX_THREADS),

Modified: incubator/stdcxx/trunk/tests/localization/22.locale.num.put.mt.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/localization/22.locale.num.put.mt.cpp?view=diff&rev=551428&r1=551427&r2=551428
==============================================================================
--- incubator/stdcxx/trunk/tests/localization/22.locale.num.put.mt.cpp (original)
+++ incubator/stdcxx/trunk/tests/localization/22.locale.num.put.mt.cpp Wed Jun 27 18:50:17
2007
@@ -33,20 +33,16 @@
 #include <cstring>    // for strlen()
 
 #include <rw_locale.h>
-#include <rw_thread.h>
+#include <rw_thread.h>   // for rw_get_processors (), rw_thread_pool()
 #include <driver.h>
 
 
 // maximum number of threads allowed by the command line interface
 #define MAX_THREADS   32
 
-
-#ifdef _RWSTD_REENTRANT
-int rw_opt_nthreads = 4;
-#else   // if !defined (_RWSTD_REENTRANT)
-// in non-threaded builds use just one thread
+// default number of threads (will be adjusted to the number
+// of processors/cores later)
 int rw_opt_nthreads = 1;
-#endif   // _RWSTD_REENTRANT
 
 // the number of times each thread should iterate (unless specified
 // otherwise on the command line)
@@ -164,7 +160,7 @@
 
             const std::ostreambuf_iterator<char> iter (&sb);
 
-            switch (PutId (i % put_max)) {
+            switch (i % put_max) {
             case put_bool:
                 if (i & 2)
                     io.setf (std::ios::boolalpha);
@@ -220,7 +216,7 @@
 
             const std::ostreambuf_iterator<wchar_t> iter (&wb);
 
-            switch (PutId (i % put_max)) {
+            switch (i % put_max) {
             case put_bool:
                 np.put (iter, io, L' ', bool (ival));
                 break;
@@ -273,11 +269,14 @@
 static int
 run_test (int, char**)
 {
-    char* const locale_list = rw_locales ();
+    // find all installed locales for which setlocale(LC_ALL) succeeds
+    const char* const locale_list =
+        rw_opt_locales ? rw_opt_locales : rw_locales (_RWSTD_LC_ALL);
 
     const std::size_t maxinx = sizeof locales / sizeof *locales;
 
-    for (char *name = locale_list; *name; name += std::strlen (name) + 1) {
+    for (const char *name = locale_list; *name; name += std::strlen (name) +1) {
+
         locales [nlocales++] = name;
 
         if (nlocales == maxinx)
@@ -345,12 +344,21 @@
 
 int main (int argc, char *argv[])
 {
+#ifdef _RWSTD_REENTRANT
+
+    // set nthreads to the number of processors by default
+    rw_opt_nthreads = rw_get_cpus ();
+
+#endif   // _RWSTD_REENTRANT
+
     return rw_test (argc, argv, __FILE__,
                     "lib.locale.num.put",
                     "thread safety", run_test,
-                    "|-nloops#0 "       // must be non-negative
-                    "|-nthreads#0-*",   // must be in [0, MAX_THREADS]
+                    "|-nloops#0 "        // must be non-negative
+                    "|-nthreads#0-* "    // must be in [0, MAX_THREADS]
+                    "|-locales=",        // must be provided
                     &rw_opt_nloops,
                     int (MAX_THREADS),
-                    &rw_opt_nthreads);
+                    &rw_opt_nthreads,
+                    &rw_opt_setlocales);
 }

Modified: incubator/stdcxx/trunk/tests/localization/22.locale.numpunct.mt.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/localization/22.locale.numpunct.mt.cpp?view=diff&rev=551428&r1=551427&r2=551428
==============================================================================
--- incubator/stdcxx/trunk/tests/localization/22.locale.numpunct.mt.cpp (original)
+++ incubator/stdcxx/trunk/tests/localization/22.locale.numpunct.mt.cpp Wed Jun 27 18:50:17
2007
@@ -41,13 +41,9 @@
 // maximum number of threads allowed by the command line interface
 #define MAX_THREADS   32
 
-
-#ifdef _RWSTD_REENTRANT
-int rw_opt_nthreads = 4;
-#else   // if !defined (_RWSTD_REENTRANT)
-// in non-threaded builds use just one thread
+// default number of threads (will be adjusted to the number
+// of processors/cores later)
 int rw_opt_nthreads = 1;
-#endif   // _RWSTD_REENTRANT
 
 // the number of times each thread should iterate (unless specified
 // otherwise on the command line)
@@ -106,9 +102,6 @@
         // construct a named locale
         const std::locale loc (locale_name);
 
-        // exercise postive and negative values
-        const int ival = i & 1 ? -i : i;
-
         if (test_char) {
             // exercise the narrow char specialization of the facet
 
@@ -165,13 +158,14 @@
 static int
 run_test (int, char**)
 {
-    // get a NUL-separated list of names of installed locales
-    char* const locale_list = rw_locales ();
+    // find all installed locales for which setlocale(LC_ALL) succeeds
+    const char* const locale_list =
+        rw_opt_locales ? rw_opt_locales : rw_locales (_RWSTD_LC_ALL);
 
     const std::size_t maxinx = sizeof locales / sizeof *locales;
 
     // iterate over locales, initializing a global punct_data array
-    for (char *name = locale_list; *name; name += std::strlen (name) + 1) {
+    for (const char *name = locale_list; *name; name += std::strlen (name) +1) {
 
         const std::size_t inx = nlocales;
 
@@ -286,12 +280,21 @@
 
 int main (int argc, char *argv[])
 {
+#ifdef _RWSTD_REENTRANT
+
+    // set nthreads to the number of processors by default
+    rw_opt_nthreads = rw_get_cpus ();
+
+#endif   // _RWSTD_REENTRANT
+
     return rw_test (argc, argv, __FILE__,
                     "lib.locale.numpunct",
                     "thread safety", run_test,
-                    "|-nloops#0 "       // must be non-negative
-                    "|-nthreads#0-*",   // must be in [0, MAX_THREADS]
+                    "|-nloops#0 "        // must be non-negative
+                    "|-nthreads#0-* "    // must be in [0, MAX_THREADS]
+                    "|-locales=",        // must be provided
                     &rw_opt_nloops,
                     int (MAX_THREADS),
-                    &rw_opt_nthreads);
+                    &rw_opt_nthreads,
+                    &rw_opt_setlocales);
 }

Modified: incubator/stdcxx/trunk/tests/localization/22.locale.time.put.mt.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/localization/22.locale.time.put.mt.cpp?view=diff&rev=551428&r1=551427&r2=551428
==============================================================================
--- incubator/stdcxx/trunk/tests/localization/22.locale.time.put.mt.cpp (original)
+++ incubator/stdcxx/trunk/tests/localization/22.locale.time.put.mt.cpp Wed Jun 27 18:50:17
2007
@@ -43,13 +43,9 @@
 #define MAX_THREADS      32
 #define MAX_LOOPS    100000
 
-
-#ifdef _RWSTD_REENTRANT
-int rw_opt_nthreads = 4;
-#else   // if !defined (_RWSTD_REENTRANT)
-// in non-threaded builds use just one thread
+// default number of threads (will be adjusted to the number
+// of processors/cores later)
 int rw_opt_nthreads = 1;
-#endif   // _RWSTD_REENTRANT
 
 // the number of times each thread should iterate
 int rw_opt_nloops = MAX_LOOPS;
@@ -73,13 +69,8 @@
 
 
 static void*
-thread_func (void *arg)
+thread_func (void*)
 {
-    const rw_thread_t* const pthread = (rw_thread_t*)arg;
-
-    // get the 0-based thread number
-    const std::size_t threadno = std::size_t (pthread->threadno);
-
     std::tm tmb = std::tm ();
 
     const char cvtspecs[] = "aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%";
@@ -169,11 +160,13 @@
 static int
 run_test (int, char**)
 {
-    char* const locale_list = rw_locales ();
+    // find all installed locales for which setlocale(LC_ALL) succeeds
+    const char* const locale_list =
+        rw_opt_locales ? rw_opt_locales : rw_locales (_RWSTD_LC_ALL);
 
     const std::size_t maxinx = sizeof locales / sizeof *locales;
 
-    for (char *name = locale_list; *name; name += std::strlen (name) + 1) {
+    for (const char *name = locale_list; *name; name += std::strlen (name) +1) {
         locales [nlocales++] = name;
 
         if (nlocales == maxinx)
@@ -241,12 +234,21 @@
 
 int main (int argc, char *argv[])
 {
+#ifdef _RWSTD_REENTRANT
+
+    // set nthreads to the number of processors by default
+    rw_opt_nthreads = rw_get_cpus ();
+
+#endif   // _RWSTD_REENTRANT
+
     return rw_test (argc, argv, __FILE__,
                     "lib.locale.time.put",
                     "thread safety", run_test,
                     "|-nloops#0 "       // must be non-negative
-                    "|-nthreads#0-*",   // must be in [0, MAX_THREADS]
+                    "|-nthreads#0-* "   // must be in [0, MAX_THREADS]
+                    "|-locales=",       // must be provided
                     &rw_opt_nloops,
                     int (MAX_THREADS),
-                    &rw_opt_nthreads);
+                    &rw_opt_nthreads,
+                    &rw_opt_setlocales);
 }

Modified: incubator/stdcxx/trunk/tests/src/locale.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/locale.cpp?view=diff&rev=551428&r1=551427&r2=551428
==============================================================================
--- incubator/stdcxx/trunk/tests/src/locale.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/locale.cpp Wed Jun 27 18:50:17 2007
@@ -36,7 +36,6 @@
 #include <file.h>         // for SHELL_RM_RF, rw_tmpnam
 #include <rw_printf.h>    // for rw_fprintf()
 #include <rw_process.h>   // for rw_system()
-#include <cstdio>
 
 
 #if defined (_RWSTD_OS_LINUX) && !defined (_XOPEN_SOURCE)
@@ -679,35 +678,35 @@
     // create a temporary locale definition file that exercises as
     // many different parts of the collate standard as possible
     char srcfname [256];
-    std::sprintf (srcfname, "%s%slocale.src", locale_root, SLASH);
+    sprintf (srcfname, "%s%slocale.src", locale_root, SLASH);
 
-    std::FILE *fout = std::fopen (srcfname, "w");
+    FILE *fout = fopen (srcfname, "w");
 
     if (!fout) {
-        std::fprintf (stderr, "%s:%d: fopen(\"%s\", \"w\") failed\n",
-                      __FILE__, __LINE__, srcfname);
+        fprintf (stderr, "%s:%d: fopen(\"%s\", \"w\") failed\n",
+                 __FILE__, __LINE__, srcfname);
         return 0;
     }
 
-       std::fprintf (fout, "%s", locale);
+       fprintf (fout, "%s", locale);
 
-    std::fclose (fout);
+    fclose (fout);
 
     // create a temporary character map file
     char cmfname [256];
-    std::sprintf (cmfname, "%s%scharmap.src", locale_root, SLASH);
+    sprintf (cmfname, "%s%scharmap.src", locale_root, SLASH);
 
-    fout = std::fopen (cmfname, "w");
+    fout = fopen (cmfname, "w");
 
     if (!fout) {
-        std::fprintf (stderr, "%s:%d: fopen(\"%s\", \"w\") failed\n",
-                      __FILE__, __LINE__, cmfname);
+        fprintf (stderr, "%s:%d: fopen(\"%s\", \"w\") failed\n",
+                 __FILE__, __LINE__, cmfname);
         return 0;
     }
 
-       std::fprintf (fout, "%s", charmap);
+       fprintf (fout, "%s", charmap);
 
-    std::fclose (fout);
+    fclose (fout);
 
        locname = "test-locale";
 
@@ -716,4 +715,56 @@
         locname = 0;
 
     return locname;
+}
+
+
+/**************************************************************************/
+
+static const char*
+_rw_locale_names;
+
+_TEST_EXPORT const char* const&
+rw_opt_locales = _rw_locale_names;
+
+
+_TEST_EXPORT int
+rw_opt_setlocales (int argc, char* argv[])
+{
+    RW_ASSERT (0 < argc && argv [0]);
+
+    // the option requires an equals sign followed by an optional argument
+    char *args = strchr (argv [0], '=');
+
+    RW_ASSERT (0 != args);
+
+    // small static buffer should be sufficient in most cases
+    static char buffer [256];
+
+    const size_t len = strlen (++args);
+
+    // dynamically allocate a bigger buffer when the small buffer
+    // isn't big enough (let the dynamically allocated buffer leak)
+    char* const locale_names =
+        sizeof buffer < len + 2 ? (char*)malloc (len + 2) : buffer;
+
+    if (0 == locale_names)
+        return 1;
+
+    locale_names [len]     = '\0';
+    locale_names [len + 1] = '\0';
+
+    memcpy (locale_names, args, len);
+
+    for (char *next = locale_names; ; ) {
+        next = strpbrk (next, ", ");
+        if (next)
+            *next++ = '\0';
+        else
+            break;
+    }
+
+    _rw_locale_names = locale_names;
+
+    // return 0 on success
+    return 0;
 }



Mime
View raw message