1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include <glib.h>
#include "spice-session.h"
static void test_session_uri(void)
{
SpiceSession *s;
gint i;
struct {
gchar *port;
gchar *tls_port;
gchar *uri_input;
gchar *uri_output;
} tests[] = {
/* Arguments with empty value */
{ "5900", NULL,
"spice://localhost?port=5900&tls-port=",
"spice://localhost?port=5900&" },
{ "5910", NULL,
"spice://localhost?tls-port=&port=5910",
"spice://localhost?port=5910&" },
{ NULL, "5920",
"spice://localhost?tls-port=5920&port=",
"spice://localhost?tls-port=5920" },
{ NULL, "5930",
"spice://localhost?port=&tls-port=5930",
"spice://localhost?tls-port=5930" },
};
/* Set URI and check URI, port and tls_port */
for (i = 0; i < G_N_ELEMENTS(tests); i++) {
gchar *uri, *port, *tls_port;
s = spice_session_new();
g_object_set(s, "uri", tests[i].uri_input, NULL);
g_object_get(s,
"uri", &uri,
"port", &port,
"tls-port", &tls_port,
NULL);
g_assert_cmpstr(tests[i].uri_output, ==, uri);
g_assert_cmpstr(tests[i].port, ==, port);
g_assert_cmpstr(tests[i].tls_port, ==, tls_port);
g_clear_pointer(&uri, g_free);
g_clear_pointer(&port, g_free);
g_clear_pointer(&tls_port, g_free);
g_object_unref(s);
}
/* Set port and tls_port, check URI */
for (i = 0; i < G_N_ELEMENTS(tests); i++) {
gchar *uri;
s = spice_session_new();
g_object_set(s,
"port", tests[i].port,
"tls-port", tests[i].tls_port,
NULL);
g_object_get(s, "uri", &uri, NULL);
g_assert_cmpstr(tests[i].uri_output, ==, uri);
g_clear_pointer(&uri, g_free);
g_object_unref(s);
}
}
int main(int argc, char* argv[])
{
g_test_init(&argc, &argv, NULL);
g_test_add_func("/session/uri", test_session_uri);
return g_test_run();
}
|