pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
crm_is_true_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 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 General Public License version 2
7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
13 
14 static void
15 bad_input(void **state) {
16  assert_false(crm_is_true(NULL));
17 }
18 
19 static void
20 is_true(void **state) {
21  assert_true(crm_is_true("true"));
22  assert_true(crm_is_true("TrUe"));
23  assert_true(crm_is_true("on"));
24  assert_true(crm_is_true("ON"));
25  assert_true(crm_is_true("yes"));
26  assert_true(crm_is_true("yES"));
27  assert_true(crm_is_true("y"));
28  assert_true(crm_is_true("Y"));
29  assert_true(crm_is_true("1"));
30 }
31 
32 static void
33 is_false(void **state) {
34  assert_false(crm_is_true("false"));
35  assert_false(crm_is_true("fAlSe"));
36  assert_false(crm_is_true("off"));
37  assert_false(crm_is_true("OFF"));
38  assert_false(crm_is_true("no"));
39  assert_false(crm_is_true("No"));
40  assert_false(crm_is_true("n"));
41  assert_false(crm_is_true("N"));
42  assert_false(crm_is_true("0"));
43 
44  assert_false(crm_is_true(""));
45  assert_false(crm_is_true("blahblah"));
46 
47  assert_false(crm_is_true("truedat"));
48  assert_false(crm_is_true("onnn"));
49  assert_false(crm_is_true("yep"));
50  assert_false(crm_is_true("Y!"));
51  assert_false(crm_is_true("100"));
52 }
53 
54 PCMK__UNIT_TEST(NULL, NULL,
55  cmocka_unit_test(bad_input),
56  cmocka_unit_test(is_true),
57  cmocka_unit_test(is_false))
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
gboolean crm_is_true(const char *s)
Definition: strings.c:488