This source file includes following definitions.
- invalid_params
- outside_limits
- inside_limits
- 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 invalid_params(void **state)
20 {
21 char *buf = malloc(9);
22
23 assert_null(score2char_stack(100, NULL, 9));
24 assert_null(score2char_stack(100, buf, 9));
25
26 free(buf);
27 }
28
29 static void
30 outside_limits(void **state)
31 {
32 char *buf = malloc(10);
33
34 buf = score2char_stack(CRM_SCORE_INFINITY * 2, buf, 10);
35 assert_string_equal(buf, CRM_INFINITY_S);
36
37 buf = score2char_stack(-CRM_SCORE_INFINITY * 2, buf, 10);
38 assert_string_equal(buf, CRM_MINUS_INFINITY_S);
39
40 free(buf);
41 }
42
43 static void
44 inside_limits(void **state)
45 {
46 char *buf = malloc(10);
47
48 buf = score2char_stack(0, buf, 10);
49 assert_string_equal(buf, "0");
50
51 buf = score2char_stack(1024, buf, 10);
52 assert_string_equal(buf, "1024");
53
54 buf = score2char_stack(-1024, buf, 10);
55 assert_string_equal(buf, "-1024");
56
57 free(buf);
58 }
59
60 int main(int argc, char **argv)
61 {
62 const struct CMUnitTest tests[] = {
63 cmocka_unit_test(invalid_params),
64 cmocka_unit_test(outside_limits),
65 cmocka_unit_test(inside_limits),
66 };
67
68 cmocka_set_message_output(CM_OUTPUT_TAP);
69 return cmocka_run_group_tests(tests, NULL, NULL);
70 }