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 ///////////////////////////////////////////////////////////////////////////////
29 #define memcrap(buf, size) memset(buf, 0xFD, size)
31 #define expect(test) ((test) ? 0 : (fprintf(stderr, "%s:%u: %s\n", \
32 __FILE__, __LINE__, #test), abort(), 0))
34 #define succeed(test) expect(!(test))
36 #define fail(test) expect(test)
39 static inline const char *
40 lzma_ret_sym(lzma_ret ret)
42 if ((unsigned int)(ret) > LZMA_PROG_ERROR)
43 return "UNKNOWN_ERROR";
45 static const char *msgs[] = {
49 "LZMA_UNSUPPORTED_CHECK",
52 "LZMA_MEMLIMIT_ERROR",
65 coder_loop(lzma_stream *strm, uint8_t *in, size_t in_size,
66 uint8_t *out, size_t out_size,
67 lzma_ret expected_ret, lzma_action finishing_action)
69 size_t in_left = in_size;
70 size_t out_left = out_size > 0 ? out_size + 1 : 0;
71 lzma_action action = LZMA_RUN;
76 strm->next_out = NULL;
82 action = finishing_action;
90 strm->next_out = out++;
94 ret = lzma_code(strm, action);
101 if (ret != expected_ret)
104 if (expected_ret == LZMA_STREAM_END) {
105 if (strm->total_in != in_size || strm->total_out != out_size)
108 if (strm->total_in != in_size || strm->total_out != out_size)
117 decoder_loop_ret(lzma_stream *strm, uint8_t *in, size_t in_size,
118 lzma_ret expected_ret)
120 return coder_loop(strm, in, in_size, NULL, 0, expected_ret, LZMA_RUN);
125 decoder_loop(lzma_stream *strm, uint8_t *in, size_t in_size)
127 return coder_loop(strm, in, in_size, NULL, 0,
128 LZMA_STREAM_END, LZMA_RUN);