mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-18 17:45:48 +00:00
test: add forAllApiVersions helper function (#4611)
Introduce a new variadic template helper function, `forAllApiVersions`, that accepts callables to execute a set of functions over a range of versions - from RPC::apiMinimumSupportedVersion to RPC::apiBetaVersion. This avoids the duplication of code. Context: #4552
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include <ripple/protocol/STAmount.h>
|
||||
#include <ripple/protocol/STObject.h>
|
||||
#include <ripple/protocol/STTx.h>
|
||||
#include <ripple/rpc/impl/RPCHelpers.h>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <test/jtx/AbstractClient.h>
|
||||
@@ -755,6 +756,40 @@ Env::rpc(std::string const& cmd, Args&&... args)
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/**
|
||||
* The SingleVersionedTestCallable concept checks for a callable that takes
|
||||
* an unsigned integer as its argument and returns void.
|
||||
*/
|
||||
template <class T>
|
||||
concept SingleVersionedTestCallable = requires(T callable, unsigned int version)
|
||||
{
|
||||
{
|
||||
callable(version)
|
||||
}
|
||||
->std::same_as<void>;
|
||||
};
|
||||
|
||||
/**
|
||||
* The VersionedTestCallable concept checks if a set of callables all satisfy
|
||||
* the SingleVersionedTestCallable concept. This allows forAllApiVersions to
|
||||
* accept any number of functions. It executes a set of provided functions over
|
||||
* a range of versions from RPC::apiMinimumSupportedVersion to
|
||||
* RPC::apiBetaVersion. This is useful for running a series of tests or
|
||||
* operations that need to be performed on multiple versions of an API.
|
||||
*/
|
||||
template <class... T>
|
||||
concept VersionedTestCallable = (... && SingleVersionedTestCallable<T>);
|
||||
void
|
||||
forAllApiVersions(VersionedTestCallable auto... testCallable)
|
||||
{
|
||||
for (auto testVersion = RPC::apiMinimumSupportedVersion;
|
||||
testVersion <= RPC::apiBetaVersion;
|
||||
++testVersion)
|
||||
{
|
||||
(..., testCallable(testVersion));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace jtx
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <ripple/protocol/ErrorCodes.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <ripple/rpc/impl/RPCHelpers.h>
|
||||
#include <test/jtx.h>
|
||||
|
||||
#include <boost/container/flat_set.hpp>
|
||||
@@ -854,12 +853,8 @@ public:
|
||||
void
|
||||
run() override
|
||||
{
|
||||
for (auto testVersion = RPC::apiMinimumSupportedVersion;
|
||||
testVersion <= RPC::apiBetaVersion;
|
||||
++testVersion)
|
||||
{
|
||||
testParameters(testVersion);
|
||||
}
|
||||
test::jtx::forAllApiVersions(
|
||||
std::bind_front(&AccountTx_test::testParameters, this));
|
||||
testContents();
|
||||
testAccountDelete();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <ripple/protocol/ErrorCodes.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <ripple/rpc/impl/RPCHelpers.h>
|
||||
#include <test/app/Import_json.h>
|
||||
#include <test/jtx.h>
|
||||
|
||||
@@ -2369,13 +2368,8 @@ public:
|
||||
testQueue();
|
||||
testLedgerAccountsOption();
|
||||
|
||||
// version specific tests
|
||||
for (auto testVersion = RPC::apiMinimumSupportedVersion;
|
||||
testVersion <= RPC::apiBetaVersion;
|
||||
++testVersion)
|
||||
{
|
||||
testLedgerEntryInvalidParams(testVersion);
|
||||
}
|
||||
test::jtx::forAllApiVersions(std::bind_front(
|
||||
&LedgerRPC_test::testLedgerEntryInvalidParams, this));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user