54 using ::testing::Message;
56 using ::testing::TestWithParam;
60 using ::testing::internal::ParamGenerator;
61 using ::testing::internal::UnitTestOptions;
77 template <
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";
119 template <
typename T>
121 typename ParamGenerator<T>::iterator it = generator.begin();
124 it = generator.begin();
137 TEST(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;
172 TEST(RangeTest, IntRangeWithDefaultStep) {
173 const ParamGenerator<int> gen =
Range(0, 3);
174 const int expected_values[] = {0, 1, 2};
180 TEST(RangeTest, IntRangeSingleValue) {
181 const ParamGenerator<int> gen =
Range(0, 1);
182 const int expected_values[] = {0};
188 TEST(RangeTest, IntRangeEmpty) {
189 const ParamGenerator<int> gen =
Range(0, 0);
195 TEST(RangeTest, IntRangeWithCustomStep) {
196 const ParamGenerator<int> gen =
Range(0, 9, 3);
197 const int expected_values[] = {0, 3, 6};
205 TEST(RangeTest, IntRangeWithCustomStepOverUpperBound) {
206 const ParamGenerator<int> gen =
Range(0, 4, 3);
207 const int expected_values[] = {0, 3};
226 return DogAdder(msg.GetString().c_str());
237 TEST(RangeTest, WorksWithACustomType) {
238 const ParamGenerator<DogAdder> gen =
240 ParamGenerator<DogAdder>::iterator it = gen.begin();
271 TEST(RangeTest, WorksWithACustomTypeWithDifferentIncrementType) {
273 ParamGenerator<IntWrapper>::iterator it = gen.begin();
286 TEST(ValuesInTest, ValuesInArray) {
287 int array[] = {3, 5, 8};
288 const ParamGenerator<int> gen =
ValuesIn(array);
294 TEST(ValuesInTest, ValuesInConstArray) {
295 const int array[] = {3, 5, 8};
296 const ParamGenerator<int> gen =
ValuesIn(array);
302 TEST(ValuesInTest, ValuesInSingleElementArray) {
304 const ParamGenerator<int> gen =
ValuesIn(array);
310 TEST(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};
323 TEST(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};
337 TEST(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};
349 TEST(ValuesInTest, ValuesInEmptyIteratorRange) {
350 typedef ::std::vector<int> ContainerType;
351 ContainerType values;
352 const ParamGenerator<int> gen =
ValuesIn(values.begin(), values.end());
358 TEST(ValuesTest, ValuesWorks) {
359 const ParamGenerator<int> gen =
Values(3, 5, 8);
361 const int expected_values[] = {3, 5, 8};
367 TEST(ValuesTest, ValuesWorksForValuesOfCompatibleTypes) {
368 const ParamGenerator<double> gen =
Values(3, 5.0
f, 8.0);
370 const double expected_values[] = {3.0, 5.0, 8.0};
374 TEST(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};
393 TEST(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};
409 TEST(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)};
422 TEST(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)};
436 TEST(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)};
448 TEST(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)};
459 TEST(CombineTest, CombineWithFirstParameterEmptyRange) {
460 const ParamGenerator<std::tuple<int, int> > gen =
467 TEST(CombineTest, CombineWithSecondParameterEmptyRange) {
468 const ParamGenerator<std::tuple<int, int> > gen =
475 TEST(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_; }
506 TEST(CombineTest, NonDefaultConstructAssign) {
507 const ParamGenerator<std::tuple<int, NonDefaultConstructAssignString> > gen =
511 ParamGenerator<std::tuple<int, NonDefaultConstructAssignString> >::iterator
536 TEST(ParamGeneratorTest, AssignmentWorks) {
537 ParamGenerator<int> gen =
Values(1, 2);
538 const ParamGenerator<int> gen2 =
Values(3, 4);
541 const int expected_values[] = {3, 4};
554 template <
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;
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.";
589 <<
"Fixture TearDown method of ParamTestGenerationTest test case "
590 <<
"has not been run as expected.";
592 <<
"Test in ParamTestGenerationTest test case "
593 <<
"has not been run as expected.";
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.";
655 vector<int> expected_values(test_generation_params,
660 sort(expected_values.begin(), expected_values.end());
676 Environment::Instance()->TestBodyExecuted();
677 EXPECT_EQ(current_parameter_, GetParam());
678 collected_parameters_.push_back(GetParam());
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());
824 TEST(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) {
903 TEST(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 .*");
1072 namespace works_here {
1078 template <
typename T>
1094 template <
typename T>
NonDefaultConstructAssignString & operator=(const NonDefaultConstructAssignString &)=delete
NonParameterizedBaseTest()
TestGenerationEnvironment()
internal::ValueArray< T...> Values(T...v)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
Environment * AddGlobalTestEnvironment(Environment *env)
static TestGenerationEnvironment * Instance()
IntWrapper operator+(int other) const
const TestInfo * GetTestInfo(int i) const
void FixtureConstructorExecuted()
#define PREFIX_WITH_FOO(test_name)
const int & dummy_value() const
const int test_generation_params[]
void VerifyGenerator(const ParamGenerator< T > &generator, const T(&expected_values)[N])
::std::string PrintValue(const T &value)
::std::string PrintToString(const T &value)
#define EXPECT_NE(val1, val2)
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestGenerationEnvironment)
static void SetUpTestSuite()
internal::ParamGenerator< bool > Bool()
#define TEST_F(test_fixture, test_name)
#define EXPECT_GE(val1, val2)
#define TEST(test_suite_name, test_name)
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestGenerationTest)
NonDefaultConstructAssignString(const std::string &s)
IntWrapper operator=(const IntWrapper &other)
TYPED_TEST_SUITE_P(NotUsedTypeTest)
std::string operator()(const ::testing::TestParamInfo< int > &info)
internal::ParamGenerator< T > Range(T start, T end, IncrementT step)
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NotInstantiatedTest)
void VerifyGeneratorIsEmpty(const ParamGenerator< T > &generator)
internal::ParamGenerator< typename std::iterator_traits< ForwardIterator >::value_type > ValuesIn(ForwardIterator begin, ForwardIterator end)
const TestSuite * GetTestSuite(int i) const
NonDefaultConstructAssignString()=delete
internal::CartesianProductHolder< Generator...> Combine(const Generator &...g)
static void TearDownTestSuite()
static vector< int > collected_parameters_
std::ostream & operator<<(std::ostream &os, const Expr< T > &xx)
int fixture_constructor_count_
bool operator<(const DogAdder &other) const
int total_test_suite_count() const
ADVar foo(double d, ADVar x, ADVar y)
bool operator<(const IntWrapper &other) const
std::string operator()(const ::testing::TestParamInfo< std::string > &inf)
#define EXPECT_STREQ(s1, s2)
DogAdder operator+(const DogAdder &other) const
static void set_param_value(int param_value)
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
TEST_P(NotInstantiatedTest, Used)
ParamGenerator< int > extern_gen
std::string CustomParamNameFunction(const ::testing::TestParamInfo< std::string > &inf)
DogAdder(const DogAdder &other)
#define PREFIX_WITH_MACRO(test_name)
#define EXPECT_EQ(val1, val2)
#define TEST_P(test_suite_name, test_name)
IntWrapper(const IntWrapper &other)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
DogAdder operator=(const DogAdder &other)
TestGenerationEnvironment< PARAMETER_COUNT > Environment
static void TearDownTestSuite()
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
DogAdder(const char *a_value)
const std::string & str() const
#define EXPECT_TRUE(condition)
static UnitTest * GetInstance()
REGISTER_TYPED_TEST_SUITE_P(NotInstantiatedTypeTest, Used)
const std::string & value() const
TYPED_TEST_P(NotInstantiatedTypeTest, Used)
~NonDefaultConstructAssignString()=default
#define EXPECT_FALSE(condition)
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name,...)
#define ASSERT_FALSE(condition)
ParameterizedDerivedTest()