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

Christophe Fergeau cfergeau at redhat.com
Wed Nov 6 13:43:44 UTC 2013


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   | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/test-os.xml | 31 +++++++++++++++++++++++++++
 2 files changed, 96 insertions(+)
 create mode 100644 test/test-os.xml

diff --git a/test/test-os.c b/test/test-os.c
index 8ea86df..d21dda8 100644
--- a/test/test-os.c
+++ b/test/test-os.c
@@ -63,6 +63,70 @@ 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_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_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_snapshot(os), "OS should 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_snapshot(os), "OS should not 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_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 +194,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..c410aa7
--- /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>
+    <is-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-snapshot>true</is-snapshot>
+  </os>
+
+  <os id="http://libosinfo.org/test/os/test4">
+    <short-id>test4</short-id>
+    <is-snapshot>false</is-snapshot>
+  </os>
+
+  <os id="http://libosinfo.org/test/os/test5">
+    <short-id>test5</short-id>
+    <is-snapshot>invalid-value</is-snapshot>
+  </os>
+</libosinfo>
-- 
1.8.4.2




More information about the Libosinfo mailing list