51using ::testing::AddGlobalTestEnvironment;
53using ::testing::Message;
54using ::testing::Range;
55using ::testing::TestWithParam;
56using ::testing::Values;
57using ::testing::ValuesIn;
60using ::testing::Combine;
62using ::testing::make_tuple;
63using ::testing::tuple;
66using ::testing::internal::ParamGenerator;
67using ::testing::internal::UnitTestOptions;
77 ::std::stringstream stream;
90template <
typename T1,
typename T2>
92 ::std::stringstream stream;
93 stream <<
"(" << get<0>(
value) <<
", " << get<1>(
value) <<
")";
97template <
typename T1,
typename T2,
typename T3>
99 ::std::stringstream stream;
100 stream <<
"(" << get<0>(
value) <<
", " << get<1>(
value)
101 <<
", "<< get<2>(
value) <<
")";
105template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
106 typename T6,
typename T7,
typename T8,
typename T9,
typename T10>
108 const tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>&
value) {
109 ::std::stringstream stream;
110 stream <<
"(" << get<0>(
value) <<
", " << get<1>(
value)
111 <<
", "<< get<2>(
value) <<
", " << get<3>(
value)
112 <<
", "<< get<4>(
value) <<
", " << get<5>(
value)
113 <<
", "<< get<6>(
value) <<
", " << get<7>(
value)
114 <<
", "<< get<8>(
value) <<
", " << get<9>(
value) <<
")";
123template <
typename T,
size_t N>
125 const T (&expected_values)[
N]) {
126 typename ParamGenerator<T>::iterator it = generator.begin();
127 for (
size_t i = 0; i <
N; ++i) {
129 <<
"At element " << i <<
" when accessing via an iterator "
130 <<
"created with the copy constructor.\n";
134 <<
"where i is " << i
135 <<
", expected_values[i] is " <<
PrintValue(expected_values[i])
137 <<
", and 'it' is an iterator created with the copy constructor.\n";
141 <<
"At the presumed end of sequence when accessing via an iterator "
142 <<
"created with the copy constructor.\n";
148 it = generator.begin();
149 for (
size_t i = 0; i <
N; ++i) {
151 <<
"At element " << i <<
" when accessing via an iterator "
152 <<
"created with the assignment operator.\n";
154 <<
"where i is " << i
155 <<
", expected_values[i] is " <<
PrintValue(expected_values[i])
157 <<
", and 'it' is an iterator created with the copy constructor.\n";
161 <<
"At the presumed end of sequence when accessing via an iterator "
162 <<
"created with the assignment operator.\n";
167 typename ParamGenerator<T>::iterator it = generator.begin();
170 it = generator.begin();
183TEST(IteratorTest, ParamIteratorConformsToForwardIteratorConcept) {
184 const ParamGenerator<int> gen = Range(0, 10);
185 ParamGenerator<int>::iterator it = gen.begin();
188 ParamGenerator<int>::iterator it2 = it;
189 EXPECT_TRUE(*it == *it2) <<
"Initialized iterators must point to the "
190 <<
"element same as its source points to";
196 EXPECT_TRUE(*it == *it2) <<
"Assigned iterators must point to the "
197 <<
"element same as its source points to";
200 EXPECT_EQ(&it, &(++it)) <<
"Result of the prefix operator++ must be "
201 <<
"refer to the original object";
205 int original_value = *it;
218TEST(RangeTest, IntRangeWithDefaultStep) {
219 const ParamGenerator<int> gen = Range(0, 3);
220 const int expected_values[] = {0, 1, 2};
226TEST(RangeTest, IntRangeSingleValue) {
227 const ParamGenerator<int> gen = Range(0, 1);
228 const int expected_values[] = {0};
234TEST(RangeTest, IntRangeEmpty) {
235 const ParamGenerator<int> gen = Range(0, 0);
241TEST(RangeTest, IntRangeWithCustomStep) {
242 const ParamGenerator<int> gen = Range(0, 9, 3);
243 const int expected_values[] = {0, 3, 6};
251TEST(RangeTest, IntRangeWithCustomStepOverUpperBound) {
252 const ParamGenerator<int> gen = Range(0, 4, 3);
253 const int expected_values[] = {0, 3};
261 explicit DogAdder(
const char* a_value) : value_(a_value) {}
266 value_ = other.value_;
271 msg << value_.c_str() << other.value_.c_str();
272 return DogAdder(msg.GetString().c_str());
275 return value_ < other.value_;
277 const std::string&
value()
const {
return value_; }
283TEST(RangeTest, WorksWithACustomType) {
284 const ParamGenerator<DogAdder> gen =
286 ParamGenerator<DogAdder>::iterator it = gen.begin();
303 value_ = other.value_;
309 return value_ < other.value_;
311 int value()
const {
return value_; }
317TEST(RangeTest, WorksWithACustomTypeWithDifferentIncrementType) {
319 ParamGenerator<IntWrapper>::iterator it = gen.begin();
332TEST(ValuesInTest, ValuesInArray) {
333 int array[] = {3, 5, 8};
334 const ParamGenerator<int> gen = ValuesIn(array);
340TEST(ValuesInTest, ValuesInConstArray) {
341 const int array[] = {3, 5, 8};
342 const ParamGenerator<int> gen = ValuesIn(array);
348TEST(ValuesInTest, ValuesInSingleElementArray) {
350 const ParamGenerator<int> gen = ValuesIn(array);
356TEST(ValuesInTest, ValuesInVector) {
357 typedef ::std::vector<int> ContainerType;
358 ContainerType values;
362 const ParamGenerator<int> gen = ValuesIn(values);
364 const int expected_values[] = {3, 5, 8};
369TEST(ValuesInTest, ValuesInIteratorRange) {
370 typedef ::std::vector<int> ContainerType;
371 ContainerType values;
375 const ParamGenerator<int> gen = ValuesIn(values.begin(), values.end());
377 const int expected_values[] = {3, 5, 8};
383TEST(ValuesInTest, ValuesInSingleElementIteratorRange) {
384 typedef ::std::vector<int> ContainerType;
385 ContainerType values;
386 values.push_back(42);
387 const ParamGenerator<int> gen = ValuesIn(values.begin(), values.end());
389 const int expected_values[] = {42};
395TEST(ValuesInTest, ValuesInEmptyIteratorRange) {
396 typedef ::std::vector<int> ContainerType;
397 ContainerType values;
398 const ParamGenerator<int> gen = ValuesIn(values.begin(), values.end());
405 const ParamGenerator<int> gen = Values(3, 5, 8);
407 const int expected_values[] = {3, 5, 8};
413TEST(ValuesTest, ValuesWorksForValuesOfCompatibleTypes) {
414 const ParamGenerator<double> gen = Values(3, 5.0f, 8.0);
416 const double expected_values[] = {3.0, 5.0, 8.0};
420TEST(ValuesTest, ValuesWorksForMaxLengthList) {
421 const ParamGenerator<int> gen = Values(
422 10, 20, 30, 40, 50, 60, 70, 80, 90, 100,
423 110, 120, 130, 140, 150, 160, 170, 180, 190, 200,
424 210, 220, 230, 240, 250, 260, 270, 280, 290, 300,
425 310, 320, 330, 340, 350, 360, 370, 380, 390, 400,
426 410, 420, 430, 440, 450, 460, 470, 480, 490, 500);
428 const int expected_values[] = {
429 10, 20, 30, 40, 50, 60, 70, 80, 90, 100,
430 110, 120, 130, 140, 150, 160, 170, 180, 190, 200,
431 210, 220, 230, 240, 250, 260, 270, 280, 290, 300,
432 310, 320, 330, 340, 350, 360, 370, 380, 390, 400,
433 410, 420, 430, 440, 450, 460, 470, 480, 490, 500};
439TEST(ValuesTest, ValuesWithSingleParameter) {
440 const ParamGenerator<int> gen = Values(42);
442 const int expected_values[] = {42};
448 const ParamGenerator<bool> gen =
Bool();
450 const bool expected_values[] = {
false,
true};
454# if GTEST_HAS_COMBINE
457TEST(CombineTest, CombineWithTwoParameters) {
458 const char*
foo =
"foo";
459 const char*
bar =
"bar";
460 const ParamGenerator<tuple<const char*, int> > gen =
463 tuple<const char*, int> expected_values[] = {
464 make_tuple(
foo, 3), make_tuple(
foo, 4),
465 make_tuple(
bar, 3), make_tuple(
bar, 4)};
470TEST(CombineTest, CombineWithThreeParameters) {
471 const ParamGenerator<tuple<int, int, int> > gen = Combine(
Values(0, 1),
474 tuple<int, int, int> expected_values[] = {
475 make_tuple(0, 3, 5), make_tuple(0, 3, 6),
476 make_tuple(0, 4, 5), make_tuple(0, 4, 6),
477 make_tuple(1, 3, 5), make_tuple(1, 3, 6),
478 make_tuple(1, 4, 5), make_tuple(1, 4, 6)};
485TEST(CombineTest, CombineWithFirstParameterSingleValue) {
486 const ParamGenerator<tuple<int, int> > gen = Combine(
Values(42),
489 tuple<int, int> expected_values[] = {make_tuple(42, 0), make_tuple(42, 1)};
496TEST(CombineTest, CombineWithSecondParameterSingleValue) {
497 const ParamGenerator<tuple<int, int> > gen = Combine(
Values(0, 1),
500 tuple<int, int> expected_values[] = {make_tuple(0, 42), make_tuple(1, 42)};
506TEST(CombineTest, CombineWithFirstParameterEmptyRange) {
507 const ParamGenerator<tuple<int, int> > gen = Combine(
Range(0, 0),
514TEST(CombineTest, CombineWithSecondParameterEmptyRange) {
515 const ParamGenerator<tuple<int, int> > gen = Combine(
Values(0, 1),
522TEST(CombineTest, CombineWithMaxNumberOfParameters) {
523 const char*
foo =
"foo";
524 const char*
bar =
"bar";
525 const ParamGenerator<tuple<
const char*, int, int, int, int, int, int, int,
533 tuple<const char*, int, int, int, int, int, int, int, int, int>
534 expected_values[] = {make_tuple(
foo, 1, 2, 3, 4, 5, 6, 7, 8, 9),
535 make_tuple(
bar, 1, 2, 3, 4, 5, 6, 7, 8, 9)};
541class NonDefaultConstructAssignString {
543 NonDefaultConstructAssignString(
const std::string&
s) : str_(
s) {}
545 const std::string&
str()
const {
return str_; }
551 NonDefaultConstructAssignString();
553 void operator=(
const NonDefaultConstructAssignString&);
556TEST(CombineTest, NonDefaultConstructAssign) {
557 const ParamGenerator<tuple<int, NonDefaultConstructAssignString> > gen =
558 Combine(
Values(0, 1),
Values(NonDefaultConstructAssignString(
"A"),
559 NonDefaultConstructAssignString(
"B")));
561 ParamGenerator<tuple<int, NonDefaultConstructAssignString> >::iterator it =
588TEST(ParamGeneratorTest, AssignmentWorks) {
589 ParamGenerator<int> gen = Values(1, 2);
590 const ParamGenerator<int> gen2 = Values(3, 4);
593 const int expected_values[] = {3, 4};
606template <
int kExpectedCalls>
622 bool perform_check =
false;
624 for (
int i = 0; i < kExpectedCalls; ++i) {
626 msg <<
"TestsExpandedAndRun/" << i;
627 if (UnitTestOptions::FilterMatchesTest(
628 "TestExpansionModule/MultipleTestGenerationTest",
629 msg.GetString().c_str())) {
630 perform_check =
true;
634 EXPECT_EQ(kExpectedCalls, fixture_constructor_count_)
635 <<
"Fixture constructor of ParamTestGenerationTest test case "
636 <<
"has not been run as expected.";
638 <<
"Fixture SetUp method of ParamTestGenerationTest test case "
639 <<
"has not been run as expected.";
640 EXPECT_EQ(kExpectedCalls, tear_down_count_)
641 <<
"Fixture TearDown method of ParamTestGenerationTest test case "
642 <<
"has not been run as expected.";
643 EXPECT_EQ(kExpectedCalls, test_body_count_)
644 <<
"Test in ParamTestGenerationTest test case "
645 <<
"has not been run as expected.";
651 tear_down_count_(0), test_body_count_(0) {}
653 int fixture_constructor_count_;
655 int tear_down_count_;
656 int test_body_count_;
686 bool all_tests_in_test_case_selected =
true;
690 test_name <<
"TestsExpandedAndRun/" << i;
691 if ( !UnitTestOptions::FilterMatchesTest(
692 "TestExpansionModule/MultipleTestGenerationTest",
693 test_name.GetString())) {
694 all_tests_in_test_case_selected =
false;
698 <<
"When running the TestGenerationTest test case all of its tests\n"
699 <<
"must be selected by the filter flag for the test case to pass.\n"
700 <<
"If not all of them are enabled, we can't reliably conclude\n"
701 <<
"that the correct number of tests have been generated.";
712 sort(expected_values.begin(), expected_values.end());
728 Environment::Instance()->TestBodyExecuted();
729 EXPECT_EQ(current_parameter_, GetParam());
730 collected_parameters_.push_back(GetParam());
751 static int param_value_;
753int GeneratorEvaluationTest::param_value_ = 0;
811 <<
"If some (but not all) SeparateInstanceTest tests have been "
812 <<
"filtered out this test will fail. Make sure that all "
813 <<
"GeneratorEvaluationTest are selected or de-selected together "
814 <<
"by the test filter.";
837 const ::testing::TestInfo*
const test_info =
840 EXPECT_STREQ(
"ZeroToFiveSequence/NamingTest", test_info->test_case_name());
842 Message index_stream;
843 index_stream <<
"TestsReportCorrectNamesAndParameters/" << GetParam();
844 EXPECT_STREQ(index_stream.GetString().c_str(), test_info->name());
854#define PREFIX_WITH_FOO(test_name) Foo##test_name
855#define PREFIX_WITH_MACRO(test_name) Macro##test_name
858 const ::testing::TestInfo*
const test_info =
861 EXPECT_STREQ(
"FortyTwo/MacroNamingTest", test_info->test_case_name());
872 const ::testing::TestInfo*
const test_info =
875 EXPECT_STREQ(
"MacroNamingTestNonParametrized", test_info->test_case_name());
887 std::string
operator()(const ::testing::TestParamInfo<std::string>& inf) {
894 Values(std::string(
"FunctorName")),
899 Values(
"abcdefghijklmnopqrstuvwxyz",
900 "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
905 const ::testing::TestParamInfo<std::string>& inf) {
914 Values(std::string(
"FunctionName")),
921class CustomLambdaNamingTest :
public TestWithParam<std::string> {};
922TEST_P(CustomLambdaNamingTest, CustomTestNames) {}
925 Values(std::string(
"LambdaName")),
926 [](const ::testing::TestParamInfo<std::string>& inf) {
932TEST(CustomNamingTest, CheckNameRegistry) {
934 std::set<std::string> test_names;
935 for (
int case_num = 0;
938 const ::testing::TestCase* test_case = unit_test->
GetTestCase(case_num);
939 for (
int test_num = 0;
940 test_num < test_case->total_test_count();
942 const ::testing::TestInfo* test_info = test_case->GetTestInfo(test_num);
943 test_names.insert(std::string(test_info->name()));
946 EXPECT_EQ(1u, test_names.count(
"CustomTestNames/FunctorName"));
947 EXPECT_EQ(1u, test_names.count(
"CustomTestNames/FunctionName"));
949 EXPECT_EQ(1u, test_names.count(
"CustomTestNames/LambdaName"));
958 const ::testing::TestInfo*
const test_info =
960 Message test_name_stream;
961 test_name_stream <<
"TestsReportCorrectNames/" << GetParam();
962 EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name());
985 const ::testing::TestInfo*
const test_info =
987 Message test_name_stream;
988 test_name_stream <<
"TestsReportCorrectNames/" << GetParam();
989 EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name());
1001 std::string
operator()(const ::testing::TestParamInfo<int>& info) {
1004 return ::testing::PrintToString(
value);
1016 const ::testing::TestInfo*
const test_info =
1019 Message test_name_stream;
1020 test_name_stream <<
"TestsReportCorrectNames/" << sum_;
1021 EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name());
1044 const ::testing::TestInfo*
const test_info =
1089 ".* value-parameterized test .*");
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
static void set_param_value(int param_value)
IntWrapper operator=(const IntWrapper &other)
bool operator<(const IntWrapper &other) const
IntWrapper operator+(int other) const
IntWrapper(const IntWrapper &other)
NonParameterizedBaseTest()
ParameterizedDerivedTest()
static void TearDownTestCase()
static TestGenerationEnvironment * Instance()
void FixtureConstructorExecuted()
static vector< int > collected_parameters_
static void SetUpTestCase()
static void TearDownTestCase()
TestGenerationEnvironment< PARAMETER_COUNT > Environment
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
static UnitTest * GetInstance()
const TestCase * GetTestCase(int i) const
int total_test_case_count() const
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
#define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator,...)
#define TEST_P(test_case_name, test_name)
std::string CustomParamNameFunction(const ::testing::TestParamInfo< std::string > &inf)
ParamGenerator< int > extern_gen
void VerifyGenerator(const ParamGenerator< T > &generator, const T(&expected_values)[N])
::std::string PrintValue(const T &value)
#define PREFIX_WITH_FOO(test_name)
void VerifyGeneratorIsEmpty(const ParamGenerator< T > &generator)
std::ostream & operator<<(std::ostream &stream, const CustomStruct &val)
#define PREFIX_WITH_MACRO(test_name)
const int test_generation_params[]
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
#define TEST_F(test_fixture, test_name)
#define EXPECT_EQ(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 TEST(test_case_name, test_name)
#define EXPECT_FALSE(condition)
internal::ValueArray1< T1 > Values(T1 v1)
internal::ParamGenerator< T > Range(T start, T end, IncrementT step)
::std::string PrintToString(const T &value)
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
#define T(meth, val, expected)
std::string operator()(const ::testing::TestParamInfo< std::string > &inf)
std::string operator()(const ::testing::TestParamInfo< int > &info)