memory_ut.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "memory.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #pragma pack(1)
  4. struct Y_PACKED TSampleStruct1 {
  5. ui8 A;
  6. ui8 B;
  7. };
  8. #pragma pack(1)
  9. struct Y_PACKED TSampleStruct2 {
  10. ui8 A;
  11. ui16 B;
  12. i32 C;
  13. };
  14. #pragma pack(1)
  15. struct Y_PACKED TSampleStruct3 {
  16. TSampleStruct2 A;
  17. ui64 B;
  18. };
  19. #pragma pack()
  20. Y_UNIT_TEST_SUITE(TUtilDraftMemoryTest) {
  21. Y_UNIT_TEST(IsZeroTest) {
  22. ui8 a1 = 0;
  23. UNIT_ASSERT(IsZero(a1));
  24. a1 = 0xF0;
  25. UNIT_ASSERT(!IsZero(a1));
  26. i32 a2 = -1;
  27. UNIT_ASSERT(!IsZero(a2));
  28. a2 = 0;
  29. UNIT_ASSERT(IsZero(a2));
  30. double a3 = 0.0;
  31. UNIT_ASSERT(IsZero(a3));
  32. a3 = 1.e-13;
  33. UNIT_ASSERT(!IsZero(a3));
  34. TSampleStruct1 ss1;
  35. ss1.A = 0;
  36. ss1.B = 0;
  37. UNIT_ASSERT(IsZero(ss1));
  38. ss1.A = 0;
  39. ss1.B = 12;
  40. UNIT_ASSERT(!IsZero(ss1));
  41. TSampleStruct2 ss2;
  42. ss2.A = 0;
  43. ss2.B = 100;
  44. ss2.C = 0;
  45. UNIT_ASSERT(!IsZero(ss2));
  46. ss2.B = 0;
  47. UNIT_ASSERT(IsZero(ss2));
  48. TSampleStruct3 ss3;
  49. ss3.A = ss2;
  50. ss3.B = 0;
  51. UNIT_ASSERT(IsZero(ss3));
  52. ss3.B = 0x030;
  53. UNIT_ASSERT(!IsZero(ss3));
  54. ss3.B = 0;
  55. ss3.A.C = -789;
  56. UNIT_ASSERT(!IsZero(ss3));
  57. }
  58. }