|
0 |
/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
1 |
/*
|
|
2 |
* Virt Viewer: A virtual machine console viewer
|
|
3 |
*
|
|
4 |
* Copyright (C) 2016 Red Hat, Inc.
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; either version 2 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
19 |
*/
|
|
20 |
|
|
21 |
#include <config.h>
|
|
22 |
#include <glib.h>
|
|
23 |
#include <glib-object.h>
|
|
24 |
#include <gtk/gtk.h>
|
|
25 |
|
|
26 |
#include "virt-viewer-app.h"
|
|
27 |
|
|
28 |
G_BEGIN_DECLS
|
|
29 |
|
|
30 |
#define VIRT_VIEWER_TEST_TYPE virt_viewer_test_get_type()
|
|
31 |
#define VIRT_VIEWER_TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIRT_VIEWER_TEST_TYPE, VirtViewerTest))
|
|
32 |
#define VIRT_VIEWER_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VIRT_VIEWER_TEST_TYPE, VirtViewerTestClass))
|
|
33 |
#define VIRT_VIEWER_TEST_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIRT_VIEWER_TEST_TYPE))
|
|
34 |
#define VIRT_VIEWER_TEST_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VIRT_VIEWER_TEST_TYPE))
|
|
35 |
#define VIRT_VIEWER_TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VIRT_VIEWER_TEST_TYPE, VirtViewerTestClass))
|
|
36 |
|
|
37 |
typedef struct {
|
|
38 |
VirtViewerApp parent;
|
|
39 |
} VirtViewerTest;
|
|
40 |
|
|
41 |
typedef struct {
|
|
42 |
VirtViewerAppClass parent_class;
|
|
43 |
} VirtViewerTestClass;
|
|
44 |
|
|
45 |
GType virt_viewer_test_get_type (void);
|
|
46 |
|
|
47 |
G_DEFINE_TYPE (VirtViewerTest, virt_viewer_test, VIRT_VIEWER_TYPE_APP)
|
|
48 |
|
|
49 |
VirtViewerTest *virt_viewer_test_new (void);
|
|
50 |
|
|
51 |
G_END_DECLS
|
|
52 |
|
|
53 |
static void
|
|
54 |
virt_viewer_test_class_init (VirtViewerTestClass *klass G_GNUC_UNUSED)
|
|
55 |
{
|
|
56 |
}
|
|
57 |
|
|
58 |
static void
|
|
59 |
virt_viewer_test_init(VirtViewerTest *self G_GNUC_UNUSED)
|
|
60 |
{
|
|
61 |
}
|
|
62 |
|
|
63 |
static void
|
|
64 |
test_hotkeys_good(void)
|
|
65 |
{
|
|
66 |
const gchar *hotkeys[] = {
|
|
67 |
"toggle-fullscreen=shift+f11",
|
|
68 |
"release-cursor=shift+f12,secure-attention=ctrl+shift+b",
|
|
69 |
"smartcard-insert=shift+I,smartcard-remove=shift+R",
|
|
70 |
};
|
|
71 |
|
|
72 |
guint i;
|
|
73 |
|
|
74 |
VirtViewerTest *viewer = g_object_new(VIRT_VIEWER_TEST_TYPE, NULL);
|
|
75 |
VirtViewerApp *app = VIRT_VIEWER_APP(viewer);
|
|
76 |
for (i = 0; i < G_N_ELEMENTS(hotkeys); i++) {
|
|
77 |
virt_viewer_app_set_hotkeys(app, hotkeys[i]);
|
|
78 |
}
|
|
79 |
g_object_unref(viewer);
|
|
80 |
}
|
|
81 |
|
|
82 |
static void
|
|
83 |
test_hotkeys_bad(void)
|
|
84 |
{
|
|
85 |
const struct {
|
|
86 |
const gchar *hotkey_str;
|
|
87 |
const GLogLevelFlags log_level;
|
|
88 |
const gchar *message;
|
|
89 |
} hotkeys[] = {
|
|
90 |
{
|
|
91 |
"no_value",
|
|
92 |
G_LOG_LEVEL_WARNING,
|
|
93 |
"*code should not be reached"
|
|
94 |
},{
|
|
95 |
"toggle-fullscreen=A,unknown_command=B",
|
|
96 |
G_LOG_LEVEL_WARNING,
|
|
97 |
"Unknown hotkey command unknown_command"
|
|
98 |
},
|
|
99 |
};
|
|
100 |
|
|
101 |
guint i;
|
|
102 |
|
|
103 |
VirtViewerTest *viewer = g_object_new(VIRT_VIEWER_TEST_TYPE, NULL);
|
|
104 |
VirtViewerApp *app = VIRT_VIEWER_APP(viewer);
|
|
105 |
for (i = 0; i < G_N_ELEMENTS(hotkeys); i++) {
|
|
106 |
g_test_expect_message(G_LOG_DOMAIN, hotkeys[i].log_level, hotkeys[i].message);
|
|
107 |
virt_viewer_app_set_hotkeys(app, hotkeys[i].hotkey_str);
|
|
108 |
g_test_assert_expected_messages();
|
|
109 |
}
|
|
110 |
g_object_unref(viewer);
|
|
111 |
}
|
|
112 |
|
|
113 |
int main(int argc, char* argv[])
|
|
114 |
{
|
|
115 |
gtk_init_check(&argc, &argv);
|
|
116 |
g_test_init(&argc, &argv, NULL);
|
|
117 |
|
|
118 |
g_test_add_func("/virt-viewer/good-hotkeys", test_hotkeys_good);
|
|
119 |
g_test_add_func("/virt-viewer/bad-hotkeys", test_hotkeys_bad);
|
|
120 |
|
|
121 |
return g_test_run();
|
|
122 |
}
|