On Mon, May 30, 2016 at 5:08 PM, Pavel Grunt <pgrunt@xxxxxxxxxx> wrote: > Related: rhbz#1339572 > --- > tests/Makefile.am | 12 ++++- > tests/test-hotkeys.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 134 insertions(+), 1 deletion(-) > create mode 100644 tests/test-hotkeys.c > > diff --git a/tests/Makefile.am b/tests/Makefile.am > index a1bdf85..bd13188 100644 > --- a/tests/Makefile.am > +++ b/tests/Makefile.am > @@ -2,6 +2,7 @@ NULL = > > AM_CPPFLAGS = \ > -DLOCALE_DIR=\""$(datadir)/locale"\" \ > + -DG_LOG_DOMAIN=\"virt-viewer\" \ > -I$(top_srcdir)/src/ \ > -I$(top_srcdir)/tests/ \ > $(GLIB2_CFLAGS) \ > @@ -16,7 +17,7 @@ LDADD= \ > $(LIBXML2_LIBS) \ > $(NULL) > > -TESTS = test-version-compare test-monitor-mapping > +TESTS = test-version-compare test-monitor-mapping test-hotkeys > check_PROGRAMS = $(TESTS) > test_version_compare_SOURCES = \ > test-version-compare.c \ > @@ -26,6 +27,15 @@ test_monitor_mapping_SOURCES = \ > test-monitor-mapping.c \ > $(NULL) > > +test_hotkeys_SOURCES = \ > + test-hotkeys.c \ > + $(NULL) > + > +test_hotkeys_LDADD = \ > + $(top_builddir)/src/libvirt-viewer.la \ > + $(LDADD) \ > + $(NULL) > + > if OS_WIN32 > TESTS += redirect-test > redirect_test_SOURCES = redirect-test.c > diff --git a/tests/test-hotkeys.c b/tests/test-hotkeys.c > new file mode 100644 > index 0000000..d3658f5 > --- /dev/null > +++ b/tests/test-hotkeys.c > @@ -0,0 +1,123 @@ > +/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */ > +/* > + * Virt Viewer: A virtual machine console viewer > + * > + * Copyright (C) 2016 Red Hat, Inc. > + * > + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > + */ > + > +#include <config.h> > +#include <glib.h> > +#include <glib-object.h> > +#include <gtk/gtk.h> > + > +#include "virt-viewer-app.h" > + > +G_BEGIN_DECLS > + > +#define VIRT_VIEWER_TEST_TYPE virt_viewer_test_get_type() > +#define VIRT_VIEWER_TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TEST_TYPE, VirtViewerTest)) > +#define VIRT_VIEWER_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TEST_TYPE, VirtViewerTestClass)) > +#define VIRT_VIEWER_TEST_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TEST_TYPE)) > +#define VIRT_VIEWER_TEST_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TEST_TYPE)) > +#define VIRT_VIEWER_TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TEST_TYPE, VirtViewerTestClass)) > + > +typedef struct { > + VirtViewerApp parent; > +} VirtViewerTest; > + > +typedef struct { > + VirtViewerAppClass parent_class; > +} VirtViewerTestClass; > + > +GType virt_viewer_test_get_type (void); > + > +G_DEFINE_TYPE (VirtViewerTest, virt_viewer_test, VIRT_VIEWER_TYPE_APP) > + > +VirtViewerTest *virt_viewer_test_new (void); > + > +G_END_DECLS > + > +static void > +virt_viewer_test_class_init (VirtViewerTestClass *klass G_GNUC_UNUSED) > +{ > +} > + > +static void > +virt_viewer_test_init(VirtViewerTest *self G_GNUC_UNUSED) > +{ > +} > + > +static void > +test_hotkeys_good(void) > +{ > + const gchar *hotkeys[] = { > + "toggle-fullscreen=shift+f11", > + "release-cursor=shift+f12,secure-attention=ctrl+shift+b", > + "smartcard-insert=shift+I,smartcard-remove=shift+R", > + }; > + > + guint i; > + > + VirtViewerTest *viewer = g_object_new(VIRT_VIEWER_TEST_TYPE, NULL); > + VirtViewerApp *app = VIRT_VIEWER_APP(viewer); > + for (i = 0; i < G_N_ELEMENTS(hotkeys); i++) { > + virt_viewer_app_set_hotkeys(app, hotkeys[i]); > + } > + g_object_unref(viewer); > +} > + > +static void > +test_hotkeys_bad(void) > +{ > + const struct { > + const gchar *hotkey_str; > + const GLogLevelFlags log_level; > + const gchar *message; > + } hotkeys[] = { > + { > + "no_value", > + G_LOG_LEVEL_WARNING, > + "*code should not be reached" > + },{ > + "toggle-fullscreen=A,unknown_command=B", > + G_LOG_LEVEL_WARNING, > + "Unknown hotkey command unknown_command" > + }, > + }; > + > + guint i; > + > + VirtViewerTest *viewer = g_object_new(VIRT_VIEWER_TEST_TYPE, NULL); > + VirtViewerApp *app = VIRT_VIEWER_APP(viewer); > + for (i = 0; i < G_N_ELEMENTS(hotkeys); i++) { > + g_test_expect_message(G_LOG_DOMAIN, hotkeys[i].log_level, hotkeys[i].message); > + virt_viewer_app_set_hotkeys(app, hotkeys[i].hotkey_str); > + g_test_assert_expected_messages(); > + } > + g_object_unref(viewer); > +} > + > +int main(int argc, char* argv[]) > +{ > + gtk_init_check(&argc, &argv); > + g_test_init(&argc, &argv, NULL); > + > + g_test_add_func("/virt-viewer/good-hotkeys", test_hotkeys_good); > + g_test_add_func("/virt-viewer/bad-hotkeys", test_hotkeys_bad); > + > + return g_test_run(); > +} > -- > 2.8.3 > > _______________________________________________ > virt-tools-list mailing list > virt-tools-list@xxxxxxxxxx > https://www.redhat.com/mailman/listinfo/virt-tools-list See my comments to the patch 4/5. If we really have to deal with "foo=", please, also add this to your tests. ACK with this change, if needed. Best Regards, -- _______________________________________________ virt-tools-list mailing list virt-tools-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/virt-tools-list