Commit e1e82ccd authored by Benjamin Berg's avatar Benjamin Berg

tests: Add VPN related tests

This adds tests for the VPN section. Note that the tests to check
sorting are disabled currently as sorting is not implemented.
parent 870b64b8
......@@ -379,6 +379,264 @@ test_connection_multi_add_activate (NetworkPanelFixture *fixture,
g_assert_false (bt_header && gtk_widget_is_visible(bt_header));
}
/*****************************************************************************/
static void
test_vpn_add (NetworkPanelFixture *fixture,
gconstpointer user_data)
{
NMConnection *conn;
NMSettingConnection *connsetting;
NMSettingVpn *setting;
g_autoptr(GError) error = NULL;
WAIT_DECL()
conn = nmtst_create_minimal_connection ("test_vpn_a", NULL, NM_SETTING_VPN_SETTING_NAME, &connsetting);
setting = nm_connection_get_setting_vpn (conn);
g_object_set (G_OBJECT (connsetting), NM_SETTING_CONNECTION_ID, "A", NULL);
g_object_set (G_OBJECT (setting), NM_SETTING_VPN_SERVICE_TYPE, "org.freedesktop.NetworkManager.vpnc", NULL);
nm_client_add_connection_async (fixture->client, conn, TRUE, NULL, add_cb, &info);
info.other_remaining = 1;
WAIT_CLIENT(fixture->client, 2, NM_CLIENT_CONNECTIONS, NM_CLIENT_CONNECTION_ADDED);
g_object_unref (conn);
WAIT_FINISHED(5)
g_clear_object (&info.rc);
/* Make sure it shows up. */
g_assert_nonnull (gtk_test_find_label (fixture->shell, "A VPN"));
}
/*****************************************************************************/
static void
test_vpn_add_remove (NetworkPanelFixture *fixture,
gconstpointer user_data)
{
NMConnection *conn;
NMSettingConnection *connsetting;
NMSettingVpn *setting;
g_autoptr(GError) error = NULL;
WAIT_DECL()
conn = nmtst_create_minimal_connection ("test_vpn_a", NULL, NM_SETTING_VPN_SETTING_NAME, &connsetting);
setting = nm_connection_get_setting_vpn (conn);
g_object_set (G_OBJECT (connsetting), NM_SETTING_CONNECTION_ID, "A", NULL);
g_object_set (G_OBJECT (setting), NM_SETTING_VPN_SERVICE_TYPE, "org.freedesktop.NetworkManager.vpnc", NULL);
nm_client_add_connection_async (fixture->client, conn, TRUE, NULL, add_cb, &info);
info.other_remaining = 1;
WAIT_CLIENT(fixture->client, 2, NM_CLIENT_CONNECTIONS, NM_CLIENT_CONNECTION_ADDED);
WAIT_FINISHED(5)
/* Make sure it shows up. */
g_assert_nonnull (gtk_test_find_label (fixture->shell, "A VPN"));
/* And delete again */
nm_remote_connection_delete_async (info.rc, NULL, delete_cb, &info);
info.other_remaining = 1;
WAIT_CLIENT(fixture->client, 2, NM_CLIENT_CONNECTIONS, NM_CLIENT_CONNECTION_REMOVED);
WAIT_FINISHED(5)
g_clear_object (&info.rc);
g_object_unref (conn);
/* Make sure it does not show up. */
g_assert_null (gtk_test_find_label (fixture->shell, "A VPN"));
}
/*****************************************************************************/
static void
test_vpn_updating (NetworkPanelFixture *fixture,
gconstpointer user_data)
{
NMConnection *conn;
NMSettingConnection *connsetting;
NMSettingVpn *setting;
g_autoptr(GError) error = NULL;
GVariantBuilder builder;
WAIT_DECL()
conn = nmtst_create_minimal_connection ("test_vpn_a", NULL, NM_SETTING_VPN_SETTING_NAME, &connsetting);
setting = nm_connection_get_setting_vpn (conn);
g_object_set (G_OBJECT (connsetting), NM_SETTING_CONNECTION_ID, "A", NULL);
g_object_set (G_OBJECT (setting), NM_SETTING_VPN_SERVICE_TYPE, "org.freedesktop.NetworkManager.vpnc", NULL);
nm_client_add_connection_async (fixture->client, conn, TRUE, NULL, add_cb, &info);
info.other_remaining = 1;
WAIT_CLIENT(fixture->client, 2, NM_CLIENT_CONNECTIONS, NM_CLIENT_CONNECTION_ADDED);
WAIT_FINISHED(5)
g_object_unref (conn);
/* Make sure it shows up. */
g_assert_nonnull (gtk_test_find_label (fixture->shell, "A VPN"));
/* Rename VPN from A to B */
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sa{sv}}"));
g_variant_builder_open (&builder, G_VARIANT_TYPE ("{sa{sv}}"));
g_variant_builder_add (&builder, "s", "connection");
g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_open (&builder, G_VARIANT_TYPE ("{sv}"));
g_variant_builder_add (&builder, "s", "id");
g_variant_builder_add (&builder, "v", g_variant_new_string ("B"));
g_variant_builder_close (&builder);
g_variant_builder_open (&builder, G_VARIANT_TYPE ("{sv}"));
g_variant_builder_add (&builder, "s", "type");
g_variant_builder_add (&builder, "v", g_variant_new_string (nm_connection_get_connection_type (NM_CONNECTION (info.rc))));
g_variant_builder_close (&builder);
g_variant_builder_open (&builder, G_VARIANT_TYPE ("{sv}"));
g_variant_builder_add (&builder, "s", "uuid");
g_variant_builder_add (&builder, "v", g_variant_new_string (nm_connection_get_uuid (NM_CONNECTION (info.rc))));
g_variant_builder_close (&builder);
g_variant_builder_close (&builder);
g_variant_builder_close (&builder);
nmtstc_service_update_connection_variant (
fixture->sinfo,
nm_object_get_path (NM_OBJECT (info.rc)),
g_variant_builder_end (&builder),
FALSE);
g_variant_builder_clear (&builder);
WAIT_CONNECTION(info.rc, 1, "changed");
WAIT_FINISHED(5)
g_clear_object (&info.rc);
/* Make sure it the label got renamed. */
g_assert_null (gtk_test_find_label (fixture->shell, "A VPN"));
g_assert_nonnull (gtk_test_find_label (fixture->shell, "B VPN"));
}
/*****************************************************************************/
static void
test_vpn_sorting (NetworkPanelFixture *fixture,
gconstpointer user_data)
{
NMConnection *conn;
NMSettingConnection *connsetting;
NMSettingVpn *setting;
g_autoptr(GError) error = NULL;
GVariantBuilder builder;
GtkWidget *a, *b, *container;
GList *list;
WAIT_DECL()
conn = nmtst_create_minimal_connection ("test_vpn_a", NULL, NM_SETTING_VPN_SETTING_NAME, &connsetting);
setting = nm_connection_get_setting_vpn (conn);
g_object_set (G_OBJECT (connsetting), NM_SETTING_CONNECTION_ID, "A", NULL);
g_object_set (G_OBJECT (setting), NM_SETTING_VPN_SERVICE_TYPE, "org.freedesktop.NetworkManager.vpnc", NULL);
nm_client_add_connection_async (fixture->client, conn, TRUE, NULL, add_cb, &info);
info.other_remaining = 1;
WAIT_CLIENT(fixture->client, 2, NM_CLIENT_CONNECTIONS, NM_CLIENT_CONNECTION_ADDED);
WAIT_FINISHED(5)
g_object_unref (conn);
g_clear_object (&info.rc);
/* Create a second VPN which should be in front in the list */
conn = nmtst_create_minimal_connection ("test_vpn_b", NULL, NM_SETTING_VPN_SETTING_NAME, &connsetting);
setting = nm_connection_get_setting_vpn (conn);
g_object_set (G_OBJECT (connsetting), NM_SETTING_CONNECTION_ID, "1", NULL);
g_object_set (G_OBJECT (setting), NM_SETTING_VPN_SERVICE_TYPE, "org.freedesktop.NetworkManager.vpnc", NULL);
nm_client_add_connection_async (fixture->client, conn, TRUE, NULL, add_cb, &info);
info.other_remaining = 1;
WAIT_CLIENT(fixture->client, 2, NM_CLIENT_CONNECTIONS, NM_CLIENT_CONNECTION_ADDED);
WAIT_FINISHED(5)
g_object_unref (conn);
/* Make sure both VPNs are there. */
g_assert_nonnull (gtk_test_find_label (fixture->shell, "A VPN"));
g_assert_nonnull (gtk_test_find_label (fixture->shell, "1 VPN"));
/* And test that A is after 1 */
a = find_parent_of_type (gtk_test_find_label (fixture->shell, "A VPN"), GTK_TYPE_STACK);
b = find_parent_of_type (gtk_test_find_label (fixture->shell, "1 VPN"), GTK_TYPE_STACK);
container = gtk_widget_get_parent (a);
list = gtk_container_get_children (GTK_CONTAINER (container));
g_assert_cmpint (g_list_index (list, a), >, g_list_index (list, b));
g_list_free (list);
/* Rename VPN from 1 to B */
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sa{sv}}"));
g_variant_builder_open (&builder, G_VARIANT_TYPE ("{sa{sv}}"));
g_variant_builder_add (&builder, "s", "connection");
g_variant_builder_open (&builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_open (&builder, G_VARIANT_TYPE ("{sv}"));
g_variant_builder_add (&builder, "s", "id");
g_variant_builder_add (&builder, "v", g_variant_new_string ("B"));
g_variant_builder_close (&builder);
g_variant_builder_open (&builder, G_VARIANT_TYPE ("{sv}"));
g_variant_builder_add (&builder, "s", "type");
g_variant_builder_add (&builder, "v", g_variant_new_string (nm_connection_get_connection_type (NM_CONNECTION (info.rc))));
g_variant_builder_close (&builder);
g_variant_builder_open (&builder, G_VARIANT_TYPE ("{sv}"));
g_variant_builder_add (&builder, "s", "uuid");
g_variant_builder_add (&builder, "v", g_variant_new_string (nm_connection_get_uuid (NM_CONNECTION (info.rc))));
g_variant_builder_close (&builder);
g_variant_builder_close (&builder);
g_variant_builder_close (&builder);
nmtstc_service_update_connection_variant (
fixture->sinfo,
nm_object_get_path (NM_OBJECT (info.rc)),
g_variant_builder_end (&builder),
FALSE);
g_variant_builder_clear (&builder);
WAIT_CONNECTION(info.rc, 1, "changed");
WAIT_FINISHED(5)
g_clear_object (&info.rc);
/* Make sure it the label got renamed. */
g_assert_null (gtk_test_find_label (fixture->shell, "1 VPN"));
g_assert_nonnull (gtk_test_find_label (fixture->shell, "A VPN"));
g_assert_nonnull (gtk_test_find_label (fixture->shell, "B VPN"));
/* And test that A is before B */
a = find_parent_of_type (gtk_test_find_label (fixture->shell, "A VPN"), GTK_TYPE_STACK);
b = find_parent_of_type (gtk_test_find_label (fixture->shell, "B VPN"), GTK_TYPE_STACK);
container = gtk_widget_get_parent (a);
list = gtk_container_get_children (GTK_CONTAINER (container));
g_assert_cmpint (g_list_index (list, a), <, g_list_index (list, b));
g_list_free (list);
}
/*****************************************************************************/
int
main (int argc, char **argv)
{
......@@ -444,6 +702,41 @@ main (int argc, char **argv)
test_connection_multi_add_activate,
fixture_tear_down);
g_test_add ("/network-panel-wired/vpn-add",
NetworkPanelFixture,
NULL,
fixture_set_up_empty,
test_vpn_add,
fixture_tear_down);
g_test_add ("/network-panel-wired/vpn-add-remove",
NetworkPanelFixture,
NULL,
fixture_set_up_empty,
test_vpn_add_remove,
fixture_tear_down);
g_test_add ("/network-panel-wired/vpn-updating",
NetworkPanelFixture,
NULL,
fixture_set_up_empty,
test_vpn_updating,
fixture_tear_down);
#if 0
/*
* FIXME: Currently broken, so test is disabled. Test will likely need
* updating when this is fixed to look for GTK_TYPE_LIST_BOX_ROW rather
* than GTK_TYPE_STACK.
*/
g_test_add ("/network-panel-wired/vpn-sorting",
NetworkPanelFixture,
NULL,
fixture_set_up_empty,
test_vpn_sorting,
fixture_tear_down);
#endif
return g_test_run ();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment