Merge branch 'develop' into ximinez/fix-getledger

This commit is contained in:
Ed Hennis
2026-01-15 12:05:51 -04:00
committed by GitHub
23 changed files with 785 additions and 781 deletions

View File

@@ -270,6 +270,7 @@ words:
- xbridge
- xchain
- ximinez
- EXPECT_STREQ
- XMACRO
- xrpkuwait
- xrpl

View File

@@ -17,9 +17,9 @@
"libbacktrace/cci.20210118#a7691bfccd8caaf66309df196790a5a1%1765842973.03",
"libarchive/3.8.1#ffee18995c706e02bf96e7a2f7042e0d%1765850144.736",
"jemalloc/5.3.0#e951da9cf599e956cebc117880d2d9f8%1729241615.244",
"gtest/1.17.0#5224b3b3ff3b4ce1133cbdd27d53ee7d%1768312129.152",
"grpc/1.72.0#f244a57bff01e708c55a1100b12e1589%1765850193.734",
"ed25519/2015.03#ae761bdc52730a843f0809bdf6c1b1f6%1765850143.772",
"doctest/2.4.12#eb9fb352fb2fdfc8abb17ec270945165%1765850143.95",
"date/3.0.4#862e11e80030356b53c2c38599ceb32b%1765850143.772",
"c-ares/1.34.5#5581c2b62a608b40bb85d965ab3ec7c8%1765850144.336",
"bzip2/1.0.8#c470882369c2d95c5c77e970c0c7e321%1765850143.837",

View File

@@ -39,7 +39,7 @@ class Xrpl(ConanFile):
]
test_requires = [
"doctest/2.4.12",
"gtest/1.17.0",
]
tool_requires = [

View File

@@ -427,6 +427,7 @@ class Batch_test : public beast::unit_test::suite
auto const batchFee = batch::calcBatchFee(env, 0, 2);
auto tx1 = batch::inner(pay(alice, bob, XRP(1)), seq + 1);
tx1[jss::Fee] = "1.5";
env.set_parse_failure_expected(true);
try
{
env(batch::outer(alice, seq, batchFee, tfAllOrNothing),
@@ -438,6 +439,7 @@ class Batch_test : public beast::unit_test::suite
{
BEAST_EXPECT(true);
}
env.set_parse_failure_expected(false);
}
// temSEQ_AND_TICKET: Batch: inner txn cannot have both Sequence

View File

@@ -2076,7 +2076,7 @@ class Vault_test : public beast::unit_test::suite
PrettyAsset const& asset,
Vault& vault,
MPTTester& mptt) {
testcase("MPT failed reserve to re-create MPToken");
testcase("MPT fail reserve to re-create MPToken");
auto [tx, keylet] =
vault.create({.owner = owner, .asset = asset});

View File

@@ -1,5 +1,5 @@
# Unit tests
This directory contains unit tests for the project. The difference from existing `src/test` folder
is that we switch to 3rd party testing framework (doctest). We intend to gradually move existing tests
from our own framework to doctest and such tests will be moved to this new folder.
is that we switch to 3rd party testing framework (`gtest`). We intend to gradually move existing tests
from our own framework to `gtest` and such tests will be moved to this new folder.

View File

@@ -1,14 +1,14 @@
include(XrplAddTest)
# Test requirements.
find_package(doctest REQUIRED)
find_package(GTest REQUIRED)
# Custom target for all tests defined in this file
add_custom_target(xrpl.tests)
# Common library dependencies for the rest of the tests.
add_library(xrpl.imports.test INTERFACE)
target_link_libraries(xrpl.imports.test INTERFACE doctest::doctest xrpl.libxrpl)
target_link_libraries(xrpl.imports.test INTERFACE gtest::gtest xrpl.libxrpl)
# One test for each module.
xrpl_add_test(basics)

View File

@@ -1,15 +1,13 @@
#include <xrpl/basics/RangeSet.h>
#include <doctest/doctest.h>
#include <gtest/gtest.h>
#include <cstdint>
#include <optional>
using namespace xrpl;
TEST_SUITE_BEGIN("RangeSet");
TEST_CASE("prevMissing")
TEST(RangeSet, prevMissing)
{
// Set will include:
// [ 0, 5]
@@ -31,80 +29,78 @@ TEST_CASE("prevMissing")
expected = ((i % 10) > 6) ? (i - 1) : oneBelowRange;
}
CHECK(prevMissing(set, i) == expected);
EXPECT_EQ(prevMissing(set, i), expected);
}
}
TEST_CASE("toString")
TEST(RangeSet, toString)
{
RangeSet<std::uint32_t> set;
CHECK(to_string(set) == "empty");
EXPECT_EQ(to_string(set), "empty");
set.insert(1);
CHECK(to_string(set) == "1");
EXPECT_EQ(to_string(set), "1");
set.insert(range(4u, 6u));
CHECK(to_string(set) == "1,4-6");
EXPECT_EQ(to_string(set), "1,4-6");
set.insert(2);
CHECK(to_string(set) == "1-2,4-6");
EXPECT_EQ(to_string(set), "1-2,4-6");
set.erase(range(4u, 5u));
CHECK(to_string(set) == "1-2,6");
EXPECT_EQ(to_string(set), "1-2,6");
}
TEST_CASE("fromString")
TEST(RangeSet, fromString)
{
RangeSet<std::uint32_t> set;
CHECK(!from_string(set, ""));
CHECK(boost::icl::length(set) == 0);
EXPECT_FALSE(from_string(set, ""));
EXPECT_EQ(boost::icl::length(set), 0);
CHECK(!from_string(set, "#"));
CHECK(boost::icl::length(set) == 0);
EXPECT_FALSE(from_string(set, "#"));
EXPECT_EQ(boost::icl::length(set), 0);
CHECK(!from_string(set, ","));
CHECK(boost::icl::length(set) == 0);
EXPECT_FALSE(from_string(set, ","));
EXPECT_EQ(boost::icl::length(set), 0);
CHECK(!from_string(set, ",-"));
CHECK(boost::icl::length(set) == 0);
EXPECT_FALSE(from_string(set, ",-"));
EXPECT_EQ(boost::icl::length(set), 0);
CHECK(!from_string(set, "1,,2"));
CHECK(boost::icl::length(set) == 0);
EXPECT_FALSE(from_string(set, "1,,2"));
EXPECT_EQ(boost::icl::length(set), 0);
CHECK(from_string(set, "1"));
CHECK(boost::icl::length(set) == 1);
CHECK(boost::icl::first(set) == 1);
EXPECT_TRUE(from_string(set, "1"));
EXPECT_EQ(boost::icl::length(set), 1);
EXPECT_EQ(boost::icl::first(set), 1);
CHECK(from_string(set, "1,1"));
CHECK(boost::icl::length(set) == 1);
CHECK(boost::icl::first(set) == 1);
EXPECT_TRUE(from_string(set, "1,1"));
EXPECT_EQ(boost::icl::length(set), 1);
EXPECT_EQ(boost::icl::first(set), 1);
CHECK(from_string(set, "1-1"));
CHECK(boost::icl::length(set) == 1);
CHECK(boost::icl::first(set) == 1);
EXPECT_TRUE(from_string(set, "1-1"));
EXPECT_EQ(boost::icl::length(set), 1);
EXPECT_EQ(boost::icl::first(set), 1);
CHECK(from_string(set, "1,4-6"));
CHECK(boost::icl::length(set) == 4);
CHECK(boost::icl::first(set) == 1);
CHECK(!boost::icl::contains(set, 2));
CHECK(!boost::icl::contains(set, 3));
CHECK(boost::icl::contains(set, 4));
CHECK(boost::icl::contains(set, 5));
CHECK(boost::icl::last(set) == 6);
EXPECT_TRUE(from_string(set, "1,4-6"));
EXPECT_EQ(boost::icl::length(set), 4);
EXPECT_EQ(boost::icl::first(set), 1);
EXPECT_FALSE(boost::icl::contains(set, 2));
EXPECT_FALSE(boost::icl::contains(set, 3));
EXPECT_TRUE(boost::icl::contains(set, 4));
EXPECT_TRUE(boost::icl::contains(set, 5));
EXPECT_EQ(boost::icl::last(set), 6);
CHECK(from_string(set, "1-2,4-6"));
CHECK(boost::icl::length(set) == 5);
CHECK(boost::icl::first(set) == 1);
CHECK(boost::icl::contains(set, 2));
CHECK(boost::icl::contains(set, 4));
CHECK(boost::icl::last(set) == 6);
EXPECT_TRUE(from_string(set, "1-2,4-6"));
EXPECT_EQ(boost::icl::length(set), 5);
EXPECT_EQ(boost::icl::first(set), 1);
EXPECT_TRUE(boost::icl::contains(set, 2));
EXPECT_TRUE(boost::icl::contains(set, 4));
EXPECT_EQ(boost::icl::last(set), 6);
CHECK(from_string(set, "1-2,6"));
CHECK(boost::icl::length(set) == 3);
CHECK(boost::icl::first(set) == 1);
CHECK(boost::icl::contains(set, 2));
CHECK(boost::icl::last(set) == 6);
EXPECT_TRUE(from_string(set, "1-2,6"));
EXPECT_EQ(boost::icl::length(set), 3);
EXPECT_EQ(boost::icl::first(set), 1);
EXPECT_TRUE(boost::icl::contains(set, 2));
EXPECT_EQ(boost::icl::last(set), 6);
}
TEST_SUITE_END();

View File

@@ -1,6 +1,6 @@
#include <xrpl/basics/Slice.h>
#include <doctest/doctest.h>
#include <gtest/gtest.h>
#include <array>
#include <cstdint>
@@ -12,37 +12,35 @@ static std::uint8_t const data[] = {
0x18, 0xb4, 0x70, 0xcb, 0xf5, 0xac, 0x2d, 0x89, 0x4d, 0x19, 0x9c,
0xf0, 0x2c, 0x15, 0xd1, 0xf9, 0x9b, 0x66, 0xd2, 0x30, 0xd3};
TEST_SUITE_BEGIN("Slice");
TEST_CASE("equality & inequality")
TEST(Slice, equality_and_inequality)
{
Slice const s0{};
CHECK(s0.size() == 0);
CHECK(s0.data() == nullptr);
CHECK(s0 == s0);
EXPECT_EQ(s0.size(), 0);
EXPECT_EQ(s0.data(), nullptr);
EXPECT_EQ(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};
CHECK(s1.size() == i);
CHECK(s1.data() != nullptr);
EXPECT_EQ(s1.size(), i);
EXPECT_NE(s1.data(), nullptr);
if (i == 0)
CHECK(s1 == s0);
EXPECT_EQ(s1, s0);
else
CHECK(s1 != s0);
EXPECT_NE(s1, s0);
for (std::size_t j = 0; j != sizeof(data); ++j)
{
Slice const s2{data, j};
if (i == j)
CHECK(s1 == s2);
EXPECT_EQ(s1, s2);
else
CHECK(s1 != s2);
EXPECT_NE(s1, s2);
}
}
@@ -53,22 +51,22 @@ TEST_CASE("equality & inequality")
for (std::size_t i = 0; i != sizeof(data); ++i)
a[i] = b[i] = data[i];
CHECK(makeSlice(a) == makeSlice(b));
EXPECT_EQ(makeSlice(a), makeSlice(b));
b[7]++;
CHECK(makeSlice(a) != makeSlice(b));
EXPECT_NE(makeSlice(a), makeSlice(b));
a[7]++;
CHECK(makeSlice(a) == makeSlice(b));
EXPECT_EQ(makeSlice(a), makeSlice(b));
}
TEST_CASE("indexing")
TEST(Slice, indexing)
{
Slice const s{data, sizeof(data)};
for (std::size_t i = 0; i != sizeof(data); ++i)
CHECK(s[i] == data[i]);
EXPECT_EQ(s[i], data[i]);
}
TEST_CASE("advancing")
TEST(Slice, advancing)
{
for (std::size_t i = 0; i < sizeof(data); ++i)
{
@@ -77,10 +75,8 @@ TEST_CASE("advancing")
Slice s(data + i, sizeof(data) - i);
s += j;
CHECK(s.data() == data + i + j);
CHECK(s.size() == sizeof(data) - i - j);
EXPECT_EQ(s.data(), data + i + j);
EXPECT_EQ(s.size(), sizeof(data) - i - j);
}
}
}
TEST_SUITE_END();

View File

@@ -1,6 +1,6 @@
#include <xrpl/basics/base64.h>
#include <doctest/doctest.h>
#include <gtest/gtest.h>
#include <string>
@@ -10,11 +10,11 @@ static void
check(std::string const& in, std::string const& out)
{
auto const encoded = base64_encode(in);
CHECK(encoded == out);
CHECK(base64_decode(encoded) == in);
EXPECT_EQ(encoded, out);
EXPECT_EQ(base64_decode(encoded), in);
}
TEST_CASE("base64")
TEST(base64, base64)
{
// cspell: disable
check("", "");
@@ -46,5 +46,5 @@ TEST_CASE("base64")
std::string const notBase64 = "not_base64!!";
std::string const truncated = "not";
CHECK(base64_decode(notBase64) == base64_decode(truncated));
EXPECT_EQ(base64_decode(notBase64), base64_decode(truncated));
}

View File

@@ -1,13 +1,13 @@
#include <xrpl/basics/contract.h>
#include <doctest/doctest.h>
#include <gtest/gtest.h>
#include <stdexcept>
#include <string>
using namespace xrpl;
TEST_CASE("contract")
TEST(contract, contract)
{
try
{
@@ -15,7 +15,7 @@ TEST_CASE("contract")
}
catch (std::runtime_error const& e1)
{
CHECK(std::string(e1.what()) == "Throw test");
EXPECT_STREQ(e1.what(), "Throw test");
try
{
@@ -23,15 +23,15 @@ TEST_CASE("contract")
}
catch (std::runtime_error const& e2)
{
CHECK(std::string(e2.what()) == "Throw test");
EXPECT_STREQ(e2.what(), "Throw test");
}
catch (...)
{
CHECK(false);
FAIL() << "std::runtime_error should have been re-caught";
}
}
catch (...)
{
CHECK(false);
FAIL() << "std::runtime_error should have been caught the first time";
}
}

View File

@@ -1,2 +1,8 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>
#include <gtest/gtest.h>
int
main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@@ -1,45 +1,45 @@
#include <xrpl/basics/mulDiv.h>
#include <doctest/doctest.h>
#include <gtest/gtest.h>
#include <cstdint>
#include <limits>
using namespace xrpl;
TEST_CASE("mulDiv")
TEST(mulDiv, mulDiv)
{
auto const max = std::numeric_limits<std::uint64_t>::max();
std::uint64_t const max32 = std::numeric_limits<std::uint32_t>::max();
auto result = mulDiv(85, 20, 5);
REQUIRE(result);
CHECK(*result == 340);
ASSERT_TRUE(result.has_value());
EXPECT_EQ(*result, 340);
result = mulDiv(20, 85, 5);
REQUIRE(result);
CHECK(*result == 340);
ASSERT_TRUE(result.has_value());
EXPECT_EQ(*result, 340);
result = mulDiv(0, max - 1, max - 3);
REQUIRE(result);
CHECK(*result == 0);
ASSERT_TRUE(result.has_value());
EXPECT_EQ(*result, 0);
result = mulDiv(max - 1, 0, max - 3);
REQUIRE(result);
CHECK(*result == 0);
ASSERT_TRUE(result.has_value());
EXPECT_EQ(*result, 0);
result = mulDiv(max, 2, max / 2);
REQUIRE(result);
CHECK(*result == 4);
ASSERT_TRUE(result.has_value());
EXPECT_EQ(*result, 4);
result = mulDiv(max, 1000, max / 1000);
REQUIRE(result);
CHECK(*result == 1000000);
ASSERT_TRUE(result.has_value());
EXPECT_EQ(*result, 1000000);
result = mulDiv(max, 1000, max / 1001);
REQUIRE(result);
CHECK(*result == 1001000);
ASSERT_TRUE(result.has_value());
EXPECT_EQ(*result, 1001000);
result = mulDiv(max32 + 1, max32 + 1, 5);
REQUIRE(result);
CHECK(*result == 3689348814741910323);
ASSERT_TRUE(result.has_value());
EXPECT_EQ(*result, 3689348814741910323);
// Overflow
result = mulDiv(max - 1, max - 2, 5);
CHECK(!result);
EXPECT_FALSE(result.has_value());
}

View File

@@ -1,10 +1,10 @@
#include <xrpl/basics/scope.h>
#include <doctest/doctest.h>
#include <gtest/gtest.h>
using namespace xrpl;
TEST_CASE("scope_exit")
TEST(scope, scope_exit)
{
// scope_exit always executes the functor on destruction,
// unless release() is called
@@ -12,23 +12,23 @@ TEST_CASE("scope_exit")
{
scope_exit x{[&i]() { i = 1; }};
}
CHECK(i == 1);
EXPECT_EQ(i, 1);
{
scope_exit x{[&i]() { i = 2; }};
x.release();
}
CHECK(i == 1);
EXPECT_EQ(i, 1);
{
scope_exit x{[&i]() { i += 2; }};
auto x2 = std::move(x);
}
CHECK(i == 3);
EXPECT_EQ(i, 3);
{
scope_exit x{[&i]() { i = 4; }};
x.release();
auto x2 = std::move(x);
}
CHECK(i == 3);
EXPECT_EQ(i, 3);
{
try
{
@@ -39,7 +39,7 @@ TEST_CASE("scope_exit")
{
}
}
CHECK(i == 5);
EXPECT_EQ(i, 5);
{
try
{
@@ -51,10 +51,10 @@ TEST_CASE("scope_exit")
{
}
}
CHECK(i == 5);
EXPECT_EQ(i, 5);
}
TEST_CASE("scope_fail")
TEST(scope, scope_fail)
{
// scope_fail executes the functor on destruction only
// if an exception is unwinding, unless release() is called
@@ -62,23 +62,23 @@ TEST_CASE("scope_fail")
{
scope_fail x{[&i]() { i = 1; }};
}
CHECK(i == 0);
EXPECT_EQ(i, 0);
{
scope_fail x{[&i]() { i = 2; }};
x.release();
}
CHECK(i == 0);
EXPECT_EQ(i, 0);
{
scope_fail x{[&i]() { i = 3; }};
auto x2 = std::move(x);
}
CHECK(i == 0);
EXPECT_EQ(i, 0);
{
scope_fail x{[&i]() { i = 4; }};
x.release();
auto x2 = std::move(x);
}
CHECK(i == 0);
EXPECT_EQ(i, 0);
{
try
{
@@ -89,7 +89,7 @@ TEST_CASE("scope_fail")
{
}
}
CHECK(i == 5);
EXPECT_EQ(i, 5);
{
try
{
@@ -101,10 +101,10 @@ TEST_CASE("scope_fail")
{
}
}
CHECK(i == 5);
EXPECT_EQ(i, 5);
}
TEST_CASE("scope_success")
TEST(scope, scope_success)
{
// scope_success executes the functor on destruction only
// if an exception is not unwinding, unless release() is called
@@ -112,23 +112,23 @@ TEST_CASE("scope_success")
{
scope_success x{[&i]() { i = 1; }};
}
CHECK(i == 1);
EXPECT_EQ(i, 1);
{
scope_success x{[&i]() { i = 2; }};
x.release();
}
CHECK(i == 1);
EXPECT_EQ(i, 1);
{
scope_success x{[&i]() { i += 2; }};
auto x2 = std::move(x);
}
CHECK(i == 3);
EXPECT_EQ(i, 3);
{
scope_success x{[&i]() { i = 4; }};
x.release();
auto x2 = std::move(x);
}
CHECK(i == 3);
EXPECT_EQ(i, 3);
{
try
{
@@ -139,7 +139,7 @@ TEST_CASE("scope_success")
{
}
}
CHECK(i == 3);
EXPECT_EQ(i, 3);
{
try
{
@@ -151,5 +151,5 @@ TEST_CASE("scope_success")
{
}
}
CHECK(i == 3);
EXPECT_EQ(i, 3);
}

View File

@@ -1,6 +1,6 @@
#include <xrpl/basics/tagged_integer.h>
#include <doctest/doctest.h>
#include <gtest/gtest.h>
#include <type_traits>
@@ -102,127 +102,123 @@ static_assert(
!std::is_convertible<TagUInt2, TagUInt3>::value,
"TagUInt2 should not be convertible to a TagUInt3");
TEST_SUITE_BEGIN("tagged_integer");
using TagInt = tagged_integer<std::int32_t, Tag1>;
TEST_CASE("comparison operators")
TEST(tagged_integer, comparison_operators)
{
TagInt const zero(0);
TagInt const one(1);
CHECK(one == one);
CHECK(!(one == zero));
EXPECT_TRUE(one == one);
EXPECT_FALSE(one == zero);
CHECK(one != zero);
CHECK(!(one != one));
EXPECT_TRUE(one != zero);
EXPECT_FALSE(one != one);
CHECK(zero < one);
CHECK(!(one < zero));
EXPECT_TRUE(zero < one);
EXPECT_FALSE(one < zero);
CHECK(one > zero);
CHECK(!(zero > one));
EXPECT_TRUE(one > zero);
EXPECT_FALSE(zero > one);
CHECK(one >= one);
CHECK(one >= zero);
CHECK(!(zero >= one));
EXPECT_TRUE(one >= one);
EXPECT_TRUE(one >= zero);
EXPECT_FALSE(zero >= one);
CHECK(zero <= one);
CHECK(zero <= zero);
CHECK(!(one <= zero));
EXPECT_TRUE(zero <= one);
EXPECT_TRUE(zero <= zero);
EXPECT_FALSE(one <= zero);
}
TEST_CASE("increment / decrement operators")
TEST(tagged_integer, increment_decrement_operators)
{
TagInt const zero(0);
TagInt const one(1);
TagInt a{0};
++a;
CHECK(a == one);
EXPECT_EQ(a, one);
--a;
CHECK(a == zero);
EXPECT_EQ(a, zero);
a++;
CHECK(a == one);
EXPECT_EQ(a, one);
a--;
CHECK(a == zero);
EXPECT_EQ(a, zero);
}
TEST_CASE("arithmetic operators")
TEST(tagged_integer, arithmetic_operators)
{
TagInt a{-2};
CHECK(+a == TagInt{-2});
CHECK(-a == TagInt{2});
CHECK(TagInt{-3} + TagInt{4} == TagInt{1});
CHECK(TagInt{-3} - TagInt{4} == TagInt{-7});
CHECK(TagInt{-3} * TagInt{4} == TagInt{-12});
CHECK(TagInt{8} / TagInt{4} == TagInt{2});
CHECK(TagInt{7} % TagInt{4} == TagInt{3});
EXPECT_EQ(+a, TagInt{-2});
EXPECT_EQ(-a, TagInt{2});
EXPECT_EQ(TagInt{-3} + TagInt{4}, TagInt{1});
EXPECT_EQ(TagInt{-3} - TagInt{4}, TagInt{-7});
EXPECT_EQ(TagInt{-3} * TagInt{4}, TagInt{-12});
EXPECT_EQ(TagInt{8} / TagInt{4}, TagInt{2});
EXPECT_EQ(TagInt{7} % TagInt{4}, TagInt{3});
CHECK(~TagInt{8} == TagInt{~TagInt::value_type{8}});
CHECK((TagInt{6} & TagInt{3}) == TagInt{2});
CHECK((TagInt{6} | TagInt{3}) == TagInt{7});
CHECK((TagInt{6} ^ TagInt{3}) == TagInt{5});
EXPECT_EQ(~TagInt{8}, TagInt{~TagInt::value_type{8}});
EXPECT_EQ((TagInt{6} & TagInt{3}), TagInt{2});
EXPECT_EQ((TagInt{6} | TagInt{3}), TagInt{7});
EXPECT_EQ((TagInt{6} ^ TagInt{3}), TagInt{5});
CHECK((TagInt{4} << TagInt{2}) == TagInt{16});
CHECK((TagInt{16} >> TagInt{2}) == TagInt{4});
EXPECT_EQ((TagInt{4} << TagInt{2}), TagInt{16});
EXPECT_EQ((TagInt{16} >> TagInt{2}), TagInt{4});
}
TEST_CASE("assignment operators")
TEST(tagged_integer, assignment_operators)
{
TagInt a{-2};
TagInt b{0};
b = a;
CHECK(b == TagInt{-2});
EXPECT_EQ(b, TagInt{-2});
// -3 + 4 == 1
a = TagInt{-3};
a += TagInt{4};
CHECK(a == TagInt{1});
EXPECT_EQ(a, TagInt{1});
// -3 - 4 == -7
a = TagInt{-3};
a -= TagInt{4};
CHECK(a == TagInt{-7});
EXPECT_EQ(a, TagInt{-7});
// -3 * 4 == -12
a = TagInt{-3};
a *= TagInt{4};
CHECK(a == TagInt{-12});
EXPECT_EQ(a, TagInt{-12});
// 8/4 == 2
a = TagInt{8};
a /= TagInt{4};
CHECK(a == TagInt{2});
EXPECT_EQ(a, TagInt{2});
// 7 % 4 == 3
a = TagInt{7};
a %= TagInt{4};
CHECK(a == TagInt{3});
EXPECT_EQ(a, TagInt{3});
// 6 & 3 == 2
a = TagInt{6};
a /= TagInt{3};
CHECK(a == TagInt{2});
EXPECT_EQ(a, TagInt{2});
// 6 | 3 == 7
a = TagInt{6};
a |= TagInt{3};
CHECK(a == TagInt{7});
EXPECT_EQ(a, TagInt{7});
// 6 ^ 3 == 5
a = TagInt{6};
a ^= TagInt{3};
CHECK(a == TagInt{5});
EXPECT_EQ(a, TagInt{5});
// 4 << 2 == 16
a = TagInt{4};
a <<= TagInt{2};
CHECK(a == TagInt{16});
EXPECT_EQ(a, TagInt{16});
// 16 >> 2 == 4
a = TagInt{16};
a >>= TagInt{2};
CHECK(a == TagInt{4});
EXPECT_EQ(a, TagInt{4});
}
TEST_SUITE_END();

View File

@@ -1,15 +1,15 @@
#include <xrpl/crypto/csprng.h>
#include <doctest/doctest.h>
#include <gtest/gtest.h>
using namespace xrpl;
TEST_CASE("get values")
TEST(csprng, get_values)
{
auto& engine = crypto_prng();
auto rand_val = engine();
CHECK(rand_val >= engine.min());
CHECK(rand_val <= engine.max());
EXPECT_GE(rand_val, engine.min());
EXPECT_LE(rand_val, engine.max());
uint16_t twoByte{0};
engine(&twoByte, sizeof(uint16_t));
}

View File

@@ -1,2 +1,8 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>
#include <gtest/gtest.h>
int
main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@@ -2,31 +2,29 @@
#include <xrpl/json/json_reader.h>
#include <xrpl/json/json_writer.h>
#include <doctest/doctest.h>
#include <gtest/gtest.h>
#include <string>
using namespace xrpl;
using namespace Json;
TEST_SUITE_BEGIN("JsonOutput");
static void
checkOutput(std::string const& valueDesc)
{
std::string output;
Json::Value value;
REQUIRE(Json::Reader().parse(valueDesc, value));
ASSERT_TRUE(Json::Reader().parse(valueDesc, value));
auto out = stringOutput(output);
outputJson(value, out);
auto expected = Json::FastWriter().write(value);
CHECK(output == expected);
CHECK(output == valueDesc);
CHECK(output == jsonAsString(value));
EXPECT_EQ(output, expected);
EXPECT_EQ(output, valueDesc);
EXPECT_EQ(output, jsonAsString(value));
}
TEST_CASE("output cases")
TEST(JsonOutput, output_cases)
{
checkOutput("{}");
checkOutput("[]");
@@ -36,5 +34,3 @@ TEST_CASE("output cases")
checkOutput("[[]]");
checkOutput(R"({"array":[{"12":23},{},null,false,0.5]})");
}
TEST_SUITE_END();

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
#include <xrpl/json/Writer.h>
#include <doctest/doctest.h>
#include <google/protobuf/stubs/port.h>
#include <gtest/gtest.h>
#include <memory>
#include <string>
@@ -9,14 +9,14 @@
using namespace xrpl;
using namespace Json;
TEST_SUITE_BEGIN("JsonWriter");
struct WriterFixture
class WriterFixture : public ::testing::Test
{
protected:
std::string output;
std::unique_ptr<Writer> writer;
WriterFixture()
void
SetUp() override
{
writer = std::make_unique<Writer>(stringOutput(output));
}
@@ -31,7 +31,7 @@ struct WriterFixture
void
expectOutput(std::string const& expected) const
{
CHECK(output == expected);
EXPECT_EQ(output, expected);
}
void
@@ -42,20 +42,20 @@ struct WriterFixture
}
};
TEST_CASE_FIXTURE(WriterFixture, "trivial")
TEST_F(WriterFixture, trivial)
{
CHECK(output.empty());
EXPECT_TRUE(output.empty());
checkOutputAndReset("");
}
TEST_CASE_FIXTURE(WriterFixture, "near trivial")
TEST_F(WriterFixture, near_trivial)
{
CHECK(output.empty());
EXPECT_TRUE(output.empty());
writer->output(0);
checkOutputAndReset("0");
}
TEST_CASE_FIXTURE(WriterFixture, "primitives")
TEST_F(WriterFixture, primitives)
{
writer->output(true);
checkOutputAndReset("true");
@@ -79,7 +79,7 @@ TEST_CASE_FIXTURE(WriterFixture, "primitives")
checkOutputAndReset("null");
}
TEST_CASE_FIXTURE(WriterFixture, "empty")
TEST_F(WriterFixture, empty)
{
writer->startRoot(Writer::array);
writer->finish();
@@ -90,7 +90,7 @@ TEST_CASE_FIXTURE(WriterFixture, "empty")
checkOutputAndReset("{}");
}
TEST_CASE_FIXTURE(WriterFixture, "escaping")
TEST_F(WriterFixture, escaping)
{
writer->output("\\");
checkOutputAndReset(R"("\\")");
@@ -108,7 +108,7 @@ TEST_CASE_FIXTURE(WriterFixture, "escaping")
checkOutputAndReset(R"("\b\f\n\r\t")");
}
TEST_CASE_FIXTURE(WriterFixture, "array")
TEST_F(WriterFixture, array)
{
writer->startRoot(Writer::array);
writer->append(12);
@@ -116,7 +116,7 @@ TEST_CASE_FIXTURE(WriterFixture, "array")
checkOutputAndReset("[12]");
}
TEST_CASE_FIXTURE(WriterFixture, "long array")
TEST_F(WriterFixture, long_array)
{
writer->startRoot(Writer::array);
writer->append(12);
@@ -126,7 +126,7 @@ TEST_CASE_FIXTURE(WriterFixture, "long array")
checkOutputAndReset(R"([12,true,"hello"])");
}
TEST_CASE_FIXTURE(WriterFixture, "embedded array simple")
TEST_F(WriterFixture, embedded_array_simple)
{
writer->startRoot(Writer::array);
writer->startAppend(Writer::array);
@@ -135,7 +135,7 @@ TEST_CASE_FIXTURE(WriterFixture, "embedded array simple")
checkOutputAndReset("[[]]");
}
TEST_CASE_FIXTURE(WriterFixture, "object")
TEST_F(WriterFixture, object)
{
writer->startRoot(Writer::object);
writer->set("hello", "world");
@@ -143,7 +143,7 @@ TEST_CASE_FIXTURE(WriterFixture, "object")
checkOutputAndReset(R"({"hello":"world"})");
}
TEST_CASE_FIXTURE(WriterFixture, "complex object")
TEST_F(WriterFixture, complex_object)
{
writer->startRoot(Writer::object);
writer->set("hello", "world");
@@ -160,7 +160,7 @@ TEST_CASE_FIXTURE(WriterFixture, "complex object")
R"({"hello":"world","array":[true,12,[{"goodbye":"cruel world.","subarray":[23.5]}]]})");
}
TEST_CASE_FIXTURE(WriterFixture, "json value")
TEST_F(WriterFixture, json_value)
{
Json::Value value(Json::objectValue);
value["foo"] = 23;
@@ -169,5 +169,3 @@ TEST_CASE_FIXTURE(WriterFixture, "json value")
writer->finish();
checkOutputAndReset(R"({"hello":{"foo":23}})");
}
TEST_SUITE_END();

View File

@@ -1,2 +1,8 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>
#include <gtest/gtest.h>
int
main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@@ -7,7 +7,7 @@
#include <boost/beast/http.hpp>
#include <boost/beast/version.hpp>
#include <doctest/doctest.h>
#include <gtest/gtest.h>
#include <atomic>
#include <map>
@@ -217,7 +217,7 @@ runHTTPTest(
} // anonymous namespace
TEST_CASE("HTTPClient case insensitive Content-Length")
TEST(HTTPClient, case_insensitive_content_length)
{
// Test different cases of Content-Length header
std::vector<std::string> header_cases = {
@@ -249,14 +249,14 @@ TEST_CASE("HTTPClient case insensitive Content-Length")
result_error);
// Verify results
CHECK(test_completed);
CHECK(!result_error);
CHECK(result_status == 200);
CHECK(result_data == test_body);
EXPECT_TRUE(test_completed);
EXPECT_FALSE(result_error);
EXPECT_EQ(result_status, 200);
EXPECT_EQ(result_data, test_body);
}
}
TEST_CASE("HTTPClient basic HTTP request")
TEST(HTTPClient, basic_http_request)
{
TestHTTPServer server;
std::string test_body = "Test response body";
@@ -271,13 +271,13 @@ TEST_CASE("HTTPClient basic HTTP request")
bool test_completed = runHTTPTest(
server, "/basic", completed, result_status, result_data, result_error);
CHECK(test_completed);
CHECK(!result_error);
CHECK(result_status == 200);
CHECK(result_data == test_body);
EXPECT_TRUE(test_completed);
EXPECT_FALSE(result_error);
EXPECT_EQ(result_status, 200);
EXPECT_EQ(result_data, test_body);
}
TEST_CASE("HTTPClient empty response")
TEST(HTTPClient, empty_response)
{
TestHTTPServer server;
server.setResponseBody(""); // Empty body
@@ -291,13 +291,13 @@ TEST_CASE("HTTPClient empty response")
bool test_completed = runHTTPTest(
server, "/empty", completed, result_status, result_data, result_error);
CHECK(test_completed);
CHECK(!result_error);
CHECK(result_status == 200);
CHECK(result_data.empty());
EXPECT_TRUE(test_completed);
EXPECT_FALSE(result_error);
EXPECT_EQ(result_status, 200);
EXPECT_TRUE(result_data.empty());
}
TEST_CASE("HTTPClient different status codes")
TEST(HTTPClient, different_status_codes)
{
std::vector<unsigned int> status_codes = {200, 404, 500};
@@ -320,8 +320,8 @@ TEST_CASE("HTTPClient different status codes")
result_data,
result_error);
CHECK(test_completed);
CHECK(!result_error);
CHECK(result_status == static_cast<int>(status));
EXPECT_TRUE(test_completed);
EXPECT_FALSE(result_error);
EXPECT_EQ(result_status, static_cast<int>(status));
}
}

View File

@@ -1,2 +1,8 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>
#include <gtest/gtest.h>
int
main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}