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