This source file includes following definitions.
- score1_minus_inf
- score2_minus_inf
- score1_pos_inf
- score2_pos_inf
- result_infinite
- result_finite
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
13
14 static void
15 score1_minus_inf(void **state)
16 {
17 assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, -CRM_SCORE_INFINITY), -CRM_SCORE_INFINITY);
18 assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, -1), -CRM_SCORE_INFINITY);
19 assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, 0), -CRM_SCORE_INFINITY);
20 assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, 1), -CRM_SCORE_INFINITY);
21 assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, CRM_SCORE_INFINITY), -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);
28 assert_int_equal(pcmk__add_scores(0, -CRM_SCORE_INFINITY), -CRM_SCORE_INFINITY);
29 assert_int_equal(pcmk__add_scores(1, -CRM_SCORE_INFINITY), -CRM_SCORE_INFINITY);
30 assert_int_equal(pcmk__add_scores(CRM_SCORE_INFINITY, -CRM_SCORE_INFINITY), -CRM_SCORE_INFINITY);
31 }
32
33 static void
34 score1_pos_inf(void **state)
35 {
36 assert_int_equal(pcmk__add_scores(CRM_SCORE_INFINITY, CRM_SCORE_INFINITY), CRM_SCORE_INFINITY);
37 assert_int_equal(pcmk__add_scores(CRM_SCORE_INFINITY, -1), CRM_SCORE_INFINITY);
38 assert_int_equal(pcmk__add_scores(CRM_SCORE_INFINITY, 0), CRM_SCORE_INFINITY);
39 assert_int_equal(pcmk__add_scores(CRM_SCORE_INFINITY, 1), CRM_SCORE_INFINITY);
40 }
41
42 static void
43 score2_pos_inf(void **state)
44 {
45 assert_int_equal(pcmk__add_scores(-1, CRM_SCORE_INFINITY), CRM_SCORE_INFINITY);
46 assert_int_equal(pcmk__add_scores(0, CRM_SCORE_INFINITY), CRM_SCORE_INFINITY);
47 assert_int_equal(pcmk__add_scores(1, CRM_SCORE_INFINITY), CRM_SCORE_INFINITY);
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);
56 assert_int_equal(pcmk__add_scores(-4000000, 50), -CRM_SCORE_INFINITY);
57 }
58
59 static void
60 result_finite(void **state)
61 {
62 assert_int_equal(pcmk__add_scores(0, 0), 0);
63 assert_int_equal(pcmk__add_scores(0, 100), 100);
64 assert_int_equal(pcmk__add_scores(200, 0), 200);
65 assert_int_equal(pcmk__add_scores(200, -50), 150);
66 }
67
68 PCMK__UNIT_TEST(NULL, NULL,
69 cmocka_unit_test(score1_minus_inf),
70 cmocka_unit_test(score2_minus_inf),
71 cmocka_unit_test(score1_pos_inf),
72 cmocka_unit_test(score2_pos_inf),
73 cmocka_unit_test(result_infinite),
74 cmocka_unit_test(result_finite))