34 #define DEFINE_RLE_BINARY_FORMAT_TEST(fn_name, pcomp_fn, datatype_t) \
37 datatype_t input_buf[] = { 10, 10, 20, 30, 30, 30 }; \
38 size_t input_size = sizeof(input_buf) / sizeof(input_buf[0]); \
39 size_t output_size = pcomp_rle_bufsize(input_size) \
40 * sizeof(datatype_t); \
41 datatype_t* output_buf = malloc(output_size); \
43 assert(pcomp_fn(output_buf, &output_size, input_buf, \
44 input_size) == PCOMP_STAT_SUCCESS); \
46 assert(output_buf[0] == 2); \
47 assert(output_buf[1] == 10); \
48 assert(output_buf[2] == 1); \
49 assert(output_buf[3] == 20); \
50 assert(output_buf[4] == 3); \
51 assert(output_buf[5] == 30); \
56 DEFINE_RLE_BINARY_FORMAT_TEST(test_rle_binary_format_int8,
58 DEFINE_RLE_BINARY_FORMAT_TEST(test_rle_binary_format_int16,
60 DEFINE_RLE_BINARY_FORMAT_TEST(test_rle_binary_format_int32,
62 DEFINE_RLE_BINARY_FORMAT_TEST(test_rle_binary_format_int64,
65 DEFINE_RLE_BINARY_FORMAT_TEST(test_rle_binary_format_uint8,
67 DEFINE_RLE_BINARY_FORMAT_TEST(test_rle_binary_format_uint16,
69 DEFINE_RLE_BINARY_FORMAT_TEST(test_rle_binary_format_uint32,
71 DEFINE_RLE_BINARY_FORMAT_TEST(test_rle_binary_format_uint64,
74 void test_rle_binary_format(
void)
76 test_rle_binary_format_int8();
77 test_rle_binary_format_int16();
78 test_rle_binary_format_int32();
79 test_rle_binary_format_int64();
81 test_rle_binary_format_uint8();
82 test_rle_binary_format_uint16();
83 test_rle_binary_format_uint32();
84 test_rle_binary_format_uint64();
91 #define DEFINE_RLE_DECOMPRESS_TEST(fn_name, pcomp_compr_fn, \
92 pcomp_decompr_fn, datatype_t) \
95 const size_t input_size = 10000; \
96 datatype_t* input_buf \
97 = malloc(input_size * sizeof(datatype_t)); \
98 size_t compr_size = pcomp_rle_bufsize(input_size) \
99 * sizeof(datatype_t); \
100 datatype_t* compr_buf = malloc(compr_size); \
101 datatype_t* decompr_buf \
102 = malloc(input_size * sizeof(datatype_t)); \
103 size_t decompr_size = input_size; \
106 for (idx = 0; idx < input_size; ++idx) { \
108 input_buf[idx] = random() % 10; \
111 assert(pcomp_compr_fn(compr_buf, &compr_size, input_buf, \
112 input_size) == PCOMP_STAT_SUCCESS); \
113 assert(pcomp_decompr_fn(decompr_buf, decompr_size, compr_buf, \
114 compr_size) == PCOMP_STAT_SUCCESS); \
116 assert(decompr_size == input_size); \
117 for (idx = 0; idx < input_size; ++idx) { \
118 assert(decompr_buf[idx] == input_buf[idx]); \
126 DEFINE_RLE_DECOMPRESS_TEST(test_rle_decompress_int8,
128 pcomp_decompress_rle_int8, int8_t)
129 DEFINE_RLE_DECOMPRESS_TEST(test_rle_decompress_int16,
131 pcomp_decompress_rle_int16, int16_t)
132 DEFINE_RLE_DECOMPRESS_TEST(test_rle_decompress_int32,
134 pcomp_decompress_rle_int32, int32_t)
135 DEFINE_RLE_DECOMPRESS_TEST(test_rle_decompress_int64,
137 pcomp_decompress_rle_int64, int64_t)
139 DEFINE_RLE_DECOMPRESS_TEST(test_rle_decompress_uint8,
141 pcomp_decompress_rle_uint8, uint8_t)
142 DEFINE_RLE_DECOMPRESS_TEST(test_rle_decompress_uint16,
144 pcomp_decompress_rle_uint16, uint16_t)
145 DEFINE_RLE_DECOMPRESS_TEST(test_rle_decompress_uint32,
147 pcomp_decompress_rle_uint32, uint32_t)
148 DEFINE_RLE_DECOMPRESS_TEST(test_rle_decompress_uint64,
150 pcomp_decompress_rle_uint64, uint64_t)
152 void test_rle_decompression(
void)
154 test_rle_decompress_int8();
155 test_rle_decompress_int16();
156 test_rle_decompress_int32();
157 test_rle_decompress_int64();
159 test_rle_decompress_uint8();
160 test_rle_decompress_uint16();
161 test_rle_decompress_uint32();
162 test_rle_decompress_uint64();
169 void test_rle_no_overflow(
void)
171 size_t input_size = INT8_MAX + 2;
172 int8_t* input_buf = malloc(input_size *
sizeof(int8_t));
174 int8_t* output_buf = malloc(output_size);
176 const int8_t value = 123;
178 for (idx = 0; idx < input_size; ++idx) {
179 input_buf[idx] = value;
183 input_size) == PCOMP_STAT_SUCCESS);
185 assert(output_size == 4);
186 assert(output_buf[0] == INT8_MAX);
187 assert(output_buf[1] == value);
188 assert(output_buf[2] == 2);
189 assert(output_buf[3] == value);
196 test_rle_binary_format();
197 test_rle_decompression();
198 test_rle_no_overflow();
int pcomp_compress_rle_int16(int16_t *output_buf, size_t *output_size, const int16_t *input_buf, size_t input_size)
Compress an array of int16_t values using the RLE compression.
int pcomp_compress_rle_int32(int32_t *output_buf, size_t *output_size, const int32_t *input_buf, size_t input_size)
Compress an array of int32_t values using the RLE compression.
size_t pcomp_rle_bufsize(size_t input_size)
Calculate an upper limit for the size of a buffer holding RLE-encoded streams.
int pcomp_compress_rle_uint64(uint64_t *output_buf, size_t *output_size, const uint64_t *input_buf, size_t input_size)
Compress an array of uint64_t values using the RLE compression.
int pcomp_compress_rle_uint16(uint16_t *output_buf, size_t *output_size, const uint16_t *input_buf, size_t input_size)
Compress an array of uint16_t values using the RLE compression.
int pcomp_compress_rle_int64(int64_t *output_buf, size_t *output_size, const int64_t *input_buf, size_t input_size)
Compress an array of int64_t values using the RLE compression.
int pcomp_compress_rle_int8(int8_t *output_buf, size_t *output_size, const int8_t *input_buf, size_t input_size)
Compress an array of int8_t values using the RLE compression.
int pcomp_compress_rle_uint32(uint32_t *output_buf, size_t *output_size, const uint32_t *input_buf, size_t input_size)
Compress an array of uint32_t values using the RLE compression.
int pcomp_compress_rle_uint8(uint8_t *output_buf, size_t *output_size, const uint8_t *input_buf, size_t input_size)
Compress an array of uint8_t values using the RLE compression.
Header file for Libpolycomp.