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";
73 str = "LZMA_NO_CHECK";
76 case LZMA_UNSUPPORTED_CHECK:
77 str = "LZMA_UNSUPPORTED_CHECK";
81 str = "LZMA_SEE_CHECK";
84 case LZMA_FORMAT_ERROR:
85 str = "LZMA_FORMAT_ERROR";
88 case LZMA_MEMLIMIT_ERROR:
89 str = "LZMA_MEMLIMIT_ERROR";
98 coder_loop(lzma_stream *strm, uint8_t *in, size_t in_size,
99 uint8_t *out, size_t out_size,
100 lzma_ret expected_ret, lzma_action finishing_action)
102 size_t in_left = in_size;
103 size_t out_left = out_size > 0 ? out_size + 1 : 0;
104 lzma_action action = LZMA_RUN;
107 strm->next_in = NULL;
109 strm->next_out = NULL;
115 action = finishing_action;
117 strm->next_in = in++;
123 strm->next_out = out++;
127 ret = lzma_code(strm, action);
134 if (ret != expected_ret)
137 if (expected_ret == LZMA_STREAM_END) {
138 if (strm->total_in != in_size || strm->total_out != out_size)
141 if (strm->total_in != in_size || strm->total_out != out_size)
150 decoder_loop_ret(lzma_stream *strm, uint8_t *in, size_t in_size,
151 lzma_ret expected_ret)
153 return coder_loop(strm, in, in_size, NULL, 0, expected_ret, LZMA_RUN);
158 decoder_loop(lzma_stream *strm, uint8_t *in, size_t in_size)
160 return coder_loop(strm, in, in_size, NULL, 0,
161 LZMA_STREAM_END, LZMA_RUN);