blob_test.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. *******************************************************************************
  3. \file blob_test.c
  4. \brief Tests for blob functions
  5. \project bee2/test
  6. \created 2023.03.21
  7. \version 2023.03.23
  8. \copyright The Bee2 authors
  9. \license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
  10. *******************************************************************************
  11. */
  12. #include <bee2/core/blob.h>
  13. #include <bee2/core/mem.h>
  14. /*
  15. *******************************************************************************
  16. Тестирование
  17. *******************************************************************************
  18. */
  19. bool_t blobTest()
  20. {
  21. blob_t b1 = 0;
  22. blob_t b2 = 0;
  23. // create / resize
  24. b1 = blobCreate(123);
  25. b2 = blobResize(b2, 120);
  26. if (!blobIsValid(b1) || !blobIsValid(b2))
  27. {
  28. blobClose(b2), blobClose(b1);
  29. return FALSE;
  30. }
  31. // copy / cmp
  32. memSet(b1, 0x36, blobSize(b1));
  33. b2 = blobCopy(b2, b1);
  34. if (!blobIsValid(b2) ||
  35. blobSize(b1) != blobSize(b2) ||
  36. !memEq(b1, b2, blobSize(b1)) ||
  37. !blobEq(b1, b2))
  38. {
  39. blobClose(b2), blobClose(b1);
  40. return FALSE;
  41. }
  42. memSet(b2, 0x5C, blobSize(b2));
  43. if (blobCmp(b1, b2) >= 0)
  44. {
  45. blobClose(b2), blobClose(b1);
  46. return FALSE;
  47. }
  48. b2 = blobResize(b2, blobSize(b2) - 100);
  49. if (blobCmp(b1, b2) <= 0)
  50. {
  51. blobClose(b2), blobClose(b1);
  52. return FALSE;
  53. }
  54. // wipe / close
  55. blobWipe(b2);
  56. blobClose(b2);
  57. blobClose(b1);
  58. return TRUE;
  59. }