diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-07-17 08:54:44 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-07-17 08:54:44 +0200 |
| commit | 270e5b0444f67781856bf80db51650af9cb89b0c (patch) | |
| tree | 1f895ca8fdbf256dcdf550dd0a28ca99993efc08 /test/100_tables_readwrite/tables_readwrite_tests.c | |
| parent | 2d0ab15ac1f81c76cb6bb31bbdad3d2ee339e062 (diff) | |
| download | nissy-core-270e5b0444f67781856bf80db51650af9cb89b0c.tar.gz nissy-core-270e5b0444f67781856bf80db51650af9cb89b0c.zip | |
Renamed tests to make space for more coordinate tests
Diffstat (limited to 'test/100_tables_readwrite/tables_readwrite_tests.c')
| -rw-r--r-- | test/100_tables_readwrite/tables_readwrite_tests.c | 76 |
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 | |||
| 3 | int64_t readtableinfo(size_t, const unsigned char *, tableinfo_t *); | ||
| 4 | int64_t writetableinfo(const tableinfo_t *, size_t, unsigned char *); | ||
| 5 | |||
| 6 | uint64_t readn(void) { | ||
| 7 | char str[STRLENMAX]; | ||
| 8 | |||
| 9 | fgets(str, STRLENMAX, stdin); | ||
| 10 | return atoll(str); | ||
| 11 | } | ||
| 12 | |||
| 13 | tableinfo_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 | |||
| 45 | void 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 | |||
| 68 | void 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 | } | ||
