s3:registry: do not use regdb functions during db upgrade
[Samba/gebeck_regimport.git] / lib / tdb2 / test / run-tdb1.c
blobdca6473b1cab61fe17625729c79bebe75f18f35d
1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
3 #include <stdlib.h>
4 #include <err.h>
5 #include "logging.h"
7 int main(int argc, char *argv[])
9 struct tdb_context *tdb;
10 TDB_DATA key, data;
11 union tdb_attribute hsize;
13 hsize.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
14 hsize.base.next = &tap_log_attr;
15 hsize.tdb1_hashsize.hsize = 1024;
17 plan_tests(9);
18 tdb = tdb_open("run.tdb1", TDB_VERSION1,
19 O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
21 ok1(tdb);
22 key.dsize = strlen("hi");
23 key.dptr = (void *)"hi";
24 data.dsize = strlen("world");
25 data.dptr = (void *)"world";
27 ok1(tdb_store(tdb, key, data, TDB_MODIFY) == TDB_ERR_NOEXIST);
28 ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS);
29 ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_ERR_EXISTS);
30 ok1(tdb_store(tdb, key, data, TDB_MODIFY) == TDB_SUCCESS);
32 ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS);
33 ok1(data.dsize == strlen("world"));
34 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
35 free(data.dptr);
37 key.dsize++;
38 ok1(tdb_fetch(tdb, key, &data) == TDB_ERR_NOEXIST);
39 tdb_close(tdb);
41 return exit_status();