[libosinfo PATCH 2/2] tests: Add test-tree.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This test, at least for now, tests:
- The basic functionality of creating a OsinfoTree object;
- osinfo_tree_get_os_variants() API;

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

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 .gitignore                                  |  1 +
 tests/Makefile.am                           |  5 ++
 tests/dbdata/os/libosinfo.org/test-tree.xml | 28 +++++++
 tests/test-tree.c                           | 89 +++++++++++++++++++++
 4 files changed, 123 insertions(+)
 create mode 100644 tests/dbdata/os/libosinfo.org/test-tree.xml
 create mode 100644 tests/test-tree.c

diff --git a/.gitignore b/.gitignore
index 1e87ce7..fb80e9f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -68,6 +68,7 @@ tests/test-isodetect
 tests/test-mediauris
 tests/test-treeuris
 tests/test-imageuris
+tests/test-tree
 tests/*.log
 tests/*.trs
 build/
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2e92b48..bdd68d3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -20,6 +20,7 @@ check_PROGRAMS = \
 	test-install-script \
 	test-image \
 	test-imagelist \
+	test-tree \
         $(NULL)
 
 COMMON_LDADD = \
@@ -109,6 +110,10 @@ test_imagelist_LDADD = $(COMMON_LDADD)
 test_imagelist_CFLAGS = $(COMMON_CFLAGS)
 test_imagelist_SOURCES = test-imagelist.c
 
+test_tree_LDADD = $(COMMON_LDADD)
+test_tree_CFLAGS = $(COMMON_CFLAGS)
+test_tree_SOURCES = test-tree.c
+
 TESTS = $(check_PROGRAMS) \
 	$(NULL)
 
diff --git a/tests/dbdata/os/libosinfo.org/test-tree.xml b/tests/dbdata/os/libosinfo.org/test-tree.xml
new file mode 100644
index 0000000..6b2398a
--- /dev/null
+++ b/tests/dbdata/os/libosinfo.org/test-tree.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<libosinfo version="0.0.1">
+  <os id="http://libosinfo.org/test/tree";>
+    <short-id>db-tree</short-id>
+    <name>DB Tree</name>
+    <version>unknown</version>
+    <vendor>libosinfo.org</vendor>
+    <family>test</family>
+
+    <variant id="foo">
+      <name>DB Tree Foo</name>
+    </variant>
+    <variant id="bar">
+      <name>DB Tree Bar</name>
+    </variant>
+
+    <tree arch="ppc64le">
+      <variant id="bar"/>
+      <url>http://libosinfo.org/db/tree/</url>
+      <treeinfo>
+        <family>Tree</family>
+        <version>unknown</version>
+        <arch>ppc64le</arch>
+      </treeinfo>
+    </tree>
+
+  </os>
+</libosinfo>
diff --git a/tests/test-tree.c b/tests/test-tree.c
new file mode 100644
index 0000000..eeb1887
--- /dev/null
+++ b/tests/test-tree.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>
+ */
+
+#include <config.h>
+
+#include <osinfo/osinfo.h>
+
+
+static void
+test_basic(void)
+{
+    OsinfoTree *tree = osinfo_tree_new("foo", "x86_64");
+
+    g_assert_true(OSINFO_IS_TREE(tree));
+    g_assert_cmpstr((const char *)osinfo_entity_get_id(OSINFO_ENTITY(tree)), ==, "foo");
+    g_assert_cmpstr((const char *)osinfo_tree_get_architecture(tree), ==, "x86_64");
+
+    g_object_unref(tree);
+}
+
+static void
+test_os_variants(void)
+{
+    OsinfoLoader *loader = osinfo_loader_new();
+    OsinfoDb *db;
+    OsinfoOs *os;
+    OsinfoTree *tree;
+    OsinfoTreeList *list;
+    OsinfoOsVariant *variant;
+    OsinfoOsVariantList *variant_list;
+    gint list_len;
+    GError *error = NULL;
+
+    osinfo_loader_process_path(loader, SRCDIR "/tests/dbdata", &error);
+    g_assert_no_error(error);
+    db = osinfo_loader_get_db(loader);
+
+    os = osinfo_db_get_os(db, "http://libosinfo.org/test/tree";);
+
+    list = osinfo_os_get_tree_list(os);
+    list_len = osinfo_list_get_length(OSINFO_LIST(list));
+    g_assert_cmpint(list_len, ==, 1);
+
+    tree = OSINFO_TREE(osinfo_list_get_nth(OSINFO_LIST(list), 0));
+    variant_list = osinfo_tree_get_os_variants(tree);
+    list_len = osinfo_list_get_length(OSINFO_LIST(variant_list));
+    g_assert_cmpint(list_len, ==, 1);
+
+    variant = OSINFO_OS_VARIANT(osinfo_list_get_nth(OSINFO_LIST(variant_list), 0));
+    g_assert_cmpstr(osinfo_entity_get_id(OSINFO_ENTITY(variant)), ==, "bar");
+    g_assert_cmpstr(osinfo_os_variant_get_name(variant), ==, "DB Tree Bar");
+
+    g_object_unref(variant_list);
+    g_object_unref(list);
+    g_object_unref(loader);
+}
+
+int
+main(int argc, char *argv[])
+{
+    g_test_init(&argc, &argv, NULL);
+
+    g_test_add_func("/tree/basic", test_basic);
+    g_test_add_func("/tree/os-variants", test_os_variants);
+
+    /* Upfront so we don't confuse valgrind */
+    osinfo_tree_get_type();
+    osinfo_treelist_get_type();
+    osinfo_os_variantlist_get_type();
+    osinfo_loader_get_type();
+    osinfo_db_get_type();
+    osinfo_os_get_type();
+
+    return g_test_run();
+}
-- 
2.20.1

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux