diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2013-12-13 09:51:20 -0600 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2013-12-13 09:51:20 -0600 |
commit | 8c89aa772071eaa5f4c2b8bc37cb346d80a0ad6e (patch) | |
tree | 58d357eafcb62cfa6eea765909cd78868e97ee7c /tests/test-formatter.cc | |
parent | 75b0a871e757b1e71539bd0bd8d52065bd2a85ec (diff) | |
download | ayatana-indicator-datetime-8c89aa772071eaa5f4c2b8bc37cb346d80a0ad6e.tar.gz ayatana-indicator-datetime-8c89aa772071eaa5f4c2b8bc37cb346d80a0ad6e.tar.bz2 ayatana-indicator-datetime-8c89aa772071eaa5f4c2b8bc37cb346d80a0ad6e.zip |
Add tests to confirm the phone profile header's time format is sensitive to 12/24hr locales (bug #1256061)
Diffstat (limited to 'tests/test-formatter.cc')
-rw-r--r-- | tests/test-formatter.cc | 108 |
1 files changed, 108 insertions, 0 deletions
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 <charles.kerr@canonical.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#include <string> +#include <vector> + +#include <langinfo.h> +#include <locale.h> + +#include <glib/gi18n.h> + +#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); + } +} |