11be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Copyright 2008, Google Inc. 21be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// All rights reserved. 31be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// 41be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Redistribution and use in source and binary forms, with or without 51be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// modification, are permitted provided that the following conditions are 61be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// met: 71be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// 81be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// * Redistributions of source code must retain the above copyright 91be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// notice, this list of conditions and the following disclaimer. 101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// * Redistributions in binary form must reproduce the above 111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// copyright notice, this list of conditions and the following disclaimer 121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// in the documentation and/or other materials provided with the 131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// distribution. 141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// * Neither the name of Google Inc. nor the names of its 151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// contributors may be used to endorse or promote products derived from 161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// this software without specific prior written permission. 171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// 181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// 301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Author: vladl@google.com (Vlad Losev) 311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// 321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests for Google Test itself. This file verifies that the parameter 331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// generators objects produce correct parameter sequences and that 341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Google Test runtime instantiates correct tests from those sequences. 351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "gtest/gtest.h" 371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#if GTEST_HAS_PARAM_TEST 391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# include <algorithm> 4141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# include <iostream> 4241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# include <list> 4341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# include <sstream> 4441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# include <string> 4541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# include <vector> 461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// To include gtest-internal-inl.h. 4841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# define GTEST_IMPLEMENTATION_ 1 4941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# include "src/gtest-internal-inl.h" // for UnitTestOptions 5041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# undef GTEST_IMPLEMENTATION_ 511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 5241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# include "test/gtest-param-test_test.h" 531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing ::std::vector; 551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing ::std::sort; 561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing ::testing::AddGlobalTestEnvironment; 581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing ::testing::Bool; 591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing ::testing::Message; 601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing ::testing::Range; 611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing ::testing::TestWithParam; 621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing ::testing::Values; 631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing ::testing::ValuesIn; 641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# if GTEST_HAS_COMBINE 661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing ::testing::Combine; 671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing ::std::tr1::get; 681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing ::std::tr1::make_tuple; 691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing ::std::tr1::tuple; 7041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# endif // GTEST_HAS_COMBINE 711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing ::testing::internal::ParamGenerator; 731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing ::testing::internal::UnitTestOptions; 741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 7541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Prints a value to a string. 7641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// 7741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// TODO(wan@google.com): remove PrintValue() when we move matchers and 7841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// EXPECT_THAT() from Google Mock to Google Test. At that time, we 7941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// can write EXPECT_THAT(x, Eq(y)) to compare two tuples x and y, as 8041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// EXPECT_THAT() and the matchers know how to print tuples. 8141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabottemplate <typename T> 8241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot::std::string PrintValue(const T& value) { 8341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot ::std::stringstream stream; 8441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot stream << value; 8541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return stream.str(); 8641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot} 8741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 8841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# if GTEST_HAS_COMBINE 8941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 9041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// These overloads allow printing tuples in our tests. We cannot 9141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// define an operator<< for tuples, as that definition needs to be in 9241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// the std namespace in order to be picked up by Google Test via 9341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Argument-Dependent Lookup, yet defining anything in the std 9441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// namespace in non-STL code is undefined behavior. 9541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 9641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabottemplate <typename T1, typename T2> 9741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot::std::string PrintValue(const tuple<T1, T2>& value) { 9841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot ::std::stringstream stream; 9941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot stream << "(" << get<0>(value) << ", " << get<1>(value) << ")"; 10041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return stream.str(); 10141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot} 10241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 10341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabottemplate <typename T1, typename T2, typename T3> 10441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot::std::string PrintValue(const tuple<T1, T2, T3>& value) { 10541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot ::std::stringstream stream; 10641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot stream << "(" << get<0>(value) << ", " << get<1>(value) 10741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << ", "<< get<2>(value) << ")"; 10841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return stream.str(); 10941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot} 11041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 11141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabottemplate <typename T1, typename T2, typename T3, typename T4, typename T5, 11241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot typename T6, typename T7, typename T8, typename T9, typename T10> 11341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot::std::string PrintValue( 11441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot const tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>& value) { 11541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot ::std::stringstream stream; 11641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot stream << "(" << get<0>(value) << ", " << get<1>(value) 11741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << ", "<< get<2>(value) << ", " << get<3>(value) 11841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << ", "<< get<4>(value) << ", " << get<5>(value) 11941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << ", "<< get<6>(value) << ", " << get<7>(value) 12041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << ", "<< get<8>(value) << ", " << get<9>(value) << ")"; 12141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return stream.str(); 12241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot} 12341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 12441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# endif // GTEST_HAS_COMBINE 12541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 1261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Verifies that a sequence generated by the generator and accessed 1271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// via the iterator object matches the expected one using Google Test 1281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// assertions. 1291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniatemplate <typename T, size_t N> 1301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniavoid VerifyGenerator(const ParamGenerator<T>& generator, 1311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const T (&expected_values)[N]) { 1321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania typename ParamGenerator<T>::iterator it = generator.begin(); 1331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania for (size_t i = 0; i < N; ++i) { 1341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ASSERT_FALSE(it == generator.end()) 1351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "At element " << i << " when accessing via an iterator " 13641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << "created with the copy constructor.\n"; 13741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot // We cannot use EXPECT_EQ() here as the values may be tuples, 13841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot // which don't support <<. 13941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot EXPECT_TRUE(expected_values[i] == *it) 14041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << "where i is " << i 14141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << ", expected_values[i] is " << PrintValue(expected_values[i]) 14241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << ", *it is " << PrintValue(*it) 14341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << ", and 'it' is an iterator created with the copy constructor.\n"; 1441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania it++; 1451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 1461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_TRUE(it == generator.end()) 1471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "At the presumed end of sequence when accessing via an iterator " 14841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << "created with the copy constructor.\n"; 1491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 1501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // Test the iterator assignment. The following lines verify that 1511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // the sequence accessed via an iterator initialized via the 1521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // assignment operator (as opposed to a copy constructor) matches 1531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // just the same. 1541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania it = generator.begin(); 1551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania for (size_t i = 0; i < N; ++i) { 1561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ASSERT_FALSE(it == generator.end()) 1571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "At element " << i << " when accessing via an iterator " 15841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << "created with the assignment operator.\n"; 15941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot EXPECT_TRUE(expected_values[i] == *it) 16041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << "where i is " << i 16141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << ", expected_values[i] is " << PrintValue(expected_values[i]) 16241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << ", *it is " << PrintValue(*it) 16341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << ", and 'it' is an iterator created with the copy constructor.\n"; 1641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania it++; 1651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 1661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_TRUE(it == generator.end()) 1671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "At the presumed end of sequence when accessing via an iterator " 16841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot << "created with the assignment operator.\n"; 1691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 1701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 1711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniatemplate <typename T> 1721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniavoid VerifyGeneratorIsEmpty(const ParamGenerator<T>& generator) { 1731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania typename ParamGenerator<T>::iterator it = generator.begin(); 1741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_TRUE(it == generator.end()); 1751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 1761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania it = generator.begin(); 1771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_TRUE(it == generator.end()); 1781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 1791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 1801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Generator tests. They test that each of the provided generator functions 1811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// generates an expected sequence of values. The general test pattern 1821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// instantiates a generator using one of the generator functions, 1831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// checks the sequence produced by the generator using its iterator API, 1841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// and then resets the iterator back to the beginning of the sequence 1851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// and checks the sequence again. 1861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 1871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that iterators produced by generator functions conform to the 1881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// ForwardIterator concept. 1891be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(IteratorTest, ParamIteratorConformsToForwardIteratorConcept) { 1901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen = Range(0, 10); 1911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ParamGenerator<int>::iterator it = gen.begin(); 1921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 1931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // Verifies that iterator initialization works as expected. 1941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ParamGenerator<int>::iterator it2 = it; 1951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_TRUE(*it == *it2) << "Initialized iterators must point to the " 1961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "element same as its source points to"; 1971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 1981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // Verifies that iterator assignment works as expected. 1991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania it++; 2001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_FALSE(*it == *it2); 2011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania it2 = it; 2021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_TRUE(*it == *it2) << "Assigned iterators must point to the " 2031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "element same as its source points to"; 2041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 2051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // Verifies that prefix operator++() returns *this. 2061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_EQ(&it, &(++it)) << "Result of the prefix operator++ must be " 2071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "refer to the original object"; 2081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 2091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // Verifies that the result of the postfix operator++ points to the value 2101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // pointed to by the original iterator. 2111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania int original_value = *it; // Have to compute it outside of macro call to be 2121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // unaffected by the parameter evaluation order. 2131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_EQ(original_value, *(it++)); 2141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 2151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // Verifies that prefix and postfix operator++() advance an iterator 2161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // all the same. 2171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania it2 = it; 2181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania it++; 2191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ++it2; 2201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_TRUE(*it == *it2); 2211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 2221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 2231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that Range() generates the expected sequence. 2241be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(RangeTest, IntRangeWithDefaultStep) { 2251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen = Range(0, 3); 2261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const int expected_values[] = {0, 1, 2}; 2271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 2281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 2291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 2301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Edge case. Tests that Range() generates the single element sequence 2311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// as expected when provided with range limits that are equal. 2321be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(RangeTest, IntRangeSingleValue) { 2331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen = Range(0, 1); 2341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const int expected_values[] = {0}; 2351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 2361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 2371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 2381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Edge case. Tests that Range() with generates empty sequence when 2391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// supplied with an empty range. 2401be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(RangeTest, IntRangeEmpty) { 2411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen = Range(0, 0); 2421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGeneratorIsEmpty(gen); 2431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 2441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 2451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that Range() with custom step (greater then one) generates 2461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// the expected sequence. 2471be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(RangeTest, IntRangeWithCustomStep) { 2481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen = Range(0, 9, 3); 2491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const int expected_values[] = {0, 3, 6}; 2501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 2511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 2521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 2531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that Range() with custom step (greater then one) generates 2541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// the expected sequence when the last element does not fall on the 2551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// upper range limit. Sequences generated by Range() must not have 2561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// elements beyond the range limits. 2571be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(RangeTest, IntRangeWithCustomStepOverUpperBound) { 2581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen = Range(0, 4, 3); 2591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const int expected_values[] = {0, 3}; 2601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 2611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 2621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 2631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Verifies that Range works with user-defined types that define 2641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// copy constructor, operator=(), operator+(), and operator<(). 2651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaclass DogAdder { 2661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania public: 26741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot explicit DogAdder(const char* a_value) : value_(a_value) {} 2681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania DogAdder(const DogAdder& other) : value_(other.value_.c_str()) {} 2691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 2701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania DogAdder operator=(const DogAdder& other) { 2711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (this != &other) 2721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania value_ = other.value_; 2731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return *this; 2741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 2751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania DogAdder operator+(const DogAdder& other) const { 2761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Message msg; 2771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania msg << value_.c_str() << other.value_.c_str(); 2781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return DogAdder(msg.GetString().c_str()); 2791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 2801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania bool operator<(const DogAdder& other) const { 2811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return value_ < other.value_; 2821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 2831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ::testing::internal::String& value() const { return value_; } 2841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 2851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania private: 2861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ::testing::internal::String value_; 2871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}; 2881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 2891be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(RangeTest, WorksWithACustomType) { 2901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<DogAdder> gen = 2911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Range(DogAdder("cat"), DogAdder("catdogdog"), DogAdder("dog")); 2921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ParamGenerator<DogAdder>::iterator it = gen.begin(); 2931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 2941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ASSERT_FALSE(it == gen.end()); 2951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_STREQ("cat", it->value().c_str()); 2961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 2971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ASSERT_FALSE(++it == gen.end()); 2981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_STREQ("catdog", it->value().c_str()); 2991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_TRUE(++it == gen.end()); 3011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 3021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaclass IntWrapper { 3041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania public: 30541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot explicit IntWrapper(int a_value) : value_(a_value) {} 3061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania IntWrapper(const IntWrapper& other) : value_(other.value_) {} 3071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania IntWrapper operator=(const IntWrapper& other) { 3091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania value_ = other.value_; 3101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return *this; 3111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 3121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // operator+() adds a different type. 3131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania IntWrapper operator+(int other) const { return IntWrapper(value_ + other); } 3141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania bool operator<(const IntWrapper& other) const { 3151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return value_ < other.value_; 3161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 3171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania int value() const { return value_; } 3181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania private: 3201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania int value_; 3211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}; 3221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3231be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(RangeTest, WorksWithACustomTypeWithDifferentIncrementType) { 3241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<IntWrapper> gen = Range(IntWrapper(0), IntWrapper(2)); 3251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ParamGenerator<IntWrapper>::iterator it = gen.begin(); 3261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ASSERT_FALSE(it == gen.end()); 3281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_EQ(0, it->value()); 3291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ASSERT_FALSE(++it == gen.end()); 3311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_EQ(1, it->value()); 3321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_TRUE(++it == gen.end()); 3341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 3351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that ValuesIn() with an array parameter generates 3371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// the expected sequence. 3381be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(ValuesInTest, ValuesInArray) { 3391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania int array[] = {3, 5, 8}; 3401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen = ValuesIn(array); 3411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, array); 3421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 3431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that ValuesIn() with a const array parameter generates 3451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// the expected sequence. 3461be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(ValuesInTest, ValuesInConstArray) { 3471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const int array[] = {3, 5, 8}; 3481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen = ValuesIn(array); 3491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, array); 3501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 3511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Edge case. Tests that ValuesIn() with an array parameter containing a 3531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// single element generates the single element sequence. 3541be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(ValuesInTest, ValuesInSingleElementArray) { 3551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania int array[] = {42}; 3561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen = ValuesIn(array); 3571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, array); 3581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 3591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that ValuesIn() generates the expected sequence for an STL 3611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// container (vector). 3621be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(ValuesInTest, ValuesInVector) { 3631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania typedef ::std::vector<int> ContainerType; 3641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ContainerType values; 3651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania values.push_back(3); 3661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania values.push_back(5); 3671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania values.push_back(8); 3681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen = ValuesIn(values); 3691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const int expected_values[] = {3, 5, 8}; 3711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 3721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 3731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that ValuesIn() generates the expected sequence. 3751be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(ValuesInTest, ValuesInIteratorRange) { 3761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania typedef ::std::vector<int> ContainerType; 3771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ContainerType values; 3781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania values.push_back(3); 3791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania values.push_back(5); 3801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania values.push_back(8); 3811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen = ValuesIn(values.begin(), values.end()); 3821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const int expected_values[] = {3, 5, 8}; 3841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 3851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 3861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Edge case. Tests that ValuesIn() provided with an iterator range specifying a 3881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// single value generates a single-element sequence. 3891be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(ValuesInTest, ValuesInSingleElementIteratorRange) { 3901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania typedef ::std::vector<int> ContainerType; 3911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ContainerType values; 3921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania values.push_back(42); 3931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen = ValuesIn(values.begin(), values.end()); 3941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const int expected_values[] = {42}; 3961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 3971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 3981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Edge case. Tests that ValuesIn() provided with an empty iterator range 4001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// generates an empty sequence. 4011be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(ValuesInTest, ValuesInEmptyIteratorRange) { 4021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania typedef ::std::vector<int> ContainerType; 4031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ContainerType values; 4041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen = ValuesIn(values.begin(), values.end()); 4051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGeneratorIsEmpty(gen); 4071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 4081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that the Values() generates the expected sequence. 4101be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(ValuesTest, ValuesWorks) { 4111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen = Values(3, 5, 8); 4121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const int expected_values[] = {3, 5, 8}; 4141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 4151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 4161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that Values() generates the expected sequences from elements of 4181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// different types convertible to ParamGenerator's parameter type. 4191be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(ValuesTest, ValuesWorksForValuesOfCompatibleTypes) { 4201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<double> gen = Values(3, 5.0f, 8.0); 4211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const double expected_values[] = {3.0, 5.0, 8.0}; 4231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 4241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 4251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4261be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(ValuesTest, ValuesWorksForMaxLengthList) { 4271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen = Values( 4281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 4291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 4301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 4311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 310, 320, 330, 340, 350, 360, 370, 380, 390, 400, 4321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 410, 420, 430, 440, 450, 460, 470, 480, 490, 500); 4331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const int expected_values[] = { 4351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 4361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 4371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 4381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 310, 320, 330, 340, 350, 360, 370, 380, 390, 400, 4391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 410, 420, 430, 440, 450, 460, 470, 480, 490, 500}; 4401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 4411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 4421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Edge case test. Tests that single-parameter Values() generates the sequence 4441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// with the single value. 4451be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(ValuesTest, ValuesWithSingleParameter) { 4461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen = Values(42); 4471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const int expected_values[] = {42}; 4491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 4501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 4511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that Bool() generates sequence (false, true). 4531be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(BoolTest, BoolWorks) { 4541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<bool> gen = Bool(); 4551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const bool expected_values[] = {false, true}; 4571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 4581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 4591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 46041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# if GTEST_HAS_COMBINE 4611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that Combine() with two parameters generates the expected sequence. 4631be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(CombineTest, CombineWithTwoParameters) { 4641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const char* foo = "foo"; 4651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const char* bar = "bar"; 4661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<tuple<const char*, int> > gen = 4671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Combine(Values(foo, bar), Values(3, 4)); 4681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania tuple<const char*, int> expected_values[] = { 4701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania make_tuple(foo, 3), make_tuple(foo, 4), 4711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania make_tuple(bar, 3), make_tuple(bar, 4)}; 4721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 4731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 4741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that Combine() with three parameters generates the expected sequence. 4761be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(CombineTest, CombineWithThreeParameters) { 4771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<tuple<int, int, int> > gen = Combine(Values(0, 1), 4781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Values(3, 4), 4791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Values(5, 6)); 4801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania tuple<int, int, int> expected_values[] = { 4811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania make_tuple(0, 3, 5), make_tuple(0, 3, 6), 4821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania make_tuple(0, 4, 5), make_tuple(0, 4, 6), 4831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania make_tuple(1, 3, 5), make_tuple(1, 3, 6), 4841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania make_tuple(1, 4, 5), make_tuple(1, 4, 6)}; 4851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 4861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 4871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that the Combine() with the first parameter generating a single value 4891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// sequence generates a sequence with the number of elements equal to the 4901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// number of elements in the sequence generated by the second parameter. 4911be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(CombineTest, CombineWithFirstParameterSingleValue) { 4921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<tuple<int, int> > gen = Combine(Values(42), 4931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Values(0, 1)); 4941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania tuple<int, int> expected_values[] = {make_tuple(42, 0), make_tuple(42, 1)}; 4961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 4971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 4981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that the Combine() with the second parameter generating a single value 5001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// sequence generates a sequence with the number of elements equal to the 5011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// number of elements in the sequence generated by the first parameter. 5021be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(CombineTest, CombineWithSecondParameterSingleValue) { 5031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<tuple<int, int> > gen = Combine(Values(0, 1), 5041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Values(42)); 5051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 5061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania tuple<int, int> expected_values[] = {make_tuple(0, 42), make_tuple(1, 42)}; 5071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 5081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 5091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 5101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that when the first parameter produces an empty sequence, 5111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Combine() produces an empty sequence, too. 5121be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(CombineTest, CombineWithFirstParameterEmptyRange) { 5131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<tuple<int, int> > gen = Combine(Range(0, 0), 5141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Values(0, 1)); 5151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGeneratorIsEmpty(gen); 5161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 5171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 5181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that when the second parameter produces an empty sequence, 5191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Combine() produces an empty sequence, too. 5201be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(CombineTest, CombineWithSecondParameterEmptyRange) { 5211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<tuple<int, int> > gen = Combine(Values(0, 1), 5221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Range(1, 1)); 5231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGeneratorIsEmpty(gen); 5241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 5251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 5261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Edge case. Tests that combine works with the maximum number 5271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// of parameters supported by Google Test (currently 10). 5281be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(CombineTest, CombineWithMaxNumberOfParameters) { 5291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const char* foo = "foo"; 5301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const char* bar = "bar"; 5311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<tuple<const char*, int, int, int, int, int, int, int, 5321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania int, int> > gen = Combine(Values(foo, bar), 5331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Values(1), Values(2), 5341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Values(3), Values(4), 5351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Values(5), Values(6), 5361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Values(7), Values(8), 5371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Values(9)); 5381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 5391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania tuple<const char*, int, int, int, int, int, int, int, int, int> 5401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania expected_values[] = {make_tuple(foo, 1, 2, 3, 4, 5, 6, 7, 8, 9), 5411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania make_tuple(bar, 1, 2, 3, 4, 5, 6, 7, 8, 9)}; 5421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 5431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 5441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 54541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot# endif // GTEST_HAS_COMBINE 5461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 5471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that an generator produces correct sequence after being 5481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// assigned from another generator. 5491be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(ParamGeneratorTest, AssignmentWorks) { 5501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ParamGenerator<int> gen = Values(1, 2); 5511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ParamGenerator<int> gen2 = Values(3, 4); 5521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania gen = gen2; 5531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 5541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const int expected_values[] = {3, 4}; 5551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania VerifyGenerator(gen, expected_values); 5561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 5571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 5581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This test verifies that the tests are expanded and run as specified: 5591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// one test per element from the sequence produced by the generator 5601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// specified in INSTANTIATE_TEST_CASE_P. It also verifies that the test's 5611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// fixture constructor, SetUp(), and TearDown() have run and have been 5621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// supplied with the correct parameters. 5631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 5641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The use of environment object allows detection of the case where no test 5651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// case functionality is run at all. In this case TestCaseTearDown will not 5661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// be able to detect missing tests, naturally. 5671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniatemplate <int kExpectedCalls> 5681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaclass TestGenerationEnvironment : public ::testing::Environment { 5691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania public: 5701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania static TestGenerationEnvironment* Instance() { 5711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania static TestGenerationEnvironment* instance = new TestGenerationEnvironment; 5721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return instance; 5731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 5741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 5751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania void FixtureConstructorExecuted() { fixture_constructor_count_++; } 5761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania void SetUpExecuted() { set_up_count_++; } 5771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania void TearDownExecuted() { tear_down_count_++; } 5781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania void TestBodyExecuted() { test_body_count_++; } 5791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 5801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania virtual void TearDown() { 5811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // If all MultipleTestGenerationTest tests have been de-selected 5821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // by the filter flag, the following checks make no sense. 5831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania bool perform_check = false; 5841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 5851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania for (int i = 0; i < kExpectedCalls; ++i) { 5861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Message msg; 5871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania msg << "TestsExpandedAndRun/" << i; 5881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (UnitTestOptions::FilterMatchesTest( 5891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania "TestExpansionModule/MultipleTestGenerationTest", 5901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania msg.GetString().c_str())) { 5911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania perform_check = true; 5921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 5931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 5941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (perform_check) { 5951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_EQ(kExpectedCalls, fixture_constructor_count_) 5961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "Fixture constructor of ParamTestGenerationTest test case " 5971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "has not been run as expected."; 5981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_EQ(kExpectedCalls, set_up_count_) 5991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "Fixture SetUp method of ParamTestGenerationTest test case " 6001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "has not been run as expected."; 6011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_EQ(kExpectedCalls, tear_down_count_) 6021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "Fixture TearDown method of ParamTestGenerationTest test case " 6031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "has not been run as expected."; 6041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_EQ(kExpectedCalls, test_body_count_) 6051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "Test in ParamTestGenerationTest test case " 6061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "has not been run as expected."; 6071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 6081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 6091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania private: 6101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania TestGenerationEnvironment() : fixture_constructor_count_(0), set_up_count_(0), 6111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania tear_down_count_(0), test_body_count_(0) {} 6121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania int fixture_constructor_count_; 6141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania int set_up_count_; 6151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania int tear_down_count_; 6161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania int test_body_count_; 6171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania GTEST_DISALLOW_COPY_AND_ASSIGN_(TestGenerationEnvironment); 6191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}; 6201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaconst int test_generation_params[] = {36, 42, 72}; 6221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaclass TestGenerationTest : public TestWithParam<int> { 6241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania public: 6251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania enum { 6261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania PARAMETER_COUNT = 6271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania sizeof(test_generation_params)/sizeof(test_generation_params[0]) 6281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania }; 6291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania typedef TestGenerationEnvironment<PARAMETER_COUNT> Environment; 6311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania TestGenerationTest() { 6331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Environment::Instance()->FixtureConstructorExecuted(); 6341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania current_parameter_ = GetParam(); 6351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 6361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania virtual void SetUp() { 6371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Environment::Instance()->SetUpExecuted(); 6381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_EQ(current_parameter_, GetParam()); 6391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 6401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania virtual void TearDown() { 6411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Environment::Instance()->TearDownExecuted(); 6421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_EQ(current_parameter_, GetParam()); 6431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 6441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania static void SetUpTestCase() { 6461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania bool all_tests_in_test_case_selected = true; 6471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania for (int i = 0; i < PARAMETER_COUNT; ++i) { 6491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Message test_name; 6501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania test_name << "TestsExpandedAndRun/" << i; 6511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if ( !UnitTestOptions::FilterMatchesTest( 6521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania "TestExpansionModule/MultipleTestGenerationTest", 6531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania test_name.GetString())) { 6541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania all_tests_in_test_case_selected = false; 6551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 6561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 6571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_TRUE(all_tests_in_test_case_selected) 6581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "When running the TestGenerationTest test case all of its tests\n" 6591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "must be selected by the filter flag for the test case to pass.\n" 6601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "If not all of them are enabled, we can't reliably conclude\n" 6611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "that the correct number of tests have been generated."; 6621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania collected_parameters_.clear(); 6641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 6651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania static void TearDownTestCase() { 6671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania vector<int> expected_values(test_generation_params, 6681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania test_generation_params + PARAMETER_COUNT); 6691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // Test execution order is not guaranteed by Google Test, 6701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // so the order of values in collected_parameters_ can be 6711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // different and we have to sort to compare. 6721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania sort(expected_values.begin(), expected_values.end()); 6731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania sort(collected_parameters_.begin(), collected_parameters_.end()); 6741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_TRUE(collected_parameters_ == expected_values); 6761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 6771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania protected: 6781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania int current_parameter_; 6791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania static vector<int> collected_parameters_; 6801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania private: 6821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania GTEST_DISALLOW_COPY_AND_ASSIGN_(TestGenerationTest); 6831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}; 6841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniavector<int> TestGenerationTest::collected_parameters_; 6851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6861be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST_P(TestGenerationTest, TestsExpandedAndRun) { 6871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Environment::Instance()->TestBodyExecuted(); 6881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_EQ(current_parameter_, GetParam()); 6891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania collected_parameters_.push_back(GetParam()); 6901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 6911be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaINSTANTIATE_TEST_CASE_P(TestExpansionModule, TestGenerationTest, 6921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ValuesIn(test_generation_params)); 6931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 6941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// This test verifies that the element sequence (third parameter of 69541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// INSTANTIATE_TEST_CASE_P) is evaluated in InitGoogleTest() and neither at 69641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// the call site of INSTANTIATE_TEST_CASE_P nor in RUN_ALL_TESTS(). For 69741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// that, we declare param_value_ to be a static member of 69841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// GeneratorEvaluationTest and initialize it to 0. We set it to 1 in 69941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// main(), just before invocation of InitGoogleTest(). After calling 70041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// InitGoogleTest(), we set the value to 2. If the sequence is evaluated 70141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// before or after InitGoogleTest, INSTANTIATE_TEST_CASE_P will create a 70241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// test with parameter other than 1, and the test body will fail the 70341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// assertion. 7041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaclass GeneratorEvaluationTest : public TestWithParam<int> { 7051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania public: 7061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania static int param_value() { return param_value_; } 7071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania static void set_param_value(int param_value) { param_value_ = param_value; } 7081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 7091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania private: 7101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania static int param_value_; 7111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}; 7121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaint GeneratorEvaluationTest::param_value_ = 0; 7131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 7141be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST_P(GeneratorEvaluationTest, GeneratorsEvaluatedInMain) { 7151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_EQ(1, GetParam()); 7161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 7171be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaINSTANTIATE_TEST_CASE_P(GenEvalModule, 7181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania GeneratorEvaluationTest, 7191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Values(GeneratorEvaluationTest::param_value())); 7201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 7211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that generators defined in a different translation unit are 7221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// functional. Generator extern_gen is defined in gtest-param-test_test2.cc. 7231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaextern ParamGenerator<int> extern_gen; 7241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaclass ExternalGeneratorTest : public TestWithParam<int> {}; 7251be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST_P(ExternalGeneratorTest, ExternalGenerator) { 7261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // Sequence produced by extern_gen contains only a single value 7271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // which we verify here. 7281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_EQ(GetParam(), 33); 7291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 7301be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaINSTANTIATE_TEST_CASE_P(ExternalGeneratorModule, 7311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ExternalGeneratorTest, 7321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania extern_gen); 7331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 7341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that a parameterized test case can be defined in one translation 7351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// unit and instantiated in another. This test will be instantiated in 7361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// gtest-param-test_test2.cc. ExternalInstantiationTest fixture class is 7371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// defined in gtest-param-test_test.h. 7381be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST_P(ExternalInstantiationTest, IsMultipleOf33) { 7391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_EQ(0, GetParam() % 33); 7401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 7411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 7421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that a parameterized test case can be instantiated with multiple 7431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// generators. 7441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaclass MultipleInstantiationTest : public TestWithParam<int> {}; 7451be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST_P(MultipleInstantiationTest, AllowsMultipleInstances) { 7461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 7471be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaINSTANTIATE_TEST_CASE_P(Sequence1, MultipleInstantiationTest, Values(1, 2)); 7481be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaINSTANTIATE_TEST_CASE_P(Sequence2, MultipleInstantiationTest, Range(3, 5)); 7491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 7501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that a parameterized test case can be instantiated 7511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// in multiple translation units. This test will be instantiated 7521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// here and in gtest-param-test_test2.cc. 7531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// InstantiationInMultipleTranslationUnitsTest fixture class 7541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// is defined in gtest-param-test_test.h. 7551be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST_P(InstantiationInMultipleTranslaionUnitsTest, IsMultipleOf42) { 7561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_EQ(0, GetParam() % 42); 7571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 7581be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaINSTANTIATE_TEST_CASE_P(Sequence1, 7591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania InstantiationInMultipleTranslaionUnitsTest, 7601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Values(42, 42*2)); 7611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 7621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that each iteration of parameterized test runs in a separate test 7631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// object. 7641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaclass SeparateInstanceTest : public TestWithParam<int> { 7651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania public: 7661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania SeparateInstanceTest() : count_(0) {} 7671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 7681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania static void TearDownTestCase() { 7691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_GE(global_count_, 2) 7701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "If some (but not all) SeparateInstanceTest tests have been " 7711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "filtered out this test will fail. Make sure that all " 7721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "GeneratorEvaluationTest are selected or de-selected together " 7731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << "by the test filter."; 7741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 7751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 7761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania protected: 7771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania int count_; 7781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania static int global_count_; 7791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}; 7801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaint SeparateInstanceTest::global_count_ = 0; 7811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 7821be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST_P(SeparateInstanceTest, TestsRunInSeparateInstances) { 7831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_EQ(0, count_++); 7841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania global_count_++; 7851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 7861be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaINSTANTIATE_TEST_CASE_P(FourElemSequence, SeparateInstanceTest, Range(1, 4)); 7871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 7881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests that all instantiations of a test have named appropriately. Test 7891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// defined with TEST_P(TestCaseName, TestName) and instantiated with 7901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// INSTANTIATE_TEST_CASE_P(SequenceName, TestCaseName, generator) must be named 7911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// SequenceName/TestCaseName.TestName/i, where i is the 0-based index of the 7921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// sequence element used to instantiate the test. 7931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaclass NamingTest : public TestWithParam<int> {}; 7941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 79541d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotTEST_P(NamingTest, TestsReportCorrectNamesAndParameters) { 7961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const ::testing::TestInfo* const test_info = 7971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ::testing::UnitTest::GetInstance()->current_test_info(); 7981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 7991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania EXPECT_STREQ("ZeroToFiveSequence/NamingTest", test_info->test_case_name()); 8001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 80141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot Message index_stream; 80241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot index_stream << "TestsReportCorrectNamesAndParameters/" << GetParam(); 80341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot EXPECT_STREQ(index_stream.GetString().c_str(), test_info->name()); 80441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 80541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot EXPECT_EQ(::testing::PrintToString(GetParam()), test_info->value_param()); 8061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 8071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 8081be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaINSTANTIATE_TEST_CASE_P(ZeroToFiveSequence, NamingTest, Range(0, 5)); 8091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 81041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Class that cannot be streamed into an ostream. It needs to be copyable 81141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// (and, in case of MSVC, also assignable) in order to be a test parameter 81241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// type. Its default copy constructor and assignment operator do exactly 81341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// what we need. 81441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass Unstreamable { 81541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot public: 81641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot explicit Unstreamable(int value) : value_(value) {} 81741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 81841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot private: 81941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot int value_; 82041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot}; 82141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 82241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass CommentTest : public TestWithParam<Unstreamable> {}; 82341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 82441d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotTEST_P(CommentTest, TestsCorrectlyReportUnstreamableParams) { 82541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot const ::testing::TestInfo* const test_info = 82641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot ::testing::UnitTest::GetInstance()->current_test_info(); 82741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 82841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot EXPECT_EQ(::testing::PrintToString(GetParam()), test_info->value_param()); 82941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot} 83041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 83141d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotINSTANTIATE_TEST_CASE_P(InstantiationWithComments, 83241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot CommentTest, 83341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot Values(Unstreamable(1))); 83441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 83541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Verify that we can create a hierarchy of test fixtures, where the base 83641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// class fixture is not parameterized and the derived class is. In this case 83741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// ParameterizedDerivedTest inherits from NonParameterizedBaseTest. We 83841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// perform simple tests on both. 83941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass NonParameterizedBaseTest : public ::testing::Test { 84041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot public: 84141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot NonParameterizedBaseTest() : n_(17) { } 84241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot protected: 84341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot int n_; 84441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot}; 84541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 84641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotclass ParameterizedDerivedTest : public NonParameterizedBaseTest, 84741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot public ::testing::WithParamInterface<int> { 84841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot protected: 84941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot ParameterizedDerivedTest() : count_(0) { } 85041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot int count_; 85141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot static int global_count_; 85241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot}; 85341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 85441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotint ParameterizedDerivedTest::global_count_ = 0; 85541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 85641d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotTEST_F(NonParameterizedBaseTest, FixtureIsInitialized) { 85741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot EXPECT_EQ(17, n_); 85841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot} 85941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 86041d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotTEST_P(ParameterizedDerivedTest, SeesSequence) { 86141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot EXPECT_EQ(17, n_); 86241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot EXPECT_EQ(0, count_++); 86341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot EXPECT_EQ(GetParam(), global_count_++); 86441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot} 86541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 86641d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotINSTANTIATE_TEST_CASE_P(RangeZeroToFive, ParameterizedDerivedTest, Range(0, 5)); 86741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 8681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif // GTEST_HAS_PARAM_TEST 8691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 8701be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(CompileTest, CombineIsDefinedOnlyWhenGtestHasParamTestIsDefined) { 8711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#if GTEST_HAS_COMBINE && !GTEST_HAS_PARAM_TEST 8721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania FAIL() << "GTEST_HAS_COMBINE is defined while GTEST_HAS_PARAM_TEST is not\n" 8731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif 8741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 8751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 8761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaint main(int argc, char **argv) { 8771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#if GTEST_HAS_PARAM_TEST 8781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania // Used in TestGenerationTest test case. 8791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania AddGlobalTestEnvironment(TestGenerationTest::Environment::Instance()); 88041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot // Used in GeneratorEvaluationTest test case. Tests that the updated value 88141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot // will be picked up for instantiating tests in GeneratorEvaluationTest. 8821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania GeneratorEvaluationTest::set_param_value(1); 8831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif // GTEST_HAS_PARAM_TEST 8841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 88541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot ::testing::InitGoogleTest(&argc, argv); 88641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 88741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#if GTEST_HAS_PARAM_TEST 88841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot // Used in GeneratorEvaluationTest test case. Tests that value updated 88941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot // here will NOT be used for instantiating tests in 89041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot // GeneratorEvaluationTest. 89141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot GeneratorEvaluationTest::set_param_value(2); 89241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#endif // GTEST_HAS_PARAM_TEST 89341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 8941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return RUN_ALL_TESTS(); 8951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 896