aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/22_locale
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-12-15 10:25:53 +0100
committerJakub Jelinek <jakub@redhat.com>2021-12-15 10:25:53 +0100
commita5b4ebc217afe6c31334e017d1fead4a6b8e53b2 (patch)
tree9873099fcd6aeaa5053b69ab180b7aaca7f2405b /libstdc++-v3/testsuite/22_locale
parent8f9fea41a767f6ad8cf3d521031048a2491f98b1 (diff)
downloadgcc-a5b4ebc217afe6c31334e017d1fead4a6b8e53b2.zip
gcc-a5b4ebc217afe6c31334e017d1fead4a6b8e53b2.tar.gz
gcc-a5b4ebc217afe6c31334e017d1fead4a6b8e53b2.tar.bz2
libstdc++: Poor man's case insensitive comparisons in time_get [PR71557]
This patch uses the same not completely correct case insensitive comparisons as used elsewhere in the same header. Proper comparisons that would handle even multi-byte characters would be harder, but I don't see them implemented in __ctype's methods. 2021-12-15 Jakub Jelinek <jakub@redhat.com> PR libstdc++/71557 * include/bits/locale_facets_nonio.tcc (_M_extract_via_format): Compare characters other than format specifiers and whitespace case insensitively. (_M_extract_name): Compare characters case insensitively. * testsuite/22_locale/time_get/get/char/71557.cc: New test. * testsuite/22_locale/time_get/get/wchar_t/71557.cc: New test.
Diffstat (limited to 'libstdc++-v3/testsuite/22_locale')
-rw-r--r--libstdc++-v3/testsuite/22_locale/time_get/get/char/71557.cc96
-rw-r--r--libstdc++-v3/testsuite/22_locale/time_get/get/wchar_t/71557.cc96
2 files changed, 192 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/22_locale/time_get/get/char/71557.cc b/libstdc++-v3/testsuite/22_locale/time_get/get/char/71557.cc
new file mode 100644
index 0000000..a0214c2
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/time_get/get/char/71557.cc
@@ -0,0 +1,96 @@
+// { dg-do run { target c++11 } }
+
+// Copyright (C) 2021 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <locale>
+#include <sstream>
+#include <iterator>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ using namespace std;
+
+ locale loc_c = locale::classic();
+
+ istringstream iss;
+ iss.imbue(loc_c);
+ const time_get<char>& tget = use_facet<time_get<char>>(iss.getloc());
+ typedef istreambuf_iterator<char> iter;
+ const iter end;
+
+ tm time;
+ ios_base::iostate err = ios_base::badbit;
+
+ iss.str("20:48:01 MAR 31 2016");
+ string format = "%H:%M:%S %b %d %Y";
+ auto ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2016 - 1900 );
+ VERIFY( time.tm_mon == 2 );
+ VERIFY( time.tm_mday == 31 );
+ VERIFY( time.tm_hour == 20 );
+ VERIFY( time.tm_min == 48 );
+ VERIFY( time.tm_sec == 01 );
+
+ iss.str("21:38:11 apr 30 2017");
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2017 - 1900 );
+ VERIFY( time.tm_mon == 3 );
+ VERIFY( time.tm_mday == 30 );
+ VERIFY( time.tm_hour == 21 );
+ VERIFY( time.tm_min == 38 );
+ VERIFY( time.tm_sec == 11 );
+
+ iss.str("22:28:21 mAy 29 2018");
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2018 - 1900 );
+ VERIFY( time.tm_mon == 4 );
+ VERIFY( time.tm_mday == 29 );
+ VERIFY( time.tm_hour == 22 );
+ VERIFY( time.tm_min == 28 );
+ VERIFY( time.tm_sec == 21 );
+
+ iss.str("23:18:31 JuN 28 2019");
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2019 - 1900 );
+ VERIFY( time.tm_mon == 5 );
+ VERIFY( time.tm_mday == 28 );
+ VERIFY( time.tm_hour == 23 );
+ VERIFY( time.tm_min == 18 );
+ VERIFY( time.tm_sec == 31 );
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/22_locale/time_get/get/wchar_t/71557.cc b/libstdc++-v3/testsuite/22_locale/time_get/get/wchar_t/71557.cc
new file mode 100644
index 0000000..ed6af05
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/time_get/get/wchar_t/71557.cc
@@ -0,0 +1,96 @@
+// { dg-do run { target c++11 } }
+
+// Copyright (C) 2021 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <locale>
+#include <sstream>
+#include <iterator>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ using namespace std;
+
+ locale loc_c = locale::classic();
+
+ wistringstream iss;
+ iss.imbue(loc_c);
+ const time_get<wchar_t>& tget = use_facet<time_get<wchar_t>>(iss.getloc());
+ typedef istreambuf_iterator<wchar_t> iter;
+ const iter end;
+
+ tm time;
+ ios_base::iostate err = ios_base::badbit;
+
+ iss.str(L"20:48:01 MAR 31 2016");
+ wstring format = L"%H:%M:%S %b %d %Y";
+ auto ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2016 - 1900 );
+ VERIFY( time.tm_mon == 2 );
+ VERIFY( time.tm_mday == 31 );
+ VERIFY( time.tm_hour == 20 );
+ VERIFY( time.tm_min == 48 );
+ VERIFY( time.tm_sec == 01 );
+
+ iss.str(L"21:38:11 apr 30 2017");
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2017 - 1900 );
+ VERIFY( time.tm_mon == 3 );
+ VERIFY( time.tm_mday == 30 );
+ VERIFY( time.tm_hour == 21 );
+ VERIFY( time.tm_min == 38 );
+ VERIFY( time.tm_sec == 11 );
+
+ iss.str(L"22:28:21 mAy 29 2018");
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2018 - 1900 );
+ VERIFY( time.tm_mon == 4 );
+ VERIFY( time.tm_mday == 29 );
+ VERIFY( time.tm_hour == 22 );
+ VERIFY( time.tm_min == 28 );
+ VERIFY( time.tm_sec == 21 );
+
+ iss.str(L"23:18:31 JuN 28 2019");
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2019 - 1900 );
+ VERIFY( time.tm_mon == 5 );
+ VERIFY( time.tm_mday == 28 );
+ VERIFY( time.tm_hour == 23 );
+ VERIFY( time.tm_min == 18 );
+ VERIFY( time.tm_sec == 31 );
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}