Skip to content

Commit

Permalink
Move NameGenerator to util (#1428)
Browse files Browse the repository at this point in the history
Fixes for #876
  • Loading branch information
PeterChen13579 authored and kuznetsss committed Jun 18, 2024
1 parent 0064490 commit 119b1ab
Show file tree
Hide file tree
Showing 21 changed files with 95 additions and 283 deletions.
28 changes: 28 additions & 0 deletions tests/common/util/NameGenerator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//------------------------------------------------------------------------------
/*
This file is part of clio: https://github.com/XRPLF/clio
Copyright (c) 2024, the clio developers.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

#pragma once

#include <string>

namespace tests::util {

static auto const NameGenerator = [](auto const& info) { return info.param.testName; };

} // namespace tests::util
13 changes: 2 additions & 11 deletions tests/unit/rpc/JsonBoolTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
//==============================================================================
#include "rpc/common/JsonBool.hpp"
#include "util/NameGenerator.hpp"

#include <boost/json/parse.hpp>
#include <boost/json/value_to.hpp>
Expand All @@ -37,16 +38,6 @@ struct JsonBoolTestsCaseBundle {

class JsonBoolTests : public TestWithParam<JsonBoolTestsCaseBundle> {
public:
struct NameGenerator {
template <class ParamType>
std::string
operator()(testing::TestParamInfo<ParamType> const& info) const
{
auto bundle = static_cast<JsonBoolTestsCaseBundle>(info.param);
return bundle.testName;
}
};

static auto
generateTestValuesForParametersTest()
{
Expand All @@ -72,7 +63,7 @@ INSTANTIATE_TEST_CASE_P(
JsonBoolCheckGroup,
JsonBoolTests,
ValuesIn(JsonBoolTests::generateTestValuesForParametersTest()),
JsonBoolTests::NameGenerator{}
tests::util::NameGenerator
);

TEST_P(JsonBoolTests, Parse)
Expand Down
13 changes: 3 additions & 10 deletions tests/unit/rpc/handlers/AMMInfoTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "rpc/common/Types.hpp"
#include "rpc/handlers/AMMInfo.hpp"
#include "util/Fixtures.hpp"
#include "util/NameGenerator.hpp"
#include "util/TestObject.hpp"

#include <boost/json/parse.hpp>
Expand Down Expand Up @@ -66,15 +67,7 @@ struct AMMInfoParamTestCaseBundle {
std::string expectedErrorMessage;
};

struct AMMInfoParameterTest : public RPCAMMInfoHandlerTest, public WithParamInterface<AMMInfoParamTestCaseBundle> {
struct NameGenerator {
std::string
operator()(auto const& info) const
{
return static_cast<AMMInfoParamTestCaseBundle>(info.param).testName;
}
};
};
struct AMMInfoParameterTest : public RPCAMMInfoHandlerTest, public WithParamInterface<AMMInfoParamTestCaseBundle> {};

static auto
generateTestValuesForParametersTest()
Expand Down Expand Up @@ -106,7 +99,7 @@ INSTANTIATE_TEST_CASE_P(
RPCAMMInfoGroup1,
AMMInfoParameterTest,
ValuesIn(generateTestValuesForParametersTest()),
AMMInfoParameterTest::NameGenerator{}
tests::util::NameGenerator
);

TEST_P(AMMInfoParameterTest, InvalidParams)
Expand Down
15 changes: 3 additions & 12 deletions tests/unit/rpc/handlers/AccountInfoTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "rpc/common/Types.hpp"
#include "rpc/handlers/AccountInfo.hpp"
#include "util/Fixtures.hpp"
#include "util/NameGenerator.hpp"
#include "util/TestObject.hpp"

#include <boost/json/parse.hpp>
Expand Down Expand Up @@ -62,17 +63,7 @@ struct AccountInfoParamTestCaseBundle {

// parameterized test cases for parameters check
struct AccountInfoParameterTest : public RPCAccountInfoHandlerTest,
public WithParamInterface<AccountInfoParamTestCaseBundle> {
struct NameGenerator {
template <class ParamType>
std::string
operator()(testing::TestParamInfo<ParamType> const& info) const
{
auto bundle = static_cast<AccountInfoParamTestCaseBundle>(info.param);
return bundle.testName;
}
};
};
public WithParamInterface<AccountInfoParamTestCaseBundle> {};

static auto
generateTestValuesForParametersTest()
Expand Down Expand Up @@ -114,7 +105,7 @@ INSTANTIATE_TEST_CASE_P(
RPCAccountInfoGroup1,
AccountInfoParameterTest,
ValuesIn(generateTestValuesForParametersTest()),
AccountInfoParameterTest::NameGenerator{}
tests::util::NameGenerator
);

TEST_P(AccountInfoParameterTest, InvalidParams)
Expand Down
15 changes: 3 additions & 12 deletions tests/unit/rpc/handlers/AccountNFTsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "rpc/common/Types.hpp"
#include "rpc/handlers/AccountNFTs.hpp"
#include "util/Fixtures.hpp"
#include "util/NameGenerator.hpp"
#include "util/TestObject.hpp"

#include <boost/json/parse.hpp>
Expand Down Expand Up @@ -66,17 +67,7 @@ struct AccountNFTParamTestCaseBundle {

// parameterized test cases for parameters check
struct AccountNFTParameterTest : public RPCAccountNFTsHandlerTest,
public WithParamInterface<AccountNFTParamTestCaseBundle> {
struct NameGenerator {
template <class ParamType>
std::string
operator()(testing::TestParamInfo<ParamType> const& info) const
{
auto bundle = static_cast<AccountNFTParamTestCaseBundle>(info.param);
return bundle.testName;
}
};
};
public WithParamInterface<AccountNFTParamTestCaseBundle> {};

static auto
generateTestValuesForParametersTest()
Expand Down Expand Up @@ -155,7 +146,7 @@ INSTANTIATE_TEST_CASE_P(
RPCAccountNFTsGroup1,
AccountNFTParameterTest,
ValuesIn(generateTestValuesForParametersTest()),
AccountNFTParameterTest::NameGenerator{}
tests::util::NameGenerator
);

TEST_P(AccountNFTParameterTest, InvalidParams)
Expand Down
15 changes: 3 additions & 12 deletions tests/unit/rpc/handlers/AccountObjectsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "rpc/common/Types.hpp"
#include "rpc/handlers/AccountObjects.hpp"
#include "util/Fixtures.hpp"
#include "util/NameGenerator.hpp"
#include "util/TestObject.hpp"

#include <boost/json/parse.hpp>
Expand Down Expand Up @@ -71,17 +72,7 @@ struct AccountObjectsParamTestCaseBundle {

// parameterized test cases for parameters check
struct AccountObjectsParameterTest : public RPCAccountObjectsHandlerTest,
public WithParamInterface<AccountObjectsParamTestCaseBundle> {
struct NameGenerator {
template <class ParamType>
std::string
operator()(testing::TestParamInfo<ParamType> const& info) const
{
auto bundle = static_cast<AccountObjectsParamTestCaseBundle>(info.param);
return bundle.testName;
}
};
};
public WithParamInterface<AccountObjectsParamTestCaseBundle> {};

static auto
generateTestValuesForParametersTest()
Expand Down Expand Up @@ -180,7 +171,7 @@ INSTANTIATE_TEST_CASE_P(
RPCAccountObjectsGroup1,
AccountObjectsParameterTest,
ValuesIn(generateTestValuesForParametersTest()),
AccountObjectsParameterTest::NameGenerator{}
tests::util::NameGenerator
);

TEST_P(AccountObjectsParameterTest, InvalidParams)
Expand Down
15 changes: 3 additions & 12 deletions tests/unit/rpc/handlers/AccountOffersTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "rpc/common/Types.hpp"
#include "rpc/handlers/AccountOffers.hpp"
#include "util/Fixtures.hpp"
#include "util/NameGenerator.hpp"
#include "util/TestObject.hpp"

#include <boost/json/parse.hpp>
Expand Down Expand Up @@ -62,17 +63,7 @@ struct AccountOfferParamTestCaseBundle {

// parameterized test cases for parameters check
struct AccountOfferParameterTest : public RPCAccountOffersHandlerTest,
public WithParamInterface<AccountOfferParamTestCaseBundle> {
struct NameGenerator {
template <class ParamType>
std::string
operator()(testing::TestParamInfo<ParamType> const& info) const
{
auto bundle = static_cast<AccountOfferParamTestCaseBundle>(info.param);
return bundle.testName;
}
};
};
public WithParamInterface<AccountOfferParamTestCaseBundle> {};

static auto
generateTestValuesForParametersTest()
Expand Down Expand Up @@ -151,7 +142,7 @@ INSTANTIATE_TEST_CASE_P(
RPCAccountOffersGroup1,
AccountOfferParameterTest,
ValuesIn(generateTestValuesForParametersTest()),
AccountOfferParameterTest::NameGenerator{}
tests::util::NameGenerator
);

TEST_P(AccountOfferParameterTest, InvalidParams)
Expand Down
26 changes: 4 additions & 22 deletions tests/unit/rpc/handlers/AccountTxTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "rpc/common/Types.hpp"
#include "rpc/handlers/AccountTx.hpp"
#include "util/Fixtures.hpp"
#include "util/NameGenerator.hpp"
#include "util/TestObject.hpp"

#include <boost/json/parse.hpp>
Expand Down Expand Up @@ -63,15 +64,6 @@ struct AccountTxParamTestCaseBundle {
// parameterized test cases for parameters check
struct AccountTxParameterTest : public RPCAccountTxHandlerTest,
public WithParamInterface<AccountTxParamTestCaseBundle> {
struct NameGenerator {
template <class ParamType>
std::string
operator()(testing::TestParamInfo<ParamType> const& info) const
{
return info.param.testName;
}
};

static auto
generateTestValuesForParametersTest()
{
Expand Down Expand Up @@ -401,7 +393,7 @@ INSTANTIATE_TEST_CASE_P(
RPCAccountTxGroup1,
AccountTxParameterTest,
ValuesIn(AccountTxParameterTest::generateTestValuesForParametersTest()),
AccountTxParameterTest::NameGenerator{}
tests::util::NameGenerator
);

TEST_P(AccountTxParameterTest, CheckParams)
Expand Down Expand Up @@ -1564,17 +1556,7 @@ struct AccountTxTransactionBundle {

// parameterized test cases for parameters check
struct AccountTxTransactionTypeTest : public RPCAccountTxHandlerTest,
public WithParamInterface<AccountTxTransactionBundle> {
struct NameGenerator {
template <class ParamType>
std::string
operator()(testing::TestParamInfo<ParamType> const& info) const
{
auto bundle = static_cast<AccountTxTransactionBundle>(info.param);
return bundle.testName;
}
};
};
public WithParamInterface<AccountTxTransactionBundle> {};

static auto
generateTransactionTypeTestValues()
Expand Down Expand Up @@ -2049,7 +2031,7 @@ INSTANTIATE_TEST_CASE_P(
RPCAccountTxTransactionTypeTest,
AccountTxTransactionTypeTest,
ValuesIn(generateTransactionTypeTestValues()),
AccountTxTransactionTypeTest::NameGenerator{}
tests::util::NameGenerator
);

TEST_P(AccountTxTransactionTypeTest, SpecificTransactionType)
Expand Down
15 changes: 3 additions & 12 deletions tests/unit/rpc/handlers/BookChangesTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "rpc/common/Types.hpp"
#include "rpc/handlers/BookChanges.hpp"
#include "util/Fixtures.hpp"
#include "util/NameGenerator.hpp"
#include "util/TestObject.hpp"

#include <boost/json/parse.hpp>
Expand Down Expand Up @@ -60,17 +61,7 @@ struct BookChangesParamTestCaseBundle {

// parameterized test cases for parameters check
struct BookChangesParameterTest : public RPCBookChangesHandlerTest,
public WithParamInterface<BookChangesParamTestCaseBundle> {
struct NameGenerator {
template <class ParamType>
std::string
operator()(testing::TestParamInfo<ParamType> const& info) const
{
auto bundle = static_cast<BookChangesParamTestCaseBundle>(info.param);
return bundle.testName;
}
};
};
public WithParamInterface<BookChangesParamTestCaseBundle> {};

static auto
generateTestValuesForParametersTest()
Expand All @@ -92,7 +83,7 @@ INSTANTIATE_TEST_CASE_P(
RPCBookChangesGroup1,
BookChangesParameterTest,
ValuesIn(generateTestValuesForParametersTest()),
BookChangesParameterTest::NameGenerator{}
tests::util::NameGenerator
);

TEST_P(BookChangesParameterTest, InvalidParams)
Expand Down
Loading

0 comments on commit 119b1ab

Please sign in to comment.