[Libosinfo] [PATCH 3/5] Add testcase for loading OS XML

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Thu Nov 21 17:52:55 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 | 35 ++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+)
 create mode 100644 test/test-os.xml

diff --git a/test/test-os.c b/test/test-os.c
index 8ea86df..67a683c 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_is_pre_release(os), "OS should be a pre-release");
+    fail_unless(osinfo_os_get_is_continuous_snapshot(os), "OS should be a snapshot");
+
+    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_is_pre_release(os), "OS should not be a pre-release");
+    fail_unless(!osinfo_os_get_is_continuous_snapshot(os), "OS should not be a snapshot");
+
+    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_is_pre_release(os), "OS should be a pre-release");
+    fail_unless(!osinfo_os_get_is_continuous_snapshot(os), "OS should not be a snapshot");
+
+    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_is_pre_release(os), "OS should not be a pre-release");
+    fail_unless(osinfo_os_get_is_continuous_snapshot(os), "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_is_pre_release(os), "OS should not be a pre-release");
+    fail_unless(!osinfo_os_get_is_continuous_snapshot(os), "OS should not be a snapshot");
+
+    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..ea97b56
--- /dev/null
+++ b/test/test-os.xml
@@ -0,0 +1,35 @@
+<?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>
+    <is-pre-release/>
+    <is-continuous-snapshot/>
+  </os>
+
+  <os id="http://libosinfo.org/test/os/test2">
+    <short-id>test2</short-id>
+  </os>
+
+  <os id="http://libosinfo.org/test/os/test3">
+    <short-id>test3</short-id>
+    <is-pre-release>true</is-pre-release>
+    <is-continuous-snapshot>false</is-continuous-snapshot>
+  </os>
+
+  <os id="http://libosinfo.org/test/os/test4">
+    <short-id>test4</short-id>
+    <is-pre-release>false</is-pre-release>
+    <is-continuous-snapshot>true</is-continuous-snapshot>
+  </os>
+
+  <os id="http://libosinfo.org/test/os/test5">
+    <short-id>test5</short-id>
+    <is-pre-release>invalid-value</is-pre-release>
+    <is-continuous-snapshot>invalid-value</is-continuous-snapshot>
+  </os>
+</libosinfo>
-- 
1.8.4.2




More information about the Libosinfo mailing list