Raw
1 #include "unit-test.h"
2 #include "read-cache-ll.h"
3
4 static void check_strcmp_offset(const char *string1, const char *string2,
5 int expect_result, uintmax_t expect_offset)
6 {
7 size_t offset;
8 int result = strcmp_offset(string1, string2, &offset);
9
10 /*
11 * Because different CRTs behave differently, only rely on signs of the
12 * result values.
13 */
14 result = (result < 0 ? -1 :
15 result > 0 ? 1 :
16 0);
17
18 cl_assert_equal_i(result, expect_result);
19 cl_assert_equal_i((uintmax_t)offset, expect_offset);
20 }
21
22 void test_strcmp_offset__empty(void)
23 {
24 check_strcmp_offset("", "", 0, 0);
25 }
26
27 void test_strcmp_offset__equal(void)
28 {
29 check_strcmp_offset("abc", "abc", 0, 3);
30 }
31
32 void test_strcmp_offset__different(void)
33 {
34 check_strcmp_offset("abc", "def", -1, 0);
35 }
36
37 void test_strcmp_offset__mismatch(void)
38 {
39 check_strcmp_offset("abc", "abz", -1, 2);
40 }
41
42 void test_strcmp_offset__different_length(void)
43 {
44 check_strcmp_offset("abc", "abcdef", -1, 3);
45 }