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#include <xrpl/beast/unit_test.h>
22#include <array>
23#include <vector>
24
25namespace ripple {
26namespace NodeStore {
27namespace tests {
28
30{
31public:
32 void
34 {
35 testcase("encode, decode");
36 for (auto const v : vv)
37 {
39 auto const n0 = write_varint(vi.data(), v);
40 expect(n0 > 0, "write error");
41 expect(n0 == size_varint(v), "size error");
42 std::size_t v1;
43 auto const n1 = read_varint(vi.data(), n0, v1);
44 expect(n1 == n0, "read error");
45 expect(v == v1, "wrong value");
46 }
47 }
48
49 void
50 run() override
51 {
53 {0,
54 1,
55 2,
56 126,
57 127,
58 128,
59 253,
60 254,
61 255,
62 16127,
63 16128,
64 16129,
65 0xff,
66 0xffff,
67 0xffffffff,
68 0xffffffffffffUL,
69 0xffffffffffffffffUL});
70 }
71};
72
73BEAST_DEFINE_TESTSUITE(varint, NodeStore, ripple);
74
75} // namespace tests
76} // namespace NodeStore
77} // namespace ripple
A testsuite class.
Definition: suite.h:53
testcase_t testcase
Memberspace for declaring test cases.
Definition: suite.h:153
bool expect(Condition const &shouldBeTrue)
Evaluate a test condition.
Definition: suite.h:227
void run() override
Runs the suite.
Definition: varint_test.cpp:50
void test_varints(std::vector< std::size_t > vv)
Definition: varint_test.cpp:33
T data(T... args)
std::size_t read_varint(void const *buf, std::size_t buflen, std::size_t &t)
Definition: varint.h:56
std::size_t size_varint(T v)
Definition: varint.h:89
std::size_t write_varint(void *p0, std::size_t v)
Definition: varint.h:102
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26