source: vendor/current/lib/tdb/test/run-nested-traverse.c

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 2.2 KB
Line 
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"
21
22static struct agent *agent;
23
24static bool correct_key(TDB_DATA key)
25{
26 return key.dsize == strlen("hi")
27 && memcmp(key.dptr, "hi", key.dsize) == 0;
28}
29
30static bool correct_data(TDB_DATA data)
31{
32 return data.dsize == strlen("world")
33 && memcmp(data.dptr, "world", data.dsize) == 0;
34}
35
36static int traverse2(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
37 void *p)
38{
39 ok1(correct_key(key));
40 ok1(correct_data(data));
41 return 0;
42}
43
44static int traverse1(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
45 void *p)
46{
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);
52
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;
57}
58
59int main(int argc, char *argv[])
60{
61 struct tdb_context *tdb;
62 TDB_DATA key, data;
63
64 plan_tests(17);
65 agent = prepare_external_agent();
66
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);
70
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);
76
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");
81
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);
86
87 return exit_status();
88}
Note: See TracBrowser for help on using the repository browser.