35 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ 36 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ 55 template <
class ParamType>
67 template <
class ParamType>
83 CodeLocation code_location);
102 virtual void Advance() = 0;
110 virtual const T* Current()
const = 0;
120 template <
typename T>
131 impl_.reset(other.impl_->Clone());
135 const T&
operator*()
const {
return *impl_->Current(); }
149 return impl_.get() == other.impl_.get() || impl_->Equals(*other.impl_);
152 return !(*
this == other);
158 std::unique_ptr<ParamIteratorInterface<T> > impl_;
163 template <
typename T>
193 iterator
begin()
const {
return iterator(impl_->Begin()); }
194 iterator
end()
const {
return iterator(impl_->End()); }
197 std::shared_ptr<const ParamGeneratorInterface<T> > impl_;
204 template <
typename T,
typename IncrementT>
208 : begin_(begin), end_(end),
209 step_(step), end_index_(CalculateEndIndex(begin, end, step)) {}
213 return new Iterator(
this, begin_, 0, step_);
216 return new Iterator(
this, end_, end_index_, step_);
224 : base_(base), value_(value), index_(index), step_(step) {}
225 ~Iterator()
override {}
230 void Advance()
override {
231 value_ =
static_cast<T
>(value_ + step_);
235 return new Iterator(*
this);
237 const T* Current()
const override {
return &value_; }
242 <<
"The program attempted to compare iterators " 243 <<
"from different generators." << std::endl;
244 const int other_index =
245 CheckedDowncastToActualType<const Iterator>(&other)->index_;
246 return index_ == other_index;
250 Iterator(
const Iterator& other)
252 base_(other.base_), value_(other.value_), index_(other.index_),
253 step_(other.step_) {}
256 void operator=(
const Iterator& other);
261 const IncrementT step_;
264 static int CalculateEndIndex(
const T& begin,
266 const IncrementT& step) {
268 for (T
i = begin; i < end; i = static_cast<T>(
i + step))
278 const IncrementT step_;
281 const int end_index_;
289 template <
typename T>
292 template <
typename ForwardIterator>
294 : container_(begin, end) {}
298 return new Iterator(
this, container_.begin());
301 return new Iterator(
this, container_.end());
305 typedef typename ::std::vector<T> ContainerType;
310 typename ContainerType::const_iterator iterator)
311 : base_(base), iterator_(iterator) {}
312 ~Iterator()
override {}
317 void Advance()
override {
322 return new Iterator(*
this);
331 const T* Current()
const override {
332 if (value_.get() ==
nullptr) value_.reset(
new T(*iterator_));
339 <<
"The program attempted to compare iterators " 340 <<
"from different generators." << std::endl;
342 CheckedDowncastToActualType<const Iterator>(&other)->iterator_;
346 Iterator(
const Iterator& other)
351 iterator_(other.iterator_) {}
354 typename ContainerType::const_iterator iterator_;
360 mutable std::unique_ptr<const T> value_;
366 const ContainerType container_;
373 template <
class ParamType>
376 name_stream << info.
index;
380 template <
typename T =
int>
382 static_assert(
sizeof(T) == 0,
"Empty arguments are not allowed.");
384 template <
typename T =
int>
391 template <
class TestClass>
396 parameter_(parameter) {}
398 TestClass::SetParam(¶meter_);
399 return new TestClass();
403 const ParamType parameter_;
412 template <
class ParamType>
428 template <
class TestSuite>
459 virtual const std::string& GetTestSuiteName()
const = 0;
461 virtual TypeId GetTestSuiteTypeId()
const = 0;
466 virtual void RegisterTests() = 0;
482 template <
class TestSuite>
495 : test_suite_name_(name), code_location_(code_location) {}
499 return test_suite_name_;
511 tests_.push_back(std::shared_ptr<TestInfo>(
512 new TestInfo(test_suite_name, test_base_name, meta_factory)));
517 GeneratorCreationFunc* func,
519 const char* file,
int line) {
520 instantiations_.push_back(
521 InstantiationInfo(instantiation_name, func, name_func, file, line));
530 for (
typename TestInfoContainer::iterator test_it = tests_.begin();
531 test_it != tests_.end(); ++test_it) {
532 std::shared_ptr<TestInfo> test_info = *test_it;
533 for (
typename InstantiationContainer::iterator gen_it =
534 instantiations_.begin(); gen_it != instantiations_.end();
536 const std::string& instantiation_name = gen_it->name;
539 const char* file = gen_it->file;
540 int line = gen_it->line;
542 std::string test_suite_name;
543 if ( !instantiation_name.empty() )
544 test_suite_name = instantiation_name +
"/";
545 test_suite_name += test_info->test_suite_base_name;
548 std::set<std::string> test_param_names;
551 param_it != generator.
end(); ++param_it, ++
i) {
554 std::string param_name = name_func(
558 <<
"Parameterized test name '" << param_name
559 <<
"' is invalid, in " << file
560 <<
" line " << line << std::endl;
563 <<
"Duplicate parameterized test name '" << param_name
564 <<
"', in " << file <<
" line " << line << std::endl;
566 test_param_names.insert(param_name);
568 test_name_stream << test_info->test_base_name <<
"/" << param_name;
570 test_suite_name.c_str(), test_name_stream.
GetString().c_str(),
573 GetTestSuiteTypeId(),
576 test_info->test_meta_factory->CreateTestFactory(*param_it));
586 TestInfo(
const char* a_test_suite_base_name,
const char* a_test_base_name,
588 : test_suite_base_name(a_test_suite_base_name),
589 test_base_name(a_test_base_name),
590 test_meta_factory(a_test_meta_factory) {}
592 const std::string test_suite_base_name;
593 const std::string test_base_name;
594 const std::unique_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
596 using TestInfoContainer = ::std::vector<std::shared_ptr<TestInfo> >;
600 struct InstantiationInfo {
601 InstantiationInfo(
const std::string &name_in,
602 GeneratorCreationFunc* generator_in,
607 generator(generator_in),
608 name_func(name_func_in),
613 GeneratorCreationFunc* generator;
618 typedef ::std::vector<InstantiationInfo> InstantiationContainer;
620 static bool IsValidParamName(
const std::string& name) {
627 if (!isalnum(name[
index]) && name[
index] !=
'_')
634 const std::string test_suite_name_;
636 TestInfoContainer tests_;
637 InstantiationContainer instantiations_;
643 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 644 template <
class TestCase>
646 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 658 for (
auto& test_suite_info : test_suite_infos_) {
659 delete test_suite_info;
665 template <
class TestSuite>
667 const char* test_suite_name,
CodeLocation code_location) {
669 for (
auto& test_suite_info : test_suite_infos_) {
670 if (test_suite_info->GetTestSuiteName() == test_suite_name) {
671 if (test_suite_info->GetTestSuiteTypeId() != GetTypeId<TestSuite>()) {
687 if (typed_test_info ==
nullptr) {
689 test_suite_name, code_location);
690 test_suite_infos_.push_back(typed_test_info);
692 return typed_test_info;
695 for (
auto& test_suite_info : test_suite_infos_) {
696 test_suite_info->RegisterTests();
700 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 701 template <
class TestCase>
703 const char* test_case_name,
CodeLocation code_location) {
704 return GetTestSuitePatternHolder<TestCase>(test_case_name, code_location);
707 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ 710 using TestSuiteInfoContainer = ::std::vector<ParameterizedTestSuiteInfoBase*>;
712 TestSuiteInfoContainer test_suite_infos_;
721 template <
class Container>
723 const Container& container);
728 template <
typename... Ts>
733 template <
typename T>
739 template <
typename T,
size_t... I>
741 return std::vector<T>{
static_cast<T
>(v_.template Get<I>())...};
747 template <
typename... T>
758 return new Iterator(
this, generators_,
false);
761 return new Iterator(
this, generators_,
true);
767 template <
size_t... I>
768 class IteratorImpl<IndexSequence<I...>>
774 begin_(std::get<I>(generators).begin()...),
775 end_(std::get<I>(generators).end()...),
776 current_(is_end ? end_ : begin_) {
777 ComputeCurrentValue();
779 ~IteratorImpl()
override {}
786 void Advance()
override {
789 ++std::get<
sizeof...(T) - 1>(current_);
791 AdvanceIfEnd<
sizeof...(T) - 1>();
792 ComputeCurrentValue();
795 return new IteratorImpl(*
this);
798 const ParamType* Current()
const override {
return current_value_.get(); }
804 <<
"The program attempted to compare iterators " 805 <<
"from different generators." << std::endl;
806 const IteratorImpl* typed_other =
807 CheckedDowncastToActualType<const IteratorImpl>(&other);
812 if (AtEnd() && typed_other->AtEnd())
return true;
816 (same = same && std::get<I>(current_) ==
817 std::get<I>(typed_other->current_))...};
823 template <
size_t ThisI>
824 void AdvanceIfEnd() {
825 if (std::get<ThisI>(current_) != std::get<ThisI>(end_))
return;
827 bool last = ThisI == 0;
833 constexpr
size_t NextI = ThisI - (ThisI != 0);
834 std::get<ThisI>(current_) = std::get<ThisI>(begin_);
835 ++std::get<NextI>(current_);
836 AdvanceIfEnd<NextI>();
839 void ComputeCurrentValue() {
841 current_value_ = std::make_shared<ParamType>(*std::get<I>(current_)...);
846 (at_end = at_end || std::get<I>(current_) == std::get<I>(end_))...};
852 std::tuple<typename ParamGenerator<T>::iterator...> begin_;
853 std::tuple<typename ParamGenerator<T>::iterator...> end_;
854 std::tuple<typename ParamGenerator<T>::iterator...> current_;
855 std::shared_ptr<ParamType> current_value_;
860 std::tuple<ParamGenerator<T>...> generators_;
863 template <
class... Gen>
867 template <
typename... T>
874 std::tuple<Gen...> generators_;
880 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ void TestNotEmpty(const T &)
Definition: gtest-param-util.h:385
ParamType param
Definition: gtest-param-util.h:60
iterator end() const
Definition: gtest-param-util.h:194
virtual ~ParamIteratorInterface()
Definition: gtest-param-util.h:93
Definition: gmock-actions.h:59
Definition: gtest-param-util.h:205
void RegisterTests()
Definition: gtest-param-util.h:694
TypeId GetTestSuiteTypeId() const override
Definition: gtest-param-util.h:502
bool operator==(const ParamIterator &other) const
Definition: gtest-param-util.h:148
~ParameterizedTestSuiteRegistry()
Definition: gtest-param-util.h:657
~CartesianProductGenerator() override
Definition: gtest-param-util.h:755
ParamIteratorInterface< T > * End() const override
Definition: gtest-param-util.h:215
::std::string PrintToString(const T &value)
Definition: gtest-printers.h:914
T ParamType
Definition: gtest-param-util.h:166
Definition: gtest-internal.h:503
Definition: gtest-param-util.h:290
size_t index
Definition: gtest-param-util.h:61
void AddTestPattern(const char *test_suite_name, const char *test_base_name, TestMetaFactoryBase< ParamType > *meta_factory)
Definition: gtest-param-util.h:509
TestParamInfo(const ParamType &a_param, size_t an_index)
Definition: gtest-param-util.h:57
CartesianProductHolder(const Gen &...g)
Definition: gtest-param-util.h:866
#define GTEST_API_
Definition: gtest-port.h:759
ParamGenerator(const ParamGenerator &other)
Definition: gtest-param-util.h:186
RangeGenerator(T begin, T end, IncrementT step)
Definition: gtest-param-util.h:207
int i
Definition: gmock-matchers_test.cc:711
Definition: gtest-param-util.h:56
ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end)
Definition: gtest-param-util.h:293
Definition: gtest-message.h:90
Definition: gtest-internal.h:440
ParamIterator(const ParamIterator &other)
Definition: gtest-param-util.h:128
Test * CreateTest() override
Definition: gtest-param-util.h:397
ParamIteratorInterface< T > * Begin() const override
Definition: gtest-param-util.h:297
virtual ~ParameterizedTestSuiteInfoBase()
Definition: gtest-param-util.h:456
ParameterizedTestSuiteRegistry()
Definition: gtest-param-util.h:656
GTEST_API_ void ReportInvalidTestSuiteType(const char *test_suite_name, CodeLocation code_location)
Definition: gtest.cc:2607
const void * TypeId
Definition: gtest-internal.h:405
void RegisterTests() override
Definition: gtest-param-util.h:529
Definition: gtest-internal.h:480
int AddTestSuiteInstantiation(const std::string &instantiation_name, GeneratorCreationFunc *func, ParamNameGeneratorFunc *name_func, const char *file, int line)
Definition: gtest-param-util.h:516
Definition: gtest-param-util.h:483
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)
Definition: gtest.cc:2595
#define GTEST_CHECK_(condition)
Definition: gtest-port.h:1014
~RangeGenerator() override
Definition: gtest-param-util.h:210
Definition: gtest-param-util.h:392
TestClass::ParamType ParamType
Definition: gtest-param-util.h:394
ParameterizedTestSuiteInfoBase()
Definition: gtest-param-util.h:469
ParamIterator operator++(int)
Definition: gtest-param-util.h:143
ptrdiff_t difference_type
Definition: gtest-param-util.h:125
std::string(const TestParamInfo< ParamType > &) ParamNameGeneratorFunc
Definition: gtest-param-util.h:491
virtual ~ParamGeneratorInterface()
Definition: gtest-param-util.h:168
ParamIterator< T > iterator
Definition: gtest-param-util.h:183
bool operator!=(const ParamIterator &other) const
Definition: gtest-param-util.h:151
CartesianProductGenerator(const std::tuple< ParamGenerator< T >... > &g)
Definition: gtest-param-util.h:753
ParameterizedTestSuiteInfo(const char *name, CodeLocation code_location)
Definition: gtest-param-util.h:493
Definition: gtest-param-util.h:654
std::string GetString() const
Definition: gtest.cc:996
Definition: gtest-internal.h:1172
Definition: gtest-internal.h:1153
const T & reference
Definition: gtest-param-util.h:124
Definition: gtest-param-util.h:454
ParameterizedTestSuiteInfo< TestSuite > * GetTestSuitePatternHolder(const char *test_suite_name, CodeLocation code_location)
Definition: gtest-param-util.h:666
::std::tuple< T... > ParamType
Definition: gtest-param-util.h:751
std::string operator()(const TestParamInfo< ParamType > &info) const
Definition: gtest-param-util.h:68
int value
Definition: gmock-matchers_test.cc:657
std::string DefaultParamName(const TestParamInfo< ParamType > &info)
Definition: gtest-param-util.h:374
virtual const ParamGeneratorInterface< T > * BaseGenerator() const =0
Definition: gtest-param-util.h:729
ParamIteratorInterface< T > * Begin() const override
Definition: gtest-param-util.h:212
const T * operator->() const
Definition: gtest-param-util.h:136
type
Definition: upload.py:443
ParameterizedTestFactory(ParamType parameter)
Definition: gtest-param-util.h:395
ParamIteratorInterface< T > * End() const override
Definition: gtest-param-util.h:300
void Abort()
Definition: gtest-port.h:2133
ParamGenerator & operator=(const ParamGenerator &other)
Definition: gtest-param-util.h:188
Definition: gtest-param-util.h:91
Definition: gtest-param-util.h:864
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition: gtest-port.h:688
ParamIteratorInterface< ParamType > * Begin() const override
Definition: gtest-param-util.h:757
ParameterizedTestCaseInfo< TestCase > * GetTestCasePatternHolder(const char *test_case_name, CodeLocation code_location)
Definition: gtest-param-util.h:702
Definition: gtest-param-util.h:121
~ValuesInIteratorRangeGenerator() override
Definition: gtest-param-util.h:295
Definition: gtest-param-util.h:748
const std::string & GetTestSuiteName() const override
Definition: gtest-param-util.h:498
Definition: gtest-param-util.h:85
virtual ParamIteratorInterface * Clone() const =0
const T & operator*() const
Definition: gtest-param-util.h:135
ParamGenerator(ParamGeneratorInterface< T > *impl)
Definition: gtest-param-util.h:185
Definition: gtest-internal.h:1200
Definition: gtest-param-util.h:86
internal::ParamGenerator< typename::testing::internal::IteratorTraits< ForwardIterator >::value_type > ValuesIn(ForwardIterator begin, ForwardIterator end)
Definition: gtest-param-test.h:296
Derived * CheckedDowncastToActualType(Base *base)
Definition: gtest-port.h:1135
typename TestSuite::ParamType ParamType
Definition: gtest-param-util.h:488
ParamIterator & operator=(const ParamIterator &other)
Definition: gtest-param-util.h:129
ValueArray(Ts...v)
Definition: gtest-param-util.h:731
T value_type
Definition: gtest-param-util.h:123
ParamIteratorInterface< ParamType > * End() const override
Definition: gtest-param-util.h:760
Definition: gtest-param-util.h:66
ParamIterator & operator++()
Definition: gtest-param-util.h:138
iterator begin() const
Definition: gtest-param-util.h:193