[network-manager-openvpn/NM_0_8] test: handle relative paths if testcase launched manually (bgo #626292)



commit bebe633d468663932cd3c53ccc34df8088cb0b06
Author: Dan Williams <dcbw redhat com>
Date:   Mon Aug 9 11:29:10 2010 -0500

    test: handle relative paths if testcase launched manually (bgo #626292)
    
    The file dialog will always give us absolute paths, so we never hit
    this bug in the testcase and import scripts.  But if the tool is
    launched manually we need to get the absolute path to the config file.

 properties/import-export.c            |   22 +++++++++++++---------
 properties/tests/test-import-export.c |   17 +++++++++++++----
 2 files changed, 26 insertions(+), 13 deletions(-)
---
diff --git a/properties/import-export.c b/properties/import-export.c
index ecb7b79..a33b1b7 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -209,7 +209,7 @@ do_import (const char *path, char **lines, GError **error)
 	gboolean have_pass = FALSE, have_sk = FALSE;
 	const char *ctype = NULL;
 	char *basename;
-	char *default_path;
+	char *default_path, *tmp, *tmp2;
 
 	connection = nm_connection_new ();
 	s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
@@ -221,7 +221,15 @@ do_import (const char *path, char **lines, GError **error)
 	
 	/* Get the default path for ca, cert, key file, these files maybe
 	 * in same path with the configuration file */
-	default_path = g_path_get_dirname (path);
+	if (g_path_is_absolute (path))
+		default_path = g_path_get_dirname (path);
+	else {
+		tmp = g_get_current_dir ();
+		tmp2 = g_path_get_dirname (path);
+		default_path = g_build_filename (tmp, tmp2, NULL);
+		g_free (tmp);
+		g_free (tmp2);
+	}
 
 	basename = g_path_get_basename (path);
 	last_dot = strrchr (basename, '.');
@@ -282,7 +290,7 @@ do_import (const char *path, char **lines, GError **error)
 				errno = 0;
 				secs = strtol (items[0], NULL, 10);
 				if ((errno == 0) && (secs >= 0) && (secs < 0xffff)) {
-					char *tmp = g_strdup_printf ("%d", (guint32) secs);
+					tmp = g_strdup_printf ("%d", (guint32) secs);
 					nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_TUNNEL_MTU, tmp);
 					g_free (tmp);
 				} else
@@ -303,7 +311,7 @@ do_import (const char *path, char **lines, GError **error)
 				errno = 0;
 				secs = strtol (items[0], NULL, 10);
 				if ((errno == 0) && (secs >= 0) && (secs < 0xffff)) {
-					char *tmp = g_strdup_printf ("%d", (guint32) secs);
+					tmp = g_strdup_printf ("%d", (guint32) secs);
 					nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_FRAGMENT_SIZE, tmp);
 					g_free (tmp);
 				} else
@@ -329,7 +337,7 @@ do_import (const char *path, char **lines, GError **error)
 				errno = 0;
 				secs = strtol (items[0], NULL, 10);
 				if ((errno == 0) && (secs >= 0) && (secs < 604800)) {
-					char *tmp = g_strdup_printf ("%d", (guint32) secs);
+					tmp = g_strdup_printf ("%d", (guint32) secs);
 					nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_RENEG_SECONDS, tmp);
 					g_free (tmp);
 				} else
@@ -349,8 +357,6 @@ do_import (const char *path, char **lines, GError **error)
 				have_remote = TRUE;
 
 				if (g_strv_length (items) >= 2) {
-					char *tmp;
-
 					tmp = parse_port (items[1], *line);
 					if (tmp) {
 						nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_PORT, tmp);
@@ -367,8 +373,6 @@ do_import (const char *path, char **lines, GError **error)
 
 		if (   !strncmp (*line, PORT_TAG, strlen (PORT_TAG))
 		    || !strncmp (*line, RPORT_TAG, strlen (RPORT_TAG))) {
-			char *tmp;
-
 			/* Port specified in 'remote' always takes precedence */
 			if (nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PORT))
 				continue;
diff --git a/properties/tests/test-import-export.c b/properties/tests/test-import-export.c
index 3a0686e..77ee420 100644
--- a/properties/tests/test-import-export.c
+++ b/properties/tests/test-import-export.c
@@ -753,7 +753,7 @@ int main (int argc, char **argv)
 	DBusGConnection *bus;
 	char *basename;
 	NMVpnPluginUiInterface *plugin = NULL;
-	char *test_dir;
+	char *tmp, *tmp2, *test_dir;
 
 	if (argc != 2)
 		FAIL ("args", "usage: %s <conf path>", argv[0]);
@@ -771,9 +771,18 @@ int main (int argc, char **argv)
 	        "plugin-init", "failed to initialize UI plugin");
 
 	/* Strip off trailing '/' from tests directory if present */
-	test_dir = argv[1];
-	if (test_dir[strlen (test_dir) - 1] == '/')
-		test_dir[strlen (test_dir) - 1] = '\0';
+	tmp = argv[1];
+	if (tmp[strlen (tmp) - 1] == '/')
+		tmp[strlen (tmp) - 1] = '\0';
+
+	if (g_path_is_absolute (tmp))
+		test_dir = g_strdup (tmp);
+	else {
+		tmp2 = g_get_current_dir ();
+		test_dir = g_build_filename (tmp2, tmp, NULL);
+		g_free (tmp2);
+	}
+
 	/* The tests */
 	test_password_import (plugin, test_dir);
 	test_password_export (plugin, test_dir);



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