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. known_numeric
  6. case_sensitive

   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     pcmk__schema_init();
  22     return 0;
  23 }
  24 
  25 static int
  26 teardown(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  27 {
  28     pcmk__schema_cleanup();
  29     unsetenv("PCMK_schema_directory");
  30     return 0;
  31 }
  32 
  33 // Unknown schemas (including NULL) are unsupported, but sort first as failsafe
  34 static void
  35 unknown_is_lesser(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  36 {
  37     assert_true(pcmk__cmp_schemas_by_name("pacemaker-0.1",
  38                                           "pacemaker-0.2") == 0);
  39     assert_true(pcmk__cmp_schemas_by_name("pacemaker-0.1",
  40                                           "pacemaker-1.0") < 0);
  41     assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.0",
  42                                           "pacemaker-0.1") > 0);
  43     assert_true(pcmk__cmp_schemas_by_name("pacemaker-0.1",
  44                                           PCMK_VALUE_NONE) < 0);
  45     assert_true(pcmk__cmp_schemas_by_name(PCMK_VALUE_NONE,
  46                                           "pacemaker-0.1") > 0);
  47     assert_true(pcmk__cmp_schemas_by_name(NULL, NULL) == 0);
  48     assert_true(pcmk__cmp_schemas_by_name(NULL, "pacemaker-0.0") == 0);
  49     assert_true(pcmk__cmp_schemas_by_name(NULL, "pacemaker-2.0") < 0);
  50     assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.3", NULL) > 0);
  51     assert_true(pcmk__cmp_schemas_by_name(NULL, PCMK_VALUE_NONE) < 0);
  52     assert_true(pcmk__cmp_schemas_by_name(PCMK_VALUE_NONE, NULL) > 0);
  53 }
  54 
  55 // @COMPAT none is deprecated since 2.1.8
  56 static void
  57 none_is_greater(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  58 {
  59     assert_true(pcmk__cmp_schemas_by_name(PCMK_VALUE_NONE,
  60                                           PCMK_VALUE_NONE) == 0);
  61     assert_true(pcmk__cmp_schemas_by_name("pacemaker-3.10",
  62                                           PCMK_VALUE_NONE) < 0);
  63     assert_true(pcmk__cmp_schemas_by_name(PCMK_VALUE_NONE,
  64                                           "pacemaker-1.0") > 0);
  65 }
  66 
  67 static void
  68 known_numeric(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  69 {
  70     assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.0",
  71                                           "pacemaker-1.0") == 0);
  72     assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.2",
  73                                           "pacemaker-1.0") > 0);
  74     assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.2",
  75                                           "pacemaker-2.0") < 0);
  76 }
  77 
  78 static void
  79 case_sensitive(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  80 {
  81     assert_true(pcmk__cmp_schemas_by_name("Pacemaker-1.0",
  82                                           "pacemaker-1.0") != 0);
  83     assert_true(pcmk__cmp_schemas_by_name("PACEMAKER-1.2",
  84                                           "pacemaker-1.2") != 0);
  85     assert_true(pcmk__cmp_schemas_by_name("PaceMaker-2.0",
  86                                           "pacemaker-2.0") != 0);
  87 }
  88 
  89 PCMK__UNIT_TEST(setup, teardown,
  90                 cmocka_unit_test(unknown_is_lesser),
  91                 cmocka_unit_test(none_is_greater),
  92                 cmocka_unit_test(known_numeric),
  93                 cmocka_unit_test(case_sensitive));

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