[gnome-control-center/gnome-3-22] info: Add test suite for info cleanup
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/gnome-3-22] info: Add test suite for info cleanup
- Date: Wed, 16 Nov 2016 16:07:11 +0000 (UTC)
commit 59ad2792b091ce8888fda08e50c12dbe463d0f75
Author: Bastien Nocera <hadess hadess net>
Date: Wed Nov 16 15:20:39 2016 +0100
info: Add test suite for info cleanup
https://bugzilla.gnome.org/show_bug.cgi?id=774240
panels/info/Makefile.am | 13 +++++-
panels/info/info-cleanup-test.txt | 1 +
panels/info/test-info-cleanup.c | 88 +++++++++++++++++++++++++++++++++++++
3 files changed, 101 insertions(+), 1 deletions(-)
---
diff --git a/panels/info/Makefile.am b/panels/info/Makefile.am
index 492fcb1..0e53fec 100644
--- a/panels/info/Makefile.am
+++ b/panels/info/Makefile.am
@@ -1,3 +1,5 @@
+include $(top_srcdir)/Makefile.decl
+
cappletname = info
AM_CPPFLAGS = \
@@ -26,6 +28,15 @@ libinfo_la_SOURCES = \
libinfo_la_LIBADD = $(PANEL_LIBS) $(INFO_PANEL_LIBS)
+noinst_PROGRAMS = test-info-cleanup
+TEST_PROGS += $(noinst_PROGRAMS)
+test_info_cleanup_SOURCES = \
+ test-info-cleanup.c \
+ info-cleanup.h \
+ info-cleanup.c
+test_info_cleanup_LDADD = $(libinfo_la_LIBADD)
+test_info_cleanup_CFLAGS = $(AM_CPPFLAGS) -DTEST_SRCDIR="\"$(srcdir)\""
+
resource_files = $(shell glib-compile-resources --sourcedir=$(srcdir) --generate-dependencies
$(srcdir)/info.gresource.xml)
cc-info-resources.c: info.gresource.xml $(resource_files)
$(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name
cc_info $<
@@ -45,6 +56,6 @@ update-from-gsd:
git commit -m "info: Update from gnome-settings-daemon" $(SPACEFILES)
CLEANFILES = $(desktop_in_files) $(desktop_DATA) $(BUILT_SOURCES)
-EXTRA_DIST = $(resource_files) info.gresource.xml
+EXTRA_DIST = $(resource_files) info.gresource.xml info-cleanup-test.txt
-include $(top_srcdir)/git.mk
diff --git a/panels/info/info-cleanup-test.txt b/panels/info/info-cleanup-test.txt
new file mode 100644
index 0000000..d80c862
--- /dev/null
+++ b/panels/info/info-cleanup-test.txt
@@ -0,0 +1 @@
+Intel(R) Core(TM) i5-4590T CPU @ 2.00GHz Intel<sup>®</sup> Core<sup>™</sup> i5-4590T CPU @ 2.00GHz
diff --git a/panels/info/test-info-cleanup.c b/panels/info/test-info-cleanup.c
new file mode 100644
index 0000000..33ad91b
--- /dev/null
+++ b/panels/info/test-info-cleanup.c
@@ -0,0 +1,88 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2010 Red Hat, Inc
+ * Copyright (C) 2008 William Jon McCann <jmccann redhat com>
+ *
+ * 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/>.
+ *
+ */
+
+#include <config.h>
+
+#include <glib.h>
+#include <locale.h>
+#include "info-cleanup.h"
+
+static void
+test_info (void)
+{
+ char *contents;
+ char *result;
+ guint i;
+ char **lines;
+
+ if (g_file_get_contents (TEST_SRCDIR "/info-cleanup-test.txt", &contents, NULL, NULL) == FALSE) {
+ g_warning ("Failed to load '%s'", TEST_SRCDIR "/info-cleanup-test.txt");
+ g_test_fail ();
+ return;
+ }
+
+ lines = g_strsplit (contents, "\n", -1);
+ if (lines == NULL) {
+ g_warning ("Test file is empty");
+ g_test_fail ();
+ return;
+ }
+
+ for (i = 0; lines[i] != NULL; i++) {
+ char *utf8;
+ char **items;
+
+ if (*lines[i] == '#')
+ continue;
+ if (*lines[i] == '\0')
+ break;
+
+ items = g_strsplit (lines[i], "\t", -1);
+ utf8 = g_locale_from_utf8 (items[0], -1, NULL, NULL, NULL);
+ result = info_cleanup (items[0]);
+ if (g_strcmp0 (result, items[1]) != 0) {
+ g_error ("Result for '%s' doesn't match '%s' (got: '%s')",
+ utf8, items[1], result);
+ g_test_fail ();
+ } else {
+ g_debug ("Result for '%s' matches '%s'",
+ utf8, result);
+ }
+ g_free (result);
+ g_free (utf8);
+
+ g_strfreev (items);
+ }
+
+ g_strfreev (lines);
+ g_free (contents);
+}
+
+int main (int argc, char **argv)
+{
+ setlocale (LC_ALL, "");
+ g_test_init (&argc, &argv, NULL);
+
+ g_setenv ("G_DEBUG", "fatal_warnings", FALSE);
+
+ g_test_add_func ("/info/info", test_info);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]