62#define DATA(...) { __VA_ARGS__ }
65#define DEFLATE( name, FORMAT, COMPRESSED, EXPECTED ) \
66 static const uint8_t name ## _compressed[] = COMPRESSED; \
67 static const uint8_t name ## _expected[] = EXPECTED; \
68 static struct deflate_test name = { \
70 .compressed = name ## _compressed, \
71 .compressed_len = sizeof ( name ## _compressed ), \
72 .expected = name ## _expected, \
73 .expected_len = sizeof ( name ## _expected ), \
78 DATA ( 0x01, 0x00, 0x00, 0xff, 0xff ),
DATA() );
82 DATA ( 0x01, 0x04, 0x00, 0xfb, 0xff, 0x69, 0x50, 0x58, 0x45 ),
83 DATA ( 0x69, 0x50, 0x58, 0x45 ) );
87 DATA ( 0x00, 0x02, 0x00, 0xfd, 0xff, 0x69, 0x50, 0x01, 0x02, 0x00,
88 0xfd, 0xff, 0x58, 0x45 ),
89 DATA ( 0x69, 0x50, 0x58, 0x45 ) );
96 DATA ( 0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0x28, 0xcf, 0x2f, 0xca,
98 DATA ( 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c,
103 DATA ( 0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0xc8, 0x00, 0x93, 0xe5,
104 0xf9, 0x45, 0x39, 0x29, 0x00 ),
105 DATA ( 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x68, 0x65, 0x6c, 0x6c,
106 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64 ) );
110 DATA ( 0x0d, 0xc6, 0xdb, 0x09, 0x00, 0x21, 0x0c, 0x04, 0xc0, 0x56,
111 0xb6, 0x28, 0x1b, 0x08, 0x79, 0x70, 0x01, 0x35, 0xe2, 0xa6,
112 0x7f, 0xce, 0xf9, 0x9a, 0xf1, 0x25, 0xc1, 0xe3, 0x9a, 0x91,
113 0x2a, 0x9d, 0xb5, 0x61, 0x1e, 0xb9, 0x9d, 0x10, 0xcc, 0x22,
114 0xa7, 0x93, 0xd0, 0x5a, 0xe7, 0xbe, 0xb8, 0xc1, 0xa4, 0x05,
115 0x51, 0x77, 0x49, 0xff ),
116 DATA ( 0x54, 0x68, 0x69, 0x73, 0x20, 0x73, 0x70, 0x65, 0x63, 0x69,
117 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x64,
118 0x65, 0x66, 0x69, 0x6e, 0x65, 0x73, 0x20, 0x61, 0x20, 0x6c,
119 0x6f, 0x73, 0x73, 0x6c, 0x65, 0x73, 0x73, 0x20, 0x63, 0x6f,
120 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x20, 0x64,
121 0x61, 0x74, 0x61, 0x20, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74 ) );
125 DATA ( 0x78, 0x01, 0x8b, 0xf2, 0xf1, 0x74, 0x52, 0x70, 0xce, 0xcf,
126 0x2d, 0x28, 0x4a, 0x2d, 0x2e, 0x4e, 0x4d, 0x51, 0x70, 0x49,
127 0x2c, 0x49, 0x54, 0x70, 0xcb, 0x2f, 0xca, 0x4d, 0x2c, 0x51,
128 0x08, 0x2e, 0x48, 0x4d, 0xce, 0x4c, 0xcb, 0x4c, 0x4e, 0x2c,
129 0xc9, 0xcc, 0xcf, 0x03, 0x00, 0x2c, 0x0e, 0x0e, 0xeb ),
130 DATA ( 0x5a, 0x4c, 0x49, 0x42, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x72,
131 0x65, 0x73, 0x73, 0x65, 0x64, 0x20, 0x44, 0x61, 0x74, 0x61,
132 0x20, 0x46, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x20, 0x53, 0x70,
133 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f,
139 { { 0, 1, 5, -1UL, } },
140 { { 0, 0, 1, 0, 0, 1, -1UL } },
141 { { 10, 8, 4, 7, 11, -1UL } },
158 const char *file,
unsigned int line ) {
160 const void *
data =
test->compressed;
161 size_t remaining =
test->compressed_len;
162 size_t frag_len = -1UL;
170 deflate_chunk_init ( &
out, buf, 0,
sizeof ( buf ) );
173 for ( i = 0 ; i < (
sizeof (
frags->len ) /
174 sizeof (
frags->len[0] ) ) ; i++ ) {
178 frag_len =
frags->len[i];
179 if ( frag_len > remaining )
180 frag_len = remaining;
184 &
out ) == 0, file, line );
190 remaining -= frag_len;
204 okx (
out.offset ==
test->expected_len, file, line );
205 okx (
out.data == buf, file, line );
209#define deflate_ok( deflate, test, frags ) \
210 deflate_okx ( deflate, test, frags, __FILE__, __LINE__ )
#define NULL
NULL pointer (VOID *)
#define DATA(...)
Define inline data.
void deflate_init(struct deflate *deflate, enum deflate_format format)
Initialise decompressor.
int deflate_inflate(struct deflate *deflate, const void *data, size_t len, struct deflate_chunk *out)
Inflate compressed data.
DEFLATE decompression algorithm.
static int deflate_finished(struct deflate *deflate)
Check if decompression has finished.
deflate_format
Compression formats.
@ DEFLATE_ZLIB
ZLIB header and footer.
@ DEFLATE_RAW
Raw DEFLATE data (no header or footer)
#define deflate_ok(deflate, test, frags)
#define DEFLATE(name, FORMAT, COMPRESSED, EXPECTED)
Define a DEFLATE test.
static void deflate_test_exec(void)
Perform DEFLATE self-test.
#define DATA(...)
Define inline data.
static struct deflate_test_fragments zlib_fragments[]
static void deflate_okx(struct deflate *deflate, struct deflate_test *test, struct deflate_test_fragments *frags, const char *file, unsigned int line)
Report DEFLATE test result.
uint8_t data[48]
Additional event data.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
void * malloc(size_t size)
Allocate memory.
static void(* free)(struct refcnt *refcnt))
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
size_t len[8]
Fragment lengths.
const void * expected
Expected uncompressed data.
size_t expected_len
Length of expected uncompressed data.
size_t compressed_len
Length of compressed data.
const void * compressed
Compressed data.
enum deflate_format format
Compression format.
const uint8_t * end
End of input data pointer.
const uint8_t * in
Current input data pointer.
Self-test infrastructure.
#define okx(success, file, line)
Report test result.
#define __self_test
Declare a self-test.
struct velocity_frag frags[7]