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

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