Re: [libvirt] [PATCH 01/14] Add test case for virURIPtr classs
On Thu, Mar 22, 2012 at 11:54:07AM +0800, Osier Yang wrote: On 2012年03月21日 01:33, Daniel P. Berrange wrote: From: Daniel P. Berrangeberra...@redhat.com To ensure we properly escape unescape IPv6 numeric addresses, add a test case * tests/Makefile.am, tests/viruritest.c: URI parsing test --- tests/Makefile.am |7 ++- tests/viruritest.c | 139 2 files changed, 145 insertions(+), 1 deletions(-) create mode 100644 tests/viruritest.c +static int testURIParse(const void *args) +{ +int ret = -1; +virURIPtr uri = NULL; +const struct URIParseData *data = args; +char *uristr; + +if (!(uri = virURIParse(data-uri))) { +virReportOOMError(); It's not neccessary to be out of memory error, perhaps VIR_DEBUG with a msg is better here. libxml doesn't do any usefull error reporting here so we can't find out what is actually wrong :-( Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 01/14] Add test case for virURIPtr classs
On 2012年03月21日 01:33, Daniel P. Berrange wrote: From: Daniel P. Berrangeberra...@redhat.com To ensure we properly escape unescape IPv6 numeric addresses, add a test case * tests/Makefile.am, tests/viruritest.c: URI parsing test --- tests/Makefile.am |7 ++- tests/viruritest.c | 139 2 files changed, 145 insertions(+), 1 deletions(-) create mode 100644 tests/viruritest.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 0c8cf37..035c8c6 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -96,7 +96,7 @@ check_PROGRAMS = virshtest conftest sockettest \ commandtest commandhelper seclabeltest \ virhashtest virnetmessagetest virnetsockettest ssh \ utiltest virnettlscontexttest shunloadtest \ - virtimetest + virtimetest viruritest check_LTLIBRARIES = libshunload.la @@ -219,6 +219,7 @@ TESTS = virshtest \ virnetsockettest \ virnettlscontexttest \ virtimetest \ +viruritest \ Seems like this uses spaces? shunloadtest \ utiltest \ $(test_scripts) @@ -506,6 +507,10 @@ virtimetest_SOURCES = \ virtimetest_CFLAGS = -Dabs_builddir=\$(abs_builddir)\ $(AM_CFLAGS) virtimetest_LDADD = ../src/libvirt-net-rpc.la $(LDADDS) +viruritest_SOURCES = \ + viruritest.c testutils.h testutils.c +viruritest_CFLAGS = -Dabs_builddir=\$(abs_builddir)\ $(AM_CFLAGS) +viruritest_LDADD = ../src/libvirt-net-rpc.la $(LDADDS) seclabeltest_SOURCES = \ seclabeltest.c diff --git a/tests/viruritest.c b/tests/viruritest.c new file mode 100644 index 000..a5de50a --- /dev/null +++ b/tests/viruritest.c @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2011 Red Hat, Inc. s/2011/2012/ + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Daniel P. Berrangeberra...@redhat.com + */ + +#includeconfig.h + +#includestdlib.h +#includesignal.h + +#include testutils.h +#include util.h +#include virterror_internal.h +#include memory.h +#include logging.h + +#include viruri.h + +#define VIR_FROM_THIS VIR_FROM_RPC + +struct URIParseData { +const char *uri; +const char *scheme; +const char *server; +int port; +const char *path; +const char *query; +const char *fragment; +}; + +static int testURIParse(const void *args) +{ +int ret = -1; +virURIPtr uri = NULL; +const struct URIParseData *data = args; +char *uristr; + +if (!(uri = virURIParse(data-uri))) { +virReportOOMError(); It's not neccessary to be out of memory error, perhaps VIR_DEBUG with a msg is better here. +goto cleanup; +} + +if (!(uristr = virURIFormat(uri))) { +virReportOOMError(); likewise +goto cleanup; +} + +if (!STREQ(uristr, data-uri)) { +VIR_DEBUG(URI did not roundtrip, expect '%s', actual '%s', + data-uri, uristr); +goto cleanup; +} + +if (!STREQ(uri-scheme, data-scheme)) { +VIR_DEBUG(Expected scheme '%s', actual '%s', + data-scheme, uri-scheme); +goto cleanup; +} + +if (!STREQ(uri-server, data-server)) { +VIR_DEBUG(Expected server '%s', actual '%s', + data-server, uri-server); +goto cleanup; +} + +if (uri-port != data-port) { +VIR_DEBUG(Expected port '%d', actual '%d', + data-port, uri-port); +goto cleanup; +} + +if (!STREQ_NULLABLE(uri-path, data-path)) { +VIR_DEBUG(Expected path '%s', actual '%s', + data-path, uri-path); +goto cleanup; +} + +if (!STREQ_NULLABLE(uri-query, data-query)) { +VIR_DEBUG(Expected query '%s', actual '%s', + data-query, uri-query); +goto cleanup; +} + +if (!STREQ_NULLABLE(uri-fragment, data-fragment)) { +VIR_DEBUG(Expected fragment '%s', actual '%s', + data-fragment, uri-fragment); +goto cleanup; +} + +ret = 0; +cleanup: +VIR_FREE(uristr); +xmlFreeURI(uri); +return ret; +} + + +static int +mymain(void) +{ +int ret = 0; + +signal(SIGPIPE, SIG_IGN); + +#define TEST_PARSE(uri, scheme, server, port, path, query, fragment)\ +do {
[libvirt] [PATCH 01/14] Add test case for virURIPtr classs
From: Daniel P. Berrange berra...@redhat.com To ensure we properly escape unescape IPv6 numeric addresses, add a test case * tests/Makefile.am, tests/viruritest.c: URI parsing test --- tests/Makefile.am |7 ++- tests/viruritest.c | 139 2 files changed, 145 insertions(+), 1 deletions(-) create mode 100644 tests/viruritest.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 0c8cf37..035c8c6 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -96,7 +96,7 @@ check_PROGRAMS = virshtest conftest sockettest \ commandtest commandhelper seclabeltest \ virhashtest virnetmessagetest virnetsockettest ssh \ utiltest virnettlscontexttest shunloadtest \ - virtimetest + virtimetest viruritest check_LTLIBRARIES = libshunload.la @@ -219,6 +219,7 @@ TESTS = virshtest \ virnetsockettest \ virnettlscontexttest \ virtimetest \ +viruritest \ shunloadtest \ utiltest \ $(test_scripts) @@ -506,6 +507,10 @@ virtimetest_SOURCES = \ virtimetest_CFLAGS = -Dabs_builddir=\$(abs_builddir)\ $(AM_CFLAGS) virtimetest_LDADD = ../src/libvirt-net-rpc.la $(LDADDS) +viruritest_SOURCES = \ + viruritest.c testutils.h testutils.c +viruritest_CFLAGS = -Dabs_builddir=\$(abs_builddir)\ $(AM_CFLAGS) +viruritest_LDADD = ../src/libvirt-net-rpc.la $(LDADDS) seclabeltest_SOURCES = \ seclabeltest.c diff --git a/tests/viruritest.c b/tests/viruritest.c new file mode 100644 index 000..a5de50a --- /dev/null +++ b/tests/viruritest.c @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2011 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Daniel P. Berrange berra...@redhat.com + */ + +#include config.h + +#include stdlib.h +#include signal.h + +#include testutils.h +#include util.h +#include virterror_internal.h +#include memory.h +#include logging.h + +#include viruri.h + +#define VIR_FROM_THIS VIR_FROM_RPC + +struct URIParseData { +const char *uri; +const char *scheme; +const char *server; +int port; +const char *path; +const char *query; +const char *fragment; +}; + +static int testURIParse(const void *args) +{ +int ret = -1; +virURIPtr uri = NULL; +const struct URIParseData *data = args; +char *uristr; + +if (!(uri = virURIParse(data-uri))) { +virReportOOMError(); +goto cleanup; +} + +if (!(uristr = virURIFormat(uri))) { +virReportOOMError(); +goto cleanup; +} + +if (!STREQ(uristr, data-uri)) { +VIR_DEBUG(URI did not roundtrip, expect '%s', actual '%s', + data-uri, uristr); +goto cleanup; +} + +if (!STREQ(uri-scheme, data-scheme)) { +VIR_DEBUG(Expected scheme '%s', actual '%s', + data-scheme, uri-scheme); +goto cleanup; +} + +if (!STREQ(uri-server, data-server)) { +VIR_DEBUG(Expected server '%s', actual '%s', + data-server, uri-server); +goto cleanup; +} + +if (uri-port != data-port) { +VIR_DEBUG(Expected port '%d', actual '%d', + data-port, uri-port); +goto cleanup; +} + +if (!STREQ_NULLABLE(uri-path, data-path)) { +VIR_DEBUG(Expected path '%s', actual '%s', + data-path, uri-path); +goto cleanup; +} + +if (!STREQ_NULLABLE(uri-query, data-query)) { +VIR_DEBUG(Expected query '%s', actual '%s', + data-query, uri-query); +goto cleanup; +} + +if (!STREQ_NULLABLE(uri-fragment, data-fragment)) { +VIR_DEBUG(Expected fragment '%s', actual '%s', + data-fragment, uri-fragment); +goto cleanup; +} + +ret = 0; +cleanup: +VIR_FREE(uristr); +xmlFreeURI(uri); +return ret; +} + + +static int +mymain(void) +{ +int ret = 0; + +signal(SIGPIPE, SIG_IGN); + +#define TEST_PARSE(uri, scheme, server, port, path, query, fragment)\ +do { \ +conststruct URIParseData data = { \ +uri, scheme, server, port, path, query, fragment\ +};