diff options
| author | 2023-02-07 06:19:40 +0000 | |
|---|---|---|
| committer | 2023-02-07 06:19:40 +0000 | |
| commit | 72395822512cb3b7ef590e772dbe0c046c999249 (patch) | |
| tree | a7611e16491af407fb51081178740cb545a451a0 /test_encode_decode.c | |
| parent | test_encode_decode: add messages (diff) | |
test encode and decode
Diffstat (limited to '')
| -rw-r--r-- | test_encode_decode.c | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/test_encode_decode.c b/test_encode_decode.c index 3b117cf..e165e1e 100644 --- a/test_encode_decode.c +++ b/test_encode_decode.c @@ -1,9 +1,10 @@ -#include "creole.c" #include <string.h> #include <assert.h> #include <stdio.h> #include <stdlib.h> +#include "creole.c" +#if 0 struct seq { creole_word max; unsigned encode_to; @@ -173,10 +174,55 @@ static void test_encode(void) { tests[test](high_bits); } } +#endif + +void encode_decode_byte_seq(creole_word max, unsigned encode_to, unsigned high_bits) { + unsigned char buf[7]; + struct creole_reader r = {0}; + struct word w; + creole_word i = 0; + + for (;;) { + r.p = buf; + r.left = encode_to; + assert(creole_encode(i, encode_to, high_bits, + buf) == 1); + + assert(decode_seq(&r, &w) == 1); + assert(w.len == encode_to); + if (w.high_bits != high_bits) { + printf("high bits %u != %u\n", w.high_bits, high_bits); + abort(); + } + + if (w.word != i) { + printf("word %X != %X\n", w.word, i); + abort(); + } + + if (i == max) + break; + i++; + } +} + +static void test_encode_decode(void) { + unsigned high_bits = 0; + int encode_len; + creole_word maxima[6] = {0x7F, 0xFFF, 0x1FFFF, 0x3FFFFF, 0x7FFFFFF, 0xFFFFFFFF}; + + encode_decode_byte_seq(0x7F, 1, 0); + +#pragma omp parallel for collapse(2) num_threads(8) + for (high_bits = 0; high_bits < 16; high_bits++) { + for (encode_len = 2; encode_len < 8; encode_len++) + encode_decode_byte_seq(maxima[encode_len - 2], encode_len, high_bits); + } +} int main(void) { printf("test encode\n"); - test_encode(); + test_encode_decode(); printf("finished\n"); return 0; |
