[Libosinfo] [libosinfo PATCH 2/2] tests: Add tests for multiple short-ids

Fabiano Fidêncio fidencio at redhat.com
Mon Apr 29 08:51:40 UTC 2019


I've decided to for testing the multiple short-ids in the os level, as
it's reflects better the usage of the newly added APIs.

https://gitlab.com/libosinfo/libosinfo/issues/19

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 .../test-os-multipleshortids.xml              | 13 ++++++++
 tests/test-os.c                               | 32 +++++++++++++++++++
 2 files changed, 45 insertions(+)
 create mode 100644 tests/dbdata/os/libosinfo.org/test-os-multipleshortids.xml

diff --git a/tests/dbdata/os/libosinfo.org/test-os-multipleshortids.xml b/tests/dbdata/os/libosinfo.org/test-os-multipleshortids.xml
new file mode 100644
index 0000000..ccc2b54
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-os-multipleshortids.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/os/multipleshortids">
+    <short-id>shortid0</short-id>
+    <short-id>shortid1</short-id>
+    <short-id>shortid2</short-id>
+    <name>Multiple Short Ids</name>
+    <version>unknown</version>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+    <release-status>prerelease</release-status>
+  </os>
+</libosinfo>
diff --git a/tests/test-os.c b/tests/test-os.c
index b8b0a16..fe7c2d6 100644
--- a/tests/test-os.c
+++ b/tests/test-os.c
@@ -619,6 +619,37 @@ test_find_install_script(void)
     g_object_unref(os);
 }
 
+static void
+test_multiple_short_ids(void)
+{
+    OsinfoLoader *loader = osinfo_loader_new();
+    OsinfoDb *db;
+    OsinfoOs *os;
+    GList *shortid_list, *l;
+    GError *error = NULL;
+    const gchar *shortid;
+    const gchar *expected_short_id_list[] = {"shortid0", "shortid1", "shortid2"};
+    gsize i;
+
+    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);
+
+    os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/multipleshortids");
+    g_assert(OSINFO_IS_OS(os));
+
+    shortid = osinfo_product_get_short_id(OSINFO_PRODUCT(os));
+    g_assert_cmpstr(shortid, ==, expected_short_id_list[0]);
+
+    shortid_list = osinfo_product_get_short_id_list(OSINFO_PRODUCT(os));
+    for (l = shortid_list, i = 0; l != NULL; l = l->next, i++) {
+        g_assert_cmpstr(l->data, ==, expected_short_id_list[i]);
+    }
+    g_list_free(shortid_list);
+
+    g_object_unref(db);
+}
 
 int
 main(int argc, char *argv[])
@@ -638,6 +669,7 @@ main(int argc, char *argv[])
     g_test_add_func("/os/resources/basic", test_resources_basic);
     g_test_add_func("/os/resources/inheritance", test_resources_inheritance);
     g_test_add_func("/os/find_install_script", test_find_install_script);
+    g_test_add_func("/os/mulitple_short_ids", test_multiple_short_ids);
 
     /* Upfront so we don't confuse valgrind */
     osinfo_platform_get_type();
-- 
2.21.0




More information about the Libosinfo mailing list