This source file includes following definitions.
- no_numbers
- trailing_numbers
- middle_numbers
- unequal_lengths
- 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 no_numbers(void **state)
20 {
21
22 assert_int_equal(pcmk__numeric_strcasecmp("abcd", "efgh"), -1);
23 assert_int_equal(pcmk__numeric_strcasecmp("abcd", "abcd"), 0);
24 assert_int_equal(pcmk__numeric_strcasecmp("efgh", "abcd"), 1);
25
26 assert_int_equal(pcmk__numeric_strcasecmp("AbCd", "eFgH"), -1);
27 assert_int_equal(pcmk__numeric_strcasecmp("ABCD", "abcd"), 0);
28 assert_int_equal(pcmk__numeric_strcasecmp("EFgh", "ABcd"), 1);
29 }
30
31 static void
32 trailing_numbers(void **state)
33 {
34 assert_int_equal(pcmk__numeric_strcasecmp("node1", "node2"), -1);
35 assert_int_equal(pcmk__numeric_strcasecmp("node1", "node1"), 0);
36 assert_int_equal(pcmk__numeric_strcasecmp("node2", "node1"), 1);
37
38 assert_int_equal(pcmk__numeric_strcasecmp("node1", "node10"), -1);
39 assert_int_equal(pcmk__numeric_strcasecmp("node10", "node10"), 0);
40 assert_int_equal(pcmk__numeric_strcasecmp("node10", "node1"), 1);
41
42 assert_int_equal(pcmk__numeric_strcasecmp("node10", "remotenode9"), -1);
43 assert_int_equal(pcmk__numeric_strcasecmp("remotenode9", "node10"), 1);
44
45
46 assert_int_equal(pcmk__numeric_strcasecmp("node001", "node1"), 1);
47 assert_int_equal(pcmk__numeric_strcasecmp("node1", "node001"), -1);
48 }
49
50 static void
51 middle_numbers(void **state)
52 {
53 assert_int_equal(pcmk__numeric_strcasecmp("node1abc", "node1def"), -1);
54 assert_int_equal(pcmk__numeric_strcasecmp("node1def", "node1abc"), 1);
55
56 assert_int_equal(pcmk__numeric_strcasecmp("node1abc", "node2abc"), -1);
57 assert_int_equal(pcmk__numeric_strcasecmp("node2abc", "node1abc"), 1);
58 }
59
60 static void
61 unequal_lengths(void **state)
62 {
63 assert_int_equal(pcmk__numeric_strcasecmp("node-ab", "node-abc"), -1);
64 assert_int_equal(pcmk__numeric_strcasecmp("node-abc", "node-ab"), 1);
65
66 assert_int_equal(pcmk__numeric_strcasecmp("node1ab", "node1abc"), -1);
67 assert_int_equal(pcmk__numeric_strcasecmp("node1abc", "node1ab"), 1);
68 }
69
70 int
71 main(int argc, char **argv)
72 {
73 const struct CMUnitTest tests[] = {
74 cmocka_unit_test(no_numbers),
75 cmocka_unit_test(trailing_numbers),
76 cmocka_unit_test(middle_numbers),
77 cmocka_unit_test(unequal_lengths),
78 };
79
80 cmocka_set_message_output(CM_OUTPUT_TAP);
81 return cmocka_run_group_tests(tests, NULL, NULL);
82 }