gtest-param-util.h (googletest-release-1.11.0) | : | gtest-param-util.h (googletest-release-1.12.0) | ||
---|---|---|---|---|
skipping to change at line 32 | skipping to change at line 32 | |||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
// (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. | |||
// Type and function utilities for implementing parameterized tests. | // Type and function utilities for implementing parameterized tests. | |||
// GOOGLETEST_CM0001 DO NOT DELETE | // IWYU pragma: private, include "gtest/gtest.h" | |||
// IWYU pragma: friend gtest/.* | ||||
// IWYU pragma: friend gmock/.* | ||||
#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ | |||
#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ | |||
#include <ctype.h> | #include <ctype.h> | |||
#include <cassert> | #include <cassert> | |||
#include <iterator> | #include <iterator> | |||
#include <memory> | #include <memory> | |||
#include <set> | #include <set> | |||
#include <tuple> | #include <tuple> | |||
#include <type_traits> | #include <type_traits> | |||
#include <utility> | #include <utility> | |||
#include <vector> | #include <vector> | |||
#include "gtest/internal/gtest-internal.h" | ||||
#include "gtest/internal/gtest-port.h" | ||||
#include "gtest/gtest-printers.h" | #include "gtest/gtest-printers.h" | |||
#include "gtest/gtest-test-part.h" | #include "gtest/gtest-test-part.h" | |||
#include "gtest/internal/gtest-internal.h" | ||||
#include "gtest/internal/gtest-port.h" | ||||
namespace testing { | namespace testing { | |||
// Input to a parameterized test name generator, describing a test parameter. | // Input to a parameterized test name generator, describing a test parameter. | |||
// Consists of the parameter value and the integer parameter index. | // Consists of the parameter value and the integer parameter index. | |||
template <class ParamType> | template <class ParamType> | |||
struct TestParamInfo { | struct TestParamInfo { | |||
TestParamInfo(const ParamType& a_param, size_t an_index) : | TestParamInfo(const ParamType& a_param, size_t an_index) | |||
param(a_param), | : param(a_param), index(an_index) {} | |||
index(an_index) {} | ||||
ParamType param; | ParamType param; | |||
size_t index; | size_t index; | |||
}; | }; | |||
// A builtin parameterized test name generator which returns the result of | // A builtin parameterized test name generator which returns the result of | |||
// testing::PrintToString. | // testing::PrintToString. | |||
struct PrintToStringParamName { | struct PrintToStringParamName { | |||
template <class ParamType> | template <class ParamType> | |||
std::string operator()(const TestParamInfo<ParamType>& info) const { | std::string operator()(const TestParamInfo<ParamType>& info) const { | |||
return PrintToString(info.param); | return PrintToString(info.param); | |||
skipping to change at line 86 | skipping to change at line 87 | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. | // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. | |||
// Utility Functions | // Utility Functions | |||
// Outputs a message explaining invalid registration of different | // Outputs a message explaining invalid registration of different | |||
// fixture class for the same test suite. This may happen when | // fixture class for the same test suite. This may happen when | |||
// TEST_P macro is used to define two tests with the same name | // TEST_P macro is used to define two tests with the same name | |||
// but in different namespaces. | // but in different namespaces. | |||
GTEST_API_ void ReportInvalidTestSuiteType(const char* test_suite_name, | GTEST_API_ void ReportInvalidTestSuiteType(const char* test_suite_name, | |||
CodeLocation code_location); | CodeLocation code_location); | |||
template <typename> class ParamGeneratorInterface; | template <typename> | |||
template <typename> class ParamGenerator; | class ParamGeneratorInterface; | |||
template <typename> | ||||
class ParamGenerator; | ||||
// Interface for iterating over elements provided by an implementation | // Interface for iterating over elements provided by an implementation | |||
// of ParamGeneratorInterface<T>. | // of ParamGeneratorInterface<T>. | |||
template <typename T> | template <typename T> | |||
class ParamIteratorInterface { | class ParamIteratorInterface { | |||
public: | public: | |||
virtual ~ParamIteratorInterface() {} | virtual ~ParamIteratorInterface() {} | |||
// A pointer to the base generator instance. | // A pointer to the base generator instance. | |||
// Used only for the purposes of iterator comparison | // Used only for the purposes of iterator comparison | |||
// to make sure that two iterators belong to the same generator. | // to make sure that two iterators belong to the same generator. | |||
skipping to change at line 131 | skipping to change at line 134 | |||
template <typename T> | template <typename T> | |||
class ParamIterator { | class ParamIterator { | |||
public: | public: | |||
typedef T value_type; | typedef T value_type; | |||
typedef const T& reference; | typedef const T& reference; | |||
typedef ptrdiff_t difference_type; | typedef ptrdiff_t difference_type; | |||
// ParamIterator assumes ownership of the impl_ pointer. | // ParamIterator assumes ownership of the impl_ pointer. | |||
ParamIterator(const ParamIterator& other) : impl_(other.impl_->Clone()) {} | ParamIterator(const ParamIterator& other) : impl_(other.impl_->Clone()) {} | |||
ParamIterator& operator=(const ParamIterator& other) { | ParamIterator& operator=(const ParamIterator& other) { | |||
if (this != &other) | if (this != &other) impl_.reset(other.impl_->Clone()); | |||
impl_.reset(other.impl_->Clone()); | ||||
return *this; | return *this; | |||
} | } | |||
const T& operator*() const { return *impl_->Current(); } | const T& operator*() const { return *impl_->Current(); } | |||
const T* operator->() const { return impl_->Current(); } | const T* operator->() const { return impl_->Current(); } | |||
// Prefix version of operator++. | // Prefix version of operator++. | |||
ParamIterator& operator++() { | ParamIterator& operator++() { | |||
impl_->Advance(); | impl_->Advance(); | |||
return *this; | return *this; | |||
} | } | |||
skipping to change at line 159 | skipping to change at line 161 | |||
bool operator==(const ParamIterator& other) const { | bool operator==(const ParamIterator& other) const { | |||
return impl_.get() == other.impl_.get() || impl_->Equals(*other.impl_); | return impl_.get() == other.impl_.get() || impl_->Equals(*other.impl_); | |||
} | } | |||
bool operator!=(const ParamIterator& other) const { | bool operator!=(const ParamIterator& other) const { | |||
return !(*this == other); | return !(*this == other); | |||
} | } | |||
private: | private: | |||
friend class ParamGenerator<T>; | friend class ParamGenerator<T>; | |||
explicit ParamIterator(ParamIteratorInterface<T>* impl) : impl_(impl) {} | explicit ParamIterator(ParamIteratorInterface<T>* impl) : impl_(impl) {} | |||
std::unique_ptr<ParamIteratorInterface<T> > impl_; | std::unique_ptr<ParamIteratorInterface<T>> impl_; | |||
}; | }; | |||
// ParamGeneratorInterface<T> is the binary interface to access generators | // ParamGeneratorInterface<T> is the binary interface to access generators | |||
// defined in other translation units. | // defined in other translation units. | |||
template <typename T> | template <typename T> | |||
class ParamGeneratorInterface { | class ParamGeneratorInterface { | |||
public: | public: | |||
typedef T ParamType; | typedef T ParamType; | |||
virtual ~ParamGeneratorInterface() {} | virtual ~ParamGeneratorInterface() {} | |||
skipping to change at line 181 | skipping to change at line 183 | |||
// Generator interface definition | // Generator interface definition | |||
virtual ParamIteratorInterface<T>* Begin() const = 0; | virtual ParamIteratorInterface<T>* Begin() const = 0; | |||
virtual ParamIteratorInterface<T>* End() const = 0; | virtual ParamIteratorInterface<T>* End() const = 0; | |||
}; | }; | |||
// Wraps ParamGeneratorInterface<T> and provides general generator syntax | // Wraps ParamGeneratorInterface<T> and provides general generator syntax | |||
// compatible with the STL Container concept. | // compatible with the STL Container concept. | |||
// This class implements copy initialization semantics and the contained | // This class implements copy initialization semantics and the contained | |||
// ParamGeneratorInterface<T> instance is shared among all copies | // ParamGeneratorInterface<T> instance is shared among all copies | |||
// of the original object. This is possible because that instance is immutable. | // of the original object. This is possible because that instance is immutable. | |||
template<typename T> | template <typename T> | |||
class ParamGenerator { | class ParamGenerator { | |||
public: | public: | |||
typedef ParamIterator<T> iterator; | typedef ParamIterator<T> iterator; | |||
explicit ParamGenerator(ParamGeneratorInterface<T>* impl) : impl_(impl) {} | explicit ParamGenerator(ParamGeneratorInterface<T>* impl) : impl_(impl) {} | |||
ParamGenerator(const ParamGenerator& other) : impl_(other.impl_) {} | ParamGenerator(const ParamGenerator& other) : impl_(other.impl_) {} | |||
ParamGenerator& operator=(const ParamGenerator& other) { | ParamGenerator& operator=(const ParamGenerator& other) { | |||
impl_ = other.impl_; | impl_ = other.impl_; | |||
return *this; | return *this; | |||
} | } | |||
iterator begin() const { return iterator(impl_->Begin()); } | iterator begin() const { return iterator(impl_->Begin()); } | |||
iterator end() const { return iterator(impl_->End()); } | iterator end() const { return iterator(impl_->End()); } | |||
private: | private: | |||
std::shared_ptr<const ParamGeneratorInterface<T> > impl_; | std::shared_ptr<const ParamGeneratorInterface<T>> impl_; | |||
}; | }; | |||
// Generates values from a range of two comparable values. Can be used to | // Generates values from a range of two comparable values. Can be used to | |||
// generate sequences of user-defined types that implement operator+() and | // generate sequences of user-defined types that implement operator+() and | |||
// operator<(). | // operator<(). | |||
// This class is used in the Range() function. | // This class is used in the Range() function. | |||
template <typename T, typename IncrementT> | template <typename T, typename IncrementT> | |||
class RangeGenerator : public ParamGeneratorInterface<T> { | class RangeGenerator : public ParamGeneratorInterface<T> { | |||
public: | public: | |||
RangeGenerator(T begin, T end, IncrementT step) | RangeGenerator(T begin, T end, IncrementT step) | |||
: begin_(begin), end_(end), | : begin_(begin), | |||
step_(step), end_index_(CalculateEndIndex(begin, end, step)) {} | end_(end), | |||
step_(step), | ||||
end_index_(CalculateEndIndex(begin, end, step)) {} | ||||
~RangeGenerator() override {} | ~RangeGenerator() override {} | |||
ParamIteratorInterface<T>* Begin() const override { | ParamIteratorInterface<T>* Begin() const override { | |||
return new Iterator(this, begin_, 0, step_); | return new Iterator(this, begin_, 0, step_); | |||
} | } | |||
ParamIteratorInterface<T>* End() const override { | ParamIteratorInterface<T>* End() const override { | |||
return new Iterator(this, end_, end_index_, step_); | return new Iterator(this, end_, end_index_, step_); | |||
} | } | |||
private: | private: | |||
skipping to change at line 253 | skipping to change at line 257 | |||
<< "The program attempted to compare iterators " | << "The program attempted to compare iterators " | |||
<< "from different generators." << std::endl; | << "from different generators." << std::endl; | |||
const int other_index = | const int other_index = | |||
CheckedDowncastToActualType<const Iterator>(&other)->index_; | CheckedDowncastToActualType<const Iterator>(&other)->index_; | |||
return index_ == other_index; | return index_ == other_index; | |||
} | } | |||
private: | private: | |||
Iterator(const Iterator& other) | Iterator(const Iterator& other) | |||
: ParamIteratorInterface<T>(), | : ParamIteratorInterface<T>(), | |||
base_(other.base_), value_(other.value_), index_(other.index_), | base_(other.base_), | |||
value_(other.value_), | ||||
index_(other.index_), | ||||
step_(other.step_) {} | step_(other.step_) {} | |||
// No implementation - assignment is unsupported. | // No implementation - assignment is unsupported. | |||
void operator=(const Iterator& other); | void operator=(const Iterator& other); | |||
const ParamGeneratorInterface<T>* const base_; | const ParamGeneratorInterface<T>* const base_; | |||
T value_; | T value_; | |||
int index_; | int index_; | |||
const IncrementT step_; | const IncrementT step_; | |||
}; // class RangeGenerator::Iterator | }; // class RangeGenerator::Iterator | |||
static int CalculateEndIndex(const T& begin, | static int CalculateEndIndex(const T& begin, const T& end, | |||
const T& end, | ||||
const IncrementT& step) { | const IncrementT& step) { | |||
int end_index = 0; | int end_index = 0; | |||
for (T i = begin; i < end; i = static_cast<T>(i + step)) | for (T i = begin; i < end; i = static_cast<T>(i + step)) end_index++; | |||
end_index++; | ||||
return end_index; | return end_index; | |||
} | } | |||
// No implementation - assignment is unsupported. | // No implementation - assignment is unsupported. | |||
void operator=(const RangeGenerator& other); | void operator=(const RangeGenerator& other); | |||
const T begin_; | const T begin_; | |||
const T end_; | const T end_; | |||
const IncrementT step_; | const IncrementT step_; | |||
// The index for the end() iterator. All the elements in the generated | // The index for the end() iterator. All the elements in the generated | |||
skipping to change at line 342 | skipping to change at line 346 | |||
if (value_.get() == nullptr) value_.reset(new T(*iterator_)); | if (value_.get() == nullptr) value_.reset(new T(*iterator_)); | |||
return value_.get(); | return value_.get(); | |||
} | } | |||
bool Equals(const ParamIteratorInterface<T>& other) const override { | bool Equals(const ParamIteratorInterface<T>& other) const override { | |||
// Having the same base generator guarantees that the other | // Having the same base generator guarantees that the other | |||
// iterator is of the same type and we can downcast. | // iterator is of the same type and we can downcast. | |||
GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) | GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) | |||
<< "The program attempted to compare iterators " | << "The program attempted to compare iterators " | |||
<< "from different generators." << std::endl; | << "from different generators." << std::endl; | |||
return iterator_ == | return iterator_ == | |||
CheckedDowncastToActualType<const Iterator>(&other)->iterator_; | CheckedDowncastToActualType<const Iterator>(&other)->iterator_; | |||
} | } | |||
private: | private: | |||
Iterator(const Iterator& other) | Iterator(const Iterator& other) | |||
// The explicit constructor call suppresses a false warning | // The explicit constructor call suppresses a false warning | |||
// emitted by gcc when supplied with the -Wextra option. | // emitted by gcc when supplied with the -Wextra option. | |||
: ParamIteratorInterface<T>(), | : ParamIteratorInterface<T>(), | |||
base_(other.base_), | base_(other.base_), | |||
iterator_(other.iterator_) {} | iterator_(other.iterator_) {} | |||
const ParamGeneratorInterface<T>* const base_; | const ParamGeneratorInterface<T>* const base_; | |||
typename ContainerType::const_iterator iterator_; | typename ContainerType::const_iterator iterator_; | |||
// A cached value of *iterator_. We keep it here to allow access by | // A cached value of *iterator_. We keep it here to allow access by | |||
// pointer in the wrapping iterator's operator->(). | // pointer in the wrapping iterator's operator->(). | |||
// value_ needs to be mutable to be accessed in Current(). | // value_ needs to be mutable to be accessed in Current(). | |||
// Use of std::unique_ptr helps manage cached value's lifetime, | // Use of std::unique_ptr helps manage cached value's lifetime, | |||
skipping to change at line 395 | skipping to change at line 399 | |||
void TestNotEmpty(const T&) {} | void TestNotEmpty(const T&) {} | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. | // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. | |||
// | // | |||
// Stores a parameter value and later creates tests parameterized with that | // Stores a parameter value and later creates tests parameterized with that | |||
// value. | // value. | |||
template <class TestClass> | template <class TestClass> | |||
class ParameterizedTestFactory : public TestFactoryBase { | class ParameterizedTestFactory : public TestFactoryBase { | |||
public: | public: | |||
typedef typename TestClass::ParamType ParamType; | typedef typename TestClass::ParamType ParamType; | |||
explicit ParameterizedTestFactory(ParamType parameter) : | explicit ParameterizedTestFactory(ParamType parameter) | |||
parameter_(parameter) {} | : parameter_(parameter) {} | |||
Test* CreateTest() override { | Test* CreateTest() override { | |||
TestClass::SetParam(¶meter_); | TestClass::SetParam(¶meter_); | |||
return new TestClass(); | return new TestClass(); | |||
} | } | |||
private: | private: | |||
const ParamType parameter_; | const ParamType parameter_; | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestFactory); | ParameterizedTestFactory(const ParameterizedTestFactory&) = delete; | |||
ParameterizedTestFactory& operator=(const ParameterizedTestFactory&) = delete; | ||||
}; | }; | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. | // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. | |||
// | // | |||
// TestMetaFactoryBase is a base class for meta-factories that create | // TestMetaFactoryBase is a base class for meta-factories that create | |||
// test factories for passing into MakeAndRegisterTestInfo function. | // test factories for passing into MakeAndRegisterTestInfo function. | |||
template <class ParamType> | template <class ParamType> | |||
class TestMetaFactoryBase { | class TestMetaFactoryBase { | |||
public: | public: | |||
virtual ~TestMetaFactoryBase() {} | virtual ~TestMetaFactoryBase() {} | |||
skipping to change at line 441 | skipping to change at line 446 | |||
public: | public: | |||
using ParamType = typename TestSuite::ParamType; | using ParamType = typename TestSuite::ParamType; | |||
TestMetaFactory() {} | TestMetaFactory() {} | |||
TestFactoryBase* CreateTestFactory(ParamType parameter) override { | TestFactoryBase* CreateTestFactory(ParamType parameter) override { | |||
return new ParameterizedTestFactory<TestSuite>(parameter); | return new ParameterizedTestFactory<TestSuite>(parameter); | |||
} | } | |||
private: | private: | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestMetaFactory); | TestMetaFactory(const TestMetaFactory&) = delete; | |||
TestMetaFactory& operator=(const TestMetaFactory&) = delete; | ||||
}; | }; | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. | // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. | |||
// | // | |||
// ParameterizedTestSuiteInfoBase is a generic interface | // ParameterizedTestSuiteInfoBase is a generic interface | |||
// to ParameterizedTestSuiteInfo classes. ParameterizedTestSuiteInfoBase | // to ParameterizedTestSuiteInfo classes. ParameterizedTestSuiteInfoBase | |||
// accumulates test information provided by TEST_P macro invocations | // accumulates test information provided by TEST_P macro invocations | |||
// and generators provided by INSTANTIATE_TEST_SUITE_P macro invocations | // and generators provided by INSTANTIATE_TEST_SUITE_P macro invocations | |||
// and uses that information to register all resulting test instances | // and uses that information to register all resulting test instances | |||
// in RegisterTests method. The ParameterizeTestSuiteRegistry class holds | // in RegisterTests method. The ParameterizeTestSuiteRegistry class holds | |||
skipping to change at line 472 | skipping to change at line 478 | |||
// UnitTest class invokes this method to register tests in this | // UnitTest class invokes this method to register tests in this | |||
// test suite right before running them in RUN_ALL_TESTS macro. | // test suite right before running them in RUN_ALL_TESTS macro. | |||
// This method should not be called more than once on any single | // This method should not be called more than once on any single | |||
// instance of a ParameterizedTestSuiteInfoBase derived class. | // instance of a ParameterizedTestSuiteInfoBase derived class. | |||
virtual void RegisterTests() = 0; | virtual void RegisterTests() = 0; | |||
protected: | protected: | |||
ParameterizedTestSuiteInfoBase() {} | ParameterizedTestSuiteInfoBase() {} | |||
private: | private: | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfoBase); | ParameterizedTestSuiteInfoBase(const ParameterizedTestSuiteInfoBase&) = | |||
delete; | ||||
ParameterizedTestSuiteInfoBase& operator=( | ||||
const ParameterizedTestSuiteInfoBase&) = delete; | ||||
}; | }; | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. | // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. | |||
// | // | |||
// Report a the name of a test_suit as safe to ignore | // Report a the name of a test_suit as safe to ignore | |||
// as the side effect of construction of this type. | // as the side effect of construction of this type. | |||
struct GTEST_API_ MarkAsIgnored { | struct GTEST_API_ MarkAsIgnored { | |||
explicit MarkAsIgnored(const char* test_suite); | explicit MarkAsIgnored(const char* test_suite); | |||
}; | }; | |||
skipping to change at line 548 | skipping to change at line 557 | |||
// This method should not be called more than once on any single | // This method should not be called more than once on any single | |||
// instance of a ParameterizedTestSuiteInfoBase derived class. | // instance of a ParameterizedTestSuiteInfoBase derived class. | |||
// UnitTest has a guard to prevent from calling this method more than once. | // UnitTest has a guard to prevent from calling this method more than once. | |||
void RegisterTests() override { | void RegisterTests() override { | |||
bool generated_instantiations = false; | bool generated_instantiations = false; | |||
for (typename TestInfoContainer::iterator test_it = tests_.begin(); | for (typename TestInfoContainer::iterator test_it = tests_.begin(); | |||
test_it != tests_.end(); ++test_it) { | test_it != tests_.end(); ++test_it) { | |||
std::shared_ptr<TestInfo> test_info = *test_it; | std::shared_ptr<TestInfo> test_info = *test_it; | |||
for (typename InstantiationContainer::iterator gen_it = | for (typename InstantiationContainer::iterator gen_it = | |||
instantiations_.begin(); gen_it != instantiations_.end(); | instantiations_.begin(); | |||
++gen_it) { | gen_it != instantiations_.end(); ++gen_it) { | |||
const std::string& instantiation_name = gen_it->name; | const std::string& instantiation_name = gen_it->name; | |||
ParamGenerator<ParamType> generator((*gen_it->generator)()); | ParamGenerator<ParamType> generator((*gen_it->generator)()); | |||
ParamNameGeneratorFunc* name_func = gen_it->name_func; | ParamNameGeneratorFunc* name_func = gen_it->name_func; | |||
const char* file = gen_it->file; | const char* file = gen_it->file; | |||
int line = gen_it->line; | int line = gen_it->line; | |||
std::string test_suite_name; | std::string test_suite_name; | |||
if ( !instantiation_name.empty() ) | if (!instantiation_name.empty()) | |||
test_suite_name = instantiation_name + "/"; | test_suite_name = instantiation_name + "/"; | |||
test_suite_name += test_info->test_suite_base_name; | test_suite_name += test_info->test_suite_base_name; | |||
size_t i = 0; | size_t i = 0; | |||
std::set<std::string> test_param_names; | std::set<std::string> test_param_names; | |||
for (typename ParamGenerator<ParamType>::iterator param_it = | for (typename ParamGenerator<ParamType>::iterator param_it = | |||
generator.begin(); | generator.begin(); | |||
param_it != generator.end(); ++param_it, ++i) { | param_it != generator.end(); ++param_it, ++i) { | |||
generated_instantiations = true; | generated_instantiations = true; | |||
Message test_name_stream; | Message test_name_stream; | |||
std::string param_name = name_func( | std::string param_name = | |||
TestParamInfo<ParamType>(*param_it, i)); | name_func(TestParamInfo<ParamType>(*param_it, i)); | |||
GTEST_CHECK_(IsValidParamName(param_name)) | GTEST_CHECK_(IsValidParamName(param_name)) | |||
<< "Parameterized test name '" << param_name | << "Parameterized test name '" << param_name | |||
<< "' is invalid, in " << file | << "' is invalid, in " << file << " line " << line << std::endl; | |||
<< " line " << line << std::endl; | ||||
GTEST_CHECK_(test_param_names.count(param_name) == 0) | GTEST_CHECK_(test_param_names.count(param_name) == 0) | |||
<< "Duplicate parameterized test name '" << param_name | << "Duplicate parameterized test name '" << param_name << "', in " | |||
<< "', in " << file << " line " << line << std::endl; | << file << " line " << line << std::endl; | |||
test_param_names.insert(param_name); | test_param_names.insert(param_name); | |||
if (!test_info->test_base_name.empty()) { | if (!test_info->test_base_name.empty()) { | |||
test_name_stream << test_info->test_base_name << "/"; | test_name_stream << test_info->test_base_name << "/"; | |||
} | } | |||
test_name_stream << param_name; | test_name_stream << param_name; | |||
MakeAndRegisterTestInfo( | MakeAndRegisterTestInfo( | |||
test_suite_name.c_str(), test_name_stream.GetString().c_str(), | test_suite_name.c_str(), test_name_stream.GetString().c_str(), | |||
nullptr, // No type parameter. | nullptr, // No type parameter. | |||
PrintToString(*param_it).c_str(), test_info->code_location, | PrintToString(*param_it).c_str(), test_info->code_location, | |||
GetTestSuiteTypeId(), | GetTestSuiteTypeId(), | |||
SuiteApiResolver<TestSuite>::GetSetUpCaseOrSuite(file, line), | SuiteApiResolver<TestSuite>::GetSetUpCaseOrSuite(file, line), | |||
SuiteApiResolver<TestSuite>::GetTearDownCaseOrSuite(file, line), | SuiteApiResolver<TestSuite>::GetTearDownCaseOrSuite(file, line), | |||
test_info->test_meta_factory->CreateTestFactory(*param_it)); | test_info->test_meta_factory->CreateTestFactory(*param_it)); | |||
} // for param_it | } // for param_it | |||
} // for gen_it | } // for gen_it | |||
} // for test_it | } // for test_it | |||
if (!generated_instantiations) { | if (!generated_instantiations) { | |||
// There are no generaotrs, or they all generate nothing ... | // There are no generaotrs, or they all generate nothing ... | |||
InsertSyntheticTestCase(GetTestSuiteName(), code_location_, | InsertSyntheticTestCase(GetTestSuiteName(), code_location_, | |||
!tests_.empty()); | !tests_.empty()); | |||
} | } | |||
} // RegisterTests | } // RegisterTests | |||
private: | private: | |||
// LocalTestInfo structure keeps information about a single test registered | // LocalTestInfo structure keeps information about a single test registered | |||
// with TEST_P macro. | // with TEST_P macro. | |||
struct TestInfo { | struct TestInfo { | |||
TestInfo(const char* a_test_suite_base_name, const char* a_test_base_name, | TestInfo(const char* a_test_suite_base_name, const char* a_test_base_name, | |||
TestMetaFactoryBase<ParamType>* a_test_meta_factory, | TestMetaFactoryBase<ParamType>* a_test_meta_factory, | |||
CodeLocation a_code_location) | CodeLocation a_code_location) | |||
: test_suite_base_name(a_test_suite_base_name), | : test_suite_base_name(a_test_suite_base_name), | |||
test_base_name(a_test_base_name), | test_base_name(a_test_base_name), | |||
test_meta_factory(a_test_meta_factory), | test_meta_factory(a_test_meta_factory), | |||
code_location(a_code_location) {} | code_location(a_code_location) {} | |||
const std::string test_suite_base_name; | const std::string test_suite_base_name; | |||
const std::string test_base_name; | const std::string test_base_name; | |||
const std::unique_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory; | const std::unique_ptr<TestMetaFactoryBase<ParamType>> test_meta_factory; | |||
const CodeLocation code_location; | const CodeLocation code_location; | |||
}; | }; | |||
using TestInfoContainer = ::std::vector<std::shared_ptr<TestInfo> >; | using TestInfoContainer = ::std::vector<std::shared_ptr<TestInfo>>; | |||
// Records data received from INSTANTIATE_TEST_SUITE_P macros: | // Records data received from INSTANTIATE_TEST_SUITE_P macros: | |||
// <Instantiation name, Sequence generator creation function, | // <Instantiation name, Sequence generator creation function, | |||
// Name generator function, Source file, Source line> | // Name generator function, Source file, Source line> | |||
struct InstantiationInfo { | struct InstantiationInfo { | |||
InstantiationInfo(const std::string &name_in, | InstantiationInfo(const std::string& name_in, | |||
GeneratorCreationFunc* generator_in, | GeneratorCreationFunc* generator_in, | |||
ParamNameGeneratorFunc* name_func_in, | ParamNameGeneratorFunc* name_func_in, const char* file_in, | |||
const char* file_in, | int line_in) | |||
int line_in) | : name(name_in), | |||
: name(name_in), | generator(generator_in), | |||
generator(generator_in), | name_func(name_func_in), | |||
name_func(name_func_in), | file(file_in), | |||
file(file_in), | line(line_in) {} | |||
line(line_in) {} | ||||
std::string name; | ||||
std::string name; | GeneratorCreationFunc* generator; | |||
GeneratorCreationFunc* generator; | ParamNameGeneratorFunc* name_func; | |||
ParamNameGeneratorFunc* name_func; | const char* file; | |||
const char* file; | int line; | |||
int line; | ||||
}; | }; | |||
typedef ::std::vector<InstantiationInfo> InstantiationContainer; | typedef ::std::vector<InstantiationInfo> InstantiationContainer; | |||
static bool IsValidParamName(const std::string& name) { | static bool IsValidParamName(const std::string& name) { | |||
// Check for empty string | // Check for empty string | |||
if (name.empty()) | if (name.empty()) return false; | |||
return false; | ||||
// Check for invalid characters | // Check for invalid characters | |||
for (std::string::size_type index = 0; index < name.size(); ++index) { | for (std::string::size_type index = 0; index < name.size(); ++index) { | |||
if (!IsAlNum(name[index]) && name[index] != '_') | if (!IsAlNum(name[index]) && name[index] != '_') return false; | |||
return false; | ||||
} | } | |||
return true; | return true; | |||
} | } | |||
const std::string test_suite_name_; | const std::string test_suite_name_; | |||
CodeLocation code_location_; | CodeLocation code_location_; | |||
TestInfoContainer tests_; | TestInfoContainer tests_; | |||
InstantiationContainer instantiations_; | InstantiationContainer instantiations_; | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfo); | ParameterizedTestSuiteInfo(const ParameterizedTestSuiteInfo&) = delete; | |||
ParameterizedTestSuiteInfo& operator=(const ParameterizedTestSuiteInfo&) = | ||||
delete; | ||||
}; // class ParameterizedTestSuiteInfo | }; // class ParameterizedTestSuiteInfo | |||
// 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_ | |||
template <class TestCase> | template <class TestCase> | |||
using ParameterizedTestCaseInfo = ParameterizedTestSuiteInfo<TestCase>; | using ParameterizedTestCaseInfo = ParameterizedTestSuiteInfo<TestCase>; | |||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. | // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. | |||
// | // | |||
skipping to change at line 710 | skipping to change at line 717 | |||
// Complain about incorrect usage of Google Test facilities | // Complain about incorrect usage of Google Test facilities | |||
// and terminate the program since we cannot guaranty correct | // and terminate the program since we cannot guaranty correct | |||
// test suite setup and tear-down in this case. | // test suite setup and tear-down in this case. | |||
ReportInvalidTestSuiteType(test_suite_name, code_location); | ReportInvalidTestSuiteType(test_suite_name, code_location); | |||
posix::Abort(); | posix::Abort(); | |||
} else { | } else { | |||
// At this point we are sure that the object we found is of the same | // At this point we are sure that the object we found is of the same | |||
// type we are looking for, so we downcast it to that type | // type we are looking for, so we downcast it to that type | |||
// without further checks. | // without further checks. | |||
typed_test_info = CheckedDowncastToActualType< | typed_test_info = CheckedDowncastToActualType< | |||
ParameterizedTestSuiteInfo<TestSuite> >(test_suite_info); | ParameterizedTestSuiteInfo<TestSuite>>(test_suite_info); | |||
} | } | |||
break; | break; | |||
} | } | |||
} | } | |||
if (typed_test_info == nullptr) { | if (typed_test_info == nullptr) { | |||
typed_test_info = new ParameterizedTestSuiteInfo<TestSuite>( | typed_test_info = new ParameterizedTestSuiteInfo<TestSuite>( | |||
test_suite_name, code_location); | test_suite_name, code_location); | |||
test_suite_infos_.push_back(typed_test_info); | test_suite_infos_.push_back(typed_test_info); | |||
} | } | |||
return typed_test_info; | return typed_test_info; | |||
skipping to change at line 742 | skipping to change at line 749 | |||
return GetTestSuitePatternHolder<TestCase>(test_case_name, code_location); | return GetTestSuitePatternHolder<TestCase>(test_case_name, code_location); | |||
} | } | |||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ | |||
private: | private: | |||
using TestSuiteInfoContainer = ::std::vector<ParameterizedTestSuiteInfoBase*>; | using TestSuiteInfoContainer = ::std::vector<ParameterizedTestSuiteInfoBase*>; | |||
TestSuiteInfoContainer test_suite_infos_; | TestSuiteInfoContainer test_suite_infos_; | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteRegistry); | ParameterizedTestSuiteRegistry(const ParameterizedTestSuiteRegistry&) = | |||
delete; | ||||
ParameterizedTestSuiteRegistry& operator=( | ||||
const ParameterizedTestSuiteRegistry&) = delete; | ||||
}; | }; | |||
// Keep track of what type-parameterized test suite are defined and | // Keep track of what type-parameterized test suite are defined and | |||
// where as well as which are intatiated. This allows susequently | // where as well as which are intatiated. This allows susequently | |||
// identifying suits that are defined but never used. | // identifying suits that are defined but never used. | |||
class TypeParameterizedTestSuiteRegistry { | class TypeParameterizedTestSuiteRegistry { | |||
public: | public: | |||
// Add a suite definition | // Add a suite definition | |||
void RegisterTestSuite(const char* test_suite_name, | void RegisterTestSuite(const char* test_suite_name, | |||
CodeLocation code_location); | CodeLocation code_location); | |||
skipping to change at line 837 | skipping to change at line 847 | |||
} | } | |||
private: | private: | |||
template <class I> | template <class I> | |||
class IteratorImpl; | class IteratorImpl; | |||
template <size_t... I> | template <size_t... I> | |||
class IteratorImpl<IndexSequence<I...>> | class IteratorImpl<IndexSequence<I...>> | |||
: public ParamIteratorInterface<ParamType> { | : public ParamIteratorInterface<ParamType> { | |||
public: | public: | |||
IteratorImpl(const ParamGeneratorInterface<ParamType>* base, | IteratorImpl(const ParamGeneratorInterface<ParamType>* base, | |||
const std::tuple<ParamGenerator<T>...>& generators, bool is_end) | const std::tuple<ParamGenerator<T>...>& generators, | |||
bool is_end) | ||||
: base_(base), | : base_(base), | |||
begin_(std::get<I>(generators).begin()...), | begin_(std::get<I>(generators).begin()...), | |||
end_(std::get<I>(generators).end()...), | end_(std::get<I>(generators).end()...), | |||
current_(is_end ? end_ : begin_) { | current_(is_end ? end_ : begin_) { | |||
ComputeCurrentValue(); | ComputeCurrentValue(); | |||
} | } | |||
~IteratorImpl() override {} | ~IteratorImpl() override {} | |||
const ParamGeneratorInterface<ParamType>* BaseGenerator() const override { | const ParamGeneratorInterface<ParamType>* BaseGenerator() const override { | |||
return base_; | return base_; | |||
End of changes. 35 change blocks. | ||||
66 lines changed or deleted | 77 lines changed or added |