replace autogenerated TypesX classes by variadic ones
This commit is contained in:
parent
37f3227831
commit
eed64b5fc6
|
@ -27,7 +27,6 @@
|
||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||||
|
|
||||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
|
#ifndef GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
|
||||||
|
@ -189,12 +188,12 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
|
||||||
gtest_type_params_##TestSuiteName##_NameGenerator
|
gtest_type_params_##TestSuiteName##_NameGenerator
|
||||||
|
|
||||||
#define TYPED_TEST_SUITE(CaseName, Types, ...) \
|
#define TYPED_TEST_SUITE(CaseName, Types, ...) \
|
||||||
typedef ::testing::internal::TypeList<Types>::type GTEST_TYPE_PARAMS_( \
|
typedef ::testing::internal::GenerateTypeList<Types>::type \
|
||||||
CaseName); \
|
GTEST_TYPE_PARAMS_(CaseName); \
|
||||||
typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \
|
typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \
|
||||||
GTEST_NAME_GENERATOR_(CaseName)
|
GTEST_NAME_GENERATOR_(CaseName)
|
||||||
|
|
||||||
# define TYPED_TEST(CaseName, TestName) \
|
#define TYPED_TEST(CaseName, TestName) \
|
||||||
template <typename gtest_TypeParam_> \
|
template <typename gtest_TypeParam_> \
|
||||||
class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \
|
class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \
|
||||||
: public CaseName<gtest_TypeParam_> { \
|
: public CaseName<gtest_TypeParam_> { \
|
||||||
|
@ -204,8 +203,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
|
||||||
void TestBody() override; \
|
void TestBody() override; \
|
||||||
}; \
|
}; \
|
||||||
static bool gtest_##CaseName##_##TestName##_registered_ \
|
static bool gtest_##CaseName##_##TestName##_registered_ \
|
||||||
GTEST_ATTRIBUTE_UNUSED_ = \
|
GTEST_ATTRIBUTE_UNUSED_ = ::testing::internal::TypeParameterizedTest< \
|
||||||
::testing::internal::TypeParameterizedTest< \
|
|
||||||
CaseName, \
|
CaseName, \
|
||||||
::testing::internal::TemplateSel<GTEST_TEST_CLASS_NAME_(CaseName, \
|
::testing::internal::TemplateSel<GTEST_TEST_CLASS_NAME_(CaseName, \
|
||||||
TestName)>, \
|
TestName)>, \
|
||||||
|
@ -307,7 +305,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
|
||||||
static bool gtest_##Prefix##_##SuiteName GTEST_ATTRIBUTE_UNUSED_ = \
|
static bool gtest_##Prefix##_##SuiteName GTEST_ATTRIBUTE_UNUSED_ = \
|
||||||
::testing::internal::TypeParameterizedTestSuite< \
|
::testing::internal::TypeParameterizedTestSuite< \
|
||||||
SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \
|
SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \
|
||||||
::testing::internal::TypeList<Types>::type>:: \
|
::testing::internal::GenerateTypeList<Types>::type>:: \
|
||||||
Register(#Prefix, \
|
Register(#Prefix, \
|
||||||
::testing::internal::CodeLocation(__FILE__, __LINE__), \
|
::testing::internal::CodeLocation(__FILE__, __LINE__), \
|
||||||
>EST_TYPED_TEST_SUITE_P_STATE_(SuiteName), #SuiteName, \
|
>EST_TYPED_TEST_SUITE_P_STATE_(SuiteName), #SuiteName, \
|
||||||
|
@ -315,7 +313,7 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
|
||||||
::testing::internal::GenerateNames< \
|
::testing::internal::GenerateNames< \
|
||||||
::testing::internal::NameGeneratorSelector< \
|
::testing::internal::NameGeneratorSelector< \
|
||||||
__VA_ARGS__>::type, \
|
__VA_ARGS__>::type, \
|
||||||
::testing::internal::TypeList<Types>::type>())
|
::testing::internal::GenerateTypeList<Types>::type>())
|
||||||
|
|
||||||
// Legacy API is deprecated but still available
|
// Legacy API is deprecated but still available
|
||||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||||
|
|
|
@ -662,7 +662,7 @@ struct NameGeneratorSelector {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename NameGenerator>
|
template <typename NameGenerator>
|
||||||
void GenerateNamesRecursively(Types0, std::vector<std::string>*, int) {}
|
void GenerateNamesRecursively(internal::None, std::vector<std::string>*, int) {}
|
||||||
|
|
||||||
template <typename NameGenerator, typename Types>
|
template <typename NameGenerator, typename Types>
|
||||||
void GenerateNamesRecursively(Types, std::vector<std::string>* result, int i) {
|
void GenerateNamesRecursively(Types, std::vector<std::string>* result, int i) {
|
||||||
|
@ -729,7 +729,7 @@ class TypeParameterizedTest {
|
||||||
|
|
||||||
// The base case for the compile time recursion.
|
// The base case for the compile time recursion.
|
||||||
template <GTEST_TEMPLATE_ Fixture, class TestSel>
|
template <GTEST_TEMPLATE_ Fixture, class TestSel>
|
||||||
class TypeParameterizedTest<Fixture, TestSel, Types0> {
|
class TypeParameterizedTest<Fixture, TestSel, internal::None> {
|
||||||
public:
|
public:
|
||||||
static bool Register(const char* /*prefix*/, const CodeLocation&,
|
static bool Register(const char* /*prefix*/, const CodeLocation&,
|
||||||
const char* /*case_name*/, const char* /*test_names*/,
|
const char* /*case_name*/, const char* /*test_names*/,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -33,8 +33,8 @@ $var n = 50 $$ Maximum length of type lists we want to support.
|
||||||
// Type utilities needed for implementing typed and type-parameterized
|
// Type utilities needed for implementing typed and type-parameterized
|
||||||
// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
|
// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
|
||||||
//
|
//
|
||||||
// Currently we support at most $n types in a list, and at most $n
|
// Currently we support at most $n type-parameterized tests
|
||||||
// type-parameterized tests in one type-parameterized test suite.
|
// in one type-parameterized test suite.
|
||||||
// Please contact googletestframework@googlegroups.com if you need
|
// Please contact googletestframework@googlegroups.com if you need
|
||||||
// more.
|
// more.
|
||||||
|
|
||||||
|
@ -104,84 +104,6 @@ std::string GetTypeName() {
|
||||||
|
|
||||||
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
||||||
|
|
||||||
// A unique type used as the default value for the arguments of class
|
|
||||||
// template Types. This allows us to simulate variadic templates
|
|
||||||
// (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
|
|
||||||
// support directly.
|
|
||||||
struct None {};
|
|
||||||
|
|
||||||
// The following family of struct and struct templates are used to
|
|
||||||
// represent type lists. In particular, TypesN<T1, T2, ..., TN>
|
|
||||||
// represents a type list with N types (T1, T2, ..., and TN) in it.
|
|
||||||
// Except for Types0, every struct in the family has two member types:
|
|
||||||
// Head for the first type in the list, and Tail for the rest of the
|
|
||||||
// list.
|
|
||||||
|
|
||||||
// The empty type list.
|
|
||||||
struct Types0 {};
|
|
||||||
|
|
||||||
// Type lists of length 1, 2, 3, and so on.
|
|
||||||
|
|
||||||
template <typename T1>
|
|
||||||
struct Types1 {
|
|
||||||
typedef T1 Head;
|
|
||||||
typedef Types0 Tail;
|
|
||||||
};
|
|
||||||
|
|
||||||
$range i 2..n
|
|
||||||
|
|
||||||
$for i [[
|
|
||||||
$range j 1..i
|
|
||||||
$range k 2..i
|
|
||||||
template <$for j, [[typename T$j]]>
|
|
||||||
struct Types$i {
|
|
||||||
typedef T1 Head;
|
|
||||||
typedef Types$(i-1)<$for k, [[T$k]]> Tail;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
]]
|
|
||||||
|
|
||||||
} // namespace internal
|
|
||||||
|
|
||||||
// We don't want to require the users to write TypesN<...> directly,
|
|
||||||
// as that would require them to count the length. Types<...> is much
|
|
||||||
// easier to write, but generates horrible messages when there is a
|
|
||||||
// compiler error, as gcc insists on printing out each template
|
|
||||||
// argument, even if it has the default value (this means Types<int>
|
|
||||||
// will appear as Types<int, None, None, ..., None> in the compiler
|
|
||||||
// errors).
|
|
||||||
//
|
|
||||||
// Our solution is to combine the best part of the two approaches: a
|
|
||||||
// user would write Types<T1, ..., TN>, and Google Test will translate
|
|
||||||
// that to TypesN<T1, ..., TN> internally to make error messages
|
|
||||||
// readable. The translation is done by the 'type' member of the
|
|
||||||
// Types template.
|
|
||||||
|
|
||||||
$range i 1..n
|
|
||||||
template <$for i, [[typename T$i = internal::None]]>
|
|
||||||
struct Types {
|
|
||||||
typedef internal::Types$n<$for i, [[T$i]]> type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct Types<$for i, [[internal::None]]> {
|
|
||||||
typedef internal::Types0 type;
|
|
||||||
};
|
|
||||||
|
|
||||||
$range i 1..n-1
|
|
||||||
$for i [[
|
|
||||||
$range j 1..i
|
|
||||||
$range k i+1..n
|
|
||||||
template <$for j, [[typename T$j]]>
|
|
||||||
struct Types<$for j, [[T$j]]$for k[[, internal::None]]> {
|
|
||||||
typedef internal::Types$i<$for j, [[T$j]]> type;
|
|
||||||
};
|
|
||||||
|
|
||||||
]]
|
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
# define GTEST_TEMPLATE_ template <typename T> class
|
# define GTEST_TEMPLATE_ template <typename T> class
|
||||||
|
|
||||||
// The template "selector" struct TemplateSel<Tmpl> is used to
|
// The template "selector" struct TemplateSel<Tmpl> is used to
|
||||||
|
@ -278,25 +200,55 @@ struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> {
|
||||||
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
// The TypeList template makes it possible to use either a single type
|
// A unique type indicating an empty node
|
||||||
// or a Types<...> list in TYPED_TEST_SUITE() and
|
struct None {};
|
||||||
// INSTANTIATE_TYPED_TEST_SUITE_P().
|
|
||||||
|
|
||||||
template <typename T>
|
// Tuple-like type lists
|
||||||
struct TypeList {
|
template <typename Head_, typename... Tail_>
|
||||||
typedef Types1<T> type;
|
struct Types {
|
||||||
|
using Head = Head_;
|
||||||
|
using Tail = Types<Tail_...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename Head_>
|
||||||
|
struct Types<Head_> {
|
||||||
|
using Head = Head_;
|
||||||
|
using Tail = None;
|
||||||
|
};
|
||||||
|
|
||||||
$range i 1..n
|
// Helper metafunctions to tell apart a single type from types
|
||||||
template <$for i, [[typename T$i]]>
|
// generated by ::testing::Types
|
||||||
struct TypeList<Types<$for i, [[T$i]]> > {
|
template <typename... Ts>
|
||||||
typedef typename Types<$for i, [[T$i]]>::type type;
|
struct ProxyTypeList {
|
||||||
|
typedef Types<Ts...> type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename>
|
||||||
|
struct is_proxy_type_list : std::false_type {};
|
||||||
|
|
||||||
|
template <typename... Ts>
|
||||||
|
struct is_proxy_type_list<ProxyTypeList<Ts...>> : std::true_type {};
|
||||||
|
|
||||||
|
// Generator which conditionally creates type lists.
|
||||||
|
// It recognizes if a requested type list should be created
|
||||||
|
// and prevents creating a new type list nested within another one.
|
||||||
|
template <typename T>
|
||||||
|
struct GenerateTypeList {
|
||||||
|
private:
|
||||||
|
using proxy = typename std::conditional<is_proxy_type_list<T>::value, T,
|
||||||
|
ProxyTypeList<T>>::type;
|
||||||
|
|
||||||
|
public:
|
||||||
|
using type = typename proxy::type;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
|
template <typename... Ts>
|
||||||
|
using Types = internal::ProxyTypeList<Ts...>;
|
||||||
|
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
|
|
||||||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
|
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
|
||||||
|
|
|
@ -188,7 +188,7 @@ TEST(ApiTest, TestSuiteImmutableAccessorsWork) {
|
||||||
ASSERT_TRUE(test_suite != nullptr);
|
ASSERT_TRUE(test_suite != nullptr);
|
||||||
|
|
||||||
EXPECT_STREQ("TestSuiteWithCommentTest/0", test_suite->name());
|
EXPECT_STREQ("TestSuiteWithCommentTest/0", test_suite->name());
|
||||||
EXPECT_STREQ(GetTypeName<int>().c_str(), test_suite->type_param());
|
EXPECT_STREQ(GetTypeName<Types<int>>().c_str(), test_suite->type_param());
|
||||||
EXPECT_TRUE(test_suite->should_run());
|
EXPECT_TRUE(test_suite->should_run());
|
||||||
EXPECT_EQ(0, test_suite->disabled_test_count());
|
EXPECT_EQ(0, test_suite->disabled_test_count());
|
||||||
EXPECT_EQ(1, test_suite->test_to_run_count());
|
EXPECT_EQ(1, test_suite->test_to_run_count());
|
||||||
|
@ -199,7 +199,7 @@ TEST(ApiTest, TestSuiteImmutableAccessorsWork) {
|
||||||
EXPECT_STREQ("Dummy", tests[0]->name());
|
EXPECT_STREQ("Dummy", tests[0]->name());
|
||||||
EXPECT_STREQ("TestSuiteWithCommentTest/0", tests[0]->test_suite_name());
|
EXPECT_STREQ("TestSuiteWithCommentTest/0", tests[0]->test_suite_name());
|
||||||
EXPECT_TRUE(IsNull(tests[0]->value_param()));
|
EXPECT_TRUE(IsNull(tests[0]->value_param()));
|
||||||
EXPECT_STREQ(GetTypeName<int>().c_str(), tests[0]->type_param());
|
EXPECT_STREQ(GetTypeName<Types<int>>().c_str(), tests[0]->type_param());
|
||||||
EXPECT_TRUE(tests[0]->should_run());
|
EXPECT_TRUE(tests[0]->should_run());
|
||||||
|
|
||||||
delete[] tests;
|
delete[] tests;
|
||||||
|
@ -265,7 +265,8 @@ class FinalSuccessChecker : public Environment {
|
||||||
|
|
||||||
#if GTEST_HAS_TYPED_TEST
|
#if GTEST_HAS_TYPED_TEST
|
||||||
EXPECT_STREQ("TestSuiteWithCommentTest/0", test_suites[2]->name());
|
EXPECT_STREQ("TestSuiteWithCommentTest/0", test_suites[2]->name());
|
||||||
EXPECT_STREQ(GetTypeName<int>().c_str(), test_suites[2]->type_param());
|
EXPECT_STREQ(GetTypeName<Types<int>>().c_str(),
|
||||||
|
test_suites[2]->type_param());
|
||||||
EXPECT_TRUE(test_suites[2]->should_run());
|
EXPECT_TRUE(test_suites[2]->should_run());
|
||||||
EXPECT_EQ(0, test_suites[2]->disabled_test_count());
|
EXPECT_EQ(0, test_suites[2]->disabled_test_count());
|
||||||
ASSERT_EQ(1, test_suites[2]->total_test_count());
|
ASSERT_EQ(1, test_suites[2]->total_test_count());
|
||||||
|
@ -317,7 +318,7 @@ class FinalSuccessChecker : public Environment {
|
||||||
EXPECT_STREQ("Dummy", tests[0]->name());
|
EXPECT_STREQ("Dummy", tests[0]->name());
|
||||||
EXPECT_STREQ("TestSuiteWithCommentTest/0", tests[0]->test_suite_name());
|
EXPECT_STREQ("TestSuiteWithCommentTest/0", tests[0]->test_suite_name());
|
||||||
EXPECT_TRUE(IsNull(tests[0]->value_param()));
|
EXPECT_TRUE(IsNull(tests[0]->value_param()));
|
||||||
EXPECT_STREQ(GetTypeName<int>().c_str(), tests[0]->type_param());
|
EXPECT_STREQ(GetTypeName<Types<int>>().c_str(), tests[0]->type_param());
|
||||||
EXPECT_TRUE(tests[0]->should_run());
|
EXPECT_TRUE(tests[0]->should_run());
|
||||||
EXPECT_TRUE(tests[0]->result()->Passed());
|
EXPECT_TRUE(tests[0]->result()->Passed());
|
||||||
EXPECT_EQ(0, tests[0]->result()->test_property_count());
|
EXPECT_EQ(0, tests[0]->result()->test_property_count());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user