34#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
35#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
53template <
class ParamType>
65 template <
class ParamType>
80 CodeLocation code_location);
82template <
typename>
class ParamGeneratorInterface;
83template <
typename>
class ParamGenerator;
128 impl_.reset(other.impl_->Clone());
146 return impl_.get() == other.impl_.get() || impl_->Equals(*other.impl_);
149 return !(*
this == other);
155 scoped_ptr<ParamIteratorInterface<T> > impl_;
201template <
typename T,
typename IncrementT>
205 : begin_(begin), end_(end),
206 step_(step), end_index_(CalculateEndIndex(begin, end, step)) {}
210 return new Iterator(
this, begin_, 0, step_);
213 return new Iterator(
this, end_, end_index_, step_);
221 : base_(base), value_(
value), index_(index), step_(step) {}
222 virtual ~Iterator() {}
224 virtual const ParamGeneratorInterface<T>* BaseGenerator()
const {
227 virtual void Advance() {
228 value_ =
static_cast<T>(value_ + step_);
231 virtual ParamIteratorInterface<T>* Clone()
const {
232 return new Iterator(*
this);
234 virtual const T* Current()
const {
return &value_; }
235 virtual bool Equals(
const ParamIteratorInterface<T>& other)
const {
239 <<
"The program attempted to compare iterators "
240 <<
"from different generators." << std::endl;
241 const int other_index =
243 return index_ == other_index;
247 Iterator(
const Iterator& other)
248 : ParamIteratorInterface<
T>(),
250 step_(
other.step_) {}
253 void operator=(
const Iterator& other);
255 const ParamGeneratorInterface<T>*
const base_;
258 const IncrementT step_;
261 static int CalculateEndIndex(
const T& begin,
263 const IncrementT& step) {
265 for (
T i = begin; i < end; i = static_cast<T>(i + step))
275 const IncrementT step_;
278 const int end_index_;
289 template <
typename ForwardIterator>
291 : container_(begin, end) {}
295 return new Iterator(
this, container_.begin());
298 return new Iterator(
this, container_.end());
302 typedef typename ::std::vector<T> ContainerType;
307 typename ContainerType::const_iterator iterator)
308 : base_(base), iterator_(iterator) {}
309 virtual ~Iterator() {}
311 virtual const ParamGeneratorInterface<T>* BaseGenerator()
const {
314 virtual void Advance() {
318 virtual ParamIteratorInterface<T>* Clone()
const {
319 return new Iterator(*
this);
328 virtual const T* Current()
const {
329 if (value_.
get() == NULL)
330 value_.
reset(
new T(*iterator_));
333 virtual bool Equals(
const ParamIteratorInterface<T>& other)
const {
337 <<
"The program attempted to compare iterators "
338 <<
"from different generators." << std::endl;
344 Iterator(
const Iterator& other)
347 : ParamIteratorInterface<
T>(),
349 iterator_(
other.iterator_) {}
351 const ParamGeneratorInterface<T>*
const base_;
352 typename ContainerType::const_iterator iterator_;
358 mutable scoped_ptr<const T> value_;
364 const ContainerType container_;
371template <
class ParamType>
374 name_stream << info.index;
383template <
class ParamType,
class ParamNameGenFunctor>
388template <
class ParamType>
393template <
class ParamType>
402template <
class TestClass>
409 TestClass::SetParam(¶meter_);
423template <
class ParamType>
439template <
class TestCase>
493template <
class TestCase>
506 : test_case_name_(
name), code_location_(code_location) {}
519 const char* test_base_name,
528 GeneratorCreationFunc* func,
530 const char* file,
int line) {
531 instantiations_.push_back(
532 InstantiationInfo(instantiation_name, func, name_func, file, line));
541 for (
typename TestInfoContainer::iterator test_it = tests_.begin();
542 test_it != tests_.end(); ++test_it) {
544 for (
typename InstantiationContainer::iterator gen_it =
545 instantiations_.begin(); gen_it != instantiations_.end();
547 const std::string& instantiation_name = gen_it->name;
550 const char* file = gen_it->file;
551 int line = gen_it->line;
553 std::string test_case_name;
554 if ( !instantiation_name.empty() )
555 test_case_name = instantiation_name +
"/";
556 test_case_name += test_info->test_case_base_name;
559 std::set<std::string> test_param_names;
562 param_it != generator.
end(); ++param_it, ++i) {
565 std::string param_name = name_func(
569 <<
"Parameterized test name '" << param_name
570 <<
"' is invalid, in " << file
571 <<
" line " << line << std::endl;
574 <<
"Duplicate parameterized test name '" << param_name
575 <<
"', in " << file <<
" line " << line << std::endl;
577 test_param_names.insert(param_name);
579 test_name_stream << test_info->test_base_name <<
"/" << param_name;
581 test_case_name.c_str(),
584 PrintToString(*param_it).c_str(),
587 TestCase::SetUpTestCase,
588 TestCase::TearDownTestCase,
589 test_info->test_meta_factory->CreateTestFactory(*param_it));
599 TestInfo(
const char* a_test_case_base_name,
600 const char* a_test_base_name,
602 test_case_base_name(a_test_case_base_name),
603 test_base_name(a_test_base_name),
604 test_meta_factory(a_test_meta_factory) {}
606 const std::string test_case_base_name;
607 const std::string test_base_name;
608 const scoped_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
610 typedef ::std::vector<linked_ptr<TestInfo> > TestInfoContainer;
614 struct InstantiationInfo {
615 InstantiationInfo(
const std::string &name_in,
616 GeneratorCreationFunc* generator_in,
621 generator(generator_in),
622 name_func(name_func_in),
627 GeneratorCreationFunc* generator;
632 typedef ::std::vector<InstantiationInfo> InstantiationContainer;
634 static bool IsValidParamName(
const std::string&
name) {
640 for (std::string::size_type index = 0; index <
name.size(); ++index) {
641 if (!isalnum(
name[index]) &&
name[index] !=
'_')
648 const std::string test_case_name_;
649 CodeLocation code_location_;
650 TestInfoContainer tests_;
651 InstantiationContainer instantiations_;
666 for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
667 it != test_case_infos_.end(); ++it) {
674 template <
class TestCase>
676 const char* test_case_name,
679 for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
680 it != test_case_infos_.end(); ++it) {
681 if ((*it)->GetTestCaseName() == test_case_name) {
682 if ((*it)->GetTestCaseTypeId() != GetTypeId<TestCase>()) {
698 if (typed_test_info == NULL) {
700 test_case_name, code_location);
701 test_case_infos_.push_back(typed_test_info);
703 return typed_test_info;
706 for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
707 it != test_case_infos_.end(); ++it) {
708 (*it)->RegisterTests();
713 typedef ::std::vector<ParameterizedTestCaseInfoBase*> TestCaseInfoContainer;
715 TestCaseInfoContainer test_case_infos_;
std::string GetString() const
ParamGenerator(const ParamGenerator &other)
ParamGenerator(ParamGeneratorInterface< T > *impl)
ParamIterator< T > iterator
ParamGenerator & operator=(const ParamGenerator &other)
virtual ParamIteratorInterface< T > * End() const =0
virtual ~ParamGeneratorInterface()
virtual ParamIteratorInterface< T > * Begin() const =0
ptrdiff_t difference_type
const T & operator*() const
bool operator!=(const ParamIterator &other) const
ParamIterator & operator++()
ParamIterator(const ParamIterator &other)
const T * operator->() const
ParamIterator & operator=(const ParamIterator &other)
bool operator==(const ParamIterator &other) const
ParamIterator operator++(int)
virtual ParamIteratorInterface * Clone() const =0
virtual const ParamGeneratorInterface< T > * BaseGenerator() const =0
virtual const T * Current() const =0
virtual bool Equals(const ParamIteratorInterface &other) const =0
virtual ~ParamIteratorInterface()
ParameterizedTestCaseInfoBase()
virtual const std::string & GetTestCaseName() const =0
virtual void RegisterTests()=0
virtual TypeId GetTestCaseTypeId() const =0
virtual ~ParameterizedTestCaseInfoBase()
virtual TypeId GetTestCaseTypeId() const
typedef ParamGenerator(GeneratorCreationFunc)()
void AddTestPattern(const char *test_case_name, const char *test_base_name, TestMetaFactoryBase< ParamType > *meta_factory)
ParamNameGenFunc< ParamType >::Type ParamNameGeneratorFunc
ParameterizedTestCaseInfo(const char *name, CodeLocation code_location)
TestCase::ParamType ParamType
virtual void RegisterTests()
virtual const std::string & GetTestCaseName() const
int AddTestCaseInstantiation(const std::string &instantiation_name, GeneratorCreationFunc *func, ParamNameGeneratorFunc *name_func, const char *file, int line)
~ParameterizedTestCaseRegistry()
ParameterizedTestCaseRegistry()
ParameterizedTestCaseInfo< TestCase > * GetTestCasePatternHolder(const char *test_case_name, CodeLocation code_location)
virtual Test * CreateTest()
ParameterizedTestFactory(ParamType parameter)
TestClass::ParamType ParamType
virtual ParamIteratorInterface< T > * Begin() const
virtual ParamIteratorInterface< T > * End() const
RangeGenerator(T begin, T end, IncrementT step)
virtual ~RangeGenerator()
virtual ParamIteratorInterface< T > * Begin() const
virtual ParamIteratorInterface< T > * End() const
ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end)
virtual ~ValuesInIteratorRangeGenerator()
#define GTEST_CHECK_(condition)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
GTEST_API_ TestInfo * MakeAndRegisterTestInfo(const char *test_case_name, const char *name, const char *type_param, const char *value_param, CodeLocation code_location, TypeId fixture_class_id, SetUpTestCaseFunc set_up_tc, TearDownTestCaseFunc tear_down_tc, TestFactoryBase *factory)
std::string DefaultParamName(const TestParamInfo< ParamType > &info)
GTEST_API_ void ReportInvalidTestCaseType(const char *test_case_name, CodeLocation code_location)
ParamNameGenFunc< ParamType >::Type * GetParamNameGen()
Derived * CheckedDowncastToActualType(Base *base)
::std::string PrintToString(const T &value)
#define T(meth, val, expected)
std::string operator()(const TestParamInfo< ParamType > &info) const
TestParamInfo(const ParamType &a_param, size_t an_index)
std::string Type(const TestParamInfo< ParamType > &)