1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Common definitions for test applications
6 // Author: Lasse Collin
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
11 ///////////////////////////////////////////////////////////////////////////////
22 #define memcrap(buf, size) memset(buf, 0xFD, size)
24 #define expect(test) ((test) ? 0 : (fprintf(stderr, "%s:%u: %s\n", \
25 __FILE__, __LINE__, #test), abort(), 0))
27 #define succeed(test) expect(!(test))
29 #define fail(test) expect(test)
32 static inline const char *
33 lzma_ret_sym(lzma_ret ret)
35 if ((unsigned int)(ret) > LZMA_PROG_ERROR)
36 return "UNKNOWN_ERROR";
38 static const char *msgs[] = {
42 "LZMA_UNSUPPORTED_CHECK",
45 "LZMA_MEMLIMIT_ERROR",
58 coder_loop(lzma_stream *strm, uint8_t *in, size_t in_size,
59 uint8_t *out, size_t out_size,
60 lzma_ret expected_ret, lzma_action finishing_action)
62 size_t in_left = in_size;
63 size_t out_left = out_size > 0 ? out_size + 1 : 0;
64 lzma_action action = LZMA_RUN;
69 strm->next_out = NULL;
75 action = finishing_action;
83 strm->next_out = out++;
87 ret = lzma_code(strm, action);
94 if (ret != expected_ret)
97 if (expected_ret == LZMA_STREAM_END) {
98 if (strm->total_in != in_size || strm->total_out != out_size)
101 if (strm->total_in != in_size || strm->total_out != out_size)
110 decoder_loop_ret(lzma_stream *strm, uint8_t *in, size_t in_size,
111 lzma_ret expected_ret)
113 return coder_loop(strm, in, in_size, NULL, 0, expected_ret, LZMA_RUN);
118 decoder_loop(lzma_stream *strm, uint8_t *in, size_t in_size)
120 return coder_loop(strm, in, in_size, NULL, 0,
121 LZMA_STREAM_END, LZMA_RUN);