root/lib/common/tests/schemas/pcmk__find_x_0_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_0
  4. last_is_0
  5. last_is_not_0
  6. schema_0_missing

   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 <stdio.h>  // NULL, rename()
  13 #include <stdlib.h> // setenv(), unsetenv()
  14 #include <glib.h>
  15 
  16 #include <crm/common/unittest_internal.h>
  17 #include "crmcommon_private.h"
  18 
  19 #define SCHEMA_PREFIX PCMK__TEST_SCHEMA_DIR "/find_x_0/pacemaker-"
  20 
  21 static int
  22 setup(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  23 {
  24     // Use a unique schema directory so we can move files around
  25     setenv("PCMK_schema_directory", PCMK__TEST_SCHEMA_DIR "/find_x_0", 1);
  26     return 0;
  27 }
  28 
  29 static int
  30 teardown(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  31 {
  32     unsetenv("PCMK_schema_directory");
  33     return 0;
  34 }
  35 
  36 static void
  37 assert_schema_0(int schema_index, const char *schema_name)
     /* [previous][next][first][last][top][bottom][index][help] */
  38 {
  39     GList *entry = NULL;
  40     pcmk__schema_t *schema = NULL;
  41 
  42     entry = pcmk__find_x_0_schema();
  43     assert_non_null(entry);
  44 
  45     schema = entry->data;
  46     assert_non_null(schema);
  47 
  48     assert_int_equal(schema->schema_index, schema_index);
  49     assert_string_equal(schema->name, schema_name);
  50 }
  51 
  52 static void
  53 last_is_0(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  54 {
  55     /* This loads all the schemas normally linked for unit testing, so we have
  56      * many 1.x and 2.x schemas and a single pacemaker-3.0 schema at index 14.
  57      */
  58     crm_schema_init();
  59     assert_schema_0(14, "pacemaker-3.0");
  60     crm_schema_cleanup();
  61 }
  62 
  63 static void
  64 last_is_not_0(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  65 {
  66     /* Disable the pacemaker-3.0 schema, so we now should get pacemaker-2.0 at
  67      * index 3.
  68      */
  69     assert_int_equal(0, rename(SCHEMA_PREFIX "3.0.rng",
  70                                SCHEMA_PREFIX "3.0.bak"));
  71     crm_schema_init();
  72     assert_schema_0(3, "pacemaker-2.0");
  73     assert_int_equal(0, rename(SCHEMA_PREFIX "3.0.bak",
  74                                SCHEMA_PREFIX "3.0.rng"));
  75     crm_schema_cleanup();
  76 }
  77 
  78 static void
  79 schema_0_missing(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  80 {
  81     /* Disable the pacemaker-3.0 and pacemaker-2.0 schemas, so we now should get
  82      * pacemaker-2.1 at index 3.
  83      */
  84     assert_int_equal(0, rename(SCHEMA_PREFIX "3.0.rng",
  85                                SCHEMA_PREFIX "3.0.bak"));
  86     assert_int_equal(0, rename(SCHEMA_PREFIX "2.0.rng",
  87                                SCHEMA_PREFIX "2.0.bak"));
  88     crm_schema_init();
  89     assert_schema_0(3, "pacemaker-2.1");
  90     assert_int_equal(0, rename(SCHEMA_PREFIX "2.0.bak",
  91                                SCHEMA_PREFIX "2.0.rng"));
  92     assert_int_equal(0, rename(SCHEMA_PREFIX "3.0.bak",
  93                                SCHEMA_PREFIX "3.0.rng"));
  94     crm_schema_cleanup();
  95 }
  96 
  97 PCMK__UNIT_TEST(setup, teardown,
  98                 cmocka_unit_test(last_is_0),
  99                 cmocka_unit_test(last_is_not_0),
 100                 cmocka_unit_test(schema_0_missing))

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