diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2021-10-25 12:41:01 +0200 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2021-11-04 13:47:45 +0100 |
commit | f975210c3e3fe871906857fa18bc402cd57e33bf (patch) | |
tree | 5dcd45c879cb1d0b99e67724ea3647926c545643 | |
parent | fb1ebd05e02048b0d1a4ab3ff3b942c05639152d (diff) | |
download | network-manager-applet-f975210c3e3fe871906857fa18bc402cd57e33bf.tar.gz |
tests: add a test for the ethernet dialog
This is a small standalone program that presents the ethernet security
dialog. Invoking this dialog would otherwise requires a somewhat
complicated setup, making it difficult to verify the effect of changes
in the code.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.am | 22 | ||||
-rw-r--r-- | meson.build | 1 | ||||
-rw-r--r-- | src/meson.build | 4 | ||||
-rw-r--r-- | src/tests/ethernet-dialog.c | 66 | ||||
-rw-r--r-- | src/tests/meson.build | 14 |
6 files changed, 107 insertions, 1 deletions
@@ -124,6 +124,7 @@ src/nm-applet src/applet-dbus-bindings.h src/applet-resources.c src/applet-resources.h +src/tests/ethernet-dialog man/*.1 /test-driver diff --git a/Makefile.am b/Makefile.am index d97d54cc..ad8407a9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -234,6 +234,28 @@ EXTRA_DIST += src/utils/meson.build ############################################################################### +check_PROGRAMS_norun += src/tests/ethernet-dialog + +src_tests_ethernet_dialog_SOURCES = \ + src/applet-resources.h \ + src/applet-resources.c \ + src/applet-dialogs.c \ + src/applet-dialogs.h \ + src/ethernet-dialog.c \ + src/ethernet-dialog.h \ + src/tests/ethernet-dialog.c + +src_tests_ethernet_dialog_CPPFLAGS = \ + "-I$(srcdir)/src/" \ + $(src_nm_applet_CPPFLAGS) + +src_tests_ethernet_dialog_LDADD = \ + $(src_nm_applet_LDADD) + +EXTRA_DIST += src/tests/meson.build + +############################################################################### + wireless_security_c_real = \ src/wireless-security/eap-method.h \ src/wireless-security/eap-method.c diff --git a/meson.build b/meson.build index 6af3879c..33adb632 100644 --- a/meson.build +++ b/meson.build @@ -237,6 +237,7 @@ subdir('po') subdir('icons') subdir('shared') subdir('src') +subdir('src/tests') subdir('man') i18n = import('i18n') diff --git a/src/meson.build b/src/meson.build index 2d910bb2..fade5afa 100644 --- a/src/meson.build +++ b/src/meson.build @@ -27,12 +27,14 @@ resource_data = files( 'info.ui' ) -sources += gnome.compile_resources( +resource_sources = gnome.compile_resources( 'applet-resources', 'applet.gresource.xml', dependencies: resource_data ) +sources += resource_sources + incs = [ top_inc, utils_inc, diff --git a/src/tests/ethernet-dialog.c b/src/tests/ethernet-dialog.c new file mode 100644 index 00000000..34260ff4 --- /dev/null +++ b/src/tests/ethernet-dialog.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2021 Red Hat, Inc. + */ + +#include "nm-default.h" +#include "ethernet-dialog.h" + +#include <gtk/gtk.h> +#include <NetworkManager.h> + +int +main (int argc, char *argv[]) +{ + NMConnection *connection, *new_connection; + GHashTable *diff = NULL, *setting_diff; + GHashTableIter iter, setting_iter; + const char *setting, *key; + GtkWidget *dialog; + GError *error = NULL; + gs_unref_bytes GBytes *ssid = g_bytes_new_static ("<Secured Wired>", + NM_STRLEN ("<Secured Wired>")); + + gtk_init (&argc, &argv); + + connection = nm_simple_connection_new (); + nm_connection_add_setting (connection, + g_object_new (NM_TYPE_SETTING_CONNECTION, + NM_SETTING_CONNECTION_ID, "<Secured Wired>", + NULL)); + nm_connection_add_setting (connection, + g_object_new (NM_TYPE_SETTING_WIRED, + NULL)); + nm_connection_add_setting (connection, + g_object_new (NM_TYPE_SETTING_802_1X, + NM_SETTING_802_1X_EAP, (const char * const []){ "peap", NULL }, + NM_SETTING_802_1X_IDENTITY, "budulinek", + NM_SETTING_802_1X_PHASE2_AUTH, "gtc", + NULL)); + + if (!nm_connection_normalize (connection, NULL, NULL, &error)) { + nm_connection_dump (connection); + g_printerr ("Error: %s\n", error->message); + g_error_free (error); + return 1; + } + + dialog = nma_ethernet_dialog_new (nm_simple_connection_new_clone (connection)); + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) { + g_print ("settings changed:\n"); + new_connection = nma_ethernet_dialog_get_connection (dialog); + nm_connection_diff (connection, new_connection, NM_SETTING_COMPARE_FLAG_EXACT, &diff); + if (diff) { + g_hash_table_iter_init (&iter, diff); + while (g_hash_table_iter_next (&iter, (gpointer) &setting, (gpointer) &setting_diff)) { + g_hash_table_iter_init (&setting_iter, setting_diff); + while (g_hash_table_iter_next (&setting_iter, (gpointer) &key, NULL)) + g_print (" %s.%s\n", setting, key); + } + + g_hash_table_destroy (diff); + } + } + gtk_widget_destroy (dialog); + g_object_unref (connection); +} diff --git a/src/tests/meson.build b/src/tests/meson.build new file mode 100644 index 00000000..5a2fecfa --- /dev/null +++ b/src/tests/meson.build @@ -0,0 +1,14 @@ +executable( + 'ethernet-dialog', + [resource_sources, + '../applet-dialogs.c', + '../applet-dialogs.h', + '../ethernet-dialog.c', + '../ethernet-dialog.h', + 'ethernet-dialog.c'], + include_directories: incs, + dependencies: deps, + c_args: cflags, + link_whole: libwireless_security_libnm, + install: false +) |