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

   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 <crm/common/unittest_internal.h>
  13 
  14 static void
  15 bad_input(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  16     assert_false(crm_is_true(NULL));
  17 }
  18 
  19 static void
  20 is_true(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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))

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