|
|
07d9f9 |
From 087bba6bbc4d47e3e068c8b5ee902637de04bc7e Mon Sep 17 00:00:00 2001
|
|
|
07d9f9 |
From: Pavel Grunt <pgrunt@redhat.com>
|
|
|
07d9f9 |
Date: Wed, 1 Jun 2016 10:04:44 +0200
|
|
|
07d9f9 |
Subject: [PATCH 08/15] tests: Add test for SpiceURI
|
|
|
07d9f9 |
|
|
|
07d9f9 |
Related: rhbz#1335239
|
|
|
07d9f9 |
(cherry picked from commit dab190d8d2cb93f85f1858135354dd4e93ff48f8)
|
|
|
07d9f9 |
---
|
|
|
07d9f9 |
tests/Makefile.am | 2 ++
|
|
|
07d9f9 |
tests/uri.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
07d9f9 |
2 files changed, 105 insertions(+)
|
|
|
07d9f9 |
create mode 100644 tests/uri.c
|
|
|
07d9f9 |
|
|
|
07d9f9 |
diff --git a/tests/Makefile.am b/tests/Makefile.am
|
|
|
07d9f9 |
index c1d95c1..9517431 100644
|
|
|
07d9f9 |
--- a/tests/Makefile.am
|
|
|
07d9f9 |
+++ b/tests/Makefile.am
|
|
|
07d9f9 |
@@ -4,6 +4,7 @@ noinst_PROGRAMS =
|
|
|
07d9f9 |
TESTS = coroutine \
|
|
|
07d9f9 |
util \
|
|
|
07d9f9 |
session \
|
|
|
07d9f9 |
+ test-spice-uri \
|
|
|
07d9f9 |
$(NULL)
|
|
|
07d9f9 |
|
|
|
07d9f9 |
if WITH_PHODAV
|
|
|
07d9f9 |
@@ -35,6 +36,7 @@ util_SOURCES = util.c
|
|
|
07d9f9 |
coroutine_SOURCES = coroutine.c
|
|
|
07d9f9 |
session_SOURCES = session.c
|
|
|
07d9f9 |
pipe_SOURCES = pipe.c
|
|
|
07d9f9 |
+test_spice_uri_SOURCES = uri.c
|
|
|
07d9f9 |
usb_acl_helper_SOURCES = usb-acl-helper.c
|
|
|
07d9f9 |
usb_acl_helper_CFLAGS = -DTESTDIR=\"$(abs_builddir)\"
|
|
|
07d9f9 |
mock_acl_helper_SOURCES = mock-acl-helper.c
|
|
|
07d9f9 |
diff --git a/tests/uri.c b/tests/uri.c
|
|
|
07d9f9 |
new file mode 100644
|
|
|
07d9f9 |
index 0000000..b68f159
|
|
|
07d9f9 |
--- /dev/null
|
|
|
07d9f9 |
+++ b/tests/uri.c
|
|
|
07d9f9 |
@@ -0,0 +1,103 @@
|
|
|
07d9f9 |
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
07d9f9 |
+/*
|
|
|
07d9f9 |
+ Copyright (C) 2016 Red Hat, Inc.
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+ This library is free software; you can redistribute it and/or
|
|
|
07d9f9 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
07d9f9 |
+ License as published by the Free Software Foundation; either
|
|
|
07d9f9 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+ This library is distributed in the hope that it will be useful,
|
|
|
07d9f9 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
07d9f9 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
07d9f9 |
+ Lesser General Public License for more details.
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
07d9f9 |
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
07d9f9 |
+*/
|
|
|
07d9f9 |
+#include <glib.h>
|
|
|
07d9f9 |
+#include <spice-client.h>
|
|
|
07d9f9 |
+#include "spice-uri-priv.h"
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+struct test_case {
|
|
|
07d9f9 |
+ gchar *uri;
|
|
|
07d9f9 |
+ gchar *scheme;
|
|
|
07d9f9 |
+ gchar *hostname;
|
|
|
07d9f9 |
+ guint port;
|
|
|
07d9f9 |
+ gchar *user;
|
|
|
07d9f9 |
+ gchar *password;
|
|
|
07d9f9 |
+ gchar *error_msg;
|
|
|
07d9f9 |
+};
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+static void test_spice_uri_bad(const struct test_case invalid_test_cases[], const guint cases_cnt)
|
|
|
07d9f9 |
+{
|
|
|
07d9f9 |
+ guint i;
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+ SpiceURI *uri = spice_uri_new();
|
|
|
07d9f9 |
+ g_assert_nonnull(uri);
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+ for (i = 0; i < cases_cnt; i++) {
|
|
|
07d9f9 |
+ GError *error = NULL;
|
|
|
07d9f9 |
+ g_assert_false(spice_uri_parse(uri, invalid_test_cases[i].uri, &error));
|
|
|
07d9f9 |
+ g_assert_error(error, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED);
|
|
|
07d9f9 |
+ g_assert_cmpstr(error->message, ==, invalid_test_cases[i].error_msg);
|
|
|
07d9f9 |
+ g_error_free(error);
|
|
|
07d9f9 |
+ }
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+ g_object_unref(uri);
|
|
|
07d9f9 |
+}
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+static void test_spice_uri_good(const struct test_case valid_test_cases[], const guint cases_cnt)
|
|
|
07d9f9 |
+{
|
|
|
07d9f9 |
+ guint i;
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+ SpiceURI *uri = spice_uri_new();
|
|
|
07d9f9 |
+ g_assert_nonnull(uri);
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+ for (i = 0; i < cases_cnt; i++) {
|
|
|
07d9f9 |
+ GError *error = NULL;
|
|
|
07d9f9 |
+ g_assert_true(spice_uri_parse(uri, valid_test_cases[i].uri, &error));
|
|
|
07d9f9 |
+ g_assert_cmpstr(spice_uri_get_scheme(uri), ==, valid_test_cases[i].scheme);
|
|
|
07d9f9 |
+ g_assert_cmpstr(spice_uri_get_hostname(uri), ==, valid_test_cases[i].hostname);
|
|
|
07d9f9 |
+ g_assert_cmpstr(spice_uri_get_user(uri), ==, valid_test_cases[i].user);
|
|
|
07d9f9 |
+ g_assert_cmpstr(spice_uri_get_password(uri), ==, valid_test_cases[i].password);
|
|
|
07d9f9 |
+ g_assert_cmpuint(spice_uri_get_port(uri), ==, valid_test_cases[i].port);
|
|
|
07d9f9 |
+ g_assert_no_error(error);
|
|
|
07d9f9 |
+ }
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+ g_object_unref(uri);
|
|
|
07d9f9 |
+}
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+static void test_spice_uri_ipv4_bad(void)
|
|
|
07d9f9 |
+{
|
|
|
07d9f9 |
+ const struct test_case invalid_test_cases[] = {
|
|
|
07d9f9 |
+ {"http://:80", "http", NULL, 80, NULL, NULL, "Invalid hostname in uri address"},
|
|
|
07d9f9 |
+ {"http://", "http", NULL, 3128, NULL, NULL, "Invalid hostname in uri address"},
|
|
|
07d9f9 |
+ {"http://127.0.0.1:port", "http", "127.0.0.1", 3128, NULL, NULL,
|
|
|
07d9f9 |
+ "Invalid uri port: port"},
|
|
|
07d9f9 |
+ };
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+ test_spice_uri_bad(invalid_test_cases, G_N_ELEMENTS(invalid_test_cases));
|
|
|
07d9f9 |
+}
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+static void test_spice_uri_ipv4_good(void)
|
|
|
07d9f9 |
+{
|
|
|
07d9f9 |
+ const struct test_case valid_test_cases[] = {
|
|
|
07d9f9 |
+ {"http://127.0.0.1/", "http", "127.0.0.1", 3128, NULL, NULL, NULL},
|
|
|
07d9f9 |
+ {"https://127.0.0.1", "https", "127.0.0.1", 3129, NULL, NULL, NULL},
|
|
|
07d9f9 |
+ {"127.0.0.1", "http", "127.0.0.1", 3128, NULL, NULL, NULL},
|
|
|
07d9f9 |
+ {"http://user:password@host:80", "http", "host", 80, "user", "password", NULL},
|
|
|
07d9f9 |
+ };
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+ test_spice_uri_good(valid_test_cases, G_N_ELEMENTS(valid_test_cases));
|
|
|
07d9f9 |
+}
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+int main(int argc, char* argv[])
|
|
|
07d9f9 |
+{
|
|
|
07d9f9 |
+ g_test_init(&argc, &argv, NULL);
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+ g_test_add_func("/spice_uri/ipv4/bad-uri", test_spice_uri_ipv4_bad);
|
|
|
07d9f9 |
+ g_test_add_func("/spice_uri/ipv4/good-uri", test_spice_uri_ipv4_good);
|
|
|
07d9f9 |
+
|
|
|
07d9f9 |
+ return g_test_run();
|
|
|
07d9f9 |
+}
|
|
|
07d9f9 |
--
|
|
|
07d9f9 |
2.5.5
|
|
|
07d9f9 |
|