--- tests/session.c | 157 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 105 insertions(+), 52 deletions(-) diff --git a/tests/session.c b/tests/session.c index 494e92f..09856b3 100644 --- a/tests/session.c +++ b/tests/session.c @@ -1,5 +1,16 @@ #include <spice-client.h> +typedef struct { + const gchar *port; + const gchar *tls_port; + const gchar *host; + const gchar *username; + const gchar *password; + const gchar *uri_input; + const gchar *uri_output; + const gchar *message; +} TestCase; + static void test_session_uri_bad(void) { SpiceSession *s; @@ -121,62 +132,13 @@ static void test_session_uri_bad(void) g_object_unref(s); } -static void test_session_uri_good(void) +static void test_session_uri_good(const TestCase *tests, const guint cases) { SpiceSession *s; guint i; - struct { - gchar *port; - gchar *tls_port; - gchar *host; - gchar *username; - gchar *password; - gchar *uri_input; - gchar *uri_output; - gchar *message; - } tests[] = { - /* Arguments with empty value */ - { "5900", NULL, - "localhost", - NULL, NULL, - "spice://localhost?port=5900&tls-port=", - "spice://localhost?port=5900&" }, - { "5910", NULL, - "localhost", - "user", NULL, - "spice://user@localhost?tls-port=&port=5910", - "spice://localhost?port=5910&" }, - { NULL, "5920", - "localhost", - "user", "password", - "spice://user@localhost?tls-port=5920&port=&password=password", - "spice://localhost?tls-port=5920", - "password may be visible in process listings"}, - { NULL, "5930", - "localhost", - NULL, NULL, - "spice://localhost?port=&tls-port=5930", - "spice://localhost?tls-port=5930" }, - { "42", NULL, - "localhost", - NULL, NULL, - "spice://localhost:42", - "spice://localhost?port=42&" }, - { "42", "5930", - "localhost", - NULL, NULL, - "spice://localhost:42?tls-port=5930", - "spice://localhost?port=42&tls-port=5930" }, - { "42", "5930", - "127.0.0.1", - NULL, NULL, - "spice://127.0.0.1:42?tls-port=5930", - "spice://127.0.0.1?port=42&tls-port=5930" }, - }; - /* Set URI and check URI, port and tls_port */ - for (i = 0; i < G_N_ELEMENTS(tests); i++) { + for (i = 0; i < cases; i++) { gchar *uri, *port, *tls_port, *host, *username, *password; s = spice_session_new(); @@ -226,12 +188,103 @@ static void test_session_uri_good(void) } } +static void test_session_uri_ipv4_good(void) +{ + const TestCase tests[] = { + /* Arguments with empty value */ + { "5900", NULL, + "localhost", + NULL, NULL, + "spice://localhost?port=5900&tls-port=", + "spice://localhost?port=5900&" }, + { "5910", NULL, + "localhost", + "user", NULL, + "spice://user@localhost?tls-port=&port=5910", + "spice://localhost?port=5910&" }, + { NULL, "5920", + "localhost", + "user", "password", + "spice://user@localhost?tls-port=5920&port=&password=password", + "spice://localhost?tls-port=5920", + "password may be visible in process listings"}, + { NULL, "5930", + "localhost", + NULL, NULL, + "spice://localhost?port=&tls-port=5930", + "spice://localhost?tls-port=5930" }, + { "42", NULL, + "localhost", + NULL, NULL, + "spice://localhost:42", + "spice://localhost?port=42&" }, + { "42", "5930", + "localhost", + NULL, NULL, + "spice://localhost:42?tls-port=5930", + "spice://localhost?port=42&tls-port=5930" }, + { "42", "5930", + "127.0.0.1", + NULL, NULL, + "spice://127.0.0.1:42?tls-port=5930", + "spice://127.0.0.1?port=42&tls-port=5930" }, + }; + + test_session_uri_good(tests, G_N_ELEMENTS(tests)); +} + +static void test_session_uri_ipv6_good(void) +{ + const TestCase tests[] = { + /* Arguments with empty value */ + { "5900", NULL, + "[2010:836B:4179::836B:4179]", + NULL, NULL, + "spice://[2010:836B:4179::836B:4179]?port=5900&tls-port=", + "spice://[2010:836B:4179::836B:4179]?port=5900&" }, + { "5910", NULL, + "[::192.9.5.5]", + "user", NULL, + "spice://user@[::192.9.5.5]?tls-port=&port=5910", + "spice://[::192.9.5.5]?port=5910&" }, + { NULL, "5920", + "[3ffe:2a00:100:7031::1]", + "user", "password", + "spice://user@[3ffe:2a00:100:7031::1]?tls-port=5920&port=&password=password", + "spice://[3ffe:2a00:100:7031::1]?tls-port=5920", + "password may be visible in process listings"}, + { NULL, "5930", + "[1080:0:0:0:8:800:200C:417A]", + NULL, NULL, + "spice://[1080:0:0:0:8:800:200C:417A]?port=&tls-port=5930", + "spice://[1080:0:0:0:8:800:200C:417A]?tls-port=5930" }, + { "42", NULL, + "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]", + NULL, NULL, + "spice://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:42", + "spice://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]?port=42&" }, + { "42", "5930", + "[::192.9.5.5]", + NULL, NULL, + "spice://[::192.9.5.5]:42?tls-port=5930", + "spice://[::192.9.5.5]?port=42&tls-port=5930" }, + { "42", "5930", + "[::FFFF:129.144.52.38]", + NULL, NULL, + "spice://[::FFFF:129.144.52.38]:42?tls-port=5930", + "spice://[::FFFF:129.144.52.38]?port=42&tls-port=5930" }, + }; + + test_session_uri_good(tests, G_N_ELEMENTS(tests)); +} + int main(int argc, char* argv[]) { g_test_init(&argc, &argv, NULL); g_test_add_func("/session/bad-uri", test_session_uri_bad); - g_test_add_func("/session/good-uri", test_session_uri_good); + g_test_add_func("/session/good-ipv4-uri", test_session_uri_ipv4_good); + g_test_add_func("/session/good-ipv6-uri", test_session_uri_ipv6_good); return g_test_run(); } -- 2.10.1 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel