diff options
author | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2010-12-06 22:18:59 +0000 |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2010-12-06 22:18:59 +0000 |
commit | 915129ee6fd4d9c5564aafedb238a237592a3d42 (patch) | |
tree | 2995f382edd65f2a7e095a8868d45f22cb60d063 /include/gtest/gtest-param-test.h | |
parent | b5eb6ed9e27b7bf80a406e4a38ffe42db43889cc (diff) | |
download | googletest-915129ee6fd4d9c5564aafedb238a237592a3d42.tar.gz googletest-915129ee6fd4d9c5564aafedb238a237592a3d42.tar.bz2 googletest-915129ee6fd4d9c5564aafedb238a237592a3d42.zip |
Allows a value-parameterized test fixture to derive from Test and WithParamInterface<T> separately; contributed by Matt Austern.
Diffstat (limited to 'include/gtest/gtest-param-test.h')
-rw-r--r-- | include/gtest/gtest-param-test.h | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/include/gtest/gtest-param-test.h b/include/gtest/gtest-param-test.h index fb6ec8f5..9a92303b 100644 --- a/include/gtest/gtest-param-test.h +++ b/include/gtest/gtest-param-test.h @@ -1,4 +1,6 @@ -// This file was GENERATED by a script. DO NOT EDIT BY HAND!!! +// This file was GENERATED by command: +// pump.py gtest-param-test.h.pump +// DO NOT EDIT BY HAND!!! // Copyright 2008, Google Inc. // All rights reserved. @@ -48,10 +50,12 @@ #if 0 // To write value-parameterized tests, first you should define a fixture -// class. It must be derived from testing::TestWithParam<T>, where T is -// the type of your parameter values. TestWithParam<T> is itself derived -// from testing::Test. T can be any copyable type. If it's a raw pointer, -// you are responsible for managing the lifespan of the pointed values. +// class. It is usually derived from testing::TestWithParam<T> (see below for +// another inheritance scheme that's sometimes useful in more complicated +// class hierarchies), where the type of your parameter values. +// TestWithParam<T> is itself derived from testing::Test. T can be any +// copyable type. If it's a raw pointer, you are responsible for managing the +// lifespan of the pointed values. class FooTest : public ::testing::TestWithParam<const char*> { // You can implement all the usual class fixture members here. @@ -146,6 +150,32 @@ INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets)); // In the future, we plan to publish the API for defining new parameter // generators. But for now this interface remains part of the internal // implementation and is subject to change. +// +// +// A parameterized test fixture must be derived from testing::Test and from +// testing::WithParamInterface<T>, where T is the type of the parameter +// values. Inheriting from TestWithParam<T> satisfies that requirement because +// TestWithParam<T> inherits from both Test and WithParamInterface. In more +// complicated hierarchies, however, it is occasionally useful to inherit +// separately from Test and WithParamInterface. For example: + +class BaseTest : public ::testing::Test { + // You can inherit all the usual members for a non-parameterized test + // fixture here. +}; + +class DerivedTest : public BaseTest, public ::testing::WithParamInterface<int> { + // The usual test fixture members go here too. +}; + +TEST_F(BaseTest, HasFoo) { + // This is an ordinary non-parameterized test. +} + +TEST_P(DerivedTest, DoesBlah) { + // GetParam works just the same here as if you inherit from TestWithParam. + EXPECT_TRUE(foo.Blah(GetParam())); +} #endif // 0 |