[Libosinfo] [libosinfo PATCH 09/18] test-os: Add test_devices_inheritance_deprecation()

Fabiano Fidêncio fidencio at redhat.com
Thu Nov 8 06:55:28 UTC 2018


Now that OsinfoOs can deal with the concept of a "deprecated" 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-deprecated-1.xml          | 14 +++
 .../test-os-devices-deprecated-2-clone.xml    | 10 ++
 .../test-os-devices-deprecated-2.xml          | 10 ++
 .../test-os-devices-deprecated-3.xml          | 14 +++
 .../test-os-devices-deprecated-4-clone.xml    | 10 ++
 .../test-os-devices-deprecated-4.xml          | 10 ++
 tests/test-os.c                               | 99 +++++++++++++++++++
 7 files changed, 167 insertions(+)
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-1.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-2-clone.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-2.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-3.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-4-clone.xml
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-4.xml

diff --git a/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-1.xml b/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-1.xml
new file mode 100644
index 0000000..624b5af
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-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/deprecated/1">
+    <short-id>devices-deprecated-1</short-id>
+    <name>Devices Deprecated 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" deprecated="true"/>
+    </devices>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-2-clone.xml b/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-2-clone.xml
new file mode 100644
index 0000000..19ae831
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-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/deprecated/2-clone">
+    <short-id>devices-deprecated-2-clone</short-id>
+    <name>Devices Deprecated 2 Clone</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <clones id="http://libosinfo.org/test/os/devices/deprecated/2"/>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-2.xml b/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-2.xml
new file mode 100644
index 0000000..dd0d8b1
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-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/deprecated/2">
+    <short-id>devices-deprecated-2</short-id>
+    <name>Devices Deprecated 2</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <derives-from id="http://libosinfo.org/test/os/devices/deprecated/1"/>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-3.xml b/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-3.xml
new file mode 100644
index 0000000..7f9a33a
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-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/deprecated/3">
+    <short-id>devices-deprecated-3</short-id>
+    <name>Devices Deprecated 3</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <derives-from id="http://libosinfo.org/test/os/devices/deprecated/2"/>
+
+    <devices>
+      <device id="http://libosinfo.org/test/device/one"/>
+    </devices>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-4-clone.xml b/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-4-clone.xml
new file mode 100644
index 0000000..cdfe980
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-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/deprecated/4-clone">
+    <short-id>devices-deprecated-4</short-id>
+    <name>Devices Deprecated 4</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <clones id="http://libosinfo.org/test/os/devices/deprecated/4"/>
+  </os>
+</libosinfo>
diff --git a/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-4.xml b/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-4.xml
new file mode 100644
index 0000000..bb51d71
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-devices-deprecated-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/deprecated/4">
+    <short-id>devices-deprecated-4</short-id>
+    <name>Devices Deprecated 4</name>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <derives-from id="http://libosinfo.org/test/os/devices/deprecated/3"/>
+  </os>
+</libosinfo>
diff --git a/tests/test-os.c b/tests/test-os.c
index 18c2829..87a0a8a 100644
--- a/tests/test-os.c
+++ b/tests/test-os.c
@@ -244,6 +244,104 @@ test_devices_inheritance_basic(void)
 }
 
 
+static void
+devices_inheritance_depreaction_check(OsinfoDb *db,
+                                      const gchar *os_id,
+                                      gboolean deprecated)
+{
+    OsinfoOs *os;
+    OsinfoDeviceList *all_devs_list;
+    OsinfoDevice *dev;
+
+    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)), ==, 1);
+
+    dev = OSINFO_DEVICE(osinfo_list_get_nth(OSINFO_LIST(all_devs_list), 0));
+    g_assert(OSINFO_IS_DEVICE(dev));
+
+    g_assert_true(osinfo_os_is_device_deprecated(os, dev) == deprecated);
+}
+
+
+static void
+test_devices_inheritance_deprecation(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_depreaction_check(db,
+                                          "http://libosinfo.org/test/os/devices/basic/1",
+                                          FALSE);
+
+    /*
+     * "http://libosinfo.org/test/os/devices/deprecated/1" derives-from
+     * "http://libosinfo.org/test/os/devices/basic/1" ...
+     * And the device is marked as deprecated
+     */
+    devices_inheritance_depreaction_check(db,
+                                          "http://libosinfo.org/test/os/devices/deprecated/1",
+                                          TRUE);
+
+    /*
+     * http://libosinfo.org/test/os/devices/deprecated/2 derives-from
+     * http://libosinfo.org/test/os/devices/deprecated/1
+     */
+    devices_inheritance_depreaction_check(db,
+                                          "http://libosinfo.org/test/os/devices/deprecated/2",
+                                          TRUE);
+
+    /*
+     * http://libosinfo.org/test/os/devices/deprecated/2-clone clones
+     * http://libosinfo.org/test/os/devices/deprecated/2
+     */
+    devices_inheritance_depreaction_check(db,
+                                          "http://libosinfo.org/test/os/devices/deprecated/2-clone",
+                                          TRUE);
+
+    /*
+     * http://libosinfo.org/test/os/devices/deprecated/3 derives-from
+     * http://libosinfo.org/test/os/devices/deprecated/2 ...
+     * And the device is not marked as deprecated anymore
+     */
+    devices_inheritance_depreaction_check(db,
+                                          "http://libosinfo.org/test/os/devices/deprecated/3",
+                                          FALSE);
+
+
+    /*
+     * http://libosinfo.org/test/os/devices/deprecated/4 derives-from
+     * http://libosinfo.org/test/os/devices/deprecated/3
+     */
+    devices_inheritance_depreaction_check(db,
+                                          "http://libosinfo.org/test/os/devices/deprecated/4",
+                                          FALSE);
+
+    /*
+     * http://libosinfo.org/test/os/devices/deprecated/4-clone clones
+     * http://libosinfo.org/test/os/devices/deprecated/4
+     */
+    devices_inheritance_depreaction_check(db,
+                                          "http://libosinfo.org/test/os/devices/deprecated/4-clone",
+                                          FALSE);
+
+    g_object_unref(db);
+}
+
+
 int
 main(int argc, char *argv[])
 {
@@ -255,6 +353,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/deprecation", test_devices_inheritance_deprecation);
 
     /* Upfront so we don't confuse valgrind */
     osinfo_platform_get_type();
-- 
2.19.1




More information about the Libosinfo mailing list