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. missing_separator
  3. only_separator
  4. no_range_end
  5. no_range_start
  6. range_start_and_end
  7. garbage
  8. main

   1 /*
   2  * Copyright 2020-2021 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     long long start, end;
  22 
  23     assert_int_equal(pcmk__parse_ll_range(NULL, &start, &end), pcmk_rc_unknown_format);
  24     assert_int_equal(pcmk__parse_ll_range("", &start, &end), pcmk_rc_unknown_format);
  25 }
  26 
  27 static void
  28 missing_separator(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  29 {
  30     long long start, end;
  31 
  32     assert_int_equal(pcmk__parse_ll_range("1234", &start, &end), pcmk_rc_ok);
  33     assert_int_equal(start, 1234);
  34     assert_int_equal(end, 1234);
  35 }
  36 
  37 static void
  38 only_separator(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  39 {
  40     long long start, end;
  41 
  42     assert_int_equal(pcmk__parse_ll_range("-", &start, &end), pcmk_rc_unknown_format);
  43     assert_int_equal(start, PCMK__PARSE_INT_DEFAULT);
  44     assert_int_equal(end, PCMK__PARSE_INT_DEFAULT);
  45 }
  46 
  47 static void
  48 no_range_end(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  49 {
  50     long long start, end;
  51 
  52     assert_int_equal(pcmk__parse_ll_range("2000-", &start, &end), pcmk_rc_ok);
  53     assert_int_equal(start, 2000);
  54     assert_int_equal(end, PCMK__PARSE_INT_DEFAULT);
  55 }
  56 
  57 static void
  58 no_range_start(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  59 {
  60     long long start, end;
  61 
  62     assert_int_equal(pcmk__parse_ll_range("-2020", &start, &end), pcmk_rc_ok);
  63     assert_int_equal(start, PCMK__PARSE_INT_DEFAULT);
  64     assert_int_equal(end, 2020);
  65 }
  66 
  67 static void
  68 range_start_and_end(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  69 {
  70     long long start, end;
  71 
  72     assert_int_equal(pcmk__parse_ll_range("2000-2020", &start, &end), pcmk_rc_ok);
  73     assert_int_equal(start, 2000);
  74     assert_int_equal(end, 2020);
  75 }
  76 
  77 static void
  78 garbage(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  79 {
  80     long long start, end;
  81 
  82     assert_int_equal(pcmk__parse_ll_range("2000x-", &start, &end), pcmk_rc_unknown_format);
  83     assert_int_equal(start, PCMK__PARSE_INT_DEFAULT);
  84     assert_int_equal(end, PCMK__PARSE_INT_DEFAULT);
  85 
  86     assert_int_equal(pcmk__parse_ll_range("-x2000", &start, &end), pcmk_rc_unknown_format);
  87     assert_int_equal(start, PCMK__PARSE_INT_DEFAULT);
  88     assert_int_equal(end, PCMK__PARSE_INT_DEFAULT);
  89 }
  90 
  91 int main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
  92 {
  93     const struct CMUnitTest tests[] = {
  94         cmocka_unit_test(empty_input_string),
  95         cmocka_unit_test(missing_separator),
  96         cmocka_unit_test(only_separator),
  97         cmocka_unit_test(no_range_end),
  98         cmocka_unit_test(no_range_start),
  99         cmocka_unit_test(range_start_and_end),
 100 
 101         cmocka_unit_test(garbage),
 102     };
 103 
 104     cmocka_set_message_output(CM_OUTPUT_TAP);
 105     return cmocka_run_group_tests(tests, NULL, NULL);
 106 }

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