root/lib/common/tests/strings/pcmk__scan_port_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. out_of_range
  4. typical_case
  5. main

   1 /*
   2  * Copyright 2022 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 empty_input_string(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  20 {
  21     int result;
  22 
  23     assert_int_equal(pcmk__scan_port("", &result), EINVAL);
  24     assert_int_equal(result, -1);
  25 }
  26 
  27 static void
  28 bad_input_string(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  29 {
  30     int result;
  31 
  32     assert_int_equal(pcmk__scan_port("abc", &result), EINVAL);
  33     assert_int_equal(result, -1);
  34 }
  35 
  36 static void
  37 out_of_range(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  38 {
  39     int result;
  40 
  41     assert_int_equal(pcmk__scan_port("-1", &result), pcmk_rc_before_range);
  42     assert_int_equal(result, -1);
  43     assert_int_equal(pcmk__scan_port("65536",  &result), pcmk_rc_after_range);
  44     assert_int_equal(result, -1);
  45 }
  46 
  47 static void
  48 typical_case(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  49 {
  50     int result;
  51 
  52     assert_int_equal(pcmk__scan_port("0", &result), pcmk_rc_ok);
  53     assert_int_equal(result, 0);
  54 
  55     assert_int_equal(pcmk__scan_port("80", &result), pcmk_rc_ok);
  56     assert_int_equal(result, 80);
  57 }
  58 
  59 int main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
  60 {
  61     const struct CMUnitTest tests[] = {
  62         cmocka_unit_test(empty_input_string),
  63         cmocka_unit_test(bad_input_string),
  64         cmocka_unit_test(out_of_range),
  65         cmocka_unit_test(typical_case),
  66     };
  67 
  68     cmocka_set_message_output(CM_OUTPUT_TAP);
  69     return cmocka_run_group_tests(tests, NULL, NULL);
  70 }
  71 

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