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

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

DEFINITIONS

This source file includes following definitions.
  1. empty_input_string
  2. null_input_variables
  3. missing_separator
  4. only_separator
  5. no_range_end
  6. no_range_start
  7. range_start_and_end
  8. garbage
  9. strtoll_errors

   1 /*
   2  * Copyright 2020-2024 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 start, end;
  18 
  19     assert_int_equal(pcmk__parse_ll_range(NULL, &start, &end), ENODATA);
  20     assert_int_equal(pcmk__parse_ll_range("", &start, &end), ENODATA);
  21 }
  22 
  23 static void
  24 null_input_variables(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  25 {
  26     long long start, end;
  27 
  28     pcmk__assert_asserts(pcmk__parse_ll_range("1234", NULL, &end));
  29     pcmk__assert_asserts(pcmk__parse_ll_range("1234", &start, NULL));
  30 }
  31 
  32 static void
  33 missing_separator(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  34 {
  35     long long start, end;
  36 
  37     assert_int_equal(pcmk__parse_ll_range("1234", &start, &end), pcmk_rc_ok);
  38     assert_int_equal(start, 1234);
  39     assert_int_equal(end, 1234);
  40 }
  41 
  42 static void
  43 only_separator(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  44 {
  45     long long start, end;
  46 
  47     assert_int_equal(pcmk__parse_ll_range("-", &start, &end), pcmk_rc_bad_input);
  48     assert_int_equal(start, PCMK__PARSE_INT_DEFAULT);
  49     assert_int_equal(end, PCMK__PARSE_INT_DEFAULT);
  50 }
  51 
  52 static void
  53 no_range_end(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  54 {
  55     long long start, end;
  56 
  57     assert_int_equal(pcmk__parse_ll_range("2000-", &start, &end), pcmk_rc_ok);
  58     assert_int_equal(start, 2000);
  59     assert_int_equal(end, PCMK__PARSE_INT_DEFAULT);
  60 }
  61 
  62 static void
  63 no_range_start(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  64 {
  65     long long start, end;
  66 
  67     assert_int_equal(pcmk__parse_ll_range("-2020", &start, &end), pcmk_rc_ok);
  68     assert_int_equal(start, PCMK__PARSE_INT_DEFAULT);
  69     assert_int_equal(end, 2020);
  70 }
  71 
  72 static void
  73 range_start_and_end(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  74 {
  75     long long start, end;
  76 
  77     assert_int_equal(pcmk__parse_ll_range("2000-2020", &start, &end), pcmk_rc_ok);
  78     assert_int_equal(start, 2000);
  79     assert_int_equal(end, 2020);
  80 
  81     assert_int_equal(pcmk__parse_ll_range("2000-2020-2030", &start, &end), pcmk_rc_bad_input);
  82 }
  83 
  84 static void
  85 garbage(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  86 {
  87     long long start, end;
  88 
  89     assert_int_equal(pcmk__parse_ll_range("2000x-", &start, &end), pcmk_rc_bad_input);
  90     assert_int_equal(start, PCMK__PARSE_INT_DEFAULT);
  91     assert_int_equal(end, PCMK__PARSE_INT_DEFAULT);
  92 
  93     assert_int_equal(pcmk__parse_ll_range("-x2000", &start, &end), pcmk_rc_bad_input);
  94     assert_int_equal(start, PCMK__PARSE_INT_DEFAULT);
  95     assert_int_equal(end, PCMK__PARSE_INT_DEFAULT);
  96 }
  97 
  98 static void
  99 strtoll_errors(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
 100 {
 101     long long start, end;
 102 
 103     assert_int_equal(pcmk__parse_ll_range("20000000000000000000-", &start, &end), EOVERFLOW);
 104     assert_int_equal(pcmk__parse_ll_range("100-20000000000000000000", &start, &end), EOVERFLOW);
 105 }
 106 
 107 PCMK__UNIT_TEST(NULL, NULL,
 108                 cmocka_unit_test(empty_input_string),
 109                 cmocka_unit_test(null_input_variables),
 110                 cmocka_unit_test(missing_separator),
 111                 cmocka_unit_test(only_separator),
 112                 cmocka_unit_test(no_range_end),
 113                 cmocka_unit_test(no_range_start),
 114                 cmocka_unit_test(range_start_and_end),
 115                 cmocka_unit_test(strtoll_errors),
 116                 cmocka_unit_test(garbage))

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