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

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

DEFINITIONS

This source file includes following definitions.
  1. setup
  2. teardown
  3. invalid_name
  4. valid_name

   1 /*
   2  * Copyright 2023 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/unittest_internal.h>
  13 #include <crm/common/lists_internal.h>
  14 
  15 #include <glib.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 invalid_name(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  35 {
  36     assert_null(pcmk__schema_files_later_than("xyz"));
  37     assert_null(pcmk__schema_files_later_than("pacemaker-"));
  38 }
  39 
  40 static void
  41 valid_name(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  42 {
  43     GList *schemas = NULL;
  44 
  45     schemas = pcmk__schema_files_later_than("pacemaker-1.0");
  46     assert_int_equal(g_list_length(schemas), 18);
  47     /* There is no "pacemaker-1.1". */
  48     assert_string_equal("pacemaker-1.2.rng", g_list_nth_data(schemas, 0));
  49     assert_string_equal("upgrade-1.3.xsl", g_list_nth_data(schemas, 1));
  50     assert_string_equal("pacemaker-1.3.rng", g_list_nth_data(schemas, 2));
  51     assert_string_equal("pacemaker-2.0.rng", g_list_nth_data(schemas, 3));
  52     assert_string_equal("pacemaker-2.1.rng", g_list_nth_data(schemas, 4));
  53     assert_string_equal("pacemaker-2.2.rng", g_list_nth_data(schemas, 5));
  54     assert_string_equal("pacemaker-2.3.rng", g_list_nth_data(schemas, 6));
  55     assert_string_equal("pacemaker-2.4.rng", g_list_nth_data(schemas, 7));
  56     assert_string_equal("pacemaker-2.5.rng", g_list_nth_data(schemas, 8));
  57     assert_string_equal("pacemaker-2.6.rng", g_list_nth_data(schemas, 9));
  58     assert_string_equal("pacemaker-2.7.rng", g_list_nth_data(schemas, 10));
  59     assert_string_equal("pacemaker-2.8.rng", g_list_nth_data(schemas, 11));
  60     assert_string_equal("pacemaker-2.9.rng", g_list_nth_data(schemas, 12));
  61     assert_string_equal("upgrade-2.10-leave.xsl", g_list_nth_data(schemas, 13));
  62     assert_string_equal("upgrade-2.10-enter.xsl", g_list_nth_data(schemas, 14));
  63     assert_string_equal("upgrade-2.10.xsl", g_list_nth_data(schemas, 15));
  64     assert_string_equal("pacemaker-2.10.rng", g_list_nth_data(schemas, 16));
  65     assert_string_equal("pacemaker-3.0.rng", g_list_nth_data(schemas, 17));
  66     g_list_free_full(schemas, free);
  67 
  68     /* Adding .rng to the end of the schema we're requesting is also valid. */
  69     schemas = pcmk__schema_files_later_than("pacemaker-2.0.rng");
  70     assert_int_equal(g_list_length(schemas), 14);
  71     assert_string_equal("pacemaker-2.1.rng", g_list_nth_data(schemas, 0));
  72     assert_string_equal("pacemaker-2.2.rng", g_list_nth_data(schemas, 1));
  73     assert_string_equal("pacemaker-2.3.rng", g_list_nth_data(schemas, 2));
  74     assert_string_equal("pacemaker-2.4.rng", g_list_nth_data(schemas, 3));
  75     assert_string_equal("pacemaker-2.5.rng", g_list_nth_data(schemas, 4));
  76     assert_string_equal("pacemaker-2.6.rng", g_list_nth_data(schemas, 5));
  77     assert_string_equal("pacemaker-2.7.rng", g_list_nth_data(schemas, 6));
  78     assert_string_equal("pacemaker-2.8.rng", g_list_nth_data(schemas, 7));
  79     assert_string_equal("pacemaker-2.9.rng", g_list_nth_data(schemas, 8));
  80     assert_string_equal("upgrade-2.10-leave.xsl", g_list_nth_data(schemas, 9));
  81     assert_string_equal("upgrade-2.10-enter.xsl", g_list_nth_data(schemas, 10));
  82     assert_string_equal("upgrade-2.10.xsl", g_list_nth_data(schemas, 11));
  83     assert_string_equal("pacemaker-2.10.rng", g_list_nth_data(schemas, 12));
  84     assert_string_equal("pacemaker-3.0.rng", g_list_nth_data(schemas, 13));
  85     g_list_free_full(schemas, free);
  86 
  87     /* Check that "pacemaker-2.10" counts as later than "pacemaker-2.9". */
  88     schemas = pcmk__schema_files_later_than("pacemaker-2.9");
  89     assert_int_equal(g_list_length(schemas), 5);
  90     assert_string_equal("upgrade-2.10-leave.xsl", g_list_nth_data(schemas, 0));
  91     assert_string_equal("upgrade-2.10-enter.xsl", g_list_nth_data(schemas, 1));
  92     assert_string_equal("upgrade-2.10.xsl", g_list_nth_data(schemas, 2));
  93     assert_string_equal("pacemaker-2.10.rng", g_list_nth_data(schemas, 3));
  94     assert_string_equal("pacemaker-3.0.rng", g_list_nth_data(schemas, 4));
  95     g_list_free_full(schemas, free);
  96 
  97     /* And then something way in the future that will never apply due to our
  98      * special schema directory.
  99      */
 100     schemas = pcmk__schema_files_later_than("pacemaker-9.0");
 101     assert_null(schemas);
 102 }
 103 
 104 PCMK__UNIT_TEST(setup, teardown,
 105                 cmocka_unit_test(invalid_name),
 106                 cmocka_unit_test(valid_name))

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