libnm-glib/test: add asserts to test-remote-settings-client
- register a weak references and ensure that the connection is removed when expected. - disconnect the vis_new_connection_cb() handler Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
@@ -49,7 +49,7 @@ cleanup (void)
|
|||||||
|
|
||||||
#define test_assert(condition) \
|
#define test_assert(condition) \
|
||||||
do { \
|
do { \
|
||||||
gboolean _condition = ( condition ); \
|
gboolean _condition = !!( condition ); \
|
||||||
\
|
\
|
||||||
if (G_UNLIKELY (!_condition)) { \
|
if (G_UNLIKELY (!_condition)) { \
|
||||||
cleanup (); \
|
cleanup (); \
|
||||||
@@ -70,6 +70,7 @@ add_cb (NMRemoteSettings *s,
|
|||||||
|
|
||||||
*((gboolean *) user_data) = TRUE;
|
*((gboolean *) user_data) = TRUE;
|
||||||
remote = connection;
|
remote = connection;
|
||||||
|
g_object_add_weak_pointer (G_OBJECT (connection), (void **) &remote);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TEST_CON_ID "blahblahblah"
|
#define TEST_CON_ID "blahblahblah"
|
||||||
@@ -186,6 +187,7 @@ test_make_invisible (void)
|
|||||||
} while ((done == FALSE) && (now - start < 5));
|
} while ((done == FALSE) && (now - start < 5));
|
||||||
test_assert (done == TRUE);
|
test_assert (done == TRUE);
|
||||||
|
|
||||||
|
g_assert (remote);
|
||||||
g_signal_handlers_disconnect_by_func (remote, G_CALLBACK (invis_removed_cb), &done);
|
g_signal_handlers_disconnect_by_func (remote, G_CALLBACK (invis_removed_cb), &done);
|
||||||
|
|
||||||
/* Ensure NMRemoteSettings no longer has the connection */
|
/* Ensure NMRemoteSettings no longer has the connection */
|
||||||
@@ -198,6 +200,7 @@ test_make_invisible (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* And ensure the invisible connection no longer has any settings */
|
/* And ensure the invisible connection no longer has any settings */
|
||||||
|
g_assert (remote);
|
||||||
nm_connection_for_each_setting_value (NM_CONNECTION (remote),
|
nm_connection_for_each_setting_value (NM_CONNECTION (remote),
|
||||||
invis_has_settings_cb,
|
invis_has_settings_cb,
|
||||||
&has_settings);
|
&has_settings);
|
||||||
@@ -253,8 +256,11 @@ test_make_visible (void)
|
|||||||
} while ((new == NULL) && (now - start < 5));
|
} while ((new == NULL) && (now - start < 5));
|
||||||
|
|
||||||
/* Ensure the new connection is the same as the one we made visible again */
|
/* Ensure the new connection is the same as the one we made visible again */
|
||||||
|
test_assert (new);
|
||||||
test_assert (new == remote);
|
test_assert (new == remote);
|
||||||
|
|
||||||
|
g_signal_handlers_disconnect_by_func (settings, G_CALLBACK (vis_new_connection_cb), &new);
|
||||||
|
|
||||||
/* Ensure NMRemoteSettings has the connection */
|
/* Ensure NMRemoteSettings has the connection */
|
||||||
list = nm_remote_settings_list_connections (settings);
|
list = nm_remote_settings_list_connections (settings);
|
||||||
for (iter = list; iter; iter = g_slist_next (iter)) {
|
for (iter = list; iter; iter = g_slist_next (iter)) {
|
||||||
@@ -311,6 +317,8 @@ test_remove_connection (void)
|
|||||||
test_assert (g_slist_length (list) > 0);
|
test_assert (g_slist_length (list) > 0);
|
||||||
|
|
||||||
connection = NM_REMOTE_CONNECTION (list->data);
|
connection = NM_REMOTE_CONNECTION (list->data);
|
||||||
|
g_assert (connection);
|
||||||
|
g_assert (remote == connection);
|
||||||
path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection)));
|
path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection)));
|
||||||
g_signal_connect (connection, "removed", G_CALLBACK (removed_cb), &done);
|
g_signal_connect (connection, "removed", G_CALLBACK (removed_cb), &done);
|
||||||
|
|
||||||
@@ -330,6 +338,8 @@ test_remove_connection (void)
|
|||||||
} while ((done == FALSE) && (now - start < 5));
|
} while ((done == FALSE) && (now - start < 5));
|
||||||
test_assert (done == TRUE);
|
test_assert (done == TRUE);
|
||||||
|
|
||||||
|
g_assert (!remote);
|
||||||
|
|
||||||
/* Ensure NMRemoteSettings no longer has the connection */
|
/* Ensure NMRemoteSettings no longer has the connection */
|
||||||
list = nm_remote_settings_list_connections (settings);
|
list = nm_remote_settings_list_connections (settings);
|
||||||
for (iter = list; iter; iter = g_slist_next (iter)) {
|
for (iter = list; iter; iter = g_slist_next (iter)) {
|
||||||
|
Reference in New Issue
Block a user