[libosinfo PATCH 23/31] tests: Add basic tests for FeatureLinkList

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

 



Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 .gitignore                   |   1 +
 tests/Makefile.am            |   5 +
 tests/test-featurelinklist.c | 317 +++++++++++++++++++++++++++++++++++
 3 files changed, 323 insertions(+)
 create mode 100644 tests/test-featurelinklist.c

diff --git a/.gitignore b/.gitignore
index 64c9111..6ff3b56 100644
--- a/.gitignore
+++ b/.gitignore
@@ -59,6 +59,7 @@ tests/test-devicelist
 tests/test-devicelinklist
 tests/test-feature
 tests/test-featurelink
+tests/test-featurelinklist
 tests/test-featurelist
 tests/test-filter
 tests/test-hypervisorlist
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9c6db9b..11d9609 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -12,6 +12,7 @@ check_PROGRAMS = \
 	test-devicelinklist \
 	test-feature \
 	test-featurelink \
+	test-featurelinklist \
 	test-featurelist \
 	test-filter \
 	test-product \
@@ -68,6 +69,10 @@ test_featurelink_LDADD = $(COMMON_LDADD)
 test_featurelink_CFLAGS = $(COMMON_CFLAGS)
 test_featurelink_SOURCES = test-featurelink.c
 
+test_featurelinklist_LDADD = $(COMMON_LDADD)
+test_featurelinklist_CFLAGS = $(COMMON_CFLAGS)
+test_featurelinklist_SOURCES = test-featurelinklist.c
+
 test_featurelist_LDADD = $(COMMON_LDADD)
 test_featurelist_CFLAGS = $(COMMON_CFLAGS)
 test_featurelist_SOURCES = test-featurelist.c
diff --git a/tests/test-featurelinklist.c b/tests/test-featurelinklist.c
new file mode 100644
index 0000000..5f4d817
--- /dev/null
+++ b/tests/test-featurelinklist.c
@@ -0,0 +1,317 @@
+/*
+ * Copyright (C) 2018 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/>
+ *
+ * Authors:
+ *   Fabiano Fidêncio <fidencio@xxxxxxxxxx>
+ */
+
+#include <config.h>
+
+#include <osinfo/osinfo.h>
+
+
+static void
+test_union(void)
+{
+    OsinfoFeatureLinkList *list1 = osinfo_featurelinklist_new();
+    OsinfoFeatureLinkList *list2 = osinfo_featurelinklist_new();
+    OsinfoFeatureLinkList *list3;
+    OsinfoFeature *dev1 = osinfo_feature_new("wibble1");
+    OsinfoFeature *dev2 = osinfo_feature_new("wibble2");
+    OsinfoFeature *dev3 = osinfo_feature_new("wibble3");
+    OsinfoFeature *dev4 = osinfo_feature_new("wibble4");
+    OsinfoFeatureLink *ent1 = osinfo_featurelink_new(dev1);
+    OsinfoFeatureLink *ent2 = osinfo_featurelink_new(dev2);
+    OsinfoFeatureLink *ent3 = osinfo_featurelink_new(dev3);
+    OsinfoFeatureLink *ent4 = osinfo_featurelink_new(dev4);
+
+    osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent1));
+    osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent2));
+    osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent3));
+
+    osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent1));
+    osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent4));
+
+    list3 = OSINFO_FEATURELINKLIST(osinfo_list_new_union(OSINFO_LIST(list1), OSINFO_LIST(list2)));
+
+    g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(list3)), ==, 4);
+
+    gboolean has1 = FALSE;
+    gboolean has2 = FALSE;
+    gboolean has3 = FALSE;
+    gboolean has4 = FALSE;
+    gboolean hasBad = FALSE;
+    int i;
+    for (i = 0; i < osinfo_list_get_length(OSINFO_LIST(list3)); i++) {
+        OsinfoFeatureLink *ent = OSINFO_FEATURELINK(osinfo_list_get_nth(OSINFO_LIST(list3), i));
+        if (ent == ent1)
+            has1 = TRUE;
+        else if (ent == ent2)
+            has2 = TRUE;
+        else if (ent == ent3)
+            has3 = TRUE;
+        else if (ent == ent4)
+            has4 = TRUE;
+        else
+            hasBad = TRUE;
+    }
+    g_assert_true(has1);
+    g_assert_true(has2);
+    g_assert_true(has3);
+    g_assert_true(has4);
+    g_assert_false(hasBad);
+
+    g_object_unref(dev1);
+    g_object_unref(dev2);
+    g_object_unref(dev3);
+    g_object_unref(dev4);
+    g_object_unref(ent1);
+    g_object_unref(ent2);
+    g_object_unref(ent3);
+    g_object_unref(ent4);
+    g_object_unref(list1);
+    g_object_unref(list2);
+    g_object_unref(list3);
+}
+
+
+static void
+test_intersect(void)
+{
+    OsinfoFeatureLinkList *list1 = osinfo_featurelinklist_new();
+    OsinfoFeatureLinkList *list2 = osinfo_featurelinklist_new();
+    OsinfoFeatureLinkList *list3;
+    OsinfoFeature *dev1 = osinfo_feature_new("wibble1");
+    OsinfoFeature *dev2 = osinfo_feature_new("wibble2");
+    OsinfoFeature *dev3 = osinfo_feature_new("wibble3");
+    OsinfoFeature *dev4 = osinfo_feature_new("wibble4");
+    OsinfoFeatureLink *ent1 = osinfo_featurelink_new(dev1);
+    OsinfoFeatureLink *ent2 = osinfo_featurelink_new(dev2);
+    OsinfoFeatureLink *ent3 = osinfo_featurelink_new(dev3);
+    OsinfoFeatureLink *ent4 = osinfo_featurelink_new(dev4);
+
+    osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent1));
+    osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent2));
+    osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent3));
+
+    osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent1));
+    osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent3));
+    osinfo_list_add(OSINFO_LIST(list2), OSINFO_ENTITY(ent4));
+
+    list3 = OSINFO_FEATURELINKLIST(osinfo_list_new_intersection(OSINFO_LIST(list1), OSINFO_LIST(list2)));
+
+    g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(list3)), ==, 2);
+
+    gboolean has1 = FALSE;
+    gboolean has2 = FALSE;
+    gboolean has3 = FALSE;
+    gboolean has4 = FALSE;
+    gboolean hasBad = FALSE;
+    int i;
+    for (i = 0; i < osinfo_list_get_length(OSINFO_LIST(list3)); i++) {
+        OsinfoFeatureLink *ent = OSINFO_FEATURELINK(osinfo_list_get_nth(OSINFO_LIST(list3), i));
+        if (ent == ent1)
+            has1 = TRUE;
+        else if (ent == ent2)
+            has2 = TRUE;
+        else if (ent == ent3)
+            has3 = TRUE;
+        else if (ent == ent4)
+            has4 = TRUE;
+        else
+            hasBad = TRUE;
+    }
+    g_assert_true(has1);
+    g_assert_false(has2);
+    g_assert_true(has3);
+    g_assert_false(has4);
+    g_assert_false(hasBad);
+
+    g_object_unref(dev1);
+    g_object_unref(dev2);
+    g_object_unref(dev3);
+    g_object_unref(dev4);
+    g_object_unref(ent1);
+    g_object_unref(ent2);
+    g_object_unref(ent3);
+    g_object_unref(ent4);
+    g_object_unref(list1);
+    g_object_unref(list2);
+    g_object_unref(list3);
+}
+
+
+static void
+test_filter(void)
+{
+    OsinfoFeatureLinkList *list1 = osinfo_featurelinklist_new();
+    OsinfoFeatureLinkList *list2;
+    OsinfoFilter *filter = osinfo_filter_new();
+    OsinfoFeature *dev1 = osinfo_feature_new("wibble1");
+    OsinfoFeature *dev2 = osinfo_feature_new("wibble2");
+    OsinfoFeature *dev3 = osinfo_feature_new("wibble3");
+    OsinfoFeature *dev4 = osinfo_feature_new("wibble4");
+    OsinfoFeatureLink *ent1 = osinfo_featurelink_new(dev1);
+    OsinfoFeatureLink *ent2 = osinfo_featurelink_new(dev2);
+    OsinfoFeatureLink *ent3 = osinfo_featurelink_new(dev3);
+    OsinfoFeatureLink *ent4 = osinfo_featurelink_new(dev4);
+
+    osinfo_entity_add_param(OSINFO_ENTITY(ent1), "class", "network");
+    osinfo_entity_add_param(OSINFO_ENTITY(ent1), "class", "wilma");
+    osinfo_entity_add_param(OSINFO_ENTITY(ent2), "class", "network");
+    osinfo_entity_add_param(OSINFO_ENTITY(ent3), "class", "network");
+    osinfo_entity_add_param(OSINFO_ENTITY(ent3), "class", "audio");
+    osinfo_entity_add_param(OSINFO_ENTITY(ent4), "class", "audio");
+
+    osinfo_filter_add_constraint(filter, "class", "network");
+
+    osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent1));
+    osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent2));
+    osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent3));
+    osinfo_list_add(OSINFO_LIST(list1), OSINFO_ENTITY(ent4));
+
+    list2 = OSINFO_FEATURELINKLIST(osinfo_list_new_filtered(OSINFO_LIST(list1), filter));
+
+    g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(list2)), ==, 3);
+
+    gboolean has1 = FALSE;
+    gboolean has2 = FALSE;
+    gboolean has3 = FALSE;
+    gboolean has4 = FALSE;
+    gboolean hasBad = FALSE;
+    int i;
+    for (i = 0; i < osinfo_list_get_length(OSINFO_LIST(list2)); i++) {
+        OsinfoFeatureLink *ent = OSINFO_FEATURELINK(osinfo_list_get_nth(OSINFO_LIST(list2), i));
+        if (ent == ent1)
+            has1 = TRUE;
+        else if (ent == ent2)
+            has2 = TRUE;
+        else if (ent == ent3)
+            has3 = TRUE;
+        else if (ent == ent4)
+            has4 = TRUE;
+        else
+            hasBad = TRUE;
+    }
+    g_assert_true(has1);
+    g_assert_true(has2);
+    g_assert_true(has3);
+    g_assert_false(has4);
+    g_assert_false(hasBad);
+
+    g_object_unref(dev1);
+    g_object_unref(dev2);
+    g_object_unref(dev3);
+    g_object_unref(dev4);
+    g_object_unref(ent1);
+    g_object_unref(ent2);
+    g_object_unref(ent3);
+    g_object_unref(ent4);
+    g_object_unref(filter);
+    g_object_unref(list1);
+    g_object_unref(list2);
+}
+
+
+static void
+test_get_features(void)
+{
+    OsinfoFeatureLinkList *devlink_list = osinfo_featurelinklist_new();
+    OsinfoFeature *dev1 = osinfo_feature_new("wibble1");
+    OsinfoFeature *dev2 = osinfo_feature_new("wibble2");
+    OsinfoFeature *dev3 = osinfo_feature_new("wibble3");
+    OsinfoFeature *dev4 = osinfo_feature_new("wibble4");
+    OsinfoFeatureLink *ent1 = osinfo_featurelink_new(dev1);
+    OsinfoFeatureLink *ent2 = osinfo_featurelink_new(dev2);
+    OsinfoFeatureLink *ent3 = osinfo_featurelink_new(dev3);
+    OsinfoFeatureLink *ent4 = osinfo_featurelink_new(dev4);
+    OsinfoFeatureList *dev_list;
+
+    osinfo_list_add(OSINFO_LIST(devlink_list), OSINFO_ENTITY(ent1));
+    osinfo_list_add(OSINFO_LIST(devlink_list), OSINFO_ENTITY(ent2));
+    osinfo_list_add(OSINFO_LIST(devlink_list), OSINFO_ENTITY(ent3));
+    osinfo_list_add(OSINFO_LIST(devlink_list), OSINFO_ENTITY(ent4));
+    g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(devlink_list)), ==, 4);
+
+    dev_list = osinfo_featurelist_new();
+    osinfo_linklist_get_targets(OSINFO_LINKLIST(devlink_list),
+                                NULL,
+                                OSINFO_LIST(dev_list));
+    g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(dev_list)), ==, 4);
+
+    gboolean has1 = FALSE;
+    gboolean has2 = FALSE;
+    gboolean has3 = FALSE;
+    gboolean has4 = FALSE;
+    gboolean hasBad = FALSE;
+    int i;
+    for (i = 0; i < osinfo_list_get_length(OSINFO_LIST(dev_list)); i++) {
+        OsinfoFeature *dev = OSINFO_FEATURE(osinfo_list_get_nth(OSINFO_LIST(dev_list), i));
+        if (dev == dev1)
+            has1 = TRUE;
+        else if (dev == dev2)
+            has2 = TRUE;
+        else if (dev == dev3)
+            has3 = TRUE;
+        else if (dev == dev4)
+            has4 = TRUE;
+        else
+            hasBad = TRUE;
+    }
+    g_assert_true(has1);
+    g_assert_true(has2);
+    g_assert_true(has3);
+    g_assert_true(has4);
+    g_assert_false(hasBad);
+
+    g_object_unref(dev1);
+    g_object_unref(dev2);
+    g_object_unref(dev3);
+    g_object_unref(dev4);
+    g_object_unref(ent1);
+    g_object_unref(ent2);
+    g_object_unref(ent3);
+    g_object_unref(ent4);
+    g_object_unref(dev_list);
+    g_object_unref(devlink_list);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+    g_test_init(&argc, &argv, NULL);
+
+    g_test_add_func("/featurelinklist/union", test_union);
+    g_test_add_func("/featurelinklist/intersect", test_intersect);
+    g_test_add_func("/featurelinklist/filter", test_filter);
+    g_test_add_func("/featurelinklist/get_features", test_get_features);
+
+    /* Upfront so we don't confuse valgrind */
+    osinfo_feature_get_type();
+    osinfo_featurelist_get_type();
+    osinfo_filter_get_type();
+    osinfo_linklist_get_type();
+
+    return g_test_run();
+}
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
-- 
2.19.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