[network-manager-openvpn: 17/25] properties/tests: refactor creation of vpn plugin instance



commit 6dd985307f7a0f9583b395f60df32b4b43a30250
Author: Thomas Haller <thaller redhat com>
Date:   Wed Feb 3 12:59:54 2016 +0100

    properties/tests: refactor creation of vpn plugin instance

 properties/tests/test-import-export.c |   27 ++++++++++++++++++---------
 1 files changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/properties/tests/test-import-export.c b/properties/tests/test-import-export.c
index 147dd7b..132bd03 100644
--- a/properties/tests/test-import-export.c
+++ b/properties/tests/test-import-export.c
@@ -36,6 +36,22 @@
 #define TEST_SRCDIR_CONF     TEST_SRCDIR"/conf"
 #define TEST_BUILDDIR_CONF   TEST_BUILDDIR"/conf"
 
+/*****************************************************************************/
+
+static NMVpnEditorPlugin *
+_create_plugin (void)
+{
+       NMVpnEditorPlugin *plugin;
+       GError *error = NULL;
+
+       plugin = nm_vpn_editor_plugin_factory (&error);
+       g_assert_no_error (error);
+       g_assert (OPENVPN_IS_EDITOR_PLUGIN (plugin));
+       return plugin;
+}
+
+/*****************************************************************************/
+
 inline static in_addr_t
 _addr_from_string (const char *saddr)
 {
@@ -1450,19 +1466,14 @@ NMTST_DEFINE ();
 
 int main (int argc, char **argv)
 {
-       GError *error = NULL;
        char *basename;
-       NMVpnEditorPlugin *plugin = NULL;
+       gs_unref_object NMVpnEditorPlugin *plugin = NULL;
 
        _nmovpn_test_temp_path = TEST_BUILDDIR_CONF;
 
        nmtst_init (&argc, &argv, TRUE);
 
-       plugin = nm_vpn_editor_plugin_factory (&error);
-       if (error)
-               FAIL ("plugin-init", "failed to initialize UI plugin: %s", error->message);
-       ASSERT (plugin != NULL,
-               "plugin-init", "failed to initialize UI plugin");
+       plugin = _create_plugin ();
 
        /* The tests */
        test_password_import (plugin, TEST_SRCDIR_CONF);
@@ -1520,8 +1531,6 @@ int main (int argc, char **argv)
 
        test_args_parse_line ();
 
-       g_object_unref (plugin);
-
        basename = g_path_get_basename (argv[0]);
        fprintf (stdout, "%s: SUCCESS\n", basename);
        g_free (basename);


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