xrpld
Loading...
Searching...
No Matches
tests/libxrpl/protocol/Serializer.cpp
1#include <xrpl/protocol/Serializer.h>
2
3#include <gtest/gtest.h>
4
5#include <array>
6#include <cstdint>
7#include <limits>
8
9using namespace xrpl;
10
11TEST(Serializer, add32_roundtrip)
12{
13 static constexpr auto kValues = std::to_array<std::int32_t>({
15 -1,
16 0,
17 1,
19 });
20
21 for (std::int32_t const value : kValues)
22 {
23 Serializer s;
24 s.add32(value);
25 EXPECT_EQ(s.size(), 4);
26 SerialIter sit(s.slice());
27 EXPECT_EQ(sit.geti32(), value);
28 }
29}
30
31TEST(Serializer, add64_roundtrip)
32{
33 static constexpr auto kValues = std::to_array<std::int64_t>({
35 -1,
36 0,
37 1,
39 });
40
41 for (std::int64_t const value : kValues)
42 {
43 Serializer s;
44 s.add64(value);
45 EXPECT_EQ(s.size(), 8);
46 SerialIter sit(s.slice());
47 EXPECT_EQ(sit.geti64(), value);
48 }
49}
Slice slice() const noexcept
Definition Serializer.h:45
std::size_t size() const noexcept
Definition Serializer.h:51
T max(T... args)
T min(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
TEST(FileUtilitiesTest, get_file_contents)