rippled
Loading...
Searching...
No Matches
Basics_test.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 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 <test/nodestore/TestBase.h>
21
22#include <xrpl/nodestore/detail/DecodedBlob.h>
23#include <xrpl/nodestore/detail/EncodedBlob.h>
24
25namespace ripple {
26namespace NodeStore {
27
28// Tests predictable batches, and NodeObject blob encoding
29//
31{
32public:
33 // Make sure predictable object generation works!
34 void
35 testBatches(std::uint64_t const seedValue)
36 {
37 testcase("batch");
38
39 auto batch1 = createPredictableBatch(numObjectsToTest, seedValue);
40
41 auto batch2 = createPredictableBatch(numObjectsToTest, seedValue);
42
43 BEAST_EXPECT(areBatchesEqual(batch1, batch2));
44
45 auto batch3 = createPredictableBatch(numObjectsToTest, seedValue + 1);
46
47 BEAST_EXPECT(!areBatchesEqual(batch1, batch3));
48 }
49
50 // Checks encoding/decoding blobs
51 void
52 testBlobs(std::uint64_t const seedValue)
53 {
54 testcase("encoding");
55
57
58 for (int i = 0; i < batch.size(); ++i)
59 {
60 EncodedBlob encoded(batch[i]);
61
62 DecodedBlob decoded(
63 encoded.getKey(), encoded.getData(), encoded.getSize());
64
65 BEAST_EXPECT(decoded.wasOk());
66
67 if (decoded.wasOk())
68 {
69 std::shared_ptr<NodeObject> const object(
70 decoded.createObject());
71
72 BEAST_EXPECT(isSame(batch[i], object));
73 }
74 }
75 }
76
77 void
78 run() override
79 {
80 std::uint64_t const seedValue = 50;
81
82 testBatches(seedValue);
83
84 testBlobs(seedValue);
85 }
86};
87
88BEAST_DEFINE_TESTSUITE(NodeStoreBasic, nodestore, ripple);
89
90} // namespace NodeStore
91} // namespace ripple
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:155
Parsed key/value blob into NodeObject components.
Definition DecodedBlob.h:39
std::shared_ptr< NodeObject > createObject()
Create a NodeObject from this data.
bool wasOk() const noexcept
Determine if the decoding was successful.
Definition DecodedBlob.h:46
Convert a NodeObject from in-memory to database format.
Definition EncodedBlob.h:56
void const * getKey() const noexcept
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:77
static Batch createPredictableBatch(int numObjects, std::uint64_t seed)
Definition TestBase.h:82
static bool areBatchesEqual(Batch const &lhs, Batch const &rhs)
Definition TestBase.h:122
bool isSame(std::shared_ptr< NodeObject > const &lhs, std::shared_ptr< NodeObject > const &rhs)
Returns true if objects are identical.
Definition TestBase.h:59
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25