rippled
Loading...
Searching...
No Matches
varint_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of Beast: https://github.com/vinniefalco/Beast
4 Copyright 2014, Vinnie Falco <vinnie.falco@gmail.com>
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 <xrpld/nodestore/detail/varint.h>
21
22#include <xrpl/beast/unit_test.h>
23
24#include <array>
25#include <vector>
26
27namespace ripple {
28namespace NodeStore {
29namespace tests {
30
32{
33public:
34 void
36 {
37 testcase("encode, decode");
38 for (auto const v : vv)
39 {
41 auto const n0 = write_varint(vi.data(), v);
42 expect(n0 > 0, "write error");
43 expect(n0 == size_varint(v), "size error");
44 std::size_t v1;
45 auto const n1 = read_varint(vi.data(), n0, v1);
46 expect(n1 == n0, "read error");
47 expect(v == v1, "wrong value");
48 }
49 }
50
51 void
52 run() override
53 {
55 {0,
56 1,
57 2,
58 126,
59 127,
60 128,
61 253,
62 254,
63 255,
64 16127,
65 16128,
66 16129,
67 0xff,
68 0xffff,
69 0xffffffff,
70 0xffffffffffffUL,
71 0xffffffffffffffffUL});
72 }
73};
74
75BEAST_DEFINE_TESTSUITE(varint, nodestore, ripple);
76
77} // namespace tests
78} // namespace NodeStore
79} // namespace ripple
A testsuite class.
Definition suite.h:55
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:155
bool expect(Condition const &shouldBeTrue)
Evaluate a test condition.
Definition suite.h:229
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:57
std::size_t size_varint(T v)
Definition varint.h:90
std::size_t write_varint(void *p0, std::size_t v)
Definition varint.h:103
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25