tdb: add tdb_rescue()
[samba.git] / lib / tdb / test / run-rescue-find_entry.c
1 #include "../common/tdb_private.h"
2 #include "../common/io.c"
3 #include "../common/tdb.c"
4 #include "../common/lock.c"
5 #include "../common/freelist.c"
6 #include "../common/traverse.c"
7 #include "../common/transaction.c"
8 #include "../common/error.c"
9 #include "../common/open.c"
10 #include "../common/check.c"
11 #include "../common/hash.c"
12 #include "../common/rescue.c"
13 #include "tap-interface.h"
14 #include <stdlib.h>
15 #include "logging.h"
16
17 #define NUM 20
18
19 /* Binary searches are deceptively simple: easy to screw up! */
20 int main(int argc, char *argv[])
21 {
22         unsigned int i, j, n;
23         struct found f[NUM+1];
24         struct found_table table;
25
26         /* Set up array for searching. */
27         for (i = 0; i < NUM+1; i++) {
28                 f[i].head = i * 3;
29         }
30         table.arr = f;
31
32         for (i = 0; i < NUM; i++) {
33                 table.num = i;
34                 for (j = 0; j < (i + 2) * 3; j++) {
35                         n = find_entry(&table, j);
36                         ok1(n <= i);
37
38                         /* If we were searching for something too large... */
39                         if (j > i*3)
40                                 ok1(n == i);
41                         else {
42                                 /* It must give us something after j */
43                                 ok1(f[n].head >= j);
44                                 ok1(n == 0 || f[n-1].head < j);
45                         }
46                 }
47         }
48
49         return exit_status();
50 }