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

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

DEFINITIONS

This source file includes following definitions.
  1. empty_input_string
  2. bad_input_string
  3. trailing_chars
  4. no_result_variable
  5. typical_case

   1 /*
   2  * Copyright 2023 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 
  12 #include <crm/common/unittest_internal.h>
  13 
  14 static void
  15 empty_input_string(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  16 {
  17     long long result;
  18 
  19     assert_int_equal(pcmk__scan_ll(NULL, &result, 47), pcmk_rc_ok);
  20     assert_int_equal(result, 47);
  21 }
  22 
  23 static void
  24 bad_input_string(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  25 {
  26     long long result;
  27 
  28     assert_int_equal(pcmk__scan_ll("asdf", &result, 47), EINVAL);
  29     assert_int_equal(result, 47);
  30     assert_int_equal(pcmk__scan_ll("as12", &result, 47), EINVAL);
  31     assert_int_equal(result, 47);
  32 }
  33 
  34 static void
  35 trailing_chars(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  36 {
  37     long long result;
  38 
  39     assert_int_equal(pcmk__scan_ll("12as", &result, 47), pcmk_rc_ok);
  40     assert_int_equal(result, 12);
  41 }
  42 
  43 static void
  44 no_result_variable(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  45 {
  46     assert_int_equal(pcmk__scan_ll("1234", NULL, 47), pcmk_rc_ok);
  47     assert_int_equal(pcmk__scan_ll("asdf", NULL, 47), EINVAL);
  48 }
  49 
  50 static void
  51 typical_case(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  52 {
  53     long long result;
  54 
  55     assert_int_equal(pcmk__scan_ll("1234", &result, 47), pcmk_rc_ok);
  56     assert_int_equal(result, 1234);
  57 }
  58 
  59 PCMK__UNIT_TEST(NULL, NULL,
  60                 cmocka_unit_test(empty_input_string),
  61                 cmocka_unit_test(bad_input_string),
  62                 cmocka_unit_test(trailing_chars),
  63                 cmocka_unit_test(no_result_variable),
  64                 cmocka_unit_test(typical_case))

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