smbd: Obsolete MSG_SMB_OPEN_RETRY
[Samba.git] / lib / tdb / test / run-nested-traverse.c
blob37d57c012581eb841aa2d6d3c336b89e363907ea
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 "tap-interface.h"
15 #undef fcntl
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 traverse2(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 static int traverse1(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
44 void *p)
46 ok1(correct_key(key));
47 ok1(correct_data(data));
48 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
49 == WOULD_HAVE_BLOCKED);
50 tdb_traverse(tdb, traverse2, NULL);
52 /* That should *not* release the transaction lock! */
53 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
54 == WOULD_HAVE_BLOCKED);
55 return 0;
58 int main(int argc, char *argv[])
60 struct tdb_context *tdb;
61 TDB_DATA key, data;
63 plan_tests(17);
64 agent = prepare_external_agent();
66 tdb = tdb_open_ex("run-nested-traverse.tdb", 1024, TDB_CLEAR_IF_FIRST,
67 O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
68 ok1(tdb);
70 ok1(external_agent_operation(agent, OPEN, tdb_name(tdb)) == SUCCESS);
71 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
72 == SUCCESS);
73 ok1(external_agent_operation(agent, TRANSACTION_COMMIT, tdb_name(tdb))
74 == SUCCESS);
76 key.dsize = strlen("hi");
77 key.dptr = (void *)"hi";
78 data.dptr = (void *)"world";
79 data.dsize = strlen("world");
81 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
82 tdb_traverse(tdb, traverse1, NULL);
83 tdb_traverse_read(tdb, traverse1, NULL);
84 tdb_close(tdb);
86 return exit_status();