[virt-tools-list] [PATCH virt-viewer 2/2] Move tests under /tests directory
Pavel Grunt
pgrunt at redhat.com
Wed Mar 9 13:21:23 UTC 2016
Keep tests separated from the code
---
Makefile.am | 2 +-
configure.ac | 1 +
src/Makefile.am | 40 ---------------
src/test-monitor-mapping.c | 119 -------------------------------------------
src/test-version-compare.c | 61 ----------------------
tests/Makefile.am | 30 +++++++++++
tests/test-monitor-mapping.c | 119 +++++++++++++++++++++++++++++++++++++++++++
tests/test-version-compare.c | 61 ++++++++++++++++++++++
8 files changed, 212 insertions(+), 221 deletions(-)
delete mode 100644 src/test-monitor-mapping.c
delete mode 100644 src/test-version-compare.c
create mode 100644 tests/Makefile.am
create mode 100644 tests/test-monitor-mapping.c
create mode 100644 tests/test-version-compare.c
diff --git a/Makefile.am b/Makefile.am
index 769fa21..49ed54c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@ NULL =
ACLOCAL_AMFLAGS = -I m4
-SUBDIRS = icons src man po data
+SUBDIRS = icons src man po data tests
AM_DISTCHECK_CONFIGURE_FLAGS = --disable-update-mimedb
EXTRA_DIST = \
diff --git a/configure.ac b/configure.ac
index e1c9b1b..6d8475b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -255,6 +255,7 @@ AC_CONFIG_FILES([
po/Makefile.in
src/Makefile
src/virt-viewer.rc
+ tests/Makefile
virt-viewer.spec
])
AC_OUTPUT
diff --git a/src/Makefile.am b/src/Makefile.am
index aaa111d..5380b9c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -139,46 +139,6 @@ libvirt_viewer_la_CFLAGS = \
$(COMMON_CFLAGS)
$(NULL)
-check_PROGRAMS = test-version-compare test-monitor-mapping
-TESTS = $(check_PROGRAMS)
-test_version_compare_SOURCES = \
- test-version-compare.c \
- $(NULL)
-test_version_compare_LDFLAGS = \
- $(GLIB2_LIBS) \
- $(GTK_LIBS) \
- $(LIBXML2_LIBS) \
- $(NULL)
-test_version_compare_CFLAGS = \
- -DLOCALE_DIR=\""$(datadir)/locale"\" \
- $(GLIB2_CFLAGS) \
- $(GTK_CFLAGS) \
- $(LIBXML2_CFLAGS) \
- $(WARN_CFLAGS) \
- $(NULL)
-test_version_compare_LDADD = \
- libvirt-viewer-util.la \
- $(NULL)
-
-test_monitor_mapping_SOURCES = \
- test-monitor-mapping.c \
- $(NULL)
-test_monitor_mapping_LDFLAGS = \
- $(GLIB2_LIBS) \
- $(GTK_LIBS) \
- $(LIBXML2_LIBS) \
- $(NULL)
-test_monitor_mapping_CFLAGS = \
- -DLOCALE_DIR=\""$(datadir)/locale"\" \
- $(GLIB2_CFLAGS) \
- $(GTK_CFLAGS) \
- $(LIBXML2_CFLAGS) \
- $(WARN_CFLAGS) \
- $(NULL)
-test_monitor_mapping_LDADD = \
- libvirt-viewer-util.la \
- $(NULL)
-
if HAVE_LIBVIRT
bin_PROGRAMS += virt-viewer
virt_viewer_SOURCES = \
diff --git a/src/test-monitor-mapping.c b/src/test-monitor-mapping.c
deleted file mode 100644
index 004aa51..0000000
--- a/src/test-monitor-mapping.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
-/*
- * Virt Viewer: A virtual machine console viewer
- *
- * Copyright (C) 2016 Red Hat, 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <config.h>
-#include <glib.h>
-#include <virt-viewer-util.h>
-
-gboolean doDebug = FALSE;
-
-/**
- * is_valid_monitor_mapping:
- * @mapping: a value for the "monitor-mapping" key
- *
- * Tests the validity of the settings file for the "monitor-mapping" key:
- * [test-monitor-mapping]
- * monitor-mapping=@mapping
- *
- * Returns: %TRUE if the mapping is valid
- */
-static gboolean
-is_valid_monitor_mapping(const gchar *mapping)
-{
- GKeyFile *key_file;
- gboolean valid;
- const gint nmonitors = 4;
- const gchar *group_name = "test-monitor-mapping";
- const gchar *key = "monitor-mapping";
- const gchar *key_data_fmt = "[%s]\n%s=%s\n";
- gchar *key_data = g_strdup_printf(key_data_fmt, group_name, key, mapping);
-
- key_file = g_key_file_new();
- valid = g_key_file_load_from_data(key_file, key_data, -1, G_KEY_FILE_NONE, NULL);
- if (valid) {
- gsize nmappings;
- gchar **mappings = g_key_file_get_string_list(key_file, group_name, key, &nmappings, NULL);
- GHashTable *map = virt_viewer_parse_monitor_mappings(mappings, nmappings, nmonitors);
-
- valid = (map != NULL);
-
- g_strfreev(mappings);
- g_clear_pointer(&map, g_hash_table_unref);
- }
-
- g_key_file_free(key_file);
- g_free(key_data);
- return valid;
-}
-
-int main(void)
-{
- /* valid monitor mappings */
- g_assert_true(is_valid_monitor_mapping("1:1"));
- g_assert_true(is_valid_monitor_mapping("1:1;2:2"));
- g_assert_true(is_valid_monitor_mapping("1:1;2:2;3:3;"));
- g_assert_true(is_valid_monitor_mapping("1:2;2:1;3:3;4:4"));
- g_assert_true(is_valid_monitor_mapping("4:1;3:2;2:3;1:4"));
-
- /* invalid monitors mappings */
- /* zero ids */
- g_assert_false(is_valid_monitor_mapping("0:0"));
- /* negative guest display id */
- g_assert_false(is_valid_monitor_mapping("-1:1"));
- /* negative client monitor id */
- g_assert_false(is_valid_monitor_mapping("1:-1"));
- /* negative guest display & client monitor id */
- g_assert_false(is_valid_monitor_mapping("-1:-1"));
- /* high guest display id */
- g_assert_false(is_valid_monitor_mapping("100:1"));
- /* high client monitor id */
- g_assert_false(is_valid_monitor_mapping("1:100"));
- /* missing guest display id */
- g_assert_false(is_valid_monitor_mapping("1:1;3:3"));
- /* guest display id used twice */
- g_assert_false(is_valid_monitor_mapping("1:1;1:2"));
- /* client monitor id used twice */
- g_assert_false(is_valid_monitor_mapping("1:1;2:1"));
- /* floating point guest display id */
- g_assert_false(is_valid_monitor_mapping("1.111:1"));
- /* floating point client monitor id */
- g_assert_false(is_valid_monitor_mapping("1:1.111"));
- /* empty mapping */
- g_assert_false(is_valid_monitor_mapping(""));
- g_assert_false(is_valid_monitor_mapping(";"));
- /* missing guest display id */
- g_assert_false(is_valid_monitor_mapping(":1"));
- /* missing client monitor id */
- g_assert_false(is_valid_monitor_mapping("1:"));
- /* missing guest display & client monitor id */
- g_assert_false(is_valid_monitor_mapping(":"));
- /*missing colon */
- g_assert_false(is_valid_monitor_mapping("11"));
- /*missing semicolon */
- g_assert_false(is_valid_monitor_mapping("1:12:2"));
- /* strings */
- g_assert_false(is_valid_monitor_mapping("1:a"));
- g_assert_false(is_valid_monitor_mapping("a:1"));
- g_assert_false(is_valid_monitor_mapping("a:a"));
- g_assert_false(is_valid_monitor_mapping("monitor mapping"));
-
- return 0;
-}
diff --git a/src/test-version-compare.c b/src/test-version-compare.c
deleted file mode 100644
index f14887b..0000000
--- a/src/test-version-compare.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
-/*
- * Virt Viewer: A virtual machine console viewer
- *
- * Copyright (C) 2015 Red Hat, 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <config.h>
-#include <glib.h>
-#include <virt-viewer-util.h>
-
-gboolean doDebug = FALSE;
-
-int main(void)
-{
- g_assert(virt_viewer_compare_buildid("1-1", "1-1") == 0);
- g_assert(virt_viewer_compare_buildid("1-1", "1-1.1") < 0);
- g_assert(virt_viewer_compare_buildid("1-1", "1-2") < 0);
- g_assert(virt_viewer_compare_buildid("1-3", "1-2") > 0);
- g_assert(virt_viewer_compare_buildid("2-3", "1-2") > 0);
- g_assert(virt_viewer_compare_buildid("2-3", "3-2") < 0);
- g_assert(virt_viewer_compare_buildid("2-3", "3-4") < 0);
- g_assert(virt_viewer_compare_buildid("4-3", "3-4") > 0);
-
- g_assert(virt_viewer_compare_buildid("4.0-", "3-4") > 0);
- g_assert(virt_viewer_compare_buildid("4.0-", "3.4-4") > 0);
- g_assert(virt_viewer_compare_buildid(".0-", "3.4-4") < 0);
- g_assert(virt_viewer_compare_buildid("4-", "3-4") > 0);
- g_assert(virt_viewer_compare_buildid("4-3", "3-") > 0);
- g_assert(virt_viewer_compare_buildid("-3", "3-4") < 0);
- g_assert(virt_viewer_compare_buildid("4-3", "-4") > 0);
- g_assert(virt_viewer_compare_buildid("-3", "-4") < 0);
- g_assert(virt_viewer_compare_buildid("4", "3-4") > 0);
- g_assert(virt_viewer_compare_buildid("4-3", "3") > 0);
- g_assert(virt_viewer_compare_buildid("3", "3-4") < 0);
- g_assert(virt_viewer_compare_buildid("4-3", "4") > 0);
- g_assert(virt_viewer_compare_buildid("-3", "-4") < 0);
-
- /* These trigger runtime warnings */
- g_assert(virt_viewer_compare_buildid("-3", "-") > 0);
- g_assert(virt_viewer_compare_buildid("", "-") == 0);
- g_assert(virt_viewer_compare_buildid("", "") == 0);
- g_assert(virt_viewer_compare_buildid("", NULL) == 0);
- g_assert(virt_viewer_compare_buildid(NULL, NULL) == 0);
-
- return 0;
-}
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..470733b
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,30 @@
+NULL =
+
+AM_CPPFLAGS = \
+ -DLOCALE_DIR=\""$(datadir)/locale"\" \
+ -I$(top_srcdir)/src/ \
+ -I$(top_srcdir)/tests/ \
+ $(GLIB2_CFLAGS) \
+ $(GTK_CFLAGS) \
+ $(LIBXML2_CFLAGS) \
+ $(WARN_CFLAGS) \
+ $(NULL)
+
+LDADD= \
+ $(top_builddir)/src/libvirt-viewer-util.la \
+ $(GLIB2_LIBS) \
+ $(GTK_LIBS) \
+ $(LIBXML2_LIBS) \
+ $(NULL)
+
+TESTS = test-version-compare test-monitor-mapping
+check_PROGRAMS = $(TESTS)
+test_version_compare_SOURCES = \
+ test-version-compare.c \
+ $(NULL)
+
+test_monitor_mapping_SOURCES = \
+ test-monitor-mapping.c \
+ $(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/tests/test-monitor-mapping.c b/tests/test-monitor-mapping.c
new file mode 100644
index 0000000..004aa51
--- /dev/null
+++ b/tests/test-monitor-mapping.c
@@ -0,0 +1,119 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ * Virt Viewer: A virtual machine console viewer
+ *
+ * Copyright (C) 2016 Red Hat, 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <config.h>
+#include <glib.h>
+#include <virt-viewer-util.h>
+
+gboolean doDebug = FALSE;
+
+/**
+ * is_valid_monitor_mapping:
+ * @mapping: a value for the "monitor-mapping" key
+ *
+ * Tests the validity of the settings file for the "monitor-mapping" key:
+ * [test-monitor-mapping]
+ * monitor-mapping=@mapping
+ *
+ * Returns: %TRUE if the mapping is valid
+ */
+static gboolean
+is_valid_monitor_mapping(const gchar *mapping)
+{
+ GKeyFile *key_file;
+ gboolean valid;
+ const gint nmonitors = 4;
+ const gchar *group_name = "test-monitor-mapping";
+ const gchar *key = "monitor-mapping";
+ const gchar *key_data_fmt = "[%s]\n%s=%s\n";
+ gchar *key_data = g_strdup_printf(key_data_fmt, group_name, key, mapping);
+
+ key_file = g_key_file_new();
+ valid = g_key_file_load_from_data(key_file, key_data, -1, G_KEY_FILE_NONE, NULL);
+ if (valid) {
+ gsize nmappings;
+ gchar **mappings = g_key_file_get_string_list(key_file, group_name, key, &nmappings, NULL);
+ GHashTable *map = virt_viewer_parse_monitor_mappings(mappings, nmappings, nmonitors);
+
+ valid = (map != NULL);
+
+ g_strfreev(mappings);
+ g_clear_pointer(&map, g_hash_table_unref);
+ }
+
+ g_key_file_free(key_file);
+ g_free(key_data);
+ return valid;
+}
+
+int main(void)
+{
+ /* valid monitor mappings */
+ g_assert_true(is_valid_monitor_mapping("1:1"));
+ g_assert_true(is_valid_monitor_mapping("1:1;2:2"));
+ g_assert_true(is_valid_monitor_mapping("1:1;2:2;3:3;"));
+ g_assert_true(is_valid_monitor_mapping("1:2;2:1;3:3;4:4"));
+ g_assert_true(is_valid_monitor_mapping("4:1;3:2;2:3;1:4"));
+
+ /* invalid monitors mappings */
+ /* zero ids */
+ g_assert_false(is_valid_monitor_mapping("0:0"));
+ /* negative guest display id */
+ g_assert_false(is_valid_monitor_mapping("-1:1"));
+ /* negative client monitor id */
+ g_assert_false(is_valid_monitor_mapping("1:-1"));
+ /* negative guest display & client monitor id */
+ g_assert_false(is_valid_monitor_mapping("-1:-1"));
+ /* high guest display id */
+ g_assert_false(is_valid_monitor_mapping("100:1"));
+ /* high client monitor id */
+ g_assert_false(is_valid_monitor_mapping("1:100"));
+ /* missing guest display id */
+ g_assert_false(is_valid_monitor_mapping("1:1;3:3"));
+ /* guest display id used twice */
+ g_assert_false(is_valid_monitor_mapping("1:1;1:2"));
+ /* client monitor id used twice */
+ g_assert_false(is_valid_monitor_mapping("1:1;2:1"));
+ /* floating point guest display id */
+ g_assert_false(is_valid_monitor_mapping("1.111:1"));
+ /* floating point client monitor id */
+ g_assert_false(is_valid_monitor_mapping("1:1.111"));
+ /* empty mapping */
+ g_assert_false(is_valid_monitor_mapping(""));
+ g_assert_false(is_valid_monitor_mapping(";"));
+ /* missing guest display id */
+ g_assert_false(is_valid_monitor_mapping(":1"));
+ /* missing client monitor id */
+ g_assert_false(is_valid_monitor_mapping("1:"));
+ /* missing guest display & client monitor id */
+ g_assert_false(is_valid_monitor_mapping(":"));
+ /*missing colon */
+ g_assert_false(is_valid_monitor_mapping("11"));
+ /*missing semicolon */
+ g_assert_false(is_valid_monitor_mapping("1:12:2"));
+ /* strings */
+ g_assert_false(is_valid_monitor_mapping("1:a"));
+ g_assert_false(is_valid_monitor_mapping("a:1"));
+ g_assert_false(is_valid_monitor_mapping("a:a"));
+ g_assert_false(is_valid_monitor_mapping("monitor mapping"));
+
+ return 0;
+}
diff --git a/tests/test-version-compare.c b/tests/test-version-compare.c
new file mode 100644
index 0000000..f14887b
--- /dev/null
+++ b/tests/test-version-compare.c
@@ -0,0 +1,61 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ * Virt Viewer: A virtual machine console viewer
+ *
+ * Copyright (C) 2015 Red Hat, 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <config.h>
+#include <glib.h>
+#include <virt-viewer-util.h>
+
+gboolean doDebug = FALSE;
+
+int main(void)
+{
+ g_assert(virt_viewer_compare_buildid("1-1", "1-1") == 0);
+ g_assert(virt_viewer_compare_buildid("1-1", "1-1.1") < 0);
+ g_assert(virt_viewer_compare_buildid("1-1", "1-2") < 0);
+ g_assert(virt_viewer_compare_buildid("1-3", "1-2") > 0);
+ g_assert(virt_viewer_compare_buildid("2-3", "1-2") > 0);
+ g_assert(virt_viewer_compare_buildid("2-3", "3-2") < 0);
+ g_assert(virt_viewer_compare_buildid("2-3", "3-4") < 0);
+ g_assert(virt_viewer_compare_buildid("4-3", "3-4") > 0);
+
+ g_assert(virt_viewer_compare_buildid("4.0-", "3-4") > 0);
+ g_assert(virt_viewer_compare_buildid("4.0-", "3.4-4") > 0);
+ g_assert(virt_viewer_compare_buildid(".0-", "3.4-4") < 0);
+ g_assert(virt_viewer_compare_buildid("4-", "3-4") > 0);
+ g_assert(virt_viewer_compare_buildid("4-3", "3-") > 0);
+ g_assert(virt_viewer_compare_buildid("-3", "3-4") < 0);
+ g_assert(virt_viewer_compare_buildid("4-3", "-4") > 0);
+ g_assert(virt_viewer_compare_buildid("-3", "-4") < 0);
+ g_assert(virt_viewer_compare_buildid("4", "3-4") > 0);
+ g_assert(virt_viewer_compare_buildid("4-3", "3") > 0);
+ g_assert(virt_viewer_compare_buildid("3", "3-4") < 0);
+ g_assert(virt_viewer_compare_buildid("4-3", "4") > 0);
+ g_assert(virt_viewer_compare_buildid("-3", "-4") < 0);
+
+ /* These trigger runtime warnings */
+ g_assert(virt_viewer_compare_buildid("-3", "-") > 0);
+ g_assert(virt_viewer_compare_buildid("", "-") == 0);
+ g_assert(virt_viewer_compare_buildid("", "") == 0);
+ g_assert(virt_viewer_compare_buildid("", NULL) == 0);
+ g_assert(virt_viewer_compare_buildid(NULL, NULL) == 0);
+
+ return 0;
+}
--
2.5.0
More information about the virt-tools-list
mailing list