[Libosinfo] [libosinfo PATCH v2 5/8] test-db: Add test for guessing tree from OS

Fabiano Fidêncio fidencio at redhat.com
Thu Mar 28 21:26:11 UTC 2019


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

diff --git a/tests/dbdata/os/libosinfo.org/test-db-tree.xml b/tests/dbdata/os/libosinfo.org/test-db-tree.xml
new file mode 100644
index 0000000..420e8bb
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-db-tree.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/db/tree">
+    <short-id>db-tree</short-id>
+    <name>DB Tree</name>
+    <version>unknown</version>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+
+    <tree arch="all">
+      <treeinfo>
+        <family>Tree</family>
+        <version>unknown</version>
+      </treeinfo>
+    </tree>
+
+    <tree arch="i686">
+      <treeinfo>
+        <family>Tree</family>
+        <version>unknown</version>
+      </treeinfo>
+    </tree>
+
+  </os>
+</libosinfo>
diff --git a/tests/test-db.c b/tests/test-db.c
index a0fa490..d5e8b49 100644
--- a/tests/test-db.c
+++ b/tests/test-db.c
@@ -450,6 +450,57 @@ test_identify_media(void)
 }
 
 
+static OsinfoTree *
+create_tree(const gchar *arch)
+{
+    OsinfoTree *tree;
+
+    tree = osinfo_tree_new("foo", arch);
+    osinfo_entity_set_param(OSINFO_ENTITY(tree),
+                            OSINFO_TREE_PROP_TREEINFO_FAMILY,
+                            "Tree");
+    osinfo_entity_set_param(OSINFO_ENTITY(tree),
+                            OSINFO_TREE_PROP_TREEINFO_VERSION,
+                            "unknown");
+    return tree;
+}
+
+
+static void
+test_guess_os_from_tree(void)
+{
+    OsinfoLoader *loader = osinfo_loader_new();
+    OsinfoDb *db;
+    OsinfoTree *tree;
+    OsinfoTree *matched_tree = NULL;
+    OsinfoOs *os;
+
+    GError *error = NULL;
+
+    osinfo_loader_process_path(loader, SRCDIR "/tests/dbdata", &error);
+    g_assert_no_error(error);
+    db = osinfo_loader_get_db(loader);
+
+    /* Matching against an "all" architecture" */
+    tree = create_tree("x86_64");
+    os = osinfo_db_guess_os_from_tree(db, tree, &matched_tree);
+    g_assert_nonnull(os);
+    g_assert_nonnull(matched_tree);
+    g_assert_cmpstr(osinfo_tree_get_architecture(matched_tree), ==, "all");
+    g_object_unref(tree);
+    matched_tree = NULL;
+
+    /* Matching against a known architecture, which has to have precendence */
+    tree = create_tree("i686");
+    os = osinfo_db_guess_os_from_tree(db, tree, &matched_tree);
+    g_assert_nonnull(os);
+    g_assert_nonnull(matched_tree);
+    g_assert_cmpstr(osinfo_tree_get_architecture(matched_tree), ==, "i686");
+
+    g_object_unref(tree);
+    g_object_unref(loader);
+}
+
 
 int
 main(int argc, char *argv[])
@@ -465,6 +516,7 @@ main(int argc, char *argv[])
     g_test_add_func("/db/prop_os", test_prop_os);
     g_test_add_func("/db/rel_os", test_rel_os);
     g_test_add_func("/db/identify_media", test_identify_media);
+    g_test_add_func("/db/guess_os_from_tree", test_guess_os_from_tree);
 
     /* Upfront so we don't confuse valgrind */
     osinfo_entity_get_type();
@@ -480,6 +532,7 @@ main(int argc, char *argv[])
     osinfo_loader_get_type();
     osinfo_install_script_get_type();
     osinfo_install_scriptlist_get_type();
+    osinfo_tree_get_type();
 
     return g_test_run();
 }
-- 
2.20.1




More information about the Libosinfo mailing list