test: test LZP compression

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-06-15 14:31:14 +00:00
parent c244d425ca
commit 2a79e08343
3 changed files with 17 additions and 5 deletions

View file

@ -10,8 +10,8 @@ void
lzp_compress(uint8_t *out, size_t *outsz, const uint8_t *in, size_t insz) lzp_compress(uint8_t *out, size_t *outsz, const uint8_t *in, size_t insz)
{ {
uint8_t c; uint8_t c;
uint16_t hash = 0; uint16_t hash;
uint32_t mask = 0; uint32_t mask;
uint8_t table[LZP_HASH_SIZE] = { 0 }; uint8_t table[LZP_HASH_SIZE] = { 0 };
size_t i, j; size_t i, j;
size_t inpos; size_t inpos;
@ -20,9 +20,11 @@ lzp_compress(uint8_t *out, size_t *outsz, const uint8_t *in, size_t insz)
inpos = 0; inpos = 0;
outpos = 0; outpos = 0;
hash = 0;
while (inpos < insz) while (inpos < insz)
{ {
j = 1; j = 1;
mask = 0;
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
if (inpos >= insz) if (inpos >= insz)

View file

View file

@ -4,14 +4,24 @@
#include <setjmp.h> #include <setjmp.h>
#include <cmocka.h> #include <cmocka.h>
static const char *uncompress_data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" void lzp_compress(uint8_t *out, size_t *outsz, const uint8_t *in, size_t insz);
void lzp_decompress(uint8_t *out, size_t *outsz, const uint8_t *in, size_t insz);
static const char uncompress_data[298] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc" "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"
"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccabcabcabcabcabcabcabcabcabcabcabcabcabcabc"; "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccabcabcabcabcabcabcabcabcabcabcabcabcabcabc";
static void static void
test_lzp(void **state) test_lzp(void **state)
{ {
(void)state; uint8_t compressed[298];
char result[298];
size_t outsz;
lzp_compress(compressed, &outsz, (uint8_t *)uncompress_data, 298);
lzp_decompress((uint8_t *)result, &outsz, compressed, outsz);
assert_int_equal(298, outsz);
assert_memory_equal(uncompress_data, result, 298);
} }
int int