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_sensitive

   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     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 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(NULL));
  52     assert_null(pcmk__get_schema(""));
  53     assert_null(pcmk__get_schema("blahblah"));
  54     assert_null(pcmk__get_schema("pacemaker-2.47"));
  55     assert_null(pcmk__get_schema("pacemaker-47.0"));
  56 }
  57 
  58 static void
  59 known_schema(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  60 {
  61     assert_schema("pacemaker-1.0", 0);
  62     assert_schema("pacemaker-1.2", 1);
  63     assert_schema("pacemaker-2.0", 3);
  64     assert_schema("pacemaker-2.5", 8);
  65     assert_schema("pacemaker-3.0", 14);
  66 }
  67 
  68 static void
  69 case_sensitive(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  70 {
  71     assert_null(pcmk__get_schema("PACEMAKER-1.0"));
  72     assert_null(pcmk__get_schema("pAcEmAkEr-2.0"));
  73     assert_null(pcmk__get_schema("paceMAKER-3.0"));
  74 }
  75 
  76 PCMK__UNIT_TEST(setup, teardown,
  77                 cmocka_unit_test(unknown_schema),
  78                 cmocka_unit_test(known_schema),
  79                 cmocka_unit_test(case_sensitive));

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