diff --git a/lib/common/tests/acl/pcmk__is_user_in_group_test.c b/lib/common/tests/acl/pcmk__is_user_in_group_test.c index 537449bca9..917d92e086 100644 --- a/lib/common/tests/acl/pcmk__is_user_in_group_test.c +++ b/lib/common/tests/acl/pcmk__is_user_in_group_test.c @@ -1,38 +1,38 @@ /* * Copyright 2020-2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include #include "../../crmcommon_private.h" #include "mock_private.h" static void is_pcmk__is_user_in_group(void **state) { pcmk__mock_grent = true; // null user assert_false(pcmk__is_user_in_group(NULL, "grp0")); // null group assert_false(pcmk__is_user_in_group("user0", NULL)); // nonexistent group assert_false(pcmk__is_user_in_group("user0", "nonexistent_group")); // user is in group assert_true(pcmk__is_user_in_group("user0", "grp0")); // user is not in group assert_false(pcmk__is_user_in_group("user2", "grp0")); pcmk__mock_grent = false; } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(is_pcmk__is_user_in_group)) diff --git a/lib/common/tests/acl/pcmk_acl_required_test.c b/lib/common/tests/acl/pcmk_acl_required_test.c index 6c425a0ce8..bd5b922d64 100644 --- a/lib/common/tests/acl/pcmk_acl_required_test.c +++ b/lib/common/tests/acl/pcmk_acl_required_test.c @@ -1,26 +1,26 @@ /* * Copyright 2020-2021 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void is_pcmk_acl_required(void **state) { assert_false(pcmk_acl_required(NULL)); assert_false(pcmk_acl_required("")); assert_true(pcmk_acl_required("123")); assert_false(pcmk_acl_required(CRM_DAEMON_USER)); assert_false(pcmk_acl_required("root")); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(is_pcmk_acl_required)) diff --git a/lib/common/tests/acl/xml_acl_denied_test.c b/lib/common/tests/acl/xml_acl_denied_test.c index 117c5bd4c2..faf2a393a2 100644 --- a/lib/common/tests/acl/xml_acl_denied_test.c +++ b/lib/common/tests/acl/xml_acl_denied_test.c @@ -1,61 +1,61 @@ /* * Copyright 2020-2021 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include #include "../../crmcommon_private.h" static void is_xml_acl_denied_without_node(void **state) { xmlNode *test_xml = create_xml_node(NULL, "test_xml"); assert_false(xml_acl_denied(test_xml)); test_xml->doc->_private = NULL; assert_false(xml_acl_denied(test_xml)); test_xml->doc = NULL; assert_false(xml_acl_denied(test_xml)); test_xml = NULL; assert_false(xml_acl_denied(test_xml)); } static void is_xml_acl_denied_with_node(void **state) { xml_doc_private_t *docpriv; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); // allocate memory for _private, which is NULL by default test_xml->doc->_private = calloc(1, sizeof(xml_doc_private_t)); assert_false(xml_acl_denied(test_xml)); // cast _private from void* to xml_doc_private_t* docpriv = test_xml->doc->_private; // enable an irrelevant flag docpriv->flags |= pcmk__xf_acl_enabled; assert_false(xml_acl_denied(test_xml)); // enable pcmk__xf_acl_denied docpriv->flags |= pcmk__xf_acl_denied; assert_true(xml_acl_denied(test_xml)); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(is_xml_acl_denied_without_node), cmocka_unit_test(is_xml_acl_denied_with_node)) diff --git a/lib/common/tests/acl/xml_acl_enabled_test.c b/lib/common/tests/acl/xml_acl_enabled_test.c index 8530fce1ce..28665f4905 100644 --- a/lib/common/tests/acl/xml_acl_enabled_test.c +++ b/lib/common/tests/acl/xml_acl_enabled_test.c @@ -1,61 +1,61 @@ /* * Copyright 2020-2021 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include #include "../../crmcommon_private.h" static void is_xml_acl_enabled_without_node(void **state) { xmlNode *test_xml = create_xml_node(NULL, "test_xml"); assert_false(xml_acl_enabled(test_xml)); test_xml->doc->_private = NULL; assert_false(xml_acl_enabled(test_xml)); test_xml->doc = NULL; assert_false(xml_acl_enabled(test_xml)); test_xml = NULL; assert_false(xml_acl_enabled(test_xml)); } static void is_xml_acl_enabled_with_node(void **state) { xml_doc_private_t *docpriv; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); // allocate memory for _private, which is NULL by default test_xml->doc->_private = calloc(1, sizeof(xml_doc_private_t)); assert_false(xml_acl_enabled(test_xml)); // cast _private from void* to xml_doc_private_t* docpriv = test_xml->doc->_private; // enable an irrelevant flag docpriv->flags |= pcmk__xf_acl_denied; assert_false(xml_acl_enabled(test_xml)); // enable pcmk__xf_acl_enabled docpriv->flags |= pcmk__xf_acl_enabled; assert_true(xml_acl_enabled(test_xml)); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(is_xml_acl_enabled_without_node), cmocka_unit_test(is_xml_acl_enabled_with_node)) diff --git a/lib/common/tests/agents/crm_generate_ra_key_test.c b/lib/common/tests/agents/crm_generate_ra_key_test.c index 4d85502cd7..f71c1c27bd 100644 --- a/lib/common/tests/agents/crm_generate_ra_key_test.c +++ b/lib/common/tests/agents/crm_generate_ra_key_test.c @@ -1,48 +1,48 @@ /* * Copyright 2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void all_params_null(void **state) { assert_null(crm_generate_ra_key(NULL, NULL, NULL)); } static void some_params_null(void **state) { char *retval; assert_null(crm_generate_ra_key("std", "prov", NULL)); retval = crm_generate_ra_key("std", NULL, "ty"); assert_string_equal(retval, "std:ty"); free(retval); assert_null(crm_generate_ra_key(NULL, "prov", "ty")); assert_null(crm_generate_ra_key("std", NULL, NULL)); assert_null(crm_generate_ra_key(NULL, "prov", NULL)); assert_null(crm_generate_ra_key(NULL, NULL, "ty")); } static void no_params_null(void **state) { char *retval; retval = crm_generate_ra_key("std", "prov", "ty"); assert_string_equal(retval, "std:prov:ty"); free(retval); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(all_params_null), cmocka_unit_test(some_params_null), cmocka_unit_test(no_params_null)) diff --git a/lib/common/tests/agents/crm_parse_agent_spec_test.c b/lib/common/tests/agents/crm_parse_agent_spec_test.c index 67f7ef5e2b..cfd75f05c1 100644 --- a/lib/common/tests/agents/crm_parse_agent_spec_test.c +++ b/lib/common/tests/agents/crm_parse_agent_spec_test.c @@ -1,87 +1,87 @@ /* * Copyright 2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void all_params_null(void **state) { assert_int_equal(crm_parse_agent_spec(NULL, NULL, NULL, NULL), -EINVAL); assert_int_equal(crm_parse_agent_spec("", NULL, NULL, NULL), -EINVAL); assert_int_equal(crm_parse_agent_spec(":", NULL, NULL, NULL), -EINVAL); assert_int_equal(crm_parse_agent_spec("::", NULL, NULL, NULL), -EINVAL); } static void no_prov_or_type(void **state) { assert_int_equal(crm_parse_agent_spec("ocf", NULL, NULL, NULL), -EINVAL); assert_int_equal(crm_parse_agent_spec("ocf:", NULL, NULL, NULL), -EINVAL); assert_int_equal(crm_parse_agent_spec("ocf::", NULL, NULL, NULL), -EINVAL); } static void no_type(void **state) { assert_int_equal(crm_parse_agent_spec("ocf:pacemaker:", NULL, NULL, NULL), -EINVAL); } static void get_std_and_ty(void **state) { char *std = NULL; char *prov = NULL; char *ty = NULL; assert_int_equal(crm_parse_agent_spec("stonith:fence_xvm", &std, &prov, &ty), pcmk_ok); assert_string_equal(std, "stonith"); assert_null(prov); assert_string_equal(ty, "fence_xvm"); free(std); free(ty); } static void get_all_values(void **state) { char *std = NULL; char *prov = NULL; char *ty = NULL; assert_int_equal(crm_parse_agent_spec("ocf:pacemaker:ping", &std, &prov, &ty), pcmk_ok); assert_string_equal(std, "ocf"); assert_string_equal(prov, "pacemaker"); assert_string_equal(ty, "ping"); free(std); free(prov); free(ty); } static void get_systemd_values(void **state) { char *std = NULL; char *prov = NULL; char *ty = NULL; assert_int_equal(crm_parse_agent_spec("systemd:UNIT@A:B", &std, &prov, &ty), pcmk_ok); assert_string_equal(std, "systemd"); assert_null(prov); assert_string_equal(ty, "UNIT@A:B"); free(std); free(ty); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(all_params_null), cmocka_unit_test(no_prov_or_type), cmocka_unit_test(no_type), cmocka_unit_test(get_std_and_ty), cmocka_unit_test(get_all_values), cmocka_unit_test(get_systemd_values)) diff --git a/lib/common/tests/agents/pcmk__effective_rc_test.c b/lib/common/tests/agents/pcmk__effective_rc_test.c index ce9f2b3357..c9bad9792d 100644 --- a/lib/common/tests/agents/pcmk__effective_rc_test.c +++ b/lib/common/tests/agents/pcmk__effective_rc_test.c @@ -1,36 +1,36 @@ /* * Copyright 2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void pcmk__effective_rc_test(void **state) { /* All other PCMK_OCF_* values after UNKNOWN are deprecated and no longer used, * so probably not worth testing them. */ assert_int_equal(PCMK_OCF_OK, pcmk__effective_rc(PCMK_OCF_OK)); assert_int_equal(PCMK_OCF_OK, pcmk__effective_rc(PCMK_OCF_DEGRADED)); assert_int_equal(PCMK_OCF_RUNNING_PROMOTED, pcmk__effective_rc(PCMK_OCF_DEGRADED_PROMOTED)); assert_int_equal(PCMK_OCF_UNKNOWN, pcmk__effective_rc(PCMK_OCF_UNKNOWN)); /* There's nothing that says pcmk__effective_rc is restricted to PCMK_OCF_* * values. That's just how it's used. Let's check some values outside * that range just to be sure. */ assert_int_equal(-1, pcmk__effective_rc(-1)); assert_int_equal(255, pcmk__effective_rc(255)); assert_int_equal(INT_MAX, pcmk__effective_rc(INT_MAX)); assert_int_equal(INT_MIN, pcmk__effective_rc(INT_MIN)); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(pcmk__effective_rc_test)) diff --git a/lib/common/tests/agents/pcmk_get_ra_caps_test.c b/lib/common/tests/agents/pcmk_get_ra_caps_test.c index 833dca5047..178dce5ffb 100644 --- a/lib/common/tests/agents/pcmk_get_ra_caps_test.c +++ b/lib/common/tests/agents/pcmk_get_ra_caps_test.c @@ -1,63 +1,63 @@ /* * Copyright 2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void ocf_standard(void **state) { uint32_t expected = pcmk_ra_cap_provider | pcmk_ra_cap_params | pcmk_ra_cap_unique | pcmk_ra_cap_promotable; assert_int_equal(pcmk_get_ra_caps("ocf"), expected); assert_int_equal(pcmk_get_ra_caps("OCF"), expected); } static void stonith_standard(void **state) { uint32_t expected = pcmk_ra_cap_params | pcmk_ra_cap_unique | pcmk_ra_cap_stdin | pcmk_ra_cap_fence_params; assert_int_equal(pcmk_get_ra_caps("stonith"), expected); assert_int_equal(pcmk_get_ra_caps("StOnItH"), expected); } static void service_standard(void **state) { assert_int_equal(pcmk_get_ra_caps("systemd"), pcmk_ra_cap_status); assert_int_equal(pcmk_get_ra_caps("SYSTEMD"), pcmk_ra_cap_status); assert_int_equal(pcmk_get_ra_caps("service"), pcmk_ra_cap_status); assert_int_equal(pcmk_get_ra_caps("SeRvIcE"), pcmk_ra_cap_status); assert_int_equal(pcmk_get_ra_caps("lsb"), pcmk_ra_cap_status); assert_int_equal(pcmk_get_ra_caps("LSB"), pcmk_ra_cap_status); assert_int_equal(pcmk_get_ra_caps("upstart"), pcmk_ra_cap_status); assert_int_equal(pcmk_get_ra_caps("uPsTaRt"), pcmk_ra_cap_status); } static void nagios_standard(void **state) { assert_int_equal(pcmk_get_ra_caps("nagios"), pcmk_ra_cap_params); assert_int_equal(pcmk_get_ra_caps("NAGios"), pcmk_ra_cap_params); } static void unknown_standard(void **state) { assert_int_equal(pcmk_get_ra_caps("blahblah"), pcmk_ra_cap_none); assert_int_equal(pcmk_get_ra_caps(""), pcmk_ra_cap_none); assert_int_equal(pcmk_get_ra_caps(NULL), pcmk_ra_cap_none); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(ocf_standard), cmocka_unit_test(stonith_standard), cmocka_unit_test(service_standard), cmocka_unit_test(nagios_standard), cmocka_unit_test(unknown_standard)) diff --git a/lib/common/tests/agents/pcmk_stonith_param_test.c b/lib/common/tests/agents/pcmk_stonith_param_test.c index 4994282fd4..fad431ea26 100644 --- a/lib/common/tests/agents/pcmk_stonith_param_test.c +++ b/lib/common/tests/agents/pcmk_stonith_param_test.c @@ -1,50 +1,50 @@ /* * Copyright 2020-2021 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void is_stonith_param(void **state) { assert_false(pcmk_stonith_param(NULL)); assert_false(pcmk_stonith_param("")); assert_false(pcmk_stonith_param("unrecognized")); assert_false(pcmk_stonith_param("pcmk_unrecognized")); assert_false(pcmk_stonith_param("x" PCMK_STONITH_ACTION_LIMIT)); assert_false(pcmk_stonith_param(PCMK_STONITH_ACTION_LIMIT "x")); assert_true(pcmk_stonith_param(PCMK_STONITH_ACTION_LIMIT)); assert_true(pcmk_stonith_param(PCMK_STONITH_DELAY_BASE)); assert_true(pcmk_stonith_param(PCMK_STONITH_DELAY_MAX)); assert_true(pcmk_stonith_param(PCMK_STONITH_HOST_ARGUMENT)); assert_true(pcmk_stonith_param(PCMK_STONITH_HOST_CHECK)); assert_true(pcmk_stonith_param(PCMK_STONITH_HOST_LIST)); assert_true(pcmk_stonith_param(PCMK_STONITH_HOST_MAP)); assert_true(pcmk_stonith_param(PCMK_STONITH_PROVIDES)); assert_true(pcmk_stonith_param(PCMK_STONITH_STONITH_TIMEOUT)); } static void is_stonith_action_param(void **state) { /* Currently, the function accepts any string not containing underbars as * the action name, so we do not need to verify particular action names. */ assert_false(pcmk_stonith_param("pcmk_on_unrecognized")); assert_true(pcmk_stonith_param("pcmk_on_action")); assert_true(pcmk_stonith_param("pcmk_on_timeout")); assert_true(pcmk_stonith_param("pcmk_on_retries")); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(is_stonith_param), cmocka_unit_test(is_stonith_action_param)) diff --git a/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c index 1b20d74afa..863fbb947b 100644 --- a/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c +++ b/lib/common/tests/cmdline/pcmk__cmdline_preproc_test.c @@ -1,156 +1,156 @@ /* * Copyright 2020-2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include #include #include #define LISTS_EQ(a, b) { \ assert_int_equal(g_strv_length((gchar **) (a)), g_strv_length((gchar **) (b))); \ for (int i = 0; i < g_strv_length((a)); i++) { \ assert_string_equal((a)[i], (b)[i]); \ } \ } static void empty_input(void **state) { assert_null(pcmk__cmdline_preproc(NULL, "")); } static void no_specials(void **state) { const char *argv[] = { "crm_mon", "-a", "-b", "-c", "-d", "-1", NULL }; const gchar *expected[] = { "crm_mon", "-a", "-b", "-c", "-d", "-1", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL); LISTS_EQ(processed, expected); g_strfreev(processed); processed = pcmk__cmdline_preproc((char **) argv, ""); LISTS_EQ(processed, expected); g_strfreev(processed); } static void single_dash(void **state) { const char *argv[] = { "crm_mon", "-", NULL }; const gchar *expected[] = { "crm_mon", "-", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL); LISTS_EQ(processed, expected); g_strfreev(processed); } static void double_dash(void **state) { const char *argv[] = { "crm_mon", "-a", "--", "-bc", NULL }; const gchar *expected[] = { "crm_mon", "-a", "--", "-bc", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL); LISTS_EQ(processed, expected); g_strfreev(processed); } static void special_args(void **state) { const char *argv[] = { "crm_mon", "-aX", "-Fval", NULL }; const gchar *expected[] = { "crm_mon", "-a", "X", "-F", "val", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, "aF"); LISTS_EQ(processed, expected); g_strfreev(processed); } static void special_arg_at_end(void **state) { const char *argv[] = { "crm_mon", "-a", NULL }; const gchar *expected[] = { "crm_mon", "-a", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, "a"); LISTS_EQ(processed, expected); g_strfreev(processed); } static void long_arg(void **state) { const char *argv[] = { "crm_mon", "--blah=foo", NULL }; const gchar *expected[] = { "crm_mon", "--blah=foo", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL); LISTS_EQ(processed, expected); g_strfreev(processed); } static void negative_score(void **state) { const char *argv[] = { "crm_mon", "-v", "-1000", NULL }; const gchar *expected[] = { "crm_mon", "-v", "-1000", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, "v"); LISTS_EQ(processed, expected); g_strfreev(processed); } static void negative_score_2(void **state) { const char *argv[] = { "crm_mon", "-1i3", NULL }; const gchar *expected[] = { "crm_mon", "-1", "-i", "-3", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, NULL); LISTS_EQ(processed, expected); g_strfreev(processed); } static void string_arg_with_dash(void **state) { const char *argv[] = { "crm_mon", "-n", "crm_mon_options", "-v", "--opt1 --opt2", NULL }; const gchar *expected[] = { "crm_mon", "-n", "crm_mon_options", "-v", "--opt1 --opt2", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, "v"); LISTS_EQ(processed, expected); g_strfreev(processed); } static void string_arg_with_dash_2(void **state) { const char *argv[] = { "crm_mon", "-n", "crm_mon_options", "-v", "-1i3", NULL }; const gchar *expected[] = { "crm_mon", "-n", "crm_mon_options", "-v", "-1i3", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, "v"); LISTS_EQ(processed, expected); g_strfreev(processed); } static void string_arg_with_dash_3(void **state) { const char *argv[] = { "crm_mon", "-abc", "-1i3", NULL }; const gchar *expected[] = { "crm_mon", "-a", "-b", "-c", "-1i3", NULL }; gchar **processed = pcmk__cmdline_preproc((char **) argv, "c"); LISTS_EQ(processed, expected); g_strfreev(processed); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(empty_input), cmocka_unit_test(no_specials), cmocka_unit_test(single_dash), cmocka_unit_test(double_dash), cmocka_unit_test(special_args), cmocka_unit_test(special_arg_at_end), cmocka_unit_test(long_arg), cmocka_unit_test(negative_score), cmocka_unit_test(negative_score_2), cmocka_unit_test(string_arg_with_dash), cmocka_unit_test(string_arg_with_dash_2), cmocka_unit_test(string_arg_with_dash_3)) diff --git a/lib/common/tests/cmdline/pcmk__quote_cmdline_test.c b/lib/common/tests/cmdline/pcmk__quote_cmdline_test.c index d87b88f91b..42bd8cad68 100644 --- a/lib/common/tests/cmdline/pcmk__quote_cmdline_test.c +++ b/lib/common/tests/cmdline/pcmk__quote_cmdline_test.c @@ -1,56 +1,56 @@ /* * Copyright 2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include #include static void empty_input(void **state) { assert_null(pcmk__quote_cmdline(NULL)); } static void no_spaces(void **state) { const char *argv[] = { "crm_resource", "-r", "rsc1", "--meta", "-p", "comment", "-v", "hello", "--output-as=xml", NULL }; const gchar *expected = "crm_resource -r rsc1 --meta -p comment -v hello --output-as=xml"; gchar *processed = pcmk__quote_cmdline((gchar **) argv); assert_string_equal(processed, expected); g_free(processed); } static void spaces_no_quote(void **state) { const char *argv[] = { "crm_resource", "-r", "rsc1", "--meta", "-p", "comment", "-v", "hello world", "--output-as=xml", NULL }; const gchar *expected = "crm_resource -r rsc1 --meta -p comment -v 'hello world' --output-as=xml"; gchar *processed = pcmk__quote_cmdline((gchar **) argv); assert_string_equal(processed, expected); g_free(processed); } static void spaces_with_quote(void **state) { const char *argv[] = { "crm_resource", "-r", "rsc1", "--meta", "-p", "comment", "-v", "here's johnny", "--output-as=xml", NULL }; const gchar *expected = "crm_resource -r rsc1 --meta -p comment -v 'here\\\'s johnny' --output-as=xml"; gchar *processed = pcmk__quote_cmdline((gchar **) argv); assert_string_equal(processed, expected); g_free(processed); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(empty_input), cmocka_unit_test(no_spaces), cmocka_unit_test(spaces_no_quote), cmocka_unit_test(spaces_with_quote)) diff --git a/lib/common/tests/flags/pcmk__clear_flags_as_test.c b/lib/common/tests/flags/pcmk__clear_flags_as_test.c index 7f3afc7ecb..07dbe28e5b 100644 --- a/lib/common/tests/flags/pcmk__clear_flags_as_test.c +++ b/lib/common/tests/flags/pcmk__clear_flags_as_test.c @@ -1,41 +1,41 @@ /* * Copyright 2020-2021 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include static void clear_none(void **state) { assert_int_equal(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", "test", 0x0f0, 0x00f, NULL), 0x0f0); assert_int_equal(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", "test", 0x0f0, 0xf0f, NULL), 0x0f0); } static void clear_some(void **state) { assert_int_equal(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", "test", 0x0f0, 0x020, NULL), 0x0d0); assert_int_equal(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", "test", 0x0f0, 0x030, NULL), 0x0c0); } static void clear_all(void **state) { assert_int_equal(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", "test", 0x0f0, 0x0f0, NULL), 0x000); assert_int_equal(pcmk__clear_flags_as(__func__, __LINE__, LOG_TRACE, "Test", "test", 0x0f0, 0xfff, NULL), 0x000); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(clear_none), cmocka_unit_test(clear_some), cmocka_unit_test(clear_all)) diff --git a/lib/common/tests/flags/pcmk__set_flags_as_test.c b/lib/common/tests/flags/pcmk__set_flags_as_test.c index 89df19b43a..cd14c85f36 100644 --- a/lib/common/tests/flags/pcmk__set_flags_as_test.c +++ b/lib/common/tests/flags/pcmk__set_flags_as_test.c @@ -1,25 +1,25 @@ /* * Copyright 2020-2021 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include static void set_flags(void **state) { assert_int_equal(pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, "Test", "test", 0x0f0, 0x00f, NULL), 0x0ff); assert_int_equal(pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, "Test", "test", 0x0f0, 0xf0f, NULL), 0xfff); assert_int_equal(pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE, "Test", "test", 0x0f0, 0xfff, NULL), 0xfff); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(set_flags)) diff --git a/lib/common/tests/flags/pcmk_all_flags_set_test.c b/lib/common/tests/flags/pcmk_all_flags_set_test.c index 00d36aeba6..512ccce065 100644 --- a/lib/common/tests/flags/pcmk_all_flags_set_test.c +++ b/lib/common/tests/flags/pcmk_all_flags_set_test.c @@ -1,33 +1,33 @@ /* * Copyright 2020-2021 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include static void all_set(void **state) { assert_false(pcmk_all_flags_set(0x000, 0x003)); assert_true(pcmk_all_flags_set(0x00f, 0x003)); assert_false(pcmk_all_flags_set(0x00f, 0x010)); assert_false(pcmk_all_flags_set(0x00f, 0x011)); assert_true(pcmk_all_flags_set(0x000, 0x000)); assert_true(pcmk_all_flags_set(0x00f, 0x000)); } static void one_is_set(void **state) { // pcmk_is_set() is a simple macro alias for pcmk_all_flags_set() assert_true(pcmk_is_set(0x00f, 0x001)); assert_false(pcmk_is_set(0x00f, 0x010)); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(all_set), cmocka_unit_test(one_is_set)) diff --git a/lib/common/tests/flags/pcmk_any_flags_set_test.c b/lib/common/tests/flags/pcmk_any_flags_set_test.c index de8e0bf14c..dc3aabca14 100644 --- a/lib/common/tests/flags/pcmk_any_flags_set_test.c +++ b/lib/common/tests/flags/pcmk_any_flags_set_test.c @@ -1,26 +1,26 @@ /* * Copyright 2020-2021 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include static void any_set(void **state) { assert_false(pcmk_any_flags_set(0x000, 0x000)); assert_false(pcmk_any_flags_set(0x000, 0x001)); assert_true(pcmk_any_flags_set(0x00f, 0x001)); assert_false(pcmk_any_flags_set(0x00f, 0x010)); assert_true(pcmk_any_flags_set(0x00f, 0x011)); assert_false(pcmk_any_flags_set(0x000, 0x000)); assert_false(pcmk_any_flags_set(0x00f, 0x000)); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(any_set)) diff --git a/lib/common/tests/health/pcmk__parse_health_strategy_test.c b/lib/common/tests/health/pcmk__parse_health_strategy_test.c index 0e0d45b2c7..28cc702c08 100644 --- a/lib/common/tests/health/pcmk__parse_health_strategy_test.c +++ b/lib/common/tests/health/pcmk__parse_health_strategy_test.c @@ -1,56 +1,56 @@ /* * Copyright 2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include static void valid(void **state) { assert_int_equal(pcmk__parse_health_strategy(NULL), pcmk__health_strategy_none); assert_int_equal(pcmk__parse_health_strategy("none"), pcmk__health_strategy_none); assert_int_equal(pcmk__parse_health_strategy("NONE"), pcmk__health_strategy_none); assert_int_equal(pcmk__parse_health_strategy("None"), pcmk__health_strategy_none); assert_int_equal(pcmk__parse_health_strategy("nOnE"), pcmk__health_strategy_none); assert_int_equal(pcmk__parse_health_strategy("migrate-on-red"), pcmk__health_strategy_no_red); assert_int_equal(pcmk__parse_health_strategy("only-green"), pcmk__health_strategy_only_green); assert_int_equal(pcmk__parse_health_strategy("progressive"), pcmk__health_strategy_progressive); assert_int_equal(pcmk__parse_health_strategy("custom"), pcmk__health_strategy_custom); } static void invalid(void **state) { assert_int_equal(pcmk__parse_health_strategy("foo"), pcmk__health_strategy_none); assert_int_equal(pcmk__parse_health_strategy("custom1"), pcmk__health_strategy_none); assert_int_equal(pcmk__parse_health_strategy("not-only-green-here"), pcmk__health_strategy_none); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(valid), cmocka_unit_test(invalid)) diff --git a/lib/common/tests/health/pcmk__validate_health_strategy_test.c b/lib/common/tests/health/pcmk__validate_health_strategy_test.c index ef10589921..c7c60aa905 100644 --- a/lib/common/tests/health/pcmk__validate_health_strategy_test.c +++ b/lib/common/tests/health/pcmk__validate_health_strategy_test.c @@ -1,38 +1,38 @@ /* * Copyright 2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include // Test functions static void valid_strategy(void **state) { assert_true(pcmk__validate_health_strategy("none")); assert_true(pcmk__validate_health_strategy("None")); assert_true(pcmk__validate_health_strategy("NONE")); assert_true(pcmk__validate_health_strategy("NoNe")); assert_true(pcmk__validate_health_strategy("migrate-on-red")); assert_true(pcmk__validate_health_strategy("only-green")); assert_true(pcmk__validate_health_strategy("progressive")); assert_true(pcmk__validate_health_strategy("custom")); } static void invalid_strategy(void **state) { assert_false(pcmk__validate_health_strategy(NULL)); assert_false(pcmk__validate_health_strategy("")); assert_false(pcmk__validate_health_strategy("none to speak of")); assert_false(pcmk__validate_health_strategy("customized")); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(valid_strategy), cmocka_unit_test(invalid_strategy)) diff --git a/lib/common/tests/io/pcmk__full_path_test.c b/lib/common/tests/io/pcmk__full_path_test.c index 6cfb691858..dbbd71bced 100644 --- a/lib/common/tests/io/pcmk__full_path_test.c +++ b/lib/common/tests/io/pcmk__full_path_test.c @@ -1,52 +1,52 @@ /* * Copyright 2020-2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include "mock_private.h" static void function_asserts(void **state) { pcmk__assert_asserts(pcmk__full_path(NULL, "/dir")); pcmk__assert_asserts(pcmk__full_path("file", NULL)); pcmk__assert_asserts( { pcmk__mock_strdup = true; // strdup() will return NULL expect_string(__wrap_strdup, s, "/full/path"); pcmk__full_path("/full/path", "/dir"); pcmk__mock_strdup = false; // Use real strdup() } ); } static void full_path(void **state) { char *path = NULL; path = pcmk__full_path("file", "/dir"); assert_int_equal(strcmp(path, "/dir/file"), 0); free(path); path = pcmk__full_path("/full/path", "/dir"); assert_int_equal(strcmp(path, "/full/path"), 0); free(path); path = pcmk__full_path("../relative/path", "/dir"); assert_int_equal(strcmp(path, "/dir/../relative/path"), 0); free(path); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(function_asserts), cmocka_unit_test(full_path)) diff --git a/lib/common/tests/io/pcmk__get_tmpdir_test.c b/lib/common/tests/io/pcmk__get_tmpdir_test.c index f79051f090..bc1751377f 100644 --- a/lib/common/tests/io/pcmk__get_tmpdir_test.c +++ b/lib/common/tests/io/pcmk__get_tmpdir_test.c @@ -1,68 +1,68 @@ /* * Copyright 2021-2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include "mock_private.h" static void getenv_returns_invalid(void **state) { const char *result; pcmk__mock_getenv = true; expect_string(__wrap_getenv, name, "TMPDIR"); will_return(__wrap_getenv, NULL); // getenv("TMPDIR") return value result = pcmk__get_tmpdir(); assert_string_equal(result, "/tmp"); expect_string(__wrap_getenv, name, "TMPDIR"); will_return(__wrap_getenv, ""); // getenv("TMPDIR") return value result = pcmk__get_tmpdir(); assert_string_equal(result, "/tmp"); expect_string(__wrap_getenv, name, "TMPDIR"); will_return(__wrap_getenv, "subpath"); // getenv("TMPDIR") return value result = pcmk__get_tmpdir(); assert_string_equal(result, "/tmp"); pcmk__mock_getenv = false; } static void getenv_returns_valid(void **state) { const char *result; pcmk__mock_getenv = true; expect_string(__wrap_getenv, name, "TMPDIR"); will_return(__wrap_getenv, "/var/tmp"); // getenv("TMPDIR") return value result = pcmk__get_tmpdir(); assert_string_equal(result, "/var/tmp"); expect_string(__wrap_getenv, name, "TMPDIR"); will_return(__wrap_getenv, "/"); // getenv("TMPDIR") return value result = pcmk__get_tmpdir(); assert_string_equal(result, "/"); expect_string(__wrap_getenv, name, "TMPDIR"); will_return(__wrap_getenv, "/tmp/abcd.1234"); // getenv("TMPDIR") return value result = pcmk__get_tmpdir(); assert_string_equal(result, "/tmp/abcd.1234"); pcmk__mock_getenv = false; } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(getenv_returns_invalid), cmocka_unit_test(getenv_returns_valid)) diff --git a/lib/common/tests/iso8601/pcmk__readable_interval_test.c b/lib/common/tests/iso8601/pcmk__readable_interval_test.c index b45f3e383e..43b55410b0 100644 --- a/lib/common/tests/iso8601/pcmk__readable_interval_test.c +++ b/lib/common/tests/iso8601/pcmk__readable_interval_test.c @@ -1,27 +1,27 @@ /* * Copyright 2021 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void readable_interval(void **state) { assert_string_equal(pcmk__readable_interval(0), "0s"); assert_string_equal(pcmk__readable_interval(30000), "30s"); assert_string_equal(pcmk__readable_interval(150000), "2m30s"); assert_string_equal(pcmk__readable_interval(3333), "3.333s"); assert_string_equal(pcmk__readable_interval(UINT_MAX), "49d17h2m47.295s"); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(readable_interval)) diff --git a/lib/common/tests/lists/pcmk__list_of_1_test.c b/lib/common/tests/lists/pcmk__list_of_1_test.c index ed070b9e45..a3e0bbca88 100644 --- a/lib/common/tests/lists/pcmk__list_of_1_test.c +++ b/lib/common/tests/lists/pcmk__list_of_1_test.c @@ -1,45 +1,45 @@ /* * Copyright 2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void empty_list(void **state) { assert_false(pcmk__list_of_1(NULL)); } static void singleton_list(void **state) { GList *lst = NULL; lst = g_list_append(lst, strdup("abc")); assert_true(pcmk__list_of_1(lst)); g_list_free_full(lst, free); } static void longer_list(void **state) { GList *lst = NULL; lst = g_list_append(lst, strdup("abc")); lst = g_list_append(lst, strdup("xyz")); assert_false(pcmk__list_of_1(lst)); g_list_free_full(lst, free); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(empty_list), cmocka_unit_test(singleton_list), cmocka_unit_test(longer_list)) diff --git a/lib/common/tests/lists/pcmk__list_of_multiple_test.c b/lib/common/tests/lists/pcmk__list_of_multiple_test.c index e9aebfd82d..0966037541 100644 --- a/lib/common/tests/lists/pcmk__list_of_multiple_test.c +++ b/lib/common/tests/lists/pcmk__list_of_multiple_test.c @@ -1,45 +1,45 @@ /* * Copyright 2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void empty_list(void **state) { assert_false(pcmk__list_of_multiple(NULL)); } static void singleton_list(void **state) { GList *lst = NULL; lst = g_list_append(lst, strdup("abc")); assert_false(pcmk__list_of_multiple(lst)); g_list_free_full(lst, free); } static void longer_list(void **state) { GList *lst = NULL; lst = g_list_append(lst, strdup("abc")); lst = g_list_append(lst, strdup("xyz")); assert_true(pcmk__list_of_multiple(lst)); g_list_free_full(lst, free); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(empty_list), cmocka_unit_test(singleton_list), cmocka_unit_test(longer_list)) diff --git a/lib/common/tests/lists/pcmk__subtract_lists_test.c b/lib/common/tests/lists/pcmk__subtract_lists_test.c index 814e6b49f7..1198e2ba7d 100644 --- a/lib/common/tests/lists/pcmk__subtract_lists_test.c +++ b/lib/common/tests/lists/pcmk__subtract_lists_test.c @@ -1,144 +1,144 @@ /* * Copyright 2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include #include static void different_lists(void **state) { GList *from = NULL; GList *items = NULL; GList *result = NULL; from = g_list_append(from, strdup("abc")); from = g_list_append(from, strdup("def")); from = g_list_append(from, strdup("ghi")); items = g_list_append(items, strdup("123")); items = g_list_append(items, strdup("456")); result = pcmk__subtract_lists(from, items, (GCompareFunc) strcmp); assert_int_equal(g_list_length(result), 3); assert_string_equal(g_list_nth_data(result, 0), "abc"); assert_string_equal(g_list_nth_data(result, 1), "def"); assert_string_equal(g_list_nth_data(result, 2), "ghi"); g_list_free(result); g_list_free_full(from, free); g_list_free_full(items, free); } static void remove_first_item(void **state) { GList *from = NULL; GList *items = NULL; GList *result = NULL; from = g_list_append(from, strdup("abc")); from = g_list_append(from, strdup("def")); from = g_list_append(from, strdup("ghi")); items = g_list_append(items, strdup("abc")); result = pcmk__subtract_lists(from, items, (GCompareFunc) strcmp); assert_int_equal(g_list_length(result), 2); assert_string_equal(g_list_nth_data(result, 0), "def"); assert_string_equal(g_list_nth_data(result, 1), "ghi"); g_list_free(result); g_list_free_full(from, free); g_list_free_full(items, free); } static void remove_middle_item(void **state) { GList *from = NULL; GList *items = NULL; GList *result = NULL; from = g_list_append(from, strdup("abc")); from = g_list_append(from, strdup("def")); from = g_list_append(from, strdup("ghi")); items = g_list_append(items, strdup("def")); result = pcmk__subtract_lists(from, items, (GCompareFunc) strcmp); assert_int_equal(g_list_length(result), 2); assert_string_equal(g_list_nth_data(result, 0), "abc"); assert_string_equal(g_list_nth_data(result, 1), "ghi"); g_list_free(result); g_list_free_full(from, free); g_list_free_full(items, free); } static void remove_last_item(void **state) { GList *from = NULL; GList *items = NULL; GList *result = NULL; from = g_list_append(from, strdup("abc")); from = g_list_append(from, strdup("def")); from = g_list_append(from, strdup("ghi")); items = g_list_append(items, strdup("ghi")); result = pcmk__subtract_lists(from, items, (GCompareFunc) strcmp); assert_int_equal(g_list_length(result), 2); assert_string_equal(g_list_nth_data(result, 0), "abc"); assert_string_equal(g_list_nth_data(result, 1), "def"); g_list_free(result); g_list_free_full(from, free); g_list_free_full(items, free); } static void remove_all_items(void **state) { GList *from = NULL; GList *items = NULL; GList *result = NULL; from = g_list_append(from, strdup("abc")); from = g_list_append(from, strdup("def")); from = g_list_append(from, strdup("ghi")); items = g_list_append(items, strdup("abc")); items = g_list_append(items, strdup("def")); items = g_list_append(items, strdup("ghi")); result = pcmk__subtract_lists(from, items, (GCompareFunc) strcmp); assert_int_equal(g_list_length(result), 0); g_list_free(result); g_list_free_full(from, free); g_list_free_full(items, free); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(different_lists), cmocka_unit_test(remove_first_item), cmocka_unit_test(remove_middle_item), cmocka_unit_test(remove_last_item), cmocka_unit_test(remove_all_items)) diff --git a/lib/common/tests/nvpair/pcmk__xe_attr_is_true_test.c b/lib/common/tests/nvpair/pcmk__xe_attr_is_true_test.c index 4f0dd26339..3723707943 100644 --- a/lib/common/tests/nvpair/pcmk__xe_attr_is_true_test.c +++ b/lib/common/tests/nvpair/pcmk__xe_attr_is_true_test.c @@ -1,50 +1,50 @@ /* * Copyright 2021 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void empty_input(void **state) { xmlNode *node = string2xml(""); assert_false(pcmk__xe_attr_is_true(NULL, NULL)); assert_false(pcmk__xe_attr_is_true(NULL, "whatever")); assert_false(pcmk__xe_attr_is_true(node, NULL)); free_xml(node); } static void attr_missing(void **state) { xmlNode *node = string2xml(""); assert_false(pcmk__xe_attr_is_true(node, "c")); free_xml(node); } static void attr_present(void **state) { xmlNode *node = string2xml(""); assert_true(pcmk__xe_attr_is_true(node, "a")); assert_false(pcmk__xe_attr_is_true(node, "b")); free_xml(node); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(empty_input), cmocka_unit_test(attr_missing), cmocka_unit_test(attr_present)) diff --git a/lib/common/tests/nvpair/pcmk__xe_get_bool_attr_test.c b/lib/common/tests/nvpair/pcmk__xe_get_bool_attr_test.c index 523186ce4d..318d90e7ab 100644 --- a/lib/common/tests/nvpair/pcmk__xe_get_bool_attr_test.c +++ b/lib/common/tests/nvpair/pcmk__xe_get_bool_attr_test.c @@ -1,59 +1,59 @@ /* * Copyright 2021 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void empty_input(void **state) { xmlNode *node = string2xml(""); bool value; assert_int_equal(pcmk__xe_get_bool_attr(NULL, NULL, &value), ENODATA); assert_int_equal(pcmk__xe_get_bool_attr(NULL, "whatever", &value), ENODATA); assert_int_equal(pcmk__xe_get_bool_attr(node, NULL, &value), EINVAL); assert_int_equal(pcmk__xe_get_bool_attr(node, "whatever", NULL), EINVAL); free_xml(node); } static void attr_missing(void **state) { xmlNode *node = string2xml(""); bool value; assert_int_equal(pcmk__xe_get_bool_attr(node, "c", &value), ENODATA); free_xml(node); } static void attr_present(void **state) { xmlNode *node = string2xml(""); bool value; value = false; assert_int_equal(pcmk__xe_get_bool_attr(node, "a", &value), pcmk_rc_ok); assert_true(value); value = true; assert_int_equal(pcmk__xe_get_bool_attr(node, "b", &value), pcmk_rc_ok); assert_false(value); assert_int_equal(pcmk__xe_get_bool_attr(node, "c", &value), pcmk_rc_unknown_format); free_xml(node); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(empty_input), cmocka_unit_test(attr_missing), cmocka_unit_test(attr_present)) diff --git a/lib/common/tests/nvpair/pcmk__xe_set_bool_attr_test.c b/lib/common/tests/nvpair/pcmk__xe_set_bool_attr_test.c index 95e95e192c..e1fb9c4564 100644 --- a/lib/common/tests/nvpair/pcmk__xe_set_bool_attr_test.c +++ b/lib/common/tests/nvpair/pcmk__xe_set_bool_attr_test.c @@ -1,31 +1,31 @@ /* * Copyright 2021 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include #include static void set_attr(void **state) { xmlNode *node = string2xml(""); pcmk__xe_set_bool_attr(node, "a", true); pcmk__xe_set_bool_attr(node, "b", false); assert_string_equal(crm_element_value(node, "a"), XML_BOOLEAN_TRUE); assert_string_equal(crm_element_value(node, "b"), XML_BOOLEAN_FALSE); free_xml(node); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(set_attr)) diff --git a/lib/common/tests/operations/copy_in_properties_test.c b/lib/common/tests/operations/copy_in_properties_test.c index 31de7c805d..7882551382 100644 --- a/lib/common/tests/operations/copy_in_properties_test.c +++ b/lib/common/tests/operations/copy_in_properties_test.c @@ -1,62 +1,62 @@ /* * Copyright 2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void target_is_NULL(void **state) { xmlNode *test_xml_1 = create_xml_node(NULL, "test_xml_1"); xmlNode *test_xml_2 = NULL; pcmk__xe_set_props(test_xml_1, "test_prop", "test_value", NULL); copy_in_properties(test_xml_2, test_xml_1); assert_ptr_equal(test_xml_2, NULL); } static void src_is_NULL(void **state) { xmlNode *test_xml_1 = NULL; xmlNode *test_xml_2 = create_xml_node(NULL, "test_xml_2"); copy_in_properties(test_xml_2, test_xml_1); assert_ptr_equal(test_xml_2->properties, NULL); } static void copying_is_successful(void **state) { const char *xml_1_value; const char *xml_2_value; xmlNode *test_xml_1 = create_xml_node(NULL, "test_xml_1"); xmlNode *test_xml_2 = create_xml_node(NULL, "test_xml_2"); pcmk__xe_set_props(test_xml_1, "test_prop", "test_value", NULL); copy_in_properties(test_xml_2, test_xml_1); xml_1_value = crm_element_value(test_xml_1, "test_prop"); xml_2_value = crm_element_value(test_xml_2, "test_prop"); assert_string_equal(xml_1_value, xml_2_value); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(target_is_NULL), cmocka_unit_test(src_is_NULL), cmocka_unit_test(copying_is_successful)) diff --git a/lib/common/tests/operations/expand_plus_plus_test.c b/lib/common/tests/operations/expand_plus_plus_test.c index 652c2f78c1..41471f957d 100644 --- a/lib/common/tests/operations/expand_plus_plus_test.c +++ b/lib/common/tests/operations/expand_plus_plus_test.c @@ -1,256 +1,256 @@ /* * Copyright 2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void value_is_name_plus_plus(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "5"); expand_plus_plus(test_xml, "X", "X++"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "6"); } static void value_is_name_plus_equals_integer(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "5"); expand_plus_plus(test_xml, "X", "X+=2"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "7"); } // NULL input static void target_is_NULL(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "5"); expand_plus_plus(NULL, "X", "X++"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "5"); } static void name_is_NULL(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "5"); expand_plus_plus(test_xml, NULL, "X++"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "5"); } static void value_is_NULL(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "5"); expand_plus_plus(test_xml, "X", NULL); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "5"); } // the value input doesn't start with the name input static void value_is_wrong_name(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "5"); expand_plus_plus(test_xml, "X", "Y++"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "Y++"); } static void value_is_only_an_integer(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "5"); expand_plus_plus(test_xml, "X", "2"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "2"); } // non-integers static void variable_is_initialized_to_be_NULL(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", NULL); expand_plus_plus(test_xml, "X", "X++"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "X++"); } static void variable_is_initialized_to_be_non_numeric(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "hello"); expand_plus_plus(test_xml, "X", "X++"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "1"); } static void variable_is_initialized_to_be_non_numeric_2(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "hello"); expand_plus_plus(test_xml, "X", "X+=2"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "2"); } static void variable_is_initialized_to_be_numeric_and_decimal_point_containing(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "5.01"); expand_plus_plus(test_xml, "X", "X++"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "6"); } static void variable_is_initialized_to_be_numeric_and_decimal_point_containing_2(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "5.50"); expand_plus_plus(test_xml, "X", "X++"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "6"); } static void variable_is_initialized_to_be_numeric_and_decimal_point_containing_3(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "5.99"); expand_plus_plus(test_xml, "X", "X++"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "6"); } static void value_is_non_numeric(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "5"); expand_plus_plus(test_xml, "X", "X+=hello"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "5"); } static void value_is_numeric_and_decimal_point_containing(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "5"); expand_plus_plus(test_xml, "X", "X+=2.01"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "7"); } static void value_is_numeric_and_decimal_point_containing_2(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "5"); expand_plus_plus(test_xml, "X", "X+=1.50"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "6"); } static void value_is_numeric_and_decimal_point_containing_3(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "5"); expand_plus_plus(test_xml, "X", "X+=1.99"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "6"); } // undefined input static void name_is_undefined(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "Y", "5"); expand_plus_plus(test_xml, "X", "X++"); new_value = crm_element_value(test_xml, "X"); assert_string_equal(new_value, "X++"); } // large input static void assignment_result_is_too_large(void **state) { const char *new_value; xmlNode *test_xml = create_xml_node(NULL, "test_xml"); crm_xml_add(test_xml, "X", "5"); expand_plus_plus(test_xml, "X", "X+=100000000000"); new_value = crm_element_value(test_xml, "X"); printf("assignment result is too large %s\n", new_value); assert_string_equal(new_value, "1000000"); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(value_is_name_plus_plus), cmocka_unit_test(value_is_name_plus_equals_integer), cmocka_unit_test(target_is_NULL), cmocka_unit_test(name_is_NULL), cmocka_unit_test(value_is_NULL), cmocka_unit_test(value_is_wrong_name), cmocka_unit_test(value_is_only_an_integer), cmocka_unit_test(variable_is_initialized_to_be_NULL), cmocka_unit_test(variable_is_initialized_to_be_non_numeric), cmocka_unit_test(variable_is_initialized_to_be_non_numeric_2), cmocka_unit_test(variable_is_initialized_to_be_numeric_and_decimal_point_containing), cmocka_unit_test(variable_is_initialized_to_be_numeric_and_decimal_point_containing_2), cmocka_unit_test(variable_is_initialized_to_be_numeric_and_decimal_point_containing_3), cmocka_unit_test(value_is_non_numeric), cmocka_unit_test(value_is_numeric_and_decimal_point_containing), cmocka_unit_test(value_is_numeric_and_decimal_point_containing_2), cmocka_unit_test(value_is_numeric_and_decimal_point_containing_3), cmocka_unit_test(name_is_undefined), cmocka_unit_test(assignment_result_is_too_large)) diff --git a/lib/common/tests/operations/fix_plus_plus_recursive_test.c b/lib/common/tests/operations/fix_plus_plus_recursive_test.c index 9c5972ca76..b3c7cc2e98 100644 --- a/lib/common/tests/operations/fix_plus_plus_recursive_test.c +++ b/lib/common/tests/operations/fix_plus_plus_recursive_test.c @@ -1,47 +1,47 @@ /* * Copyright 2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void element_nodes(void **state) { const char *new_value_root; const char *new_value_child; const char *new_value_grandchild; xmlNode *test_xml_root = create_xml_node(NULL, "test_xml_root"); xmlNode *test_xml_child = create_xml_node(test_xml_root, "test_xml_child"); xmlNode *test_xml_grandchild = create_xml_node(test_xml_child, "test_xml_grandchild"); xmlNode *test_xml_text = pcmk_create_xml_text_node(test_xml_root, "text_xml_text", "content"); xmlNode *test_xml_comment = string2xml(""); crm_xml_add(test_xml_root, "X", "5"); crm_xml_add(test_xml_child, "X", "X++"); crm_xml_add(test_xml_grandchild, "X", "X+=2"); crm_xml_add(test_xml_text, "X", "X++"); fix_plus_plus_recursive(test_xml_root); fix_plus_plus_recursive(test_xml_comment); new_value_root = crm_element_value(test_xml_root, "X"); new_value_child = crm_element_value(test_xml_child, "X"); new_value_grandchild = crm_element_value(test_xml_grandchild, "X"); assert_string_equal(new_value_root, "5"); assert_string_equal(new_value_child, "1"); assert_string_equal(new_value_grandchild, "2"); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(element_nodes)) diff --git a/lib/common/tests/operations/parse_op_key_test.c b/lib/common/tests/operations/parse_op_key_test.c index 7486f7c208..d6494496f4 100644 --- a/lib/common/tests/operations/parse_op_key_test.c +++ b/lib/common/tests/operations/parse_op_key_test.c @@ -1,221 +1,221 @@ /* * Copyright 2020-2021 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include static void basic(void **state) { char *rsc = NULL; char *ty = NULL; guint ms = 0; assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, &ms)); assert_string_equal(rsc, "Fencing"); assert_string_equal(ty, "monitor"); assert_int_equal(ms, 60000); free(rsc); free(ty); } static void colon_in_rsc(void **state) { char *rsc = NULL; char *ty = NULL; guint ms = 0; assert_true(parse_op_key("ClusterIP:0_start_0", &rsc, &ty, &ms)); assert_string_equal(rsc, "ClusterIP:0"); assert_string_equal(ty, "start"); assert_int_equal(ms, 0); free(rsc); free(ty); assert_true(parse_op_key("imagestoreclone:1_post_notify_stop_0", &rsc, &ty, &ms)); assert_string_equal(rsc, "imagestoreclone:1"); assert_string_equal(ty, "post_notify_stop"); assert_int_equal(ms, 0); free(rsc); free(ty); } static void dashes_in_rsc(void **state) { char *rsc = NULL; char *ty = NULL; guint ms = 0; assert_true(parse_op_key("httpd-bundle-0_monitor_30000", &rsc, &ty, &ms)); assert_string_equal(rsc, "httpd-bundle-0"); assert_string_equal(ty, "monitor"); assert_int_equal(ms, 30000); free(rsc); free(ty); assert_true(parse_op_key("httpd-bundle-ip-192.168.122.132_start_0", &rsc, &ty, &ms)); assert_string_equal(rsc, "httpd-bundle-ip-192.168.122.132"); assert_string_equal(ty, "start"); assert_int_equal(ms, 0); free(rsc); free(ty); } static void migrate_to_from(void **state) { char *rsc = NULL; char *ty = NULL; guint ms = 0; assert_true(parse_op_key("vm_migrate_from_0", &rsc, &ty, &ms)); assert_string_equal(rsc, "vm"); assert_string_equal(ty, "migrate_from"); assert_int_equal(ms, 0); free(rsc); free(ty); assert_true(parse_op_key("vm_migrate_to_0", &rsc, &ty, &ms)); assert_string_equal(rsc, "vm"); assert_string_equal(ty, "migrate_to"); assert_int_equal(ms, 0); free(rsc); free(ty); assert_true(parse_op_key("vm_idcc_devel_migrate_to_0", &rsc, &ty, &ms)); assert_string_equal(rsc, "vm_idcc_devel"); assert_string_equal(ty, "migrate_to"); assert_int_equal(ms, 0); free(rsc); free(ty); } static void pre_post(void **state) { char *rsc = NULL; char *ty = NULL; guint ms = 0; assert_true(parse_op_key("rsc_drbd_7788:1_post_notify_start_0", &rsc, &ty, &ms)); assert_string_equal(rsc, "rsc_drbd_7788:1"); assert_string_equal(ty, "post_notify_start"); assert_int_equal(ms, 0); free(rsc); free(ty); assert_true(parse_op_key("rabbitmq-bundle-clone_pre_notify_stop_0", &rsc, &ty, &ms)); assert_string_equal(rsc, "rabbitmq-bundle-clone"); assert_string_equal(ty, "pre_notify_stop"); assert_int_equal(ms, 0); free(rsc); free(ty); assert_true(parse_op_key("post_notify_start_0", &rsc, &ty, &ms)); assert_string_equal(rsc, "post_notify"); assert_string_equal(ty, "start"); assert_int_equal(ms, 0); free(rsc); free(ty); } static void skip_rsc(void **state) { char *ty = NULL; guint ms = 0; assert_true(parse_op_key("Fencing_monitor_60000", NULL, &ty, &ms)); assert_string_equal(ty, "monitor"); assert_int_equal(ms, 60000); free(ty); } static void skip_ty(void **state) { char *rsc = NULL; guint ms = 0; assert_true(parse_op_key("Fencing_monitor_60000", &rsc, NULL, &ms)); assert_string_equal(rsc, "Fencing"); assert_int_equal(ms, 60000); free(rsc); } static void skip_ms(void **state) { char *rsc = NULL; char *ty = NULL; assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, NULL)); assert_string_equal(rsc, "Fencing"); assert_string_equal(ty, "monitor"); free(rsc); free(ty); } static void empty_input(void **state) { char *rsc = NULL; char *ty = NULL; guint ms = 0; assert_false(parse_op_key("", &rsc, &ty, &ms)); assert_null(rsc); assert_null(ty); assert_int_equal(ms, 0); assert_false(parse_op_key(NULL, &rsc, &ty, &ms)); assert_null(rsc); assert_null(ty); assert_int_equal(ms, 0); } static void malformed_input(void **state) { char *rsc = NULL; char *ty = NULL; guint ms = 0; assert_false(parse_op_key("httpd-bundle-0", &rsc, &ty, &ms)); assert_null(rsc); assert_null(ty); assert_int_equal(ms, 0); assert_false(parse_op_key("httpd-bundle-0_monitor", &rsc, &ty, &ms)); assert_null(rsc); assert_null(ty); assert_int_equal(ms, 0); assert_false(parse_op_key("httpd-bundle-0_30000", &rsc, &ty, &ms)); assert_null(rsc); assert_null(ty); assert_int_equal(ms, 0); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(basic), cmocka_unit_test(colon_in_rsc), cmocka_unit_test(dashes_in_rsc), cmocka_unit_test(migrate_to_from), cmocka_unit_test(pre_post), cmocka_unit_test(skip_rsc), cmocka_unit_test(skip_ty), cmocka_unit_test(skip_ms), cmocka_unit_test(empty_input), cmocka_unit_test(malformed_input)) diff --git a/lib/common/tests/operations/pcmk_is_probe_test.c b/lib/common/tests/operations/pcmk_is_probe_test.c index d439cf0e12..4a65e3f9af 100644 --- a/lib/common/tests/operations/pcmk_is_probe_test.c +++ b/lib/common/tests/operations/pcmk_is_probe_test.c @@ -1,25 +1,25 @@ /* * Copyright 2021 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include static void is_probe_test(void **state) { assert_false(pcmk_is_probe(NULL, 0)); assert_false(pcmk_is_probe("", 0)); assert_false(pcmk_is_probe("blahblah", 0)); assert_false(pcmk_is_probe("monitor", 1)); assert_true(pcmk_is_probe("monitor", 0)); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(is_probe_test)) diff --git a/lib/common/tests/operations/pcmk_xe_is_probe_test.c b/lib/common/tests/operations/pcmk_xe_is_probe_test.c index f8bee6f287..62b21d9b0f 100644 --- a/lib/common/tests/operations/pcmk_xe_is_probe_test.c +++ b/lib/common/tests/operations/pcmk_xe_is_probe_test.c @@ -1,43 +1,43 @@ /* * Copyright 2021 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include static void op_is_probe_test(void **state) { xmlNode *node = NULL; assert_false(pcmk_xe_is_probe(NULL)); node = string2xml(""); assert_false(pcmk_xe_is_probe(node)); free_xml(node); node = string2xml(""); assert_false(pcmk_xe_is_probe(node)); free_xml(node); node = string2xml(""); assert_false(pcmk_xe_is_probe(node)); free_xml(node); node = string2xml(""); assert_false(pcmk_xe_is_probe(node)); free_xml(node); node = string2xml(""); assert_true(pcmk_xe_is_probe(node)); free_xml(node); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(op_is_probe_test)) diff --git a/lib/common/tests/operations/pcmk_xe_mask_probe_failure_test.c b/lib/common/tests/operations/pcmk_xe_mask_probe_failure_test.c index 04461626f6..9e380192bf 100644 --- a/lib/common/tests/operations/pcmk_xe_mask_probe_failure_test.c +++ b/lib/common/tests/operations/pcmk_xe_mask_probe_failure_test.c @@ -1,150 +1,150 @@ /* * Copyright 2021 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include static void op_is_not_probe_test(void **state) { xmlNode *node = NULL; /* Not worth testing this thoroughly since it's just a duplicate of whether * pcmk_op_is_probe works or not. */ node = string2xml(""); assert_false(pcmk_xe_mask_probe_failure(node)); free_xml(node); } static void op_does_not_have_right_values_test(void **state) { xmlNode *node = NULL; node = string2xml(""); assert_false(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_false(pcmk_xe_mask_probe_failure(node)); free_xml(node); } static void check_values_test(void **state) { xmlNode *node = NULL; /* PCMK_EXEC_NOT_SUPPORTED */ node = string2xml(""); assert_false(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_true(pcmk_xe_mask_probe_failure(node)); free_xml(node); /* PCMK_EXEC_DONE */ node = string2xml(""); assert_false(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_true(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_true(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_false(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_false(pcmk_xe_mask_probe_failure(node)); free_xml(node); /* PCMK_EXEC_NOT_INSTALLED */ node = string2xml(""); assert_true(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_true(pcmk_xe_mask_probe_failure(node)); free_xml(node); /* PCMK_EXEC_ERROR */ node = string2xml(""); assert_false(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_true(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_true(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_false(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_false(pcmk_xe_mask_probe_failure(node)); free_xml(node); /* PCMK_EXEC_ERROR_HARD */ node = string2xml(""); assert_false(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_true(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_true(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_false(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_false(pcmk_xe_mask_probe_failure(node)); free_xml(node); /* PCMK_EXEC_ERROR_FATAL */ node = string2xml(""); assert_false(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_true(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_true(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_false(pcmk_xe_mask_probe_failure(node)); free_xml(node); node = string2xml(""); assert_false(pcmk_xe_mask_probe_failure(node)); free_xml(node); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(op_is_not_probe_test), cmocka_unit_test(op_does_not_have_right_values_test), cmocka_unit_test(check_values_test)) diff --git a/lib/common/tests/options/pcmk__env_option_enabled_test.c b/lib/common/tests/options/pcmk__env_option_enabled_test.c index 6c879c621e..b7d5d25daa 100644 --- a/lib/common/tests/options/pcmk__env_option_enabled_test.c +++ b/lib/common/tests/options/pcmk__env_option_enabled_test.c @@ -1,101 +1,101 @@ /* * Copyright 2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include "mock_private.h" static void disabled_null_value(void **state) { // Return false if option value not found (NULL accomplishes this) assert_false(pcmk__env_option_enabled(NULL, NULL)); assert_false(pcmk__env_option_enabled("pacemaker-execd", NULL)); } static void enabled_true_value(void **state) { // Return true if option value is true, with or without daemon name pcmk__mock_getenv = true; expect_string(__wrap_getenv, name, "PCMK_env_var"); will_return(__wrap_getenv, "true"); assert_true(pcmk__env_option_enabled(NULL, "env_var")); expect_string(__wrap_getenv, name, "PCMK_env_var"); will_return(__wrap_getenv, "true"); assert_true(pcmk__env_option_enabled("pacemaker-execd", "env_var")); pcmk__mock_getenv = false; } static void disabled_false_value(void **state) { // Return false if option value is false (no daemon list) pcmk__mock_getenv = true; expect_string(__wrap_getenv, name, "PCMK_env_var"); will_return(__wrap_getenv, "false"); assert_false(pcmk__env_option_enabled(NULL, "env_var")); expect_string(__wrap_getenv, name, "PCMK_env_var"); will_return(__wrap_getenv, "false"); assert_false(pcmk__env_option_enabled("pacemaker-execd", "env_var")); pcmk__mock_getenv = false; } static void enabled_daemon_in_list(void **state) { // Return true if daemon is in the option's value pcmk__mock_getenv = true; expect_string(__wrap_getenv, name, "PCMK_env_var"); will_return(__wrap_getenv, "pacemaker-execd"); assert_true(pcmk__env_option_enabled("pacemaker-execd", "env_var")); expect_string(__wrap_getenv, name, "PCMK_env_var"); will_return(__wrap_getenv, "pacemaker-execd,pacemaker-fenced"); assert_true(pcmk__env_option_enabled("pacemaker-execd", "env_var")); expect_string(__wrap_getenv, name, "PCMK_env_var"); will_return(__wrap_getenv, "pacemaker-controld,pacemaker-execd"); assert_true(pcmk__env_option_enabled("pacemaker-execd", "env_var")); expect_string(__wrap_getenv, name, "PCMK_env_var"); will_return(__wrap_getenv, "pacemaker-controld,pacemaker-execd,pacemaker-fenced"); assert_true(pcmk__env_option_enabled("pacemaker-execd", "env_var")); pcmk__mock_getenv = false; } static void disabled_daemon_not_in_list(void **state) { // Return false if value is not true and daemon is not in the option's value pcmk__mock_getenv = true; expect_string(__wrap_getenv, name, "PCMK_env_var"); will_return(__wrap_getenv, "pacemaker-controld,pacemaker-fenced"); assert_false(pcmk__env_option_enabled("pacemaker-execd", "env_var")); pcmk__mock_getenv = false; } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(disabled_null_value), cmocka_unit_test(enabled_true_value), cmocka_unit_test(disabled_false_value), cmocka_unit_test(enabled_daemon_in_list), cmocka_unit_test(disabled_daemon_not_in_list)) diff --git a/lib/common/tests/options/pcmk__env_option_test.c b/lib/common/tests/options/pcmk__env_option_test.c index fc58e320af..2b85b68431 100644 --- a/lib/common/tests/options/pcmk__env_option_test.c +++ b/lib/common/tests/options/pcmk__env_option_test.c @@ -1,134 +1,134 @@ /* * Copyright 2022 the Pacemaker project contributors * * The version control history for this file may have further details. * - * This source code is licensed under the GNU Lesser General Public License - * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. */ #include #include #include "mock_private.h" static void empty_input_string(void **state) { pcmk__mock_getenv = true; // getenv() not called assert_null(pcmk__env_option(NULL)); assert_null(pcmk__env_option("")); pcmk__mock_getenv = false; } static void input_too_long_for_both(void **state) { /* pcmk__env_option() prepends "PCMK_" before lookup. If the option name is * too long for the buffer or isn't found in the env, then it prepends "HA_" * and tries again. A string of length (NAME_MAX - 3) will set us just over * just over the edge for both tries. */ char long_opt[NAME_MAX - 2]; for (int i = 0; i < NAME_MAX - 3; i++) { long_opt[i] = 'a'; } long_opt[NAME_MAX - 3] = '\0'; pcmk__mock_getenv = true; // getenv() not called assert_null(pcmk__env_option(long_opt)); pcmk__mock_getenv = false; } static void input_too_long_for_pcmk(void **state) { /* If an input is too long for "PCMK_