aboutsummaryrefslogtreecommitdiff
path: root/tests/test-formatter.cc
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-12-13 19:39:47 +0000
committerTarmac <Unknown>2013-12-13 19:39:47 +0000
commit79972de2f13e9886330f87c3f7ce3a24f641c46d (patch)
tree23dae184a48b6ee3659cf2c7163d31fcf8d56f6c /tests/test-formatter.cc
parent171d8c455f8dcd00e3e0eb37d02b0ffa82f06cb7 (diff)
parentb91dc2ac50d421d29e22bac9c9564029ba64350d (diff)
downloadayatana-indicator-datetime-79972de2f13e9886330f87c3f7ce3a24f641c46d.tar.gz
ayatana-indicator-datetime-79972de2f13e9886330f87c3f7ce3a24f641c46d.tar.bz2
ayatana-indicator-datetime-79972de2f13e9886330f87c3f7ce3a24f641c46d.zip
Make the phone profile's header format sensitive to whether the phone is running in a 12h or 24h locale, and use a 12h or 24h notation accordingly. Fixes: https://bugs.launchpad.net/bugs/1256061.
Approved by PS Jenkins bot, Ted Gould.
Diffstat (limited to 'tests/test-formatter.cc')
-rw-r--r--tests/test-formatter.cc98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/test-formatter.cc b/tests/test-formatter.cc
new file mode 100644
index 0000000..6a408ab
--- /dev/null
+++ b/tests/test-formatter.cc
@@ -0,0 +1,98 @@
+
+/*
+ * 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 <langinfo.h>
+#include <locale.h>
+
+#include <glib/gi18n.h>
+
+#include "utils.h"
+
+#include "glib-fixture.h"
+
+/***
+****
+***/
+
+class FormatterFixture: public GlibFixture
+{
+ private:
+
+ typedef GlibFixture super;
+ gchar * original_locale = nullptr;
+
+ protected:
+
+ virtual void SetUp ()
+ {
+ super::SetUp ();
+
+ original_locale = g_strdup (setlocale (LC_TIME, NULL));
+ }
+
+ virtual void TearDown ()
+ {
+ 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);
+ }
+}