[Libosinfo] [libosinfo PATCH 30/31] test-os: Add test_features_inheritance_basic()

Fabiano Fidêncio fidencio at redhat.com
Fri Nov 23 10:15:19 UTC 2018


Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 .../test-os-features-basic-1.xml              | 13 +++++
 .../test-os-features-basic-2-clone.xml        | 10 ++++
 .../test-os-features-basic-2.xml              | 10 ++++
 tests/test-os.c                               | 58 +++++++++++++++++++
 4 files changed, 91 insertions(+)
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-features-basic-1.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-features-basic-2-clone.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-features-basic-2.xml

diff --git a/tests/dbdata/os/libosinfo.org/test-os-features-basic-1.xml b/tests/dbdata/os/libosinfo.org/test-os-features-basic-1.xml
new file mode 100644
index 0000000..b34bbf3
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-features-basic-1.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+    <os id="http://libosinfo.org/test/os/features/basic/1">
+    <short-id>features-basic-1</short-id>
+    <name>Features Basic 1</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+
+    <features>
+      <feature>cpu-hotplug</feature>
+    </features>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-features-basic-2-clone.xml b/tests/dbdata/os/libosinfo.org/test-os-features-basic-2-clone.xml
new file mode 100644
index 0000000..cf65ea7
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-features-basic-2-clone.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/os/features/basic/2-clone">
+    <short-id>features-basic-2-clone</short-id>
+    <name>Features Basic 2 Clone</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <clones id="http://libosinfo.org/test/os/features/basic/2"/>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-features-basic-2.xml b/tests/dbdata/os/libosinfo.org/test-os-features-basic-2.xml
new file mode 100644
index 0000000..d3af204
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-features-basic-2.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/os/features/basic/2">
+    <short-id>features-basic-2</short-id>
+    <name>Features Basic 2</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <derives-from id="http://libosinfo.org/test/os/features/basic/1"/>
+  </os>
+</libosinfo>
diff --git a/tests/test-os.c b/tests/test-os.c
index 9cd75f0..55261ba 100644
--- a/tests/test-os.c
+++ b/tests/test-os.c
@@ -706,6 +706,62 @@ test_devices_inheritance_basic(void)
 }
 
 
+static void
+features_inheritance_basic_check(OsinfoDb *db,
+                                 const gchar *os_id)
+{
+    OsinfoOs *os;
+    OsinfoFeatureList *feature_list;
+    OsinfoFeature *feature;
+
+    g_debug("Testing \"%s\"", os_id);
+
+    os = osinfo_db_get_os(db, os_id);
+    g_assert(OSINFO_IS_OS(os));
+
+    feature_list = osinfo_os_get_all_features(os, NULL);
+    g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(feature_list)), ==, 1);
+
+    feature = OSINFO_FEATURE(osinfo_list_get_nth(OSINFO_LIST(feature_list), 0));
+    g_assert(OSINFO_IS_FEATURE(feature));
+
+    g_object_unref(feature_list);
+}
+
+
+static void
+test_features_inheritance_basic(void)
+{
+    OsinfoLoader *loader = osinfo_loader_new();
+    OsinfoDb *db;
+    GError *error = NULL;
+
+    osinfo_loader_process_path(loader, SRCDIR "/tests/dbdata", &error);
+    g_assert_no_error(error);
+    db = g_object_ref(osinfo_loader_get_db(loader));
+    g_object_unref(loader);
+
+    /*
+     * "http://libosinfo.org/test/os/features/basic/1 has one feature set
+     */
+    features_inheritance_basic_check(db, "http://libosinfo.org/test/os/features/basic/1");
+
+    /*
+     * http://libosinfo.org/test/os/features/basic/2 derives-from
+     * http://libosinfo.org/test/os/features/basic/1
+     */
+    features_inheritance_basic_check(db, "http://libosinfo.org/test/os/features/basic/2");
+
+    /*
+     * http://libosinfo.org/test/os/features/basic/2-clone clones
+     * http://libosinfo.org/test/os/features/basic/2
+     */
+    features_inheritance_basic_check(db, "http://libosinfo.org/test/os/features/basic/2-clone");
+
+    g_object_unref(db);
+}
+
+
 static void
 devices_inheritance_removal_check_devs(OsinfoDb *db,
                                        const gchar *os_id,
@@ -994,6 +1050,8 @@ main(int argc, char *argv[])
                     test_devices_inheritance_removal);
     g_test_add_func("/os/features", test_features);
     g_test_add_func("/os/features/duplication", test_features_duplication);
+    g_test_add_func("/os/features/inheritance/basic",
+                    test_features_inheritance_basic);
     g_test_add_func("/os/resources/minimum_recommended_maximum",
                     test_resources_minimum_recommended_maximum);
     g_test_add_func("/os/resources/uniqueness", test_resources_uniqueness);
-- 
2.19.1




More information about the Libosinfo mailing list