From 8c89aa772071eaa5f4c2b8bc37cb346d80a0ad6e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 13 Dec 2013 09:51:20 -0600 Subject: Add tests to confirm the phone profile header's time format is sensitive to 12/24hr locales (bug #1256061) --- tests/test-formatter.cc | 108 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 tests/test-formatter.cc (limited to 'tests/test-formatter.cc') diff --git a/tests/test-formatter.cc b/tests/test-formatter.cc new file mode 100644 index 0000000..488d9e1 --- /dev/null +++ b/tests/test-formatter.cc @@ -0,0 +1,108 @@ + +/* + * Copyright 2013 Canonical Ltd. + * + * Authors: + * Charles Kerr + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, 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 program. If not, see . + */ + +#include +#include + +#include +#include + +#include + +#include "utils.h" +#include "settings-shared.h" + +#include "glib-fixture.h" + +/*** +**** +***/ + +class FormatterFixture: public GlibFixture +{ + private: + + typedef GlibFixture super; + gchar * original_locale = nullptr; + + protected: + + GSettings * settings = nullptr; + + virtual void SetUp () + { + super::SetUp (); + + settings = g_settings_new (SETTINGS_INTERFACE); + + original_locale = g_strdup (setlocale (LC_TIME, NULL)); + } + + virtual void TearDown () + { + g_clear_object (&settings); + + setlocale (LC_TIME, original_locale); + g_clear_pointer (&original_locale, g_free); + + super::TearDown (); + } + + bool SetLocale (const char * expected_locale, const char * name) + { + setlocale (LC_TIME, expected_locale); + const char * actual_locale = setlocale (LC_TIME, NULL); + if (!g_strcmp0 (expected_locale, actual_locale)) + { + return true; + } + else + { + g_warning ("Unable to set locale to %s; skipping %s locale tests.", expected_locale, name); + return false; + } + } + + inline bool Set24hLocale () { return SetLocale ("C", "24h"); } + inline bool Set12hLocale () { return SetLocale ("en_US.utf8", "12h"); } +}; + + +/** + * Test the phone header format + */ +TEST_F (FormatterFixture, TestPhoneHeader) +{ + // test the default value in a 24h locale + if (Set24hLocale ()) + { + const gchar * format = get_terse_header_time_format_string (); + ASSERT_NE (nullptr, format); + ASSERT_STREQ ("%H:%M", format); + } + + // test the default value in a 12h locale + if (Set12hLocale ()) + { + const gchar * format = get_terse_header_time_format_string (); + ASSERT_NE (nullptr, format); + ASSERT_STREQ ("%l:%M %p", format); + } +} -- cgit v1.2.3