sample7_unittest.cc (googletest-release-1.11.0) | : | sample7_unittest.cc (googletest-release-1.12.0) | ||
---|---|---|---|---|
skipping to change at line 38 | skipping to change at line 38 | |||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
// This sample shows how to test common properties of multiple | // This sample shows how to test common properties of multiple | |||
// implementations of an interface (aka interface tests) using | // implementations of an interface (aka interface tests) using | |||
// value-parameterized tests. Each test in the test case has | // value-parameterized tests. Each test in the test case has | |||
// a parameter that is an interface pointer to an implementation | // a parameter that is an interface pointer to an implementation | |||
// tested. | // tested. | |||
// The interface and its implementations are in this header. | // The interface and its implementations are in this header. | |||
#include "prime_tables.h" | #include "prime_tables.h" | |||
#include "gtest/gtest.h" | #include "gtest/gtest.h" | |||
namespace { | namespace { | |||
using ::testing::TestWithParam; | using ::testing::TestWithParam; | |||
using ::testing::Values; | using ::testing::Values; | |||
// As a general rule, to prevent a test from affecting the tests that come | // As a general rule, to prevent a test from affecting the tests that come | |||
// after it, you should create and destroy the tested objects for each test | // after it, you should create and destroy the tested objects for each test | |||
// instead of reusing them. In this sample we will define a simple factory | // instead of reusing them. In this sample we will define a simple factory | |||
// function for PrimeTable objects. We will instantiate objects in test's | // function for PrimeTable objects. We will instantiate objects in test's | |||
// SetUp() method and delete them in TearDown() method. | // SetUp() method and delete them in TearDown() method. | |||
typedef PrimeTable* CreatePrimeTableFunc(); | typedef PrimeTable* CreatePrimeTableFunc(); | |||
PrimeTable* CreateOnTheFlyPrimeTable() { | PrimeTable* CreateOnTheFlyPrimeTable() { return new OnTheFlyPrimeTable(); } | |||
return new OnTheFlyPrimeTable(); | ||||
} | ||||
template <size_t max_precalculated> | template <size_t max_precalculated> | |||
PrimeTable* CreatePreCalculatedPrimeTable() { | PrimeTable* CreatePreCalculatedPrimeTable() { | |||
return new PreCalculatedPrimeTable(max_precalculated); | return new PreCalculatedPrimeTable(max_precalculated); | |||
} | } | |||
// Inside the test body, fixture constructor, SetUp(), and TearDown() you | // Inside the test body, fixture constructor, SetUp(), and TearDown() you | |||
// can refer to the test parameter by GetParam(). In this case, the test | // can refer to the test parameter by GetParam(). In this case, the test | |||
// parameter is a factory function which we call in fixture's SetUp() to | // parameter is a factory function which we call in fixture's SetUp() to | |||
// create and store an instance of PrimeTable. | // create and store an instance of PrimeTable. | |||
End of changes. 2 change blocks. | ||||
4 lines changed or deleted | 1 lines changed or added |