Skip to content

Commit

Permalink
Add make_vector to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Oct 23, 2023
1 parent dc77c4f commit dff8113
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/test/basics/PerfLog_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <ripple/protocol/jss.h>
#include <ripple/rpc/impl/Handler.h>
#include <test/jtx/Env.h>
#include <test/jtx/TestHelpers.h>

#include <atomic>
#include <chrono>
Expand Down Expand Up @@ -309,9 +310,8 @@ class PerfLog_test : public beast::unit_test::suite

// Get the all the labels we can use for RPC interfaces without
// causing an assert.
std::set<const char*> handlerNames = ripple::RPC::getHandlerNames();
std::vector<char const*> labels(
handlerNames.begin(), handlerNames.end());
std::vector<char const*> labels =
test::jtx::make_vector(ripple::RPC::getHandlerNames());
std::shuffle(labels.begin(), labels.end(), default_prng());

// Get two IDs to associate with each label. Errors tend to happen at
Expand Down
9 changes: 9 additions & 0 deletions src/test/jtx/TestHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@
#include <ripple/protocol/jss.h>
#include <test/jtx/Env.h>

#include <ranges>

namespace ripple {
namespace test {
namespace jtx {

// Helper to make vector from iterable
auto
make_vector(auto const& input) requires std::ranges::range<decltype(input)>
{
return std::vector(std::ranges::begin(input), std::ranges::end(input));
}

// Functions used in debugging
Json::Value
getAccountOffers(Env& env, AccountID const& acct, bool current = false);
Expand Down
5 changes: 2 additions & 3 deletions src/test/rpc/Handler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ class Handler_test : public beast::unit_test::suite
std::random_device dev;
std::ranlux48 prng(dev());

std::set<const char*> handlerNames = RPC::getHandlerNames();
std::vector<const char*> names(
handlerNames.begin(), handlerNames.end());
std::vector<const char*> names =
test::jtx::make_vector(ripple::RPC::getHandlerNames());

std::uniform_int_distribution<std::size_t> distr{0, names.size() - 1};

Expand Down

0 comments on commit dff8113

Please sign in to comment.