static_test.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 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. #include "decompress_sources.h"
  15. #include <linux/zstd.h>
  16. #define CONTROL(x) \
  17. do { \
  18. if (!(x)) { \
  19. fprintf(stderr, "%s:%u: %s failed!\n", __FUNCTION__, __LINE__, #x); \
  20. abort(); \
  21. } \
  22. } while (0)
  23. static const char kEmptyZstdFrame[] = {
  24. 0x28, 0xb5, 0x2f, 0xfd, 0x24, 0x00, 0x01, 0x00, 0x00, 0x99, 0xe9, 0xd8, 0x51
  25. };
  26. static void test_decompress_unzstd(void) {
  27. fprintf(stderr, "Testing decompress unzstd... ");
  28. {
  29. size_t const wkspSize = zstd_dctx_workspace_bound();
  30. void* wksp = malloc(wkspSize);
  31. ZSTD_DCtx* dctx = zstd_init_dctx(wksp, wkspSize);
  32. CONTROL(wksp != NULL);
  33. CONTROL(dctx != NULL);
  34. {
  35. size_t const dSize = zstd_decompress_dctx(dctx, NULL, 0, kEmptyZstdFrame, sizeof(kEmptyZstdFrame));
  36. CONTROL(!zstd_is_error(dSize));
  37. CONTROL(dSize == 0);
  38. }
  39. free(wksp);
  40. }
  41. fprintf(stderr, "Ok\n");
  42. }
  43. int main(void) {
  44. test_decompress_unzstd();
  45. return 0;
  46. }