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 binsearch_args
{
20 static int binsearch_func(size_t i
, void *void_args
)
22 struct binsearch_args
*args
= void_args
;
24 return args
->key
< args
->arr
[i
];
27 static void test_binsearch(void)
29 int arr
[] = { 2, 4, 6, 8, 10 };
30 size_t sz
= ARRAY_SIZE(arr
);
31 struct binsearch_args args
= {
36 for (i
= 1; i
< 11; i
++) {
39 res
= binsearch(sz
, &binsearch_func
, &args
);
42 EXPECT(args
.key
< arr
[res
]);
44 EXPECT(args
.key
>= arr
[res
- 1]);
47 EXPECT(args
.key
== 10 || args
.key
== 11);
52 static void test_names_length(void)
54 char *a
[] = { "a", "b", NULL
};
55 EXPECT(names_length(a
) == 2);
58 static void test_parse_names_normal(void)
62 parse_names(in
, strlen(in
), &out
);
63 EXPECT(!strcmp(out
[0], "a"));
64 EXPECT(!strcmp(out
[1], "b"));
69 static void test_parse_names_drop_empty(void)
73 parse_names(in
, strlen(in
), &out
);
74 EXPECT(!strcmp(out
[0], "a"));
79 static void test_common_prefix(void)
81 struct strbuf s1
= STRBUF_INIT
;
82 struct strbuf s2
= STRBUF_INIT
;
83 strbuf_addstr(&s1
, "abcdef");
84 strbuf_addstr(&s2
, "abc");
85 EXPECT(common_prefix_size(&s1
, &s2
) == 3);
90 int basics_test_main(int argc
, const char *argv
[])
92 RUN_TEST(test_common_prefix
);
93 RUN_TEST(test_parse_names_normal
);
94 RUN_TEST(test_parse_names_drop_empty
);
95 RUN_TEST(test_binsearch
);
96 RUN_TEST(test_names_length
);