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(-PCMK_SCORE_INFINITY,
18 -PCMK_SCORE_INFINITY),
19 -PCMK_SCORE_INFINITY);
20 assert_int_equal(pcmk__add_scores(-PCMK_SCORE_INFINITY, -1),
21 -PCMK_SCORE_INFINITY);
22 assert_int_equal(pcmk__add_scores(-PCMK_SCORE_INFINITY, 0),
23 -PCMK_SCORE_INFINITY);
24 assert_int_equal(pcmk__add_scores(-PCMK_SCORE_INFINITY, 1),
25 -PCMK_SCORE_INFINITY);
26 assert_int_equal(pcmk__add_scores(-PCMK_SCORE_INFINITY,
27 PCMK_SCORE_INFINITY),
28 -PCMK_SCORE_INFINITY);
29 }
30
31 static void
32 score2_minus_inf(void **state)
33 {
34 assert_int_equal(pcmk__add_scores(-1, -PCMK_SCORE_INFINITY),
35 -PCMK_SCORE_INFINITY);
36 assert_int_equal(pcmk__add_scores(0, -PCMK_SCORE_INFINITY),
37 -PCMK_SCORE_INFINITY);
38 assert_int_equal(pcmk__add_scores(1, -PCMK_SCORE_INFINITY),
39 -PCMK_SCORE_INFINITY);
40 assert_int_equal(pcmk__add_scores(PCMK_SCORE_INFINITY,
41 -PCMK_SCORE_INFINITY),
42 -PCMK_SCORE_INFINITY);
43 }
44
45 static void
46 score1_pos_inf(void **state)
47 {
48 assert_int_equal(pcmk__add_scores(PCMK_SCORE_INFINITY, PCMK_SCORE_INFINITY),
49 PCMK_SCORE_INFINITY);
50 assert_int_equal(pcmk__add_scores(PCMK_SCORE_INFINITY, -1),
51 PCMK_SCORE_INFINITY);
52 assert_int_equal(pcmk__add_scores(PCMK_SCORE_INFINITY, 0),
53 PCMK_SCORE_INFINITY);
54 assert_int_equal(pcmk__add_scores(PCMK_SCORE_INFINITY, 1),
55 PCMK_SCORE_INFINITY);
56 }
57
58 static void
59 score2_pos_inf(void **state)
60 {
61 assert_int_equal(pcmk__add_scores(-1, PCMK_SCORE_INFINITY),
62 PCMK_SCORE_INFINITY);
63 assert_int_equal(pcmk__add_scores(0, PCMK_SCORE_INFINITY),
64 PCMK_SCORE_INFINITY);
65 assert_int_equal(pcmk__add_scores(1, PCMK_SCORE_INFINITY),
66 PCMK_SCORE_INFINITY);
67 }
68
69 static void
70 result_infinite(void **state)
71 {
72 assert_int_equal(pcmk__add_scores(INT_MAX, INT_MAX), PCMK_SCORE_INFINITY);
73 assert_int_equal(pcmk__add_scores(INT_MIN, INT_MIN), -PCMK_SCORE_INFINITY);
74 assert_int_equal(pcmk__add_scores(2000000, 50), PCMK_SCORE_INFINITY);
75 assert_int_equal(pcmk__add_scores(PCMK_SCORE_INFINITY/2,
76 PCMK_SCORE_INFINITY/2),
77 PCMK_SCORE_INFINITY);
78 assert_int_equal(pcmk__add_scores(-PCMK_SCORE_INFINITY/2,
79 -PCMK_SCORE_INFINITY/2),
80 -PCMK_SCORE_INFINITY);
81 assert_int_equal(pcmk__add_scores(-4000000, 50), -PCMK_SCORE_INFINITY);
82 }
83
84 static void
85 result_finite(void **state)
86 {
87 assert_int_equal(pcmk__add_scores(0, 0), 0);
88 assert_int_equal(pcmk__add_scores(0, 100), 100);
89 assert_int_equal(pcmk__add_scores(200, 0), 200);
90 assert_int_equal(pcmk__add_scores(200, -50), 150);
91 }
92
93 PCMK__UNIT_TEST(NULL, NULL,
94 cmocka_unit_test(score1_minus_inf),
95 cmocka_unit_test(score2_minus_inf),
96 cmocka_unit_test(score1_pos_inf),
97 cmocka_unit_test(score2_pos_inf),
98 cmocka_unit_test(result_infinite),
99 cmocka_unit_test(result_finite))