[libosinfo PATCH v3 03/12] tests: Add basic test for OsinfoFeature

[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-feature.c | 68 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+)
 create mode 100644 tests/test-feature.c

diff --git a/.gitignore b/.gitignore
index b888b50..524d9a1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -54,6 +54,7 @@ tests/test-list
 tests/test-db
 tests/test-devicelist
 tests/test-devicelinklist
+tests/test-feature
 tests/test-filter
 tests/test-hypervisorlist
 tests/test-install-script
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 45703df..6f3cdb4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -7,6 +7,7 @@ check_PROGRAMS = \
 	test-list \
 	test-devicelist \
 	test-devicelinklist \
+	test-feature \
 	test-filter \
 	test-media \
 	test-product \
@@ -54,6 +55,10 @@ test_device_LDADD = $(COMMON_LDADD)
 test_device_CFLAGS = $(COMMON_CFLAGS)
 test_device_SOURCES = test-device.c
 
+test_feature_LDADD = $(COMMON_LDADD)
+test_feature_CFLAGS = $(COMMON_CFLAGS)
+test_feature_SOURCES = test-feature.c
+
 test_filter_LDADD = $(COMMON_LDADD)
 test_filter_CFLAGS = $(COMMON_CFLAGS)
 test_filter_SOURCES = test-filter.c
diff --git a/tests/test-feature.c b/tests/test-feature.c
new file mode 100644
index 0000000..1a02a72
--- /dev/null
+++ b/tests/test-feature.c
@@ -0,0 +1,68 @@
+/*
+ * 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/>
+ */
+
+#include <config.h>
+
+#include <osinfo/osinfo.h>
+#include "osinfo/osinfo_feature_private.h"
+
+
+static void
+test_basic(void)
+{
+    OsinfoFeature *feature;
+
+    feature = osinfo_feature_new("feature:0", "cpu-hotplug", "x86_64");
+    g_assert_true(OSINFO_IS_FEATURE(feature));
+    g_assert_cmpstr(osinfo_entity_get_id(OSINFO_ENTITY(feature)), ==, "feature:0");
+    g_assert_cmpstr(osinfo_feature_get_name(feature), ==, "cpu-hotplug");
+    g_assert_cmpstr(osinfo_feature_get_architecture(feature), ==, "x86_64");
+    g_assert_cmpint(osinfo_feature_get_state(feature), ==, OSINFO_FEATURE_STATE_ABSENT);
+    g_assert_true(osinfo_feature_get_supported(feature));
+    osinfo_feature_set_supported(feature, FALSE);
+    g_assert_false(osinfo_feature_get_supported(feature));
+
+    g_object_unref(feature);
+
+    feature = osinfo_feature_new("feature:1", "hyperv-relaxed", "x86_64");
+    g_assert_true(OSINFO_IS_FEATURE(feature));
+    osinfo_feature_set_state(feature, OSINFO_FEATURE_STATE_ON);
+    g_assert_cmpint(osinfo_feature_get_state(feature), ==, OSINFO_FEATURE_STATE_ON);
+
+    g_object_unref(feature);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+    g_test_init(&argc, &argv, NULL);
+
+    g_test_add_func("/feature/basic", test_basic);
+
+    /* Upfront so we don't confuse valgrind */
+    osinfo_feature_get_type();
+
+    return g_test_run();
+}
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
-- 
2.19.2

_______________________________________________
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