1 #include <stddef.h>
2 #include <stdint.h>
3 #include <stdio.h>
4 
5 #include "zstd_seekable.h"
6 
7 /* Basic unit tests for zstd seekable format */
main(int argc,const char ** argv)8 int main(int argc, const char** argv)
9 {
10     unsigned testNb = 1;
11     printf("Beginning zstd seekable format tests...\n");
12     printf("Test %u - check that seekable decompress does not hang: ", testNb++);
13     {   /* Github issue #2335 */
14         const size_t compressed_size = 17;
15         const uint8_t compressed_data[17] = {
16             '^',
17             '*',
18             'M',
19             '\x18',
20             '\t',
21             '\x00',
22             '\x00',
23             '\x00',
24             '\x00',
25             '\x00',
26             '\x00',
27             '\x00',
28             ';',
29             (uint8_t)('\xb1'),
30             (uint8_t)('\xea'),
31             (uint8_t)('\x92'),
32             (uint8_t)('\x8f'),
33         };
34         const size_t uncompressed_size = 32;
35         uint8_t uncompressed_data[32];
36 
37         ZSTD_seekable* stream = ZSTD_seekable_create();
38         size_t status = ZSTD_seekable_initBuff(stream, compressed_data, compressed_size);
39         if (ZSTD_isError(status)) {
40             ZSTD_seekable_free(stream);
41             goto _test_error;
42         }
43 
44         const size_t offset = 2;
45         /* Should return an error, but not hang */
46         status = ZSTD_seekable_decompress(stream, uncompressed_data, uncompressed_size, offset);
47         if (!ZSTD_isError(status)) {
48             ZSTD_seekable_free(stream);
49             goto _test_error;
50         }
51 
52         ZSTD_seekable_free(stream);
53     }
54     printf("Success!\n");
55 
56     /* TODO: Add more tests */
57     printf("Finished tests\n");
58     return 0;
59 
60 _test_error:
61     printf("test failed! Exiting..\n");
62     return 1;
63 }
64