diff options
Diffstat (limited to 'include/gtest/gtest.h')
-rw-r--r-- | include/gtest/gtest.h | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/include/gtest/gtest.h b/include/gtest/gtest.h index 6ce58d72..f7ed948b 100644 --- a/include/gtest/gtest.h +++ b/include/gtest/gtest.h @@ -1589,9 +1589,13 @@ class GTEST_API_ AssertHelper { } // namespace internal #if GTEST_HAS_PARAM_TEST -// The abstract base class that all value-parameterized tests inherit from. +// The pure interface class that all value-parameterized tests inherit from. +// A value-parameterized class must inherit from both ::testing::Test and +// ::testing::WithParamInterface. In most cases that just means inheriting +// from ::testing::TestWithParam, but more complicated test hierarchies +// may need to inherit from Test and WithParamInterface at different levels. // -// This class adds support for accessing the test parameter value via +// This interface has support for accessing the test parameter value via // the GetParam() method. // // Use it with one of the parameter generator defining functions, like Range(), @@ -1620,12 +1624,16 @@ class GTEST_API_ AssertHelper { // INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10)); template <typename T> -class TestWithParam : public Test { +class WithParamInterface { public: typedef T ParamType; + virtual ~WithParamInterface() {} // The current parameter value. Is also available in the test fixture's - // constructor. + // constructor. This member function is non-static, even though it only + // references static data, to reduce the opportunity for incorrect uses + // like writing 'WithParamInterface<bool>::GetParam()' for a test that + // uses a fixture whose parameter type is int. const ParamType& GetParam() const { return *parameter_; } private: @@ -1638,12 +1646,19 @@ class TestWithParam : public Test { // Static value used for accessing parameter during a test lifetime. static const ParamType* parameter_; - // TestClass must be a subclass of TestWithParam<T>. + // TestClass must be a subclass of WithParamInterface<T> and Test. template <class TestClass> friend class internal::ParameterizedTestFactory; }; template <typename T> -const T* TestWithParam<T>::parameter_ = NULL; +const T* WithParamInterface<T>::parameter_ = NULL; + +// Most value-parameterized classes can ignore the existence of +// WithParamInterface, and can just inherit from ::testing::TestWithParam. + +template <typename T> +class TestWithParam : public Test, public WithParamInterface<T> { +}; #endif // GTEST_HAS_PARAM_TEST |