diff --git a/lib/common/tests/schemas/pcmk__cmp_schemas_by_name_test.c b/lib/common/tests/schemas/pcmk__cmp_schemas_by_name_test.c index 4a4e874009..fce1ebdeb7 100644 --- a/lib/common/tests/schemas/pcmk__cmp_schemas_by_name_test.c +++ b/lib/common/tests/schemas/pcmk__cmp_schemas_by_name_test.c @@ -1,98 +1,110 @@ /* * Copyright 2024 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU General Public License version 2 * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include #include #include "crmcommon_private.h" static int setup(void **state) { setenv("PCMK_schema_directory", PCMK__TEST_SCHEMA_DIR, 1); crm_schema_init(); return 0; } static int teardown(void **state) { crm_schema_cleanup(); unsetenv("PCMK_schema_directory"); return 0; } // NULL schema name defaults to the "none" schema static void unknown_is_lesser(void **state) { assert_true(pcmk__cmp_schemas_by_name("pacemaker-0.1", "pacemaker-0.2") == 0); assert_true(pcmk__cmp_schemas_by_name("pacemaker-0.1", "pacemaker-1.0") < 0); assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.0", "pacemaker-0.1") > 0); assert_true(pcmk__cmp_schemas_by_name("pacemaker-0.6", "pacemaker-next") < 0); assert_true(pcmk__cmp_schemas_by_name("pacemaker-next", "pacemaker-0.7") > 0); assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.1", NULL) < 0); assert_true(pcmk__cmp_schemas_by_name(NULL, "pacemaker-0.0") > 0); } static void none_is_greater(void **state) { assert_true(pcmk__cmp_schemas_by_name(NULL, NULL) == 0); assert_true(pcmk__cmp_schemas_by_name(NULL, PCMK_VALUE_NONE) == 0); assert_true(pcmk__cmp_schemas_by_name(PCMK_VALUE_NONE, NULL) == 0); assert_true(pcmk__cmp_schemas_by_name(PCMK_VALUE_NONE, PCMK_VALUE_NONE) == 0); assert_true(pcmk__cmp_schemas_by_name("pacemaker-next", PCMK_VALUE_NONE) < 0); assert_true(pcmk__cmp_schemas_by_name(PCMK_VALUE_NONE, "pacemaker-next") > 0); assert_true(pcmk__cmp_schemas_by_name("pacemaker-3.0", PCMK_VALUE_NONE) < 0); assert_true(pcmk__cmp_schemas_by_name(PCMK_VALUE_NONE, "pacemaker-1.0") > 0); } static void next_is_before_none(void **state) { assert_true(pcmk__cmp_schemas_by_name("pacemaker-next", "pacemaker-next") == 0); assert_true(pcmk__cmp_schemas_by_name(NULL, "pacemaker-next") > 0); assert_true(pcmk__cmp_schemas_by_name("pacemaker-next", NULL) < 0); assert_true(pcmk__cmp_schemas_by_name("pacemaker-3.0", "pacemaker-next") < 0); assert_true(pcmk__cmp_schemas_by_name("pacemaker-next", "pacemaker-1.0") > 0); } static void known_numeric(void **state) { assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.0", "pacemaker-1.0") == 0); assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.2", "pacemaker-1.0") > 0); assert_true(pcmk__cmp_schemas_by_name("pacemaker-1.2", "pacemaker-2.0") < 0); } +static void +case_insensitive(void **state) +{ + assert_true(pcmk__cmp_schemas_by_name("Pacemaker-1.0", + "pacemaker-1.0") == 0); + assert_true(pcmk__cmp_schemas_by_name("PACEMAKER-1.2", + "pacemaker-1.0") > 0); + assert_true(pcmk__cmp_schemas_by_name("PaceMaker-1.2", + "pacemaker-2.0") < 0); +} + PCMK__UNIT_TEST(setup, teardown, cmocka_unit_test(unknown_is_lesser), cmocka_unit_test(none_is_greater), cmocka_unit_test(next_is_before_none), - cmocka_unit_test(known_numeric)); + cmocka_unit_test(known_numeric), + cmocka_unit_test(case_insensitive)); diff --git a/lib/common/tests/schemas/pcmk__get_schema_test.c b/lib/common/tests/schemas/pcmk__get_schema_test.c index edc0c995e9..a44089623b 100644 --- a/lib/common/tests/schemas/pcmk__get_schema_test.c +++ b/lib/common/tests/schemas/pcmk__get_schema_test.c @@ -1,73 +1,79 @@ /* * Copyright 2023-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU General Public License version 2 * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include #include #include "crmcommon_private.h" static int setup(void **state) { setenv("PCMK_schema_directory", PCMK__TEST_SCHEMA_DIR, 1); crm_schema_init(); return 0; } static int teardown(void **state) { crm_schema_cleanup(); unsetenv("PCMK_schema_directory"); return 0; } static void assert_schema(const char *name, int expected_index) { GList *schema_entry = NULL; pcmk__schema_t *schema = NULL; schema_entry = pcmk__get_schema(name); assert_non_null(schema_entry); schema = schema_entry->data; assert_non_null(schema); assert_int_equal(schema->schema_index, expected_index); } static void unknown_schema(void **state) { assert_null(pcmk__get_schema("")); assert_null(pcmk__get_schema("blahblah")); assert_null(pcmk__get_schema("pacemaker-2.47")); assert_null(pcmk__get_schema("pacemaker-47.0")); } static void known_schema(void **state) { assert_schema(NULL, 16); // defaults to "none" assert_schema("pacemaker-1.0", 0); - assert_schema("PACEMAKER-1.0", 0); assert_schema("pacemaker-1.2", 1); assert_schema("pacemaker-2.0", 3); - assert_schema("pAcEmAkEr-2.0", 3); assert_schema("pacemaker-2.5", 8); assert_schema("pacemaker-3.0", 14); +} + +static void +case_insensitive(void **state) +{ + assert_schema("PACEMAKER-1.0", 0); + assert_schema("pAcEmAkEr-2.0", 3); assert_schema("paceMAKER-3.0", 14); } PCMK__UNIT_TEST(setup, teardown, cmocka_unit_test(unknown_schema), - cmocka_unit_test(known_schema)); + cmocka_unit_test(known_schema), + cmocka_unit_test(case_insensitive));