1 #include <ccan/tdb2/tdb2.h>
2 #include <ccan/tap/tap.h>
9 int main(int argc
, char *argv
[])
12 struct tdb_context
*tdb
;
13 struct tdb_data d
= { NULL
, 0 }; /* Bogus GCC warning */
14 struct tdb_data key
= tdb_mkdata("key", 3);
15 struct tdb_data data
= tdb_mkdata("data", 4);
16 int flags
[] = { TDB_INTERNAL
, TDB_DEFAULT
, TDB_NOMMAP
,
17 TDB_INTERNAL
|TDB_CONVERT
, TDB_CONVERT
,
18 TDB_NOMMAP
|TDB_CONVERT
,
19 TDB_INTERNAL
|TDB_VERSION1
, TDB_VERSION1
,
20 TDB_NOMMAP
|TDB_VERSION1
,
21 TDB_INTERNAL
|TDB_CONVERT
|TDB_VERSION1
,
22 TDB_CONVERT
|TDB_VERSION1
,
23 TDB_NOMMAP
|TDB_CONVERT
|TDB_VERSION1
};
25 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * 15 + 8 * 13);
26 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
27 tdb
= tdb_open("api-81-seqnum.tdb", flags
[i
]|TDB_SEQNUM
,
28 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &tap_log_attr
);
33 ok1(tdb_get_seqnum(tdb
) == seq
);
34 ok1(tdb_store(tdb
, key
, data
, TDB_INSERT
) == 0);
35 ok1(tdb_get_seqnum(tdb
) == ++seq
);
36 /* Fetch doesn't change seqnum */
37 if (ok1(tdb_fetch(tdb
, key
, &d
) == TDB_SUCCESS
))
39 ok1(tdb_get_seqnum(tdb
) == seq
);
40 ok1(tdb_append(tdb
, key
, data
) == TDB_SUCCESS
);
41 /* Append in tdb1 (or store over value) bumps twice! */
42 if (flags
[i
] & TDB_VERSION1
)
44 ok1(tdb_get_seqnum(tdb
) == ++seq
);
46 ok1(tdb_delete(tdb
, key
) == TDB_SUCCESS
);
47 ok1(tdb_get_seqnum(tdb
) == ++seq
);
48 /* Empty append works */
49 ok1(tdb_append(tdb
, key
, data
) == TDB_SUCCESS
);
50 ok1(tdb_get_seqnum(tdb
) == ++seq
);
52 ok1(tdb_wipe_all(tdb
) == TDB_SUCCESS
);
53 ok1(tdb_get_seqnum(tdb
) == ++seq
);
55 if (!(flags
[i
] & TDB_INTERNAL
)) {
56 ok1(tdb_transaction_start(tdb
) == TDB_SUCCESS
);
57 ok1(tdb_store(tdb
, key
, data
, TDB_INSERT
) == 0);
58 ok1(tdb_get_seqnum(tdb
) == ++seq
);
59 /* Append in tdb1 (or store over value) bumps twice! */
60 if (flags
[i
] & TDB_VERSION1
)
62 ok1(tdb_append(tdb
, key
, data
) == TDB_SUCCESS
);
63 ok1(tdb_get_seqnum(tdb
) == ++seq
);
64 ok1(tdb_delete(tdb
, key
) == TDB_SUCCESS
);
65 ok1(tdb_get_seqnum(tdb
) == ++seq
);
66 ok1(tdb_transaction_commit(tdb
) == TDB_SUCCESS
);
67 ok1(tdb_get_seqnum(tdb
) == seq
);
69 ok1(tdb_transaction_start(tdb
) == TDB_SUCCESS
);
70 ok1(tdb_store(tdb
, key
, data
, TDB_INSERT
) == 0);
71 ok1(tdb_get_seqnum(tdb
) == seq
+ 1);
72 tdb_transaction_cancel(tdb
);
73 ok1(tdb_get_seqnum(tdb
) == seq
);
76 ok1(tap_log_messages
== 0);