mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-23 12:05: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/STAmount.h>
|
||||||
#include <ripple/protocol/STObject.h>
|
#include <ripple/protocol/STObject.h>
|
||||||
#include <ripple/protocol/STTx.h>
|
#include <ripple/protocol/STTx.h>
|
||||||
|
#include <ripple/rpc/impl/RPCHelpers.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <test/jtx/AbstractClient.h>
|
#include <test/jtx/AbstractClient.h>
|
||||||
@@ -755,6 +756,40 @@ Env::rpc(std::string const& cmd, Args&&... args)
|
|||||||
std::forward<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 jtx
|
||||||
} // namespace test
|
} // namespace test
|
||||||
} // namespace ripple
|
} // namespace ripple
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
#include <ripple/beast/unit_test.h>
|
#include <ripple/beast/unit_test.h>
|
||||||
#include <ripple/protocol/ErrorCodes.h>
|
#include <ripple/protocol/ErrorCodes.h>
|
||||||
#include <ripple/protocol/jss.h>
|
#include <ripple/protocol/jss.h>
|
||||||
#include <ripple/rpc/impl/RPCHelpers.h>
|
|
||||||
#include <test/jtx.h>
|
#include <test/jtx.h>
|
||||||
|
|
||||||
#include <boost/container/flat_set.hpp>
|
#include <boost/container/flat_set.hpp>
|
||||||
@@ -854,12 +853,8 @@ public:
|
|||||||
void
|
void
|
||||||
run() override
|
run() override
|
||||||
{
|
{
|
||||||
for (auto testVersion = RPC::apiMinimumSupportedVersion;
|
test::jtx::forAllApiVersions(
|
||||||
testVersion <= RPC::apiBetaVersion;
|
std::bind_front(&AccountTx_test::testParameters, this));
|
||||||
++testVersion)
|
|
||||||
{
|
|
||||||
testParameters(testVersion);
|
|
||||||
}
|
|
||||||
testContents();
|
testContents();
|
||||||
testAccountDelete();
|
testAccountDelete();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
#include <ripple/beast/unit_test.h>
|
#include <ripple/beast/unit_test.h>
|
||||||
#include <ripple/protocol/ErrorCodes.h>
|
#include <ripple/protocol/ErrorCodes.h>
|
||||||
#include <ripple/protocol/jss.h>
|
#include <ripple/protocol/jss.h>
|
||||||
#include <ripple/rpc/impl/RPCHelpers.h>
|
|
||||||
#include <test/app/Import_json.h>
|
#include <test/app/Import_json.h>
|
||||||
#include <test/jtx.h>
|
#include <test/jtx.h>
|
||||||
|
|
||||||
@@ -2369,13 +2368,8 @@ public:
|
|||||||
testQueue();
|
testQueue();
|
||||||
testLedgerAccountsOption();
|
testLedgerAccountsOption();
|
||||||
|
|
||||||
// version specific tests
|
test::jtx::forAllApiVersions(std::bind_front(
|
||||||
for (auto testVersion = RPC::apiMinimumSupportedVersion;
|
&LedgerRPC_test::testLedgerEntryInvalidParams, this));
|
||||||
testVersion <= RPC::apiBetaVersion;
|
|
||||||
++testVersion)
|
|
||||||
{
|
|
||||||
testLedgerEntryInvalidParams(testVersion);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user