vangyzen created this revision.
vangyzen added a subscriber: cfe-commits.
Herald added a subscriber: emaste.

Locale data can vary across platforms.  Rather than hard-code the expected
data in the units tests, get it from the OS via the C API.

This fixes these unit tests on FreeBSD.  It might fix them on Linux, too.
I have not tested other platforms, but I will if I get agreement
on the approach.


https://reviews.llvm.org/D26979

Files:
  
test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/grouping.pass.cpp
  
test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp

Index: test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp
===================================================================
--- test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp
+++ test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp
@@ -20,6 +20,7 @@
 // XFAIL: linux-gnu
 
 #include <locale>
+#include <clocale>
 #include <cassert>
 
 #include "platform_support.h" // locale name macros
@@ -40,29 +41,41 @@
         }
     }
     {
+        char expected = ',';
+        const char *ret = std::setlocale(LC_NUMERIC, LOCALE_en_US_UTF_8);
+        if (ret != NULL)
+        {
+            expected = *std::localeconv()->thousands_sep;
+        }
         std::locale l(LOCALE_en_US_UTF_8);
         {
             typedef char C;
             const std::numpunct<C>& np = std::use_facet<std::numpunct<C> >(l);
-            assert(np.thousands_sep() == ',');
+            assert(np.thousands_sep() == expected);
         }
         {
             typedef wchar_t C;
             const std::numpunct<C>& np = std::use_facet<std::numpunct<C> >(l);
-            assert(np.thousands_sep() == L',');
+            assert(np.thousands_sep() == expected);
         }
     }
     {
+        char expected = ',';
+        const char *ret = std::setlocale(LC_NUMERIC, LOCALE_fr_FR_UTF_8);
+        if (ret != NULL)
+        {
+            expected = *std::localeconv()->thousands_sep;
+        }
         std::locale l(LOCALE_fr_FR_UTF_8);
         {
             typedef char C;
             const std::numpunct<C>& np = std::use_facet<std::numpunct<C> >(l);
-            assert(np.thousands_sep() == ',');
+            assert(np.thousands_sep() == expected);
         }
         {
             typedef wchar_t C;
             const std::numpunct<C>& np = std::use_facet<std::numpunct<C> >(l);
-            assert(np.thousands_sep() == L',');
+            assert(np.thousands_sep() == expected);
         }
     }
 }
Index: test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/grouping.pass.cpp
===================================================================
--- test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/grouping.pass.cpp
+++ test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/grouping.pass.cpp
@@ -20,6 +20,7 @@
 // XFAIL: linux-gnu
 
 #include <locale>
+#include <clocale>
 #include <cassert>
 
 #include "platform_support.h" // locale name macros
@@ -40,29 +41,41 @@
         }
     }
     {
+        const char *expected = "\3\3";
+        const char *ret = std::setlocale(LC_NUMERIC, LOCALE_en_US_UTF_8);
+        if (ret != NULL)
+        {
+            expected = std::localeconv()->grouping;
+        }
         std::locale l(LOCALE_en_US_UTF_8);
         {
             typedef char C;
             const std::numpunct<C>& np = std::use_facet<std::numpunct<C> >(l);
-            assert(np.grouping() == "\3\3");
+            assert(np.grouping() == expected);
         }
         {
             typedef wchar_t C;
             const std::numpunct<C>& np = std::use_facet<std::numpunct<C> >(l);
-            assert(np.grouping() == "\3\3");
+            assert(np.grouping() == expected);
         }
     }
     {
+        const char *expected = "\x7F";
+        const char *ret = std::setlocale(LC_NUMERIC, LOCALE_fr_FR_UTF_8);
+        if (ret != NULL)
+        {
+            expected = std::localeconv()->grouping;
+        }
         std::locale l(LOCALE_fr_FR_UTF_8);
         {
             typedef char C;
             const std::numpunct<C>& np = std::use_facet<std::numpunct<C> >(l);
-            assert(np.grouping() == "\x7F");
+            assert(np.grouping() == expected);
         }
         {
             typedef wchar_t C;
             const std::numpunct<C>& np = std::use_facet<std::numpunct<C> >(l);
-            assert(np.grouping() == "\x7F");
+            assert(np.grouping() == expected);
         }
     }
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to