git subrepo pull (merge) --force deps/libchdr
[pcsx_rearmed.git] / deps / libchdr / deps / zstd-1.5.5 / contrib / linux-kernel / test / static_test.c
CommitLineData
648db22b 1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
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
27static const char kEmptyZstdFrame[] = {
28 0x28, 0xb5, 0x2f, 0xfd, 0x24, 0x00, 0x01, 0x00, 0x00, 0x99, 0xe9, 0xd8, 0x51
29};
30
31static void test_decompress_unzstd(void) {
32 fprintf(stderr, "Testing decompress unzstd... ");
33 {
34 size_t const wkspSize = zstd_dctx_workspace_bound();
35 void* wksp = malloc(wkspSize);
36 ZSTD_DCtx* dctx = zstd_init_dctx(wksp, wkspSize);
37 CONTROL(wksp != NULL);
38 CONTROL(dctx != NULL);
39 {
40 size_t const dSize = zstd_decompress_dctx(dctx, NULL, 0, kEmptyZstdFrame, sizeof(kEmptyZstdFrame));
41 CONTROL(!zstd_is_error(dSize));
42 CONTROL(dSize == 0);
43 }
44 free(wksp);
45 }
46 fprintf(stderr, "Ok\n");
47}
48
49int main(void) {
50 test_decompress_unzstd();
51 return 0;
52}