[gnome-control-center] datetime: Port tests to GTest



commit 1428b52fdc0e240d65ecd9408612fe1eaffe52d9
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Jun 10 14:33:32 2016 +0200

    datetime: Port tests to GTest
    
    test-timezone is still disabled though, as it is too noisy still.

 panels/datetime/Makefile.am              |   14 +++------
 panels/datetime/po-timezones/Makefile.am |    2 +
 panels/datetime/test-endianess.c         |   38 ++++++++++++++++---------
 panels/datetime/test-timezone-gfx.c      |   43 ++++++++++++++++++------------
 panels/datetime/test-timezone.c          |   23 ++++++++++++----
 5 files changed, 74 insertions(+), 46 deletions(-)
---
diff --git a/panels/datetime/Makefile.am b/panels/datetime/Makefile.am
index 05eaa31..4fc533e 100644
--- a/panels/datetime/Makefile.am
+++ b/panels/datetime/Makefile.am
@@ -1,3 +1,5 @@
+include $(top_srcdir)/Makefile.decl
+
 # This is used in PANEL_CFLAGS
 cappletname = datetime
 
@@ -23,7 +25,9 @@ AM_CPPFLAGS =                                         \
        -DGNOMECC_DATA_DIR="\"$(pkgdatadir)\""          \
        $(NULL)
 
-noinst_PROGRAMS = test-timezone-gfx test-endianess test-timezone
+# test-timezone is still too noisy
+noinst_PROGRAMS = $(TEST_PROGS) test-timezone
+TEST_PROGS += test-timezone-gfx test-endianess
 
 test_timezone_SOURCES = test-timezone.c cc-timezone-map.h cc-timezone-map.c tz.c tz.h 
cc-datetime-resources.c cc-datetime-resources.h
 test_timezone_LDADD = $(DATETIME_PANEL_LIBS) -lm
@@ -37,16 +41,8 @@ test_endianess_SOURCES = test-endianess.c date-endian.c date-endian.h
 test_endianess_LDADD = $(DATETIME_PANEL_LIBS)
 test_endianess_CFLAGS = $(DATETIME_PANEL_CFLAGS)
 
-all-local: check-local
-
-check-local: test-timezone-gfx test-endianess test-timezone
-       $(builddir)/test-timezone-gfx $(srcdir)/data
-       $(builddir)/test-endianess
-#      $(builddir)/test-timezone
-
 noinst_LTLIBRARIES = libdate_time.la
 
-
 # This requires running d-bus session and accessible timedate1 daemon
 # FIXME: need to find a way how to filter out unnecessary d-bus stuff (introspectable, properties)
 #timedated1-interface.xml:
diff --git a/panels/datetime/po-timezones/Makefile.am b/panels/datetime/po-timezones/Makefile.am
index 33fd5e0..b508d21 100644
--- a/panels/datetime/po-timezones/Makefile.am
+++ b/panels/datetime/po-timezones/Makefile.am
@@ -15,6 +15,8 @@ NLSPACKAGE = $(GETTEXT_PACKAGE)-timezones
 %.mo: %.po
        $(AM_V_GEN) msgfmt -o $@ $<
 
+test:
+
 install: $(CATALOGS)
        @mkdir -p $(DESTDIR)$(localedir)
        for n in $(CATALOGS); do \
diff --git a/panels/datetime/test-endianess.c b/panels/datetime/test-endianess.c
index 490df17..06b2613 100644
--- a/panels/datetime/test-endianess.c
+++ b/panels/datetime/test-endianess.c
@@ -20,14 +20,35 @@ print_endianess (const char *lang)
                g_print ("\t\t%s\n", date_endian_to_string (endianess));
 }
 
-int main (int argc, char **argv)
+static void
+test_endianess (void)
 {
        GDir *dir;
        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;
 
@@ -38,18 +59,7 @@ int main (int argc, char **argv)
                return 0;
        }
 
-       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) {
-                       return 1;
-               }
-       }
-
-       while ((name = g_dir_read_name (dir)) != NULL)
-               print_endianess (name);
+       g_test_add_func ("/datetime/endianess", test_endianess);
 
-       return 0;
+       return g_test_run ();
 }
diff --git a/panels/datetime/test-timezone-gfx.c b/panels/datetime/test-timezone-gfx.c
index d667c42..debe9e4 100644
--- a/panels/datetime/test-timezone-gfx.c
+++ b/panels/datetime/test-timezone-gfx.c
@@ -3,24 +3,13 @@
 
 #include "tz.h"
 
-int main (int argc, char **argv)
+static void
+test_timezone_gfx (gconstpointer data)
 {
+       const char *pixmap_dir = data;
        TzDB *db;
        GPtrArray *locs;
        guint i;
-       char *pixmap_dir;
-       int retval = 0;
-
-        setlocale (LC_ALL, "");
-
-       if (argc == 2) {
-               pixmap_dir = g_strdup (argv[1]);
-       } else if (argc == 1) {
-               pixmap_dir = g_strdup ("data/");
-       } else {
-               g_message ("Usage: %s [PIXMAP DIRECTORY]", argv[0]);
-               return 1;
-       }
 
        db = tz_load_db ();
        locs = tz_get_locations (db);
@@ -42,14 +31,34 @@ int main (int argc, char **argv)
 
                if (g_file_test (path, G_FILE_TEST_IS_REGULAR) == FALSE) {
                        g_message ("File '%s' missing for zone '%s'", filename, loc->zone);
-                       retval = 1;
+                       g_test_fail ();
                }
 
                g_free (filename);
                g_free (path);
        }
        tz_db_free (db);
-       g_free (pixmap_dir);
+}
+
+int main (int argc, char **argv)
+{
+       char *pixmap_dir;
+
+        setlocale (LC_ALL, "");
+       g_test_init (&argc, &argv, NULL);
+
+       g_setenv ("G_DEBUG", "fatal_warnings", FALSE);
+
+       if (argc == 2) {
+               pixmap_dir = g_strdup (argv[1]);
+       } else if (argc == 1) {
+               pixmap_dir = g_strdup ("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 retval;
+       return g_test_run ();
 }
diff --git a/panels/datetime/test-timezone.c b/panels/datetime/test-timezone.c
index 5667657..db5c030 100644
--- a/panels/datetime/test-timezone.c
+++ b/panels/datetime/test-timezone.c
@@ -1,3 +1,4 @@
+#include <locale.h>
 #include <gtk/gtk.h>
 #include "cc-timezone-map.h"
 
@@ -56,15 +57,13 @@ get_timezone_list (GList *tzs,
        return tzs;
 }
 
-int main (int argc, char **argv)
+static void
+test_timezone (void)
 {
        CcTimezoneMap *map;
        TzDB *tz_db;
        GList *tzs, *l;
        GHashTable *ht;
-       int ret = 0;
-
-       gtk_init (&argc, &argv);
 
        ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
        map = cc_timezone_map_new ();
@@ -83,12 +82,13 @@ int main (int argc, char **argv)
                                else
                                        g_print ("Failed to locate timezone '%s' (original name: '%s')\n", 
clean_tz, timezone);
                                g_hash_table_insert (ht, g_strdup (clean_tz), GINT_TO_POINTER (TRUE));
+                               g_test_fail ();
                        }
                        /* We don't warn for those two, we'll just fallback
                         * in the panel code */
                        if (!g_str_equal (clean_tz, "posixrules") &&
                            !g_str_equal (clean_tz, "Factory"))
-                               ret = 1;
+                               g_test_fail ();
                }
                g_free (timezone);
                g_free (clean_tz);
@@ -96,6 +96,17 @@ int main (int argc, char **argv)
        g_list_free (tzs);
        tz_db_free (tz_db);
        g_hash_table_destroy (ht);
+}
+
+int main (int argc, char **argv)
+{
+       setlocale (LC_ALL, "");
+       gtk_init (NULL, NULL);
+       g_test_init (&argc, &argv, NULL);
+
+       g_setenv ("G_DEBUG", "fatal_warnings", FALSE);
+
+       g_test_add_func ("/datetime/timezone", test_timezone);
 
-       return ret;
+       return g_test_run ();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]