tdb2: change API to return the error value.
[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         enum TDB_ERROR err;
13         plan_tests(TDB_ERR_RDONLY*-1 + 2);
14
15         for (err = TDB_SUCCESS; err >= TDB_ERR_RDONLY; err--) {
16                 switch (err) {
17                 case TDB_SUCCESS:
18                         ok1(!strcmp(tdb_errorstr(err),
19                                     "Success"));
20                         break;
21                 case TDB_ERR_IO:
22                         ok1(!strcmp(tdb_errorstr(err),
23                                     "IO Error"));
24                         break;
25                 case TDB_ERR_LOCK:
26                         ok1(!strcmp(tdb_errorstr(err),
27                                     "Locking error"));
28                         break;
29                 case TDB_ERR_OOM:
30                         ok1(!strcmp(tdb_errorstr(err),
31                                     "Out of memory"));
32                         break;
33                 case TDB_ERR_EXISTS:
34                         ok1(!strcmp(tdb_errorstr(err),
35                                     "Record exists"));
36                         break;
37                 case TDB_ERR_EINVAL:
38                         ok1(!strcmp(tdb_errorstr(err),
39                                     "Invalid parameter"));
40                         break;
41                 case TDB_ERR_NOEXIST:
42                         ok1(!strcmp(tdb_errorstr(err),
43                                     "Record does not exist"));
44                         break;
45                 case TDB_ERR_RDONLY:
46                         ok1(!strcmp(tdb_errorstr(err),
47                                     "write not permitted"));
48                         break;
49                 case TDB_ERR_CORRUPT:
50                         ok1(!strcmp(tdb_errorstr(err),
51                                     "Corrupt database"));
52                         break;
53                 }
54         }
55         ok1(!strcmp(tdb_errorstr(err), "Invalid error code"));
56
57         return exit_status();
58 }