Update THANKS
[xz/debian.git] / tests / test_filter_str.c
blob0deb589991646040ef32587fd8668ed67b2c2c77
1 // SPDX-License-Identifier: 0BSD
3 ///////////////////////////////////////////////////////////////////////////////
4 //
5 /// \file test_filter_str.c
6 /// \brief Tests Filter string functions
7 //
8 // Author: Jia Tan
9 //
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "tests.h"
15 static void
16 test_lzma_str_to_filters(void)
18 lzma_filter filters[LZMA_FILTERS_MAX + 1];
19 int error_pos;
21 // Test with NULL string.
22 error_pos = -1;
23 assert_true(lzma_str_to_filters(NULL, &error_pos, filters, 0,
24 NULL) != NULL);
25 assert_int_eq(error_pos, 0);
27 // Test with NULL filter array.
28 error_pos = -1;
29 assert_true(lzma_str_to_filters("lzma2", &error_pos, NULL, 0,
30 NULL) != NULL);
31 assert_int_eq(error_pos, 0);
33 // Test with unsupported flags.
34 error_pos = -1;
35 assert_true(lzma_str_to_filters("lzma2", &error_pos, filters,
36 UINT32_MAX, NULL) != NULL);
37 assert_int_eq(error_pos, 0);
39 error_pos = -1;
40 assert_true(lzma_str_to_filters("lzma2", &error_pos, filters,
41 LZMA_STR_NO_SPACES << 1, NULL) != NULL);
42 assert_int_eq(error_pos, 0);
44 error_pos = -1;
45 assert_true(lzma_str_to_filters("lzma2", &error_pos, filters,
46 LZMA_STR_NO_SPACES, NULL) != NULL);
47 assert_int_eq(error_pos, 0);
49 // Test with empty string.
50 error_pos = -1;
51 assert_true(lzma_str_to_filters("", &error_pos,
52 filters, 0, NULL) != NULL);
53 assert_int_eq(error_pos, 0);
55 // Test with invalid filter name and missing filter name.
56 error_pos = -1;
57 assert_true(lzma_str_to_filters("abcd", &error_pos,
58 filters, 0, NULL) != NULL);
59 assert_int_eq(error_pos, 0);
61 error_pos = -1;
62 assert_true(lzma_str_to_filters("lzma2 abcd", &error_pos,
63 filters, 0, NULL) != NULL);
64 assert_int_eq(error_pos, 6);
66 error_pos = -1;
67 assert_true(lzma_str_to_filters("lzma2--abcd", &error_pos,
68 filters, 0, NULL) != NULL);
69 assert_int_eq(error_pos, 7);
71 error_pos = -1;
72 assert_true(lzma_str_to_filters("lzma2--", &error_pos,
73 filters, 0, NULL) != NULL);
74 assert_int_eq(error_pos, 7);
76 // Test LZMA_STR_ALL_FILTERS flag (should work with LZMA1 if built).
77 #if defined(HAVE_ENCODER_LZMA1) || defined(HAVE_DECODER_LZMA1)
78 // Using LZMA1 as a Filter should fail without LZMA_STR_ALL_FILTERS.
79 error_pos = -1;
80 assert_true(lzma_str_to_filters("lzma1", &error_pos, filters,
81 0, NULL) != NULL);
82 assert_int_eq(error_pos, 0);
84 error_pos = -1;
85 assert_true(lzma_str_to_filters("lzma1", &error_pos, filters,
86 LZMA_STR_ALL_FILTERS, NULL) == NULL);
87 assert_int_eq(error_pos, 5);
89 // Verify Filters array IDs are correct. The array should contain
90 // only two elements:
91 // 1. LZMA1 Filter
92 // 2. LZMA_VLI_UNKNOWN filter array terminator
93 assert_uint_eq(filters[0].id, LZMA_FILTER_LZMA1);
94 assert_uint_eq(filters[1].id, LZMA_VLI_UNKNOWN);
96 lzma_filters_free(filters, NULL);
97 #endif
99 // Test LZMA_STR_NO_VALIDATION flag. This should allow having the
100 // same Filter multiple times in the chain and having a non-last
101 // Filter like lzma2 appear before another Filter.
102 // Without the flag, "lzma2 lzma2" must fail.
103 error_pos = -1;
104 assert_true(lzma_str_to_filters("lzma2 lzma2", &error_pos, filters,
105 0, NULL) != NULL);
106 assert_int_eq(error_pos, 11);
108 error_pos = -1;
109 assert_true(lzma_str_to_filters("lzma2 lzma2", &error_pos, filters,
110 LZMA_STR_NO_VALIDATION, NULL) == NULL);
111 assert_int_eq(error_pos, 11);
113 assert_uint_eq(filters[0].id, LZMA_FILTER_LZMA2);
114 assert_uint_eq(filters[1].id, LZMA_FILTER_LZMA2);
115 assert_uint_eq(filters[2].id, LZMA_VLI_UNKNOWN);
117 lzma_filters_free(filters, NULL);
119 // Should fail with invalid Filter options (lc + lp must be <= 4).
120 error_pos = -1;
121 assert_true(lzma_str_to_filters("lzma2:lc=3,lp=3", &error_pos, filters,
122 LZMA_STR_NO_VALIDATION, NULL) != NULL);
123 assert_int_eq(error_pos, 15);
125 // Test invalid option name.
126 error_pos = -1;
127 assert_true(lzma_str_to_filters("lzma2:foo=1,bar=2", &error_pos,
128 filters, 0, NULL) != NULL);
129 assert_int_eq(error_pos, 6);
131 error_pos = -1;
132 assert_true(lzma_str_to_filters("lzma2:pb=1,bar=2", &error_pos,
133 filters, 0, NULL) != NULL);
134 assert_int_eq(error_pos, 11);
136 // Test missing option value.
137 error_pos = -1;
138 assert_true(lzma_str_to_filters("lzma2:lc=", &error_pos,
139 filters, 0, NULL) != NULL);
140 assert_int_eq(error_pos, 9);
142 error_pos = -1;
143 assert_true(lzma_str_to_filters("lzma2:=,pb=1", &error_pos,
144 filters, 0, NULL) != NULL);
145 assert_int_eq(error_pos, 6);
147 // Test unsupported preset value.
148 error_pos = -1;
149 assert_true(lzma_str_to_filters("-10", &error_pos,
150 filters, 0, NULL) != NULL);
151 assert_int_eq(error_pos, 2);
153 error_pos = -1;
154 assert_true(lzma_str_to_filters("-5f", &error_pos,
155 filters, 0, NULL) != NULL);
156 assert_int_eq(error_pos, 2);
158 // Test filter chain too long.
159 error_pos = -1;
160 assert_true(lzma_str_to_filters("lzma2 lzma2 lzma2 lzma2 lzma2",
161 &error_pos, filters, LZMA_STR_NO_VALIDATION,
162 NULL) != NULL);
163 assert_int_eq(error_pos, 24); // The fifth is too many.
165 #if defined(HAVE_ENCODER_LZMA1) || defined(HAVE_DECODER_LZMA1)
166 // Should fail with a Filter not supported in the .xz format (lzma1).
167 error_pos = -1;
168 assert_true(lzma_str_to_filters("lzma1", &error_pos, filters,
169 LZMA_STR_NO_VALIDATION, NULL) != NULL);
170 assert_int_eq(error_pos, 0);
171 #endif
173 // Test setting options with the "=" format.
174 error_pos = -1;
175 assert_true(lzma_str_to_filters("lzma2=dict=4096,lc=2,lp=2,pb=1,"
176 "mode=fast,nice=3,mf=hc3,depth=10", &error_pos,
177 filters, 0, NULL) == NULL);
178 assert_int_eq(error_pos, 63);
179 assert_uint_eq(filters[0].id, LZMA_FILTER_LZMA2);
180 assert_uint_eq(filters[1].id, LZMA_VLI_UNKNOWN);
182 lzma_options_lzma *opts = filters[0].options;
183 assert_uint_eq(opts->dict_size, 4096);
184 assert_uint_eq(opts->lc, 2);
185 assert_uint_eq(opts->lp, 2);
186 assert_uint_eq(opts->pb, 1);
187 assert_uint_eq(opts->mode, LZMA_MODE_FAST);
188 assert_uint_eq(opts->nice_len, 3);
189 assert_uint_eq(opts->mf, LZMA_MF_HC3);
190 assert_uint_eq(opts->depth, 10);
192 lzma_filters_free(filters, NULL);
194 #if defined(HAVE_ENCODER_X86) || defined(HAVE_DECODER_X86)
195 // Test BCJ Filter options.
196 error_pos = -1;
197 assert_true(lzma_str_to_filters("x86:start=16", &error_pos, filters,
198 LZMA_STR_NO_VALIDATION, NULL) == NULL);
199 assert_int_eq(error_pos, 12);
201 assert_uint_eq(filters[0].id, LZMA_FILTER_X86);
202 assert_uint_eq(filters[1].id, LZMA_VLI_UNKNOWN);
204 lzma_options_bcj *bcj_opts = filters[0].options;
205 assert_uint_eq(bcj_opts->start_offset, 16);
207 lzma_filters_free(filters, NULL);
208 #endif
210 #if defined(HAVE_ENCODER_DELTA) || defined(HAVE_DECODER_DELTA)
211 // Test Delta Filter options.
212 error_pos = -1;
213 assert_true(lzma_str_to_filters("delta:dist=20", &error_pos, filters,
214 LZMA_STR_NO_VALIDATION, NULL) == NULL);
215 assert_int_eq(error_pos, 13);
217 assert_uint_eq(filters[0].id, LZMA_FILTER_DELTA);
218 assert_uint_eq(filters[1].id, LZMA_VLI_UNKNOWN);
220 lzma_options_delta *delta_opts = filters[0].options;
221 assert_uint_eq(delta_opts->dist, 20);
223 lzma_filters_free(filters, NULL);
224 #endif
226 // Test skipping leading spaces.
227 error_pos = -1;
228 assert_true(lzma_str_to_filters(" lzma2", &error_pos, filters,
229 0, NULL) == NULL);
230 assert_int_eq(error_pos, 9);
232 assert_uint_eq(filters[0].id, LZMA_FILTER_LZMA2);
233 assert_uint_eq(filters[1].id, LZMA_VLI_UNKNOWN);
235 lzma_filters_free(filters, NULL);
237 // Test skipping trailing spaces.
238 error_pos = -1;
239 assert_true(lzma_str_to_filters("lzma2 ", &error_pos, filters,
240 0, NULL) == NULL);
241 assert_int_eq(error_pos, 9);
243 assert_uint_eq(filters[0].id, LZMA_FILTER_LZMA2);
244 assert_uint_eq(filters[1].id, LZMA_VLI_UNKNOWN);
246 lzma_filters_free(filters, NULL);
248 // Test with "--" instead of space separating.
249 error_pos = -1;
250 assert_true(lzma_str_to_filters("lzma2--lzma2", &error_pos, filters,
251 LZMA_STR_NO_VALIDATION, NULL) == NULL);
252 assert_int_eq(error_pos, 12);
254 assert_uint_eq(filters[0].id, LZMA_FILTER_LZMA2);
255 assert_uint_eq(filters[1].id, LZMA_FILTER_LZMA2);
256 assert_uint_eq(filters[2].id, LZMA_VLI_UNKNOWN);
258 lzma_filters_free(filters, NULL);
260 // Test preset with and without leading "-", and with "e".
261 error_pos = -1;
262 assert_true(lzma_str_to_filters("-3", &error_pos, filters,
263 0, NULL) == NULL);
264 assert_int_eq(error_pos, 2);
266 assert_uint_eq(filters[0].id, LZMA_FILTER_LZMA2);
267 assert_uint_eq(filters[1].id, LZMA_VLI_UNKNOWN);
269 lzma_filters_free(filters, NULL);
271 error_pos = -1;
272 assert_true(lzma_str_to_filters("4", &error_pos, filters,
273 0, NULL) == NULL);
274 assert_int_eq(error_pos, 1);
276 assert_uint_eq(filters[0].id, LZMA_FILTER_LZMA2);
277 assert_uint_eq(filters[1].id, LZMA_VLI_UNKNOWN);
279 lzma_filters_free(filters, NULL);
281 error_pos = -1;
282 assert_true(lzma_str_to_filters("9e", &error_pos, filters,
283 0, NULL) == NULL);
284 assert_int_eq(error_pos, 2);
286 assert_uint_eq(filters[0].id, LZMA_FILTER_LZMA2);
287 assert_uint_eq(filters[1].id, LZMA_VLI_UNKNOWN);
289 lzma_filters_free(filters, NULL);
291 // Test using a preset as an lzma2 option.
292 error_pos = -1;
293 assert_true(lzma_str_to_filters("lzma2:preset=9e", &error_pos, filters,
294 0, NULL) == NULL);
295 assert_int_eq(error_pos, 15);
297 assert_uint_eq(filters[0].id, LZMA_FILTER_LZMA2);
298 assert_uint_eq(filters[1].id, LZMA_VLI_UNKNOWN);
300 lzma_filters_free(filters, NULL);
302 // Test setting dictionary size with invalid modifier suffix.
303 error_pos = -1;
304 assert_true(lzma_str_to_filters("lzma2:dict=4096ZiB", &error_pos, filters,
305 0, NULL) != NULL);
306 assert_int_eq(error_pos, 15);
308 error_pos = -1;
309 assert_true(lzma_str_to_filters("lzma2:dict=4096KiBs", &error_pos, filters,
310 0, NULL) != NULL);
311 assert_int_eq(error_pos, 15);
313 // Test option that cannot have multiplier modifier.
314 error_pos = -1;
315 assert_true(lzma_str_to_filters("lzma2:pb=1k", &error_pos, filters,
316 0, NULL) != NULL);
317 assert_int_eq(error_pos, 10);
319 // Test option value too large.
320 error_pos = -1;
321 assert_true(lzma_str_to_filters("lzma2:dict=4096GiB", &error_pos, filters,
322 0, NULL) != NULL);
323 assert_int_eq(error_pos, 11);
325 // Test valid uses of multiplier modifiers (k,m,g).
326 error_pos = -1;
327 assert_true(lzma_str_to_filters("lzma2:dict=4096KiB", &error_pos, filters,
328 0, NULL) == NULL);
329 assert_int_eq(error_pos, 18);
331 assert_uint_eq(filters[0].id, LZMA_FILTER_LZMA2);
332 assert_uint_eq(filters[1].id, LZMA_VLI_UNKNOWN);
334 opts = filters[0].options;
335 assert_uint_eq(opts->dict_size, 4096 << 10);
337 lzma_filters_free(filters, NULL);
339 error_pos = -1;
340 assert_true(lzma_str_to_filters("lzma2:dict=40Mi", &error_pos, filters,
341 0, NULL) == NULL);
342 assert_int_eq(error_pos, 15);
344 assert_uint_eq(filters[0].id, LZMA_FILTER_LZMA2);
345 assert_uint_eq(filters[1].id, LZMA_VLI_UNKNOWN);
347 opts = filters[0].options;
348 assert_uint_eq(opts->dict_size, 40 << 20);
350 lzma_filters_free(filters, NULL);
352 error_pos = -1;
353 assert_true(lzma_str_to_filters("lzma2:dict=1g", &error_pos, filters,
354 0, NULL) == NULL);
355 assert_int_eq(error_pos, 13);
357 assert_uint_eq(filters[0].id, LZMA_FILTER_LZMA2);
358 assert_uint_eq(filters[1].id, LZMA_VLI_UNKNOWN);
360 opts = filters[0].options;
361 assert_uint_eq(opts->dict_size, 1 << 30);
363 lzma_filters_free(filters, NULL);
367 static void
368 test_lzma_str_from_filters(void)
370 lzma_filter filters[LZMA_FILTERS_MAX];
371 filters[0].id = LZMA_VLI_UNKNOWN;
373 char *output_str = NULL;
375 // Test basic NULL inputs.
376 assert_lzma_ret(lzma_str_from_filters(NULL, filters, 0, NULL),
377 LZMA_PROG_ERROR);
379 assert_lzma_ret(lzma_str_from_filters(&output_str, NULL, 0, NULL),
380 LZMA_PROG_ERROR);
382 // Test with empty filters array.
383 assert_lzma_ret(lzma_str_from_filters(&output_str, filters, 0, NULL),
384 LZMA_OPTIONS_ERROR);
386 // Create a simple filter array only containing an LZMA2 Filter.
387 assert_true(lzma_str_to_filters("lzma2", NULL, filters, 0, NULL)
388 == NULL);
390 // Test with bad flags.
391 assert_lzma_ret(lzma_str_from_filters(&output_str, filters,
392 LZMA_STR_ALL_FILTERS, NULL), LZMA_OPTIONS_ERROR);
394 assert_lzma_ret(lzma_str_from_filters(&output_str, filters,
395 LZMA_STR_NO_VALIDATION, NULL), LZMA_OPTIONS_ERROR);
397 // Test with no flags.
398 assert_lzma_ret(lzma_str_from_filters(&output_str, filters, 0, NULL),
399 LZMA_OK);
401 assert_str_eq(output_str, "lzma2");
402 free(output_str);
404 // Test LZMA_STR_ENCODER flag.
405 // Only the return value is checked since the actual string
406 // may change in the future (even though it is unlikely).
407 // The order of options or the inclusion of new options could
408 // cause a change in output, so we will avoid hardcoding an
409 // expected result.
410 assert_lzma_ret(lzma_str_from_filters(&output_str, filters,
411 LZMA_STR_ENCODER, NULL), LZMA_OK);
412 free(output_str);
414 // Test LZMA_STR_DECODER flag.
415 assert_lzma_ret(lzma_str_from_filters(&output_str, filters,
416 LZMA_STR_DECODER, NULL), LZMA_OK);
417 free(output_str);
419 // Test LZMA_STR_GETOPT_LONG flag.
420 assert_lzma_ret(lzma_str_from_filters(&output_str, filters,
421 LZMA_STR_GETOPT_LONG, NULL), LZMA_OK);
422 free(output_str);
424 // Test LZMA_STR_NO_SPACES flag.
425 assert_lzma_ret(lzma_str_from_filters(&output_str, filters,
426 LZMA_STR_NO_SPACES, NULL), LZMA_OK);
428 // Check to be sure there are no spaces.
429 assert_true(strchr(output_str, ' ') == NULL);
431 free(output_str);
433 lzma_filters_free(filters, NULL);
435 #if defined(HAVE_ENCODER_X86) || defined(HAVE_DECODER_X86)
436 assert_true(lzma_str_to_filters("x86 lzma2", NULL, filters, 0, NULL)
437 == NULL);
439 // It always allocates the options structure even when it's not
440 // needed due to start_offset = 0 being the default.
441 assert_true(filters[0].options != NULL);
443 assert_lzma_ret(lzma_str_from_filters(&output_str, filters, 0, NULL),
444 LZMA_OK);
446 assert_str_eq(output_str, "x86 lzma2");
448 free(output_str);
450 // Test setting BCJ option to NULL.
451 free(filters[0].options);
452 filters[0].options = NULL;
454 assert_lzma_ret(lzma_str_from_filters(&output_str, filters, 0, NULL),
455 LZMA_OK);
457 assert_str_eq(output_str, "x86 lzma2");
459 lzma_filters_free(filters, NULL);
460 free(output_str);
461 #endif
463 lzma_options_lzma opts;
464 assert_false(lzma_lzma_preset(&opts, LZMA_PRESET_DEFAULT));
466 // Test with too many Filters (array terminated after 4+ filters).
467 lzma_filter oversized_filters[LZMA_FILTERS_MAX + 2];
469 for (uint32_t i = 0; i < ARRAY_SIZE(oversized_filters) - 1; i++) {
470 oversized_filters[i].id = LZMA_FILTER_LZMA2;
471 oversized_filters[i].options = &opts;
474 oversized_filters[LZMA_FILTERS_MAX + 1].id = LZMA_VLI_UNKNOWN;
475 oversized_filters[LZMA_FILTERS_MAX + 1].options = NULL;
477 assert_lzma_ret(lzma_str_from_filters(&output_str, oversized_filters,
478 0, NULL), LZMA_OPTIONS_ERROR);
480 // Test with NULL filter options (when they cannot be NULL).
481 filters[0].id = LZMA_FILTER_LZMA2;
482 filters[0].options = NULL;
483 filters[1].id = LZMA_VLI_UNKNOWN;
485 assert_lzma_ret(lzma_str_from_filters(&output_str, filters,
486 LZMA_STR_ENCODER, NULL), LZMA_OPTIONS_ERROR);
488 // Test with bad Filter ID.
489 filters[0].id = LZMA_VLI_UNKNOWN - 1;
490 assert_lzma_ret(lzma_str_from_filters(&output_str, filters,
491 LZMA_STR_ENCODER, NULL), LZMA_OPTIONS_ERROR);
495 static const char supported_encoders[][9] = {
496 "lzma2",
497 #ifdef HAVE_ENCODER_X86
498 "x86",
499 #endif
500 #ifdef HAVE_ENCODER_POWERPC
501 "powerpc",
502 #endif
503 #ifdef HAVE_ENCODER_IA64
504 "ia64",
505 #endif
506 #ifdef HAVE_ENCODER_ARM
507 "arm",
508 #endif
509 #ifdef HAVE_ENCODER_ARMTHUMB
510 "armthumb",
511 #endif
512 #ifdef HAVE_ENCODER_SPARC
513 "sparc",
514 #endif
515 #ifdef HAVE_ENCODER_ARM64
516 "arm64",
517 #endif
518 #ifdef HAVE_ENCODER_RISCV
519 "riscv",
520 #endif
521 #ifdef HAVE_ENCODER_DELTA
522 "delta",
523 #endif
526 static const char supported_decoders[][9] = {
527 "lzma2",
528 #ifdef HAVE_DECODER_X86
529 "x86",
530 #endif
531 #ifdef HAVE_DECODER_POWERPC
532 "powerpc",
533 #endif
534 #ifdef HAVE_DECODER_IA64
535 "ia64",
536 #endif
537 #ifdef HAVE_DECODER_ARM
538 "arm",
539 #endif
540 #ifdef HAVE_DECODER_ARMTHUMB
541 "armthumb",
542 #endif
543 #ifdef HAVE_DECODER_SPARC
544 "sparc",
545 #endif
546 #ifdef HAVE_DECODER_ARM64
547 "arm64",
548 #endif
549 #ifdef HAVE_DECODER_RISCV
550 "riscv",
551 #endif
552 #ifdef HAVE_DECODER_DELTA
553 "delta",
554 #endif
557 static const char supported_filters[][9] = {
558 "lzma2",
559 #if defined(HAVE_ENCODER_X86) || defined(HAVE_DECODER_X86)
560 "x86",
561 #endif
562 #if defined(HAVE_ENCODER_POWERPC) || defined(HAVE_DECODER_POWERPC)
563 "powerpc",
564 #endif
565 #if defined(HAVE_ENCODER_IA64) || defined(HAVE_DECODER_IA64)
566 "ia64",
567 #endif
568 #if defined(HAVE_ENCODER_ARM) || defined(HAVE_DECODER_ARM)
569 "arm",
570 #endif
571 #if defined(HAVE_ENCODER_ARMTHUMB) || defined(HAVE_DECODER_ARMTHUMB)
572 "armthumb",
573 #endif
574 #if defined(HAVE_ENCODER_SPARC) || defined(HAVE_DECODER_SPARC)
575 "sparc",
576 #endif
577 #if defined(HAVE_ENCODER_ARM64) || defined(HAVE_DECODER_ARM64)
578 "arm64",
579 #endif
580 #if defined(HAVE_ENCODER_RISCV) || defined(HAVE_DECODER_RISCV)
581 "riscv",
582 #endif
583 #if defined(HAVE_ENCODER_DELTA) || defined(HAVE_DECODER_DELTA)
584 "delta",
585 #endif
589 static void
590 test_lzma_str_list_filters(void)
592 // Test with basic NULL inputs.
593 assert_lzma_ret(lzma_str_list_filters(NULL, LZMA_VLI_UNKNOWN, 0,
594 NULL), LZMA_PROG_ERROR);
596 char *str = NULL;
598 // Test with bad flags.
599 assert_lzma_ret(lzma_str_list_filters(&str, LZMA_VLI_UNKNOWN,
600 LZMA_STR_NO_VALIDATION , NULL), LZMA_OPTIONS_ERROR);
601 assert_true(str == NULL);
603 assert_lzma_ret(lzma_str_list_filters(&str, LZMA_VLI_UNKNOWN,
604 LZMA_STR_NO_SPACES, NULL), LZMA_OPTIONS_ERROR);
605 assert_true(str == NULL);
607 // Test with bad Filter ID.
608 assert_lzma_ret(lzma_str_list_filters(&str, LZMA_VLI_UNKNOWN - 1,
609 0, NULL), LZMA_OPTIONS_ERROR);
610 assert_true(str == NULL);
612 // Test LZMA_STR_ENCODER flag.
613 assert_lzma_ret(lzma_str_list_filters(&str, LZMA_VLI_UNKNOWN,
614 LZMA_STR_ENCODER, NULL), LZMA_OK);
616 // NOTE: Just checking for "contains" is a bit weak check as
617 // "arm" matches "armthumb" and "arm64" too.
618 for (uint32_t i = 0; i < ARRAY_SIZE(supported_encoders); i++)
619 assert_str_contains(str, supported_encoders[i]);
621 free(str);
623 // Test LZMA_STR_DECODER flag.
624 assert_lzma_ret(lzma_str_list_filters(&str, LZMA_VLI_UNKNOWN,
625 LZMA_STR_DECODER, NULL), LZMA_OK);
627 for (uint32_t i = 0; i < ARRAY_SIZE(supported_decoders); i++)
628 assert_str_contains(str, supported_decoders[i]);
630 free(str);
632 // Test LZMA_STR_GETOPT_LONG flag.
633 assert_lzma_ret(lzma_str_list_filters(&str, LZMA_VLI_UNKNOWN,
634 LZMA_STR_GETOPT_LONG, NULL), LZMA_OK);
635 assert_str_contains(str, "--");
637 free(str);
639 // Test LZMA_STR_ALL_FILTERS flag.
640 assert_lzma_ret(lzma_str_list_filters(&str, LZMA_VLI_UNKNOWN,
641 LZMA_STR_ALL_FILTERS, NULL), LZMA_OK);
642 #if defined(HAVE_ENCODER_LZMA1) || defined(HAVE_DECODER_LZMA1)
643 // With the flag, the string should contain the LZMA1 Filter.
644 assert_str_contains(str, "lzma1");
646 free(str);
648 // If a non .xz filter is specified, it should still list the Filter.
649 assert_lzma_ret(lzma_str_list_filters(&str, LZMA_FILTER_LZMA1,
650 0, NULL), LZMA_OK);
651 assert_str_eq(str, "lzma1");
652 #endif
653 free(str);
655 // Test with no flags.
656 assert_lzma_ret(lzma_str_list_filters(&str, LZMA_VLI_UNKNOWN,
657 0, NULL), LZMA_OK);
659 for (uint32_t i = 0; i < ARRAY_SIZE(supported_filters); i++)
660 assert_str_contains(str, supported_filters[i]);
662 assert_str_doesnt_contain(str, "lzma1");
664 free(str);
666 // Test providing a Filter ID.
667 assert_lzma_ret(lzma_str_list_filters(&str, LZMA_FILTER_LZMA2,
668 LZMA_STR_ALL_FILTERS, NULL), LZMA_OK);
669 assert_str_eq(str, "lzma2");
671 free(str);
675 extern int
676 main(int argc, char **argv)
678 tuktest_start(argc, argv);
680 tuktest_run(test_lzma_str_to_filters);
681 tuktest_run(test_lzma_str_from_filters);
682 tuktest_run(test_lzma_str_list_filters);
684 return tuktest_end();