summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-02-27 10:24:09 +0100
committerThomas Haller <thaller@redhat.com>2015-03-12 18:16:58 +0100
commit997fc07ca5b3bcafcdaa69dc7c7f6d8671efa4b4 (patch)
tree8ed96d29452bece679082017eb4f0f07ecdb1950
parentc9a8764ad2805e22e1c556679e09636550374e21 (diff)
downloadNetworkManager-997fc07ca5b3bcafcdaa69dc7c7f6d8671efa4b4.tar.gz
test: add nmtst_create_connection_from_keyfile()
-rw-r--r--include/nm-test-utils.h30
-rw-r--r--libnm-core/tests/test-keyfile.c7
2 files changed, 37 insertions, 0 deletions
diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h
index 33b8fa51a7..187a0f1931 100644
--- a/include/nm-test-utils.h
+++ b/include/nm-test-utils.h
@@ -1061,6 +1061,36 @@ nmtst_assert_hwaddr_equals (gconstpointer hwaddr1, gssize hwaddr1_len, const cha
nmtst_assert_hwaddr_equals (hwaddr1, hwaddr1_len, expected, G_STRLOC)
#endif
+#if defined(__NM_SIMPLE_CONNECTION_H__) && defined(__NM_SETTING_CONNECTION_H__) && defined(__NM_KEYFILE_INTERNAL_H__)
+
+inline static NMConnection *
+nmtst_create_connection_from_keyfile (const char *keyfile_str, const char *keyfile_name, const char *base_dir)
+{
+ GKeyFile *keyfile;
+ GError *error = NULL;
+ gboolean success;
+ NMConnection *con;
+
+ g_assert (keyfile_str);
+
+ keyfile = g_key_file_new ();
+ success = g_key_file_load_from_data (keyfile, keyfile_str, strlen (keyfile_str), G_KEY_FILE_NONE, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+
+ con = nm_keyfile_read (keyfile, keyfile_name, base_dir, NULL, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (NM_IS_CONNECTION (con));
+
+ g_key_file_unref (keyfile);
+
+ nmtst_connection_normalize (con);
+
+ return con;
+}
+
+#endif
+
#ifdef __NM_CONNECTION_H__
typedef enum {
diff --git a/libnm-core/tests/test-keyfile.c b/libnm-core/tests/test-keyfile.c
index a0f590e7cd..43958cb6bb 100644
--- a/libnm-core/tests/test-keyfile.c
+++ b/libnm-core/tests/test-keyfile.c
@@ -345,6 +345,13 @@ test_8021x_cert_read (void)
gs_unref_object NMConnection *con = NULL;
NMSetting8021x *s_8021x;
+ con = nmtst_create_connection_from_keyfile (
+ "[connection]\n"
+ "type=ethernet",
+ "/test_8021x_cert_read/test0", NULL);
+ CLEAR (&con, &keyfile);
+
+
keyfile = _keyfile_load_from_data (
"[connection]\n"
"type=ethernet"