[virt-tools-list] [PATCH libosinfo 3/3] Add test case for validating all URIs

Daniel P. Berrange berrange at redhat.com
Tue Feb 21 17:46:16 UTC 2012


From: "Daniel P. Berrange" <berrange at redhat.com>

---
 configure.ac              |    2 +
 libosinfo.spec.in         |    2 +
 mingw32-libosinfo.spec.in |    2 +
 test/Makefile.am          |   11 +++-
 test/test-mediauris.c     |  137 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 153 insertions(+), 1 deletions(-)
 create mode 100644 test/test-mediauris.c

diff --git a/configure.ac b/configure.ac
index a5aec10..0b9574f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -17,6 +17,8 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
 
 PKG_CHECK_MODULES([GOBJECT], [gobject-2.0])
 PKG_CHECK_MODULES([GIO], [gio-2.0])
+PKG_CHECK_MODULES([SOUP], [libsoup-2.4])
+PKG_CHECK_MODULES([SOUP_GNOME], [libsoup-gnome-2.4])
 PKG_CHECK_MODULES([LIBXML], [libxml-2.0 >= 2.6.0])
 
 GTK_DOC_CHECK([1.10],[--flavour no-tmpl])
diff --git a/libosinfo.spec.in b/libosinfo.spec.in
index 4114d00..8b98be0 100644
--- a/libosinfo.spec.in
+++ b/libosinfo.spec.in
@@ -24,6 +24,8 @@ BuildRequires: check-devel
 BuildRequires: libxml2-devel >= 2.6.0
 BuildRequires: vala
 BuildRequires: vala-tools
+BuildRequires: libsoup-devel
+BuildRequires: libsoup-gnome-devel
 %if %{with_gir}
 BuildRequires: gobject-introspection-devel
 %endif
diff --git a/mingw32-libosinfo.spec.in b/mingw32-libosinfo.spec.in
index a0be786..2a0379a 100644
--- a/mingw32-libosinfo.spec.in
+++ b/mingw32-libosinfo.spec.in
@@ -22,6 +22,8 @@ BuildRequires: mingw32-binutils
 
 BuildRequires: mingw32-glib2
 BuildRequires: mingw32-libxml2
+BuildRequires: mingw32-libsoup
+BuildRequires: mingw32-libsoup-gnome
 BuildRequires: pkgconfig
 
 Requires: pkgconfig
diff --git a/test/Makefile.am b/test/Makefile.am
index 33438f9..afa817d 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -13,17 +13,22 @@ check_PROGRAMS = \
 	test-platformlist \
 	test-db \
 	test-loader \
-	test-isodetect
+	test-isodetect \
+	test-mediauris
 
 COMMON_LDADD = \
 	$(COVERAGE_LDFLAGS) \
 	$(GOBJECT_LIBS) \
+	$(SOUP_LIBS) \
+	$(SOUP_GNOME_LIBS) \
 	$(CHECK_LIBS) \
 	../osinfo/libosinfo-1.0.la
 COMMON_CFLAGS = \
 	$(WARN_CFLAGS) \
 	$(COVERAGE_CFLAGS) \
 	$(GOBJECT_CFLAGS) \
+	$(SOUP_CFLAGS) \
+	$(SOUP_GNOME_CFLAGS) \
 	-I$(top_srcdir) \
 	-DSRCDIR="\"$(top_srcdir)\"" \
 	$(CHECK_CFLAGS)
@@ -84,6 +89,10 @@ test_isodetect_LDADD = $(COMMON_LDADD)
 test_isodetect_CFLAGS = $(COMMON_CFLAGS)
 test_isodetect_SOURCES = test-isodetect.c
 
+test_mediauris_LDADD = $(COMMON_LDADD)
+test_mediauris_CFLAGS = $(COMMON_CFLAGS)
+test_mediauris_SOURCES = test-mediauris.c
+
 TESTS = $(check_PROGRAMS)
 
 TESTS_ENVIRONMENT = \
diff --git a/test/test-mediauris.c b/test/test-mediauris.c
new file mode 100644
index 0000000..0912fb8
--- /dev/null
+++ b/test/test-mediauris.c
@@ -0,0 +1,137 @@
+#include <config.h>
+#include <stdlib.h>
+#include <osinfo/osinfo.h>
+#include <check.h>
+#include <libsoup/soup.h>
+#define HAVE_LIBSOUP_GNOME
+#include <libsoup/soup-gnome.h>
+
+static void test_media(OsinfoMediaList *medialist, GError **error, SoupSession *session)
+{
+    GList *mediael = NULL, *tmp;
+
+    tmp = mediael = osinfo_list_get_elements(OSINFO_LIST(medialist));
+    while (tmp) {
+        OsinfoMedia *media = tmp->data;
+        const gchar *url = osinfo_media_get_url(media);
+        SoupMessage *msg;
+        guint status;
+
+        if (url == NULL || g_str_equal(url, "")) {
+            tmp = tmp->next;
+            continue;
+        }
+
+        g_print("%s\n", url);
+        msg = soup_message_new("HEAD", url);
+        status = soup_session_send_message(session, msg);
+
+        fail_unless(SOUP_STATUS_IS_SUCCESSFUL(status), "Failed HEAD on %s", url);
+
+        g_object_unref(msg);
+        tmp = tmp->next;
+    }
+
+    g_list_free(mediael);
+}
+
+START_TEST(test_uris)
+{
+    SoupSession *session;
+    OsinfoLoader *loader = osinfo_loader_new();
+    OsinfoDb *db = osinfo_loader_get_db(loader);
+    GError *error = NULL;
+    OsinfoOsList *oslist = NULL;
+    GList *osel = NULL, *tmp;
+    gchar *debugstr;
+
+    session = soup_session_async_new_with_options(
+#ifdef HAVE_LIBSOUP_GNOME
+                                                  SOUP_SESSION_ADD_FEATURE_BY_TYPE,
+                                                  SOUP_TYPE_PROXY_RESOLVER_GNOME,
+#endif
+                                                  NULL);
+    if ((debugstr = getenv("LIBOSINFO_TEST_DEBUG"))) {
+        SoupLogger *logger;
+        int debug_level = atoi(debugstr);
+
+        logger = soup_logger_new (debug_level, -1);
+        soup_session_add_feature (session, SOUP_SESSION_FEATURE (logger));
+        g_object_unref (logger);
+    }
+
+    fail_unless(OSINFO_IS_LOADER(loader), "Loader is not a LOADER");
+    fail_unless(OSINFO_IS_DB(db), "Db is not a DB");
+
+    osinfo_loader_process_path(loader, SRCDIR "/data", &error);
+    fail_unless(error == NULL, error ? error->message : "none");
+
+    oslist = osinfo_db_get_os_list(db);
+    tmp = osel = osinfo_list_get_elements(OSINFO_LIST(oslist));
+    while (tmp) {
+        OsinfoOs *os = tmp->data;
+        OsinfoMediaList *medialist = osinfo_os_get_media_list(os);
+
+        test_media(medialist, &error, session);
+
+        fail_unless(error == NULL, error ? error->message : "none");
+
+        g_object_unref(medialist);
+        tmp = tmp->next;
+    }
+
+    g_list_free(tmp);
+    if (oslist)
+        g_object_unref(oslist);
+
+    g_object_unref(loader);
+}
+END_TEST
+
+
+
+static Suite *
+list_suite(void)
+{
+    Suite *s = suite_create("List");
+    TCase *tc = tcase_create("Core");
+    tcase_set_timeout(tc, 120);
+
+    tcase_add_test(tc, test_uris);
+    suite_add_tcase(s, tc);
+    return s;
+}
+
+int main(void)
+{
+    int number_failed;
+    Suite *s = list_suite ();
+    SRunner *sr = srunner_create (s);
+
+    g_type_init();
+
+    /* Upfront so we don't confuse valgrind */
+    osinfo_entity_get_type();
+    osinfo_db_get_type();
+    osinfo_device_get_type();
+    osinfo_platform_get_type();
+    osinfo_os_get_type();
+    osinfo_list_get_type();
+    osinfo_devicelist_get_type();
+    osinfo_platformlist_get_type();
+    osinfo_oslist_get_type();
+    osinfo_filter_get_type();
+
+    srunner_run_all (sr, CK_ENV);
+    number_failed = srunner_ntests_failed (sr);
+    srunner_free (sr);
+
+    return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
-- 
1.7.7.6




More information about the virt-tools-list mailing list