[Libosinfo] [libosinfo PATCH v2 15/15] test-os: Add test_devices_inheritance_removal()

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


Now that OsinfoOs can deal with the concept of a "removed" device, let's
add some tests covering the possible situations we may face and ensure
we won't regress here.

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

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 .../test-os-devices-removed-1.xml             |  14 +++
 .../test-os-devices-removed-2-clone.xml       |  10 ++
 .../test-os-devices-removed-2.xml             |  10 ++
 .../test-os-devices-removed-3.xml             |  14 +++
 .../test-os-devices-removed-4-clone.xml       |  10 ++
 .../test-os-devices-removed-4.xml             |  10 ++
 tests/test-os.c                               | 110 ++++++++++++++++++
 7 files changed, 178 insertions(+)
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-devices-removed-1.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-devices-removed-2-clone.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-devices-removed-2.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-devices-removed-3.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-devices-removed-4-clone.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-devices-removed-4.xml

diff --git a/tests/dbdata/os/libosinfo.org/test-os-devices-removed-1.xml b/tests/dbdata/os/libosinfo.org/test-os-devices-removed-1.xml
new file mode 100644
index 0000000..2851ecd
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-devices-removed-1.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/os/devices/removed/1">
+    <short-id>devices-removed-1</short-id>
+    <name>Devices Removed 1</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <derives-from id="http://libosinfo.org/test/os/devices/basic/1"/>
+
+    <devices>
+      <device id="http://libosinfo.org/test/device/one" removed="true"/>
+    </devices>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-devices-removed-2-clone.xml b/tests/dbdata/os/libosinfo.org/test-os-devices-removed-2-clone.xml
new file mode 100644
index 0000000..8ab01d2
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-devices-removed-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/removed/2-clone">
+    <short-id>devices-removed-2-clone</short-id>
+    <name>Devices Removed 2 Clone</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <clones id="http://libosinfo.org/test/os/devices/removed/2"/>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-devices-removed-2.xml b/tests/dbdata/os/libosinfo.org/test-os-devices-removed-2.xml
new file mode 100644
index 0000000..1fd07c5
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-devices-removed-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/removed/2">
+    <short-id>devices-removed-2</short-id>
+    <name>Devices Removed 2</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <derives-from id="http://libosinfo.org/test/os/devices/removed/1"/>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-devices-removed-3.xml b/tests/dbdata/os/libosinfo.org/test-os-devices-removed-3.xml
new file mode 100644
index 0000000..1387469
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-devices-removed-3.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/os/devices/removed/3">
+    <short-id>devices-removed-3</short-id>
+    <name>Devices Removed 3</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <derives-from id="http://libosinfo.org/test/os/devices/removed/2"/>
+
+    <devices>
+      <device id="http://libosinfo.org/test/device/one"/>
+    </devices>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-devices-removed-4-clone.xml b/tests/dbdata/os/libosinfo.org/test-os-devices-removed-4-clone.xml
new file mode 100644
index 0000000..dab31f4
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-devices-removed-4-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/removed/4-clone">
+    <short-id>devices-removed-4-clone</short-id>
+    <name>Devices Removed 4 Clone</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <clones id="http://libosinfo.org/test/os/devices/removed/4"/>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-devices-removed-4.xml b/tests/dbdata/os/libosinfo.org/test-os-devices-removed-4.xml
new file mode 100644
index 0000000..19d5f48
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-devices-removed-4.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/removed/4">
+    <short-id>devices-removed-4</short-id>
+    <name>Devices Removed 4</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <derives-from id="http://libosinfo.org/test/os/devices/removed/3"/>
+  </os>
+</libosinfo>
diff --git a/tests/test-os.c b/tests/test-os.c
index 18c2829..06e793d 100644
--- a/tests/test-os.c
+++ b/tests/test-os.c
@@ -244,6 +244,115 @@ test_devices_inheritance_basic(void)
 }
 
 
+static void
+devices_inheritance_removal_check_devs(OsinfoDb *db,
+                                       const gchar *os_id,
+                                       gint all_devs_list_len,
+                                       gint dev_list_len,
+                                       gint all_devlinks_list_len,
+                                       gint devlink_list_len)
+{
+    OsinfoOs *os;
+    OsinfoDeviceLinkList *devlink_list, *all_devlinks_list;
+    OsinfoDeviceList *dev_list, *all_devs_list;
+
+    g_debug("Testing \"%s\"", os_id);
+
+    os = osinfo_db_get_os(db, os_id);
+    g_assert(OSINFO_IS_OS(os));
+
+    all_devs_list = osinfo_os_get_all_devices(os, NULL);
+    g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(all_devs_list)), ==, all_devs_list_len);
+    g_object_unref(all_devs_list);
+
+    dev_list = osinfo_os_get_devices(os, NULL);
+    g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(dev_list)), ==, dev_list_len);
+    g_object_unref(dev_list);
+
+    all_devlinks_list = osinfo_os_get_all_device_links(os, NULL);
+    g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(all_devlinks_list)), ==, all_devlinks_list_len);
+    g_object_unref(all_devlinks_list);
+
+    devlink_list = osinfo_os_get_device_links(os, NULL);
+    g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(devlink_list)), ==, devlink_list_len);
+    g_object_unref(devlink_list);
+}
+
+
+static void
+test_devices_inheritance_removal(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_removal_check_devs(db,
+                                           "http://libosinfo.org/test/os/devices/basic/1",
+                                           1, 1, 1, 1);
+
+    /*
+     * http://libosinfo.org/test/os/devices/removed/1 derives-from
+     * http://libosinfo.org/test/os/devices/basic/1 ...
+     * And the device is marked as removed
+     */
+    devices_inheritance_removal_check_devs(db,
+                                           "http://libosinfo.org/test/os/devices/removed/1",
+                                           0, 0, 0, 0);
+
+    /*
+     * http://libosinfo.org/test/os/devices/removed/2 derives-from
+     * http://libosinfo.org/test/os/devices/removed/1
+     */
+    devices_inheritance_removal_check_devs(db,
+                                           "http://libosinfo.org/test/os/devices/removed/2",
+                                           0, 0, 0, 0);
+
+    /*
+     * http://libosinfo.org/test/os/devices/removed/2-clone clones
+     * http://libosinfo.org/test/os/devices/removed/2
+     */
+    devices_inheritance_removal_check_devs(db,
+                                           "http://libosinfo.org/test/os/devices/removed/2-clone",
+                                           0, 0, 0, 0);
+
+    /*
+     * http://libosinfo.org/test/os/devices/removed/3 derives-from
+     * http://libosinfo.org/test/os/devices/removed/2
+     * And the device is not marked as removed anymore
+     */
+    devices_inheritance_removal_check_devs(db,
+                                           "http://libosinfo.org/test/os/devices/removed/3",
+                                           1, 1, 1, 1);
+
+    /*
+     * http://libosinfo.org/test/os/devices/removed/4 derives-from
+     * http://libosinfo.org/test/os/devices/removed/3
+     */
+    devices_inheritance_removal_check_devs(db,
+                                           "http://libosinfo.org/test/os/devices/removed/4",
+                                           1, 0, 1, 0);
+
+
+    /*
+     * http://libosinfo.org/test/os/devices/removed/4-clone clones
+     * http://libosinfo.org/test/os/devices/removed/4
+     */
+    devices_inheritance_removal_check_devs(db,
+                                           "http://libosinfo.org/test/os/devices/removed/4-clone",
+                                           1, 0, 1, 0);
+
+    g_object_unref(db);
+}
+
+
 int
 main(int argc, char *argv[])
 {
@@ -255,6 +364,7 @@ main(int argc, char *argv[])
     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);
+    g_test_add_func("/os/devices_inheritance/removal", test_devices_inheritance_removal);
 
     /* Upfront so we don't confuse valgrind */
     osinfo_platform_get_type();
-- 
2.19.1




More information about the Libosinfo mailing list