summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2012-02-23 12:08:42 +0000
committerDaniel P. Berrange <berrange@redhat.com>2012-02-23 16:56:46 +0000
commitef94cea1a5eae54547154393c52b026766a1406d (patch)
tree5e96a1740727ca266669d32236d0338fe488f420 /test
parenta958dfb2d6dd551e5cd6b3d15d960ccece77330b (diff)
Add test for tree URIs
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am8
-rw-r--r--test/test-treeuris.c140
2 files changed, 147 insertions, 1 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 174b070..94543ef 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -16,7 +16,9 @@ check_PROGRAMS = \
test-db \
test-loader \
test-isodetect \
- test-mediauris
+ test-mediauris \
+ test-treeuris \
+ $(NULL)
COMMON_LDADD = \
$(COVERAGE_LDFLAGS) \
@@ -95,6 +97,10 @@ test_mediauris_LDADD = $(COMMON_LDADD)
test_mediauris_CFLAGS = $(COMMON_CFLAGS)
test_mediauris_SOURCES = test-mediauris.c
+test_treeuris_LDADD = $(COMMON_LDADD)
+test_treeuris_CFLAGS = $(COMMON_CFLAGS)
+test_treeuris_SOURCES = test-treeuris.c
+
TESTS = $(check_PROGRAMS)
TESTS_ENVIRONMENT = \
diff --git a/test/test-treeuris.c b/test/test-treeuris.c
new file mode 100644
index 0000000..b07cc6e
--- /dev/null
+++ b/test/test-treeuris.c
@@ -0,0 +1,140 @@
+#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_tree(OsinfoTreeList *treelist, GError **error, SoupSession *session)
+{
+ GList *treeel = NULL, *tmp;
+
+ tmp = treeel = osinfo_list_get_elements(OSINFO_LIST(treelist));
+ while (tmp) {
+ OsinfoTree *tree = tmp->data;
+ const gchar *url = osinfo_tree_get_url(tree);
+ 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(treeel);
+}
+
+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;
+ OsinfoTreeList *treelist = osinfo_os_get_tree_list(os);
+
+ test_tree(treelist, &error, session);
+
+ fail_unless(error == NULL, error ? error->message : "none");
+
+ g_object_unref(treelist);
+ 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);
+
+ if (!getenv("LIBOSINFO_NETWORK_TESTS"))
+ return 77; /* Skip */
+
+ 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:
+ */