root/lib/common/tests/strings/crm_is_true_test.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. bad_input
  2. is_true
  3. is_false
  4. main

   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 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 static void
  19 bad_input(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  20     assert_false(crm_is_true(NULL));
  21 }
  22 
  23 static void
  24 is_true(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  25     assert_true(crm_is_true("true"));
  26     assert_true(crm_is_true("TrUe"));
  27     assert_true(crm_is_true("on"));
  28     assert_true(crm_is_true("ON"));
  29     assert_true(crm_is_true("yes"));
  30     assert_true(crm_is_true("yES"));
  31     assert_true(crm_is_true("y"));
  32     assert_true(crm_is_true("Y"));
  33     assert_true(crm_is_true("1"));
  34 }
  35 
  36 static void
  37 is_false(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  38     assert_false(crm_is_true("false"));
  39     assert_false(crm_is_true("fAlSe"));
  40     assert_false(crm_is_true("off"));
  41     assert_false(crm_is_true("OFF"));
  42     assert_false(crm_is_true("no"));
  43     assert_false(crm_is_true("No"));
  44     assert_false(crm_is_true("n"));
  45     assert_false(crm_is_true("N"));
  46     assert_false(crm_is_true("0"));
  47 
  48     assert_false(crm_is_true(""));
  49     assert_false(crm_is_true("blahblah"));
  50 
  51     assert_false(crm_is_true("truedat"));
  52     assert_false(crm_is_true("onnn"));
  53     assert_false(crm_is_true("yep"));
  54     assert_false(crm_is_true("Y!"));
  55     assert_false(crm_is_true("100"));
  56 }
  57 
  58 int
  59 main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
  60 {
  61     const struct CMUnitTest tests[] = {
  62         cmocka_unit_test(bad_input),
  63         cmocka_unit_test(is_true),
  64         cmocka_unit_test(is_false),
  65     };
  66 
  67     cmocka_set_message_output(CM_OUTPUT_TAP);
  68     return cmocka_run_group_tests(tests, NULL, NULL);
  69 }

/* [previous][next][first][last][top][bottom][index][help] */