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