This source file includes following definitions.
- empty_params
- equal_versions
- unequal_versions
- shorter_versions
- 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 empty_params(void **state)
20 {
21 assert_int_equal(compare_version(NULL, NULL), 0);
22 assert_int_equal(compare_version(NULL, "abc"), -1);
23 assert_int_equal(compare_version(NULL, "1.0.1"), -1);
24 assert_int_equal(compare_version("abc", NULL), 1);
25 assert_int_equal(compare_version("1.0.1", NULL), 1);
26 }
27
28 static void
29 equal_versions(void **state)
30 {
31 assert_int_equal(compare_version("0.4.7", "0.4.7"), 0);
32 assert_int_equal(compare_version("1.0", "1.0"), 0);
33 }
34
35 static void
36 unequal_versions(void **state)
37 {
38 assert_int_equal(compare_version("0.4.7", "0.4.8"), -1);
39 assert_int_equal(compare_version("0.4.8", "0.4.7"), 1);
40
41 assert_int_equal(compare_version("0.2.3", "0.3"), -1);
42 assert_int_equal(compare_version("0.3", "0.2.3"), 1);
43
44 assert_int_equal(compare_version("0.99", "1.0"), -1);
45 assert_int_equal(compare_version("1.0", "0.99"), 1);
46 }
47
48 static void
49 shorter_versions(void **state)
50 {
51 assert_int_equal(compare_version("1.0", "1.0.1"), -1);
52 assert_int_equal(compare_version("1.0.1", "1.0"), 1);
53 }
54
55 int main(int argc, char **argv)
56 {
57 const struct CMUnitTest tests[] = {
58 cmocka_unit_test(empty_params),
59 cmocka_unit_test(equal_versions),
60 cmocka_unit_test(unequal_versions),
61 cmocka_unit_test(shorter_versions),
62 };
63
64 cmocka_set_message_output(CM_OUTPUT_TAP);
65 return cmocka_run_group_tests(tests, NULL, NULL);
66 }