[gnome-control-center] shell: Port tests to GTest
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] shell: Port tests to GTest
- Date: Fri, 10 Jun 2016 15:20:26 +0000 (UTC)
commit af5f2f3d7375c9a14bf91ddd45978ae47fca497d
Author: Bastien Nocera <hadess hadess net>
Date: Fri Jun 10 15:02:57 2016 +0200
shell: Port tests to GTest
shell/Makefile.am | 6 +++-
shell/alt/Makefile.am | 2 +
shell/appdata/Makefile.am | 2 +
shell/test-hostname.c | 66 ++++++++++++++++++++++++++++-----------------
4 files changed, 49 insertions(+), 27 deletions(-)
---
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 36fb22e..45819f0 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -1,7 +1,10 @@
+include $(top_srcdir)/Makefile.decl
+
SUBDIRS = appdata alt
AM_CPPFLAGS = \
-DGNOMELOCALEDIR="\"$(datadir)/locale\""\
+ -DTEST_SRCDIR=\""$(srcdir)/"\" \
-I$(top_srcdir) \
$(SHELL_CFLAGS) \
$(CHEESE_CFLAGS) \
@@ -156,12 +159,11 @@ EXTRA_DIST = \
CLEANFILES = $(BUILT_SOURCES) $(completion_DATA) $(servicefile_DATA)
DISTCLEANFILES = gnome-control-center.desktop gnome-control-center.desktop.in
+TEST_PROGS += test-hostname
noinst_PROGRAMS += test-hostname
test_hostname_SOURCES = hostname-helper.c hostname-helper.h test-hostname.c
test_hostname_LDADD = $(PANEL_LIBS) $(INFO_PANEL_LIBS)
EXTRA_DIST += hostnames-test.txt
-check-local: test-hostname
- $(builddir)/test-hostname $(srcdir)/hostnames-test.txt > /dev/null
-include $(top_srcdir)/git.mk
diff --git a/shell/alt/Makefile.am b/shell/alt/Makefile.am
index 948b019..b933eea 100644
--- a/shell/alt/Makefile.am
+++ b/shell/alt/Makefile.am
@@ -16,4 +16,6 @@ libshell_alt_la_SOURCES = \
libshell_alt_la_LIBADD = $(top_builddir)/libgd/libgd.la
+test:
+
-include $(top_srcdir)/git.mk
diff --git a/shell/appdata/Makefile.am b/shell/appdata/Makefile.am
index 8ef0428..51bc83b 100644
--- a/shell/appdata/Makefile.am
+++ b/shell/appdata/Makefile.am
@@ -4,6 +4,8 @@ appdata_DATA = $(appdata_in_files:.xml.in=.xml)
appdata_in_files = \
gnome-control-center.appdata.xml.in
+test:
+
EXTRA_DIST = $(appdata_in_files)
CLEANFILES = \
diff --git a/shell/test-hostname.c b/shell/test-hostname.c
index 9a6e6e5..d8cee19 100644
--- a/shell/test-hostname.c
+++ b/shell/test-hostname.c
@@ -6,36 +6,25 @@
#include "hostname-helper.h"
-int main (int argc, char **argv)
+static void
+test_hostname (void)
{
+ char *contents;
char *result;
guint i;
- char *contents;
char **lines;
- char *locale;
- /* Running in some locales will
- * break the tests as "ü" will be transliterated to
- * "ue" in de_DE, and 'u"' in the C locale.
- *
- * Work around that by forcing en_US with UTF-8 in
- * our tests
- * https://bugzilla.gnome.org/show_bug.cgi?id=650342 */
- locale = setlocale (LC_ALL, "en_US.UTF-8");
- if (locale == NULL) {
- g_debug("Missing en_US.UTF-8 locale, ignoring test.");
- return 0;
+ if (g_file_get_contents (TEST_SRCDIR "/hostnames-test.txt", &contents, NULL, NULL) == FALSE) {
+ g_warning ("Failed to load '%s'", TEST_SRCDIR "/hostnames-test.txt");
+ g_test_fail ();
+ return;
}
- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
- if (g_file_get_contents (argv[1], &contents, NULL, NULL) == FALSE) {
- g_warning ("Failed to load '%s'", argv[1]);
- return 1;
- }
lines = g_strsplit (contents, "\n", -1);
if (lines == NULL) {
g_warning ("Test file is empty");
- return 1;
+ g_test_fail ();
+ return;
}
for (i = 0; lines[i] != NULL; i++) {
@@ -50,23 +39,27 @@ int main (int argc, char **argv)
items = g_strsplit (lines[i], "\t", -1);
utf8 = g_locale_from_utf8 (items[0], -1, NULL, NULL, NULL);
result = pretty_hostname_to_static (items[0], FALSE);
- if (g_strcmp0 (result, items[2]) != 0)
+ if (g_strcmp0 (result, items[2]) != 0) {
g_error ("Result for '%s' doesn't match '%s' (got: '%s')",
utf8, items[2], result);
- else
+ g_test_fail ();
+ } else {
g_debug ("Result for '%s' matches '%s'",
utf8, result);
+ }
g_free (result);
g_free (utf8);
result = pretty_hostname_to_static (items[0], TRUE);
utf8 = g_locale_from_utf8 (items[0], -1, NULL, NULL, NULL);
- if (g_strcmp0 (result, items[1]) != 0)
+ if (g_strcmp0 (result, items[1]) != 0) {
g_error ("Result for '%s' doesn't match '%s' (got: '%s')",
utf8, items[1], result);
- else
+ g_test_fail ();
+ } else {
g_debug ("Result for '%s' matches '%s'",
utf8, result);
+ }
g_free (result);
g_free (utf8);
@@ -74,6 +67,29 @@ int main (int argc, char **argv)
}
g_strfreev (lines);
+ g_free (contents);
+}
+
+int main (int argc, char **argv)
+{
+ char *locale;
+
+ /* Running in some locales will
+ * break the tests as "ü" will be transliterated to
+ * "ue" in de_DE, and 'u"' in the C locale.
+ *
+ * Work around that by forcing en_US with UTF-8 in
+ * our tests
+ * https://bugzilla.gnome.org/show_bug.cgi?id=650342 */
+ locale = setlocale (LC_ALL, "en_US.UTF-8");
+ if (locale == NULL) {
+ g_debug("Missing en_US.UTF-8 locale, ignoring test.");
+ return 0;
+ }
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/shell/hostname", test_hostname);
- return 0;
+ return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]