35 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
36 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
45 #include <type_traits>
57 template <
class ParamType>
69 template <
class ParamType>
85 CodeLocation code_location);
112 virtual const T*
Current()
const = 0;
122 template <
typename T>
154 return !(*
this == other);
160 std::unique_ptr<ParamIteratorInterface<T> >
impl_;
165 template <
typename T>
183 class ParamGenerator {
199 std::shared_ptr<const ParamGeneratorInterface<T> >
impl_;
206 template <
typename T,
typename IncrementT>
244 <<
"The program attempted to compare iterators "
245 <<
"from different generators." << std::endl;
246 const int other_index =
247 CheckedDowncastToActualType<const Iterator>(&other)->
index_;
248 return index_ == other_index;
268 const IncrementT& step) {
270 for (
T i = begin; i < end; i = static_cast<T>(
i + step))
291 template <
typename T>
294 template <
typename ForwardIterator>
312 typename ContainerType::const_iterator iterator)
341 <<
"The program attempted to compare iterators "
342 <<
"from different generators." << std::endl;
344 CheckedDowncastToActualType<const Iterator>(&other)->iterator_;
375 template <
class ParamType>
378 name_stream << info.
index;
382 template <
typename T =
int>
384 static_assert(
sizeof(
T) == 0,
"Empty arguments are not allowed.");
386 template <
typename T =
int>
393 template <
class TestClass>
401 return new TestClass();
414 template <
class ParamType>
430 template <
class TestSuite>
495 template <
class TestSuite>
526 test_suite_name, test_base_name, meta_factory, code_location)));
531 GeneratorCreationFunc*
func,
533 const char* file,
int line) {
544 bool generated_instantiations =
false;
546 for (
typename TestInfoContainer::iterator test_it =
tests_.begin();
547 test_it !=
tests_.end(); ++test_it) {
548 std::shared_ptr<TestInfo> test_info = *test_it;
549 for (
typename InstantiationContainer::iterator gen_it =
552 const std::string& instantiation_name = gen_it->name;
555 const char* file = gen_it->file;
556 int line = gen_it->line;
558 std::string test_suite_name;
559 if ( !instantiation_name.empty() )
560 test_suite_name = instantiation_name +
"/";
561 test_suite_name += test_info->test_suite_base_name;
564 std::set<std::string> test_param_names;
567 param_it != generator.end(); ++param_it, ++
i) {
568 generated_instantiations =
true;
572 std::string param_name = name_func(
576 <<
"Parameterized test name '" << param_name
577 <<
"' is invalid, in " << file
578 <<
" line " << line << std::endl;
581 <<
"Duplicate parameterized test name '" << param_name
582 <<
"', in " << file <<
" line " << line << std::endl;
584 test_param_names.insert(param_name);
586 if (!test_info->test_base_name.empty()) {
587 test_name_stream << test_info->test_base_name <<
"/";
589 test_name_stream << param_name;
591 test_suite_name.c_str(), test_name_stream.
GetString().c_str(),
597 test_info->test_meta_factory->CreateTestFactory(*param_it));
602 if (!generated_instantiations) {
613 TestInfo(
const char* a_test_suite_base_name,
const char* a_test_base_name,
632 GeneratorCreationFunc* generator_in,
656 for (std::string::size_type index = 0; index < name.size(); ++index) {
657 if (!isalnum(name[index]) && name[index] !=
'_')
673 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
674 template <
class TestCase>
676 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
689 delete test_suite_info;
695 template <
class TestSuite>
697 const char* test_suite_name,
CodeLocation code_location) {
700 if (test_suite_info->GetTestSuiteName() == test_suite_name) {
701 if (test_suite_info->GetTestSuiteTypeId() != GetTypeId<TestSuite>()) {
717 if (typed_test_info ==
nullptr) {
719 test_suite_name, code_location);
720 test_suite_infos_.push_back(typed_test_info);
722 return typed_test_info;
726 test_suite_info->RegisterTests();
730 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
731 template <
class TestCase>
733 const char* test_case_name,
CodeLocation code_location) {
734 return GetTestSuitePatternHolder<TestCase>(test_case_name, code_location);
737 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
772 std::map<std::string, TypeParameterizedTestSuiteInfo>
suites_;
779 template <
class Container>
786 template <
typename... Ts>
791 template <
typename T>
797 template <
typename T,
size_t... I>
799 return std::vector<T>{
static_cast<T>(
v_.template Get<I>())...};
805 template <
typename...
T>
825 template <
size_t... I>
832 begin_(std::get<I>(generators).begin()...),
833 end_(std::get<I>(generators).end()...),
834 current_(is_end ? end_ : begin_) {
835 ComputeCurrentValue();
847 ++std::get<
sizeof...(T) - 1>(current_);
849 AdvanceIfEnd<
sizeof...(T) - 1>();
850 ComputeCurrentValue();
862 <<
"The program attempted to compare iterators "
863 <<
"from different generators." << std::endl;
865 CheckedDowncastToActualType<const IteratorImpl>(&other);
870 if (AtEnd() && typed_other->AtEnd())
return true;
874 (same = same && std::get<I>(current_) ==
875 std::get<I>(typed_other->current_))...};
881 template <
size_t ThisI>
883 if (std::get<ThisI>(current_) != std::get<ThisI>(end_))
return;
885 bool last = ThisI == 0;
891 constexpr
size_t NextI = ThisI - (ThisI != 0);
892 std::get<ThisI>(current_) = std::get<ThisI>(begin_);
893 ++std::get<NextI>(current_);
894 AdvanceIfEnd<NextI>();
899 current_value_ = std::make_shared<ParamType>(*std::get<I>(current_)...);
904 (at_end = at_end || std::get<I>(current_) == std::get<I>(end_))...};
910 std::tuple<typename ParamGenerator<T>::iterator...>
begin_;
911 std::tuple<typename ParamGenerator<T>::iterator...>
end_;
912 std::tuple<typename ParamGenerator<T>::iterator...>
current_;
921 template <
class... Gen>
925 template <
typename...
T>
938 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
virtual TypeId GetTestSuiteTypeId() const =0
virtual ParamIteratorInterface< T > * End() const =0
::std::vector< T > ContainerType
const ParamGeneratorInterface< T > *const base_
ParamGenerator(const ParamGenerator &other)
virtual ~ParamIteratorInterface()
static SetUpTearDownSuiteFuncType GetTearDownCaseOrSuite(const char *filename, int line_num)
std::tuple< Gen...> generators_
void ComputeCurrentValue()
void RegisterInstantiation(const char *test_suite_name)
void operator=(const RangeGenerator &other)
ParamIterator< T > iterator
TypeId GetTestSuiteTypeId() const override
const std::unique_ptr< TestMetaFactoryBase< ParamType > > test_meta_factory
Iterator(const ParamGeneratorInterface< T > *base, T value, int index, IncrementT step)
ParamIteratorInterface< ParamType > * Clone() const override
std::tuple< typename ParamGenerator< T >::iterator...> begin_
MarkAsIgnored(const char *test_suite)
bool operator==(const ParamIterator &other) const
~ParameterizedTestSuiteRegistry()
~CartesianProductGenerator() override
ParamIteratorInterface< T > * End() const override
void operator=(const Iterator &other)
::std::string PrintToString(const T &value)
const ContainerType container_
std::shared_ptr< ParamType > current_value_
const ParamType * Current() const override
virtual bool Equals(const ParamIteratorInterface &other) const =0
const std::string test_suite_base_name
GeneratorCreationFunc * generator
Iterator(const Iterator &other)
std::tuple< typename ParamGenerator< T >::iterator...> current_
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteRegistry)
::std::vector< InstantiationInfo > InstantiationContainer
TestSuiteInfoContainer test_suite_infos_
TestParamInfo(const ParamType &a_param, size_t an_index)
CartesianProductHolder(const Gen &...g)
static bool IsValidParamName(const std::string &name)
const CodeLocation code_location
std::tuple< ParamGenerator< T >...> generators_
RangeGenerator(T begin, T end, IncrementT step)
ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end)
std::unique_ptr< const T > value_
internal::ParamGenerator< typename std::iterator_traits< ForwardIterator >::value_type > ValuesIn(ForwardIterator begin, ForwardIterator end)
void AddTestPattern(const char *test_suite_name, const char *test_base_name, TestMetaFactoryBase< ParamType > *meta_factory, CodeLocation code_location)
ParamGenerator & operator=(const ParamGenerator &other)
bool Equals(const ParamIteratorInterface< T > &other) const override
ParamIterator(const ParamIterator &other)
Test * CreateTest() override
CodeLocation code_location_
ParamIteratorInterface< T > * Begin() const override
virtual const T * Current() const =0
virtual ~ParameterizedTestSuiteInfoBase()
ParamIteratorInterface< T > * Clone() const override
ParameterizedTestSuiteRegistry()
GTEST_API_ void ReportInvalidTestSuiteType(const char *test_suite_name, CodeLocation code_location)
const ParamGeneratorInterface< T > *const base_
void RegisterTests() override
ContainerType::const_iterator iterator_
static int CalculateEndIndex(const T &begin, const T &end, const IncrementT &step)
bool Equals(const ParamIteratorInterface< ParamType > &other) const override
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 c
int AddTestSuiteInstantiation(const std::string &instantiation_name, GeneratorCreationFunc *func, ParamNameGeneratorFunc *name_func, const char *file, int line)
GTEST_API_ TestInfo * MakeAndRegisterTestInfo(const char *test_suite_name, const char *name, const char *type_param, const char *value_param, CodeLocation code_location, TypeId fixture_class_id, SetUpTestSuiteFunc set_up_tc, TearDownTestSuiteFunc tear_down_tc, TestFactoryBase *factory)
#define GTEST_CHECK_(condition)
~RangeGenerator() override
TestClass::ParamType ParamType
ParameterizedTestSuiteInfoBase()
CartesianProductGenerator(const std::tuple< ParamGenerator< T >...> &g)
ParamIterator operator++(int)
ptrdiff_t difference_type
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestFactory)
::std::vector< std::shared_ptr< TestInfo > > TestInfoContainer
std::string(const TestParamInfo< ParamType > &) ParamNameGeneratorFunc
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfoBase)
void operator=(const ValuesInIteratorRangeGenerator &other)
std::map< std::string, TypeParameterizedTestSuiteInfo > suites_
const ParamGeneratorInterface< T > * BaseGenerator() const override
bool operator!=(const ParamIterator &other) const
ParameterizedTestSuiteInfo(const char *name, CodeLocation code_location)
std::string GetString() const
const std::string test_base_name
ParameterizedTestSuiteInfo< TestSuite > * GetTestSuitePatternHolder(const char *test_suite_name, CodeLocation code_location)
InstantiationContainer instantiations_
const std::string test_suite_name_
virtual void RegisterTests()=0
::std::tuple< T...> ParamType
virtual ParamIteratorInterface< T > * Begin() const =0
std::string operator()(const TestParamInfo< ParamType > &info) const
const ParamType parameter_
InstantiationInfo(const std::string &name_in, GeneratorCreationFunc *generator_in, ParamNameGeneratorFunc *name_func_in, const char *file_in, int line_in)
::std::vector< ParameterizedTestSuiteInfoBase * > TestSuiteInfoContainer
GTEST_API_ void InsertSyntheticTestCase(const std::string &name, CodeLocation location, bool has_test_p)
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfo)
std::vector< T > MakeVector(IndexSequence< I...>) const
ParamNameGeneratorFunc * name_func
std::string DefaultParamName(const TestParamInfo< ParamType > &info)
ParamIterator(ParamIteratorInterface< T > *impl)
virtual const ParamGeneratorInterface< T > * BaseGenerator() const =0
ParamIteratorInterface< T > * Begin() const override
ParamGenerator(ParamGeneratorInterface< T > *impl)
const T * operator->() const
virtual ~ParamGeneratorInterface()
ParameterizedTestFactory(ParamType parameter)
const T * Current() const override
ParamIteratorInterface< T > * End() const override
void RegisterTestSuite(const char *test_suite_name, CodeLocation code_location)
TypeParameterizedTestSuiteInfo(CodeLocation c)
void CheckForInstantiations()
static SetUpTearDownSuiteFuncType GetSetUpCaseOrSuite(const char *filename, int line_num)
std::unique_ptr< ParamIteratorInterface< T > > impl_
ParamIteratorInterface< ParamType > * Begin() const override
ParameterizedTestCaseInfo< TestCase > * GetTestCasePatternHolder(const char *test_case_name, CodeLocation code_location)
const T func(int n, T *x)
~ValuesInIteratorRangeGenerator() override
Iterator(const ParamGeneratorInterface< T > *base, typename ContainerType::const_iterator iterator)
const std::string & GetTestSuiteName() const override
TestInfo(const char *a_test_suite_base_name, const char *a_test_base_name, TestMetaFactoryBase< ParamType > *a_test_meta_factory, CodeLocation a_code_location)
std::tuple< typename ParamGenerator< T >::iterator...> end_
virtual ParamIteratorInterface * Clone() const =0
const T & operator*() const
ParamIteratorInterface< T > * Clone() const override
const ParamGeneratorInterface< T > * BaseGenerator() const override
const T * Current() const override
Derived * CheckedDowncastToActualType(Base *base)
typename TestSuite::ParamType ParamType
const ParamGeneratorInterface< ParamType > *const base_
IteratorImpl(const ParamGeneratorInterface< ParamType > *base, const std::tuple< ParamGenerator< T >...> &generators, bool is_end)
const ParamGeneratorInterface< ParamType > * BaseGenerator() const override
IteratorImpl< typename MakeIndexSequence< sizeof...(T)>::type > Iterator
ParamIterator & operator=(const ParamIterator &other)
bool Equals(const ParamIteratorInterface< T > &other) const override
std::shared_ptr< const ParamGeneratorInterface< T > > impl_
ParamIteratorInterface< ParamType > * End() const override
virtual const std::string & GetTestSuiteName() const =0
CodeLocation code_location
ParamIterator & operator++()