pacemaker  2.1.4-dc6eb4362
Scalable High-Availability cluster resource manager
pcmk__add_scores_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022 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 Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
12 #include <stdarg.h>
13 #include <stddef.h>
14 #include <stdint.h>
15 #include <setjmp.h>
16 #include <cmocka.h>
17 
18 static void
19 score1_minus_inf(void **state)
20 {
22  assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, -1), -CRM_SCORE_INFINITY);
26 }
27 
28 static void
29 score2_minus_inf(void **state)
30 {
31  assert_int_equal(pcmk__add_scores(-1, -CRM_SCORE_INFINITY), -CRM_SCORE_INFINITY);
35 }
36 
37 static void
38 score1_pos_inf(void **state)
39 {
44 }
45 
46 static void
47 score2_pos_inf(void **state)
48 {
52 }
53 
54 static void
55 result_infinite(void **state)
56 {
57  assert_int_equal(pcmk__add_scores(INT_MAX, INT_MAX), CRM_SCORE_INFINITY);
58  assert_int_equal(pcmk__add_scores(INT_MIN, INT_MIN), -CRM_SCORE_INFINITY);
59  assert_int_equal(pcmk__add_scores(2000000, 50), CRM_SCORE_INFINITY);
60  assert_int_equal(pcmk__add_scores(-4000000, 50), -CRM_SCORE_INFINITY);
61 }
62 
63 static void
64 result_finite(void **state)
65 {
66  assert_int_equal(pcmk__add_scores(0, 0), 0);
67  assert_int_equal(pcmk__add_scores(0, 100), 100);
68  assert_int_equal(pcmk__add_scores(200, 0), 200);
69  assert_int_equal(pcmk__add_scores(200, -50), 150);
70 }
71 
72 int main(int argc, char **argv)
73 {
74  const struct CMUnitTest tests[] = {
75  cmocka_unit_test(score1_minus_inf),
76  cmocka_unit_test(score2_minus_inf),
77  cmocka_unit_test(score1_pos_inf),
78  cmocka_unit_test(score2_pos_inf),
79  cmocka_unit_test(result_infinite),
80  cmocka_unit_test(result_finite),
81  };
82 
83  cmocka_set_message_output(CM_OUTPUT_TAP);
84  return cmocka_run_group_tests(tests, NULL, NULL);
85 }
#define CRM_SCORE_INFINITY
Definition: crm.h:85
int pcmk__add_scores(int score1, int score2)
Definition: scores.c:140
int main(int argc, char **argv)