root/lib/common/tests/schemas/pcmk__cmp_schemas_by_name_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. setup
  2. teardown
  3. unknown_is_lesser
  4. none_is_greater
  5. next_is_before_none
  6. known_numeric
  7. case_insensitive

   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 <crm/common/xml.h>
  13 #include <crm/common/unittest_internal.h>
  14 #include <crm/common/xml_internal.h>
  15 #include "crmcommon_private.h"
  16 
  17 static int
  18 setup(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  19 {
  20     setenv("PCMK_schema_directory", PCMK__TEST_SCHEMA_DIR, 1);
  21     crm_schema_init();
  22     return 0;
  23 }
  24 
  25 static int
  26 teardown(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  27 {
  28     crm_schema_cleanup();
  29     unsetenv("PCMK_schema_directory");
  30     return 0;
  31 }
  32 
  33 // NULL schema name defaults to the "none" schema
  34 // @COMPAT none is deprecated since 2.1.8
  35 
  36 static void
  37 unknown_is_lesser(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  38 {
  39     assert_true(pcmk__cmp_schemas_by_name("pacemaker-0.1",
  40                                           "pacemaker-0.2") == 0);
  41     assert_true(pcmk__cmp_schemas_by_name("pacemaker-0.1",
  42                                           "pacemaker-1.0") < 0);
  43     assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.0",
  44                                           "pacemaker-0.1") > 0);
  45     assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.1", NULL) < 0);
  46     assert_true(pcmk__cmp_schemas_by_name(NULL, "pacemaker-0.0") > 0);
  47 
  48     /* @COMPAT pacemaker-next is deprecated since 2.1.5,
  49      * and pacemaker-0.6 and pacemaker-0.7 since 2.1.8
  50      */
  51     assert_true(pcmk__cmp_schemas_by_name("pacemaker-0.6",
  52                                           "pacemaker-next") < 0);
  53     assert_true(pcmk__cmp_schemas_by_name("pacemaker-next",
  54                                           "pacemaker-0.7") > 0);
  55 }
  56 
  57 // @COMPAT none is deprecated since 2.1.8
  58 static void
  59 none_is_greater(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  60 {
  61     assert_true(pcmk__cmp_schemas_by_name(NULL, NULL) == 0);
  62     assert_true(pcmk__cmp_schemas_by_name(NULL, PCMK_VALUE_NONE) == 0);
  63     assert_true(pcmk__cmp_schemas_by_name(PCMK_VALUE_NONE, NULL) == 0);
  64     assert_true(pcmk__cmp_schemas_by_name(PCMK_VALUE_NONE,
  65                                           PCMK_VALUE_NONE) == 0);
  66 
  67     assert_true(pcmk__cmp_schemas_by_name("pacemaker-3.0",
  68                                           PCMK_VALUE_NONE) < 0);
  69     assert_true(pcmk__cmp_schemas_by_name(PCMK_VALUE_NONE,
  70                                           "pacemaker-1.0") > 0);
  71 
  72     // @COMPAT pacemaker-next is deprecated since 2.1.5
  73     assert_true(pcmk__cmp_schemas_by_name("pacemaker-next",
  74                                           PCMK_VALUE_NONE) < 0);
  75     assert_true(pcmk__cmp_schemas_by_name(PCMK_VALUE_NONE,
  76                                           "pacemaker-next") > 0);
  77 }
  78 
  79 // @COMPAT pacemaker-next is deprecated since 2.1.5
  80 // @COMPAT none is deprecated since 2.1.8
  81 static void
  82 next_is_before_none(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  83 {
  84     assert_true(pcmk__cmp_schemas_by_name("pacemaker-next",
  85                                           "pacemaker-next") == 0);
  86     assert_true(pcmk__cmp_schemas_by_name(NULL, "pacemaker-next") > 0);
  87     assert_true(pcmk__cmp_schemas_by_name("pacemaker-next", NULL) < 0);
  88     assert_true(pcmk__cmp_schemas_by_name("pacemaker-3.0",
  89                                           "pacemaker-next") < 0);
  90     assert_true(pcmk__cmp_schemas_by_name("pacemaker-next",
  91                                           "pacemaker-1.0") > 0);
  92 }
  93 
  94 static void
  95 known_numeric(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  96 {
  97     assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.0",
  98                                           "pacemaker-1.0") == 0);
  99     assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.2",
 100                                           "pacemaker-1.0") > 0);
 101     assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.2",
 102                                           "pacemaker-2.0") < 0);
 103 }
 104 
 105 static void
 106 case_insensitive(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
 107 {
 108     assert_true(pcmk__cmp_schemas_by_name("Pacemaker-1.0",
 109                                           "pacemaker-1.0") == 0);
 110     assert_true(pcmk__cmp_schemas_by_name("PACEMAKER-1.2",
 111                                           "pacemaker-1.0") > 0);
 112     assert_true(pcmk__cmp_schemas_by_name("PaceMaker-1.2",
 113                                           "pacemaker-2.0") < 0);
 114 }
 115 
 116 PCMK__UNIT_TEST(setup, teardown,
 117                 cmocka_unit_test(unknown_is_lesser),
 118                 cmocka_unit_test(none_is_greater),
 119                 cmocka_unit_test(next_is_before_none),
 120                 cmocka_unit_test(known_numeric),
 121                 cmocka_unit_test(case_insensitive));

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