[network-manager-applet/lr-ethernet-dialog: 1/3] tests: add a test for the ethernet dialog
- From: Lubomir Rintel <lkundrak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/lr-ethernet-dialog: 1/3] tests: add a test for the ethernet dialog
- Date: Mon, 25 Oct 2021 11:27:00 +0000 (UTC)
commit 06a55cb8ba3e7caf8da9c3751aa0050de0213fdf
Author: Lubomir Rintel <lkundrak v3 sk>
Date: Mon Oct 25 12:41:01 2021 +0200
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.
.gitignore | 1 +
Makefile.am | 20 ++++++++++++++
meson.build | 1 +
src/meson.build | 4 ++-
src/tests/ethernet-dialog.c | 66 +++++++++++++++++++++++++++++++++++++++++++++
src/tests/meson.build | 14 ++++++++++
6 files changed, 105 insertions(+), 1 deletion(-)
---
diff --git a/.gitignore b/.gitignore
index 18600d7d..73fb6976 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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..008abfd5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -234,6 +234,26 @@ 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)
+
+###############################################################################
+
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
+)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]