vangyzen updated this revision to Diff 79322. vangyzen added a comment. Handle multibyte thousands_sep; do not reference possibly stale locale data
https://reviews.llvm.org/D26979 Files: projects/libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/grouping.pass.cpp projects/libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp
Index: projects/libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp =================================================================== --- projects/libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp +++ projects/libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp @@ -16,10 +16,8 @@ // char_type thousands_sep() const; -// TODO: investigation needed -// XFAIL: linux-gnu - #include <locale> +#include <clocale> #include <cassert> #include "platform_support.h" // locale name macros @@ -40,29 +38,45 @@ } } { + char expected; + wchar_t wexpected; + assert(std::setlocale(LC_ALL, LOCALE_en_US_UTF_8) != NULL); + const char *ts = std::localeconv()->thousands_sep; + expected = *ts; + int nb = mbtowc(&wexpected, ts, strlen(ts)+1); + assert(nb >= 0); + assert(std::setlocale(LC_ALL, "C") != NULL); 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() == wexpected); } } { + char expected; + wchar_t wexpected; + assert(std::setlocale(LC_ALL, LOCALE_fr_FR_UTF_8) != NULL); + const char *ts = std::localeconv()->thousands_sep; + expected = *ts; + int nb = mbtowc(&wexpected, ts, strlen(ts)+1); + assert(nb >= 0); + assert(std::setlocale(LC_ALL, "C") != NULL); 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() == wexpected); } } } Index: projects/libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/grouping.pass.cpp =================================================================== --- projects/libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/grouping.pass.cpp +++ projects/libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/grouping.pass.cpp @@ -16,10 +16,8 @@ // string grouping() const; -// TODO: investigation needed -// XFAIL: linux-gnu - #include <locale> +#include <clocale> #include <cassert> #include "platform_support.h" // locale name macros @@ -40,29 +38,37 @@ } } { + assert(std::setlocale(LC_NUMERIC, LOCALE_en_US_UTF_8) != NULL); + char *expected = strdup(std::localeconv()->grouping); + assert(std::setlocale(LC_NUMERIC, "C") != NULL); 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); } + free(expected); } { + assert(std::setlocale(LC_NUMERIC, LOCALE_fr_FR_UTF_8) != NULL); + char *expected = strdup(std::localeconv()->grouping); + assert(std::setlocale(LC_NUMERIC, "C") != NULL); 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); } + free(expected); } }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits