mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Format first-party source according to .clang-format
This commit is contained in:
committed by
manojsdoshi
parent
65dfc5d19e
commit
50760c6935
@@ -27,7 +27,8 @@ namespace test {
|
||||
|
||||
struct Buffer_test : beast::unit_test::suite
|
||||
{
|
||||
bool sane (Buffer const& b) const
|
||||
bool
|
||||
sane(Buffer const& b) const
|
||||
{
|
||||
if (b.size() == 0)
|
||||
return b.data() == nullptr;
|
||||
@@ -35,85 +36,81 @@ struct Buffer_test : beast::unit_test::suite
|
||||
return b.data() != nullptr;
|
||||
}
|
||||
|
||||
void run() override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
std::uint8_t const data[] =
|
||||
{
|
||||
0xa8, 0xa1, 0x38, 0x45, 0x23, 0xec, 0xe4, 0x23,
|
||||
0x71, 0x6d, 0x2a, 0x18, 0xb4, 0x70, 0xcb, 0xf5,
|
||||
0xac, 0x2d, 0x89, 0x4d, 0x19, 0x9c, 0xf0, 0x2c,
|
||||
0x15, 0xd1, 0xf9, 0x9b, 0x66, 0xd2, 0x30, 0xd3
|
||||
};
|
||||
std::uint8_t const data[] = {
|
||||
0xa8, 0xa1, 0x38, 0x45, 0x23, 0xec, 0xe4, 0x23, 0x71, 0x6d, 0x2a,
|
||||
0x18, 0xb4, 0x70, 0xcb, 0xf5, 0xac, 0x2d, 0x89, 0x4d, 0x19, 0x9c,
|
||||
0xf0, 0x2c, 0x15, 0xd1, 0xf9, 0x9b, 0x66, 0xd2, 0x30, 0xd3};
|
||||
|
||||
Buffer b0;
|
||||
BEAST_EXPECT (sane (b0));
|
||||
BEAST_EXPECT (b0.empty());
|
||||
BEAST_EXPECT(sane(b0));
|
||||
BEAST_EXPECT(b0.empty());
|
||||
|
||||
Buffer b1 { 0 };
|
||||
BEAST_EXPECT (sane (b1));
|
||||
BEAST_EXPECT (b1.empty());
|
||||
Buffer b1{0};
|
||||
BEAST_EXPECT(sane(b1));
|
||||
BEAST_EXPECT(b1.empty());
|
||||
std::memcpy(b1.alloc(16), data, 16);
|
||||
BEAST_EXPECT (sane (b1));
|
||||
BEAST_EXPECT (!b1.empty());
|
||||
BEAST_EXPECT (b1.size() == 16);
|
||||
BEAST_EXPECT(sane(b1));
|
||||
BEAST_EXPECT(!b1.empty());
|
||||
BEAST_EXPECT(b1.size() == 16);
|
||||
|
||||
Buffer b2 { b1.size() };
|
||||
BEAST_EXPECT (sane (b2));
|
||||
BEAST_EXPECT (!b2.empty());
|
||||
BEAST_EXPECT (b2.size() == b1.size());
|
||||
Buffer b2{b1.size()};
|
||||
BEAST_EXPECT(sane(b2));
|
||||
BEAST_EXPECT(!b2.empty());
|
||||
BEAST_EXPECT(b2.size() == b1.size());
|
||||
std::memcpy(b2.data(), data + 16, 16);
|
||||
|
||||
Buffer b3 { data, sizeof(data) };
|
||||
BEAST_EXPECT (sane (b3));
|
||||
BEAST_EXPECT (!b3.empty());
|
||||
BEAST_EXPECT (b3.size() == sizeof(data));
|
||||
BEAST_EXPECT (std::memcmp (b3.data(), data, b3.size()) == 0);
|
||||
Buffer b3{data, sizeof(data)};
|
||||
BEAST_EXPECT(sane(b3));
|
||||
BEAST_EXPECT(!b3.empty());
|
||||
BEAST_EXPECT(b3.size() == sizeof(data));
|
||||
BEAST_EXPECT(std::memcmp(b3.data(), data, b3.size()) == 0);
|
||||
|
||||
// Check equality and inequality comparisons
|
||||
BEAST_EXPECT (b0 == b0);
|
||||
BEAST_EXPECT (b0 != b1);
|
||||
BEAST_EXPECT (b1 == b1);
|
||||
BEAST_EXPECT (b1 != b2);
|
||||
BEAST_EXPECT (b2 != b3);
|
||||
BEAST_EXPECT(b0 == b0);
|
||||
BEAST_EXPECT(b0 != b1);
|
||||
BEAST_EXPECT(b1 == b1);
|
||||
BEAST_EXPECT(b1 != b2);
|
||||
BEAST_EXPECT(b2 != b3);
|
||||
|
||||
// Check copy constructors and copy assignments:
|
||||
{
|
||||
testcase ("Copy Construction / Assignment");
|
||||
testcase("Copy Construction / Assignment");
|
||||
|
||||
Buffer x{ b0 };
|
||||
BEAST_EXPECT (x == b0);
|
||||
BEAST_EXPECT (sane (x));
|
||||
Buffer y{ b1 };
|
||||
BEAST_EXPECT (y == b1);
|
||||
BEAST_EXPECT (sane (y));
|
||||
Buffer x{b0};
|
||||
BEAST_EXPECT(x == b0);
|
||||
BEAST_EXPECT(sane(x));
|
||||
Buffer y{b1};
|
||||
BEAST_EXPECT(y == b1);
|
||||
BEAST_EXPECT(sane(y));
|
||||
x = b2;
|
||||
BEAST_EXPECT (x == b2);
|
||||
BEAST_EXPECT (sane (x));
|
||||
BEAST_EXPECT(x == b2);
|
||||
BEAST_EXPECT(sane(x));
|
||||
x = y;
|
||||
BEAST_EXPECT (x == y);
|
||||
BEAST_EXPECT (sane (x));
|
||||
BEAST_EXPECT(x == y);
|
||||
BEAST_EXPECT(sane(x));
|
||||
y = b3;
|
||||
BEAST_EXPECT (y == b3);
|
||||
BEAST_EXPECT (sane (y));
|
||||
BEAST_EXPECT(y == b3);
|
||||
BEAST_EXPECT(sane(y));
|
||||
x = b0;
|
||||
BEAST_EXPECT (x == b0);
|
||||
BEAST_EXPECT (sane (x));
|
||||
#if defined(__clang__) && \
|
||||
(!defined(__APPLE__) && (__clang_major__ >= 7)) || \
|
||||
BEAST_EXPECT(x == b0);
|
||||
BEAST_EXPECT(sane(x));
|
||||
#if defined(__clang__) && (!defined(__APPLE__) && (__clang_major__ >= 7)) || \
|
||||
(defined(__APPLE__) && (__apple_build_version__ >= 10010043))
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wself-assign-overloaded"
|
||||
#endif
|
||||
|
||||
x = x;
|
||||
BEAST_EXPECT (x == b0);
|
||||
BEAST_EXPECT (sane (x));
|
||||
BEAST_EXPECT(x == b0);
|
||||
BEAST_EXPECT(sane(x));
|
||||
y = y;
|
||||
BEAST_EXPECT (y == b3);
|
||||
BEAST_EXPECT (sane (y));
|
||||
BEAST_EXPECT(y == b3);
|
||||
BEAST_EXPECT(sane(y));
|
||||
|
||||
#if defined(__clang__) && \
|
||||
(!defined(__APPLE__) && (__clang_major__ >= 7)) || \
|
||||
#if defined(__clang__) && (!defined(__APPLE__) && (__clang_major__ >= 7)) || \
|
||||
(defined(__APPLE__) && (__apple_build_version__ >= 10010043))
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
@@ -121,98 +118,99 @@ struct Buffer_test : beast::unit_test::suite
|
||||
|
||||
// Check move constructor & move assignments:
|
||||
{
|
||||
testcase ("Move Construction / Assignment");
|
||||
testcase("Move Construction / Assignment");
|
||||
|
||||
static_assert(std::is_nothrow_move_constructible<Buffer>::value, "");
|
||||
static_assert(
|
||||
std::is_nothrow_move_constructible<Buffer>::value, "");
|
||||
static_assert(std::is_nothrow_move_assignable<Buffer>::value, "");
|
||||
|
||||
{ // Move-construct from empty buf
|
||||
{ // Move-construct from empty buf
|
||||
Buffer x;
|
||||
Buffer y { std::move(x) };
|
||||
BEAST_EXPECT (sane(x));
|
||||
BEAST_EXPECT (x.empty());
|
||||
BEAST_EXPECT (sane(y));
|
||||
BEAST_EXPECT (y.empty());
|
||||
BEAST_EXPECT (x == y);
|
||||
Buffer y{std::move(x)};
|
||||
BEAST_EXPECT(sane(x));
|
||||
BEAST_EXPECT(x.empty());
|
||||
BEAST_EXPECT(sane(y));
|
||||
BEAST_EXPECT(y.empty());
|
||||
BEAST_EXPECT(x == y);
|
||||
}
|
||||
|
||||
{ // Move-construct from non-empty buf
|
||||
Buffer x { b1 };
|
||||
Buffer y { std::move(x) };
|
||||
BEAST_EXPECT (sane(x));
|
||||
BEAST_EXPECT (x.empty());
|
||||
BEAST_EXPECT (sane(y));
|
||||
BEAST_EXPECT (y == b1);
|
||||
{ // Move-construct from non-empty buf
|
||||
Buffer x{b1};
|
||||
Buffer y{std::move(x)};
|
||||
BEAST_EXPECT(sane(x));
|
||||
BEAST_EXPECT(x.empty());
|
||||
BEAST_EXPECT(sane(y));
|
||||
BEAST_EXPECT(y == b1);
|
||||
}
|
||||
|
||||
{ // Move assign empty buf to empty buf
|
||||
{ // Move assign empty buf to empty buf
|
||||
Buffer x;
|
||||
Buffer y;
|
||||
|
||||
x = std::move(y);
|
||||
BEAST_EXPECT (sane(x));
|
||||
BEAST_EXPECT (x.empty());
|
||||
BEAST_EXPECT (sane(y));
|
||||
BEAST_EXPECT (y.empty());
|
||||
BEAST_EXPECT(sane(x));
|
||||
BEAST_EXPECT(x.empty());
|
||||
BEAST_EXPECT(sane(y));
|
||||
BEAST_EXPECT(y.empty());
|
||||
}
|
||||
|
||||
{ // Move assign non-empty buf to empty buf
|
||||
{ // Move assign non-empty buf to empty buf
|
||||
Buffer x;
|
||||
Buffer y { b1 };
|
||||
Buffer y{b1};
|
||||
|
||||
x = std::move(y);
|
||||
BEAST_EXPECT (sane(x));
|
||||
BEAST_EXPECT (x == b1);
|
||||
BEAST_EXPECT (sane(y));
|
||||
BEAST_EXPECT (y.empty());
|
||||
BEAST_EXPECT(sane(x));
|
||||
BEAST_EXPECT(x == b1);
|
||||
BEAST_EXPECT(sane(y));
|
||||
BEAST_EXPECT(y.empty());
|
||||
}
|
||||
|
||||
{ // Move assign empty buf to non-empty buf
|
||||
Buffer x { b1 };
|
||||
{ // Move assign empty buf to non-empty buf
|
||||
Buffer x{b1};
|
||||
Buffer y;
|
||||
|
||||
x = std::move(y);
|
||||
BEAST_EXPECT (sane(x));
|
||||
BEAST_EXPECT (x.empty());
|
||||
BEAST_EXPECT (sane(y));
|
||||
BEAST_EXPECT (y.empty());
|
||||
BEAST_EXPECT(sane(x));
|
||||
BEAST_EXPECT(x.empty());
|
||||
BEAST_EXPECT(sane(y));
|
||||
BEAST_EXPECT(y.empty());
|
||||
}
|
||||
|
||||
{ // Move assign non-empty buf to non-empty buf
|
||||
Buffer x { b1 };
|
||||
Buffer y { b2 };
|
||||
Buffer z { b3 };
|
||||
{ // Move assign non-empty buf to non-empty buf
|
||||
Buffer x{b1};
|
||||
Buffer y{b2};
|
||||
Buffer z{b3};
|
||||
|
||||
x = std::move(y);
|
||||
BEAST_EXPECT (sane(x));
|
||||
BEAST_EXPECT (!x.empty());
|
||||
BEAST_EXPECT (sane(y));
|
||||
BEAST_EXPECT (y.empty());
|
||||
BEAST_EXPECT(sane(x));
|
||||
BEAST_EXPECT(!x.empty());
|
||||
BEAST_EXPECT(sane(y));
|
||||
BEAST_EXPECT(y.empty());
|
||||
|
||||
x = std::move(z);
|
||||
BEAST_EXPECT (sane(x));
|
||||
BEAST_EXPECT (!x.empty());
|
||||
BEAST_EXPECT (sane(z));
|
||||
BEAST_EXPECT (z.empty());
|
||||
BEAST_EXPECT(sane(x));
|
||||
BEAST_EXPECT(!x.empty());
|
||||
BEAST_EXPECT(sane(z));
|
||||
BEAST_EXPECT(z.empty());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
testcase ("Slice Conversion / Construction / Assignment");
|
||||
testcase("Slice Conversion / Construction / Assignment");
|
||||
|
||||
Buffer w { static_cast<Slice>(b0) };
|
||||
Buffer w{static_cast<Slice>(b0)};
|
||||
BEAST_EXPECT(sane(w));
|
||||
BEAST_EXPECT(w == b0);
|
||||
|
||||
Buffer x { static_cast<Slice>(b1) };
|
||||
Buffer x{static_cast<Slice>(b1)};
|
||||
BEAST_EXPECT(sane(x));
|
||||
BEAST_EXPECT(x == b1);
|
||||
|
||||
Buffer y { static_cast<Slice>(b2) };
|
||||
Buffer y{static_cast<Slice>(b2)};
|
||||
BEAST_EXPECT(sane(y));
|
||||
BEAST_EXPECT(y == b2);
|
||||
|
||||
Buffer z { static_cast<Slice>(b3) };
|
||||
Buffer z{static_cast<Slice>(b3)};
|
||||
BEAST_EXPECT(sane(z));
|
||||
BEAST_EXPECT(z == b3);
|
||||
|
||||
@@ -239,46 +237,45 @@ struct Buffer_test : beast::unit_test::suite
|
||||
// Assign empty slice to non-empty buffer:
|
||||
z = static_cast<Slice>(b0);
|
||||
BEAST_EXPECT(sane(z));
|
||||
BEAST_EXPECT (z == b0);
|
||||
BEAST_EXPECT(z == b0);
|
||||
}
|
||||
|
||||
{
|
||||
testcase ("Allocation, Deallocation and Clearing");
|
||||
testcase("Allocation, Deallocation and Clearing");
|
||||
|
||||
auto test = [this](Buffer const& b, std::size_t i)
|
||||
{
|
||||
auto test = [this](Buffer const& b, std::size_t i) {
|
||||
Buffer x{b};
|
||||
|
||||
// Try to allocate some number of bytes, possibly
|
||||
// zero (which means clear) and sanity check
|
||||
x(i);
|
||||
BEAST_EXPECT (sane(x));
|
||||
BEAST_EXPECT (x.size() == i);
|
||||
BEAST_EXPECT ((x.data() == nullptr) == (i == 0));
|
||||
BEAST_EXPECT(sane(x));
|
||||
BEAST_EXPECT(x.size() == i);
|
||||
BEAST_EXPECT((x.data() == nullptr) == (i == 0));
|
||||
|
||||
// Try to allocate some more data (always non-zero)
|
||||
x(i + 1);
|
||||
BEAST_EXPECT (sane(x));
|
||||
BEAST_EXPECT (x.size() == i + 1);
|
||||
BEAST_EXPECT (x.data() != nullptr);
|
||||
BEAST_EXPECT(sane(x));
|
||||
BEAST_EXPECT(x.size() == i + 1);
|
||||
BEAST_EXPECT(x.data() != nullptr);
|
||||
|
||||
// Try to clear:
|
||||
x.clear();
|
||||
BEAST_EXPECT (sane(x));
|
||||
BEAST_EXPECT (x.size() == 0);
|
||||
BEAST_EXPECT (x.data() == nullptr);
|
||||
BEAST_EXPECT(sane(x));
|
||||
BEAST_EXPECT(x.size() == 0);
|
||||
BEAST_EXPECT(x.data() == nullptr);
|
||||
|
||||
// Try to clear again:
|
||||
x.clear();
|
||||
BEAST_EXPECT (sane(x));
|
||||
BEAST_EXPECT (x.size() == 0);
|
||||
BEAST_EXPECT (x.data() == nullptr);
|
||||
BEAST_EXPECT(sane(x));
|
||||
BEAST_EXPECT(x.size() == 0);
|
||||
BEAST_EXPECT(x.data() == nullptr);
|
||||
};
|
||||
|
||||
for (std::size_t i = 0; i < 16; ++i)
|
||||
{
|
||||
test (b0, i);
|
||||
test (b1, i);
|
||||
test(b0, i);
|
||||
test(b1, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,20 +26,22 @@ namespace test {
|
||||
|
||||
struct DetectCrash_test : public beast::unit_test::suite
|
||||
{
|
||||
void testDetectCrash ()
|
||||
void
|
||||
testDetectCrash()
|
||||
{
|
||||
testcase ("Detect Crash");
|
||||
testcase("Detect Crash");
|
||||
// Kill the process. This is used to test that the multi-process
|
||||
// unit test will correctly report the crash.
|
||||
std::terminate();
|
||||
}
|
||||
void run() override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testDetectCrash();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE_MANUAL(DetectCrash,unit_test,beast);
|
||||
BEAST_DEFINE_TESTSUITE_MANUAL(DetectCrash, unit_test, beast);
|
||||
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -24,81 +24,82 @@
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
|
||||
class feeunits_test
|
||||
: public beast::unit_test::suite
|
||||
class feeunits_test : public beast::unit_test::suite
|
||||
{
|
||||
private:
|
||||
void testTypes()
|
||||
void
|
||||
testTypes()
|
||||
{
|
||||
{
|
||||
XRPAmount x{ 100 };
|
||||
XRPAmount x{100};
|
||||
BEAST_EXPECT(x.drops() == 100);
|
||||
BEAST_EXPECT((std::is_same_v<decltype(x)::unit_type,
|
||||
feeunit::dropTag>));
|
||||
BEAST_EXPECT(
|
||||
(std::is_same_v<decltype(x)::unit_type, feeunit::dropTag>));
|
||||
auto y = 4u * x;
|
||||
BEAST_EXPECT(y.value() == 400);
|
||||
BEAST_EXPECT((std::is_same_v<decltype(y)::unit_type,
|
||||
feeunit::dropTag>));
|
||||
BEAST_EXPECT(
|
||||
(std::is_same_v<decltype(y)::unit_type, feeunit::dropTag>));
|
||||
|
||||
auto z = 4 * y;
|
||||
BEAST_EXPECT(z.value() == 1600);
|
||||
BEAST_EXPECT((std::is_same_v<decltype(z)::unit_type,
|
||||
feeunit::dropTag>));
|
||||
BEAST_EXPECT(
|
||||
(std::is_same_v<decltype(z)::unit_type, feeunit::dropTag>));
|
||||
|
||||
FeeUnit32 f{ 10 };
|
||||
FeeUnit32 baseFee{ 100 };
|
||||
FeeUnit32 f{10};
|
||||
FeeUnit32 baseFee{100};
|
||||
|
||||
auto drops = mulDiv(baseFee, x, f).second;
|
||||
|
||||
BEAST_EXPECT(drops.value() == 1000);
|
||||
BEAST_EXPECT((std::is_same_v<decltype(drops)::unit_type,
|
||||
feeunit::dropTag>));
|
||||
BEAST_EXPECT(
|
||||
(std::is_same_v<decltype(drops)::unit_type, feeunit::dropTag>));
|
||||
BEAST_EXPECT((std::is_same_v<decltype(drops), XRPAmount>));
|
||||
}
|
||||
{
|
||||
XRPAmount x{ 100 };
|
||||
XRPAmount x{100};
|
||||
BEAST_EXPECT(x.value() == 100);
|
||||
BEAST_EXPECT((std::is_same_v<decltype(x)::unit_type,
|
||||
feeunit::dropTag>));
|
||||
BEAST_EXPECT(
|
||||
(std::is_same_v<decltype(x)::unit_type, feeunit::dropTag>));
|
||||
auto y = 4u * x;
|
||||
BEAST_EXPECT(y.value() == 400);
|
||||
BEAST_EXPECT((std::is_same_v<decltype(y)::unit_type,
|
||||
feeunit::dropTag>));
|
||||
BEAST_EXPECT(
|
||||
(std::is_same_v<decltype(y)::unit_type, feeunit::dropTag>));
|
||||
|
||||
FeeUnit64 f{ 10 };
|
||||
FeeUnit64 baseFee{ 100 };
|
||||
FeeUnit64 f{10};
|
||||
FeeUnit64 baseFee{100};
|
||||
|
||||
auto drops = mulDiv(baseFee, x, f).second;
|
||||
|
||||
BEAST_EXPECT(drops.value() == 1000);
|
||||
BEAST_EXPECT((std::is_same_v<decltype(drops)::unit_type,
|
||||
feeunit::dropTag>));
|
||||
BEAST_EXPECT(
|
||||
(std::is_same_v<decltype(drops)::unit_type, feeunit::dropTag>));
|
||||
BEAST_EXPECT((std::is_same_v<decltype(drops), XRPAmount>));
|
||||
}
|
||||
{
|
||||
FeeLevel64 x{ 1024 };
|
||||
FeeLevel64 x{1024};
|
||||
BEAST_EXPECT(x.value() == 1024);
|
||||
BEAST_EXPECT((std::is_same_v<decltype(x)::unit_type,
|
||||
feeunit::feelevelTag>));
|
||||
BEAST_EXPECT(
|
||||
(std::is_same_v<decltype(x)::unit_type, feeunit::feelevelTag>));
|
||||
std::uint64_t m = 4;
|
||||
auto y = m * x;
|
||||
BEAST_EXPECT(y.value() == 4096);
|
||||
BEAST_EXPECT((std::is_same_v<decltype(y)::unit_type,
|
||||
feeunit::feelevelTag>));
|
||||
BEAST_EXPECT(
|
||||
(std::is_same_v<decltype(y)::unit_type, feeunit::feelevelTag>));
|
||||
|
||||
XRPAmount basefee{ 10 };
|
||||
FeeLevel64 referencefee{ 256 };
|
||||
XRPAmount basefee{10};
|
||||
FeeLevel64 referencefee{256};
|
||||
|
||||
auto drops = mulDiv(x, basefee, referencefee).second;
|
||||
|
||||
BEAST_EXPECT(drops.value() == 40);
|
||||
BEAST_EXPECT((std::is_same_v<decltype(drops)::unit_type,
|
||||
feeunit::dropTag>));
|
||||
BEAST_EXPECT(
|
||||
(std::is_same_v<decltype(drops)::unit_type, feeunit::dropTag>));
|
||||
BEAST_EXPECT((std::is_same_v<decltype(drops), XRPAmount>));
|
||||
}
|
||||
}
|
||||
|
||||
void testJson()
|
||||
void
|
||||
testJson()
|
||||
{
|
||||
// Json value functionality
|
||||
{
|
||||
@@ -119,8 +120,8 @@ private:
|
||||
FeeUnit64 x{std::numeric_limits<std::uint64_t>::max()};
|
||||
auto y = x.jsonClipped();
|
||||
BEAST_EXPECT(y.type() == Json::uintValue);
|
||||
BEAST_EXPECT(y ==
|
||||
Json::Value{std::numeric_limits<std::uint32_t>::max()});
|
||||
BEAST_EXPECT(
|
||||
y == Json::Value{std::numeric_limits<std::uint32_t>::max()});
|
||||
}
|
||||
|
||||
{
|
||||
@@ -148,33 +149,33 @@ private:
|
||||
XRPAmount x{std::numeric_limits<std::int64_t>::max()};
|
||||
auto y = x.jsonClipped();
|
||||
BEAST_EXPECT(y.type() == Json::intValue);
|
||||
BEAST_EXPECT(y ==
|
||||
Json::Value{std::numeric_limits<std::int32_t>::max()});
|
||||
BEAST_EXPECT(
|
||||
y == Json::Value{std::numeric_limits<std::int32_t>::max()});
|
||||
}
|
||||
|
||||
{
|
||||
XRPAmount x{std::numeric_limits<std::int64_t>::min()};
|
||||
auto y = x.jsonClipped();
|
||||
BEAST_EXPECT(y.type() == Json::intValue);
|
||||
BEAST_EXPECT(y ==
|
||||
Json::Value{std::numeric_limits<std::int32_t>::min()});
|
||||
BEAST_EXPECT(
|
||||
y == Json::Value{std::numeric_limits<std::int32_t>::min()});
|
||||
}
|
||||
}
|
||||
|
||||
void testFunctions()
|
||||
void
|
||||
testFunctions()
|
||||
{
|
||||
// Explicitly test every defined function for the TaggedFee class
|
||||
// since some of them are templated, but not used anywhere else.
|
||||
{
|
||||
auto make = [&](auto x) -> FeeUnit64 {
|
||||
return x; };
|
||||
auto make = [&](auto x) -> FeeUnit64 { return x; };
|
||||
auto explicitmake = [&](auto x) -> FeeUnit64 {
|
||||
return FeeUnit64{ x };
|
||||
return FeeUnit64{x};
|
||||
};
|
||||
|
||||
FeeUnit64 defaulted;
|
||||
(void)defaulted;
|
||||
FeeUnit64 test{ 0 };
|
||||
FeeUnit64 test{0};
|
||||
BEAST_EXPECT(test.fee() == 0);
|
||||
|
||||
test = explicitmake(beast::zero);
|
||||
@@ -186,13 +187,13 @@ private:
|
||||
test = explicitmake(100u);
|
||||
BEAST_EXPECT(test.fee() == 100);
|
||||
|
||||
FeeUnit64 const targetSame{ 200u };
|
||||
FeeUnit32 const targetOther{ 300u };
|
||||
FeeUnit64 const targetSame{200u};
|
||||
FeeUnit32 const targetOther{300u};
|
||||
test = make(targetSame);
|
||||
BEAST_EXPECT(test.fee() == 200);
|
||||
BEAST_EXPECT(test == targetSame);
|
||||
BEAST_EXPECT(test < FeeUnit64{ 1000 });
|
||||
BEAST_EXPECT(test > FeeUnit64{ 100 });
|
||||
BEAST_EXPECT(test < FeeUnit64{1000});
|
||||
BEAST_EXPECT(test > FeeUnit64{100});
|
||||
test = make(targetOther);
|
||||
BEAST_EXPECT(test.fee() == 300);
|
||||
BEAST_EXPECT(test == targetOther);
|
||||
@@ -254,15 +255,14 @@ private:
|
||||
BEAST_EXPECT(to_string(test) == "200");
|
||||
}
|
||||
{
|
||||
auto make = [&](auto x) -> FeeLevelDouble {
|
||||
return x; };
|
||||
auto make = [&](auto x) -> FeeLevelDouble { return x; };
|
||||
auto explicitmake = [&](auto x) -> FeeLevelDouble {
|
||||
return FeeLevelDouble{ x };
|
||||
return FeeLevelDouble{x};
|
||||
};
|
||||
|
||||
FeeLevelDouble defaulted;
|
||||
(void)defaulted;
|
||||
FeeLevelDouble test{ 0 };
|
||||
FeeLevelDouble test{0};
|
||||
BEAST_EXPECT(test.fee() == 0);
|
||||
|
||||
test = explicitmake(beast::zero);
|
||||
@@ -274,13 +274,13 @@ private:
|
||||
test = explicitmake(100.0);
|
||||
BEAST_EXPECT(test.fee() == 100);
|
||||
|
||||
FeeLevelDouble const targetSame{ 200.0 };
|
||||
FeeLevel64 const targetOther{ 300 };
|
||||
FeeLevelDouble const targetSame{200.0};
|
||||
FeeLevel64 const targetOther{300};
|
||||
test = make(targetSame);
|
||||
BEAST_EXPECT(test.fee() == 200);
|
||||
BEAST_EXPECT(test == targetSame);
|
||||
BEAST_EXPECT(test < FeeLevelDouble{ 1000.0 });
|
||||
BEAST_EXPECT(test > FeeLevelDouble{ 100.0 });
|
||||
BEAST_EXPECT(test < FeeLevelDouble{1000.0});
|
||||
BEAST_EXPECT(test > FeeLevelDouble{100.0});
|
||||
test = targetOther.fee();
|
||||
BEAST_EXPECT(test.fee() == 300);
|
||||
BEAST_EXPECT(test == targetOther);
|
||||
@@ -341,7 +341,8 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
void run() override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
BEAST_EXPECT(INITIAL_XRP.drops() == 100'000'000'000'000'000);
|
||||
BEAST_EXPECT(INITIAL_XRP == XRPAmount{100'000'000'000'000'000});
|
||||
@@ -352,7 +353,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(feeunits,ripple_basics,ripple);
|
||||
BEAST_DEFINE_TESTSUITE(feeunits, ripple_basics, ripple);
|
||||
|
||||
} // test
|
||||
} //ripple
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -27,7 +27,8 @@ namespace ripple {
|
||||
class FileUtilities_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void testGetFileContents()
|
||||
void
|
||||
testGetFileContents()
|
||||
{
|
||||
using namespace ripple::test::detail;
|
||||
using namespace boost::system;
|
||||
@@ -35,7 +36,10 @@ public:
|
||||
constexpr const char* expectedContents =
|
||||
"This file is very short. That's all we need.";
|
||||
|
||||
FileDirGuard file(*this, "test_file", "test.txt",
|
||||
FileDirGuard file(
|
||||
*this,
|
||||
"test_file",
|
||||
"test.txt",
|
||||
"This is temporary text that should get overwritten");
|
||||
|
||||
error_code ec;
|
||||
@@ -61,14 +65,14 @@ public:
|
||||
{
|
||||
// Test with small max
|
||||
auto const bad = getFileContents(ec, path, 16);
|
||||
BEAST_EXPECT(ec && ec.value() ==
|
||||
boost::system::errc::file_too_large);
|
||||
BEAST_EXPECT(
|
||||
ec && ec.value() == boost::system::errc::file_too_large);
|
||||
BEAST_EXPECT(bad.empty());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void run () override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testGetFileContents();
|
||||
}
|
||||
@@ -76,4 +80,4 @@ public:
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(FileUtilities, ripple_basics, ripple);
|
||||
|
||||
} // ripple
|
||||
} // namespace ripple
|
||||
|
||||
@@ -25,117 +25,121 @@ namespace ripple {
|
||||
class IOUAmount_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void testZero ()
|
||||
void
|
||||
testZero()
|
||||
{
|
||||
testcase ("zero");
|
||||
testcase("zero");
|
||||
|
||||
IOUAmount const z (0, 0);
|
||||
IOUAmount const z(0, 0);
|
||||
|
||||
BEAST_EXPECT(z.mantissa () == 0);
|
||||
BEAST_EXPECT(z.exponent () == -100);
|
||||
BEAST_EXPECT(z.mantissa() == 0);
|
||||
BEAST_EXPECT(z.exponent() == -100);
|
||||
BEAST_EXPECT(!z);
|
||||
BEAST_EXPECT(z.signum () == 0);
|
||||
BEAST_EXPECT(z.signum() == 0);
|
||||
BEAST_EXPECT(z == beast::zero);
|
||||
|
||||
BEAST_EXPECT((z + z) == z);
|
||||
BEAST_EXPECT((z - z) == z);
|
||||
BEAST_EXPECT(z == -z);
|
||||
|
||||
IOUAmount const zz (beast::zero);
|
||||
IOUAmount const zz(beast::zero);
|
||||
BEAST_EXPECT(z == zz);
|
||||
}
|
||||
|
||||
void testSigNum ()
|
||||
void
|
||||
testSigNum()
|
||||
{
|
||||
testcase ("signum");
|
||||
testcase("signum");
|
||||
|
||||
IOUAmount const neg (-1, 0);
|
||||
BEAST_EXPECT(neg.signum () < 0);
|
||||
IOUAmount const neg(-1, 0);
|
||||
BEAST_EXPECT(neg.signum() < 0);
|
||||
|
||||
IOUAmount const zer (0, 0);
|
||||
BEAST_EXPECT(zer.signum () == 0);
|
||||
IOUAmount const zer(0, 0);
|
||||
BEAST_EXPECT(zer.signum() == 0);
|
||||
|
||||
IOUAmount const pos (1, 0);
|
||||
BEAST_EXPECT(pos.signum () > 0);
|
||||
IOUAmount const pos(1, 0);
|
||||
BEAST_EXPECT(pos.signum() > 0);
|
||||
}
|
||||
|
||||
void testBeastZero ()
|
||||
void
|
||||
testBeastZero()
|
||||
{
|
||||
testcase ("beast::Zero Comparisons");
|
||||
testcase("beast::Zero Comparisons");
|
||||
|
||||
using beast::zero;
|
||||
|
||||
{
|
||||
IOUAmount z (zero);
|
||||
IOUAmount z(zero);
|
||||
BEAST_EXPECT(z == zero);
|
||||
BEAST_EXPECT(z >= zero);
|
||||
BEAST_EXPECT(z <= zero);
|
||||
unexpected (z != zero);
|
||||
unexpected (z > zero);
|
||||
unexpected (z < zero);
|
||||
unexpected(z != zero);
|
||||
unexpected(z > zero);
|
||||
unexpected(z < zero);
|
||||
}
|
||||
|
||||
{
|
||||
IOUAmount const neg (-2, 0);
|
||||
IOUAmount const neg(-2, 0);
|
||||
BEAST_EXPECT(neg < zero);
|
||||
BEAST_EXPECT(neg <= zero);
|
||||
BEAST_EXPECT(neg != zero);
|
||||
unexpected (neg == zero);
|
||||
unexpected(neg == zero);
|
||||
}
|
||||
|
||||
{
|
||||
IOUAmount const pos (2, 0);
|
||||
IOUAmount const pos(2, 0);
|
||||
BEAST_EXPECT(pos > zero);
|
||||
BEAST_EXPECT(pos >= zero);
|
||||
BEAST_EXPECT(pos != zero);
|
||||
unexpected (pos == zero);
|
||||
unexpected(pos == zero);
|
||||
}
|
||||
}
|
||||
|
||||
void testComparisons ()
|
||||
void
|
||||
testComparisons()
|
||||
{
|
||||
testcase ("IOU Comparisons");
|
||||
testcase("IOU Comparisons");
|
||||
|
||||
IOUAmount const n (-2, 0);
|
||||
IOUAmount const z (0, 0);
|
||||
IOUAmount const p (2, 0);
|
||||
IOUAmount const n(-2, 0);
|
||||
IOUAmount const z(0, 0);
|
||||
IOUAmount const p(2, 0);
|
||||
|
||||
BEAST_EXPECT(z == z);
|
||||
BEAST_EXPECT(z >= z);
|
||||
BEAST_EXPECT(z <= z);
|
||||
BEAST_EXPECT(z == -z);
|
||||
unexpected (z > z);
|
||||
unexpected (z < z);
|
||||
unexpected (z != z);
|
||||
unexpected (z != -z);
|
||||
unexpected(z > z);
|
||||
unexpected(z < z);
|
||||
unexpected(z != z);
|
||||
unexpected(z != -z);
|
||||
|
||||
BEAST_EXPECT(n < z);
|
||||
BEAST_EXPECT(n <= z);
|
||||
BEAST_EXPECT(n != z);
|
||||
unexpected (n > z);
|
||||
unexpected (n >= z);
|
||||
unexpected (n == z);
|
||||
unexpected(n > z);
|
||||
unexpected(n >= z);
|
||||
unexpected(n == z);
|
||||
|
||||
BEAST_EXPECT(p > z);
|
||||
BEAST_EXPECT(p >= z);
|
||||
BEAST_EXPECT(p != z);
|
||||
unexpected (p < z);
|
||||
unexpected (p <= z);
|
||||
unexpected (p == z);
|
||||
unexpected(p < z);
|
||||
unexpected(p <= z);
|
||||
unexpected(p == z);
|
||||
|
||||
BEAST_EXPECT(n < p);
|
||||
BEAST_EXPECT(n <= p);
|
||||
BEAST_EXPECT(n != p);
|
||||
unexpected (n > p);
|
||||
unexpected (n >= p);
|
||||
unexpected (n == p);
|
||||
unexpected(n > p);
|
||||
unexpected(n >= p);
|
||||
unexpected(n == p);
|
||||
|
||||
BEAST_EXPECT(p > n);
|
||||
BEAST_EXPECT(p >= n);
|
||||
BEAST_EXPECT(p != n);
|
||||
unexpected (p < n);
|
||||
unexpected (p <= n);
|
||||
unexpected (p == n);
|
||||
unexpected(p < n);
|
||||
unexpected(p <= n);
|
||||
unexpected(p == n);
|
||||
|
||||
BEAST_EXPECT(p > -p);
|
||||
BEAST_EXPECT(p >= -p);
|
||||
@@ -146,24 +150,26 @@ public:
|
||||
BEAST_EXPECT(n != -n);
|
||||
}
|
||||
|
||||
void testToString()
|
||||
void
|
||||
testToString()
|
||||
{
|
||||
testcase("IOU strings");
|
||||
|
||||
BEAST_EXPECT(to_string(IOUAmount (-2, 0)) == "-2");
|
||||
BEAST_EXPECT(to_string(IOUAmount (0, 0)) == "0");
|
||||
BEAST_EXPECT(to_string(IOUAmount (2, 0)) == "2");
|
||||
BEAST_EXPECT(to_string(IOUAmount (25, -3)) == "0.025");
|
||||
BEAST_EXPECT(to_string(IOUAmount (-25, -3)) == "-0.025");
|
||||
BEAST_EXPECT(to_string(IOUAmount (25, 1)) == "250");
|
||||
BEAST_EXPECT(to_string(IOUAmount (-25, 1)) == "-250");
|
||||
BEAST_EXPECT(to_string(IOUAmount (2, 20)) == "2000000000000000e5");
|
||||
BEAST_EXPECT(to_string(IOUAmount (-2, -20)) == "-2000000000000000e-35");
|
||||
BEAST_EXPECT(to_string(IOUAmount(-2, 0)) == "-2");
|
||||
BEAST_EXPECT(to_string(IOUAmount(0, 0)) == "0");
|
||||
BEAST_EXPECT(to_string(IOUAmount(2, 0)) == "2");
|
||||
BEAST_EXPECT(to_string(IOUAmount(25, -3)) == "0.025");
|
||||
BEAST_EXPECT(to_string(IOUAmount(-25, -3)) == "-0.025");
|
||||
BEAST_EXPECT(to_string(IOUAmount(25, 1)) == "250");
|
||||
BEAST_EXPECT(to_string(IOUAmount(-25, 1)) == "-250");
|
||||
BEAST_EXPECT(to_string(IOUAmount(2, 20)) == "2000000000000000e5");
|
||||
BEAST_EXPECT(to_string(IOUAmount(-2, -20)) == "-2000000000000000e-35");
|
||||
}
|
||||
|
||||
void testMulRatio()
|
||||
void
|
||||
testMulRatio()
|
||||
{
|
||||
testcase ("mulRatio");
|
||||
testcase("mulRatio");
|
||||
|
||||
/* The range for the mantissa when normalized */
|
||||
constexpr std::int64_t minMantissa = 1000000000000000ull;
|
||||
@@ -172,93 +178,96 @@ public:
|
||||
/* The range for the exponent when normalized */
|
||||
constexpr int minExponent = -96;
|
||||
constexpr int maxExponent = 80;
|
||||
constexpr auto maxUInt = std::numeric_limits<std::uint32_t>::max ();
|
||||
constexpr auto maxUInt = std::numeric_limits<std::uint32_t>::max();
|
||||
|
||||
{
|
||||
// multiply by a number that would overflow the mantissa, then
|
||||
// divide by the same number, and check we didn't lose any value
|
||||
IOUAmount bigMan (maxMantissa, 0);
|
||||
BEAST_EXPECT(bigMan == mulRatio (bigMan, maxUInt, maxUInt, true));
|
||||
IOUAmount bigMan(maxMantissa, 0);
|
||||
BEAST_EXPECT(bigMan == mulRatio(bigMan, maxUInt, maxUInt, true));
|
||||
// rounding mode shouldn't matter as the result is exact
|
||||
BEAST_EXPECT(bigMan == mulRatio (bigMan, maxUInt, maxUInt, false));
|
||||
BEAST_EXPECT(bigMan == mulRatio(bigMan, maxUInt, maxUInt, false));
|
||||
}
|
||||
{
|
||||
// Similar test as above, but for negative values
|
||||
IOUAmount bigMan (-maxMantissa, 0);
|
||||
BEAST_EXPECT(bigMan == mulRatio (bigMan, maxUInt, maxUInt, true));
|
||||
IOUAmount bigMan(-maxMantissa, 0);
|
||||
BEAST_EXPECT(bigMan == mulRatio(bigMan, maxUInt, maxUInt, true));
|
||||
// rounding mode shouldn't matter as the result is exact
|
||||
BEAST_EXPECT(bigMan == mulRatio (bigMan, maxUInt, maxUInt, false));
|
||||
BEAST_EXPECT(bigMan == mulRatio(bigMan, maxUInt, maxUInt, false));
|
||||
}
|
||||
|
||||
{
|
||||
// small amounts
|
||||
IOUAmount tiny (minMantissa, minExponent);
|
||||
IOUAmount tiny(minMantissa, minExponent);
|
||||
// Round up should give the smallest allowable number
|
||||
BEAST_EXPECT(tiny == mulRatio (tiny, 1, maxUInt, true));
|
||||
BEAST_EXPECT(tiny == mulRatio (tiny, maxUInt - 1, maxUInt, true));
|
||||
BEAST_EXPECT(tiny == mulRatio(tiny, 1, maxUInt, true));
|
||||
BEAST_EXPECT(tiny == mulRatio(tiny, maxUInt - 1, maxUInt, true));
|
||||
// rounding down should be zero
|
||||
BEAST_EXPECT(beast::zero == mulRatio (tiny, 1, maxUInt, false));
|
||||
BEAST_EXPECT(beast::zero == mulRatio (tiny, maxUInt - 1, maxUInt, false));
|
||||
BEAST_EXPECT(beast::zero == mulRatio(tiny, 1, maxUInt, false));
|
||||
BEAST_EXPECT(
|
||||
beast::zero == mulRatio(tiny, maxUInt - 1, maxUInt, false));
|
||||
|
||||
// tiny negative numbers
|
||||
IOUAmount tinyNeg (-minMantissa, minExponent);
|
||||
IOUAmount tinyNeg(-minMantissa, minExponent);
|
||||
// Round up should give zero
|
||||
BEAST_EXPECT(beast::zero == mulRatio (tinyNeg, 1, maxUInt, true));
|
||||
BEAST_EXPECT(beast::zero == mulRatio (tinyNeg, maxUInt - 1, maxUInt, true));
|
||||
BEAST_EXPECT(beast::zero == mulRatio(tinyNeg, 1, maxUInt, true));
|
||||
BEAST_EXPECT(
|
||||
beast::zero == mulRatio(tinyNeg, maxUInt - 1, maxUInt, true));
|
||||
// rounding down should be tiny
|
||||
BEAST_EXPECT(tinyNeg == mulRatio (tinyNeg, 1, maxUInt, false));
|
||||
BEAST_EXPECT(tinyNeg == mulRatio (tinyNeg, maxUInt - 1, maxUInt, false));
|
||||
BEAST_EXPECT(tinyNeg == mulRatio(tinyNeg, 1, maxUInt, false));
|
||||
BEAST_EXPECT(
|
||||
tinyNeg == mulRatio(tinyNeg, maxUInt - 1, maxUInt, false));
|
||||
}
|
||||
|
||||
{
|
||||
// rounding
|
||||
{
|
||||
IOUAmount one (1, 0);
|
||||
auto const rup = mulRatio (one, maxUInt - 1, maxUInt, true);
|
||||
auto const rdown = mulRatio (one, maxUInt - 1, maxUInt, false);
|
||||
BEAST_EXPECT(rup.mantissa () - rdown.mantissa () == 1);
|
||||
}
|
||||
{
|
||||
IOUAmount big (maxMantissa, maxExponent);
|
||||
auto const rup = mulRatio (big, maxUInt - 1, maxUInt, true);
|
||||
auto const rdown = mulRatio (big, maxUInt - 1, maxUInt, false);
|
||||
BEAST_EXPECT(rup.mantissa () - rdown.mantissa () == 1);
|
||||
}
|
||||
|
||||
{
|
||||
IOUAmount negOne (-1, 0);
|
||||
auto const rup = mulRatio (negOne, maxUInt - 1, maxUInt, true);
|
||||
auto const rdown = mulRatio (negOne, maxUInt - 1, maxUInt, false);
|
||||
BEAST_EXPECT(rup.mantissa () - rdown.mantissa () == 1);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// division by zero
|
||||
IOUAmount one (1, 0);
|
||||
except ([&] {mulRatio (one, 1, 0, true);});
|
||||
}
|
||||
|
||||
{
|
||||
// overflow
|
||||
IOUAmount big (maxMantissa, maxExponent);
|
||||
except ([&] {mulRatio (big, 2, 0, true);});
|
||||
}
|
||||
{// rounding
|
||||
{IOUAmount one(1, 0);
|
||||
auto const rup = mulRatio(one, maxUInt - 1, maxUInt, true);
|
||||
auto const rdown = mulRatio(one, maxUInt - 1, maxUInt, false);
|
||||
BEAST_EXPECT(rup.mantissa() - rdown.mantissa() == 1);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void run () override
|
||||
{
|
||||
testZero ();
|
||||
testSigNum ();
|
||||
testBeastZero ();
|
||||
testComparisons ();
|
||||
testToString ();
|
||||
testMulRatio ();
|
||||
IOUAmount big(maxMantissa, maxExponent);
|
||||
auto const rup = mulRatio(big, maxUInt - 1, maxUInt, true);
|
||||
auto const rdown = mulRatio(big, maxUInt - 1, maxUInt, false);
|
||||
BEAST_EXPECT(rup.mantissa() - rdown.mantissa() == 1);
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(IOUAmount,protocol,ripple);
|
||||
{
|
||||
IOUAmount negOne(-1, 0);
|
||||
auto const rup = mulRatio(negOne, maxUInt - 1, maxUInt, true);
|
||||
auto const rdown = mulRatio(negOne, maxUInt - 1, maxUInt, false);
|
||||
BEAST_EXPECT(rup.mantissa() - rdown.mantissa() == 1);
|
||||
}
|
||||
}
|
||||
|
||||
} // ripple
|
||||
{
|
||||
// division by zero
|
||||
IOUAmount one(1, 0);
|
||||
except([&] { mulRatio(one, 1, 0, true); });
|
||||
}
|
||||
|
||||
{
|
||||
// overflow
|
||||
IOUAmount big(maxMantissa, maxExponent);
|
||||
except([&] { mulRatio(big, 2, 0, true); });
|
||||
}
|
||||
} // namespace ripple
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testZero();
|
||||
testSigNum();
|
||||
testBeastZero();
|
||||
testComparisons();
|
||||
testToString();
|
||||
testMulRatio();
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(IOUAmount, protocol, ripple);
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -17,81 +17,82 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/basics/chrono.h>
|
||||
#include <ripple/basics/KeyCache.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <ripple/basics/chrono.h>
|
||||
#include <ripple/beast/clock/manual_clock.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
class KeyCache_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void run () override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
TestStopwatch clock;
|
||||
clock.set (0);
|
||||
clock.set(0);
|
||||
|
||||
using Key = std::string;
|
||||
using Cache = KeyCache <Key>;
|
||||
using Cache = KeyCache<Key>;
|
||||
|
||||
// Insert an item, retrieve it, and age it so it gets purged.
|
||||
{
|
||||
Cache c ("test", clock, 1, 2s);
|
||||
Cache c("test", clock, 1, 2s);
|
||||
|
||||
BEAST_EXPECT(c.size () == 0);
|
||||
BEAST_EXPECT(c.insert ("one"));
|
||||
BEAST_EXPECT(! c.insert ("one"));
|
||||
BEAST_EXPECT(c.size () == 1);
|
||||
BEAST_EXPECT(c.exists ("one"));
|
||||
BEAST_EXPECT(c.touch_if_exists ("one"));
|
||||
BEAST_EXPECT(c.size() == 0);
|
||||
BEAST_EXPECT(c.insert("one"));
|
||||
BEAST_EXPECT(!c.insert("one"));
|
||||
BEAST_EXPECT(c.size() == 1);
|
||||
BEAST_EXPECT(c.exists("one"));
|
||||
BEAST_EXPECT(c.touch_if_exists("one"));
|
||||
++clock;
|
||||
c.sweep ();
|
||||
BEAST_EXPECT(c.size () == 1);
|
||||
BEAST_EXPECT(c.exists ("one"));
|
||||
c.sweep();
|
||||
BEAST_EXPECT(c.size() == 1);
|
||||
BEAST_EXPECT(c.exists("one"));
|
||||
++clock;
|
||||
c.sweep ();
|
||||
BEAST_EXPECT(c.size () == 0);
|
||||
BEAST_EXPECT(! c.exists ("one"));
|
||||
BEAST_EXPECT(! c.touch_if_exists ("one"));
|
||||
c.sweep();
|
||||
BEAST_EXPECT(c.size() == 0);
|
||||
BEAST_EXPECT(!c.exists("one"));
|
||||
BEAST_EXPECT(!c.touch_if_exists("one"));
|
||||
}
|
||||
|
||||
// Insert two items, have one expire
|
||||
{
|
||||
Cache c ("test", clock, 2, 2s);
|
||||
Cache c("test", clock, 2, 2s);
|
||||
|
||||
BEAST_EXPECT(c.insert ("one"));
|
||||
BEAST_EXPECT(c.size () == 1);
|
||||
BEAST_EXPECT(c.insert ("two"));
|
||||
BEAST_EXPECT(c.size () == 2);
|
||||
BEAST_EXPECT(c.insert("one"));
|
||||
BEAST_EXPECT(c.size() == 1);
|
||||
BEAST_EXPECT(c.insert("two"));
|
||||
BEAST_EXPECT(c.size() == 2);
|
||||
++clock;
|
||||
c.sweep ();
|
||||
BEAST_EXPECT(c.size () == 2);
|
||||
BEAST_EXPECT(c.touch_if_exists ("two"));
|
||||
c.sweep();
|
||||
BEAST_EXPECT(c.size() == 2);
|
||||
BEAST_EXPECT(c.touch_if_exists("two"));
|
||||
++clock;
|
||||
c.sweep ();
|
||||
BEAST_EXPECT(c.size () == 1);
|
||||
BEAST_EXPECT(c.exists ("two"));
|
||||
c.sweep();
|
||||
BEAST_EXPECT(c.size() == 1);
|
||||
BEAST_EXPECT(c.exists("two"));
|
||||
}
|
||||
|
||||
// Insert three items (1 over limit), sweep
|
||||
{
|
||||
Cache c ("test", clock, 2, 3s);
|
||||
Cache c("test", clock, 2, 3s);
|
||||
|
||||
BEAST_EXPECT(c.insert ("one"));
|
||||
BEAST_EXPECT(c.insert("one"));
|
||||
++clock;
|
||||
BEAST_EXPECT(c.insert ("two"));
|
||||
BEAST_EXPECT(c.insert("two"));
|
||||
++clock;
|
||||
BEAST_EXPECT(c.insert ("three"));
|
||||
BEAST_EXPECT(c.insert("three"));
|
||||
++clock;
|
||||
BEAST_EXPECT(c.size () == 3);
|
||||
c.sweep ();
|
||||
BEAST_EXPECT(c.size () < 3);
|
||||
BEAST_EXPECT(c.size() == 3);
|
||||
c.sweep();
|
||||
BEAST_EXPECT(c.size() < 3);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(KeyCache,common,ripple);
|
||||
BEAST_DEFINE_TESTSUITE(KeyCache, common, ripple);
|
||||
|
||||
}
|
||||
} // namespace ripple
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -20,8 +20,7 @@
|
||||
#include <ripple/basics/RangeSet.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
|
||||
namespace ripple
|
||||
{
|
||||
namespace ripple {
|
||||
class RangeSet_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -27,46 +27,44 @@ namespace test {
|
||||
|
||||
struct Slice_test : beast::unit_test::suite
|
||||
{
|
||||
void run() override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
std::uint8_t const data[] =
|
||||
{
|
||||
0xa8, 0xa1, 0x38, 0x45, 0x23, 0xec, 0xe4, 0x23,
|
||||
0x71, 0x6d, 0x2a, 0x18, 0xb4, 0x70, 0xcb, 0xf5,
|
||||
0xac, 0x2d, 0x89, 0x4d, 0x19, 0x9c, 0xf0, 0x2c,
|
||||
0x15, 0xd1, 0xf9, 0x9b, 0x66, 0xd2, 0x30, 0xd3
|
||||
};
|
||||
std::uint8_t const data[] = {
|
||||
0xa8, 0xa1, 0x38, 0x45, 0x23, 0xec, 0xe4, 0x23, 0x71, 0x6d, 0x2a,
|
||||
0x18, 0xb4, 0x70, 0xcb, 0xf5, 0xac, 0x2d, 0x89, 0x4d, 0x19, 0x9c,
|
||||
0xf0, 0x2c, 0x15, 0xd1, 0xf9, 0x9b, 0x66, 0xd2, 0x30, 0xd3};
|
||||
|
||||
{
|
||||
testcase ("Equality & Inequality");
|
||||
testcase("Equality & Inequality");
|
||||
|
||||
Slice const s0{};
|
||||
|
||||
BEAST_EXPECT (s0.size() == 0);
|
||||
BEAST_EXPECT (s0.data() == nullptr);
|
||||
BEAST_EXPECT (s0 == s0);
|
||||
BEAST_EXPECT(s0.size() == 0);
|
||||
BEAST_EXPECT(s0.data() == nullptr);
|
||||
BEAST_EXPECT(s0 == s0);
|
||||
|
||||
// Test slices of equal and unequal size pointing to same data:
|
||||
for (std::size_t i = 0; i != sizeof(data); ++i)
|
||||
{
|
||||
Slice const s1 { data, i };
|
||||
Slice const s1{data, i};
|
||||
|
||||
BEAST_EXPECT (s1.size() == i);
|
||||
BEAST_EXPECT (s1.data() != nullptr);
|
||||
BEAST_EXPECT(s1.size() == i);
|
||||
BEAST_EXPECT(s1.data() != nullptr);
|
||||
|
||||
if (i == 0)
|
||||
BEAST_EXPECT (s1 == s0);
|
||||
BEAST_EXPECT(s1 == s0);
|
||||
else
|
||||
BEAST_EXPECT (s1 != s0);
|
||||
BEAST_EXPECT(s1 != s0);
|
||||
|
||||
for (std::size_t j = 0; j != sizeof(data); ++j)
|
||||
{
|
||||
Slice const s2 { data, j };
|
||||
Slice const s2{data, j};
|
||||
|
||||
if (i == j)
|
||||
BEAST_EXPECT (s1 == s2);
|
||||
BEAST_EXPECT(s1 == s2);
|
||||
else
|
||||
BEAST_EXPECT (s1 != s2);
|
||||
BEAST_EXPECT(s1 != s2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,34 +75,34 @@ struct Slice_test : beast::unit_test::suite
|
||||
for (std::size_t i = 0; i != sizeof(data); ++i)
|
||||
a[i] = b[i] = data[i];
|
||||
|
||||
BEAST_EXPECT (makeSlice(a) == makeSlice(b));
|
||||
BEAST_EXPECT(makeSlice(a) == makeSlice(b));
|
||||
b[7]++;
|
||||
BEAST_EXPECT (makeSlice(a) != makeSlice(b));
|
||||
BEAST_EXPECT(makeSlice(a) != makeSlice(b));
|
||||
a[7]++;
|
||||
BEAST_EXPECT (makeSlice(a) == makeSlice(b));
|
||||
BEAST_EXPECT(makeSlice(a) == makeSlice(b));
|
||||
}
|
||||
|
||||
{
|
||||
testcase ("Indexing");
|
||||
testcase("Indexing");
|
||||
|
||||
Slice const s { data, sizeof(data) };
|
||||
Slice const s{data, sizeof(data)};
|
||||
|
||||
for (std::size_t i = 0; i != sizeof(data); ++i)
|
||||
BEAST_EXPECT (s[i] == data[i]);
|
||||
BEAST_EXPECT(s[i] == data[i]);
|
||||
}
|
||||
|
||||
{
|
||||
testcase ("Advancing");
|
||||
testcase("Advancing");
|
||||
|
||||
for (std::size_t i = 0; i < sizeof(data); ++i)
|
||||
{
|
||||
for (std::size_t j = 0; i + j < sizeof(data); ++j)
|
||||
{
|
||||
Slice s (data + i, sizeof(data) - i);
|
||||
Slice s(data + i, sizeof(data) - i);
|
||||
s += j;
|
||||
|
||||
BEAST_EXPECT (s.data() == data + i + j);
|
||||
BEAST_EXPECT (s.size() == sizeof(data) - i - j);
|
||||
BEAST_EXPECT(s.data() == data + i + j);
|
||||
BEAST_EXPECT(s.size() == sizeof(data) - i - j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,50 +27,54 @@ namespace ripple {
|
||||
class StringUtilities_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void testUnHexSuccess (std::string const& strIn, std::string const& strExpected)
|
||||
void
|
||||
testUnHexSuccess(std::string const& strIn, std::string const& strExpected)
|
||||
{
|
||||
auto rv = strUnHex (strIn);
|
||||
auto rv = strUnHex(strIn);
|
||||
BEAST_EXPECT(rv);
|
||||
BEAST_EXPECT(makeSlice(*rv) == makeSlice(strExpected));
|
||||
}
|
||||
|
||||
void testUnHexFailure (std::string const& strIn)
|
||||
void
|
||||
testUnHexFailure(std::string const& strIn)
|
||||
{
|
||||
auto rv = strUnHex (strIn);
|
||||
BEAST_EXPECT(! rv);
|
||||
auto rv = strUnHex(strIn);
|
||||
BEAST_EXPECT(!rv);
|
||||
}
|
||||
|
||||
void testUnHex ()
|
||||
void
|
||||
testUnHex()
|
||||
{
|
||||
testcase ("strUnHex");
|
||||
testcase("strUnHex");
|
||||
|
||||
testUnHexSuccess ("526970706c6544", "RippleD");
|
||||
testUnHexSuccess ("A", "\n");
|
||||
testUnHexSuccess ("0A", "\n");
|
||||
testUnHexSuccess ("D0A", "\r\n");
|
||||
testUnHexSuccess ("0D0A", "\r\n");
|
||||
testUnHexSuccess ("200D0A", " \r\n");
|
||||
testUnHexSuccess ("282A2B2C2D2E2F29", "(*+,-./)");
|
||||
testUnHexSuccess("526970706c6544", "RippleD");
|
||||
testUnHexSuccess("A", "\n");
|
||||
testUnHexSuccess("0A", "\n");
|
||||
testUnHexSuccess("D0A", "\r\n");
|
||||
testUnHexSuccess("0D0A", "\r\n");
|
||||
testUnHexSuccess("200D0A", " \r\n");
|
||||
testUnHexSuccess("282A2B2C2D2E2F29", "(*+,-./)");
|
||||
|
||||
// Check for things which contain some or only invalid characters
|
||||
testUnHexFailure ("123X");
|
||||
testUnHexFailure ("V");
|
||||
testUnHexFailure ("XRP");
|
||||
testUnHexFailure("123X");
|
||||
testUnHexFailure("V");
|
||||
testUnHexFailure("XRP");
|
||||
}
|
||||
|
||||
void testParseUrl ()
|
||||
void
|
||||
testParseUrl()
|
||||
{
|
||||
testcase ("parseUrl");
|
||||
testcase("parseUrl");
|
||||
|
||||
// Expected passes.
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "scheme://"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "scheme://"));
|
||||
BEAST_EXPECT(pUrl.scheme == "scheme");
|
||||
BEAST_EXPECT(pUrl.username.empty());
|
||||
BEAST_EXPECT(pUrl.password.empty());
|
||||
BEAST_EXPECT(pUrl.domain.empty());
|
||||
BEAST_EXPECT(! pUrl.port);
|
||||
BEAST_EXPECT(!pUrl.port);
|
||||
// RFC 3986:
|
||||
// > In general, a URI that uses the generic syntax for authority
|
||||
// with an empty path should be normalized to a path of "/".
|
||||
@@ -80,29 +84,29 @@ public:
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "scheme:///"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "scheme:///"));
|
||||
BEAST_EXPECT(pUrl.scheme == "scheme");
|
||||
BEAST_EXPECT(pUrl.username.empty());
|
||||
BEAST_EXPECT(pUrl.password.empty());
|
||||
BEAST_EXPECT(pUrl.domain.empty());
|
||||
BEAST_EXPECT(! pUrl.port);
|
||||
BEAST_EXPECT(!pUrl.port);
|
||||
BEAST_EXPECT(pUrl.path == "/");
|
||||
}
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "lower://domain"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "lower://domain"));
|
||||
BEAST_EXPECT(pUrl.scheme == "lower");
|
||||
BEAST_EXPECT(pUrl.username.empty());
|
||||
BEAST_EXPECT(pUrl.password.empty());
|
||||
BEAST_EXPECT(pUrl.domain == "domain");
|
||||
BEAST_EXPECT(! pUrl.port);
|
||||
BEAST_EXPECT(!pUrl.port);
|
||||
BEAST_EXPECT(pUrl.path.empty());
|
||||
}
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "UPPER://domain:234/"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "UPPER://domain:234/"));
|
||||
BEAST_EXPECT(pUrl.scheme == "upper");
|
||||
BEAST_EXPECT(pUrl.username.empty());
|
||||
BEAST_EXPECT(pUrl.password.empty());
|
||||
@@ -113,18 +117,18 @@ public:
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "Mixed://domain/path"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "Mixed://domain/path"));
|
||||
BEAST_EXPECT(pUrl.scheme == "mixed");
|
||||
BEAST_EXPECT(pUrl.username.empty());
|
||||
BEAST_EXPECT(pUrl.password.empty());
|
||||
BEAST_EXPECT(pUrl.domain == "domain");
|
||||
BEAST_EXPECT(! pUrl.port);
|
||||
BEAST_EXPECT(!pUrl.port);
|
||||
BEAST_EXPECT(pUrl.path == "/path");
|
||||
}
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "scheme://[::1]:123/path"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "scheme://[::1]:123/path"));
|
||||
BEAST_EXPECT(pUrl.scheme == "scheme");
|
||||
BEAST_EXPECT(pUrl.username.empty());
|
||||
BEAST_EXPECT(pUrl.password.empty());
|
||||
@@ -135,7 +139,8 @@ public:
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "scheme://user:pass@domain:123/abc:321"));
|
||||
BEAST_EXPECT(
|
||||
parseUrl(pUrl, "scheme://user:pass@domain:123/abc:321"));
|
||||
BEAST_EXPECT(pUrl.scheme == "scheme");
|
||||
BEAST_EXPECT(pUrl.username == "user");
|
||||
BEAST_EXPECT(pUrl.password == "pass");
|
||||
@@ -146,7 +151,7 @@ public:
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "scheme://user@domain:123/abc:321"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "scheme://user@domain:123/abc:321"));
|
||||
BEAST_EXPECT(pUrl.scheme == "scheme");
|
||||
BEAST_EXPECT(pUrl.username == "user");
|
||||
BEAST_EXPECT(pUrl.password.empty());
|
||||
@@ -157,7 +162,7 @@ public:
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "scheme://:pass@domain:123/abc:321"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "scheme://:pass@domain:123/abc:321"));
|
||||
BEAST_EXPECT(pUrl.scheme == "scheme");
|
||||
BEAST_EXPECT(pUrl.username.empty());
|
||||
BEAST_EXPECT(pUrl.password == "pass");
|
||||
@@ -168,7 +173,7 @@ public:
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "scheme://domain:123/abc:321"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "scheme://domain:123/abc:321"));
|
||||
BEAST_EXPECT(pUrl.scheme == "scheme");
|
||||
BEAST_EXPECT(pUrl.username.empty());
|
||||
BEAST_EXPECT(pUrl.password.empty());
|
||||
@@ -179,136 +184,137 @@ public:
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "scheme://user:pass@domain/abc:321"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "scheme://user:pass@domain/abc:321"));
|
||||
BEAST_EXPECT(pUrl.scheme == "scheme");
|
||||
BEAST_EXPECT(pUrl.username == "user");
|
||||
BEAST_EXPECT(pUrl.password == "pass");
|
||||
BEAST_EXPECT(pUrl.domain == "domain");
|
||||
BEAST_EXPECT(! pUrl.port);
|
||||
BEAST_EXPECT(!pUrl.port);
|
||||
BEAST_EXPECT(pUrl.path == "/abc:321");
|
||||
}
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "scheme://user@domain/abc:321"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "scheme://user@domain/abc:321"));
|
||||
BEAST_EXPECT(pUrl.scheme == "scheme");
|
||||
BEAST_EXPECT(pUrl.username == "user");
|
||||
BEAST_EXPECT(pUrl.password.empty());
|
||||
BEAST_EXPECT(pUrl.domain == "domain");
|
||||
BEAST_EXPECT(! pUrl.port);
|
||||
BEAST_EXPECT(!pUrl.port);
|
||||
BEAST_EXPECT(pUrl.path == "/abc:321");
|
||||
}
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "scheme://:pass@domain/abc:321"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "scheme://:pass@domain/abc:321"));
|
||||
BEAST_EXPECT(pUrl.scheme == "scheme");
|
||||
BEAST_EXPECT(pUrl.username.empty());
|
||||
BEAST_EXPECT(pUrl.password == "pass");
|
||||
BEAST_EXPECT(pUrl.domain == "domain");
|
||||
BEAST_EXPECT(! pUrl.port);
|
||||
BEAST_EXPECT(!pUrl.port);
|
||||
BEAST_EXPECT(pUrl.path == "/abc:321");
|
||||
}
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "scheme://domain/abc:321"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "scheme://domain/abc:321"));
|
||||
BEAST_EXPECT(pUrl.scheme == "scheme");
|
||||
BEAST_EXPECT(pUrl.username.empty());
|
||||
BEAST_EXPECT(pUrl.password.empty());
|
||||
BEAST_EXPECT(pUrl.domain == "domain");
|
||||
BEAST_EXPECT(! pUrl.port);
|
||||
BEAST_EXPECT(!pUrl.port);
|
||||
BEAST_EXPECT(pUrl.path == "/abc:321");
|
||||
}
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "scheme:///path/to/file"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "scheme:///path/to/file"));
|
||||
BEAST_EXPECT(pUrl.scheme == "scheme");
|
||||
BEAST_EXPECT(pUrl.username.empty());
|
||||
BEAST_EXPECT(pUrl.password.empty());
|
||||
BEAST_EXPECT(pUrl.domain.empty());
|
||||
BEAST_EXPECT(! pUrl.port);
|
||||
BEAST_EXPECT(!pUrl.port);
|
||||
BEAST_EXPECT(pUrl.path == "/path/to/file");
|
||||
}
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (
|
||||
pUrl, "scheme://user:pass@domain/path/with/an@sign"));
|
||||
BEAST_EXPECT(
|
||||
parseUrl(pUrl, "scheme://user:pass@domain/path/with/an@sign"));
|
||||
BEAST_EXPECT(pUrl.scheme == "scheme");
|
||||
BEAST_EXPECT(pUrl.username == "user");
|
||||
BEAST_EXPECT(pUrl.password == "pass");
|
||||
BEAST_EXPECT(pUrl.domain == "domain");
|
||||
BEAST_EXPECT(! pUrl.port);
|
||||
BEAST_EXPECT(!pUrl.port);
|
||||
BEAST_EXPECT(pUrl.path == "/path/with/an@sign");
|
||||
}
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (
|
||||
pUrl, "scheme://domain/path/with/an@sign"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "scheme://domain/path/with/an@sign"));
|
||||
BEAST_EXPECT(pUrl.scheme == "scheme");
|
||||
BEAST_EXPECT(pUrl.username.empty());
|
||||
BEAST_EXPECT(pUrl.password.empty());
|
||||
BEAST_EXPECT(pUrl.domain == "domain");
|
||||
BEAST_EXPECT(! pUrl.port);
|
||||
BEAST_EXPECT(!pUrl.port);
|
||||
BEAST_EXPECT(pUrl.path == "/path/with/an@sign");
|
||||
}
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "scheme://:999/"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "scheme://:999/"));
|
||||
BEAST_EXPECT(pUrl.scheme == "scheme");
|
||||
BEAST_EXPECT(pUrl.username.empty());
|
||||
BEAST_EXPECT(pUrl.password.empty());
|
||||
BEAST_EXPECT(pUrl.domain == ":999");
|
||||
BEAST_EXPECT(! pUrl.port);
|
||||
BEAST_EXPECT(!pUrl.port);
|
||||
BEAST_EXPECT(pUrl.path == "/");
|
||||
}
|
||||
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(parseUrl (pUrl, "http://::1:1234/validators"));
|
||||
BEAST_EXPECT(parseUrl(pUrl, "http://::1:1234/validators"));
|
||||
BEAST_EXPECT(pUrl.scheme == "http");
|
||||
BEAST_EXPECT(pUrl.username.empty());
|
||||
BEAST_EXPECT(pUrl.password.empty());
|
||||
BEAST_EXPECT(pUrl.domain == "::0.1.18.52");
|
||||
BEAST_EXPECT(! pUrl.port);
|
||||
BEAST_EXPECT(!pUrl.port);
|
||||
BEAST_EXPECT(pUrl.path == "/validators");
|
||||
}
|
||||
|
||||
// Expected fails.
|
||||
{
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(! parseUrl (pUrl, ""));
|
||||
BEAST_EXPECT(! parseUrl (pUrl, "nonsense"));
|
||||
BEAST_EXPECT(! parseUrl (pUrl, "://"));
|
||||
BEAST_EXPECT(! parseUrl (pUrl, ":///"));
|
||||
BEAST_EXPECT(!parseUrl(pUrl, ""));
|
||||
BEAST_EXPECT(!parseUrl(pUrl, "nonsense"));
|
||||
BEAST_EXPECT(!parseUrl(pUrl, "://"));
|
||||
BEAST_EXPECT(!parseUrl(pUrl, ":///"));
|
||||
}
|
||||
|
||||
{
|
||||
std::string strUrl("s://" + std::string(8192, ':'));
|
||||
parsedURL pUrl;
|
||||
BEAST_EXPECT(! parseUrl (pUrl, strUrl));
|
||||
BEAST_EXPECT(!parseUrl(pUrl, strUrl));
|
||||
}
|
||||
}
|
||||
|
||||
void testToString ()
|
||||
void
|
||||
testToString()
|
||||
{
|
||||
testcase ("toString");
|
||||
testcase("toString");
|
||||
auto result = to_string("hello");
|
||||
BEAST_EXPECT(result == "hello");
|
||||
}
|
||||
|
||||
void run () override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testParseUrl ();
|
||||
testUnHex ();
|
||||
testToString ();
|
||||
testParseUrl();
|
||||
testUnHex();
|
||||
testToString();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(StringUtilities, ripple_basics, ripple);
|
||||
|
||||
} // ripple
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/basics/chrono.h>
|
||||
#include <ripple/basics/TaggedCache.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <ripple/basics/chrono.h>
|
||||
#include <ripple/beast/clock/manual_clock.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <test/unit_test/SuiteJournal.h>
|
||||
|
||||
namespace ripple {
|
||||
@@ -38,102 +38,103 @@ original object.
|
||||
class TaggedCache_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void run () override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
using namespace beast::severities;
|
||||
test::SuiteJournal journal ("TaggedCache_test", *this);
|
||||
test::SuiteJournal journal("TaggedCache_test", *this);
|
||||
|
||||
TestStopwatch clock;
|
||||
clock.set (0);
|
||||
clock.set(0);
|
||||
|
||||
using Key = int;
|
||||
using Value = std::string;
|
||||
using Cache = TaggedCache <Key, Value>;
|
||||
using Cache = TaggedCache<Key, Value>;
|
||||
|
||||
Cache c ("test", 1, 1s, clock, journal);
|
||||
Cache c("test", 1, 1s, clock, journal);
|
||||
|
||||
// Insert an item, retrieve it, and age it so it gets purged.
|
||||
{
|
||||
BEAST_EXPECT(c.getCacheSize() == 0);
|
||||
BEAST_EXPECT(c.getTrackSize() == 0);
|
||||
BEAST_EXPECT(! c.insert (1, "one"));
|
||||
BEAST_EXPECT(!c.insert(1, "one"));
|
||||
BEAST_EXPECT(c.getCacheSize() == 1);
|
||||
BEAST_EXPECT(c.getTrackSize() == 1);
|
||||
|
||||
{
|
||||
std::string s;
|
||||
BEAST_EXPECT(c.retrieve (1, s));
|
||||
BEAST_EXPECT(c.retrieve(1, s));
|
||||
BEAST_EXPECT(s == "one");
|
||||
}
|
||||
|
||||
++clock;
|
||||
c.sweep ();
|
||||
BEAST_EXPECT(c.getCacheSize () == 0);
|
||||
BEAST_EXPECT(c.getTrackSize () == 0);
|
||||
c.sweep();
|
||||
BEAST_EXPECT(c.getCacheSize() == 0);
|
||||
BEAST_EXPECT(c.getTrackSize() == 0);
|
||||
}
|
||||
|
||||
// Insert an item, maintain a strong pointer, age it, and
|
||||
// verify that the entry still exists.
|
||||
{
|
||||
BEAST_EXPECT(! c.insert (2, "two"));
|
||||
BEAST_EXPECT(!c.insert(2, "two"));
|
||||
BEAST_EXPECT(c.getCacheSize() == 1);
|
||||
BEAST_EXPECT(c.getTrackSize() == 1);
|
||||
|
||||
{
|
||||
Cache::mapped_ptr p (c.fetch (2));
|
||||
Cache::mapped_ptr p(c.fetch(2));
|
||||
BEAST_EXPECT(p != nullptr);
|
||||
++clock;
|
||||
c.sweep ();
|
||||
c.sweep();
|
||||
BEAST_EXPECT(c.getCacheSize() == 0);
|
||||
BEAST_EXPECT(c.getTrackSize() == 1);
|
||||
}
|
||||
|
||||
// Make sure its gone now that our reference is gone
|
||||
++clock;
|
||||
c.sweep ();
|
||||
c.sweep();
|
||||
BEAST_EXPECT(c.getCacheSize() == 0);
|
||||
BEAST_EXPECT(c.getTrackSize() == 0);
|
||||
}
|
||||
|
||||
// Insert the same key/value pair and make sure we get the same result
|
||||
{
|
||||
BEAST_EXPECT(! c.insert (3, "three"));
|
||||
BEAST_EXPECT(!c.insert(3, "three"));
|
||||
|
||||
{
|
||||
Cache::mapped_ptr const p1 (c.fetch (3));
|
||||
Cache::mapped_ptr p2 (std::make_shared <Value> ("three"));
|
||||
Cache::mapped_ptr const p1(c.fetch(3));
|
||||
Cache::mapped_ptr p2(std::make_shared<Value>("three"));
|
||||
c.canonicalize_replace_client(3, p2);
|
||||
BEAST_EXPECT(p1.get() == p2.get());
|
||||
}
|
||||
++clock;
|
||||
c.sweep ();
|
||||
c.sweep();
|
||||
BEAST_EXPECT(c.getCacheSize() == 0);
|
||||
BEAST_EXPECT(c.getTrackSize() == 0);
|
||||
}
|
||||
|
||||
// Put an object in but keep a strong pointer to it, advance the clock a lot,
|
||||
// then canonicalize a new object with the same key, make sure you get the
|
||||
// original object.
|
||||
// Put an object in but keep a strong pointer to it, advance the clock a
|
||||
// lot, then canonicalize a new object with the same key, make sure you
|
||||
// get the original object.
|
||||
{
|
||||
// Put an object in
|
||||
BEAST_EXPECT(! c.insert (4, "four"));
|
||||
BEAST_EXPECT(!c.insert(4, "four"));
|
||||
BEAST_EXPECT(c.getCacheSize() == 1);
|
||||
BEAST_EXPECT(c.getTrackSize() == 1);
|
||||
|
||||
{
|
||||
// Keep a strong pointer to it
|
||||
Cache::mapped_ptr p1 (c.fetch (4));
|
||||
Cache::mapped_ptr p1(c.fetch(4));
|
||||
BEAST_EXPECT(p1 != nullptr);
|
||||
BEAST_EXPECT(c.getCacheSize() == 1);
|
||||
BEAST_EXPECT(c.getTrackSize() == 1);
|
||||
// Advance the clock a lot
|
||||
++clock;
|
||||
c.sweep ();
|
||||
c.sweep();
|
||||
BEAST_EXPECT(c.getCacheSize() == 0);
|
||||
BEAST_EXPECT(c.getTrackSize() == 1);
|
||||
// Canonicalize a new object with the same key
|
||||
Cache::mapped_ptr p2 (std::make_shared <std::string> ("four"));
|
||||
Cache::mapped_ptr p2(std::make_shared<std::string>("four"));
|
||||
BEAST_EXPECT(c.canonicalize_replace_client(4, p2));
|
||||
BEAST_EXPECT(c.getCacheSize() == 1);
|
||||
BEAST_EXPECT(c.getTrackSize() == 1);
|
||||
@@ -142,13 +143,13 @@ public:
|
||||
}
|
||||
|
||||
++clock;
|
||||
c.sweep ();
|
||||
c.sweep();
|
||||
BEAST_EXPECT(c.getCacheSize() == 0);
|
||||
BEAST_EXPECT(c.getTrackSize() == 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(TaggedCache,common,ripple);
|
||||
BEAST_DEFINE_TESTSUITE(TaggedCache, common, ripple);
|
||||
|
||||
}
|
||||
} // namespace ripple
|
||||
|
||||
@@ -25,32 +25,34 @@ namespace ripple {
|
||||
class XRPAmount_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void testSigNum ()
|
||||
void
|
||||
testSigNum()
|
||||
{
|
||||
testcase ("signum");
|
||||
testcase("signum");
|
||||
|
||||
for (auto i : { -1, 0, 1})
|
||||
for (auto i : {-1, 0, 1})
|
||||
{
|
||||
XRPAmount const x(i);
|
||||
|
||||
if (i < 0)
|
||||
BEAST_EXPECT(x.signum () < 0);
|
||||
BEAST_EXPECT(x.signum() < 0);
|
||||
else if (i > 0)
|
||||
BEAST_EXPECT(x.signum () > 0);
|
||||
BEAST_EXPECT(x.signum() > 0);
|
||||
else
|
||||
BEAST_EXPECT(x.signum () == 0);
|
||||
BEAST_EXPECT(x.signum() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
void testBeastZero ()
|
||||
void
|
||||
testBeastZero()
|
||||
{
|
||||
testcase ("beast::Zero Comparisons");
|
||||
testcase("beast::Zero Comparisons");
|
||||
|
||||
using beast::zero;
|
||||
|
||||
for (auto i : { -1, 0, 1})
|
||||
for (auto i : {-1, 0, 1})
|
||||
{
|
||||
XRPAmount const x (i);
|
||||
XRPAmount const x(i);
|
||||
|
||||
BEAST_EXPECT((i == 0) == (x == zero));
|
||||
BEAST_EXPECT((i != 0) == (x != zero));
|
||||
@@ -68,17 +70,18 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void testComparisons ()
|
||||
void
|
||||
testComparisons()
|
||||
{
|
||||
testcase ("XRP Comparisons");
|
||||
testcase("XRP Comparisons");
|
||||
|
||||
for (auto i : { -1, 0, 1})
|
||||
for (auto i : {-1, 0, 1})
|
||||
{
|
||||
XRPAmount const x (i);
|
||||
XRPAmount const x(i);
|
||||
|
||||
for (auto j : { -1, 0, 1})
|
||||
for (auto j : {-1, 0, 1})
|
||||
{
|
||||
XRPAmount const y (j);
|
||||
XRPAmount const y(j);
|
||||
|
||||
BEAST_EXPECT((i == j) == (x == y));
|
||||
BEAST_EXPECT((i != j) == (x != y));
|
||||
@@ -90,27 +93,29 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void testAddSub ()
|
||||
void
|
||||
testAddSub()
|
||||
{
|
||||
testcase ("Addition & Subtraction");
|
||||
testcase("Addition & Subtraction");
|
||||
|
||||
for (auto i : { -1, 0, 1})
|
||||
for (auto i : {-1, 0, 1})
|
||||
{
|
||||
XRPAmount const x (i);
|
||||
XRPAmount const x(i);
|
||||
|
||||
for (auto j : { -1, 0, 1})
|
||||
for (auto j : {-1, 0, 1})
|
||||
{
|
||||
XRPAmount const y (j);
|
||||
XRPAmount const y(j);
|
||||
|
||||
BEAST_EXPECT(XRPAmount(i + j) == (x + y));
|
||||
BEAST_EXPECT(XRPAmount(i - j) == (x - y));
|
||||
|
||||
BEAST_EXPECT((x + y) == (y + x)); // addition is commutative
|
||||
BEAST_EXPECT((x + y) == (y + x)); // addition is commutative
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testDecimal ()
|
||||
void
|
||||
testDecimal()
|
||||
{
|
||||
// Tautology
|
||||
BEAST_EXPECT(DROPS_PER_XRP.decimalXRP() == 1);
|
||||
@@ -128,7 +133,8 @@ public:
|
||||
BEAST_EXPECT(test.decimalXRP() == -100);
|
||||
}
|
||||
|
||||
void testFunctions()
|
||||
void
|
||||
testFunctions()
|
||||
{
|
||||
// Explicitly test every defined function for the XRPAmount class
|
||||
// since some of them are templated, but not used anywhere else.
|
||||
@@ -136,7 +142,7 @@ public:
|
||||
|
||||
XRPAmount defaulted;
|
||||
(void)defaulted;
|
||||
XRPAmount test{ 0 };
|
||||
XRPAmount test{0};
|
||||
BEAST_EXPECT(test.drops() == 0);
|
||||
|
||||
test = make(beast::zero);
|
||||
@@ -151,7 +157,7 @@ public:
|
||||
test = make(100u);
|
||||
BEAST_EXPECT(test.drops() == 100);
|
||||
|
||||
XRPAmount const targetSame{ 200u };
|
||||
XRPAmount const targetSame{200u};
|
||||
test = make(targetSame);
|
||||
BEAST_EXPECT(test.drops() == 200);
|
||||
BEAST_EXPECT(test == targetSame);
|
||||
@@ -210,120 +216,130 @@ public:
|
||||
BEAST_EXPECT(to_string(test) == "200");
|
||||
}
|
||||
|
||||
void testMulRatio()
|
||||
void
|
||||
testMulRatio()
|
||||
{
|
||||
testcase ("mulRatio");
|
||||
testcase("mulRatio");
|
||||
|
||||
constexpr auto maxUInt32 = std::numeric_limits<std::uint32_t>::max ();
|
||||
constexpr auto maxXRP = std::numeric_limits<XRPAmount::value_type>::max ();
|
||||
constexpr auto minXRP = std::numeric_limits<XRPAmount::value_type>::min ();
|
||||
constexpr auto maxUInt32 = std::numeric_limits<std::uint32_t>::max();
|
||||
constexpr auto maxXRP =
|
||||
std::numeric_limits<XRPAmount::value_type>::max();
|
||||
constexpr auto minXRP =
|
||||
std::numeric_limits<XRPAmount::value_type>::min();
|
||||
|
||||
{
|
||||
// multiply by a number that would overflow then divide by the same
|
||||
// number, and check we didn't lose any value
|
||||
XRPAmount big (maxXRP);
|
||||
BEAST_EXPECT(big == mulRatio (big, maxUInt32, maxUInt32, true));
|
||||
XRPAmount big(maxXRP);
|
||||
BEAST_EXPECT(big == mulRatio(big, maxUInt32, maxUInt32, true));
|
||||
// rounding mode shouldn't matter as the result is exact
|
||||
BEAST_EXPECT(big == mulRatio (big, maxUInt32, maxUInt32, false));
|
||||
BEAST_EXPECT(big == mulRatio(big, maxUInt32, maxUInt32, false));
|
||||
|
||||
// multiply and divide by values that would overflow if done naively,
|
||||
// and check that it gives the correct answer
|
||||
big -= 0xf; // Subtract a little so it's divisable by 4
|
||||
BEAST_EXPECT(mulRatio(big, 3, 4, false).value() == (big.value() / 4) * 3);
|
||||
BEAST_EXPECT(mulRatio(big, 3, 4, true).value() == (big.value() / 4) * 3);
|
||||
// multiply and divide by values that would overflow if done
|
||||
// naively, and check that it gives the correct answer
|
||||
big -= 0xf; // Subtract a little so it's divisable by 4
|
||||
BEAST_EXPECT(
|
||||
mulRatio(big, 3, 4, false).value() == (big.value() / 4) * 3);
|
||||
BEAST_EXPECT(
|
||||
mulRatio(big, 3, 4, true).value() == (big.value() / 4) * 3);
|
||||
BEAST_EXPECT((big.value() * 3) / 4 != (big.value() / 4) * 3);
|
||||
}
|
||||
|
||||
{
|
||||
// Similar test as above, but for negative values
|
||||
XRPAmount big (minXRP);
|
||||
BEAST_EXPECT(big == mulRatio (big, maxUInt32, maxUInt32, true));
|
||||
XRPAmount big(minXRP);
|
||||
BEAST_EXPECT(big == mulRatio(big, maxUInt32, maxUInt32, true));
|
||||
// rounding mode shouldn't matter as the result is exact
|
||||
BEAST_EXPECT(big == mulRatio (big, maxUInt32, maxUInt32, false));
|
||||
BEAST_EXPECT(big == mulRatio(big, maxUInt32, maxUInt32, false));
|
||||
|
||||
// multiply and divide by values that would overflow if done naively,
|
||||
// and check that it gives the correct answer
|
||||
BEAST_EXPECT(mulRatio(big, 3, 4, false).value() == (big.value() / 4) * 3);
|
||||
BEAST_EXPECT(mulRatio(big, 3, 4, true).value() == (big.value() / 4) * 3);
|
||||
// multiply and divide by values that would overflow if done
|
||||
// naively, and check that it gives the correct answer
|
||||
BEAST_EXPECT(
|
||||
mulRatio(big, 3, 4, false).value() == (big.value() / 4) * 3);
|
||||
BEAST_EXPECT(
|
||||
mulRatio(big, 3, 4, true).value() == (big.value() / 4) * 3);
|
||||
BEAST_EXPECT((big.value() * 3) / 4 != (big.value() / 4) * 3);
|
||||
}
|
||||
|
||||
{
|
||||
// small amounts
|
||||
XRPAmount tiny (1);
|
||||
XRPAmount tiny(1);
|
||||
// Round up should give the smallest allowable number
|
||||
BEAST_EXPECT(tiny == mulRatio (tiny, 1, maxUInt32, true));
|
||||
BEAST_EXPECT(tiny == mulRatio(tiny, 1, maxUInt32, true));
|
||||
// rounding down should be zero
|
||||
BEAST_EXPECT(beast::zero == mulRatio (tiny, 1, maxUInt32, false));
|
||||
BEAST_EXPECT(beast::zero ==
|
||||
mulRatio (tiny, maxUInt32 - 1, maxUInt32, false));
|
||||
BEAST_EXPECT(beast::zero == mulRatio(tiny, 1, maxUInt32, false));
|
||||
BEAST_EXPECT(
|
||||
beast::zero == mulRatio(tiny, maxUInt32 - 1, maxUInt32, false));
|
||||
|
||||
// tiny negative numbers
|
||||
XRPAmount tinyNeg (-1);
|
||||
XRPAmount tinyNeg(-1);
|
||||
// Round up should give zero
|
||||
BEAST_EXPECT(beast::zero == mulRatio (tinyNeg, 1, maxUInt32, true));
|
||||
BEAST_EXPECT(beast::zero == mulRatio (tinyNeg, maxUInt32 - 1, maxUInt32, true));
|
||||
BEAST_EXPECT(beast::zero == mulRatio(tinyNeg, 1, maxUInt32, true));
|
||||
BEAST_EXPECT(
|
||||
beast::zero ==
|
||||
mulRatio(tinyNeg, maxUInt32 - 1, maxUInt32, true));
|
||||
// rounding down should be tiny
|
||||
BEAST_EXPECT(tinyNeg == mulRatio (tinyNeg, maxUInt32 - 1, maxUInt32, false));
|
||||
BEAST_EXPECT(
|
||||
tinyNeg == mulRatio(tinyNeg, maxUInt32 - 1, maxUInt32, false));
|
||||
}
|
||||
|
||||
{
|
||||
// rounding
|
||||
{
|
||||
XRPAmount one (1);
|
||||
auto const rup = mulRatio (one, maxUInt32 - 1, maxUInt32, true);
|
||||
auto const rdown = mulRatio (one, maxUInt32 - 1, maxUInt32, false);
|
||||
BEAST_EXPECT(rup.drops () - rdown.drops () == 1);
|
||||
}
|
||||
|
||||
{
|
||||
XRPAmount big (maxXRP);
|
||||
auto const rup = mulRatio (big, maxUInt32 - 1, maxUInt32, true);
|
||||
auto const rdown = mulRatio (big, maxUInt32 - 1, maxUInt32, false);
|
||||
BEAST_EXPECT(rup.drops () - rdown.drops () == 1);
|
||||
}
|
||||
|
||||
{
|
||||
XRPAmount negOne (-1);
|
||||
auto const rup = mulRatio (negOne, maxUInt32 - 1, maxUInt32, true);
|
||||
auto const rdown = mulRatio (negOne, maxUInt32 - 1, maxUInt32, false);
|
||||
BEAST_EXPECT(rup.drops () - rdown.drops () == 1);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// division by zero
|
||||
XRPAmount one (1);
|
||||
except ([&] {mulRatio (one, 1, 0, true);});
|
||||
}
|
||||
|
||||
{
|
||||
// overflow
|
||||
XRPAmount big (maxXRP);
|
||||
except ([&] {mulRatio (big, 2, 1, true);});
|
||||
}
|
||||
|
||||
{
|
||||
// underflow
|
||||
XRPAmount bigNegative (minXRP + 10);
|
||||
BEAST_EXPECT(mulRatio(bigNegative, 2, 1, true) == minXRP);
|
||||
}
|
||||
{// rounding
|
||||
{XRPAmount one(1);
|
||||
auto const rup = mulRatio(one, maxUInt32 - 1, maxUInt32, true);
|
||||
auto const rdown = mulRatio(one, maxUInt32 - 1, maxUInt32, false);
|
||||
BEAST_EXPECT(rup.drops() - rdown.drops() == 1);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void run () override
|
||||
{
|
||||
testSigNum ();
|
||||
testBeastZero ();
|
||||
testComparisons ();
|
||||
testAddSub ();
|
||||
testDecimal ();
|
||||
testFunctions ();
|
||||
testMulRatio ();
|
||||
XRPAmount big(maxXRP);
|
||||
auto const rup = mulRatio(big, maxUInt32 - 1, maxUInt32, true);
|
||||
auto const rdown = mulRatio(big, maxUInt32 - 1, maxUInt32, false);
|
||||
BEAST_EXPECT(rup.drops() - rdown.drops() == 1);
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(XRPAmount,protocol,ripple);
|
||||
{
|
||||
XRPAmount negOne(-1);
|
||||
auto const rup = mulRatio(negOne, maxUInt32 - 1, maxUInt32, true);
|
||||
auto const rdown = mulRatio(negOne, maxUInt32 - 1, maxUInt32, false);
|
||||
BEAST_EXPECT(rup.drops() - rdown.drops() == 1);
|
||||
}
|
||||
}
|
||||
|
||||
} // ripple
|
||||
{
|
||||
// division by zero
|
||||
XRPAmount one(1);
|
||||
except([&] { mulRatio(one, 1, 0, true); });
|
||||
}
|
||||
|
||||
{
|
||||
// overflow
|
||||
XRPAmount big(maxXRP);
|
||||
except([&] { mulRatio(big, 2, 1, true); });
|
||||
}
|
||||
|
||||
{
|
||||
// underflow
|
||||
XRPAmount bigNegative(minXRP + 10);
|
||||
BEAST_EXPECT(mulRatio(bigNegative, 2, 1, true) == minXRP);
|
||||
}
|
||||
} // namespace ripple
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testSigNum();
|
||||
testBeastZero();
|
||||
testComparisons();
|
||||
testAddSub();
|
||||
testDecimal();
|
||||
testFunctions();
|
||||
testMulRatio();
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(XRPAmount, protocol, ripple);
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -35,36 +35,41 @@ class base64_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void
|
||||
check (std::string const& in, std::string const& out)
|
||||
check(std::string const& in, std::string const& out)
|
||||
{
|
||||
auto const encoded = base64_encode (in);
|
||||
auto const encoded = base64_encode(in);
|
||||
BEAST_EXPECT(encoded == out);
|
||||
BEAST_EXPECT(base64_decode (encoded) == in);
|
||||
BEAST_EXPECT(base64_decode(encoded) == in);
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
check ("", "");
|
||||
check ("f", "Zg==");
|
||||
check ("fo", "Zm8=");
|
||||
check ("foo", "Zm9v");
|
||||
check ("foob", "Zm9vYg==");
|
||||
check ("fooba", "Zm9vYmE=");
|
||||
check ("foobar", "Zm9vYmFy");
|
||||
check("", "");
|
||||
check("f", "Zg==");
|
||||
check("fo", "Zm8=");
|
||||
check("foo", "Zm9v");
|
||||
check("foob", "Zm9vYg==");
|
||||
check("fooba", "Zm9vYmE=");
|
||||
check("foobar", "Zm9vYmFy");
|
||||
|
||||
check(
|
||||
"Man is distinguished, not only by his reason, but by this singular passion from "
|
||||
"other animals, which is a lust of the mind, that by a perseverance of delight "
|
||||
"in the continued and indefatigable generation of knowledge, exceeds the short "
|
||||
"vehemence of any carnal pleasure."
|
||||
,
|
||||
"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"
|
||||
"IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg"
|
||||
"dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu"
|
||||
"dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo"
|
||||
"ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="
|
||||
);
|
||||
"Man is distinguished, not only by his reason, but by this "
|
||||
"singular passion from "
|
||||
"other animals, which is a lust of the mind, that by a "
|
||||
"perseverance of delight "
|
||||
"in the continued and indefatigable generation of knowledge, "
|
||||
"exceeds the short "
|
||||
"vehemence of any carnal pleasure.",
|
||||
"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dC"
|
||||
"BieSB0aGlz"
|
||||
"IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIG"
|
||||
"x1c3Qgb2Yg"
|
||||
"dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aG"
|
||||
"UgY29udGlu"
|
||||
"dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleG"
|
||||
"NlZWRzIHRo"
|
||||
"ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=");
|
||||
|
||||
std::string const notBase64 = "not_base64!!";
|
||||
std::string const truncated = "not";
|
||||
@@ -74,4 +79,4 @@ public:
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(base64, ripple_basics, ripple);
|
||||
|
||||
} // ripple
|
||||
} // namespace ripple
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/basics/base_uint.h>
|
||||
#include <ripple/basics/Blob.h>
|
||||
#include <ripple/basics/base_uint.h>
|
||||
#include <ripple/basics/hardened_hash.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
@@ -41,14 +41,16 @@ struct nonhash
|
||||
nonhash() = default;
|
||||
|
||||
void
|
||||
operator() (void const* key, std::size_t len) noexcept
|
||||
operator()(void const* key, std::size_t len) noexcept
|
||||
{
|
||||
assert(len == WIDTH);
|
||||
memcpy(data_.data(), key, len);
|
||||
}
|
||||
|
||||
explicit
|
||||
operator std::size_t() noexcept { return WIDTH; }
|
||||
explicit operator std::size_t() noexcept
|
||||
{
|
||||
return WIDTH;
|
||||
}
|
||||
};
|
||||
|
||||
struct base_uint_test : beast::unit_test::suite
|
||||
@@ -57,17 +59,20 @@ struct base_uint_test : beast::unit_test::suite
|
||||
static_assert(std::is_copy_constructible<test96>::value, "");
|
||||
static_assert(std::is_copy_assignable<test96>::value, "");
|
||||
|
||||
void run() override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
static_assert(!std::is_constructible<test96, std::complex<double>>::value, "");
|
||||
static_assert(!std::is_assignable<test96&, std::complex<double>>::value, "");
|
||||
static_assert(
|
||||
!std::is_constructible<test96, std::complex<double>>::value, "");
|
||||
static_assert(
|
||||
!std::is_assignable<test96&, std::complex<double>>::value, "");
|
||||
// used to verify set insertion (hashing required)
|
||||
std::unordered_set<test96, hardened_hash<>> uset;
|
||||
|
||||
Blob raw { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
|
||||
Blob raw{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
|
||||
BEAST_EXPECT(test96::bytes == raw.size());
|
||||
|
||||
test96 u { raw };
|
||||
test96 u{raw};
|
||||
uset.insert(u);
|
||||
BEAST_EXPECT(raw.size() == u.size());
|
||||
BEAST_EXPECT(to_string(u) == "0102030405060708090A0B0C");
|
||||
@@ -87,10 +92,10 @@ struct base_uint_test : beast::unit_test::suite
|
||||
// back into another base_uint (w) for comparison with the original
|
||||
nonhash<96> h;
|
||||
hash_append(h, u);
|
||||
test96 w {std::vector<std::uint8_t>(h.data_.begin(), h.data_.end())};
|
||||
test96 w{std::vector<std::uint8_t>(h.data_.begin(), h.data_.end())};
|
||||
BEAST_EXPECT(w == u);
|
||||
|
||||
test96 v { ~u };
|
||||
test96 v{~u};
|
||||
uset.insert(v);
|
||||
BEAST_EXPECT(to_string(v) == "FEFDFCFBFAF9F8F7F6F5F4F3");
|
||||
BEAST_EXPECT(*v.data() == 0xfe);
|
||||
@@ -110,7 +115,7 @@ struct base_uint_test : beast::unit_test::suite
|
||||
v = u;
|
||||
BEAST_EXPECT(v == u);
|
||||
|
||||
test96 z { beast::zero };
|
||||
test96 z{beast::zero};
|
||||
uset.insert(z);
|
||||
BEAST_EXPECT(to_string(z) == "000000000000000000000000");
|
||||
BEAST_EXPECT(*z.data() == 0);
|
||||
@@ -125,7 +130,7 @@ struct base_uint_test : beast::unit_test::suite
|
||||
BEAST_EXPECT(d == 0);
|
||||
}
|
||||
|
||||
test96 n { z };
|
||||
test96 n{z};
|
||||
n++;
|
||||
BEAST_EXPECT(n == test96(1));
|
||||
n--;
|
||||
@@ -136,11 +141,11 @@ struct base_uint_test : beast::unit_test::suite
|
||||
n = beast::zero;
|
||||
BEAST_EXPECT(n == z);
|
||||
|
||||
test96 zp1 { z };
|
||||
test96 zp1{z};
|
||||
zp1++;
|
||||
test96 zm1 { z };
|
||||
test96 zm1{z};
|
||||
zm1--;
|
||||
test96 x { zm1 ^ zp1 };
|
||||
test96 x{zm1 ^ zp1};
|
||||
uset.insert(x);
|
||||
BEAST_EXPECTS(to_string(x) == "FFFFFFFFFFFFFFFFFFFFFFFE", to_string(x));
|
||||
|
||||
@@ -153,11 +158,11 @@ struct base_uint_test : beast::unit_test::suite
|
||||
fromHex = z;
|
||||
|
||||
// fails with extra char
|
||||
BEAST_EXPECT(! fromHex.SetHexExact("A" + to_string(u)));
|
||||
BEAST_EXPECT(!fromHex.SetHexExact("A" + to_string(u)));
|
||||
fromHex = z;
|
||||
|
||||
// fails with extra char at end
|
||||
BEAST_EXPECT(! fromHex.SetHexExact(to_string(u) + "A"));
|
||||
BEAST_EXPECT(!fromHex.SetHexExact(to_string(u) + "A"));
|
||||
// NOTE: the value fromHex is actually correctly parsed
|
||||
// in this case, but that is an implementation detail and
|
||||
// not guaranteed, thus we don't check the value here.
|
||||
@@ -178,7 +183,7 @@ struct base_uint_test : beast::unit_test::suite
|
||||
fromHex = z;
|
||||
|
||||
// invalid hex chars should fail (0 replaced with Z here)
|
||||
BEAST_EXPECT(! fromHex.SetHex(
|
||||
BEAST_EXPECT(!fromHex.SetHex(
|
||||
boost::algorithm::replace_all_copy(to_string(u), "0", "Z")));
|
||||
fromHex = z;
|
||||
|
||||
@@ -187,16 +192,16 @@ struct base_uint_test : beast::unit_test::suite
|
||||
fromHex = z;
|
||||
|
||||
// strict mode fails with leading chars
|
||||
BEAST_EXPECT(! fromHex.SetHex(" 0x" + to_string(u), true));
|
||||
BEAST_EXPECT(!fromHex.SetHex(" 0x" + to_string(u), true));
|
||||
fromHex = z;
|
||||
|
||||
// SetHex ignores extra leading hexits, so the parsed value
|
||||
// is still correct for the following case (strict or non-strict)
|
||||
BEAST_EXPECT(fromHex.SetHex("DEAD" + to_string(u), true ));
|
||||
BEAST_EXPECT(fromHex.SetHex("DEAD" + to_string(u), true));
|
||||
BEAST_EXPECT(fromHex == u);
|
||||
fromHex = z;
|
||||
|
||||
BEAST_EXPECT(fromHex.SetHex("DEAD" + to_string(u), false ));
|
||||
BEAST_EXPECT(fromHex.SetHex("DEAD" + to_string(u), false));
|
||||
BEAST_EXPECT(fromHex == u);
|
||||
fromHex = z;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@ namespace ripple {
|
||||
class contract_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void run () override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -56,6 +57,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(contract,basics,ripple);
|
||||
BEAST_DEFINE_TESTSUITE(contract, basics, ripple);
|
||||
|
||||
}
|
||||
} // namespace ripple
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <iomanip>
|
||||
#include <functional>
|
||||
#include <iomanip>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -37,16 +37,16 @@ private:
|
||||
T t;
|
||||
|
||||
public:
|
||||
explicit test_user_type_member (T const& t_ = T())
|
||||
: t (t_)
|
||||
explicit test_user_type_member(T const& t_ = T()) : t(t_)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Hasher>
|
||||
friend void hash_append (Hasher& h, test_user_type_member const& a) noexcept
|
||||
friend void
|
||||
hash_append(Hasher& h, test_user_type_member const& a) noexcept
|
||||
{
|
||||
using beast::hash_append;
|
||||
hash_append (h, a.t);
|
||||
hash_append(h, a.t);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -57,21 +57,21 @@ private:
|
||||
T t;
|
||||
|
||||
public:
|
||||
explicit test_user_type_free (T const& t_ = T())
|
||||
: t (t_)
|
||||
explicit test_user_type_free(T const& t_ = T()) : t(t_)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Hasher>
|
||||
friend void hash_append (Hasher& h, test_user_type_free const& a) noexcept
|
||||
friend void
|
||||
hash_append(Hasher& h, test_user_type_free const& a) noexcept
|
||||
{
|
||||
using beast::hash_append;
|
||||
hash_append (h, a.t);
|
||||
hash_append(h, a.t);
|
||||
}
|
||||
};
|
||||
|
||||
} // detail
|
||||
} // ripple
|
||||
} // namespace detail
|
||||
} // namespace ripple
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -80,40 +80,40 @@ namespace ripple {
|
||||
namespace detail {
|
||||
|
||||
template <class T>
|
||||
using test_hardened_unordered_set =
|
||||
std::unordered_set <T, hardened_hash <>>;
|
||||
using test_hardened_unordered_set = std::unordered_set<T, hardened_hash<>>;
|
||||
|
||||
template <class T>
|
||||
using test_hardened_unordered_map =
|
||||
std::unordered_map <T, int, hardened_hash <>>;
|
||||
using test_hardened_unordered_map = std::unordered_map<T, int, hardened_hash<>>;
|
||||
|
||||
template <class T>
|
||||
using test_hardened_unordered_multiset =
|
||||
std::unordered_multiset <T, hardened_hash <>>;
|
||||
std::unordered_multiset<T, hardened_hash<>>;
|
||||
|
||||
template <class T>
|
||||
using test_hardened_unordered_multimap =
|
||||
std::unordered_multimap <T, int, hardened_hash <>>;
|
||||
std::unordered_multimap<T, int, hardened_hash<>>;
|
||||
|
||||
} // detail
|
||||
} // namespace detail
|
||||
|
||||
template <std::size_t Bits, class UInt = std::uint64_t>
|
||||
class unsigned_integer
|
||||
{
|
||||
private:
|
||||
static_assert (std::is_integral<UInt>::value &&
|
||||
std::is_unsigned <UInt>::value,
|
||||
"UInt must be an unsigned integral type");
|
||||
static_assert(
|
||||
std::is_integral<UInt>::value && std::is_unsigned<UInt>::value,
|
||||
"UInt must be an unsigned integral type");
|
||||
|
||||
static_assert (Bits%(8*sizeof(UInt))==0,
|
||||
static_assert(
|
||||
Bits % (8 * sizeof(UInt)) == 0,
|
||||
"Bits must be a multiple of 8*sizeof(UInt)");
|
||||
|
||||
static_assert (Bits >= (8*sizeof(UInt)),
|
||||
static_assert(
|
||||
Bits >= (8 * sizeof(UInt)),
|
||||
"Bits must be at least 8*sizeof(UInt)");
|
||||
|
||||
static std::size_t const size = Bits/(8*sizeof(UInt));
|
||||
static std::size_t const size = Bits / (8 * sizeof(UInt));
|
||||
|
||||
std::array <UInt, size> m_vec;
|
||||
std::array<UInt, size> m_vec;
|
||||
|
||||
public:
|
||||
using value_type = UInt;
|
||||
@@ -122,13 +122,12 @@ public:
|
||||
static std::size_t const bytes = bits / 8;
|
||||
|
||||
template <class Int>
|
||||
static
|
||||
unsigned_integer
|
||||
from_number (Int v)
|
||||
static unsigned_integer
|
||||
from_number(Int v)
|
||||
{
|
||||
unsigned_integer result;
|
||||
for (std::size_t i (1); i < size; ++i)
|
||||
result.m_vec [i] = 0;
|
||||
for (std::size_t i(1); i < size; ++i)
|
||||
result.m_vec[i] = 0;
|
||||
result.m_vec[0] = v;
|
||||
return result;
|
||||
}
|
||||
@@ -146,50 +145,44 @@ public:
|
||||
}
|
||||
|
||||
template <class Hasher>
|
||||
friend void hash_append(Hasher& h, unsigned_integer const& a) noexcept
|
||||
friend void
|
||||
hash_append(Hasher& h, unsigned_integer const& a) noexcept
|
||||
{
|
||||
using beast::hash_append;
|
||||
hash_append (h, a.m_vec);
|
||||
hash_append(h, a.m_vec);
|
||||
}
|
||||
|
||||
friend
|
||||
std::ostream&
|
||||
operator<< (std::ostream& s, unsigned_integer const& v)
|
||||
friend std::ostream&
|
||||
operator<<(std::ostream& s, unsigned_integer const& v)
|
||||
{
|
||||
for (std::size_t i (0); i < size; ++i)
|
||||
s <<
|
||||
std::hex <<
|
||||
std::setfill ('0') <<
|
||||
std::setw (2*sizeof(UInt)) <<
|
||||
v.m_vec[i]
|
||||
;
|
||||
for (std::size_t i(0); i < size; ++i)
|
||||
s << std::hex << std::setfill('0') << std::setw(2 * sizeof(UInt))
|
||||
<< v.m_vec[i];
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
using sha256_t = unsigned_integer <256, std::size_t>;
|
||||
using sha256_t = unsigned_integer<256, std::size_t>;
|
||||
|
||||
#ifndef __INTELLISENSE__
|
||||
static_assert (sha256_t::bits == 256,
|
||||
"sha256_t must have 256 bits");
|
||||
static_assert(sha256_t::bits == 256, "sha256_t must have 256 bits");
|
||||
#endif
|
||||
|
||||
} // ripple
|
||||
} // namespace ripple
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ripple {
|
||||
|
||||
class hardened_hash_test
|
||||
: public beast::unit_test::suite
|
||||
class hardened_hash_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
template <class T>
|
||||
void
|
||||
check ()
|
||||
check()
|
||||
{
|
||||
T t{};
|
||||
hardened_hash <>() (t);
|
||||
hardened_hash<>()(t);
|
||||
pass();
|
||||
}
|
||||
|
||||
@@ -197,39 +190,39 @@ public:
|
||||
void
|
||||
check_user_type()
|
||||
{
|
||||
check <U <bool>> ();
|
||||
check <U <char>> ();
|
||||
check <U <signed char>> ();
|
||||
check <U <unsigned char>> ();
|
||||
check<U<bool>>();
|
||||
check<U<char>>();
|
||||
check<U<signed char>>();
|
||||
check<U<unsigned char>>();
|
||||
// These cause trouble for boost
|
||||
//check <U <char16_t>> ();
|
||||
//check <U <char32_t>> ();
|
||||
check <U <wchar_t>> ();
|
||||
check <U <short>> ();
|
||||
check <U <unsigned short>> ();
|
||||
check <U <int>> ();
|
||||
check <U <unsigned int>> ();
|
||||
check <U <long>> ();
|
||||
check <U <long long>> ();
|
||||
check <U <unsigned long>> ();
|
||||
check <U <unsigned long long>> ();
|
||||
check <U <float>> ();
|
||||
check <U <double>> ();
|
||||
check <U <long double>> ();
|
||||
// check <U <char16_t>> ();
|
||||
// check <U <char32_t>> ();
|
||||
check<U<wchar_t>>();
|
||||
check<U<short>>();
|
||||
check<U<unsigned short>>();
|
||||
check<U<int>>();
|
||||
check<U<unsigned int>>();
|
||||
check<U<long>>();
|
||||
check<U<long long>>();
|
||||
check<U<unsigned long>>();
|
||||
check<U<unsigned long long>>();
|
||||
check<U<float>>();
|
||||
check<U<double>>();
|
||||
check<U<long double>>();
|
||||
}
|
||||
|
||||
template <template <class T> class C >
|
||||
template <template <class T> class C>
|
||||
void
|
||||
check_container()
|
||||
{
|
||||
{
|
||||
C <detail::test_user_type_member <std::string>> c;
|
||||
C<detail::test_user_type_member<std::string>> c;
|
||||
}
|
||||
|
||||
pass();
|
||||
|
||||
{
|
||||
C <detail::test_user_type_free <std::string>> c;
|
||||
C<detail::test_user_type_free<std::string>> c;
|
||||
}
|
||||
|
||||
pass();
|
||||
@@ -238,29 +231,29 @@ public:
|
||||
void
|
||||
test_user_types()
|
||||
{
|
||||
testcase ("user types");
|
||||
check_user_type <detail::test_user_type_member> ();
|
||||
check_user_type <detail::test_user_type_free> ();
|
||||
testcase("user types");
|
||||
check_user_type<detail::test_user_type_member>();
|
||||
check_user_type<detail::test_user_type_free>();
|
||||
}
|
||||
|
||||
void
|
||||
test_containers()
|
||||
{
|
||||
testcase ("containers");
|
||||
check_container <detail::test_hardened_unordered_set>();
|
||||
check_container <detail::test_hardened_unordered_map>();
|
||||
check_container <detail::test_hardened_unordered_multiset>();
|
||||
check_container <detail::test_hardened_unordered_multimap>();
|
||||
testcase("containers");
|
||||
check_container<detail::test_hardened_unordered_set>();
|
||||
check_container<detail::test_hardened_unordered_map>();
|
||||
check_container<detail::test_hardened_unordered_multiset>();
|
||||
check_container<detail::test_hardened_unordered_multimap>();
|
||||
}
|
||||
|
||||
void
|
||||
run () override
|
||||
run() override
|
||||
{
|
||||
test_user_types();
|
||||
test_containers();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(hardened_hash,basics,ripple);
|
||||
BEAST_DEFINE_TESTSUITE(hardened_hash, basics, ripple);
|
||||
|
||||
} // ripple
|
||||
} // namespace ripple
|
||||
|
||||
@@ -25,7 +25,8 @@ namespace test {
|
||||
|
||||
struct mulDiv_test : beast::unit_test::suite
|
||||
{
|
||||
void run() override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
const auto max = std::numeric_limits<std::uint64_t>::max();
|
||||
const std::uint64_t max32 = std::numeric_limits<std::uint32_t>::max();
|
||||
|
||||
@@ -25,90 +25,113 @@
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
|
||||
class tagged_integer_test
|
||||
: public beast::unit_test::suite
|
||||
class tagged_integer_test : public beast::unit_test::suite
|
||||
{
|
||||
private:
|
||||
struct Tag1 { };
|
||||
struct Tag2 { };
|
||||
struct Tag1
|
||||
{
|
||||
};
|
||||
struct Tag2
|
||||
{
|
||||
};
|
||||
|
||||
// Static checks that types are not interoperable
|
||||
|
||||
using TagUInt1 = tagged_integer <std::uint32_t, Tag1>;
|
||||
using TagUInt2 = tagged_integer <std::uint32_t, Tag2>;
|
||||
using TagUInt3 = tagged_integer <std::uint64_t, Tag1>;
|
||||
using TagUInt1 = tagged_integer<std::uint32_t, Tag1>;
|
||||
using TagUInt2 = tagged_integer<std::uint32_t, Tag2>;
|
||||
using TagUInt3 = tagged_integer<std::uint64_t, Tag1>;
|
||||
|
||||
// Check construction of tagged_integers
|
||||
static_assert (std::is_constructible<TagUInt1, std::uint32_t>::value,
|
||||
static_assert(
|
||||
std::is_constructible<TagUInt1, std::uint32_t>::value,
|
||||
"TagUInt1 should be constructible using a std::uint32_t");
|
||||
|
||||
static_assert (!std::is_constructible<TagUInt1, std::uint64_t>::value,
|
||||
static_assert(
|
||||
!std::is_constructible<TagUInt1, std::uint64_t>::value,
|
||||
"TagUInt1 should not be constructible using a std::uint64_t");
|
||||
|
||||
static_assert (std::is_constructible<TagUInt3, std::uint32_t>::value,
|
||||
static_assert(
|
||||
std::is_constructible<TagUInt3, std::uint32_t>::value,
|
||||
"TagUInt3 should be constructible using a std::uint32_t");
|
||||
|
||||
static_assert (std::is_constructible<TagUInt3, std::uint64_t>::value,
|
||||
static_assert(
|
||||
std::is_constructible<TagUInt3, std::uint64_t>::value,
|
||||
"TagUInt3 should be constructible using a std::uint64_t");
|
||||
|
||||
// Check assignment of tagged_integers
|
||||
static_assert (!std::is_assignable<TagUInt1, std::uint32_t>::value,
|
||||
static_assert(
|
||||
!std::is_assignable<TagUInt1, std::uint32_t>::value,
|
||||
"TagUInt1 should not be assignable with a std::uint32_t");
|
||||
|
||||
static_assert (!std::is_assignable<TagUInt1, std::uint64_t>::value,
|
||||
static_assert(
|
||||
!std::is_assignable<TagUInt1, std::uint64_t>::value,
|
||||
"TagUInt1 should not be assignable with a std::uint64_t");
|
||||
|
||||
static_assert (!std::is_assignable<TagUInt3, std::uint32_t>::value,
|
||||
static_assert(
|
||||
!std::is_assignable<TagUInt3, std::uint32_t>::value,
|
||||
"TagUInt3 should not be assignable with a std::uint32_t");
|
||||
|
||||
static_assert (!std::is_assignable<TagUInt3, std::uint64_t>::value,
|
||||
static_assert(
|
||||
!std::is_assignable<TagUInt3, std::uint64_t>::value,
|
||||
"TagUInt3 should not be assignable with a std::uint64_t");
|
||||
|
||||
static_assert (std::is_assignable<TagUInt1, TagUInt1>::value,
|
||||
static_assert(
|
||||
std::is_assignable<TagUInt1, TagUInt1>::value,
|
||||
"TagUInt1 should be assignable with a TagUInt1");
|
||||
|
||||
static_assert (!std::is_assignable<TagUInt1, TagUInt2>::value,
|
||||
static_assert(
|
||||
!std::is_assignable<TagUInt1, TagUInt2>::value,
|
||||
"TagUInt1 should not be assignable with a TagUInt2");
|
||||
|
||||
static_assert (std::is_assignable<TagUInt3, TagUInt3>::value,
|
||||
static_assert(
|
||||
std::is_assignable<TagUInt3, TagUInt3>::value,
|
||||
"TagUInt3 should be assignable with a TagUInt1");
|
||||
|
||||
static_assert (!std::is_assignable<TagUInt1, TagUInt3>::value,
|
||||
static_assert(
|
||||
!std::is_assignable<TagUInt1, TagUInt3>::value,
|
||||
"TagUInt1 should not be assignable with a TagUInt3");
|
||||
|
||||
static_assert (!std::is_assignable<TagUInt3, TagUInt1>::value,
|
||||
static_assert(
|
||||
!std::is_assignable<TagUInt3, TagUInt1>::value,
|
||||
"TagUInt3 should not be assignable with a TagUInt1");
|
||||
|
||||
// Check convertibility of tagged_integers
|
||||
static_assert (!std::is_convertible<std::uint32_t, TagUInt1>::value,
|
||||
static_assert(
|
||||
!std::is_convertible<std::uint32_t, TagUInt1>::value,
|
||||
"std::uint32_t should not be convertible to a TagUInt1");
|
||||
|
||||
static_assert (!std::is_convertible<std::uint32_t, TagUInt3>::value,
|
||||
static_assert(
|
||||
!std::is_convertible<std::uint32_t, TagUInt3>::value,
|
||||
"std::uint32_t should not be convertible to a TagUInt3");
|
||||
|
||||
static_assert (!std::is_convertible<std::uint64_t, TagUInt3>::value,
|
||||
static_assert(
|
||||
!std::is_convertible<std::uint64_t, TagUInt3>::value,
|
||||
"std::uint64_t should not be convertible to a TagUInt3");
|
||||
|
||||
static_assert (!std::is_convertible<std::uint64_t, TagUInt2>::value,
|
||||
static_assert(
|
||||
!std::is_convertible<std::uint64_t, TagUInt2>::value,
|
||||
"std::uint64_t should not be convertible to a TagUInt2");
|
||||
|
||||
static_assert (!std::is_convertible<TagUInt1, TagUInt2>::value,
|
||||
static_assert(
|
||||
!std::is_convertible<TagUInt1, TagUInt2>::value,
|
||||
"TagUInt1 should not be convertible to TagUInt2");
|
||||
|
||||
static_assert (!std::is_convertible<TagUInt1, TagUInt3>::value,
|
||||
static_assert(
|
||||
!std::is_convertible<TagUInt1, TagUInt3>::value,
|
||||
"TagUInt1 should not be convertible to TagUInt3");
|
||||
|
||||
static_assert (!std::is_convertible<TagUInt2, TagUInt3>::value,
|
||||
static_assert(
|
||||
!std::is_convertible<TagUInt2, TagUInt3>::value,
|
||||
"TagUInt2 should not be convertible to a TagUInt3");
|
||||
|
||||
|
||||
public:
|
||||
void run () override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
using TagInt = tagged_integer<std::int32_t, Tag1>;
|
||||
|
||||
{
|
||||
testcase ("Comparison Operators");
|
||||
testcase("Comparison Operators");
|
||||
|
||||
TagInt const zero(0);
|
||||
TagInt const one(1);
|
||||
@@ -135,7 +158,7 @@ public:
|
||||
}
|
||||
|
||||
{
|
||||
testcase ("Increment/Decrement Operators");
|
||||
testcase("Increment/Decrement Operators");
|
||||
TagInt const zero(0);
|
||||
TagInt const one(1);
|
||||
TagInt a{0};
|
||||
@@ -149,19 +172,18 @@ public:
|
||||
BEAST_EXPECT(a == zero);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
testcase ("Arithmetic Operators");
|
||||
testcase("Arithmetic Operators");
|
||||
TagInt a{-2};
|
||||
BEAST_EXPECT(+a == TagInt{-2});
|
||||
BEAST_EXPECT(-a == TagInt{2});
|
||||
BEAST_EXPECT(TagInt{-3} + TagInt{4} == TagInt{1});
|
||||
BEAST_EXPECT(TagInt{-3} - TagInt{4} == TagInt{-7});
|
||||
BEAST_EXPECT(TagInt{-3} * TagInt{4} == TagInt{-12});
|
||||
BEAST_EXPECT(TagInt{8}/TagInt{4} == TagInt{2});
|
||||
BEAST_EXPECT(TagInt{7} %TagInt{4} == TagInt{3});
|
||||
BEAST_EXPECT(TagInt{8} / TagInt{4} == TagInt{2});
|
||||
BEAST_EXPECT(TagInt{7} % TagInt{4} == TagInt{3});
|
||||
|
||||
BEAST_EXPECT(~TagInt{8} == TagInt{~TagInt::value_type{8}});
|
||||
BEAST_EXPECT(~TagInt{8} == TagInt{~TagInt::value_type{8}});
|
||||
BEAST_EXPECT((TagInt{6} & TagInt{3}) == TagInt{2});
|
||||
BEAST_EXPECT((TagInt{6} | TagInt{3}) == TagInt{7});
|
||||
BEAST_EXPECT((TagInt{6} ^ TagInt{3}) == TagInt{5});
|
||||
@@ -170,7 +192,7 @@ public:
|
||||
BEAST_EXPECT((TagInt{16} >> TagInt{2}) == TagInt{4});
|
||||
}
|
||||
{
|
||||
testcase ("Assignment Operators");
|
||||
testcase("Assignment Operators");
|
||||
TagInt a{-2};
|
||||
TagInt b{0};
|
||||
b = a;
|
||||
@@ -226,13 +248,10 @@ public:
|
||||
a >>= TagInt{2};
|
||||
BEAST_EXPECT(a == TagInt{4});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(tagged_integer,ripple_basics,ripple);
|
||||
BEAST_DEFINE_TESTSUITE(tagged_integer, ripple_basics, ripple);
|
||||
|
||||
} // test
|
||||
} // ripple
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
Reference in New Issue
Block a user