test_index_hash.c revision 1.1.1.1.2.2 1 1.1.1.1.2.2 martin // SPDX-License-Identifier: 0BSD
2 1.1.1.1.2.2 martin
3 1.1.1.1.2.2 martin ///////////////////////////////////////////////////////////////////////////////
4 1.1.1.1.2.2 martin //
5 1.1.1.1.2.2 martin /// \file test_index_hash.c
6 1.1.1.1.2.2 martin /// \brief Tests src/liblzma/common/index_hash.c API functions
7 1.1.1.1.2.2 martin ///
8 1.1.1.1.2.2 martin /// \note No test included for lzma_index_hash_end since it
9 1.1.1.1.2.2 martin /// would be trivial unless tested for memory leaks
10 1.1.1.1.2.2 martin /// with something like valgrind
11 1.1.1.1.2.2 martin //
12 1.1.1.1.2.2 martin // Author: Jia Tan
13 1.1.1.1.2.2 martin //
14 1.1.1.1.2.2 martin ///////////////////////////////////////////////////////////////////////////////
15 1.1.1.1.2.2 martin
16 1.1.1.1.2.2 martin #include "tests.h"
17 1.1.1.1.2.2 martin
18 1.1.1.1.2.2 martin // Needed for UNPADDED_SIZE_MIN and UNPADDED_SIZE_MAX macro definitions
19 1.1.1.1.2.2 martin // and index_size and vli_ceil4 helper functions
20 1.1.1.1.2.2 martin #include "common/index.h"
21 1.1.1.1.2.2 martin
22 1.1.1.1.2.2 martin
23 1.1.1.1.2.2 martin static void
24 1.1.1.1.2.2 martin test_lzma_index_hash_init(void)
25 1.1.1.1.2.2 martin {
26 1.1.1.1.2.2 martin #ifndef HAVE_DECODERS
27 1.1.1.1.2.2 martin assert_skip("Decoder support disabled");
28 1.1.1.1.2.2 martin #else
29 1.1.1.1.2.2 martin // First test with NULL index_hash.
30 1.1.1.1.2.2 martin // This should create a fresh index_hash.
31 1.1.1.1.2.2 martin lzma_index_hash *index_hash = lzma_index_hash_init(NULL, NULL);
32 1.1.1.1.2.2 martin assert_true(index_hash != NULL);
33 1.1.1.1.2.2 martin
34 1.1.1.1.2.2 martin // Next test with non-NULL index_hash.
35 1.1.1.1.2.2 martin lzma_index_hash *second_hash = lzma_index_hash_init(index_hash, NULL);
36 1.1.1.1.2.2 martin
37 1.1.1.1.2.2 martin // It should not create a new index_hash pointer.
38 1.1.1.1.2.2 martin // Instead it must just re-init the first index_hash.
39 1.1.1.1.2.2 martin assert_true(index_hash == second_hash);
40 1.1.1.1.2.2 martin
41 1.1.1.1.2.2 martin lzma_index_hash_end(index_hash, NULL);
42 1.1.1.1.2.2 martin #endif
43 1.1.1.1.2.2 martin }
44 1.1.1.1.2.2 martin
45 1.1.1.1.2.2 martin
46 1.1.1.1.2.2 martin static void
47 1.1.1.1.2.2 martin test_lzma_index_hash_append(void)
48 1.1.1.1.2.2 martin {
49 1.1.1.1.2.2 martin #ifndef HAVE_DECODERS
50 1.1.1.1.2.2 martin assert_skip("Decoder support disabled");
51 1.1.1.1.2.2 martin #else
52 1.1.1.1.2.2 martin // Test all invalid parameters
53 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_append(NULL, 0, 0),
54 1.1.1.1.2.2 martin LZMA_PROG_ERROR);
55 1.1.1.1.2.2 martin
56 1.1.1.1.2.2 martin // Test NULL index_hash
57 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_append(NULL, UNPADDED_SIZE_MIN,
58 1.1.1.1.2.2 martin LZMA_VLI_MAX), LZMA_PROG_ERROR);
59 1.1.1.1.2.2 martin
60 1.1.1.1.2.2 martin // Test with invalid Unpadded Size
61 1.1.1.1.2.2 martin lzma_index_hash *index_hash = lzma_index_hash_init(NULL, NULL);
62 1.1.1.1.2.2 martin assert_true(index_hash != NULL);
63 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_append(index_hash,
64 1.1.1.1.2.2 martin UNPADDED_SIZE_MIN - 1, LZMA_VLI_MAX),
65 1.1.1.1.2.2 martin LZMA_PROG_ERROR);
66 1.1.1.1.2.2 martin
67 1.1.1.1.2.2 martin // Test with invalid Uncompressed Size
68 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_append(index_hash,
69 1.1.1.1.2.2 martin UNPADDED_SIZE_MIN, LZMA_VLI_MAX + 1),
70 1.1.1.1.2.2 martin LZMA_PROG_ERROR);
71 1.1.1.1.2.2 martin
72 1.1.1.1.2.2 martin // First append a Record describing a small Block.
73 1.1.1.1.2.2 martin // This should succeed.
74 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_append(index_hash,
75 1.1.1.1.2.2 martin UNPADDED_SIZE_MIN, 1), LZMA_OK);
76 1.1.1.1.2.2 martin
77 1.1.1.1.2.2 martin // Append another small Record.
78 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_append(index_hash,
79 1.1.1.1.2.2 martin UNPADDED_SIZE_MIN, 1), LZMA_OK);
80 1.1.1.1.2.2 martin
81 1.1.1.1.2.2 martin // Append a Record that would cause the compressed size to grow
82 1.1.1.1.2.2 martin // too big
83 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_append(index_hash,
84 1.1.1.1.2.2 martin UNPADDED_SIZE_MAX, 1), LZMA_DATA_ERROR);
85 1.1.1.1.2.2 martin
86 1.1.1.1.2.2 martin lzma_index_hash_end(index_hash, NULL);
87 1.1.1.1.2.2 martin #endif
88 1.1.1.1.2.2 martin }
89 1.1.1.1.2.2 martin
90 1.1.1.1.2.2 martin
91 1.1.1.1.2.2 martin #if defined(HAVE_ENCODERS) && defined(HAVE_DECODERS)
92 1.1.1.1.2.2 martin // Fill an index_hash with unpadded and uncompressed VLIs
93 1.1.1.1.2.2 martin // by calling lzma_index_hash_append
94 1.1.1.1.2.2 martin static void
95 1.1.1.1.2.2 martin fill_index_hash(lzma_index_hash *index_hash, const lzma_vli *unpadded_sizes,
96 1.1.1.1.2.2 martin const lzma_vli *uncomp_sizes, uint32_t block_count)
97 1.1.1.1.2.2 martin {
98 1.1.1.1.2.2 martin for (uint32_t i = 0; i < block_count; ++i)
99 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_append(index_hash,
100 1.1.1.1.2.2 martin unpadded_sizes[i], uncomp_sizes[i]), LZMA_OK);
101 1.1.1.1.2.2 martin }
102 1.1.1.1.2.2 martin
103 1.1.1.1.2.2 martin
104 1.1.1.1.2.2 martin // Set the contents of buf to the expected Index based on the
105 1.1.1.1.2.2 martin // .xz specification. This needs the unpadded and uncompressed VLIs
106 1.1.1.1.2.2 martin // to correctly create the Index.
107 1.1.1.1.2.2 martin static void
108 1.1.1.1.2.2 martin generate_index(uint8_t *buf, const lzma_vli *unpadded_sizes,
109 1.1.1.1.2.2 martin const lzma_vli *uncomp_sizes, uint32_t block_count,
110 1.1.1.1.2.2 martin size_t index_max_size)
111 1.1.1.1.2.2 martin {
112 1.1.1.1.2.2 martin size_t in_pos = 0;
113 1.1.1.1.2.2 martin size_t out_pos = 0;
114 1.1.1.1.2.2 martin
115 1.1.1.1.2.2 martin // First set Index Indicator
116 1.1.1.1.2.2 martin buf[out_pos++] = INDEX_INDICATOR;
117 1.1.1.1.2.2 martin
118 1.1.1.1.2.2 martin // Next write out Number of Records
119 1.1.1.1.2.2 martin assert_lzma_ret(lzma_vli_encode(block_count, &in_pos, buf,
120 1.1.1.1.2.2 martin &out_pos, index_max_size), LZMA_STREAM_END);
121 1.1.1.1.2.2 martin
122 1.1.1.1.2.2 martin // Next write out each Record.
123 1.1.1.1.2.2 martin // A Record consists of Unpadded Size and Uncompressed Size
124 1.1.1.1.2.2 martin // written next to each other as VLIs.
125 1.1.1.1.2.2 martin for (uint32_t i = 0; i < block_count; ++i) {
126 1.1.1.1.2.2 martin in_pos = 0;
127 1.1.1.1.2.2 martin assert_lzma_ret(lzma_vli_encode(unpadded_sizes[i], &in_pos,
128 1.1.1.1.2.2 martin buf, &out_pos, index_max_size), LZMA_STREAM_END);
129 1.1.1.1.2.2 martin in_pos = 0;
130 1.1.1.1.2.2 martin assert_lzma_ret(lzma_vli_encode(uncomp_sizes[i], &in_pos,
131 1.1.1.1.2.2 martin buf, &out_pos, index_max_size), LZMA_STREAM_END);
132 1.1.1.1.2.2 martin }
133 1.1.1.1.2.2 martin
134 1.1.1.1.2.2 martin // Add Index Padding
135 1.1.1.1.2.2 martin lzma_vli rounded_out_pos = vli_ceil4(out_pos);
136 1.1.1.1.2.2 martin memzero(buf + out_pos, rounded_out_pos - out_pos);
137 1.1.1.1.2.2 martin out_pos = rounded_out_pos;
138 1.1.1.1.2.2 martin
139 1.1.1.1.2.2 martin // Add the CRC32
140 1.1.1.1.2.2 martin write32le(buf + out_pos, lzma_crc32(buf, out_pos, 0));
141 1.1.1.1.2.2 martin out_pos += 4;
142 1.1.1.1.2.2 martin
143 1.1.1.1.2.2 martin assert_uint_eq(out_pos, index_max_size);
144 1.1.1.1.2.2 martin }
145 1.1.1.1.2.2 martin #endif
146 1.1.1.1.2.2 martin
147 1.1.1.1.2.2 martin
148 1.1.1.1.2.2 martin static void
149 1.1.1.1.2.2 martin test_lzma_index_hash_decode(void)
150 1.1.1.1.2.2 martin {
151 1.1.1.1.2.2 martin #if !defined(HAVE_ENCODERS) || !defined(HAVE_DECODERS)
152 1.1.1.1.2.2 martin assert_skip("Encoder or decoder support disabled");
153 1.1.1.1.2.2 martin #else
154 1.1.1.1.2.2 martin lzma_index_hash *index_hash = lzma_index_hash_init(NULL, NULL);
155 1.1.1.1.2.2 martin assert_true(index_hash != NULL);
156 1.1.1.1.2.2 martin
157 1.1.1.1.2.2 martin size_t in_pos = 0;
158 1.1.1.1.2.2 martin
159 1.1.1.1.2.2 martin // Six valid values for the Unpadded Size fields in an Index
160 1.1.1.1.2.2 martin const lzma_vli unpadded_sizes[6] = {
161 1.1.1.1.2.2 martin UNPADDED_SIZE_MIN,
162 1.1.1.1.2.2 martin 1000,
163 1.1.1.1.2.2 martin 4000,
164 1.1.1.1.2.2 martin 8000,
165 1.1.1.1.2.2 martin 16000,
166 1.1.1.1.2.2 martin 32000
167 1.1.1.1.2.2 martin };
168 1.1.1.1.2.2 martin
169 1.1.1.1.2.2 martin // Six valid values for the Uncompressed Size fields in an Index
170 1.1.1.1.2.2 martin const lzma_vli uncomp_sizes[6] = {
171 1.1.1.1.2.2 martin 1,
172 1.1.1.1.2.2 martin 500,
173 1.1.1.1.2.2 martin 8000,
174 1.1.1.1.2.2 martin 20,
175 1.1.1.1.2.2 martin 1,
176 1.1.1.1.2.2 martin 500
177 1.1.1.1.2.2 martin };
178 1.1.1.1.2.2 martin
179 1.1.1.1.2.2 martin // Add two Records to an index_hash
180 1.1.1.1.2.2 martin fill_index_hash(index_hash, unpadded_sizes, uncomp_sizes, 2);
181 1.1.1.1.2.2 martin
182 1.1.1.1.2.2 martin const lzma_vli size_two_records = lzma_index_hash_size(index_hash);
183 1.1.1.1.2.2 martin assert_uint(size_two_records, >, 0);
184 1.1.1.1.2.2 martin uint8_t *index_two_records = tuktest_malloc(size_two_records);
185 1.1.1.1.2.2 martin
186 1.1.1.1.2.2 martin generate_index(index_two_records, unpadded_sizes, uncomp_sizes, 2,
187 1.1.1.1.2.2 martin size_two_records);
188 1.1.1.1.2.2 martin
189 1.1.1.1.2.2 martin // First test for basic buffer size error
190 1.1.1.1.2.2 martin in_pos = size_two_records + 1;
191 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_decode(index_hash,
192 1.1.1.1.2.2 martin index_two_records, &in_pos,
193 1.1.1.1.2.2 martin size_two_records), LZMA_BUF_ERROR);
194 1.1.1.1.2.2 martin
195 1.1.1.1.2.2 martin // Next test for invalid Index Indicator
196 1.1.1.1.2.2 martin in_pos = 0;
197 1.1.1.1.2.2 martin index_two_records[0] ^= 1;
198 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_decode(index_hash,
199 1.1.1.1.2.2 martin index_two_records, &in_pos,
200 1.1.1.1.2.2 martin size_two_records), LZMA_DATA_ERROR);
201 1.1.1.1.2.2 martin index_two_records[0] ^= 1;
202 1.1.1.1.2.2 martin
203 1.1.1.1.2.2 martin // Next verify the index_hash as expected
204 1.1.1.1.2.2 martin in_pos = 0;
205 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_decode(index_hash,
206 1.1.1.1.2.2 martin index_two_records, &in_pos,
207 1.1.1.1.2.2 martin size_two_records), LZMA_STREAM_END);
208 1.1.1.1.2.2 martin
209 1.1.1.1.2.2 martin // Next test an index_hash with three Records
210 1.1.1.1.2.2 martin index_hash = lzma_index_hash_init(index_hash, NULL);
211 1.1.1.1.2.2 martin fill_index_hash(index_hash, unpadded_sizes, uncomp_sizes, 3);
212 1.1.1.1.2.2 martin
213 1.1.1.1.2.2 martin const lzma_vli size_three_records = lzma_index_hash_size(
214 1.1.1.1.2.2 martin index_hash);
215 1.1.1.1.2.2 martin assert_uint(size_three_records, >, 0);
216 1.1.1.1.2.2 martin uint8_t *index_three_records = tuktest_malloc(size_three_records);
217 1.1.1.1.2.2 martin
218 1.1.1.1.2.2 martin generate_index(index_three_records, unpadded_sizes, uncomp_sizes,
219 1.1.1.1.2.2 martin 3, size_three_records);
220 1.1.1.1.2.2 martin
221 1.1.1.1.2.2 martin in_pos = 0;
222 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_decode(index_hash,
223 1.1.1.1.2.2 martin index_three_records, &in_pos,
224 1.1.1.1.2.2 martin size_three_records), LZMA_STREAM_END);
225 1.1.1.1.2.2 martin
226 1.1.1.1.2.2 martin // Next test an index_hash with five Records
227 1.1.1.1.2.2 martin index_hash = lzma_index_hash_init(index_hash, NULL);
228 1.1.1.1.2.2 martin fill_index_hash(index_hash, unpadded_sizes, uncomp_sizes, 5);
229 1.1.1.1.2.2 martin
230 1.1.1.1.2.2 martin const lzma_vli size_five_records = lzma_index_hash_size(
231 1.1.1.1.2.2 martin index_hash);
232 1.1.1.1.2.2 martin assert_uint(size_five_records, >, 0);
233 1.1.1.1.2.2 martin uint8_t *index_five_records = tuktest_malloc(size_five_records);
234 1.1.1.1.2.2 martin
235 1.1.1.1.2.2 martin generate_index(index_five_records, unpadded_sizes, uncomp_sizes, 5,
236 1.1.1.1.2.2 martin size_five_records);
237 1.1.1.1.2.2 martin
238 1.1.1.1.2.2 martin // Instead of testing all input at once, give input
239 1.1.1.1.2.2 martin // one byte at a time
240 1.1.1.1.2.2 martin in_pos = 0;
241 1.1.1.1.2.2 martin for (lzma_vli i = 0; i < size_five_records - 1; ++i) {
242 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_decode(index_hash,
243 1.1.1.1.2.2 martin index_five_records, &in_pos, in_pos + 1),
244 1.1.1.1.2.2 martin LZMA_OK);
245 1.1.1.1.2.2 martin }
246 1.1.1.1.2.2 martin
247 1.1.1.1.2.2 martin // Last byte should return LZMA_STREAM_END
248 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_decode(index_hash,
249 1.1.1.1.2.2 martin index_five_records, &in_pos,
250 1.1.1.1.2.2 martin in_pos + 1), LZMA_STREAM_END);
251 1.1.1.1.2.2 martin
252 1.1.1.1.2.2 martin // Next test if the index_hash is given an incorrect Unpadded
253 1.1.1.1.2.2 martin // Size. Should detect and report LZMA_DATA_ERROR
254 1.1.1.1.2.2 martin index_hash = lzma_index_hash_init(index_hash, NULL);
255 1.1.1.1.2.2 martin fill_index_hash(index_hash, unpadded_sizes, uncomp_sizes, 5);
256 1.1.1.1.2.2 martin // The sixth Record will have an invalid Unpadded Size
257 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_append(index_hash,
258 1.1.1.1.2.2 martin unpadded_sizes[5] + 1,
259 1.1.1.1.2.2 martin uncomp_sizes[5]), LZMA_OK);
260 1.1.1.1.2.2 martin
261 1.1.1.1.2.2 martin const lzma_vli size_six_records = lzma_index_hash_size(
262 1.1.1.1.2.2 martin index_hash);
263 1.1.1.1.2.2 martin
264 1.1.1.1.2.2 martin assert_uint(size_six_records, >, 0);
265 1.1.1.1.2.2 martin uint8_t *index_six_records = tuktest_malloc(size_six_records);
266 1.1.1.1.2.2 martin
267 1.1.1.1.2.2 martin generate_index(index_six_records, unpadded_sizes, uncomp_sizes, 6,
268 1.1.1.1.2.2 martin size_six_records);
269 1.1.1.1.2.2 martin in_pos = 0;
270 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_decode(index_hash,
271 1.1.1.1.2.2 martin index_six_records, &in_pos,
272 1.1.1.1.2.2 martin size_six_records), LZMA_DATA_ERROR);
273 1.1.1.1.2.2 martin
274 1.1.1.1.2.2 martin // Next test if the Index is corrupt (invalid CRC32).
275 1.1.1.1.2.2 martin // Should detect and report LZMA_DATA_ERROR
276 1.1.1.1.2.2 martin index_hash = lzma_index_hash_init(index_hash, NULL);
277 1.1.1.1.2.2 martin fill_index_hash(index_hash, unpadded_sizes, uncomp_sizes, 2);
278 1.1.1.1.2.2 martin
279 1.1.1.1.2.2 martin index_two_records[size_two_records - 1] ^= 1;
280 1.1.1.1.2.2 martin
281 1.1.1.1.2.2 martin in_pos = 0;
282 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_decode(index_hash,
283 1.1.1.1.2.2 martin index_two_records, &in_pos,
284 1.1.1.1.2.2 martin size_two_records), LZMA_DATA_ERROR);
285 1.1.1.1.2.2 martin
286 1.1.1.1.2.2 martin // Next test with Index and index_hash struct not matching
287 1.1.1.1.2.2 martin // a Record
288 1.1.1.1.2.2 martin index_hash = lzma_index_hash_init(index_hash, NULL);
289 1.1.1.1.2.2 martin fill_index_hash(index_hash, unpadded_sizes, uncomp_sizes, 2);
290 1.1.1.1.2.2 martin // Recalculate Index with invalid Unpadded Size
291 1.1.1.1.2.2 martin const lzma_vli unpadded_sizes_invalid[2] = {
292 1.1.1.1.2.2 martin unpadded_sizes[0],
293 1.1.1.1.2.2 martin unpadded_sizes[1] + 1
294 1.1.1.1.2.2 martin };
295 1.1.1.1.2.2 martin
296 1.1.1.1.2.2 martin generate_index(index_two_records, unpadded_sizes_invalid,
297 1.1.1.1.2.2 martin uncomp_sizes, 2, size_two_records);
298 1.1.1.1.2.2 martin
299 1.1.1.1.2.2 martin in_pos = 0;
300 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_decode(index_hash,
301 1.1.1.1.2.2 martin index_two_records, &in_pos,
302 1.1.1.1.2.2 martin size_two_records), LZMA_DATA_ERROR);
303 1.1.1.1.2.2 martin
304 1.1.1.1.2.2 martin lzma_index_hash_end(index_hash, NULL);
305 1.1.1.1.2.2 martin #endif
306 1.1.1.1.2.2 martin }
307 1.1.1.1.2.2 martin
308 1.1.1.1.2.2 martin
309 1.1.1.1.2.2 martin static void
310 1.1.1.1.2.2 martin test_lzma_index_hash_size(void)
311 1.1.1.1.2.2 martin {
312 1.1.1.1.2.2 martin #ifndef HAVE_DECODERS
313 1.1.1.1.2.2 martin assert_skip("Decoder support disabled");
314 1.1.1.1.2.2 martin #else
315 1.1.1.1.2.2 martin lzma_index_hash *index_hash = lzma_index_hash_init(NULL, NULL);
316 1.1.1.1.2.2 martin assert_true(index_hash != NULL);
317 1.1.1.1.2.2 martin
318 1.1.1.1.2.2 martin // First test empty index_hash
319 1.1.1.1.2.2 martin // Expected size should be:
320 1.1.1.1.2.2 martin // Index Indicator - 1 byte
321 1.1.1.1.2.2 martin // Number of Records - 1 byte
322 1.1.1.1.2.2 martin // List of Records - 0 bytes
323 1.1.1.1.2.2 martin // Index Padding - 2 bytes
324 1.1.1.1.2.2 martin // CRC32 - 4 bytes
325 1.1.1.1.2.2 martin // Total - 8 bytes
326 1.1.1.1.2.2 martin assert_uint_eq(lzma_index_hash_size(index_hash), 8);
327 1.1.1.1.2.2 martin
328 1.1.1.1.2.2 martin // Append a Record describing a small Block to the index_hash
329 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_append(index_hash,
330 1.1.1.1.2.2 martin UNPADDED_SIZE_MIN, 1), LZMA_OK);
331 1.1.1.1.2.2 martin
332 1.1.1.1.2.2 martin // Expected size should be:
333 1.1.1.1.2.2 martin // Index Indicator - 1 byte
334 1.1.1.1.2.2 martin // Number of Records - 1 byte
335 1.1.1.1.2.2 martin // List of Records - 2 bytes
336 1.1.1.1.2.2 martin // Index Padding - 0 bytes
337 1.1.1.1.2.2 martin // CRC32 - 4 bytes
338 1.1.1.1.2.2 martin // Total - 8 bytes
339 1.1.1.1.2.2 martin lzma_vli expected_size = 8;
340 1.1.1.1.2.2 martin assert_uint_eq(lzma_index_hash_size(index_hash), expected_size);
341 1.1.1.1.2.2 martin
342 1.1.1.1.2.2 martin // Append additional small Record
343 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_append(index_hash,
344 1.1.1.1.2.2 martin UNPADDED_SIZE_MIN, 1), LZMA_OK);
345 1.1.1.1.2.2 martin
346 1.1.1.1.2.2 martin // Expected size should be:
347 1.1.1.1.2.2 martin // Index Indicator - 1 byte
348 1.1.1.1.2.2 martin // Number of Records - 1 byte
349 1.1.1.1.2.2 martin // List of Records - 4 bytes
350 1.1.1.1.2.2 martin // Index Padding - 2 bytes
351 1.1.1.1.2.2 martin // CRC32 - 4 bytes
352 1.1.1.1.2.2 martin // Total - 12 bytes
353 1.1.1.1.2.2 martin expected_size = 12;
354 1.1.1.1.2.2 martin assert_uint_eq(lzma_index_hash_size(index_hash), expected_size);
355 1.1.1.1.2.2 martin
356 1.1.1.1.2.2 martin // Append a larger Record to the index_hash (3 bytes for each VLI)
357 1.1.1.1.2.2 martin const lzma_vli three_byte_vli = 0x10000;
358 1.1.1.1.2.2 martin assert_lzma_ret(lzma_index_hash_append(index_hash,
359 1.1.1.1.2.2 martin three_byte_vli, three_byte_vli), LZMA_OK);
360 1.1.1.1.2.2 martin
361 1.1.1.1.2.2 martin // Expected size should be:
362 1.1.1.1.2.2 martin // Index Indicator - 1 byte
363 1.1.1.1.2.2 martin // Number of Records - 1 byte
364 1.1.1.1.2.2 martin // List of Records - 10 bytes
365 1.1.1.1.2.2 martin // Index Padding - 0 bytes
366 1.1.1.1.2.2 martin // CRC32 - 4 bytes
367 1.1.1.1.2.2 martin // Total - 16 bytes
368 1.1.1.1.2.2 martin expected_size = 16;
369 1.1.1.1.2.2 martin assert_uint_eq(lzma_index_hash_size(index_hash), expected_size);
370 1.1.1.1.2.2 martin
371 1.1.1.1.2.2 martin lzma_index_hash_end(index_hash, NULL);
372 1.1.1.1.2.2 martin #endif
373 1.1.1.1.2.2 martin }
374 1.1.1.1.2.2 martin
375 1.1.1.1.2.2 martin
376 1.1.1.1.2.2 martin extern int
377 1.1.1.1.2.2 martin main(int argc, char **argv)
378 1.1.1.1.2.2 martin {
379 1.1.1.1.2.2 martin tuktest_start(argc, argv);
380 1.1.1.1.2.2 martin tuktest_run(test_lzma_index_hash_init);
381 1.1.1.1.2.2 martin tuktest_run(test_lzma_index_hash_append);
382 1.1.1.1.2.2 martin tuktest_run(test_lzma_index_hash_decode);
383 1.1.1.1.2.2 martin tuktest_run(test_lzma_index_hash_size);
384 1.1.1.1.2.2 martin return tuktest_end();
385 1.1.1.1.2.2 martin }
386