-
Notifications
You must be signed in to change notification settings - Fork 3
/
ZmeyaTest08.cpp
76 lines (64 loc) · 1.85 KB
/
ZmeyaTest08.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
66
67
68
69
70
71
72
73
74
75
76
#include "TestHelper.h"
#include "Zmeya.h"
#include "gtest/gtest.h"
struct IteratorsTestRoot
{
zm::Array<int> arr;
zm::HashSet<int> set;
zm::HashMap<int, int> map;
};
static void validate(const IteratorsTestRoot* root)
{
std::vector<int> temp;
EXPECT_EQ(root->arr.size(), std::size_t(11));
temp.clear();
temp.resize(root->arr.size(), 0);
for (const int& val : root->arr)
{
temp[val] += 1;
}
for (size_t i = 0; i < temp.size(); i++)
{
EXPECT_EQ(temp[i], 1);
}
EXPECT_EQ(root->set.size(), std::size_t(6));
temp.clear();
temp.resize(root->set.size(), 0);
for (const int& val : root->set)
{
temp[val] += 1;
}
for (size_t i = 0; i < temp.size(); i++)
{
EXPECT_EQ(temp[i], 1);
}
EXPECT_EQ(root->map.size(), std::size_t(3));
temp.clear();
temp.resize(root->map.size() * 2, 0);
for (const zm::Pair<const int, int>& val : root->map)
{
temp[val.first] += 1;
temp[val.second] += 1;
}
for (size_t i = 0; i < temp.size(); i++)
{
EXPECT_EQ(temp[i], 1);
}
}
TEST(ZmeyaTestSuite, IteratorsTest)
{
std::vector<char> bytesCopy;
{
std::shared_ptr<zm::BlobBuilder> blobBuilder = zm::BlobBuilder::create();
zm::BlobPtr<IteratorsTestRoot> root = blobBuilder->allocate<IteratorsTestRoot>();
blobBuilder->copyTo(root->arr, {10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0});
blobBuilder->copyTo(root->set, {0, 1, 4, 3, 5, 2});
blobBuilder->copyTo(root->map, {{0, 1}, {3, 2}, {4, 5}});
validate(root.get());
zm::Span<char> bytes = blobBuilder->finalize();
bytesCopy = utils::copyBytes(bytes);
std::memset(bytes.data, 0xFF, bytes.size);
}
const IteratorsTestRoot* rootCopy = (const IteratorsTestRoot*)(bytesCopy.data());
validate(rootCopy);
}