rippled
Loading...
Searching...
No Matches
Serializer_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2024 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpl/beast/unit_test.h>
21#include <xrpl/protocol/Serializer.h>
22
23#include <limits>
24
25namespace ripple {
26
28{
29 void
30 run() override
31 {
32 {
35 -1,
36 0,
37 1,
39 for (std::int32_t value : values)
40 {
41 Serializer s;
42 s.add32(value);
43 BEAST_EXPECT(s.size() == 4);
44 SerialIter sit(s.slice());
45 BEAST_EXPECT(sit.geti32() == value);
46 }
47 }
48 {
51 -1,
52 0,
53 1,
55 for (std::int64_t value : values)
56 {
57 Serializer s;
58 s.add64(value);
59 BEAST_EXPECT(s.size() == 8);
60 SerialIter sit(s.slice());
61 BEAST_EXPECT(sit.geti64() == value);
62 }
63 }
64 }
65};
66
67BEAST_DEFINE_TESTSUITE(Serializer, protocol, ripple);
68
69} // namespace ripple
A testsuite class.
Definition: suite.h:55
std::int64_t geti64()
Definition: Serializer.cpp:417
std::int32_t geti32()
Definition: Serializer.cpp:405
std::size_t size() const noexcept
Definition: Serializer.h:73
Slice slice() const noexcept
Definition: Serializer.h:67
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:26
void run() override
Runs the suite.