summaryrefslogtreecommitdiffstats
path: root/lib/common/tests/results
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common/tests/results')
-rw-r--r--lib/common/tests/results/Makefile.am16
-rw-r--r--lib/common/tests/results/pcmk__results_test.c61
2 files changed, 77 insertions, 0 deletions
diff --git a/lib/common/tests/results/Makefile.am b/lib/common/tests/results/Makefile.am
new file mode 100644
index 0000000..8d51d12
--- /dev/null
+++ b/lib/common/tests/results/Makefile.am
@@ -0,0 +1,16 @@
+#
+# Copyright 2021-2022 the Pacemaker project contributors
+#
+# The version control history for this file may have further details.
+#
+# This source code is licensed under the GNU General Public License version 2
+# or later (GPLv2+) WITHOUT ANY WARRANTY.
+#
+
+include $(top_srcdir)/mk/tap.mk
+include $(top_srcdir)/mk/unittest.mk
+
+# Add "_test" to the end of all test program names to simplify .gitignore.
+check_PROGRAMS = pcmk__results_test
+
+TESTS = $(check_PROGRAMS)
diff --git a/lib/common/tests/results/pcmk__results_test.c b/lib/common/tests/results/pcmk__results_test.c
new file mode 100644
index 0000000..53665d1
--- /dev/null
+++ b/lib/common/tests/results/pcmk__results_test.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2020-2021 the Pacemaker project contributors
+ *
+ * The version control history for this file may have further details.
+ *
+ * This source code is licensed under the GNU General Public License version 2
+ * or later (GPLv2+) WITHOUT ANY WARRANTY.
+ */
+
+#include <crm_internal.h>
+
+#include <crm/common/unittest_internal.h>
+
+#include <glib.h>
+#include <bzlib.h>
+
+static void
+test_for_pcmk_rc_name(void **state) {
+ assert_string_equal(pcmk_rc_name(pcmk_rc_error-1), "pcmk_rc_unknown_format");
+ assert_string_equal(pcmk_rc_name(pcmk_rc_ok), "pcmk_rc_ok");
+ assert_string_equal(pcmk_rc_name(pcmk_rc_ok), "pcmk_rc_ok");
+ assert_string_equal(pcmk_rc_name(-7777777), "Unknown");
+}
+
+static void
+test_for_pcmk_rc_str(void **state) {
+ assert_string_equal(pcmk_rc_str(pcmk_rc_error-1), "Unknown output format");
+ assert_string_equal(pcmk_rc_str(pcmk_rc_ok), "OK");
+ assert_string_equal(pcmk_rc_str(-1), "Error");
+}
+
+static void
+test_for_crm_exit_name(void **state) {
+ assert_string_equal(crm_exit_name(CRM_EX_OK), "CRM_EX_OK");
+}
+
+static void
+test_for_crm_exit_str(void **state) {
+ assert_string_equal(crm_exit_str(CRM_EX_OK), "OK");
+ assert_string_equal(crm_exit_str(129), "Interrupted by signal");
+ assert_string_equal(crm_exit_str(-7777777), "Unknown exit status");
+}
+
+static void
+test_for_pcmk_rc2exitc(void **state) {
+ assert_int_equal(pcmk_rc2exitc(pcmk_rc_ok), CRM_EX_OK);
+ assert_int_equal(pcmk_rc2exitc(-7777777), CRM_EX_ERROR);
+}
+
+static void
+test_for_bz2_strerror(void **state) {
+ assert_string_equal(bz2_strerror(BZ_STREAM_END), "Ok");
+}
+
+PCMK__UNIT_TEST(NULL, NULL,
+ cmocka_unit_test(test_for_pcmk_rc_name),
+ cmocka_unit_test(test_for_pcmk_rc_str),
+ cmocka_unit_test(test_for_crm_exit_name),
+ cmocka_unit_test(test_for_crm_exit_str),
+ cmocka_unit_test(test_for_pcmk_rc2exitc),
+ cmocka_unit_test(test_for_bz2_strerror))