s3:lib/events: s/EVENT_FD/TEVENT_FD
[Samba/gebeck_regimport.git] / lib / tdb / test / run-traverse-in-transaction.c
blobbcdc3545cd5b27148e8d118c0d4e95977a4d3470
1 #include "lock-tracking.h"
2 #include "../common/tdb_private.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 "tap-interface.h"
15 #undef fcntl_with_lockcheck
16 #include <stdlib.h>
17 #include <stdbool.h>
18 #include "external-agent.h"
19 #include "logging.h"
21 static struct agent *agent;
23 static bool correct_key(TDB_DATA key)
25 return key.dsize == strlen("hi")
26 && memcmp(key.dptr, "hi", key.dsize) == 0;
29 static bool correct_data(TDB_DATA data)
31 return data.dsize == strlen("world")
32 && memcmp(data.dptr, "world", data.dsize) == 0;
35 static int traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
36 void *p)
38 ok1(correct_key(key));
39 ok1(correct_data(data));
40 return 0;
43 int main(int argc, char *argv[])
45 struct tdb_context *tdb;
46 TDB_DATA key, data;
48 plan_tests(13);
49 agent = prepare_external_agent();
51 tdb = tdb_open_ex("run-traverse-in-transaction.tdb",
52 1024, TDB_CLEAR_IF_FIRST, O_CREAT|O_TRUNC|O_RDWR,
53 0600, &taplogctx, NULL);
54 ok1(tdb);
56 key.dsize = strlen("hi");
57 key.dptr = (void *)"hi";
58 data.dptr = (void *)"world";
59 data.dsize = strlen("world");
61 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
63 ok1(external_agent_operation(agent, OPEN, tdb_name(tdb)) == SUCCESS);
65 ok1(tdb_transaction_start(tdb) == 0);
66 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
67 == WOULD_HAVE_BLOCKED);
68 tdb_traverse(tdb, traverse, NULL);
70 /* That should *not* release the transaction lock! */
71 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
72 == WOULD_HAVE_BLOCKED);
73 tdb_traverse_read(tdb, traverse, NULL);
75 /* That should *not* release the transaction lock! */
76 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
77 == WOULD_HAVE_BLOCKED);
78 ok1(tdb_transaction_commit(tdb) == 0);
79 /* Now we should be fine. */
80 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
81 == SUCCESS);
83 tdb_close(tdb);
85 return exit_status();