xrpld
Loading...
Searching...
No Matches
tests/libxrpl/core/HashRouter.cpp
1#include <xrpl/core/HashRouter.h>
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/basics/chrono.h>
5
6#include <gtest/gtest.h>
7
8namespace xrpl::tests {
9
10namespace {
11
15struct HashRouterTest : public ::testing::Test
16{
17 TestStopwatch clock;
18 HashRouter router{HashRouter::Setup{}, clock};
19};
20
21} // namespace
22
23TEST_F(HashRouterTest, clear_flags_clears_only_the_named_flags)
24{
25 UInt256 const key{1};
26 EXPECT_TRUE(router.setFlags(key, HashRouterFlags::SAVED | HashRouterFlags::BAD));
27
28 EXPECT_TRUE(router.clearFlags(key, HashRouterFlags::SAVED));
29 EXPECT_EQ(router.getFlags(key), HashRouterFlags::BAD);
30
31 // The flag is clear, so setting it again is a change.
32 EXPECT_TRUE(router.setFlags(key, HashRouterFlags::SAVED));
33
34 // A mask with one set flag and one clear flag is still a change.
35 EXPECT_TRUE(router.clearFlags(key, HashRouterFlags::SAVED | HashRouterFlags::HELD));
36 EXPECT_EQ(router.getFlags(key), HashRouterFlags::BAD);
37}
38
39TEST_F(HashRouterTest, clear_flags_reports_when_nothing_changes)
40{
41 UInt256 const key{2};
42
43 // No entry, so nothing to clear and no entry is created: the next insertion is a new one.
44 EXPECT_FALSE(router.clearFlags(key, HashRouterFlags::SAVED));
45 EXPECT_TRUE(router.addSuppressionPeer(key, 0));
46
47 // An entry whose flags do not include the one named.
48 EXPECT_TRUE(router.setFlags(key, HashRouterFlags::BAD));
49 EXPECT_FALSE(router.clearFlags(key, HashRouterFlags::SAVED));
50 EXPECT_EQ(router.getFlags(key), HashRouterFlags::BAD);
51}
52
53} // namespace xrpl::tests
TEST_F(HashRouterTest, clear_flags_clears_only_the_named_flags)
BaseUInt< 256 > UInt256
Definition base_uint.h:581
beast::ManualClock< std::chrono::steady_clock > TestStopwatch
A manual Stopwatch for unit tests.
Definition chrono.h:95