pacemaker  2.1.4-dc6eb4362
Scalable High-Availability cluster resource manager
pcmk__results_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2020-2021 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
12 #include <stdarg.h>
13 #include <stddef.h>
14 #include <stdint.h>
15 #include <setjmp.h>
16 #include <cmocka.h>
17 
18 #include <glib.h>
19 #include <bzlib.h>
20 
21 static void
22 test_for_pcmk_rc_name(void **state) {
23  assert_string_equal(pcmk_rc_name(pcmk_rc_error-1), "pcmk_rc_unknown_format");
24  assert_string_equal(pcmk_rc_name(pcmk_rc_ok), "pcmk_rc_ok");
25  assert_string_equal(pcmk_rc_name(pcmk_rc_ok), "pcmk_rc_ok");
26  assert_string_equal(pcmk_rc_name(-7777777), "Unknown");
27 }
28 
29 static void
30 test_for_pcmk_rc_str(void **state) {
31  assert_string_equal(pcmk_rc_str(pcmk_rc_error-1), "Unknown output format");
32  assert_string_equal(pcmk_rc_str(pcmk_rc_ok), "OK");
33  assert_string_equal(pcmk_rc_str(-1), "Error");
34 }
35 
36 static void
37 test_for_crm_exit_name(void **state) {
38  assert_string_equal(crm_exit_name(CRM_EX_OK), "CRM_EX_OK");
39 }
40 
41 static void
42 test_for_crm_exit_str(void **state) {
43  assert_string_equal(crm_exit_str(CRM_EX_OK), "OK");
44  assert_string_equal(crm_exit_str(129), "Interrupted by signal");
45  assert_string_equal(crm_exit_str(-7777777), "Unknown exit status");
46 }
47 
48 static void
49 test_for_pcmk_rc2exitc(void **state) {
50  assert_int_equal(pcmk_rc2exitc(pcmk_rc_ok), CRM_EX_OK);
51  assert_int_equal(pcmk_rc2exitc(-7777777), CRM_EX_ERROR);
52 }
53 
54 static void
55 test_for_bz2_strerror(void **state) {
56  assert_string_equal(bz2_strerror(BZ_STREAM_END), "Ok");
57 }
58 
59 int main(int argc, char **argv) {
60  const struct CMUnitTest tests[] = {
61  cmocka_unit_test(test_for_pcmk_rc_name),
62  cmocka_unit_test(test_for_pcmk_rc_str),
63  cmocka_unit_test(test_for_crm_exit_name),
64  cmocka_unit_test(test_for_crm_exit_str),
65  cmocka_unit_test(test_for_pcmk_rc2exitc),
66  cmocka_unit_test(test_for_bz2_strerror),
67  };
68 
69  cmocka_set_message_output(CM_OUTPUT_TAP);
70  return cmocka_run_group_tests(tests, NULL, NULL);
71 }
const char * bz2_strerror(int rc)
Definition: results.c:742
crm_exit_t pcmk_rc2exitc(int rc)
Map a function return code to the most similar exit code.
Definition: results.c:602
Unspecified error.
Definition: results.h:240
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
Definition: results.c:370
int main(int argc, char **argv)
const char * crm_exit_str(crm_exit_t exit_code)
Definition: results.c:506
Success.
Definition: results.h:239
const char * pcmk_rc_name(int rc)
Get a return code constant name as a string.
Definition: results.c:210
const char * crm_exit_name(crm_exit_t exit_code)
Definition: results.c:457