[Spice-devel] [PATCH spice-gtk v2 3/4] test-session: Test invalid URIs
Pavel Grunt
pgrunt at redhat.com
Wed Oct 12 15:08:25 UTC 2016
---
tests/session.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 124 insertions(+), 2 deletions(-)
diff --git a/tests/session.c b/tests/session.c
index 74d32f2..494e92f 100644
--- a/tests/session.c
+++ b/tests/session.c
@@ -1,6 +1,127 @@
#include <spice-client.h>
-static void test_session_uri(void)
+static void test_session_uri_bad(void)
+{
+ SpiceSession *s;
+ guint i;
+ const struct {
+ const gchar *uri;
+ struct {
+ const GLogLevelFlags log_level;
+ const gchar *message;
+ } messages[2];
+ } uris[] = {
+ {
+ "scheme://host?port",
+ {
+ {
+ G_LOG_LEVEL_WARNING,
+ "Expected a URI scheme of 'spice://'*",
+ },{
+ G_LOG_LEVEL_CRITICAL,
+ "*assertion 's->port != NULL || s->tls_port != NULL' failed",
+ },
+ }
+ },{
+ "spice://[ipv6-host:42",
+ {
+ {
+ G_LOG_LEVEL_WARNING,
+ "Missing closing ']' in authority for URI*",
+ },{
+ G_LOG_LEVEL_CRITICAL,
+ "*assertion 's->port != NULL || s->tls_port != NULL' failed",
+ },
+ }
+ },{
+ "spice://host??",
+ {
+ {
+ G_LOG_LEVEL_WARNING,
+ "Failed to parse key in URI '?'",
+ },{
+ G_LOG_LEVEL_CRITICAL,
+ "*assertion 's->port != NULL || s->tls_port != NULL' failed",
+ },
+ }
+ },{
+ "spice://host:5900?unknown=value",
+ {
+ {
+ G_LOG_LEVEL_WARNING,
+ "unknown key in spice URI parsing: 'unknown'",
+ },{
+ G_LOG_LEVEL_CRITICAL,
+ "*assertion 's->port != NULL || s->tls_port != NULL' failed",
+ },
+ }
+ },{
+ "spice://hostname",
+ {
+ {
+ G_LOG_LEVEL_WARNING,
+ "Missing port or tls-port in spice URI*",
+ },{
+ G_LOG_LEVEL_CRITICAL,
+ "*assertion 's->port != NULL || s->tls_port != NULL' failed",
+ },
+ }
+ },{
+ "spice://hostname?port=1234&port=3456",
+ {
+ {
+ G_LOG_LEVEL_WARNING,
+ "Double set of 'port' in URI*",
+ },{
+ G_LOG_LEVEL_CRITICAL,
+ "*assertion 's->port != NULL || s->tls_port != NULL' failed",
+ },
+ }
+ },{
+ "spice://hostname?tls-port=1234&port=3456&tls-port=5678",
+ {
+ {
+ G_LOG_LEVEL_WARNING,
+ "Double set of 'tls-port' in URI*",
+ },{
+ G_LOG_LEVEL_CRITICAL,
+ "*assertion 's->port != NULL || s->tls_port != NULL' failed",
+ },
+ }
+ },{
+ "spice://hostname:5900?tls-port=1234&port=3456",
+ {
+ {
+ G_LOG_LEVEL_WARNING,
+ "Double set of 'port' in URI*",
+ },{
+ G_LOG_LEVEL_CRITICAL,
+ "*assertion 's->port != NULL || s->tls_port != NULL' failed",
+ },
+ }
+ },
+ };
+
+ s = spice_session_new();
+
+ for (i = 0; i < G_N_ELEMENTS(uris); i++) {
+ gchar *uri = NULL;
+ guint j;
+ for (j = 0; j < G_N_ELEMENTS(uris[i].messages) && uris[i].messages[j].message != NULL; j++)
+ g_test_expect_message(G_LOG_DOMAIN,
+ uris[i].messages[j].log_level,
+ uris[i].messages[j].message);
+ g_object_set(s, "uri", uris[i].uri, NULL);
+ g_object_get(s, "uri", &uri, NULL);
+ g_test_assert_expected_messages();
+ g_assert_cmpstr(uri, ==, NULL);
+ g_free(uri);
+ }
+
+ g_object_unref(s);
+}
+
+static void test_session_uri_good(void)
{
SpiceSession *s;
guint i;
@@ -109,7 +230,8 @@ int main(int argc, char* argv[])
{
g_test_init(&argc, &argv, NULL);
- g_test_add_func("/session/uri", test_session_uri);
+ g_test_add_func("/session/bad-uri", test_session_uri_bad);
+ g_test_add_func("/session/good-uri", test_session_uri_good);
return g_test_run();
}
--
2.10.1
More information about the Spice-devel
mailing list