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)
41 if ((unsigned int)(ret) > LZMA_PROG_ERROR)
42 return "UNKNOWN_ERROR";
44 static const char *msgs[] = {
48 "LZMA_UNSUPPORTED_CHECK",
51 "LZMA_MEMLIMIT_ERROR",
64 coder_loop(lzma_stream *strm, uint8_t *in, size_t in_size,
65 uint8_t *out, size_t out_size,
66 lzma_ret expected_ret, lzma_action finishing_action)
68 size_t in_left = in_size;
69 size_t out_left = out_size > 0 ? out_size + 1 : 0;
70 lzma_action action = LZMA_RUN;
75 strm->next_out = NULL;
81 action = finishing_action;
89 strm->next_out = out++;
93 ret = lzma_code(strm, action);
100 if (ret != expected_ret)
103 if (expected_ret == LZMA_STREAM_END) {
104 if (strm->total_in != in_size || strm->total_out != out_size)
107 if (strm->total_in != in_size || strm->total_out != out_size)
116 decoder_loop_ret(lzma_stream *strm, uint8_t *in, size_t in_size,
117 lzma_ret expected_ret)
119 return coder_loop(strm, in, in_size, NULL, 0, expected_ret, LZMA_RUN);
124 decoder_loop(lzma_stream *strm, uint8_t *in, size_t in_size)
126 return coder_loop(strm, in, in_size, NULL, 0,
127 LZMA_STREAM_END, LZMA_RUN);