summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-07-08 19:23:11 +0200
committerDan Winship <danw@gnome.org>2014-08-07 15:43:43 -0400
commitd83f3777adfc587be56755fc567a8fbcfac5d5b9 (patch)
tree7eb2315a22c3559d745fb2d3760a4db082af4d01 /include
parent9ec70a8877b0ae4f91bbb745702bd7272b44778f (diff)
downloadNetworkManager-d83f3777adfc587be56755fc567a8fbcfac5d5b9.tar.gz
nmtst: add nmtst_create_minimal_connection() function
Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/nm-test-utils.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h
index 09ab1ad988..d666a8e837 100644
--- a/include/nm-test-utils.h
+++ b/include/nm-test-utils.h
@@ -679,5 +679,49 @@ nmtst_ip6_config_clone (NMIP6Config *config)
#endif
+#ifdef NM_CONNECTION_H
+
+inline static NMConnection *
+nmtst_create_minimal_connection (const char *id, const char *uuid, const char *type, NMSettingConnection **out_s_con)
+{
+ NMConnection *con;
+ NMSetting *s_base = NULL;
+ NMSettingConnection *s_con;
+
+ g_assert (id);
+
+ if (uuid)
+ g_assert (nm_utils_is_uuid (uuid));
+ else
+ uuid = nm_utils_uuid_generate ();
+
+ if (type) {
+ GType type_g = nm_connection_lookup_setting_type (type);
+
+ g_assert (type_g != G_TYPE_INVALID);
+
+ s_base = g_object_new (type_g, NULL);
+ g_assert (NM_IS_SETTING (s_base));
+ }
+
+ con = nm_connection_new ();
+ s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
+
+ g_object_set (s_con,
+ NM_SETTING_CONNECTION_ID, id,
+ NM_SETTING_CONNECTION_UUID, uuid,
+ NM_SETTING_CONNECTION_TYPE, type,
+ NULL);
+ nm_connection_add_setting (con, NM_SETTING (s_con));
+
+ if (s_base)
+ nm_connection_add_setting (con, s_base);
+
+ if (out_s_con)
+ *out_s_con = s_con;
+ return con;
+}
+
+#endif
#endif /* __NM_TEST_UTILS_H__ */