From e3dada2f766fdaec79a873de12ef0ad40270da13 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Fri, 8 Dec 2017 11:42:40 +0000 Subject: tests/test-formatter.cpp: Fix locale setting and ignore failures if the build system does not have en_US.UTF-8 as valid locale available. --- tests/test-formatter.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/test-formatter.cpp b/tests/test-formatter.cpp index e61daa7..2157e7b 100644 --- a/tests/test-formatter.cpp +++ b/tests/test-formatter.cpp @@ -74,16 +74,17 @@ class FormatterFixture: public GlibFixture } else { - g_warning("Unable to set locale to %s; skipping %s locale tests.", expected_locale, name); + g_message("Unable to set locale to %s, actual locale is %s; skipping %s locale tests.", expected_locale, actual_locale, name); return false; } } - inline bool Set24hLocale() { return SetLocale("C", "24h"); } - inline bool Set12hLocale() { return SetLocale("en_US.utf8", "12h"); } + inline bool Set24hLocale() { return SetLocale("C", "24h"); } + inline bool Set12hLocale() { return SetLocale("en_US.UTF-8", "12h"); } }; +#ifdef HAS_URLDISPATCHER /** * Test the phone header format */ @@ -145,18 +146,24 @@ TEST_F(FormatterFixture, TestDesktopHeader) auto now = DateTime::Local(2020, 10, 31, 18, 30, 59); auto clock = std::make_shared(now); + bool locale_set = false; for(const auto& test_case : test_cases) { - if (test_case.is_12h ? Set12hLocale() : Set24hLocale()) - { - DesktopFormatter f(clock, m_settings); + test_case.is_12h ? locale_set = Set12hLocale() : locale_set = Set24hLocale(); + DesktopFormatter f(clock, m_settings); - m_settings->show_day.set(test_case.show_day); - m_settings->show_date.set(test_case.show_date); - m_settings->show_year.set(test_case.show_year); + m_settings->show_day.set(test_case.show_day); + m_settings->show_date.set(test_case.show_date); + m_settings->show_year.set(test_case.show_year); + if (locale_set) + { ASSERT_STREQ(test_case.expected_format_string, f.header_format.get().c_str()); } + else + { + g_message("Ignoring test (expected: %s, probably flawed test result: %s).", test_case.expected_format_string, f.header_format.get().c_str()); + } } } -- cgit v1.2.3