rippled
Loading...
Searching...
No Matches
Basics_test.cpp
1#include <test/nodestore/TestBase.h>
2
3#include <xrpl/nodestore/detail/DecodedBlob.h>
4#include <xrpl/nodestore/detail/EncodedBlob.h>
5
6namespace ripple {
7namespace NodeStore {
8
9// Tests predictable batches, and NodeObject blob encoding
10//
12{
13public:
14 // Make sure predictable object generation works!
15 void
16 testBatches(std::uint64_t const seedValue)
17 {
18 testcase("batch");
19
20 auto batch1 = createPredictableBatch(numObjectsToTest, seedValue);
21
22 auto batch2 = createPredictableBatch(numObjectsToTest, seedValue);
23
24 BEAST_EXPECT(areBatchesEqual(batch1, batch2));
25
26 auto batch3 = createPredictableBatch(numObjectsToTest, seedValue + 1);
27
28 BEAST_EXPECT(!areBatchesEqual(batch1, batch3));
29 }
30
31 // Checks encoding/decoding blobs
32 void
33 testBlobs(std::uint64_t const seedValue)
34 {
35 testcase("encoding");
36
38
39 for (int i = 0; i < batch.size(); ++i)
40 {
41 EncodedBlob encoded(batch[i]);
42
43 DecodedBlob decoded(
44 encoded.getKey(), encoded.getData(), encoded.getSize());
45
46 BEAST_EXPECT(decoded.wasOk());
47
48 if (decoded.wasOk())
49 {
50 std::shared_ptr<NodeObject> const object(
51 decoded.createObject());
52
53 BEAST_EXPECT(isSame(batch[i], object));
54 }
55 }
56 }
57
58 void
59 run() override
60 {
61 std::uint64_t const seedValue = 50;
62
63 testBatches(seedValue);
64
65 testBlobs(seedValue);
66 }
67};
68
69BEAST_DEFINE_TESTSUITE(NodeStoreBasic, nodestore, ripple);
70
71} // namespace NodeStore
72} // namespace ripple
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:152
Parsed key/value blob into NodeObject components.
Definition DecodedBlob.h:20
std::shared_ptr< NodeObject > createObject()
Create a NodeObject from this data.
bool wasOk() const noexcept
Determine if the decoding was successful.
Definition DecodedBlob.h:27
Convert a NodeObject from in-memory to database format.
Definition EncodedBlob.h:37
void const * getKey() const noexcept
Definition EncodedBlob.h:98
std::size_t getSize() const noexcept
void const * getData() const noexcept
void testBlobs(std::uint64_t const seedValue)
void testBatches(std::uint64_t const seedValue)
void run() override
Runs the suite.
static int const numObjectsToTest
Definition TestBase.h:58
static Batch createPredictableBatch(int numObjects, std::uint64_t seed)
Definition TestBase.h:63
static bool areBatchesEqual(Batch const &lhs, Batch const &rhs)
Definition TestBase.h:103
bool isSame(std::shared_ptr< NodeObject > const &lhs, std::shared_ptr< NodeObject > const &rhs)
Returns true if objects are identical.
Definition TestBase.h:40
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6