[Libosinfo] [PATCH 2/4] Add testcase for loading OS XML

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Tue Nov 26 16:00:38 UTC 2013


From: Christophe Fergeau <cfergeau at redhat.com>

There was no test testing that OS XML data is correctly loaded. This test
is also an opportunity to test the various ways of representing a boolean
in XML.
---
 test/test-os.c   | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/test-os.xml | 31 +++++++++++++++++++++++++
 2 files changed, 101 insertions(+)
 create mode 100644 test/test-os.xml

diff --git a/test/test-os.c b/test/test-os.c
index 8ea86df..6077435 100644
--- a/test/test-os.c
+++ b/test/test-os.c
@@ -63,6 +63,75 @@ START_TEST(test_devices)
 END_TEST
 
 
+START_TEST(test_loader)
+{
+    OsinfoLoader *loader;
+    OsinfoDb *db;
+    OsinfoOs *os;
+    GError *error = NULL;
+    const char *str;
+
+    loader = osinfo_loader_new();
+    osinfo_loader_process_path(loader, SRCDIR "/test/test-os.xml", &error);
+    fail_unless(error == NULL, error ? error->message:"none");
+    db = osinfo_loader_get_db(loader);
+
+    os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/test1");
+    fail_unless(os != NULL, "could not find OS 'test1'");
+    str = osinfo_product_get_short_id(OSINFO_PRODUCT(os));
+    fail_unless(g_strcmp0(str, "test1") == 0, "wrong OS short-id");
+    str = osinfo_product_get_name(OSINFO_PRODUCT(os));
+    fail_unless(g_strcmp0(str, "Test 1") == 0, "wrong OS name");
+    str = osinfo_product_get_version(OSINFO_PRODUCT(os));
+    fail_unless(g_strcmp0(str, "unknown") == 0, "wrong OS version");
+    str = osinfo_product_get_vendor(OSINFO_PRODUCT(os));
+    fail_unless(g_strcmp0(str, "libosinfo.org") == 0, "wrong OS vendor");
+    str = osinfo_os_get_family(os);
+    fail_unless(g_strcmp0(str, "test") == 0, "wrong OS family");
+    fail_unless(osinfo_os_get_release_status(os) == OSINFO_RELEASE_STATUS_PRERELEASE,
+                "OS should be a pre-release");
+
+    os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/test2");
+    fail_unless(os != NULL, "could not find OS 'test2'");
+    str = osinfo_product_get_short_id(OSINFO_PRODUCT(os));
+    fail_unless(g_strcmp0(str, "test2") == 0, "wrong OS short-id");
+    str = osinfo_product_get_name(OSINFO_PRODUCT(os));
+    fail_unless(str == NULL, "wrong OS name");
+    str = osinfo_product_get_version(OSINFO_PRODUCT(os));
+    fail_unless(str == NULL, "wrong OS version");
+    str = osinfo_product_get_vendor(OSINFO_PRODUCT(os));
+    fail_unless(str == NULL, "wrong OS vendor");
+    str = osinfo_os_get_family(os);
+    fail_unless(str == NULL, "wrong OS family");
+    fail_unless(osinfo_os_get_release_status(os) == OSINFO_RELEASE_STATUS_RELEASED,
+                "OS should be a released one");
+
+    os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/test3");
+    fail_unless(os != NULL, "could not find OS 'test3'");
+    str = osinfo_product_get_short_id(OSINFO_PRODUCT(os));
+    fail_unless(g_strcmp0(str, "test3") == 0, "wrong OS short-id");
+    fail_unless(osinfo_os_get_release_status(os) == OSINFO_RELEASE_STATUS_RELEASED,
+                "OS should be a released one");
+
+    os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/test4");
+    fail_unless(os != NULL, "could not find OS 'test4'");
+    str = osinfo_product_get_short_id(OSINFO_PRODUCT(os));
+    fail_unless(g_strcmp0(str, "test4") == 0, "wrong OS short-id");
+    fail_unless(osinfo_os_get_release_status(os) == OSINFO_RELEASE_STATUS_SNAPSHOT,
+                "OS should be a snapshot");
+
+    os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/test5");
+    fail_unless(os != NULL, "could not find OS 'test5'");
+    str = osinfo_product_get_short_id(OSINFO_PRODUCT(os));
+    fail_unless(g_strcmp0(str, "test5") == 0, "wrong OS short-id");
+    fail_unless(osinfo_os_get_release_status(os) == OSINFO_RELEASE_STATUS_RELEASED,
+                "OS should be a released one");
+
+    g_object_unref(loader);
+}
+END_TEST
+
+
 START_TEST(test_devices_filter)
 {
     OsinfoOs *os = osinfo_os_new("awesome");
@@ -130,6 +199,7 @@ os_suite(void)
     Suite *s = suite_create("Os");
     TCase *tc = tcase_create("Core");
     tcase_add_test(tc, test_basic);
+    tcase_add_test(tc, test_loader);
     tcase_add_test(tc, test_devices);
     tcase_add_test(tc, test_devices_filter);
     tcase_add_test(tc, test_device_driver);
diff --git a/test/test-os.xml b/test/test-os.xml
new file mode 100644
index 0000000..883fe58
--- /dev/null
+++ b/test/test-os.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+
+  <os id="http://libosinfo.org/test/os/test1">
+    <short-id>test1</short-id>
+    <name>Test 1</name>
+    <version>unknown</version>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <release-status>prerelease</release-status>
+  </os>
+
+  <os id="http://libosinfo.org/test/os/test2">
+    <short-id>test2</short-id>
+    <release-status>released</release-status>
+  </os>
+
+  <os id="http://libosinfo.org/test/os/test3">
+    <short-id>test3</short-id>
+  </os>
+
+  <os id="http://libosinfo.org/test/os/test4">
+    <short-id>test4</short-id>
+    <release-status>snapshot</release-status>
+  </os>
+
+  <os id="http://libosinfo.org/test/os/test5">
+    <short-id>test5</short-id>
+    <release-status>invalid-value</release-status>
+  </os>
+</libosinfo>
-- 
1.8.4.2




More information about the Libosinfo mailing list