diff options
author | Victor Toso <victortoso@redhat.com> | 2015-02-27 16:24:34 +0100 |
---|---|---|
committer | Victor Toso <victortoso@redhat.com> | 2015-02-27 17:00:07 +0100 |
commit | ca59cb30c1af0d89efa21570237b8adbe965e8b4 (patch) | |
tree | 086acd360f54a4a8834702b2dbfaabf3d18e717c /tests | |
parent | 2ff11ef4d2e20f0dba4950173c2c0be84deb5297 (diff) |
tests: add spice-session test
Checking if URIs are being parsed and generated correctly.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/session.c | 74 |
2 files changed, 76 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index b236b12..57b06db 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,6 +3,7 @@ NULL = noinst_PROGRAMS = \ coroutine \ util \ + session \ $(NULL) TESTS = $(noinst_PROGRAMS) @@ -20,5 +21,6 @@ LDADD = \ util_SOURCES = util.c coroutine_SOURCES = coroutine.c +session_SOURCES = session.c -include $(top_srcdir)/git.mk diff --git a/tests/session.c b/tests/session.c new file mode 100644 index 0000000..feee3db --- /dev/null +++ b/tests/session.c @@ -0,0 +1,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(); +} |