[Spice-devel] [PATCH spice-gtk 1/4] tests: Add test for SpiceUri

Frediano Ziglio fziglio at redhat.com
Mon May 16 14:10:54 UTC 2016


> 
> Related: rhbz#1335239
> ---
>  tests/Makefile.am      |  2 ++
>  tests/test-spice-uri.c | 64
>  ++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 66 insertions(+)
>  create mode 100644 tests/test-spice-uri.c
> 
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index c1d95c1..fb97138 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -4,6 +4,7 @@ noinst_PROGRAMS =
>  TESTS = coroutine				\
>  	util					\
>  	session					\
> +	test-spice-uri				\
>  	$(NULL)
>  
>  if WITH_PHODAV
> @@ -35,6 +36,7 @@ util_SOURCES = util.c
>  coroutine_SOURCES = coroutine.c
>  session_SOURCES = session.c
>  pipe_SOURCES = pipe.c
> +test_spice_uri_SOURCES = test-spice-uri.c
>  usb_acl_helper_SOURCES = usb-acl-helper.c
>  usb_acl_helper_CFLAGS = -DTESTDIR=\"$(abs_builddir)\"
>  mock_acl_helper_SOURCES = mock-acl-helper.c
> diff --git a/tests/test-spice-uri.c b/tests/test-spice-uri.c
> new file mode 100644
> index 0000000..993cc78
> --- /dev/null
> +++ b/tests/test-spice-uri.c
> @@ -0,0 +1,64 @@
> +/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
> +/*
> +   Copyright (C) 2016 Red Hat, Inc.
> +
> +   This library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   This library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with this library; if not, see
> <http://www.gnu.org/licenses/>.
> +*/
> +#include <glib.h>
> +#include <spice-client.h>
> +#include "spice-uri-priv.h"
> +
> +static void test_spice_uri_ipv4(void)
> +{
> +    SpiceURI *uri = spice_uri_new();
> +    g_assert_nonnull(uri);
> +
> +    /* missing hostname */
> +    g_assert_false(spice_uri_parse(uri, "http://:80", NULL));
> +    /* invalid port */
> +    g_assert_false(spice_uri_parse(uri, "http://127.0.0.1:port", NULL));
> +
> +    g_assert_true(spice_uri_parse(uri, "http://127.0.0.1/", NULL));
> +    g_assert_cmpstr(spice_uri_get_scheme(uri), ==, "http");
> +    g_assert_cmpstr(spice_uri_get_hostname(uri), ==, "127.0.0.1");
> +    g_assert_cmpuint(spice_uri_get_port(uri), ==, 3128);
> +
> +    g_assert_true(spice_uri_parse(uri, "https://127.0.0.1", NULL));
> +    g_assert_cmpstr(spice_uri_get_scheme(uri), ==, "https");
> +    g_assert_cmpstr(spice_uri_get_hostname(uri), ==, "127.0.0.1");
> +    g_assert_cmpuint(spice_uri_get_port(uri), ==, 3129);
> +
> +    g_assert_true(spice_uri_parse(uri, "127.0.0.1", NULL));
> +    g_assert_cmpstr(spice_uri_get_scheme(uri), ==, "http");
> +    g_assert_cmpstr(spice_uri_get_hostname(uri), ==, "127.0.0.1");
> +    g_assert_cmpuint(spice_uri_get_port(uri), ==, 3128);
> +
> +    g_assert_true(spice_uri_parse(uri, "http://user:password@host:80",
> NULL));
> +    g_assert_cmpstr(spice_uri_get_scheme(uri), ==, "http");
> +    g_assert_cmpstr(spice_uri_get_hostname(uri), ==, "host");
> +    g_assert_cmpstr(spice_uri_get_user(uri), ==, "user");
> +    g_assert_cmpstr(spice_uri_get_password(uri), ==, "password");
> +    g_assert_cmpuint(spice_uri_get_port(uri), ==, 80);
> +
> +    g_object_unref(uri);
> +}
> +
> +int main(int argc, char* argv[])
> +{
> +    g_test_init(&argc, &argv, NULL);
> +
> +    g_test_add_func("/spice_uri/ipv4", test_spice_uri_ipv4);
> +
> +    return g_test_run();
> +}
> --
> 2.8.2
> 

Looks ok, a bit weird that default ports are 3128 and 3129, looks different
from the "URI" definition.

Frediano


More information about the Spice-devel mailing list