root/lib/common/tests/rules/pcmk__parse_type_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. invalid
  2. valid
  3. case_insensitive
  4. default_number
  5. default_integer
  6. default_string

   1 /*
   2  * Copyright 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 <stdio.h>
  13 
  14 #include <crm/common/rules_internal.h>
  15 #include <crm/common/unittest_internal.h>
  16 #include "crmcommon_private.h"
  17 
  18 static void
  19 invalid(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  20 {
  21     assert_int_equal(pcmk__parse_type("nope", pcmk__comparison_unknown,
  22                                       NULL, NULL),
  23                      pcmk__type_unknown);
  24 }
  25 
  26 static void
  27 valid(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  28 {
  29     assert_int_equal(pcmk__parse_type(PCMK_VALUE_STRING,
  30                                       pcmk__comparison_unknown, NULL, NULL),
  31                      pcmk__type_string);
  32 
  33     assert_int_equal(pcmk__parse_type(PCMK_VALUE_INTEGER,
  34                                       pcmk__comparison_unknown, NULL, NULL),
  35                      pcmk__type_integer);
  36 
  37     assert_int_equal(pcmk__parse_type(PCMK_VALUE_NUMBER,
  38                                       pcmk__comparison_unknown, NULL, NULL),
  39                      pcmk__type_number);
  40 
  41     assert_int_equal(pcmk__parse_type(PCMK_VALUE_VERSION,
  42                                       pcmk__comparison_unknown, NULL, NULL),
  43                      pcmk__type_version);
  44 }
  45 
  46 static void
  47 case_insensitive(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 {
  49     assert_int_equal(pcmk__parse_type("STRING", pcmk__comparison_unknown,
  50                                       NULL, NULL),
  51                      pcmk__type_string);
  52 
  53     assert_int_equal(pcmk__parse_type("Integer", pcmk__comparison_unknown,
  54                                       NULL, NULL),
  55                      pcmk__type_integer);
  56 }
  57 
  58 static void
  59 default_number(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  60 {
  61     assert_int_equal(pcmk__parse_type(NULL, pcmk__comparison_lt, "1.0", "2.5"),
  62                      pcmk__type_number);
  63 
  64     assert_int_equal(pcmk__parse_type(NULL, pcmk__comparison_lte, "1.", "2"),
  65                      pcmk__type_number);
  66 
  67     assert_int_equal(pcmk__parse_type(NULL, pcmk__comparison_gt, "1", ".5"),
  68                      pcmk__type_number);
  69 
  70     assert_int_equal(pcmk__parse_type(NULL, pcmk__comparison_gte, "1.0", "2"),
  71                      pcmk__type_number);
  72 }
  73 
  74 static void
  75 default_integer(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  76 {
  77     assert_int_equal(pcmk__parse_type(NULL, pcmk__comparison_lt, "1", "2"),
  78                      pcmk__type_integer);
  79 
  80     assert_int_equal(pcmk__parse_type(NULL, pcmk__comparison_lte, "1", "2"),
  81                      pcmk__type_integer);
  82 
  83     assert_int_equal(pcmk__parse_type(NULL, pcmk__comparison_gt, "1", "2"),
  84                      pcmk__type_integer);
  85 
  86     assert_int_equal(pcmk__parse_type(NULL, pcmk__comparison_gte, "1", "2"),
  87                      pcmk__type_integer);
  88 
  89     assert_int_equal(pcmk__parse_type(NULL, pcmk__comparison_gte, NULL, NULL),
  90                      pcmk__type_integer);
  91 
  92     assert_int_equal(pcmk__parse_type(NULL, pcmk__comparison_gte, "1", NULL),
  93                      pcmk__type_integer);
  94 
  95     assert_int_equal(pcmk__parse_type(NULL, pcmk__comparison_gte, NULL, "2.5"),
  96                      pcmk__type_number);
  97 }
  98 
  99 static void
 100 default_string(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
 101 {
 102     assert_int_equal(pcmk__parse_type(NULL, pcmk__comparison_unknown,
 103                                       NULL, NULL),
 104                      pcmk__type_string);
 105 
 106     assert_int_equal(pcmk__parse_type(NULL, pcmk__comparison_defined,
 107                                       NULL, NULL),
 108                      pcmk__type_string);
 109 
 110     assert_int_equal(pcmk__parse_type(NULL, pcmk__comparison_undefined,
 111                                       NULL, NULL),
 112                      pcmk__type_string);
 113 
 114     assert_int_equal(pcmk__parse_type(NULL, pcmk__comparison_eq, NULL, NULL),
 115                      pcmk__type_string);
 116 
 117     assert_int_equal(pcmk__parse_type(NULL, pcmk__comparison_ne, NULL, NULL),
 118                      pcmk__type_string);
 119 }
 120 
 121 PCMK__UNIT_TEST(NULL, NULL,
 122                 cmocka_unit_test(invalid),
 123                 cmocka_unit_test(valid),
 124                 cmocka_unit_test(case_insensitive),
 125                 cmocka_unit_test(default_number),
 126                 cmocka_unit_test(default_integer),
 127                 cmocka_unit_test(default_string))

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