tdb: don't use err.h in tests.
[Samba/gebeck_regimport.git] / lib / tdb / test / run-traverse-in-transaction.c
blob7813a6ce9a544f4bec960e0b112fdea109c592b6
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();
50 if (!agent)
51 err(1, "preparing agent");
53 tdb = tdb_open_ex("run-traverse-in-transaction.tdb",
54 1024, TDB_CLEAR_IF_FIRST, O_CREAT|O_TRUNC|O_RDWR,
55 0600, &taplogctx, NULL);
56 ok1(tdb);
58 key.dsize = strlen("hi");
59 key.dptr = (void *)"hi";
60 data.dptr = (void *)"world";
61 data.dsize = strlen("world");
63 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
65 ok1(external_agent_operation(agent, OPEN, tdb_name(tdb)) == SUCCESS);
67 ok1(tdb_transaction_start(tdb) == 0);
68 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
69 == WOULD_HAVE_BLOCKED);
70 tdb_traverse(tdb, traverse, NULL);
72 /* That should *not* release the transaction lock! */
73 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
74 == WOULD_HAVE_BLOCKED);
75 tdb_traverse_read(tdb, traverse, NULL);
77 /* That should *not* release the transaction lock! */
78 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
79 == WOULD_HAVE_BLOCKED);
80 ok1(tdb_transaction_commit(tdb) == 0);
81 /* Now we should be fine. */
82 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
83 == SUCCESS);
85 tdb_close(tdb);
87 return exit_status();