[network-manager-applet/lr/test-programs] libnma: add some test programs



commit 83e9a74d529868aac04e7c60ec7b77848400fd4b
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Tue Feb 6 09:11:42 2018 +0100

    libnma: add some test programs
    
    These make it easy to quickly check the widgets provided by the
    libnma libary.

 .gitignore                             |  4 ++
 Makefile.am                            | 75 ++++++++++++++++++++++++++-
 src/libnma/meson.build                 |  2 +
 src/libnma/tests/meson.build           | 32 ++++++++++++
 src/libnma/tests/mobile-wizard.c       | 40 ++++++++++++++
 src/libnma/tests/run-vpn.c             | 95 ++++++++++++++++++++++++++++++++++
 src/libnma/tests/vpn-password-dialog.c | 43 +++++++++++++++
 src/libnma/tests/wifi-dialog.c         | 66 +++++++++++++++++++++++
 8 files changed, 355 insertions(+), 2 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index b8e11a6e..39390772 100644
--- a/.gitignore
+++ b/.gitignore
@@ -56,6 +56,10 @@ src/libnma/NMA-1.0.typelib
 src/libnma/nma-resources.c
 src/libnma/nma-resources.h
 src/libnma/nma-version.h
+src/libnma/tests/mobile-wizard
+src/libnma/tests/run-vpn
+src/libnma/tests/vpn-password-dialog
+src/libnma/tests/wifi-dialog
 src/libnm-gtk/libnm-gtk.pc
 src/libnm-gtk/NMGtk-1.0.gir
 src/libnm-gtk/NMGtk-1.0.typelib
diff --git a/Makefile.am b/Makefile.am
index 228d5065..7679658f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,7 +14,9 @@ lib_LTLIBRARIES =
 
 noinst_LTLIBRARIES =
 
-noinst_PROGRAMS =
+check_PROGRAMS_norun =
+
+noinst_PROGRAMS = $(check_PROGRAMS_norun)
 
 check_PROGRAMS =
 
@@ -609,6 +611,74 @@ src_libnma_NMA_1_0_gir_SCANNERFLAGS = --warn-all --identifier-prefix=NMA --symbo
 INTROSPECTION_GIRS += src/libnma/NMA-1.0.gir
 endif
 
+check_PROGRAMS_norun += src/libnma/tests/mobile-wizard
+
+src_libnma_tests_mobile_wizard_CPPFLAGS = \
+       $(dflt_cppflags) \
+       $(GLIB_CFLAGS) \
+       $(GTK3_CFLAGS) \
+       $(LIBNM_CFLAGS) \
+       "-I$(srcdir)/shared/" \
+       "-I$(srcdir)/src/libnma" \
+       -Isrc/libnma
+
+src_libnma_tests_mobile_wizard_LDADD = \
+       $(GLIB_LIBS) \
+       $(GTK3_LIBS) \
+       $(LIBNM_LIBS) \
+       src/libnma/libnma.la
+
+check_PROGRAMS_norun += src/libnma/tests/vpn-password-dialog
+
+src_libnma_tests_vpn_password_dialog_CPPFLAGS = \
+       $(dflt_cppflags) \
+       $(GLIB_CFLAGS) \
+       $(GTK3_CFLAGS) \
+       $(LIBNM_CFLAGS) \
+       "-I$(srcdir)/shared/" \
+       "-I$(srcdir)/src/libnma" \
+       -Isrc/libnma
+
+src_libnma_tests_vpn_password_dialog_LDADD = \
+       $(GLIB_LIBS) \
+       $(GTK3_LIBS) \
+       $(LIBNM_LIBS) \
+       src/libnma/libnma.la
+
+check_PROGRAMS_norun += src/libnma/tests/wifi-dialog
+
+src_libnma_tests_wifi_dialog_CPPFLAGS = \
+       $(dflt_cppflags) \
+       $(GLIB_CFLAGS) \
+       $(GTK3_CFLAGS) \
+       $(LIBNM_CFLAGS) \
+       "-I$(srcdir)/shared/" \
+       "-I$(srcdir)/src/libnma" \
+       -Isrc/libnma
+
+src_libnma_tests_wifi_dialog_LDADD = \
+       $(GLIB_LIBS) \
+       $(GTK3_LIBS) \
+       $(LIBNM_LIBS) \
+       src/libnma/libnma.la
+
+check_PROGRAMS_norun += src/libnma/tests/run-vpn
+
+src_libnma_tests_run_vpn_CPPFLAGS = \
+       $(dflt_cppflags) \
+       $(GLIB_CFLAGS) \
+       $(GTK3_CFLAGS) \
+       $(LIBNM_CFLAGS) \
+       "-I$(srcdir)/shared/" \
+       "-I$(srcdir)/src/libnma" \
+       -Isrc/libnma
+
+src_libnma_tests_run_vpn_LDADD = \
+       $(GLIB_LIBS) \
+       $(GTK3_LIBS) \
+       $(LIBNM_LIBS) \
+       src/libnma/libnma.la
+
 EXTRA_DIST += \
        src/libnma/nma-version.h.in \
        src/libnma/libnma.pc.in \
@@ -619,7 +689,8 @@ EXTRA_DIST += \
        src/libnma/nma-pkcs11-cert-chooser-dialog.ui \
        src/libnma/nma-vpn-password-dialog.ui \
        src/libnma/nma.gresource.xml \
-       src/libnma/meson.build
+       src/libnma/meson.build \
+       src/libnma/tests/meson.build
 
 ###############################################################################
 
diff --git a/src/libnma/meson.build b/src/libnma/meson.build
index 98a72aa7..9344bde1 100644
--- a/src/libnma/meson.build
+++ b/src/libnma/meson.build
@@ -112,6 +112,8 @@ libnma_dep = declare_dependency(
   include_directories: libnma_inc
 )
 
+subdir('tests')
+
 pkg.generate(
   libraries: libnma,
   version: nma_version,
diff --git a/src/libnma/tests/meson.build b/src/libnma/tests/meson.build
new file mode 100644
index 00000000..f8019789
--- /dev/null
+++ b/src/libnma/tests/meson.build
@@ -0,0 +1,32 @@
+deps = [
+  gtk_dep,
+  libnm_dep,
+  libnma_dep
+]
+
+executable(
+  'mobile-wizard',
+  'mobile-wizard.c',
+  include_directories: incs,
+  dependencies: deps,
+  c_args: cflags,
+  install: false
+)
+
+executable(
+  'vpn-password-dialog',
+  'vpn-password-dialog.c',
+  include_directories: incs,
+  dependencies: deps,
+  c_args: cflags,
+  install: false
+)
+
+executable(
+  'wifi-dialog',
+  'wifi-dialog.c',
+  include_directories: incs,
+  dependencies: deps,
+  c_args: cflags,
+  install: false
+)
diff --git a/src/libnma/tests/mobile-wizard.c b/src/libnma/tests/mobile-wizard.c
new file mode 100644
index 00000000..a5aace75
--- /dev/null
+++ b/src/libnma/tests/mobile-wizard.c
@@ -0,0 +1,40 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2018 Red Hat, Inc.
+ */
+
+#include <gtk/gtk.h>
+#include "nma-mobile-wizard.h"
+
+static void
+wizard_cb (NMAMobileWizard *self, gboolean canceled, NMAMobileWizardAccessMethod *method, gpointer user_data)
+{
+       gtk_main_quit ();
+}
+
+int
+main (int argc, char *argv[])
+{
+       NMAMobileWizard *wizard;
+
+       gtk_init (&argc, &argv);
+
+       wizard = nma_mobile_wizard_new (NULL, NULL, NM_DEVICE_MODEM_CAPABILITY_NONE, TRUE, wizard_cb, NULL);
+
+       nma_mobile_wizard_present (wizard);
+       gtk_main ();
+       nma_mobile_wizard_destroy (wizard);
+}
diff --git a/src/libnma/tests/run-vpn.c b/src/libnma/tests/run-vpn.c
new file mode 100644
index 00000000..ca936ab2
--- /dev/null
+++ b/src/libnma/tests/run-vpn.c
@@ -0,0 +1,95 @@
+/*
+ * run-vpn - VPN plugin runner for testing
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * (C) Copyright 2018 Lubomir Rintel
+ */
+
+#include "nm-default.h"
+
+#include <NetworkManager.h>
+#include <gtk/gtk.h>
+#include <stdlib.h>
+
+static gboolean
+window_deleted (GtkWidget *widget,
+                GdkEvent *event,
+                gpointer user_data)
+{
+       GMainLoop *main_loop = user_data;
+       g_main_loop_quit (main_loop);
+       return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+       gs_unref_object NMVpnEditorPlugin *plugin = NULL;
+       gs_unref_object NMVpnEditor *editor = NULL;
+       gs_unref_object NMConnection *connection = NULL;
+       gs_free char *service_type = NULL;
+       GMainLoop *main_loop;
+       GtkWidget *window;
+       GtkWidget *widget;
+       gs_free_error GError *error = NULL;
+
+       gtk_init (&argc, &argv);
+       if (argc != 2) {
+               g_printerr ("Usage: %s libnm-vpn-plugin-<name>.so\n", argv[0]);
+               return EXIT_FAILURE;
+       }
+
+       plugin = nm_vpn_editor_plugin_load (argv[1], NULL, &error);
+       if (!plugin) {
+               g_printerr ("Error: %s\n", error->message);
+               return EXIT_FAILURE;
+       }
+
+       g_object_get (G_OBJECT (plugin), "service", &service_type, NULL);
+       g_return_val_if_fail (service_type, EXIT_FAILURE);
+
+       connection = nm_simple_connection_new ();
+       nm_connection_add_setting (connection,
+               g_object_new (NM_TYPE_SETTING_VPN,
+                             "service-type", service_type,
+                             NULL));
+
+       editor = nm_vpn_editor_plugin_get_editor (plugin, connection, &error);
+       if (!editor) {
+               g_printerr ("Error: %s\n", error->message);
+               return EXIT_FAILURE;
+       }
+
+       main_loop = g_main_loop_new (NULL, FALSE);
+       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+       gtk_widget_show (window);
+       g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (window_deleted), main_loop);
+
+       widget = GTK_WIDGET (nm_vpn_editor_get_widget (editor));
+       gtk_widget_show (widget);
+       gtk_container_add (GTK_CONTAINER (window), widget);
+       g_main_loop_run (main_loop);
+
+       if (!nm_vpn_editor_update_connection (editor, connection, &error)) {
+               g_printerr ("Error: %s\n", error->message);
+               return EXIT_FAILURE;
+       }
+
+       gtk_widget_destroy (widget);
+       nm_connection_dump (connection);
+
+       return EXIT_SUCCESS;
+}
diff --git a/src/libnma/tests/vpn-password-dialog.c b/src/libnma/tests/vpn-password-dialog.c
new file mode 100644
index 00000000..92c3dea1
--- /dev/null
+++ b/src/libnma/tests/vpn-password-dialog.c
@@ -0,0 +1,43 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2018 Red Hat, Inc.
+ */
+
+#include <gtk/gtk.h>
+#include "nma-vpn-password-dialog.h"
+
+int
+main (int argc, char *argv[])
+{
+       GtkWidget *widget;
+
+       gtk_init (&argc, &argv);
+
+       widget = nma_vpn_password_dialog_new ("Title", "Message", "Password");
+
+       nma_vpn_password_dialog_set_password (NMA_VPN_PASSWORD_DIALOG (widget), "Password One");
+       nma_vpn_password_dialog_set_password_label (NMA_VPN_PASSWORD_DIALOG (widget), "First _Label");
+
+       nma_vpn_password_dialog_set_password_secondary (NMA_VPN_PASSWORD_DIALOG (widget), "Password Two");
+       nma_vpn_password_dialog_set_password_secondary_label (NMA_VPN_PASSWORD_DIALOG (widget), "_Second 
Label");
+       nma_vpn_password_dialog_set_show_password_secondary (NMA_VPN_PASSWORD_DIALOG (widget), TRUE);
+
+       nma_vpn_password_dialog_set_password_ternary (NMA_VPN_PASSWORD_DIALOG (widget), "Password Three");
+       nma_vpn_password_dialog_set_password_ternary_label (NMA_VPN_PASSWORD_DIALOG (widget), "_Third Label");
+       nma_vpn_password_dialog_set_show_password_ternary (NMA_VPN_PASSWORD_DIALOG (widget), TRUE);
+
+       nma_vpn_password_dialog_run_and_block (NMA_VPN_PASSWORD_DIALOG (widget));
+}
diff --git a/src/libnma/tests/wifi-dialog.c b/src/libnma/tests/wifi-dialog.c
new file mode 100644
index 00000000..adc74fbd
--- /dev/null
+++ b/src/libnma/tests/wifi-dialog.c
@@ -0,0 +1,66 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2018 Red Hat, Inc.
+ */
+
+#include <gtk/gtk.h>
+#include "nma-wifi-dialog.h"
+
+int
+main (int argc, char *argv[])
+{
+       GtkWidget *dialog;
+       NMClient *client = NULL;
+       NMConnection *connection = NULL;
+       NMDevice *device = NULL;
+       NMAccessPoint *ap = NULL;
+       gboolean secrets_only = FALSE;
+       GError *error = NULL;
+
+       gtk_init (&argc, &argv);
+
+       client = nm_client_new (NULL, NULL);
+       connection = nm_simple_connection_new ();
+       nm_connection_add_setting (connection,
+               g_object_new (NM_TYPE_SETTING_CONNECTION,
+                             NM_SETTING_CONNECTION_ID, "<Maj Vaj Faj>",
+                             NULL));
+       nm_connection_add_setting (connection,
+               g_object_new (NM_TYPE_SETTING_WIRELESS,
+                             NM_SETTING_WIRELESS_SSID, g_bytes_new_static ("<Maj Vaj Faj>", 13),
+                             NULL));
+       nm_connection_add_setting (connection,
+               g_object_new (NM_TYPE_SETTING_WIRELESS_SECURITY,
+                             NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap",
+                             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_wifi_dialog_new (client, connection, device, ap, secrets_only);
+       gtk_dialog_run (GTK_DIALOG (dialog));
+       gtk_widget_destroy (dialog);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]