1 /*
2 * Copyright (c) 2020, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under both the BSD-style license (found in the
6 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 * in the COPYING file in the root directory of this source tree).
8 * You may select, at your option, one of the above-listed licenses.
9 */
10 #include <stddef.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14
15 #include "decompress_sources.h"
16 #include <linux/zstd.h>
17
18 #define CONTROL(x) \
19 do { \
20 if (!(x)) { \
21 fprintf(stderr, "%s:%u: %s failed!\n", __FUNCTION__, __LINE__, #x); \
22 abort(); \
23 } \
24 } while (0)
25
26
27 static const char kEmptyZstdFrame[] = {
28 0x28, 0xb5, 0x2f, 0xfd, 0x24, 0x00, 0x01, 0x00, 0x00, 0x99, 0xe9, 0xd8, 0x51
29 };
30
test_decompress_unzstd()31 static void test_decompress_unzstd() {
32 fprintf(stderr, "Testing decompress unzstd... ");
33 {
34 size_t const wkspSize = zstd_dctx_workspace_bound();
35 void* wksp = malloc(wkspSize);
36 CONTROL(wksp != NULL);
37 ZSTD_DCtx* dctx = zstd_init_dctx(wksp, wkspSize);
38 CONTROL(dctx != NULL);
39 size_t const dSize = zstd_decompress_dctx(dctx, NULL, 0, kEmptyZstdFrame, sizeof(kEmptyZstdFrame));
40 CONTROL(!zstd_is_error(dSize));
41 CONTROL(dSize == 0);
42 free(wksp);
43 }
44 fprintf(stderr, "Ok\n");
45 }
46
main(void)47 int main(void) {
48 test_decompress_unzstd();
49 return 0;
50 }
51