-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaddress.test.cpp
65 lines (49 loc) · 1.58 KB
/
address.test.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 <boost/ut.hpp>
#include <lime/address.hpp>
#include <ranges>
#include <random>
using namespace boost::ut;
using namespace boost::ut::literals;
suite<"Address"> address_suite = []
{
auto seed = std::seed_seq{std::random_device{}()};
std::mt19937 random{seed};
static constexpr auto n = 50;
static constexpr auto offset = sizeof(int);
std::vector<int> data;
data.reserve(n);
for (auto i = 0u; n > i; i++)
{
data.emplace_back(random());
}
auto address = lime::address::at(reinterpret_cast<std::uintptr_t>(data.data()));
{
expect(eq(address.has_value(), true));
expect(eq(address->addr(), reinterpret_cast<std::uintptr_t>(data.data())));
for (const auto &value : data)
{
auto ¤t = address.value();
expect(eq(current.read<int>(), value));
auto next = current + offset;
expect(eq(next.has_value(), true));
address.emplace(std::move(next.value()));
}
}
auto back_address = lime::address::at(address->addr() - offset);
{
expect(eq(back_address.has_value(), true));
for (const auto &value : std::views::reverse(data))
{
auto ¤t = back_address.value();
expect(eq(current.read<int>(), value));
current.write(1337);
auto next = current - offset;
expect(eq(next.has_value(), true));
back_address.emplace(std::move(next.value()));
}
}
for (const auto &value : data)
{
expect(eq(value, 1337));
}
};