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:
Thomas Haller 2014-07-27 04:54:13 +02:00
parent d6b3ef0819
commit 1de6d83e29

View file

@ -49,7 +49,7 @@ cleanup (void)
#define test_assert(condition) \
do { \
gboolean _condition = ( condition ); \
gboolean _condition = !!( condition ); \
\
if (G_UNLIKELY (!_condition)) { \
cleanup (); \
@ -70,6 +70,7 @@ add_cb (NMRemoteSettings *s,
*((gboolean *) user_data) = TRUE;
remote = connection;
g_object_add_weak_pointer (G_OBJECT (connection), (void **) &remote);
}
#define TEST_CON_ID "blahblahblah"
@ -186,6 +187,7 @@ test_make_invisible (void)
} while ((done == FALSE) && (now - start < 5));
test_assert (done == TRUE);
g_assert (remote);
g_signal_handlers_disconnect_by_func (remote, G_CALLBACK (invis_removed_cb), &done);
/* 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 */
g_assert (remote);
nm_connection_for_each_setting_value (NM_CONNECTION (remote),
invis_has_settings_cb,
&has_settings);
@ -253,8 +256,11 @@ test_make_visible (void)
} while ((new == NULL) && (now - start < 5));
/* Ensure the new connection is the same as the one we made visible again */
test_assert (new);
test_assert (new == remote);
g_signal_handlers_disconnect_by_func (settings, G_CALLBACK (vis_new_connection_cb), &new);
/* Ensure NMRemoteSettings has the connection */
list = nm_remote_settings_list_connections (settings);
for (iter = list; iter; iter = g_slist_next (iter)) {
@ -311,6 +317,8 @@ test_remove_connection (void)
test_assert (g_slist_length (list) > 0);
connection = NM_REMOTE_CONNECTION (list->data);
g_assert (connection);
g_assert (remote == connection);
path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection)));
g_signal_connect (connection, "removed", G_CALLBACK (removed_cb), &done);
@ -330,6 +338,8 @@ test_remove_connection (void)
} while ((done == FALSE) && (now - start < 5));
test_assert (done == TRUE);
g_assert (!remote);
/* Ensure NMRemoteSettings no longer has the connection */
list = nm_remote_settings_list_connections (settings);
for (iter = list; iter; iter = g_slist_next (iter)) {