[Libosinfo] [libosinfo PATCH v2 05/15] tests-os: Add test_devices_inheritance_basic()

Fabiano Fidêncio fidencio at redhat.com
Mon Nov 12 10:30:52 UTC 2018


Devices are inherited from OSes that derives-from/clones some other OS.
Let's have a test case to ensure it's not going to break in the future.

https://gitlab.com/libosinfo/osinfo-db/issues/13

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 .../device/libosinfo.org/test-device-one.xml  |  7 +++
 .../libosinfo.org/test-os-devices-basic-1.xml | 13 ++++
 .../test-os-devices-basic-2-clone.xml         | 10 ++++
 .../libosinfo.org/test-os-devices-basic-2.xml | 10 ++++
 tests/test-os.c                               | 59 +++++++++++++++++++
 5 files changed, 99 insertions(+)
 create mode 100644 tests/dbdata/device/libosinfo.org/test-device-one.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-devices-basic-1.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-devices-basic-2-clone.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-devices-basic-2.xml

diff --git a/tests/dbdata/device/libosinfo.org/test-device-one.xml b/tests/dbdata/device/libosinfo.org/test-device-one.xml
new file mode 100644
index 0000000..cb1945f
--- /dev/null
+++ b/tests/dbdata/device/libosinfo.org/test-device-one.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <device id="http://libosinfo.org/test/device/one">
+    <name>test-device-one</name>
+    <class>chipset</class>
+  </device>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-devices-basic-1.xml b/tests/dbdata/os/libosinfo.org/test-os-devices-basic-1.xml
new file mode 100644
index 0000000..307944d
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-devices-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/devices/basic/1">
+    <short-id>devices-basic-1</short-id>
+    <name>Devices Basic 1</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+
+    <devices>
+      <device id="http://libosinfo.org/test/device/one"/>
+    </devices>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-devices-basic-2-clone.xml b/tests/dbdata/os/libosinfo.org/test-os-devices-basic-2-clone.xml
new file mode 100644
index 0000000..c1c0883
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-devices-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/devices/basic/2-clone">
+    <short-id>devices-basic-2-clone</short-id>
+    <name>Devices Basic 2 Clone</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <clones id="http://libosinfo.org/test/os/devices/basic/2"/>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-devices-basic-2.xml b/tests/dbdata/os/libosinfo.org/test-os-devices-basic-2.xml
new file mode 100644
index 0000000..0e5bdb8
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-devices-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/devices/basic/2">
+    <short-id>devices-basic-2</short-id>
+    <name>Devices Basic 2</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <derives-from id="http://libosinfo.org/test/os/devices/basic/1"/>
+  </os>
+</libosinfo>
diff --git a/tests/test-os.c b/tests/test-os.c
index 2ec7960..18c2829 100644
--- a/tests/test-os.c
+++ b/tests/test-os.c
@@ -188,6 +188,62 @@ test_device_driver(void)
 }
 
 
+static void
+devices_inheritance_basic_check(OsinfoDb *db,
+                                const gchar *os_id)
+{
+    OsinfoOs *os;
+    OsinfoDeviceList *dev_list;
+    OsinfoDevice *dev;
+
+    g_debug("Testing \"%s\"", os_id);
+
+    os = osinfo_db_get_os(db, os_id);
+    g_assert(OSINFO_IS_OS(os));
+
+    dev_list = osinfo_os_get_all_devices(os, NULL);
+    g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(dev_list)), ==, 1);
+
+    dev = OSINFO_DEVICE(osinfo_list_get_nth(OSINFO_LIST(dev_list), 0));
+    g_assert(OSINFO_IS_DEVICE(dev));
+
+    g_object_unref(dev_list);
+}
+
+
+static void
+test_devices_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/devices/basic/1 has one device set
+     */
+    devices_inheritance_basic_check(db, "http://libosinfo.org/test/os/devices/basic/1");
+
+    /*
+     * http://libosinfo.org/test/os/devices/basic/2 derives-from
+     * http://libosinfo.org/test/os/devices/basic/1
+     */
+    devices_inheritance_basic_check(db, "http://libosinfo.org/test/os/devices/basic/2");
+
+    /*
+     * http://libosinfo.org/test/os/devices/basic/2-clone clones
+     * http://libosinfo.org/test/os/devices/basic/2
+     */
+    devices_inheritance_basic_check(db, "http://libosinfo.org/test/os/devices/basic/2-clone");
+
+    g_object_unref(db);
+}
+
+
 int
 main(int argc, char *argv[])
 {
@@ -198,6 +254,7 @@ main(int argc, char *argv[])
     g_test_add_func("/os/devices", test_devices);
     g_test_add_func("/os/devices_filter", test_devices_filter);
     g_test_add_func("/os/device_driver", test_device_driver);
+    g_test_add_func("/os/devices_inheritance/basic", test_devices_inheritance_basic);
 
     /* Upfront so we don't confuse valgrind */
     osinfo_platform_get_type();
@@ -206,6 +263,8 @@ main(int argc, char *argv[])
     osinfo_oslist_get_type();
     osinfo_devicelist_get_type();
     osinfo_filter_get_type();
+    osinfo_resources_get_type();
+    osinfo_resourceslist_get_type();
 
     return g_test_run();
 }
-- 
2.19.1




More information about the Libosinfo mailing list