Codebase list virt-viewer / 2736081
Move tests under /tests directory Keep tests separated from the code Pavel Grunt 8 years ago
8 changed file(s) with 211 addition(s) and 221 deletion(s). Raw diff Collapse all Expand all
11
22 ACLOCAL_AMFLAGS = -I m4
33
4 SUBDIRS = icons src man po data
4 SUBDIRS = icons src man po data tests
55
66 AM_DISTCHECK_CONFIGURE_FLAGS = --disable-update-mimedb
77 EXTRA_DIST = \
254254 po/Makefile.in
255255 src/Makefile
256256 src/virt-viewer.rc
257 tests/Makefile
257258 virt-viewer.spec
258259 ])
259260 AC_OUTPUT
143143 $(COMMON_CFLAGS) \
144144 $(NULL)
145145
146 check_PROGRAMS = test-version-compare test-monitor-mapping
147 TESTS = $(check_PROGRAMS)
148 test_version_compare_SOURCES = \
149 test-version-compare.c \
150 $(NULL)
151 test_version_compare_LDFLAGS = \
152 $(GLIB2_LIBS) \
153 $(GTK_LIBS) \
154 $(LIBXML2_LIBS) \
155 $(NULL)
156 test_version_compare_CFLAGS = \
157 -DLOCALE_DIR=\""$(datadir)/locale"\" \
158 $(GLIB2_CFLAGS) \
159 $(GTK_CFLAGS) \
160 $(LIBXML2_CFLAGS) \
161 $(WARN_CFLAGS) \
162 $(NULL)
163 test_version_compare_LDADD = \
164 libvirt-viewer-util.la \
165 $(NULL)
166
167 test_monitor_mapping_SOURCES = \
168 test-monitor-mapping.c \
169 $(NULL)
170 test_monitor_mapping_LDFLAGS = \
171 $(GLIB2_LIBS) \
172 $(GTK_LIBS) \
173 $(LIBXML2_LIBS) \
174 $(NULL)
175 test_monitor_mapping_CFLAGS = \
176 -DLOCALE_DIR=\""$(datadir)/locale"\" \
177 $(GLIB2_CFLAGS) \
178 $(GTK_CFLAGS) \
179 $(LIBXML2_CFLAGS) \
180 $(WARN_CFLAGS) \
181 $(NULL)
182 test_monitor_mapping_LDADD = \
183 libvirt-viewer-util.la \
184 $(NULL)
185
186146 if HAVE_LIBVIRT
187147 bin_PROGRAMS += virt-viewer
188148 virt_viewer_SOURCES = \
+0
-119
src/test-monitor-mapping.c less more
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 <virt-viewer-util.h>
24
25 gboolean doDebug = FALSE;
26
27 /**
28 * is_valid_monitor_mapping:
29 * @mapping: a value for the "monitor-mapping" key
30 *
31 * Tests the validity of the settings file for the "monitor-mapping" key:
32 * [test-monitor-mapping]
33 * monitor-mapping=@mapping
34 *
35 * Returns: %TRUE if the mapping is valid
36 */
37 static gboolean
38 is_valid_monitor_mapping(const gchar *mapping)
39 {
40 GKeyFile *key_file;
41 gboolean valid;
42 const gint nmonitors = 4;
43 const gchar *group_name = "test-monitor-mapping";
44 const gchar *key = "monitor-mapping";
45 const gchar *key_data_fmt = "[%s]\n%s=%s\n";
46 gchar *key_data = g_strdup_printf(key_data_fmt, group_name, key, mapping);
47
48 key_file = g_key_file_new();
49 valid = g_key_file_load_from_data(key_file, key_data, -1, G_KEY_FILE_NONE, NULL);
50 if (valid) {
51 gsize nmappings;
52 gchar **mappings = g_key_file_get_string_list(key_file, group_name, key, &nmappings, NULL);
53 GHashTable *map = virt_viewer_parse_monitor_mappings(mappings, nmappings, nmonitors);
54
55 valid = (map != NULL);
56
57 g_strfreev(mappings);
58 g_clear_pointer(&map, g_hash_table_unref);
59 }
60
61 g_key_file_free(key_file);
62 g_free(key_data);
63 return valid;
64 }
65
66 int main(void)
67 {
68 /* valid monitor mappings */
69 g_assert_true(is_valid_monitor_mapping("1:1"));
70 g_assert_true(is_valid_monitor_mapping("1:1;2:2"));
71 g_assert_true(is_valid_monitor_mapping("1:1;2:2;3:3;"));
72 g_assert_true(is_valid_monitor_mapping("1:2;2:1;3:3;4:4"));
73 g_assert_true(is_valid_monitor_mapping("4:1;3:2;2:3;1:4"));
74
75 /* invalid monitors mappings */
76 /* zero ids */
77 g_assert_false(is_valid_monitor_mapping("0:0"));
78 /* negative guest display id */
79 g_assert_false(is_valid_monitor_mapping("-1:1"));
80 /* negative client monitor id */
81 g_assert_false(is_valid_monitor_mapping("1:-1"));
82 /* negative guest display & client monitor id */
83 g_assert_false(is_valid_monitor_mapping("-1:-1"));
84 /* high guest display id */
85 g_assert_false(is_valid_monitor_mapping("100:1"));
86 /* high client monitor id */
87 g_assert_false(is_valid_monitor_mapping("1:100"));
88 /* missing guest display id */
89 g_assert_false(is_valid_monitor_mapping("1:1;3:3"));
90 /* guest display id used twice */
91 g_assert_false(is_valid_monitor_mapping("1:1;1:2"));
92 /* client monitor id used twice */
93 g_assert_false(is_valid_monitor_mapping("1:1;2:1"));
94 /* floating point guest display id */
95 g_assert_false(is_valid_monitor_mapping("1.111:1"));
96 /* floating point client monitor id */
97 g_assert_false(is_valid_monitor_mapping("1:1.111"));
98 /* empty mapping */
99 g_assert_false(is_valid_monitor_mapping(""));
100 g_assert_false(is_valid_monitor_mapping(";"));
101 /* missing guest display id */
102 g_assert_false(is_valid_monitor_mapping(":1"));
103 /* missing client monitor id */
104 g_assert_false(is_valid_monitor_mapping("1:"));
105 /* missing guest display & client monitor id */
106 g_assert_false(is_valid_monitor_mapping(":"));
107 /*missing colon */
108 g_assert_false(is_valid_monitor_mapping("11"));
109 /*missing semicolon */
110 g_assert_false(is_valid_monitor_mapping("1:12:2"));
111 /* strings */
112 g_assert_false(is_valid_monitor_mapping("1:a"));
113 g_assert_false(is_valid_monitor_mapping("a:1"));
114 g_assert_false(is_valid_monitor_mapping("a:a"));
115 g_assert_false(is_valid_monitor_mapping("monitor mapping"));
116
117 return 0;
118 }
+0
-61
src/test-version-compare.c less more
0 /* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
1 /*
2 * Virt Viewer: A virtual machine console viewer
3 *
4 * Copyright (C) 2015 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 <virt-viewer-util.h>
24
25 gboolean doDebug = FALSE;
26
27 int main(void)
28 {
29 g_assert(virt_viewer_compare_buildid("1-1", "1-1") == 0);
30 g_assert(virt_viewer_compare_buildid("1-1", "1-1.1") < 0);
31 g_assert(virt_viewer_compare_buildid("1-1", "1-2") < 0);
32 g_assert(virt_viewer_compare_buildid("1-3", "1-2") > 0);
33 g_assert(virt_viewer_compare_buildid("2-3", "1-2") > 0);
34 g_assert(virt_viewer_compare_buildid("2-3", "3-2") < 0);
35 g_assert(virt_viewer_compare_buildid("2-3", "3-4") < 0);
36 g_assert(virt_viewer_compare_buildid("4-3", "3-4") > 0);
37
38 g_assert(virt_viewer_compare_buildid("4.0-", "3-4") > 0);
39 g_assert(virt_viewer_compare_buildid("4.0-", "3.4-4") > 0);
40 g_assert(virt_viewer_compare_buildid(".0-", "3.4-4") < 0);
41 g_assert(virt_viewer_compare_buildid("4-", "3-4") > 0);
42 g_assert(virt_viewer_compare_buildid("4-3", "3-") > 0);
43 g_assert(virt_viewer_compare_buildid("-3", "3-4") < 0);
44 g_assert(virt_viewer_compare_buildid("4-3", "-4") > 0);
45 g_assert(virt_viewer_compare_buildid("-3", "-4") < 0);
46 g_assert(virt_viewer_compare_buildid("4", "3-4") > 0);
47 g_assert(virt_viewer_compare_buildid("4-3", "3") > 0);
48 g_assert(virt_viewer_compare_buildid("3", "3-4") < 0);
49 g_assert(virt_viewer_compare_buildid("4-3", "4") > 0);
50 g_assert(virt_viewer_compare_buildid("-3", "-4") < 0);
51
52 /* These trigger runtime warnings */
53 g_assert(virt_viewer_compare_buildid("-3", "-") > 0);
54 g_assert(virt_viewer_compare_buildid("", "-") == 0);
55 g_assert(virt_viewer_compare_buildid("", "") == 0);
56 g_assert(virt_viewer_compare_buildid("", NULL) == 0);
57 g_assert(virt_viewer_compare_buildid(NULL, NULL) == 0);
58
59 return 0;
60 }
0 NULL =
1
2 AM_CPPFLAGS = \
3 -DLOCALE_DIR=\""$(datadir)/locale"\" \
4 -I$(top_srcdir)/src/ \
5 -I$(top_srcdir)/tests/ \
6 $(GLIB2_CFLAGS) \
7 $(GTK_CFLAGS) \
8 $(WARN_CFLAGS) \
9 $(NULL)
10
11 LDADD= \
12 $(top_builddir)/src/libvirt-viewer-util.la \
13 $(GLIB2_LIBS) \
14 $(GTK_LIBS) \
15 $(LIBXML2_LIBS) \
16 $(NULL)
17
18 TESTS = test-version-compare test-monitor-mapping
19 check_PROGRAMS = $(TESTS)
20 test_version_compare_SOURCES = \
21 test-version-compare.c \
22 $(NULL)
23
24 test_monitor_mapping_SOURCES = \
25 test-monitor-mapping.c \
26 $(NULL)
27
28 -include $(top_srcdir)/git.mk
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 <virt-viewer-util.h>
24
25 gboolean doDebug = FALSE;
26
27 /**
28 * is_valid_monitor_mapping:
29 * @mapping: a value for the "monitor-mapping" key
30 *
31 * Tests the validity of the settings file for the "monitor-mapping" key:
32 * [test-monitor-mapping]
33 * monitor-mapping=@mapping
34 *
35 * Returns: %TRUE if the mapping is valid
36 */
37 static gboolean
38 is_valid_monitor_mapping(const gchar *mapping)
39 {
40 GKeyFile *key_file;
41 gboolean valid;
42 const gint nmonitors = 4;
43 const gchar *group_name = "test-monitor-mapping";
44 const gchar *key = "monitor-mapping";
45 const gchar *key_data_fmt = "[%s]\n%s=%s\n";
46 gchar *key_data = g_strdup_printf(key_data_fmt, group_name, key, mapping);
47
48 key_file = g_key_file_new();
49 valid = g_key_file_load_from_data(key_file, key_data, -1, G_KEY_FILE_NONE, NULL);
50 if (valid) {
51 gsize nmappings;
52 gchar **mappings = g_key_file_get_string_list(key_file, group_name, key, &nmappings, NULL);
53 GHashTable *map = virt_viewer_parse_monitor_mappings(mappings, nmappings, nmonitors);
54
55 valid = (map != NULL);
56
57 g_strfreev(mappings);
58 g_clear_pointer(&map, g_hash_table_unref);
59 }
60
61 g_key_file_free(key_file);
62 g_free(key_data);
63 return valid;
64 }
65
66 int main(void)
67 {
68 /* valid monitor mappings */
69 g_assert_true(is_valid_monitor_mapping("1:1"));
70 g_assert_true(is_valid_monitor_mapping("1:1;2:2"));
71 g_assert_true(is_valid_monitor_mapping("1:1;2:2;3:3;"));
72 g_assert_true(is_valid_monitor_mapping("1:2;2:1;3:3;4:4"));
73 g_assert_true(is_valid_monitor_mapping("4:1;3:2;2:3;1:4"));
74
75 /* invalid monitors mappings */
76 /* zero ids */
77 g_assert_false(is_valid_monitor_mapping("0:0"));
78 /* negative guest display id */
79 g_assert_false(is_valid_monitor_mapping("-1:1"));
80 /* negative client monitor id */
81 g_assert_false(is_valid_monitor_mapping("1:-1"));
82 /* negative guest display & client monitor id */
83 g_assert_false(is_valid_monitor_mapping("-1:-1"));
84 /* high guest display id */
85 g_assert_false(is_valid_monitor_mapping("100:1"));
86 /* high client monitor id */
87 g_assert_false(is_valid_monitor_mapping("1:100"));
88 /* missing guest display id */
89 g_assert_false(is_valid_monitor_mapping("1:1;3:3"));
90 /* guest display id used twice */
91 g_assert_false(is_valid_monitor_mapping("1:1;1:2"));
92 /* client monitor id used twice */
93 g_assert_false(is_valid_monitor_mapping("1:1;2:1"));
94 /* floating point guest display id */
95 g_assert_false(is_valid_monitor_mapping("1.111:1"));
96 /* floating point client monitor id */
97 g_assert_false(is_valid_monitor_mapping("1:1.111"));
98 /* empty mapping */
99 g_assert_false(is_valid_monitor_mapping(""));
100 g_assert_false(is_valid_monitor_mapping(";"));
101 /* missing guest display id */
102 g_assert_false(is_valid_monitor_mapping(":1"));
103 /* missing client monitor id */
104 g_assert_false(is_valid_monitor_mapping("1:"));
105 /* missing guest display & client monitor id */
106 g_assert_false(is_valid_monitor_mapping(":"));
107 /*missing colon */
108 g_assert_false(is_valid_monitor_mapping("11"));
109 /*missing semicolon */
110 g_assert_false(is_valid_monitor_mapping("1:12:2"));
111 /* strings */
112 g_assert_false(is_valid_monitor_mapping("1:a"));
113 g_assert_false(is_valid_monitor_mapping("a:1"));
114 g_assert_false(is_valid_monitor_mapping("a:a"));
115 g_assert_false(is_valid_monitor_mapping("monitor mapping"));
116
117 return 0;
118 }
0 /* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
1 /*
2 * Virt Viewer: A virtual machine console viewer
3 *
4 * Copyright (C) 2015 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 <virt-viewer-util.h>
24
25 gboolean doDebug = FALSE;
26
27 int main(void)
28 {
29 g_assert(virt_viewer_compare_buildid("1-1", "1-1") == 0);
30 g_assert(virt_viewer_compare_buildid("1-1", "1-1.1") < 0);
31 g_assert(virt_viewer_compare_buildid("1-1", "1-2") < 0);
32 g_assert(virt_viewer_compare_buildid("1-3", "1-2") > 0);
33 g_assert(virt_viewer_compare_buildid("2-3", "1-2") > 0);
34 g_assert(virt_viewer_compare_buildid("2-3", "3-2") < 0);
35 g_assert(virt_viewer_compare_buildid("2-3", "3-4") < 0);
36 g_assert(virt_viewer_compare_buildid("4-3", "3-4") > 0);
37
38 g_assert(virt_viewer_compare_buildid("4.0-", "3-4") > 0);
39 g_assert(virt_viewer_compare_buildid("4.0-", "3.4-4") > 0);
40 g_assert(virt_viewer_compare_buildid(".0-", "3.4-4") < 0);
41 g_assert(virt_viewer_compare_buildid("4-", "3-4") > 0);
42 g_assert(virt_viewer_compare_buildid("4-3", "3-") > 0);
43 g_assert(virt_viewer_compare_buildid("-3", "3-4") < 0);
44 g_assert(virt_viewer_compare_buildid("4-3", "-4") > 0);
45 g_assert(virt_viewer_compare_buildid("-3", "-4") < 0);
46 g_assert(virt_viewer_compare_buildid("4", "3-4") > 0);
47 g_assert(virt_viewer_compare_buildid("4-3", "3") > 0);
48 g_assert(virt_viewer_compare_buildid("3", "3-4") < 0);
49 g_assert(virt_viewer_compare_buildid("4-3", "4") > 0);
50 g_assert(virt_viewer_compare_buildid("-3", "-4") < 0);
51
52 /* These trigger runtime warnings */
53 g_assert(virt_viewer_compare_buildid("-3", "-") > 0);
54 g_assert(virt_viewer_compare_buildid("", "-") == 0);
55 g_assert(virt_viewer_compare_buildid("", "") == 0);
56 g_assert(virt_viewer_compare_buildid("", NULL) == 0);
57 g_assert(virt_viewer_compare_buildid(NULL, NULL) == 0);
58
59 return 0;
60 }