debug: Fix a typo
[Samba.git] / lib / tdb / test / run-nested-traverse.c
blob22ee3e2a2a625b5f974c75d09d2dfd8ea491adf1
1 #include "../common/tdb_private.h"
2 #include "lock-tracking.h"
3 #define fcntl fcntl_with_lockcheck
4 #include "../common/io.c"
5 #include "../common/tdb.c"
6 #include "../common/lock.c"
7 #include "../common/freelist.c"
8 #include "../common/traverse.c"
9 #include "../common/transaction.c"
10 #include "../common/error.c"
11 #include "../common/open.c"
12 #include "../common/check.c"
13 #include "../common/hash.c"
14 #include "../common/mutex.c"
15 #include "tap-interface.h"
16 #undef fcntl
17 #include <stdlib.h>
18 #include <stdbool.h>
19 #include "external-agent.h"
20 #include "logging.h"
22 static struct agent *agent;
24 static bool correct_key(TDB_DATA key)
26 return key.dsize == strlen("hi")
27 && memcmp(key.dptr, "hi", key.dsize) == 0;
30 static bool correct_data(TDB_DATA data)
32 return data.dsize == strlen("world")
33 && memcmp(data.dptr, "world", data.dsize) == 0;
36 static int traverse2(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
37 void *p)
39 ok1(correct_key(key));
40 ok1(correct_data(data));
41 return 0;
44 static int traverse1(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
45 void *p)
47 ok1(correct_key(key));
48 ok1(correct_data(data));
49 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
50 == WOULD_HAVE_BLOCKED);
51 tdb_traverse(tdb, traverse2, NULL);
53 /* That should *not* release the transaction lock! */
54 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
55 == WOULD_HAVE_BLOCKED);
56 return 0;
59 int main(int argc, char *argv[])
61 struct tdb_context *tdb;
62 TDB_DATA key, data;
64 plan_tests(17);
65 agent = prepare_external_agent();
67 tdb = tdb_open_ex("run-nested-traverse.tdb", 1024, TDB_CLEAR_IF_FIRST,
68 O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
69 ok1(tdb);
71 ok1(external_agent_operation(agent, OPEN, tdb_name(tdb)) == SUCCESS);
72 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
73 == SUCCESS);
74 ok1(external_agent_operation(agent, TRANSACTION_COMMIT, tdb_name(tdb))
75 == SUCCESS);
77 key.dsize = strlen("hi");
78 key.dptr = discard_const_p(uint8_t, "hi");
79 data.dptr = discard_const_p(uint8_t, "world");
80 data.dsize = strlen("world");
82 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
83 tdb_traverse(tdb, traverse1, NULL);
84 tdb_traverse_read(tdb, traverse1, NULL);
85 tdb_close(tdb);
87 return exit_status();