-
Notifications
You must be signed in to change notification settings - Fork 3
/
ZmeyaTest02.cpp
65 lines (50 loc) · 1.74 KB
/
ZmeyaTest02.cpp
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
#include "TestHelper.h"
#include "Zmeya.h"
#include "gtest/gtest.h"
struct PointerTestNode
{
int32_t payload;
zm::Pointer<PointerTestNode> other;
};
struct PointerTestRoot
{
zm::Pointer<PointerTestNode> left;
zm::Pointer<PointerTestNode> right;
};
static void validate(const PointerTestRoot* root)
{
EXPECT_NE(root->left, nullptr);
EXPECT_NE(root->right, nullptr);
EXPECT_NE(root->left->other, nullptr);
EXPECT_NE(root->right->other, nullptr);
EXPECT_EQ(root->left->payload, -13);
EXPECT_EQ(root->right->payload, 13);
EXPECT_EQ(root->left->other->payload, 13);
EXPECT_EQ(root->right->other->payload, -13);
EXPECT_EQ(root->right->other, root->left);
EXPECT_EQ(root->left->other, root->right);
}
TEST(ZmeyaTestSuite, PointerTest)
{
std::vector<char> bytesCopy;
{
std::shared_ptr<zm::BlobBuilder> blobBuilder = zm::BlobBuilder::create();
zm::BlobPtr<PointerTestRoot> root = blobBuilder->allocate<PointerTestRoot>();
zm::BlobPtr<PointerTestNode> nodeLeft = blobBuilder->allocate<PointerTestNode>();
zm::BlobPtr<PointerTestNode> nodeRight = blobBuilder->allocate<PointerTestNode>();
root->left = nodeLeft;
root->right = nodeRight;
nodeLeft->payload = -13;
nodeLeft->other = nodeRight;
nodeRight->payload = 13;
nodeRight->other = nodeLeft;
validate(root.get());
zm::Span<char> bytes = blobBuilder->finalize(16);
// check (optional) blob size alignment
EXPECT_TRUE((bytes.size % 16) == 0);
bytesCopy = utils::copyBytes(bytes);
std::memset(bytes.data, 0xFF, bytes.size);
}
const PointerTestRoot* rootCopy = (const PointerTestRoot*)(bytesCopy.data());
validate(rootCopy);
}