]> git.ozlabs.org Git - ccan/blob - ccan/tdb/test/run-endian.c
strsplit: remove nump argument
[ccan] / ccan / tdb / test / run-endian.c
1 #define _XOPEN_SOURCE 500
2 #include <ccan/tdb/tdb.h>
3 #include <ccan/tdb/io.c>
4 #include <ccan/tdb/tdb.c>
5 #include <ccan/tdb/lock.c>
6 #include <ccan/tdb/freelist.c>
7 #include <ccan/tdb/traverse.c>
8 #include <ccan/tdb/transaction.c>
9 #include <ccan/tdb/error.c>
10 #include <ccan/tdb/open.c>
11 #include <ccan/tdb/check.c>
12 #include <ccan/tdb/hash.c>
13 #include <ccan/tap/tap.h>
14 #include <stdlib.h>
15 #include <err.h>
16 #include "logging.h"
17
18 int main(int argc, char *argv[])
19 {
20         struct tdb_context *tdb;
21         TDB_DATA key, data;
22
23         plan_tests(13);
24         tdb = tdb_open_ex("run-endian.tdb", 1024,
25                           TDB_CLEAR_IF_FIRST|TDB_CONVERT,
26                           O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
27
28         ok1(tdb);
29         key.dsize = strlen("hi");
30         key.dptr = (void *)"hi";
31         data.dsize = strlen("world");
32         data.dptr = (void *)"world";
33
34         ok1(tdb_store(tdb, key, data, TDB_MODIFY) < 0);
35         ok1(tdb_error(tdb) == TDB_ERR_NOEXIST);
36         ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
37         ok1(tdb_store(tdb, key, data, TDB_INSERT) < 0);
38         ok1(tdb_error(tdb) == TDB_ERR_EXISTS);
39         ok1(tdb_store(tdb, key, data, TDB_MODIFY) == 0);
40
41         data = tdb_fetch(tdb, key);
42         ok1(data.dsize == strlen("world"));
43         ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
44         free(data.dptr);
45
46         key.dsize++;
47         data = tdb_fetch(tdb, key);
48         ok1(data.dptr == NULL);
49         tdb_close(tdb);
50
51         /* Reopen: should read it */
52         tdb = tdb_open_ex("run-endian.tdb", 1024, 0, O_RDWR, 0,
53                           &taplogctx, NULL);
54         ok1(tdb);
55         
56         key.dsize = strlen("hi");
57         key.dptr = (void *)"hi";
58         data = tdb_fetch(tdb, key);
59         ok1(data.dsize == strlen("world"));
60         ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
61         free(data.dptr);
62         tdb_close(tdb);
63
64         return exit_status();
65 }