pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
pcmk__add_scores_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022-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 
13 
14 static void
15 score1_minus_inf(void **state)
16 {
18  assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, -1), -CRM_SCORE_INFINITY);
22 }
23 
24 static void
25 score2_minus_inf(void **state)
26 {
27  assert_int_equal(pcmk__add_scores(-1, -CRM_SCORE_INFINITY), -CRM_SCORE_INFINITY);
31 }
32 
33 static void
34 score1_pos_inf(void **state)
35 {
40 }
41 
42 static void
43 score2_pos_inf(void **state)
44 {
48 }
49 
50 static void
51 result_infinite(void **state)
52 {
53  assert_int_equal(pcmk__add_scores(INT_MAX, INT_MAX), CRM_SCORE_INFINITY);
54  assert_int_equal(pcmk__add_scores(INT_MIN, INT_MIN), -CRM_SCORE_INFINITY);
55  assert_int_equal(pcmk__add_scores(2000000, 50), CRM_SCORE_INFINITY);
58  assert_int_equal(pcmk__add_scores(-4000000, 50), -CRM_SCORE_INFINITY);
59 }
60 
61 static void
62 result_finite(void **state)
63 {
64  assert_int_equal(pcmk__add_scores(0, 0), 0);
65  assert_int_equal(pcmk__add_scores(0, 100), 100);
66  assert_int_equal(pcmk__add_scores(200, 0), 200);
67  assert_int_equal(pcmk__add_scores(200, -50), 150);
68 }
69 
70 PCMK__UNIT_TEST(NULL, NULL,
71  cmocka_unit_test(score1_minus_inf),
72  cmocka_unit_test(score2_minus_inf),
73  cmocka_unit_test(score1_pos_inf),
74  cmocka_unit_test(score2_pos_inf),
75  cmocka_unit_test(result_infinite),
76  cmocka_unit_test(result_finite))
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(bad_input), cmocka_unit_test(not_found), cmocka_unit_test(find_attrB), cmocka_unit_test(find_attrA_matching))
#define CRM_SCORE_INFINITY
Definition: crm.h:84
int pcmk__add_scores(int score1, int score2)
Definition: scores.c:116