]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/run-tdb1.c
tdb2: suppress failtest more than once on mmap.
[ccan] / ccan / tdb2 / test / run-tdb1.c
1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
3 #include <stdlib.h>
4 #include <err.h>
5 #include "logging.h"
6
7 int main(int argc, char *argv[])
8 {
9         struct tdb_context *tdb;
10         TDB_DATA key, data;
11         union tdb_attribute hsize;
12
13         hsize.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
14         hsize.base.next = &tap_log_attr;
15         hsize.tdb1_hashsize.hsize = 1024;
16
17         plan_tests(9);
18         tdb = tdb_open("run.tdb1", TDB_VERSION1,
19                        O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
20
21         ok1(tdb);
22         key.dsize = strlen("hi");
23         key.dptr = (void *)"hi";
24         data.dsize = strlen("world");
25         data.dptr = (void *)"world";
26
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);
31
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);
36
37         key.dsize++;
38         ok1(tdb_fetch(tdb, key, &data) == TDB_ERR_NOEXIST);
39         tdb_close(tdb);
40
41         return exit_status();
42 }