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

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

DEFINITIONS

This source file includes following definitions.
  1. setup
  2. teardown
  3. assert_schema
  4. unknown_schema
  5. known_schema
  6. case_insensitive

   1 /*
   2  * Copyright 2023-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 static void
  34 assert_schema(const char *name, int expected_index)
     /* [previous][next][first][last][top][bottom][index][help] */
  35 {
  36     GList *schema_entry = NULL;
  37     pcmk__schema_t *schema = NULL;
  38 
  39     schema_entry = pcmk__get_schema(name);
  40     assert_non_null(schema_entry);
  41 
  42     schema = schema_entry->data;
  43     assert_non_null(schema);
  44 
  45     assert_int_equal(schema->schema_index, expected_index);
  46 }
  47 
  48 static void
  49 unknown_schema(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  50 {
  51     assert_null(pcmk__get_schema(""));
  52     assert_null(pcmk__get_schema("blahblah"));
  53     assert_null(pcmk__get_schema("pacemaker-2.47"));
  54     assert_null(pcmk__get_schema("pacemaker-47.0"));
  55 }
  56 
  57 static void
  58 known_schema(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  59 {
  60     // @COMPAT none is deprecated since 2.1.8
  61     assert_schema(NULL, 16); // defaults to "none"
  62 
  63     assert_schema("pacemaker-1.0", 0);
  64     assert_schema("pacemaker-1.2", 1);
  65     assert_schema("pacemaker-2.0", 3);
  66     assert_schema("pacemaker-2.5", 8);
  67     assert_schema("pacemaker-3.0", 14);
  68 }
  69 
  70 static void
  71 case_insensitive(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  72 {
  73     assert_schema("PACEMAKER-1.0", 0);
  74     assert_schema("pAcEmAkEr-2.0", 3);
  75     assert_schema("paceMAKER-3.0", 14);
  76 }
  77 
  78 PCMK__UNIT_TEST(setup, teardown,
  79                 cmocka_unit_test(unknown_schema),
  80                 cmocka_unit_test(known_schema),
  81                 cmocka_unit_test(case_insensitive));

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