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 <glib.h>
  13 
  14 static void
  15 empty_input_string(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  16 {
  17     long long start, end;
  18 
  19     g_assert_cmpint(pcmk__parse_ll_range(NULL, &start, &end), ==,
  20                     pcmk_rc_unknown_format);
  21     g_assert_cmpint(pcmk__parse_ll_range("", &start, &end), ==,
  22                     pcmk_rc_unknown_format);
  23 }
  24 
  25 static void
  26 missing_separator(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  27 {
  28     long long start, end;
  29 
  30     g_assert_cmpint(pcmk__parse_ll_range("1234", &start, &end), ==, pcmk_rc_ok);
  31     g_assert_cmpint(start, ==, 1234);
  32     g_assert_cmpint(end, ==, 1234);
  33 }
  34 
  35 static void
  36 only_separator(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  37 {
  38     long long start, end;
  39 
  40     g_assert_cmpint(pcmk__parse_ll_range("-", &start, &end), ==,
  41                     pcmk_rc_unknown_format);
  42     g_assert_cmpint(start, ==, PCMK__PARSE_INT_DEFAULT);
  43     g_assert_cmpint(end, ==, PCMK__PARSE_INT_DEFAULT);
  44 }
  45 
  46 static void
  47 no_range_end(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 {
  49     long long start, end;
  50 
  51     g_assert_cmpint(pcmk__parse_ll_range("2000-", &start, &end), ==,
  52                     pcmk_rc_ok);
  53     g_assert_cmpint(start, ==, 2000);
  54     g_assert_cmpint(end, ==, PCMK__PARSE_INT_DEFAULT);
  55 }
  56 
  57 static void
  58 no_range_start(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  59 {
  60     long long start, end;
  61 
  62     g_assert_cmpint(pcmk__parse_ll_range("-2020", &start, &end), ==,
  63                     pcmk_rc_ok);
  64     g_assert_cmpint(start, ==, PCMK__PARSE_INT_DEFAULT);
  65     g_assert_cmpint(end, ==, 2020);
  66 }
  67 
  68 static void
  69 range_start_and_end(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  70 {
  71     long long start, end;
  72 
  73     g_assert_cmpint(pcmk__parse_ll_range("2000-2020", &start, &end), ==,
  74                     pcmk_rc_ok);
  75     g_assert_cmpint(start, ==, 2000);
  76     g_assert_cmpint(end, ==, 2020);
  77 }
  78 
  79 static void
  80 garbage(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  81 {
  82     long long start, end;
  83 
  84     g_assert_cmpint(pcmk__parse_ll_range("2000x-", &start, &end), ==,
  85                     pcmk_rc_unknown_format);
  86     g_assert_cmpint(start, ==, PCMK__PARSE_INT_DEFAULT);
  87     g_assert_cmpint(end, ==, PCMK__PARSE_INT_DEFAULT);
  88 
  89     g_assert_cmpint(pcmk__parse_ll_range("-x2000", &start, &end), ==,
  90                     pcmk_rc_unknown_format);
  91     g_assert_cmpint(start, ==, PCMK__PARSE_INT_DEFAULT);
  92     g_assert_cmpint(end, ==, PCMK__PARSE_INT_DEFAULT);
  93 }
  94 
  95 int main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
  96 {
  97     g_test_init(&argc, &argv, NULL);
  98 
  99     g_test_add_func("/common/strings/range/empty", empty_input_string);
 100     g_test_add_func("/common/strings/range/no_sep", missing_separator);
 101     g_test_add_func("/common/strings/range/only_sep", only_separator);
 102     g_test_add_func("/common/strings/range/no_end", no_range_end);
 103     g_test_add_func("/common/strings/range/no_start", no_range_start);
 104     g_test_add_func("/common/strings/range/start_and_end", range_start_and_end);
 105 
 106     g_test_add_func("/common/strings/range/garbage", garbage);
 107 
 108     return g_test_run();
 109 }

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