From: Tomasz Kamiński Date: Thu, 5 Jun 2025 14:27:41 +0000 (+0200) Subject: libstdc++: Test for formatting with empty spec for local_info and sys_info. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66e65eb50d16affca66f29927478d109533f71bb;p=thirdparty%2Fgcc.git libstdc++: Test for formatting with empty spec for local_info and sys_info. We do not test with wchar_t currently, as operator<< (and format) are ill-formed in such case, because we do not widen abbrev member of local_info. Adding a tests for behavior of the ostream operator and the formatting with empty chrono-spec for the chrono types. The coverage is now complete: * sys_info, local_info in this commit, * time point, zoned_time and local_time_format in r16-1107-g3cfa53aa95a19c, * duration and hh_mm_ss in r16-1099-gac0a04b7a254fb, * calendar types in r16-1016-g28a17985dd34b7. Finally, the timeout for the test was increased again and preprocessor checks for zoned_time where changed to _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI to match ones from bits/chrono_io.h file. libstdc++-v3/ChangeLog: * testsuite/std/time/format/empty_spec.cc: New tests and increased timeout. Reviewed-by: Jonathan Wakely Signed-off-by: Tomasz Kamiński --- diff --git a/libstdc++-v3/testsuite/std/time/format/empty_spec.cc b/libstdc++-v3/testsuite/std/time/format/empty_spec.cc index 48f61ee13e4..661712f1238 100644 --- a/libstdc++-v3/testsuite/std/time/format/empty_spec.cc +++ b/libstdc++-v3/testsuite/std/time/format/empty_spec.cc @@ -1,6 +1,6 @@ // { dg-do run { target c++20 } } // { dg-require-effective-target hosted } -// { dg-timeout-factor 2 } +// { dg-timeout-factor 4 } #include #include @@ -643,7 +643,7 @@ test_leap_second() WIDEN("2012-06-30 23:59:60") ); } -#if _GLIBCXX_USE_CXX11_ABI +#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI template auto make_zoned(const sys_time& st, const time_zone* tz) @@ -723,7 +723,7 @@ test_time_points() test_time_point(true); test_time_point(true); test_leap_second(); -#if _GLIBCXX_USE_CXX11_ABI +#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI test_zoned_time(); #endif test_local_time_format(); @@ -732,6 +732,108 @@ test_time_points() test_no_empty_spec>>(); } +#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI +template +void +test_sys_info() +{ + const sys_info si + { + sys_days(2024y/March/22) + 2h, + sys_days(2025y/April/11) + 23h + 15min + 10s, + 2h + 13min + 4s, + 15min, + "Zone" + }; + const std::basic_string_view<_CharT> txt + = WIDEN("[2024-03-22 02:00:00,2025-04-11 23:15:10,02:13:04,15min,Zone]"); + + verify( si, txt ); + + std::basic_string<_CharT> res; + std::basic_string_view<_CharT> sv; + + sv = res = std::format(WIDEN("{:65}"), si); + VERIFY( sv.ends_with(WIDEN(" ")) ); + sv.remove_suffix(4); + VERIFY( sv == txt ); + + sv = res = std::format(WIDEN("{:=^67}"), si); + VERIFY( sv.starts_with(WIDEN("===")) ); + VERIFY( sv.ends_with(WIDEN("===")) ); + sv.remove_prefix(3); + sv.remove_suffix(3); + VERIFY( sv == txt ); +} + +template +void test_local_info() +{ + using String = std::basic_string<_CharT>; + using StringView = std::basic_string_view<_CharT>; + + const sys_info s1 + { + sys_days(2015y/September/11) + 2h, + sys_days(2016y/March/13) + 2h, + -5h, + 0h, + "EET" + }; + const sys_info s2 + { + sys_days(2016y/March/13) + 2h, + sys_days(2015y/September/15) + 2h, + -4h, + 1h, + "EDT" + }; + + const StringView single + = WIDEN("[2015-09-11 02:00:00,2016-03-13 02:00:00,-05:00:00,0min,EET]"); + const StringView both + = WIDEN(" local time between " + "[2015-09-11 02:00:00,2016-03-13 02:00:00,-05:00:00,0min,EET]" + " and " + "[2016-03-13 02:00:00,2015-09-15 02:00:00,-04:00:00,60min,EDT]"); + + const local_info l1{local_info::nonexistent, s1, s2}; + auto exp = WIDEN("[nonexistent") + String(both) + WIDEN("]"); + verify( l1, StringView(exp) ); + + const local_info l2{local_info::ambiguous, s1, s2}; + exp = WIDEN("[ambiguous") + String(both) + WIDEN("]"); + verify( l2, StringView(exp) ); + + const local_info l3{local_info::unique, s1, s1}; + exp = WIDEN("[") + String(single) + WIDEN("]"); + verify( l3, StringView(exp) ); + + String res; + StringView sv; + + sv = res = std::format(WIDEN("{:65}"), l3); + VERIFY( sv.ends_with(WIDEN(" ")) ); + sv.remove_suffix(3); + VERIFY( sv == exp ); + + sv = res = std::format(WIDEN("{:=^67}"), l3); + VERIFY( sv.starts_with(WIDEN("==")) ); + VERIFY( sv.ends_with(WIDEN("===")) ); + sv.remove_prefix(2); + sv.remove_suffix(3); + VERIFY( sv == exp ); +} + +template +void +test_infos() +{ + test_sys_info(); + test_local_info(); +} +#endif + template void test_all() @@ -745,6 +847,9 @@ test_all() int main() { test_all(); +#if _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI + test_infos(); +#endif #ifdef _GLIBCXX_USE_WCHAR_T test_all();