1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Common definitions for test applications
6 // Copyright (C) 2006 Lasse Collin
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 ///////////////////////////////////////////////////////////////////////////////
28 #define memcrap(buf, size) memset(buf, 0xFD, size)
30 #define expect(test) ((test) ? 0 : (fprintf(stderr, "%s:%u: %s\n", \
31 __FILE__, __LINE__, #test), abort(), 0))
33 #define succeed(test) expect(!(test))
35 #define fail(test) expect(test)
38 static inline const char *
39 lzma_ret_sym(lzma_ret ret)
49 str = "LZMA_STREAM_END";
53 str = "LZMA_PROG_ERROR";
57 str = "LZMA_DATA_ERROR";
61 str = "LZMA_MEM_ERROR";
65 str = "LZMA_BUF_ERROR";
68 case LZMA_HEADER_ERROR:
69 str = "LZMA_HEADER_ERROR";
72 case LZMA_UNSUPPORTED_CHECK:
73 str = "LZMA_UNSUPPORTED_CHECK";
76 case LZMA_FORMAT_ERROR:
77 str = "LZMA_FORMAT_ERROR";
80 case LZMA_MEMLIMIT_ERROR:
81 str = "LZMA_MEMLIMIT_ERROR";
90 coder_loop(lzma_stream *strm, uint8_t *in, size_t in_size,
91 uint8_t *out, size_t out_size,
92 lzma_ret expected_ret, lzma_action finishing_action)
94 size_t in_left = in_size;
95 size_t out_left = out_size > 0 ? out_size + 1 : 0;
96 lzma_action action = LZMA_RUN;
101 strm->next_out = NULL;
107 action = finishing_action;
109 strm->next_in = in++;
115 strm->next_out = out++;
119 ret = lzma_code(strm, action);
126 if (ret != expected_ret)
129 if (expected_ret == LZMA_STREAM_END) {
130 if (strm->total_in != in_size || strm->total_out != out_size)
133 if (strm->total_in != in_size || strm->total_out != out_size)
142 decoder_loop_ret(lzma_stream *strm, uint8_t *in, size_t in_size,
143 lzma_ret expected_ret)
145 return coder_loop(strm, in, in_size, NULL, 0, expected_ret, LZMA_RUN);
150 decoder_loop(lzma_stream *strm, uint8_t *in, size_t in_size)
152 return coder_loop(strm, in, in_size, NULL, 0,
153 LZMA_STREAM_END, LZMA_RUN);