[libvirt] [gconfig v2 6/6] tests: Add test for GVirConfigDomainGraphicsListenAddress

Christophe Fergeau cfergeau at redhat.com
Fri Sep 2 14:20:01 UTC 2016


On Wed, Aug 17, 2016 at 06:58:51PM +0300, Visarion Alexandru wrote:
> From: Visarion Alexandru <viorel.visarion at gmail.com>
> 
> ---
>  tests/test-gconfig.c                               | 36 ++++++++++++++++++++++
>  .../xml/gconfig-domain-device-graphics-listen.xml  |  7 +++++
>  2 files changed, 43 insertions(+)
>  create mode 100644 tests/xml/gconfig-domain-device-graphics-listen.xml
> 
> diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c
> index a26bb5f..28565e3 100644
> --- a/tests/test-gconfig.c
> +++ b/tests/test-gconfig.c
> @@ -481,6 +481,40 @@ static void test_domain_device_graphics(void)
>      g_object_unref(G_OBJECT(domain));
>  }
>  
> +static void test_domain_device_graphics_listen(void)
> +{
> +    GVirConfigDomain *domain;
> +    GVirConfigDomainGraphicsSpice *graphics = NULL;
> +
> +    domain = gvir_config_domain_new();
> +    GList *listen_list = NULL;
> +
> +    graphics = gvir_config_domain_graphics_spice_new();
> +
> +    /* listen address node */
> +    GVirConfigDomainGraphicsListenAddress *address_listen = gvir_config_domain_graphics_listen_address_new();
> +    GInetAddress *inet_address = g_inet_address_new_from_string("0.0.0.0");

This needs to be g_object_unref'ed() when no longer needed

> +
> +    gvir_config_domain_graphics_listen_address_set_inet_address(address_listen, inet_address);
> +    GInetAddress *ret_inet_address = gvir_config_domain_graphics_listen_address_get_inet_address(address_listen);

This too needs g_object_unref()

> +    g_assert_cmpstr(g_inet_address_to_string(inet_address), ==, g_inet_address_to_string(ret_inet_address));

Better to use g_inet_address_equal() here, as otherwise you need to make
sure you free the strings returned by g_inet_address_to_string().
It's better if the test case is leak-free so that it's easier to detect
leaks in newly added code. And if people use it as a base for their
code, better if the code is not too bad.

> +
> +    gvir_config_domain_graphics_listen_address_set_address(address_listen, "127.0.0.1");
> +    const gchar *ret_address = gvir_config_domain_graphics_listen_address_get_address(address_listen);
> +    g_assert_cmpstr("127.0.0.1", ==, ret_address);
> +
> +    /* test listen setter */
> +    listen_list = g_list_append(listen_list, address_listen);

You are missing a g_list_free() when you no longer need this

> +    gvir_config_domain_graphics_spice_set_listen_devices(graphics, listen_list);
> +    g_object_unref(G_OBJECT(address_listen));
> +
> +    gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(graphics));
> +    g_object_unref(G_OBJECT(graphics));

I've fixed all this locally, so no need to resend a fixed version.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20160902/1af37fef/attachment-0001.sig>


More information about the libvir-list mailing list