61using ::testing::internal::UnitTestOptions;
77template <
typename T,
size_t N>
79 const T (&expected_values)[
N]) {
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";
124 it = generator.
begin();
137TEST(IteratorTest, ParamIteratorConformsToForwardIteratorConcept) {
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) {
174 const int expected_values[] = {0, 1, 2};
180TEST(RangeTest, IntRangeSingleValue) {
182 const int expected_values[] = {0};
188TEST(RangeTest, IntRangeEmpty) {
195TEST(RangeTest, IntRangeWithCustomStep) {
197 const int expected_values[] = {0, 3, 6};
205TEST(RangeTest, IntRangeWithCustomStepOverUpperBound) {
207 const int expected_values[] = {0, 3};
237TEST(RangeTest, WorksWithACustomType) {
271TEST(RangeTest, WorksWithACustomTypeWithDifferentIncrementType) {
286TEST(ValuesInTest, ValuesInArray) {
287 int array[] = {3, 5, 8};
294TEST(ValuesInTest, ValuesInConstArray) {
295 const int array[] = {3, 5, 8};
302TEST(ValuesInTest, ValuesInSingleElementArray) {
310TEST(ValuesInTest, ValuesInVector) {
311 typedef ::std::vector<int> ContainerType;
312 ContainerType values;
318 const int expected_values[] = {3, 5, 8};
323TEST(ValuesInTest, ValuesInIteratorRange) {
324 typedef ::std::vector<int> ContainerType;
325 ContainerType values;
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);
343 const int expected_values[] = {42};
349TEST(ValuesInTest, ValuesInEmptyIteratorRange) {
350 typedef ::std::vector<int> ContainerType;
351 ContainerType values;
361 const int expected_values[] = {3, 5, 8};
367TEST(ValuesTest, ValuesWorksForValuesOfCompatibleTypes) {
370 const double expected_values[] = {3.0, 5.0, 8.0};
374TEST(ValuesTest, ValuesWorksForMaxLengthList) {
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) {
396 const int expected_values[] = {42};
404 const bool expected_values[] = {
false,
true};
409TEST(CombineTest, CombineWithTwoParameters) {
410 const char*
foo =
"foo";
411 const char*
bar =
"bar";
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) {
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) {
440 std::tuple<int, int> expected_values[] = {std::make_tuple(42, 0),
441 std::make_tuple(42, 1)};
448TEST(CombineTest, CombineWithSecondParameterSingleValue) {
452 std::tuple<int, int> expected_values[] = {std::make_tuple(0, 42),
453 std::make_tuple(1, 42)};
459TEST(CombineTest, CombineWithFirstParameterEmptyRange) {
467TEST(CombineTest, CombineWithSecondParameterEmptyRange) {
475TEST(CombineTest, CombineWithMaxNumberOfParameters) {
476 const char*
foo =
"foo";
477 const char*
bar =
"bar";
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) {
536TEST(ParamGeneratorTest, AssignmentWorks) {
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",
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",
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());
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());
788 index_stream <<
"TestsReportCorrectNamesAndParameters/" << GetParam();
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 =
929 test_name_stream <<
"TestsReportCorrectNames/" << GetParam();
951 const ::testing::TestInfo*
const test_info =
954 test_name_stream <<
"TestsReportCorrectNames/" << GetParam();
966 std::string
operator()(const ::testing::TestParamInfo<int>& info) {
967 int value = info.param +
sum;
969 return ::testing::PrintToString(value);
981 const ::testing::TestInfo*
const test_info =
985 test_name_stream <<
"TestsReportCorrectNames/" << sum_;
1009 const ::testing::TestInfo*
const test_info =
1053 ".* value-parameterized test .*");
1078template <
typename T>
1094template <
typename T>
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)
NonDefaultConstructAssignString(const NonDefaultConstructAssignString &)=default
NonDefaultConstructAssignString & operator=(const NonDefaultConstructAssignString &)=delete
NonDefaultConstructAssignString(const std::string &s)
const std::string & str() const
~NonDefaultConstructAssignString()=default
NonDefaultConstructAssignString()=delete
NonParameterizedBaseTest()
ParamIterator< T > iterator
ParameterizedDerivedTest()
static void TearDownTestSuite()
int fixture_constructor_count_
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestGenerationEnvironment)
static TestGenerationEnvironment * Instance()
void FixtureConstructorExecuted()
TestGenerationEnvironment()
static void SetUpTestSuite()
static vector< int > collected_parameters_
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestGenerationTest)
static void TearDownTestSuite()
TestGenerationEnvironment< PARAMETER_COUNT > Environment
const int & dummy_value() const
std::string GetString() 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()
std::string CustomParamNameFunction(const ::testing::TestParamInfo< std::string > &inf)
ParamGenerator< int > extern_gen
void VerifyGenerator(const ParamGenerator< T > &generator, const T(&expected_values)[N])
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 PrintValue(const T &value)
#define PREFIX_WITH_FOO(test_name)
void VerifyGeneratorIsEmpty(const ParamGenerator< T > &generator)
internal::CartesianProductHolder< Generator... > Combine(const Generator &... g)
internal::ValueArray< T... > Values(T... v)
std::ostream & operator<<(std::ostream &stream, const CustomStruct &val)
#define PREFIX_WITH_MACRO(test_name)
const int test_generation_params[]
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
#define TEST_P(test_suite_name, test_name)
#define GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(T)
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name,...)
#define TEST_F(test_fixture, test_name)
#define EXPECT_EQ(val1, val2)
#define EXPECT_NE(val1, val2)
#define ASSERT_FALSE(condition)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
#define TEST(test_suite_name, test_name)
#define EXPECT_GE(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
#define EXPECT_FALSE(condition)
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()
REGISTER_TYPED_TEST_SUITE_P(NotInstantiatedTypeTest, Used)
NotInstantiatedTest OtherName
TYPED_TEST_SUITE_P(NotUsedTypeTest)
TYPED_TEST_P(NotInstantiatedTypeTest, Used)
std::string operator()(const ::testing::TestParamInfo< std::string > &inf)
std::string operator()(const ::testing::TestParamInfo< int > &info)