[network-manager-vpnc/th/vpn-editor-split-bgo766170: 5/19] properties/tests: refactor tests to run via TESTS instead of check-local target



commit 3ea91f478c97fd2d454cced2704cd769209b446e
Author: Thomas Haller <thaller redhat com>
Date:   Mon May 9 10:45:21 2016 +0200

    properties/tests: refactor tests to run via TESTS instead of check-local target
    
    And thus, don't expect the test-paths as command line arguments.

 .gitignore                            |    4 +++
 nm-test-helpers.h                     |    2 +-
 properties/tests/Makefile.am          |   47 +++++++++++++++----------------
 properties/tests/test-import-export.c |   48 +++++++++++++++++++-------------
 4 files changed, 56 insertions(+), 45 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 8a01bc5..90542d8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,6 +29,10 @@ m4/libtool.m4
 m4/lt*.m4
 appdata/network-manager-vpnc.metainfo.xml
 
+/test-driver
+*/tests/*.log
+*/tests/*.trs
+
 /cscope.*
 
 auth-dialog/nm-vpnc-auth-dialog
diff --git a/nm-test-helpers.h b/nm-test-helpers.h
index 840e25f..5015a1b 100644
--- a/nm-test-helpers.h
+++ b/nm-test-helpers.h
@@ -37,7 +37,7 @@ FAIL(const char *test_name, const char *fmt, ...)
        va_start (args, fmt);
        vfprintf (stderr, buf, args);
        va_end (args);
-       _exit (1);
+       g_assert_not_reached ();
 }
 
 #define ASSERT(x, test_name, fmt, ...) \
diff --git a/properties/tests/Makefile.am b/properties/tests/Makefile.am
index 4c9542b..eb9c9b6 100644
--- a/properties/tests/Makefile.am
+++ b/properties/tests/Makefile.am
@@ -1,31 +1,30 @@
-SUBDIRS=pcf
+SUBDIRS = pcf
 
-noinst_PROGRAMS = test-import-export
+noinst_PROGRAMS = \
+    test-import-export
 
 test_import_export_SOURCES = \
-       test-import-export.c
+    test-import-export.c
 
 test_import_export_CPPFLAGS = \
-       $(GLIB_CFLAGS) \
-       $(GTK_CFLAGS) \
-       $(LIBNM_CFLAGS) \
-       $(LIBNMA_CFLAGS) \
-       $(DBUS_CFLAGS) \
-       -I"$(top_srcdir)/shared/" \
-       -I"$(top_srcdir)/properties/"
+    $(GLIB_CFLAGS) \
+    $(GTK_CFLAGS) \
+    $(LIBNM_CFLAGS) \
+    $(LIBNMA_CFLAGS) \
+    $(DBUS_CFLAGS) \
+    -I"$(top_srcdir)/shared/" \
+    -I"$(top_srcdir)/properties/" \
+    -DTEST_SRCDIR="\"$(abs_srcdir)\"" \
+    -DTEST_BUILDDIR="\"$(abs_builddir)\""
 
-test_import_export_LDADD = \
-       $(GTHREAD_LIBS) \
-       $(GTK_LIBS) \
-       $(DBUS_LIBS) \
-       $(LIBNM_LIBS) \
-       $(LIBNMA_LIBS) \
-       $(top_builddir)/properties/libnm-vpn-plugin-vpnc.la
-
-if WITH_TESTS
-
-check-local: test-import-export
-       $(abs_builddir)/test-import-export $(abs_srcdir)/pcf $(abs_builddir)/pcf
-
-endif
 
+test_import_export_LDADD = \
+    $(GTHREAD_LIBS) \
+    $(GTK_LIBS) \
+    $(DBUS_LIBS) \
+    $(LIBNM_LIBS) \
+    $(LIBNMA_LIBS) \
+    $(top_builddir)/properties/libnm-vpn-plugin-vpnc.la
+
+TESTS = \
+    test-import-export
diff --git a/properties/tests/test-import-export.c b/properties/tests/test-import-export.c
index ac2c96e..9b14232 100644
--- a/properties/tests/test-import-export.c
+++ b/properties/tests/test-import-export.c
@@ -22,6 +22,7 @@
 #include "nm-default.h"
 
 #include <string.h>
+#include <sys/stat.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <locale.h>
@@ -32,6 +33,9 @@
 #include "nm-test-helpers.h"
 #include "nm-test-utils.h"
 
+#define SRCDIR TEST_SRCDIR"/pcf"
+#define TMPDIR TEST_BUILDDIR"/pcf-tmp"
+
 typedef struct {
        const char *name;
        const char *value;
@@ -747,16 +751,20 @@ test_empty_keyfile_string_null (const char *dir)
 int main (int argc, char **argv)
 {
        GError *error = NULL;
+       int errsv;
        char *basename;
        NMVpnEditorPlugin *plugin = NULL;
 
-       if (argc != 3)
-               FAIL ("args", "usage: %s <pcf path> <tmp path>", argv[0]);
-
 #if !GLIB_CHECK_VERSION (2, 35, 0)
        g_type_init ();
 #endif
 
+       if (mkdir (TMPDIR, 0755) != 0) {
+               errsv = errno;
+               if (errsv != EEXIST)
+                       g_error ("failed creating \"%s\": %s", TMPDIR, g_strerror (errsv));
+       }
+
        plugin = nm_vpn_editor_plugin_factory (&error);
        if (error)
                FAIL ("plugin-init", "failed to initialize UI plugin: %s", error->message);
@@ -764,23 +772,23 @@ int main (int argc, char **argv)
                "plugin-init", "failed to initialize UI plugin");
 
        /* The tests */
-       test_basic_import (plugin, argv[1]);
-       test_everything_via_vpn (plugin, argv[1]);
-       test_no_natt (plugin, argv[1]);
-       test_nat_cisco (plugin, argv[1]);
-       test_nat_natt (plugin, argv[1]);
-       test_nat_force_natt (plugin, argv[1]);
-       test_always_ask (plugin, argv[1]);
-       test_non_utf8_import (plugin, argv[1]);
-       test_legacy_ike_port_0_import (plugin, argv[1]);
-       test_legacy_ike_port_1_import (plugin, argv[1]);
-
-       test_basic_export (plugin, argv[1], argv[2]);
-       test_nat_export (plugin, argv[1], argv[2], NM_VPNC_NATT_MODE_CISCO);
-       test_nat_export (plugin, argv[1], argv[2], NM_VPNC_NATT_MODE_NATT);
-       test_nat_export (plugin, argv[1], argv[2], NM_VPNC_NATT_MODE_NATT_ALWAYS);
-
-       test_empty_keyfile_string_null (argv[1]);
+       test_basic_import (plugin, SRCDIR);
+       test_everything_via_vpn (plugin, SRCDIR);
+       test_no_natt (plugin, SRCDIR);
+       test_nat_cisco (plugin, SRCDIR);
+       test_nat_natt (plugin, SRCDIR);
+       test_nat_force_natt (plugin, SRCDIR);
+       test_always_ask (plugin, SRCDIR);
+       test_non_utf8_import (plugin, SRCDIR);
+       test_legacy_ike_port_0_import (plugin, SRCDIR);
+       test_legacy_ike_port_1_import (plugin, SRCDIR);
+
+       test_basic_export (plugin, SRCDIR, TMPDIR);
+       test_nat_export (plugin, SRCDIR, TMPDIR, NM_VPNC_NATT_MODE_CISCO);
+       test_nat_export (plugin, SRCDIR, TMPDIR, NM_VPNC_NATT_MODE_NATT);
+       test_nat_export (plugin, SRCDIR, TMPDIR, NM_VPNC_NATT_MODE_NATT_ALWAYS);
+
+       test_empty_keyfile_string_null (SRCDIR);
 
        g_object_unref (plugin);
 


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