Raise the level of a debug.
[Samba.git] / lib / ntdb / test / api-81-seqnum.c
blob04f49cdbe3d192eeaf22b1f8081dfcdc0e696383
1 #include "config.h"
2 #include "ntdb.h"
3 #include "tap-interface.h"
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <stdlib.h>
8 #include "logging.h"
10 int main(int argc, char *argv[])
12 unsigned int i, seq;
13 struct ntdb_context *ntdb;
14 NTDB_DATA d = { NULL, 0 }; /* Bogus GCC warning */
15 NTDB_DATA key = ntdb_mkdata("key", 3);
16 NTDB_DATA data = ntdb_mkdata("data", 4);
17 int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
18 NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
19 NTDB_NOMMAP|NTDB_CONVERT };
21 plan_tests(sizeof(flags) / sizeof(flags[0]) * 15 + 4 * 13);
22 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
23 ntdb = ntdb_open("api-81-seqnum.ntdb",
24 flags[i]|NTDB_SEQNUM|MAYBE_NOSYNC,
25 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
26 if (!ok1(ntdb))
27 continue;
29 seq = 0;
30 ok1(ntdb_get_seqnum(ntdb) == seq);
31 ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == 0);
32 ok1(ntdb_get_seqnum(ntdb) == ++seq);
33 /* Fetch doesn't change seqnum */
34 if (ok1(ntdb_fetch(ntdb, key, &d) == NTDB_SUCCESS))
35 free(d.dptr);
36 ok1(ntdb_get_seqnum(ntdb) == seq);
37 ok1(ntdb_append(ntdb, key, data) == NTDB_SUCCESS);
38 ok1(ntdb_get_seqnum(ntdb) == ++seq);
40 ok1(ntdb_delete(ntdb, key) == NTDB_SUCCESS);
41 ok1(ntdb_get_seqnum(ntdb) == ++seq);
42 /* Empty append works */
43 ok1(ntdb_append(ntdb, key, data) == NTDB_SUCCESS);
44 ok1(ntdb_get_seqnum(ntdb) == ++seq);
46 ok1(ntdb_wipe_all(ntdb) == NTDB_SUCCESS);
47 ok1(ntdb_get_seqnum(ntdb) == ++seq);
49 if (!(flags[i] & NTDB_INTERNAL)) {
50 ok1(ntdb_transaction_start(ntdb) == NTDB_SUCCESS);
51 ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == 0);
52 ok1(ntdb_get_seqnum(ntdb) == ++seq);
53 ok1(ntdb_append(ntdb, key, data) == NTDB_SUCCESS);
54 ok1(ntdb_get_seqnum(ntdb) == ++seq);
55 ok1(ntdb_delete(ntdb, key) == NTDB_SUCCESS);
56 ok1(ntdb_get_seqnum(ntdb) == ++seq);
57 ok1(ntdb_transaction_commit(ntdb) == NTDB_SUCCESS);
58 ok1(ntdb_get_seqnum(ntdb) == seq);
60 ok1(ntdb_transaction_start(ntdb) == NTDB_SUCCESS);
61 ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == 0);
62 ok1(ntdb_get_seqnum(ntdb) == seq + 1);
63 ntdb_transaction_cancel(ntdb);
64 ok1(ntdb_get_seqnum(ntdb) == seq);
66 ntdb_close(ntdb);
67 ok1(tap_log_messages == 0);
69 return exit_status();