diff --git a/lib/pengine/tests/utils/Makefile.am b/lib/pengine/tests/utils/Makefile.am index 74def73707..4a3e8a256e 100644 --- a/lib/pengine/tests/utils/Makefile.am +++ b/lib/pengine/tests/utils/Makefile.am @@ -1,18 +1,21 @@ # # 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 General Public License version 2 # or later (GPLv2+) WITHOUT ANY WARRANTY. # include $(top_srcdir)/mk/tap.mk include $(top_srcdir)/mk/unittest.mk +AM_CPPFLAGS += -I$(top_srcdir)/lib/pengine LDADD += $(top_builddir)/lib/pengine/libpe_status_test.la # Add "_test" to the end of all test program names to simplify .gitignore. -check_PROGRAMS = pe__cmp_node_name_test +check_PROGRAMS = \ + pe__cmp_node_name_test \ + pe__cmp_rsc_priority_test TESTS = $(check_PROGRAMS) diff --git a/lib/pengine/tests/utils/pe__cmp_rsc_priority_test.c b/lib/pengine/tests/utils/pe__cmp_rsc_priority_test.c new file mode 100644 index 0000000000..07ce301767 --- /dev/null +++ b/lib/pengine/tests/utils/pe__cmp_rsc_priority_test.c @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#include + +#include +#include + +#include "pe_status_private.h" + +pe_resource_t rsc1; +pe_resource_t rsc2; + +static void +rscs_equal(void **state) +{ + rsc1.priority = 0; + rsc2.priority = 0; + assert_int_equal(pe__cmp_rsc_priority(NULL, NULL), 0); + assert_int_equal(pe__cmp_rsc_priority(&rsc1, &rsc2), 0); +} + +static void +rsc1_first(void **state) +{ + rsc1.priority = 1; + rsc2.priority = 0; + assert_int_equal(pe__cmp_rsc_priority(&rsc1, NULL), -1); + assert_int_equal(pe__cmp_rsc_priority(&rsc1, &rsc2), -1); +} + +static void +rsc2_first(void **state) +{ + rsc1.priority = 0; + rsc2.priority = 1; + assert_int_equal(pe__cmp_rsc_priority(NULL, &rsc2), 1); + assert_int_equal(pe__cmp_rsc_priority(&rsc1, &rsc2), 1); +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(rscs_equal), + cmocka_unit_test(rsc1_first), + cmocka_unit_test(rsc2_first))