pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
compare_version_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU General Public License version 2
7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
13 
14 static void
15 empty_params(void **state)
16 {
17  assert_int_equal(compare_version(NULL, NULL), 0);
18  assert_int_equal(compare_version(NULL, "abc"), -1);
19  assert_int_equal(compare_version(NULL, "1.0.1"), -1);
20  assert_int_equal(compare_version("abc", NULL), 1);
21  assert_int_equal(compare_version("1.0.1", NULL), 1);
22 }
23 
24 static void
25 equal_versions(void **state)
26 {
27  assert_int_equal(compare_version("0.4.7", "0.4.7"), 0);
28  assert_int_equal(compare_version("1.0", "1.0"), 0);
29 }
30 
31 static void
32 unequal_versions(void **state)
33 {
34  assert_int_equal(compare_version("0.4.7", "0.4.8"), -1);
35  assert_int_equal(compare_version("0.4.8", "0.4.7"), 1);
36 
37  assert_int_equal(compare_version("0.2.3", "0.3"), -1);
38  assert_int_equal(compare_version("0.3", "0.2.3"), 1);
39 
40  assert_int_equal(compare_version("0.99", "1.0"), -1);
41  assert_int_equal(compare_version("1.0", "0.99"), 1);
42 }
43 
44 static void
45 shorter_versions(void **state)
46 {
47  assert_int_equal(compare_version("1.0", "1.0.1"), -1);
48  assert_int_equal(compare_version("1.0.1", "1.0"), 1);
49 }
50 
51 PCMK__UNIT_TEST(NULL, NULL,
52  cmocka_unit_test(empty_params),
53  cmocka_unit_test(equal_versions),
54  cmocka_unit_test(unequal_versions),
55  cmocka_unit_test(shorter_versions))
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(bad_input), cmocka_unit_test(not_found), cmocka_unit_test(find_attrB), cmocka_unit_test(find_attrA_matching))
int compare_version(const char *version1, const char *version2)
Definition: utils.c:189