This source file includes following definitions.
- score1_minus_inf
- score2_minus_inf
- score1_pos_inf
- score2_pos_inf
- result_infinite
- result_finite
- main
1
2
3
4
5
6
7
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 {
21 assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, -CRM_SCORE_INFINITY), -CRM_SCORE_INFINITY);
22 assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, -1), -CRM_SCORE_INFINITY);
23 assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, 0), -CRM_SCORE_INFINITY);
24 assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, 1), -CRM_SCORE_INFINITY);
25 assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, CRM_SCORE_INFINITY), -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);
32 assert_int_equal(pcmk__add_scores(0, -CRM_SCORE_INFINITY), -CRM_SCORE_INFINITY);
33 assert_int_equal(pcmk__add_scores(1, -CRM_SCORE_INFINITY), -CRM_SCORE_INFINITY);
34 assert_int_equal(pcmk__add_scores(CRM_SCORE_INFINITY, -CRM_SCORE_INFINITY), -CRM_SCORE_INFINITY);
35 }
36
37 static void
38 score1_pos_inf(void **state)
39 {
40 assert_int_equal(pcmk__add_scores(CRM_SCORE_INFINITY, CRM_SCORE_INFINITY), CRM_SCORE_INFINITY);
41 assert_int_equal(pcmk__add_scores(CRM_SCORE_INFINITY, -1), CRM_SCORE_INFINITY);
42 assert_int_equal(pcmk__add_scores(CRM_SCORE_INFINITY, 0), CRM_SCORE_INFINITY);
43 assert_int_equal(pcmk__add_scores(CRM_SCORE_INFINITY, 1), CRM_SCORE_INFINITY);
44 }
45
46 static void
47 score2_pos_inf(void **state)
48 {
49 assert_int_equal(pcmk__add_scores(-1, CRM_SCORE_INFINITY), CRM_SCORE_INFINITY);
50 assert_int_equal(pcmk__add_scores(0, CRM_SCORE_INFINITY), CRM_SCORE_INFINITY);
51 assert_int_equal(pcmk__add_scores(1, CRM_SCORE_INFINITY), CRM_SCORE_INFINITY);
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 }