rippled
Loading...
Searching...
No Matches
varint_test.cpp
1#include <xrpl/beast/unit_test.h>
2#include <xrpl/nodestore/detail/varint.h>
3
4#include <array>
5#include <vector>
6
7namespace ripple {
8namespace NodeStore {
9namespace tests {
10
12{
13public:
14 void
16 {
17 testcase("encode, decode");
18 for (auto const v : vv)
19 {
21 auto const n0 = write_varint(vi.data(), v);
22 expect(n0 > 0, "write error");
23 expect(n0 == size_varint(v), "size error");
24 std::size_t v1;
25 auto const n1 = read_varint(vi.data(), n0, v1);
26 expect(n1 == n0, "read error");
27 expect(v == v1, "wrong value");
28 }
29 }
30
31 void
32 run() override
33 {
35 {0,
36 1,
37 2,
38 126,
39 127,
40 128,
41 253,
42 254,
43 255,
44 16127,
45 16128,
46 16129,
47 0xff,
48 0xffff,
49 0xffffffff,
50 0xffffffffffffUL,
51 0xffffffffffffffffUL});
52 }
53};
54
55BEAST_DEFINE_TESTSUITE(varint, nodestore, ripple);
56
57} // namespace tests
58} // namespace NodeStore
59} // namespace ripple
A testsuite class.
Definition suite.h:52
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:152
bool expect(Condition const &shouldBeTrue)
Evaluate a test condition.
Definition suite.h:226
void run() override
Runs the suite.
void test_varints(std::vector< std::size_t > vv)
T data(T... args)
std::size_t read_varint(void const *buf, std::size_t buflen, std::size_t &t)
Definition varint.h:38
std::size_t size_varint(T v)
Definition varint.h:71
std::size_t write_varint(void *p0, std::size_t v)
Definition varint.h:84
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6