This source file includes following definitions.
- null_ptr
- no_numbers
- trailing_numbers
- middle_numbers
- unequal_lengths
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 null_ptr(void **state)
16 {
17 pcmk__assert_asserts(pcmk__numeric_strcasecmp(NULL, NULL));
18 pcmk__assert_asserts(pcmk__numeric_strcasecmp("a", NULL));
19 pcmk__assert_asserts(pcmk__numeric_strcasecmp(NULL, "a"));
20 }
21
22 static void
23 no_numbers(void **state)
24 {
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 assert_int_equal(pcmk__numeric_strcasecmp("AbCd", "eFgH"), -1);
31 assert_int_equal(pcmk__numeric_strcasecmp("ABCD", "abcd"), 0);
32 assert_int_equal(pcmk__numeric_strcasecmp("EFgh", "ABcd"), 1);
33 }
34
35 static void
36 trailing_numbers(void **state)
37 {
38 assert_int_equal(pcmk__numeric_strcasecmp("node1", "node2"), -1);
39 assert_int_equal(pcmk__numeric_strcasecmp("node1", "node1"), 0);
40 assert_int_equal(pcmk__numeric_strcasecmp("node2", "node1"), 1);
41
42 assert_int_equal(pcmk__numeric_strcasecmp("node1", "node10"), -1);
43 assert_int_equal(pcmk__numeric_strcasecmp("node10", "node10"), 0);
44 assert_int_equal(pcmk__numeric_strcasecmp("node10", "node1"), 1);
45
46 assert_int_equal(pcmk__numeric_strcasecmp("node10", "remotenode9"), -1);
47 assert_int_equal(pcmk__numeric_strcasecmp("remotenode9", "node10"), 1);
48
49
50 assert_int_equal(pcmk__numeric_strcasecmp("node001", "node1"), 1);
51 assert_int_equal(pcmk__numeric_strcasecmp("node1", "node001"), -1);
52 }
53
54 static void
55 middle_numbers(void **state)
56 {
57 assert_int_equal(pcmk__numeric_strcasecmp("node1abc", "node1def"), -1);
58 assert_int_equal(pcmk__numeric_strcasecmp("node1def", "node1abc"), 1);
59
60 assert_int_equal(pcmk__numeric_strcasecmp("node1abc", "node2abc"), -1);
61 assert_int_equal(pcmk__numeric_strcasecmp("node2abc", "node1abc"), 1);
62 }
63
64 static void
65 unequal_lengths(void **state)
66 {
67 assert_int_equal(pcmk__numeric_strcasecmp("node-ab", "node-abc"), -1);
68 assert_int_equal(pcmk__numeric_strcasecmp("node-abc", "node-ab"), 1);
69
70 assert_int_equal(pcmk__numeric_strcasecmp("node1ab", "node1abc"), -1);
71 assert_int_equal(pcmk__numeric_strcasecmp("node1abc", "node1ab"), 1);
72 }
73
74 PCMK__UNIT_TEST(NULL, NULL,
75 cmocka_unit_test(null_ptr),
76 cmocka_unit_test(no_numbers),
77 cmocka_unit_test(trailing_numbers),
78 cmocka_unit_test(middle_numbers),
79 cmocka_unit_test(unequal_lengths))