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

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

DEFINITIONS

This source file includes following definitions.
  1. empty_input_string
  2. input_below_minimum
  3. input_above_maximum
  4. input_just_right

   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 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     int result;
  18 
  19     assert_int_equal(pcmk__scan_min_int("", &result, 1), EINVAL);
  20     assert_int_equal(result, 1);
  21 
  22     assert_int_equal(pcmk__scan_min_int(NULL, &result, 1), pcmk_rc_ok);
  23     assert_int_equal(result, 1);
  24 }
  25 
  26 static void
  27 input_below_minimum(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  28 {
  29     int result;
  30 
  31     assert_int_equal(pcmk__scan_min_int("100", &result, 1024), pcmk_rc_ok);
  32     assert_int_equal(result, 1024);
  33 }
  34 
  35 static void
  36 input_above_maximum(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  37 {
  38     int result;
  39 
  40     assert_int_equal(pcmk__scan_min_int("20000000000000000", &result, 100), EOVERFLOW);
  41     assert_int_equal(result, INT_MAX);
  42 }
  43 
  44 static void
  45 input_just_right(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  46 {
  47     int result;
  48 
  49     assert_int_equal(pcmk__scan_min_int("1024", &result, 1024), pcmk_rc_ok);
  50     assert_int_equal(result, 1024);
  51 
  52     assert_int_equal(pcmk__scan_min_int("2048", &result, 1024), pcmk_rc_ok);
  53     assert_int_equal(result, 2048);
  54 }
  55 
  56 PCMK__UNIT_TEST(NULL, NULL,
  57                 cmocka_unit_test(empty_input_string),
  58                 cmocka_unit_test(input_below_minimum),
  59                 cmocka_unit_test(input_above_maximum),
  60                 cmocka_unit_test(input_just_right))

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