2 Copyright 2020 Google LLC
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file or at
6 https://developers.google.com/open-source/licenses/bsd
12 #include "test_framework.h"
13 #include "reftable-tests.h"
15 struct integer_needle_lesseq_args
{
20 static int integer_needle_lesseq(size_t i
, void *_args
)
22 struct integer_needle_lesseq_args
*args
= _args
;
23 return args
->needle
<= args
->haystack
[i
];
26 static void test_binsearch(void)
28 int haystack
[] = { 2, 4, 6, 8, 10 };
47 for (i
= 0; i
< ARRAY_SIZE(testcases
); i
++) {
48 struct integer_needle_lesseq_args args
= {
50 .needle
= testcases
[i
].needle
,
54 idx
= binsearch(ARRAY_SIZE(haystack
), &integer_needle_lesseq
, &args
);
55 EXPECT(idx
== testcases
[i
].expected_idx
);
59 static void test_names_length(void)
61 char *a
[] = { "a", "b", NULL
};
62 EXPECT(names_length(a
) == 2);
65 static void test_parse_names_normal(void)
69 parse_names(in
, strlen(in
), &out
);
70 EXPECT(!strcmp(out
[0], "a"));
71 EXPECT(!strcmp(out
[1], "b"));
76 static void test_parse_names_drop_empty(void)
80 parse_names(in
, strlen(in
), &out
);
81 EXPECT(!strcmp(out
[0], "a"));
86 static void test_common_prefix(void)
88 struct strbuf s1
= STRBUF_INIT
;
89 struct strbuf s2
= STRBUF_INIT
;
90 strbuf_addstr(&s1
, "abcdef");
91 strbuf_addstr(&s2
, "abc");
92 EXPECT(common_prefix_size(&s1
, &s2
) == 3);
97 int basics_test_main(int argc
, const char *argv
[])
99 RUN_TEST(test_common_prefix
);
100 RUN_TEST(test_parse_names_normal
);
101 RUN_TEST(test_parse_names_drop_empty
);
102 RUN_TEST(test_binsearch
);
103 RUN_TEST(test_names_length
);