54using ::testing::Message;
56using ::testing::TestWithParam;
60using ::testing::internal::ParamGenerator;
61using ::testing::internal::UnitTestOptions;
77template <
typename T,
size_t N>
79 const T (&expected_values)[N]) {
80 typename ParamGenerator<T>::iterator it = generator.begin();
81 for (
size_t i = 0;
i < N; ++
i) {
83 <<
"At element " <<
i <<
" when accessing via an iterator "
84 <<
"created with the copy constructor.\n";
89 <<
", expected_values[i] is " <<
PrintValue(expected_values[
i])
91 <<
", and 'it' is an iterator created with the copy constructor.\n";
95 <<
"At the presumed end of sequence when accessing via an iterator "
96 <<
"created with the copy constructor.\n";
102 it = generator.begin();
103 for (
size_t i = 0;
i < N; ++
i) {
105 <<
"At element " <<
i <<
" when accessing via an iterator "
106 <<
"created with the assignment operator.\n";
108 <<
"where i is " <<
i
109 <<
", expected_values[i] is " <<
PrintValue(expected_values[
i])
111 <<
", and 'it' is an iterator created with the copy constructor.\n";
115 <<
"At the presumed end of sequence when accessing via an iterator "
116 <<
"created with the assignment operator.\n";
121 typename ParamGenerator<T>::iterator it = generator.begin();
124 it = generator.begin();
137TEST(IteratorTest, ParamIteratorConformsToForwardIteratorConcept) {
138 const ParamGenerator<int> gen =
Range(0, 10);
139 ParamGenerator<int>::iterator it = gen.begin();
142 ParamGenerator<int>::iterator it2 = it;
143 EXPECT_TRUE(*it == *it2) <<
"Initialized iterators must point to the "
144 <<
"element same as its source points to";
150 EXPECT_TRUE(*it == *it2) <<
"Assigned iterators must point to the "
151 <<
"element same as its source points to";
154 EXPECT_EQ(&it, &(++it)) <<
"Result of the prefix operator++ must be "
155 <<
"refer to the original object";
159 int original_value = *it;
172TEST(RangeTest, IntRangeWithDefaultStep) {
173 const ParamGenerator<int> gen =
Range(0, 3);
174 const int expected_values[] = {0, 1, 2};
180TEST(RangeTest, IntRangeSingleValue) {
181 const ParamGenerator<int> gen =
Range(0, 1);
182 const int expected_values[] = {0};
188TEST(RangeTest, IntRangeEmpty) {
189 const ParamGenerator<int> gen =
Range(0, 0);
195TEST(RangeTest, IntRangeWithCustomStep) {
196 const ParamGenerator<int> gen =
Range(0, 9, 3);
197 const int expected_values[] = {0, 3, 6};
205TEST(RangeTest, IntRangeWithCustomStepOverUpperBound) {
206 const ParamGenerator<int> gen =
Range(0, 4, 3);
207 const int expected_values[] = {0, 3};
215 explicit DogAdder(
const char* a_value) : value_(a_value) {}
220 value_ = other.value_;
225 msg << value_.c_str() << other.value_.c_str();
226 return DogAdder(msg.GetString().c_str());
229 return value_ < other.value_;
231 const std::string&
value()
const {
return value_; }
237TEST(RangeTest, WorksWithACustomType) {
238 const ParamGenerator<DogAdder> gen =
240 ParamGenerator<DogAdder>::iterator it = gen.begin();
257 value_ = other.value_;
263 return value_ < other.value_;
265 int value()
const {
return value_; }
271TEST(RangeTest, WorksWithACustomTypeWithDifferentIncrementType) {
273 ParamGenerator<IntWrapper>::iterator it = gen.begin();
286TEST(ValuesInTest, ValuesInArray) {
287 int array[] = {3, 5, 8};
288 const ParamGenerator<int> gen =
ValuesIn(array);
294TEST(ValuesInTest, ValuesInConstArray) {
295 const int array[] = {3, 5, 8};
296 const ParamGenerator<int> gen =
ValuesIn(array);
302TEST(ValuesInTest, ValuesInSingleElementArray) {
304 const ParamGenerator<int> gen =
ValuesIn(array);
310TEST(ValuesInTest, ValuesInVector) {
311 typedef ::std::vector<int> ContainerType;
312 ContainerType values;
316 const ParamGenerator<int> gen =
ValuesIn(values);
318 const int expected_values[] = {3, 5, 8};
323TEST(ValuesInTest, ValuesInIteratorRange) {
324 typedef ::std::vector<int> ContainerType;
325 ContainerType values;
329 const ParamGenerator<int> gen =
ValuesIn(values.begin(), values.end());
331 const int expected_values[] = {3, 5, 8};
337TEST(ValuesInTest, ValuesInSingleElementIteratorRange) {
338 typedef ::std::vector<int> ContainerType;
339 ContainerType values;
340 values.push_back(42);
341 const ParamGenerator<int> gen =
ValuesIn(values.begin(), values.end());
343 const int expected_values[] = {42};
349TEST(ValuesInTest, ValuesInEmptyIteratorRange) {
350 typedef ::std::vector<int> ContainerType;
351 ContainerType values;
352 const ParamGenerator<int> gen =
ValuesIn(values.begin(), values.end());
359 const ParamGenerator<int> gen =
Values(3, 5, 8);
361 const int expected_values[] = {3, 5, 8};
367TEST(ValuesTest, ValuesWorksForValuesOfCompatibleTypes) {
368 const ParamGenerator<double> gen =
Values(3, 5.0f, 8.0);
370 const double expected_values[] = {3.0, 5.0, 8.0};
374TEST(ValuesTest, ValuesWorksForMaxLengthList) {
375 const ParamGenerator<int> gen =
Values(
376 10, 20, 30, 40, 50, 60, 70, 80, 90, 100,
377 110, 120, 130, 140, 150, 160, 170, 180, 190, 200,
378 210, 220, 230, 240, 250, 260, 270, 280, 290, 300,
379 310, 320, 330, 340, 350, 360, 370, 380, 390, 400,
380 410, 420, 430, 440, 450, 460, 470, 480, 490, 500);
382 const int expected_values[] = {
383 10, 20, 30, 40, 50, 60, 70, 80, 90, 100,
384 110, 120, 130, 140, 150, 160, 170, 180, 190, 200,
385 210, 220, 230, 240, 250, 260, 270, 280, 290, 300,
386 310, 320, 330, 340, 350, 360, 370, 380, 390, 400,
387 410, 420, 430, 440, 450, 460, 470, 480, 490, 500};
393TEST(ValuesTest, ValuesWithSingleParameter) {
394 const ParamGenerator<int> gen =
Values(42);
396 const int expected_values[] = {42};
402 const ParamGenerator<bool> gen =
Bool();
404 const bool expected_values[] = {
false,
true};
409TEST(CombineTest, CombineWithTwoParameters) {
410 const char*
foo =
"foo";
411 const char*
bar =
"bar";
412 const ParamGenerator<std::tuple<const char*, int> > gen =
415 std::tuple<const char*, int> expected_values[] = {
416 std::make_tuple(
foo, 3), std::make_tuple(
foo, 4), std::make_tuple(
bar, 3),
417 std::make_tuple(
bar, 4)};
422TEST(CombineTest, CombineWithThreeParameters) {
423 const ParamGenerator<std::tuple<int, int, int> > gen =
425 std::tuple<int, int, int> expected_values[] = {
426 std::make_tuple(0, 3, 5), std::make_tuple(0, 3, 6),
427 std::make_tuple(0, 4, 5), std::make_tuple(0, 4, 6),
428 std::make_tuple(1, 3, 5), std::make_tuple(1, 3, 6),
429 std::make_tuple(1, 4, 5), std::make_tuple(1, 4, 6)};
436TEST(CombineTest, CombineWithFirstParameterSingleValue) {
437 const ParamGenerator<std::tuple<int, int> > gen =
440 std::tuple<int, int> expected_values[] = {std::make_tuple(42, 0),
441 std::make_tuple(42, 1)};
448TEST(CombineTest, CombineWithSecondParameterSingleValue) {
449 const ParamGenerator<std::tuple<int, int> > gen =
452 std::tuple<int, int> expected_values[] = {std::make_tuple(0, 42),
453 std::make_tuple(1, 42)};
459TEST(CombineTest, CombineWithFirstParameterEmptyRange) {
460 const ParamGenerator<std::tuple<int, int> > gen =
467TEST(CombineTest, CombineWithSecondParameterEmptyRange) {
468 const ParamGenerator<std::tuple<int, int> > gen =
475TEST(CombineTest, CombineWithMaxNumberOfParameters) {
476 const char*
foo =
"foo";
477 const char*
bar =
"bar";
478 const ParamGenerator<
479 std::tuple<const char*, int, int, int, int, int, int, int, int, int> >
484 std::tuple<const char*, int, int, int, int, int, int, int, int, int>
485 expected_values[] = {std::make_tuple(
foo, 1, 2, 3, 4, 5, 6, 7, 8, 9),
486 std::make_tuple(
bar, 1, 2, 3, 4, 5, 6, 7, 8, 9)};
500 const std::string&
str()
const {
return str_; }
506TEST(CombineTest, NonDefaultConstructAssign) {
507 const ParamGenerator<std::tuple<int, NonDefaultConstructAssignString> > gen =
511 ParamGenerator<std::tuple<int, NonDefaultConstructAssignString> >::iterator
536TEST(ParamGeneratorTest, AssignmentWorks) {
537 ParamGenerator<int> gen =
Values(1, 2);
538 const ParamGenerator<int> gen2 =
Values(3, 4);
541 const int expected_values[] = {3, 4};
554template <
int kExpectedCalls>
570 bool perform_check =
false;
572 for (
int i = 0;
i < kExpectedCalls; ++
i) {
574 msg <<
"TestsExpandedAndRun/" <<
i;
575 if (UnitTestOptions::FilterMatchesTest(
576 "TestExpansionModule/MultipleTestGenerationTest",
577 msg.GetString().c_str())) {
578 perform_check =
true;
582 EXPECT_EQ(kExpectedCalls, fixture_constructor_count_)
583 <<
"Fixture constructor of ParamTestGenerationTest test case "
584 <<
"has not been run as expected.";
586 <<
"Fixture SetUp method of ParamTestGenerationTest test case "
587 <<
"has not been run as expected.";
588 EXPECT_EQ(kExpectedCalls, tear_down_count_)
589 <<
"Fixture TearDown method of ParamTestGenerationTest test case "
590 <<
"has not been run as expected.";
591 EXPECT_EQ(kExpectedCalls, test_body_count_)
592 <<
"Test in ParamTestGenerationTest test case "
593 <<
"has not been run as expected.";
599 tear_down_count_(0), test_body_count_(0) {}
601 int fixture_constructor_count_;
603 int tear_down_count_;
604 int test_body_count_;
634 bool all_tests_in_test_case_selected =
true;
638 test_name <<
"TestsExpandedAndRun/" <<
i;
639 if ( !UnitTestOptions::FilterMatchesTest(
640 "TestExpansionModule/MultipleTestGenerationTest",
641 test_name.GetString())) {
642 all_tests_in_test_case_selected =
false;
646 <<
"When running the TestGenerationTest test case all of its tests\n"
647 <<
"must be selected by the filter flag for the test case to pass.\n"
648 <<
"If not all of them are enabled, we can't reliably conclude\n"
649 <<
"that the correct number of tests have been generated.";
660 sort(expected_values.begin(), expected_values.end());
676 Environment::Instance()->TestBodyExecuted();
677 EXPECT_EQ(current_parameter_, GetParam());
678 collected_parameters_.push_back(GetParam());
699 static int param_value_;
701int GeneratorEvaluationTest::param_value_ = 0;
756 <<
"If some (but not all) SeparateInstanceTest tests have been "
757 <<
"filtered out this test will fail. Make sure that all "
758 <<
"GeneratorEvaluationTest are selected or de-selected together "
759 <<
"by the test filter.";
782 const ::testing::TestInfo*
const test_info =
785 EXPECT_STREQ(
"ZeroToFiveSequence/NamingTest", test_info->test_suite_name());
787 Message index_stream;
788 index_stream <<
"TestsReportCorrectNamesAndParameters/" << GetParam();
789 EXPECT_STREQ(index_stream.GetString().c_str(), test_info->name());
799#define PREFIX_WITH_FOO(test_name) Foo##test_name
800#define PREFIX_WITH_MACRO(test_name) Macro##test_name
803 const ::testing::TestInfo*
const test_info =
806 EXPECT_STREQ(
"FortyTwo/MacroNamingTest", test_info->test_suite_name());
817 const ::testing::TestInfo*
const test_info =
820 EXPECT_STREQ(
"MacroNamingTestNonParametrized", test_info->test_suite_name());
824TEST(MacroNameing, LookupNames) {
825 std::set<std::string> know_suite_names, know_test_names;
830 know_suite_names.insert(suite->name());
834 know_test_names.insert(std::string(suite->name()) +
"." + info->name());
840 know_suite_names.find(
"FortyTwo/MacroNamingTest"),
841 know_suite_names.end());
843 know_suite_names.find(
"MacroNamingTestNonParametrized"),
844 know_suite_names.end());
847 know_test_names.find(
"FortyTwo/MacroNamingTest.FooSomeTestName/0"),
848 know_test_names.end());
850 know_test_names.find(
"MacroNamingTestNonParametrized.FooSomeTestName"),
851 know_test_names.end());
862 std::string
operator()(const ::testing::TestParamInfo<std::string>& inf) {
868 Values(std::string(
"FunctorName")),
872 Values(
"abcdefghijklmnopqrstuvwxyz",
873 "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"01234567890_"),
877 const ::testing::TestParamInfo<std::string>& inf) {
885 Values(std::string(
"FunctionName")),
889 Values(std::string(
"FunctionNameP")),
898 Values(std::string(
"LambdaName")),
899 [](const ::testing::TestParamInfo<std::string>& inf) {
903TEST(CustomNamingTest, CheckNameRegistry) {
905 std::set<std::string> test_names;
908 const ::testing::TestSuite* test_suite = unit_test->
GetTestSuite(suite_num);
909 for (
int test_num = 0; test_num < test_suite->total_test_count();
911 const ::testing::TestInfo* test_info = test_suite->
GetTestInfo(test_num);
912 test_names.insert(std::string(test_info->name()));
915 EXPECT_EQ(1u, test_names.count(
"CustomTestNames/FunctorName"));
916 EXPECT_EQ(1u, test_names.count(
"CustomTestNames/FunctionName"));
917 EXPECT_EQ(1u, test_names.count(
"CustomTestNames/FunctionNameP"));
918 EXPECT_EQ(1u, test_names.count(
"CustomTestNames/LambdaName"));
926 const ::testing::TestInfo*
const test_info =
928 Message test_name_stream;
929 test_name_stream <<
"TestsReportCorrectNames/" << GetParam();
930 EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name());
951 const ::testing::TestInfo*
const test_info =
953 Message test_name_stream;
954 test_name_stream <<
"TestsReportCorrectNames/" << GetParam();
955 EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name());
966 std::string
operator()(const ::testing::TestParamInfo<int>& info) {
981 const ::testing::TestInfo*
const test_info =
984 Message test_name_stream;
985 test_name_stream <<
"TestsReportCorrectNames/" << sum_;
986 EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name());
1009 const ::testing::TestInfo*
const test_info =
1053 ".* value-parameterized test .*");
1078template <
typename T>
1094template <
typename T>
#define EXPECT_EQ(val1, val2)
#define EXPECT_NE(val1, val2)
#define ASSERT_FALSE(condition)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
#define EXPECT_GE(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
#define EXPECT_FALSE(condition)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
std::string CustomParamNameFunction(const ::testing::TestParamInfo< std::string > &inf)
TEST_F(PREFIX_WITH_MACRO(NamingTestNonParametrized), PREFIX_WITH_FOO(SomeTestName))
ParamGenerator< int > extern_gen
void VerifyGenerator(const ParamGenerator< T > &generator, const T(&expected_values)[N])
int main(int argc, char **argv)
::std::string PrintValue(const T &value)
#define PREFIX_WITH_FOO(test_name)
TEST_P(TestGenerationTest, TestsExpandedAndRun)
void VerifyGeneratorIsEmpty(const ParamGenerator< T > &generator)
TEST(IteratorTest, ParamIteratorConformsToForwardIteratorConcept)
INSTANTIATE_TEST_SUITE_P(TestExpansionModule, TestGenerationTest, ValuesIn(test_generation_params))
std::ostream & operator<<(std::ostream &stream, const CustomStruct &val)
#define PREFIX_WITH_MACRO(test_name)
const int test_generation_params[]
internal::ParamGenerator< bool > Bool()
Environment * AddGlobalTestEnvironment(Environment *env)
internal::ParamGenerator< typename std::iterator_traits< ForwardIterator >::value_type > ValuesIn(ForwardIterator begin, ForwardIterator end)
internal::ParamGenerator< T > Range(T start, T end, IncrementT step)
::std::string PrintToString(const T &value)
internal::CartesianProductHolder< Generator... > Combine(const Generator &... g)
internal::ValueArray< T... > Values(T... v)
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
REGISTER_TYPED_TEST_SUITE_P(NotInstantiatedTypeTest, Used)
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NotInstantiatedTest)
TYPED_TEST_SUITE_P(NotUsedTypeTest)
TEST_P(NotInstantiatedTest, Used)
TYPED_TEST_P(NotInstantiatedTypeTest, Used)
const TestInfo * GetTestInfo(int i) const
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
static UnitTest * GetInstance()
const TestSuite * GetTestSuite(int i) const
int total_test_suite_count() const
static const ParamType & GetParam()
DogAdder operator=(const DogAdder &other)
DogAdder(const DogAdder &other)
bool operator<(const DogAdder &other) const
DogAdder(const char *a_value)
const std::string & value() const
DogAdder operator+(const DogAdder &other) const
IntWrapper operator=(const IntWrapper &other)
bool operator<(const IntWrapper &other) const
IntWrapper operator+(int other) const
IntWrapper(const IntWrapper &other)
NonDefaultConstructAssignString(const NonDefaultConstructAssignString &)=default
NonDefaultConstructAssignString & operator=(const NonDefaultConstructAssignString &)=delete
NonDefaultConstructAssignString(const std::string &s)
const std::string & str() const
~NonDefaultConstructAssignString()=default
NonDefaultConstructAssignString()=delete
static TestGenerationEnvironment * Instance()
void FixtureConstructorExecuted()
static void SetUpTestSuite()
static vector< int > collected_parameters_
static void TearDownTestSuite()
TestGenerationEnvironment< PARAMETER_COUNT > Environment
static void set_param_value(int param_value)
static void TearDownTestSuite()
std::string operator()(const ::testing::TestParamInfo< std::string > &inf)
std::string operator()(const ::testing::TestParamInfo< int > &info)
const int & dummy_value() const
NonParameterizedBaseTest()
ParameterizedDerivedTest()