1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Common definitions for test applications
6 // Author: Lasse Collin
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
11 ///////////////////////////////////////////////////////////////////////////////
17 #include "tuklib_integer.h"
22 // Invalid value for the lzma_check enumeration. This must be positive
23 // but small enough to fit into signed char since the underlying type might
24 // one some platform be a signed char.
26 // Don't put LZMA_ at the beginning of the name so that it is obvious that
27 // this constant doesn't come from the API headers.
28 #define INVALID_LZMA_CHECK_ID ((lzma_check)(LZMA_CHECK_ID_MAX + 1))
31 #define memcrap(buf, size) memset(buf, 0xFD, size)
34 // TODO: Remove these three macros once all tests have been converted.
35 #define expect(test) ((test) ? 0 : (fprintf(stderr, "%s:%d: %s\n", \
36 __FILE__, __LINE__, #test), abort(), 0))
38 #define succeed(test) expect(!(test))
40 #define fail(test) expect(test)
43 // This table and macro allow getting more readable error messages when
44 // comparing the lzma_ret enumeration values.
45 static const char enum_strings_lzma_ret
[][24] = {
49 "LZMA_UNSUPPORTED_CHECK",
52 "LZMA_MEMLIMIT_ERROR",
61 #define assert_lzma_ret(test_expr, ref_val) \
62 assert_enum_eq(test_expr, ref_val, enum_strings_lzma_ret)
65 static const char enum_strings_lzma_check
[][24] = {
68 "LZMA_CHECK_UNKNOWN_2",
69 "LZMA_CHECK_UNKNOWN_3",
71 "LZMA_CHECK_UNKNOWN_5",
72 "LZMA_CHECK_UNKNOWN_6",
73 "LZMA_CHECK_UNKNOWN_7",
74 "LZMA_CHECK_UNKNOWN_8",
75 "LZMA_CHECK_UNKNOWN_9",
77 "LZMA_CHECK_UNKNOWN_11",
78 "LZMA_CHECK_UNKNOWN_12",
79 "LZMA_CHECK_UNKNOWN_13",
80 "LZMA_CHECK_UNKNOWN_14",
81 "LZMA_CHECK_UNKNOWN_15",
84 #define assert_lzma_check(test_expr, ref_val) \
85 assert_enum_eq(test_expr, ref_val, enum_strings_lzma_check)
89 coder_loop(lzma_stream
*strm
, uint8_t *in
, size_t in_size
,
90 uint8_t *out
, size_t out_size
,
91 lzma_ret expected_ret
, lzma_action finishing_action
)
93 size_t in_left
= in_size
;
94 size_t out_left
= out_size
> 0 ? out_size
+ 1 : 0;
95 lzma_action action
= LZMA_RUN
;
100 strm
->next_out
= NULL
;
106 action
= finishing_action
;
108 strm
->next_in
= in
++;
114 strm
->next_out
= out
++;
118 ret
= lzma_code(strm
, action
);
125 if (ret
!= expected_ret
)
128 if (strm
->total_in
!= in_size
|| strm
->total_out
!= out_size
)
136 decoder_loop_ret(lzma_stream
*strm
, uint8_t *in
, size_t in_size
,
137 lzma_ret expected_ret
)
139 return coder_loop(strm
, in
, in_size
, NULL
, 0, expected_ret
, LZMA_RUN
);
144 decoder_loop(lzma_stream
*strm
, uint8_t *in
, size_t in_size
)
146 return coder_loop(strm
, in
, in_size
, NULL
, 0,
147 LZMA_STREAM_END
, LZMA_RUN
);