summaryrefslogtreecommitdiffstats
path: root/lib/common/tests/results/pcmk__results_test.c
blob: 016eb7fecb2e048be70dab27c6d3b5578ef701ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * 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);
}

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))