s3:torture: call fault_setup() to get usage backtraces
[Samba/gebeck_regimport.git] / lib / ccan / asearch / test / run.c
blob2a896fccfe807c2c9a0ecb28dc1ea4d02e2b395b
1 #include <ccan/asearch/asearch.h>
2 #include <ccan/array_size/array_size.h>
3 #include <ccan/tap/tap.h>
4 #include <limits.h>
6 static int test_cmp(const int *key, const int *elt)
8 if (*key < *elt)
9 return -1;
10 else if (*key > *elt)
11 return 1;
12 return 0;
15 int main(void)
17 const int arr[] = { INT_MIN, 0, 1, 2, 3, 4, 5, 6, INT_MAX };
18 unsigned int start, num, i, total = 0;
19 int key;
21 plan_tests(285);
23 for (start = 0; start < ARRAY_SIZE(arr); start++) {
24 for (num = 0; num < ARRAY_SIZE(arr) - start; num++) {
25 key = 7;
26 ok1(asearch(&key, &arr[start], num, test_cmp) == NULL);
27 total++;
28 for (i = start; i < start+num; i++) {
29 const int *ret;
30 key = arr[i];
31 ret = asearch(&key, &arr[start], num, test_cmp);
32 ok1(ret);
33 ok1(ret && *ret == key);
34 total++;
38 diag("Tested %u searches\n", total);
39 return exit_status();