summaryrefslogtreecommitdiffstats
path: root/tests/datetime
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 14:36:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 14:36:24 +0000
commit9b6d8e63db85c30007b463e91f91a791969fa83f (patch)
tree0899af51d73c1bf986f73ae39a03c4436083018a /tests/datetime
parentInitial commit. (diff)
downloadgnome-control-center-upstream.tar.xz
gnome-control-center-upstream.zip
Adding upstream version 1:3.38.4.upstream/1%3.38.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/datetime')
-rw-r--r--tests/datetime/meson.build34
-rw-r--r--tests/datetime/test-datetime.py54
-rw-r--r--tests/datetime/test-endianess.c65
-rw-r--r--tests/datetime/test-timezone-gfx.c75
-rw-r--r--tests/datetime/test-timezone.c65
5 files changed, 293 insertions, 0 deletions
diff --git a/tests/datetime/meson.build b/tests/datetime/meson.build
new file mode 100644
index 0000000..c9f0787
--- /dev/null
+++ b/tests/datetime/meson.build
@@ -0,0 +1,34 @@
+
+test_units = [
+ 'test-timezone',
+ 'test-timezone-gfx',
+ 'test-endianess',
+]
+
+env = [
+ 'G_MESSAGES_DEBUG=all',
+ 'BUILDDIR=' + meson.current_build_dir(),
+ 'TOP_BUILDDIR=' + meson.build_root(),
+# Disable ATK, this should not be required but it caused CI failures -- 2018-12-07
+ 'NO_AT_BRIDGE=1'
+]
+cflags = [
+ '-DTEST_SRCDIR="@0@"'.format(meson.current_source_dir()),
+ '-DSRCDIR="@0@"'.format(meson.source_root() + '/panels/datetime')
+]
+
+foreach unit: test_units
+ exe = executable(
+ unit,
+ [unit + '.c'],
+ dependencies : common_deps + [m_dep, datetime_panel_lib_dep],
+ c_args : cflags
+ )
+endforeach
+
+test(
+ 'test-datetime',
+ find_program('test-datetime.py'),
+ env : env,
+ timeout : 60
+)
diff --git a/tests/datetime/test-datetime.py b/tests/datetime/test-datetime.py
new file mode 100644
index 0000000..cc69cae
--- /dev/null
+++ b/tests/datetime/test-datetime.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python3
+# Copyright © 2018 Red Hat, Inc
+# 2018 Endless Mobile, Inc
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY 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/>.
+#
+# Authors: Benjamin Berg <bberg@redhat.com>
+# Georges Basile Stavracas Neto <georges@endlessm.com>
+
+import os
+import sys
+import unittest
+
+try:
+ import dbusmock
+except ImportError:
+ sys.stderr.write('You need python-dbusmock (http://pypi.python.org/pypi/python-dbusmock) for this test suite.\n')
+ sys.exit(1)
+
+# Add the shared directory to the search path
+sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'shared'))
+
+from gtest import GTest
+from x11session import X11SessionTestCase
+
+BUILDDIR = os.environ.get('BUILDDIR', os.path.join(os.path.dirname(__file__)))
+
+
+class EndianessTestCase(X11SessionTestCase, GTest):
+ g_test_exe = os.path.join(BUILDDIR, 'test-endianess')
+
+
+class TimezoneTestCase(X11SessionTestCase, GTest):
+ g_test_exe = os.path.join(BUILDDIR, 'test-timezone')
+
+
+class TimezoneGfxTestCase(X11SessionTestCase, GTest):
+ g_test_exe = os.path.join(BUILDDIR, 'test-timezone-gfx')
+
+
+if __name__ == '__main__':
+ _test = unittest.TextTestRunner(stream=sys.stdout, verbosity=2)
+ unittest.main(testRunner=_test)
diff --git a/tests/datetime/test-endianess.c b/tests/datetime/test-endianess.c
new file mode 100644
index 0000000..9cb9200
--- /dev/null
+++ b/tests/datetime/test-endianess.c
@@ -0,0 +1,65 @@
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <locale.h>
+#include "date-endian.h"
+
+static int verbose = 0;
+
+static void
+print_endianess (const char *lang)
+{
+ DateEndianess endianess;
+
+ if (lang != NULL) {
+ setlocale (LC_TIME, lang);
+ endianess = date_endian_get_for_lang (lang, verbose);
+ } else {
+ endianess = date_endian_get_default (verbose);
+ }
+ if (verbose)
+ g_print ("\t\t%s\n", date_endian_to_string (endianess));
+}
+
+static void
+test_endianess (void)
+{
+ g_autoptr(GDir) dir = NULL;
+ const char *name;
+
+ dir = g_dir_open ("/usr/share/i18n/locales/", 0, NULL);
+ if (dir == NULL) {
+ /* Try with /usr/share/locale/
+ * https://bugzilla.gnome.org/show_bug.cgi?id=646780 */
+ dir = g_dir_open ("/usr/share/locale/", 0, NULL);
+ if (dir == NULL) {
+ g_assert_not_reached ();
+ }
+ }
+
+ while ((name = g_dir_read_name (dir)) != NULL)
+ print_endianess (name);
+}
+
+int main (int argc, char **argv)
+{
+ setlocale (LC_ALL, "");
+ bind_textdomain_codeset ("libc", "UTF-8");
+
+ g_test_init (&argc, &argv, NULL);
+
+ g_setenv ("G_DEBUG", "fatal_warnings", FALSE);
+
+ if (argv[1] != NULL) {
+ verbose = 1;
+
+ if (g_str_equal (argv[1], "-c"))
+ print_endianess (NULL);
+ else
+ print_endianess (argv[1]);
+ return 0;
+ }
+
+ g_test_add_func ("/datetime/endianess", test_endianess);
+
+ return g_test_run ();
+}
diff --git a/tests/datetime/test-timezone-gfx.c b/tests/datetime/test-timezone-gfx.c
new file mode 100644
index 0000000..1c25d48
--- /dev/null
+++ b/tests/datetime/test-timezone-gfx.c
@@ -0,0 +1,75 @@
+#include <config.h>
+#include <locale.h>
+#include <gtk/gtk.h>
+
+#include "cc-datetime-resources.h"
+#include "tz.h"
+
+static void
+test_timezone_gfx (gconstpointer data)
+{
+ g_autoptr(TzDB) db = NULL;
+ GPtrArray *locs;
+ const char *pixmap_dir;
+ guint i;
+
+ pixmap_dir = data;
+ db = tz_load_db ();
+ locs = tz_get_locations (db);
+
+ for (i = 0; i < locs->len ; i++)
+ {
+ g_autofree gchar *filename = NULL;
+ g_autofree gchar *path = NULL;
+ TzLocation *location;
+ TzInfo *info;
+ gdouble selected_offset;
+ gchar buf[16];
+
+ location = locs->pdata[i];
+ info = tz_info_from_location (location);
+ selected_offset = tz_location_get_utc_offset (location) / (60.0 * 60.0) + (info->daylight ? -1.0 : 0.0);
+ tz_info_free (info);
+
+ filename = g_strdup_printf ("timezone_%s.png", g_ascii_formatd (buf, sizeof (buf), "%g", selected_offset));
+ path = g_build_filename (pixmap_dir, filename, NULL);
+
+ if (!g_file_test (path, G_FILE_TEST_IS_REGULAR))
+ {
+ g_message ("File '%s' missing for zone '%s'", filename, location->zone);
+ g_test_fail ();
+ }
+ }
+}
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ gchar *pixmap_dir;
+
+ setlocale (LC_ALL, "");
+ g_test_init (&argc, &argv, NULL);
+
+ g_setenv ("G_DEBUG", "fatal_warnings", FALSE);
+
+ g_resources_register (cc_datetime_get_resource ());
+
+ if (argc == 2)
+ {
+ pixmap_dir = g_strdup (argv[1]);
+ }
+ else if (argc == 1)
+ {
+ pixmap_dir = g_strdup (SRCDIR "/data/");
+ }
+ else
+ {
+ g_message ("Usage: %s [PIXMAP DIRECTORY]", argv[0]);
+ return 1;
+ }
+
+ g_test_add_data_func ("/datetime/timezone-gfx", pixmap_dir, test_timezone_gfx);
+
+ return g_test_run ();
+}
diff --git a/tests/datetime/test-timezone.c b/tests/datetime/test-timezone.c
new file mode 100644
index 0000000..5962fc4
--- /dev/null
+++ b/tests/datetime/test-timezone.c
@@ -0,0 +1,65 @@
+#include <locale.h>
+#include <gtk/gtk.h>
+#include "cc-datetime-resources.h"
+#include "cc-timezone-map.h"
+
+static void
+test_timezone (void)
+{
+ g_autoptr(GHashTable) ht = NULL;
+ CcTimezoneMap *map;
+ TzDB *tz_db;
+ guint i;
+
+ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ map = cc_timezone_map_new ();
+ tz_db = tz_load_db ();
+
+ g_assert_nonnull (tz_db);
+ g_assert_nonnull (tz_db->locations);
+
+ for (i = 0; tz_db->locations && i < tz_db->locations->len; i++)
+ {
+ g_autofree gchar *clean_tz = NULL;
+ TzLocation *location = NULL;
+
+ location = g_ptr_array_index (tz_db->locations, i);
+ clean_tz = tz_info_get_clean_name (tz_db, location->zone);
+
+ if (!cc_timezone_map_set_timezone (map, location->zone))
+ {
+ if (!g_hash_table_contains (ht, clean_tz))
+ {
+ if (g_strcmp0 (clean_tz, location->zone) == 0)
+ g_printerr ("Failed to locate timezone '%s'\n", location->zone);
+ else
+ g_printerr ("Failed to locate timezone '%s' (original name: '%s')\n", clean_tz, location->zone);
+ g_hash_table_insert (ht, g_strdup (clean_tz), GINT_TO_POINTER (TRUE));
+ }
+
+ /* We don't warn for those, we'll just fallback
+ * in the panel code */
+ if (!g_str_equal (clean_tz, "posixrules") && !g_str_equal (clean_tz, "Factory"))
+ g_test_fail ();
+ }
+ }
+
+ tz_db_free (tz_db);
+}
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ setlocale (LC_ALL, "");
+ gtk_init (NULL, NULL);
+ g_test_init (&argc, &argv, NULL);
+
+ g_resources_register (cc_datetime_get_resource ());
+
+ g_setenv ("G_DEBUG", "fatal_warnings", FALSE);
+
+ g_test_add_func ("/datetime/timezone", test_timezone);
+
+ return g_test_run ();
+}