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 ///////////////////////////////////////////////////////////////////////////////
27 #define memcrap(buf, size) memset(buf, 0xFD, size)
29 #define expect(test) ((test) ? 0 : (fprintf(stderr, "%s:%u: %s\n", \
30 __FILE__, __LINE__, #test), exit(1), 0))
32 #define succeed(test) expect(!test)
34 #define fail(test) expect(test)
37 static inline const char *
38 lzma_ret_sym(lzma_ret ret)
48 str = "LZMA_STREAM_END";
52 str = "LZMA_PROG_ERROR";
56 str = "LZMA_DATA_ERROR";
60 str = "LZMA_MEM_ERROR";
64 str = "LZMA_BUF_ERROR";
67 case LZMA_HEADER_ERROR:
68 str = "LZMA_HEADER_ERROR";
71 case LZMA_UNSUPPORTED_CHECK:
72 str = "LZMA_UNSUPPORTED_CHECK";
81 coder_loop(lzma_stream *strm, uint8_t *in, size_t in_size,
82 uint8_t *out, size_t out_size,
83 lzma_ret expected_ret, lzma_action finishing_action)
85 size_t in_left = in_size;
86 size_t out_left = out_size > 0 ? out_size + 1 : 0;
87 lzma_action action = LZMA_RUN;
92 strm->next_out = NULL;
98 action = finishing_action;
100 strm->next_in = in++;
106 strm->next_out = out++;
110 ret = lzma_code(strm, action);
117 if (ret != expected_ret)
120 if (expected_ret == LZMA_STREAM_END) {
121 if (strm->total_in != in_size || strm->total_out != out_size)
124 if (strm->total_in + 1 != in_size
125 || strm->total_out != out_size)
134 decoder_loop_ret(lzma_stream *strm, uint8_t *in, size_t in_size,
135 lzma_ret expected_ret)
137 return coder_loop(strm, in, in_size, NULL, 0, expected_ret, LZMA_RUN);
142 decoder_loop(lzma_stream *strm, uint8_t *in, size_t in_size)
144 return coder_loop(strm, in, in_size, NULL, 0,
145 LZMA_STREAM_END, LZMA_RUN);