[libcxx] [test] Fix time.get.byname get_one for Glibc and Windows

This matches the fixes for the wchar version in
f081cc5037.

Differential Revision: https://reviews.llvm.org/D120283
This commit is contained in:
Martin Storsjö 2022-01-25 09:38:41 +00:00
parent c7d6448d03
commit 3fb4439a0a
1 changed files with 47 additions and 7 deletions

View File

@ -9,8 +9,6 @@
// NetBSD does not support LC_TIME at the moment
// XFAIL: netbsd
// XFAIL: LIBCXX-WINDOWS-FIXME
// REQUIRES: locale.en_US.UTF-8
// REQUIRES: locale.fr_FR.UTF-8
// REQUIRES: locale.ru_RU.UTF-8
@ -23,9 +21,6 @@
// iter_type get(iter_type s, iter_type end, ios_base& f,
// ios_base::iostate& err, tm *t, char format, char modifier = 0) const;
// TODO: investigation needed
// XFAIL: target={{.*}}-linux-gnu{{.*}}
#include <locale>
#include <cassert>
#include "test_macros.h"
@ -52,7 +47,15 @@ int main(int, char**)
std::tm t;
{
const my_facet f(LOCALE_en_US_UTF_8, 1);
#ifdef _WIN32
// On Windows, the "%c" format lacks the leading week day, which
// means that t.tm_wday doesn't get set when parsing the string.
const char in[] = "12/31/2061 11:55:59 PM";
#elif defined(TEST_HAS_GLIBC)
const char in[] = "Sat 31 Dec 2061 11:55:59 PM";
#else
const char in[] = "Sat Dec 31 23:55:59 2061";
#endif
err = std::ios_base::goodbit;
t = std::tm();
I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'c');
@ -63,12 +66,18 @@ int main(int, char**)
assert(t.tm_mday == 31);
assert(t.tm_mon == 11);
assert(t.tm_year == 161);
#ifndef _WIN32
assert(t.tm_wday == 6);
#endif
assert(err == std::ios_base::eofbit);
}
{
const my_facet f(LOCALE_en_US_UTF_8, 1);
#if defined(_WIN32) || defined(TEST_HAS_GLIBC)
const char in[] = "11:55:59 PM";
#else
const char in[] = "23:55:59";
#endif
err = std::ios_base::goodbit;
t = std::tm();
I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'X');
@ -80,7 +89,13 @@ int main(int, char**)
}
{
const my_facet f(LOCALE_fr_FR_UTF_8, 1);
#ifdef _WIN32
const char in[] = "31/12/2061 23:55:59";
#elif defined(TEST_HAS_GLIBC)
const char in[] = "sam. 31 d""\xC3\xA9""c. 2061 23:55:59";
#else
const char in[] = "Sam 31 d""\xC3\xA9""c 23:55:59 2061";
#endif
err = std::ios_base::goodbit;
t = std::tm();
I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'c');
@ -91,7 +106,9 @@ int main(int, char**)
assert(t.tm_mday == 31);
assert(t.tm_mon == 11);
assert(t.tm_year == 161);
#ifndef _WIN32
assert(t.tm_wday == 6);
#endif
assert(err == std::ios_base::eofbit);
}
{
@ -108,6 +125,11 @@ int main(int, char**)
}
{
const my_facet f(LOCALE_ru_RU_UTF_8, 1);
#ifdef TEST_HAS_GLIBC
const char in[] = "\xD0\xA1\xD0\xB1 31 \xD0\xB4\xD0\xB5\xD0\xBA 2061 23:55:59";
#elif defined(_WIN32)
const char in[] = "31.12.2061 23:55:59";
#else
const char in[] = "\xD1\x81\xD1\x83\xD0\xB1\xD0\xB1"
"\xD0\xBE\xD1\x82\xD0\xB0"
", 31 "
@ -116,6 +138,7 @@ int main(int, char**)
" 2061 "
"\xD0\xB3"
". 23:55:59";
#endif
err = std::ios_base::goodbit;
t = std::tm();
I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'c');
@ -126,7 +149,9 @@ int main(int, char**)
assert(t.tm_mday == 31);
assert(t.tm_mon == 11);
assert(t.tm_year == 161);
#ifndef _WIN32
assert(t.tm_wday == 6);
#endif
assert(err == std::ios_base::eofbit);
}
{
@ -143,8 +168,17 @@ int main(int, char**)
}
{
const my_facet f(LOCALE_zh_CN_UTF_8, 1);
const char in[] = "\xE5\x85\xAD"
" 12/31 23:55:59 2061";
#ifdef TEST_HAS_GLIBC
const char in[] = "2061" "\xE5\xB9\xB4" "12" "\xE6\x9C\x88" "31"
"\xE6\x97\xA5" " "
"\xE6\x98\x9F\xE6\x9c\x9F\xE5\x85\xAD"
" 23" "\xE6\x97\xB6" "55" "\xE5\x88\x86" "59"
"\xE7\xA7\x92";
#elif defined(_WIN32)
const char in[] = "2061/12/31 23:55:59";
#else
const char in[] = "\xE5\x85\xAD 12/31 23:55:59 2061";
#endif
err = std::ios_base::goodbit;
t = std::tm();
I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'c');
@ -155,12 +189,18 @@ int main(int, char**)
assert(t.tm_mday == 31);
assert(t.tm_mon == 11);
assert(t.tm_year == 161);
#ifndef _WIN32
assert(t.tm_wday == 6);
#endif
assert(err == std::ios_base::eofbit);
}
{
const my_facet f(LOCALE_zh_CN_UTF_8, 1);
#if defined(_WIN32)
const char in[] = "23:55:59";
#else
const char in[] = "23""\xE6\x97\xB6""55""\xE5\x88\x86""59""\xE7\xA7\x92";
#endif
err = std::ios_base::goodbit;
t = std::tm();
I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'X');