]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/run-tdb_errorstr.c
tdb2: transaction support
[ccan] / ccan / tdb2 / test / run-tdb_errorstr.c
1 #include <ccan/tdb2/tdb.c>
2 #include <ccan/tdb2/free.c>
3 #include <ccan/tdb2/lock.c>
4 #include <ccan/tdb2/io.c>
5 #include <ccan/tdb2/hash.c>
6 #include <ccan/tdb2/check.c>
7 #include <ccan/tdb2/transaction.c>
8 #include <ccan/tap/tap.h>
9
10 int main(int argc, char *argv[])
11 {
12         struct tdb_context *tdb;
13
14         plan_tests(1 + TDB_ERR_NESTING + 2);
15         tdb = tdb_open("run-tdb_errorstr.tdb", TDB_DEFAULT,
16                        O_RDWR|O_CREAT|O_TRUNC, 0600, NULL);
17         ok1(tdb);
18         if (tdb) {
19                 enum TDB_ERROR err;
20                 for (err = TDB_SUCCESS; err <= TDB_ERR_NESTING; err++) {
21                         tdb->ecode = err;
22                         switch (err) {
23                         case TDB_SUCCESS:
24                                 ok1(!strcmp(tdb_errorstr(tdb),
25                                             "Success"));
26                                 break;
27                         case TDB_ERR_NESTING:
28                                 ok1(!strcmp(tdb_errorstr(tdb),
29                                             "Transaction already started"));
30                                 break;
31                         case TDB_ERR_IO:
32                                 ok1(!strcmp(tdb_errorstr(tdb),
33                                             "IO Error"));
34                                 break;
35                         case TDB_ERR_LOCK:
36                                 ok1(!strcmp(tdb_errorstr(tdb),
37                                             "Locking error"));
38                                 break;
39                         case TDB_ERR_OOM:
40                                 ok1(!strcmp(tdb_errorstr(tdb),
41                                             "Out of memory"));
42                                 break;
43                         case TDB_ERR_EXISTS:
44                                 ok1(!strcmp(tdb_errorstr(tdb),
45                                             "Record exists"));
46                                 break;
47                         case TDB_ERR_EINVAL:
48                                 ok1(!strcmp(tdb_errorstr(tdb),
49                                             "Invalid parameter"));
50                                 break;
51                         case TDB_ERR_NOEXIST:
52                                 ok1(!strcmp(tdb_errorstr(tdb),
53                                             "Record does not exist"));
54                                 break;
55                         case TDB_ERR_RDONLY:
56                                 ok1(!strcmp(tdb_errorstr(tdb),
57                                             "write not permitted"));
58                                 break;
59                         case TDB_ERR_CORRUPT:
60                                 ok1(!strcmp(tdb_errorstr(tdb),
61                                             "Corrupt database"));
62                         }
63                 }
64                 tdb->ecode = err;
65                 ok1(!strcmp(tdb_errorstr(tdb), "Invalid error code"));
66         }
67         return exit_status();
68 }