]> git.ozlabs.org Git - ccan/blob - junkcode/rusty@rustcorp.com.au-ntdb/test/run-001-encode.c
ccan/ntdb: demote to junkcode.
[ccan] / junkcode / rusty@rustcorp.com.au-ntdb / test / run-001-encode.c
1 #include "ntdb-source.h"
2 #include "tap-interface.h"
3 #include "logging.h"
4 #include "helprun-external-agent.h"
5
6 int main(int argc, char *argv[])
7 {
8         unsigned int i;
9         struct ntdb_used_record rec;
10         struct ntdb_context ntdb = { .log_fn = tap_log_fn };
11
12         plan_tests(64 + 32 + 48*5 + 1);
13
14         /* We should be able to encode any data value. */
15         for (i = 0; i < 64; i++)
16                 ok1(set_header(&ntdb, &rec, NTDB_USED_MAGIC, 0, 1ULL << i,
17                                1ULL << i) == 0);
18
19         /* And any key and data with < 64 bits between them. */
20         for (i = 0; i < 32; i++) {
21                 ntdb_len_t dlen = 1ULL >> (63 - i), klen = 1ULL << i;
22                 ok1(set_header(&ntdb, &rec, NTDB_USED_MAGIC, klen, dlen,
23                                klen + dlen)  == 0);
24         }
25
26         /* We should neatly encode all values. */
27         for (i = 0; i < 48; i++) {
28                 uint64_t klen = 1ULL << (i < 16 ? i : 15);
29                 uint64_t dlen = 1ULL << i;
30                 uint64_t xlen = 1ULL << (i < 32 ? i : 31);
31                 ok1(set_header(&ntdb, &rec, NTDB_USED_MAGIC, klen, dlen,
32                                klen+dlen+xlen) == 0);
33                 ok1(rec_key_length(&rec) == klen);
34                 ok1(rec_data_length(&rec) == dlen);
35                 ok1(rec_extra_padding(&rec) == xlen);
36                 ok1(rec_magic(&rec) == NTDB_USED_MAGIC);
37         }
38         ok1(tap_log_messages == 0);
39         return exit_status();
40 }