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

   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 <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     int result;
  18 
  19     assert_int_equal(pcmk__scan_port("", &result), EINVAL);
  20     assert_int_equal(result, -1);
  21 }
  22 
  23 static void
  24 bad_input_string(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  25 {
  26     int result;
  27 
  28     assert_int_equal(pcmk__scan_port("abc", &result), EINVAL);
  29     assert_int_equal(result, -1);
  30 }
  31 
  32 static void
  33 out_of_range(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  34 {
  35     int result;
  36 
  37     assert_int_equal(pcmk__scan_port("-1", &result), pcmk_rc_before_range);
  38     assert_int_equal(result, -1);
  39     assert_int_equal(pcmk__scan_port("65536",  &result), pcmk_rc_after_range);
  40     assert_int_equal(result, -1);
  41 }
  42 
  43 static void
  44 typical_case(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  45 {
  46     int result;
  47 
  48     assert_int_equal(pcmk__scan_port("0", &result), pcmk_rc_ok);
  49     assert_int_equal(result, 0);
  50 
  51     assert_int_equal(pcmk__scan_port("80", &result), pcmk_rc_ok);
  52     assert_int_equal(result, 80);
  53 }
  54 
  55 PCMK__UNIT_TEST(NULL, NULL,
  56                 cmocka_unit_test(empty_input_string),
  57                 cmocka_unit_test(bad_input_string),
  58                 cmocka_unit_test(out_of_range),
  59                 cmocka_unit_test(typical_case))

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