7 #if HEATSHRINK_DYNAMIC_ALLOC 8 #error HEATSHRINK_DYNAMIC_ALLOC must be false for static allocation test suite. 20 uint64_t rn = 9223372036854775783;
21 for (
int i=0; i<size; i++) {
23 buf[i] = (rn % 26) +
'a';
27 static void dump_buf(
char *name, uint8_t *buf, uint16_t count) {
28 for (
int i=0; i<count; i++) {
29 uint8_t c = (uint8_t)buf[i];
30 printf(
"%s %d: 0x%02x ('%c')\n", name, i, c,
isprint(c) ? c :
'.');
37 size_t comp_sz = input_size + (input_size/2) + 4;
38 size_t decomp_sz = input_size + (input_size/2) + 4;
39 uint8_t *comp =
malloc(comp_sz);
40 uint8_t *decomp =
malloc(decomp_sz);
44 memset(decomp, 0, decomp_sz);
49 printf(
"\n^^ COMPRESSING\n");
50 dump_buf(
"input", input, input_size);
55 while (sunk < input_size) {
58 if (log_lvl > 1)
printf(
"^^ sunk %zd\n", count);
59 if (sunk == input_size) {
68 if (log_lvl > 1)
printf(
"^^ polled %zd\n", count);
71 if (polled >= comp_sz)
FAILm(
"compression should never expand that much");
72 if (sunk == input_size) {
76 if (log_lvl > 0)
printf(
"in: %u compressed: %u ", input_size, polled);
77 uint32_t compressed_size = polled;
82 printf(
"\n^^ DECOMPRESSING\n");
83 dump_buf(
"comp", comp, compressed_size);
85 while (sunk < compressed_size) {
88 if (log_lvl > 1)
printf(
"^^ sunk %zd\n", count);
89 if (sunk == compressed_size) {
96 decomp_sz - polled, &count);
99 if (log_lvl > 1)
printf(
"^^ polled %zd\n", count);
102 if (sunk == compressed_size) {
107 if (polled > input_size) {
108 FAILm(
"Decompressed data is larger than original input");
111 if (log_lvl > 0)
printf(
"decompressed: %u\n", polled);
112 if (polled != input_size) {
113 FAILm(
"Decompressed length does not match original input length");
116 if (log_lvl > 1)
dump_buf(
"decomp", decomp, polled);
117 for (
size_t i=0; i<input_size; i++) {
118 if (input[i] != decomp[i]) {
119 printf(
"*** mismatch at %zd\n", i);
121 for (
size_t j=0; j<= input_size; j++) {
122 printf(
"in[%zd] == 0x%02x ('%c') => out[%zd] == 0x%02x ('%c')\n",
123 j, input[j],
isprint(input[j]) ? input[j] :
'.',
124 j, decomp[j],
isprint(decomp[j]) ? decomp[j] :
'.');
142 #if __STDC_VERSION__ >= 19901L 143 for (uint32_t size=1; size < 64*1024; size <<= 1) {
145 for (uint32_t seed=1; seed<=100; seed++) {
156 int main(
int argc,
char **argv) {
158 printf(
"INPUT_BUFFER_SIZE: %u\n", HEATSHRINK_STATIC_INPUT_BUFFER_SIZE);
159 printf(
"WINDOW_BITS: %u\n", HEATSHRINK_STATIC_WINDOW_BITS);
160 printf(
"LOOKAHEAD_BITS: %u\n", HEATSHRINK_STATIC_LOOKAHEAD_BITS);
static int compress_and_expand_and_check(uint8_t *input, uint32_t input_size, int log_lvl)
HSD_poll_res heatshrink_decoder_poll(heatshrink_decoder *hsd, uint8_t *out_buf, size_t out_buf_size, size_t *output_size)
HSD_finish_res heatshrink_decoder_finish(heatshrink_decoder *hsd)
#define GREATEST_IS_VERBOSE()
static void dump_buf(char *name, uint8_t *buf, uint16_t count)
static heatshrink_decoder hsd
void heatshrink_decoder_reset(heatshrink_decoder *hsd)
HSE_finish_res heatshrink_encoder_finish(heatshrink_encoder *hse)
HSD_sink_res heatshrink_decoder_sink(heatshrink_decoder *hsd, uint8_t *in_buf, size_t size, size_t *input_size)
int main(int argc, char **argv)
HSE_poll_res heatshrink_encoder_poll(heatshrink_encoder *hse, uint8_t *out_buf, size_t out_buf_size, size_t *output_size)
HSE_sink_res heatshrink_encoder_sink(heatshrink_encoder *hse, uint8_t *in_buf, size_t size, size_t *input_size)
void heatshrink_encoder_reset(heatshrink_encoder *hse)
TEST pseudorandom_data_should_match(uint32_t size, uint32_t seed)
#define GREATEST_MAIN_BEGIN()
#define GREATEST_MAIN_END()
static void fill_with_pseudorandom_letters(uint8_t *buf, uint16_t size, uint32_t seed)
static heatshrink_encoder hse