aboutsummaryrefslogtreecommitdiff
path: root/test/100_tables_readwrite/tables_readwrite_tests.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/100_tables_readwrite/tables_readwrite_tests.c')
-rw-r--r--test/100_tables_readwrite/tables_readwrite_tests.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/test/100_tables_readwrite/tables_readwrite_tests.c b/test/100_tables_readwrite/tables_readwrite_tests.c
new file mode 100644
index 0000000..96a60bb
--- /dev/null
+++ b/test/100_tables_readwrite/tables_readwrite_tests.c
@@ -0,0 +1,76 @@
1#include "../test.h"
2
3int64_t readtableinfo(size_t, const unsigned char *, tableinfo_t *);
4int64_t writetableinfo(const tableinfo_t *, size_t, unsigned char *);
5
6uint64_t readn(void) {
7 char str[STRLENMAX];
8
9 fgets(str, STRLENMAX, stdin);
10 return atoll(str);
11}
12
13tableinfo_t test_readinfo(void) {
14 int i;
15 tableinfo_t ret;
16 char emptyline[2];
17
18 fgets(ret.solver, INFO_SOLVER_STRLEN, stdin);
19 for (i = 0; i < INFO_SOLVER_STRLEN; i++)
20 if (ret.solver[i] == '\n')
21 ret.solver[i] = 0;
22
23 fgets(emptyline, 2, stdin);
24
25 ret.type = readn();
26 ret.infosize = readn();
27 ret.fullsize = readn();
28 ret.hash = readn();
29 ret.entries = readn();
30 ret.classes = readn();
31 ret.h48h = (uint8_t)readn();
32 ret.bits = (uint8_t)readn();
33 ret.base = (uint8_t)readn();
34 ret.maxvalue = (uint8_t)readn();
35 ret.next = readn();
36
37 fgets(emptyline, 2, stdin);
38
39 for (i = 0; i < INFO_DISTRIBUTION_LEN; i++)
40 ret.distribution[i] = readn();
41
42 return ret;
43}
44
45void test_writeinfo(tableinfo_t info) {
46 int i;
47
48 printf("%s\n", info.solver);
49 printf("\n");
50
51 printf("%" PRIu64 "\n", info.type);
52 printf("%" PRIu64 "\n", info.infosize);
53 printf("%" PRIu64 "\n", info.fullsize);
54 printf("%" PRIu64 "\n", info.hash);
55 printf("%" PRIu64 "\n", info.entries);
56 printf("%" PRIu64 "\n", info.classes);
57 printf("%" PRIu8 "\n", info.h48h);
58 printf("%" PRIu8 "\n", info.bits);
59 printf("%" PRIu8 "\n", info.base);
60 printf("%" PRIu8 "\n", info.maxvalue);
61 printf("%" PRIu64 "\n", info.next);
62 printf("\n");
63
64 for (i = 0; i < INFO_DISTRIBUTION_LEN; i++)
65 printf("%" PRIu64 "\n", info.distribution[i]);
66}
67
68void run(void) {
69 unsigned char buf[INFOSIZE];
70 tableinfo_t expected, actual;
71
72 expected = test_readinfo();
73 writetableinfo(&expected, INFOSIZE, buf);
74 readtableinfo(INFOSIZE, buf, &actual);
75 test_writeinfo(actual);
76}

Generated with cgit - Back to sebastiano.tronto.net