googletest-param-test-test.cc (googletest-release-1.10.0) | : | googletest-param-test-test.cc (googletest-release-1.11.0) | ||
---|---|---|---|---|
skipping to change at line 40 | skipping to change at line 40 | |||
// | // | |||
// Tests for Google Test itself. This file verifies that the parameter | // Tests for Google Test itself. This file verifies that the parameter | |||
// generators objects produce correct parameter sequences and that | // generators objects produce correct parameter sequences and that | |||
// Google Test runtime instantiates correct tests from those sequences. | // Google Test runtime instantiates correct tests from those sequences. | |||
#include "gtest/gtest.h" | #include "gtest/gtest.h" | |||
# include <algorithm> | # include <algorithm> | |||
# include <iostream> | # include <iostream> | |||
# include <list> | # include <list> | |||
# include <set> | ||||
# include <sstream> | # include <sstream> | |||
# include <string> | # include <string> | |||
# include <vector> | # include <vector> | |||
# include "src/gtest-internal-inl.h" // for UnitTestOptions | # include "src/gtest-internal-inl.h" // for UnitTestOptions | |||
# include "test/googletest-param-test-test.h" | # include "test/googletest-param-test-test.h" | |||
using ::std::vector; | using ::std::vector; | |||
using ::std::sort; | using ::std::sort; | |||
skipping to change at line 492 | skipping to change at line 493 | |||
std::tuple<const char*, int, int, int, int, int, int, int, int, int> | std::tuple<const char*, int, int, int, int, int, int, int, int, int> | |||
expected_values[] = {std::make_tuple(foo, 1, 2, 3, 4, 5, 6, 7, 8, 9), | expected_values[] = {std::make_tuple(foo, 1, 2, 3, 4, 5, 6, 7, 8, 9), | |||
std::make_tuple(bar, 1, 2, 3, 4, 5, 6, 7, 8, 9)}; | std::make_tuple(bar, 1, 2, 3, 4, 5, 6, 7, 8, 9)}; | |||
VerifyGenerator(gen, expected_values); | VerifyGenerator(gen, expected_values); | |||
} | } | |||
class NonDefaultConstructAssignString { | class NonDefaultConstructAssignString { | |||
public: | public: | |||
NonDefaultConstructAssignString(const std::string& s) : str_(s) {} | NonDefaultConstructAssignString(const std::string& s) : str_(s) {} | |||
NonDefaultConstructAssignString() = delete; | ||||
NonDefaultConstructAssignString(const NonDefaultConstructAssignString&) = | ||||
default; | ||||
NonDefaultConstructAssignString& operator=( | ||||
const NonDefaultConstructAssignString&) = delete; | ||||
~NonDefaultConstructAssignString() = default; | ||||
const std::string& str() const { return str_; } | const std::string& str() const { return str_; } | |||
private: | private: | |||
std::string str_; | std::string str_; | |||
// Not default constructible | ||||
NonDefaultConstructAssignString(); | ||||
// Not assignable | ||||
void operator=(const NonDefaultConstructAssignString&); | ||||
}; | }; | |||
TEST(CombineTest, NonDefaultConstructAssign) { | TEST(CombineTest, NonDefaultConstructAssign) { | |||
const ParamGenerator<std::tuple<int, NonDefaultConstructAssignString> > gen = | const ParamGenerator<std::tuple<int, NonDefaultConstructAssignString> > gen = | |||
Combine(Values(0, 1), Values(NonDefaultConstructAssignString("A"), | Combine(Values(0, 1), Values(NonDefaultConstructAssignString("A"), | |||
NonDefaultConstructAssignString("B"))); | NonDefaultConstructAssignString("B"))); | |||
ParamGenerator<std::tuple<int, NonDefaultConstructAssignString> >::iterator | ParamGenerator<std::tuple<int, NonDefaultConstructAssignString> >::iterator | |||
it = gen.begin(); | it = gen.begin(); | |||
skipping to change at line 804 | skipping to change at line 806 | |||
class MacroNamingTest : public TestWithParam<int> {}; | class MacroNamingTest : public TestWithParam<int> {}; | |||
#define PREFIX_WITH_FOO(test_name) Foo##test_name | #define PREFIX_WITH_FOO(test_name) Foo##test_name | |||
#define PREFIX_WITH_MACRO(test_name) Macro##test_name | #define PREFIX_WITH_MACRO(test_name) Macro##test_name | |||
TEST_P(PREFIX_WITH_MACRO(NamingTest), PREFIX_WITH_FOO(SomeTestName)) { | TEST_P(PREFIX_WITH_MACRO(NamingTest), PREFIX_WITH_FOO(SomeTestName)) { | |||
const ::testing::TestInfo* const test_info = | const ::testing::TestInfo* const test_info = | |||
::testing::UnitTest::GetInstance()->current_test_info(); | ::testing::UnitTest::GetInstance()->current_test_info(); | |||
EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_suite_name()); | EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_suite_name()); | |||
EXPECT_STREQ("FooSomeTestName", test_info->name()); | EXPECT_STREQ("FooSomeTestName/0", test_info->name()); | |||
} | } | |||
INSTANTIATE_TEST_SUITE_P(FortyTwo, MacroNamingTest, Values(42)); | INSTANTIATE_TEST_SUITE_P(FortyTwo, MacroNamingTest, Values(42)); | |||
// Tests the same thing for non-parametrized tests. | // Tests the same thing for non-parametrized tests. | |||
class MacroNamingTestNonParametrized : public ::testing::Test {}; | class MacroNamingTestNonParametrized : public ::testing::Test {}; | |||
TEST_F(PREFIX_WITH_MACRO(NamingTestNonParametrized), | TEST_F(PREFIX_WITH_MACRO(NamingTestNonParametrized), | |||
PREFIX_WITH_FOO(SomeTestName)) { | PREFIX_WITH_FOO(SomeTestName)) { | |||
const ::testing::TestInfo* const test_info = | const ::testing::TestInfo* const test_info = | |||
::testing::UnitTest::GetInstance()->current_test_info(); | ::testing::UnitTest::GetInstance()->current_test_info(); | |||
EXPECT_STREQ("MacroNamingTestNonParametrized", test_info->test_suite_name()); | EXPECT_STREQ("MacroNamingTestNonParametrized", test_info->test_suite_name()); | |||
EXPECT_STREQ("FooSomeTestName", test_info->name()); | EXPECT_STREQ("FooSomeTestName", test_info->name()); | |||
} | } | |||
TEST(MacroNameing, LookupNames) { | ||||
std::set<std::string> know_suite_names, know_test_names; | ||||
auto ins = testing::UnitTest::GetInstance(); | ||||
int ts = 0; | ||||
while (const testing::TestSuite* suite = ins->GetTestSuite(ts++)) { | ||||
know_suite_names.insert(suite->name()); | ||||
int ti = 0; | ||||
while (const testing::TestInfo* info = suite->GetTestInfo(ti++)) { | ||||
know_test_names.insert(std::string(suite->name()) + "." + info->name()); | ||||
} | ||||
} | ||||
// Check that the expected form of the test suit name actually exists. | ||||
EXPECT_NE( // | ||||
know_suite_names.find("FortyTwo/MacroNamingTest"), | ||||
know_suite_names.end()); | ||||
EXPECT_NE( | ||||
know_suite_names.find("MacroNamingTestNonParametrized"), | ||||
know_suite_names.end()); | ||||
// Check that the expected form of the test name actually exists. | ||||
EXPECT_NE( // | ||||
know_test_names.find("FortyTwo/MacroNamingTest.FooSomeTestName/0"), | ||||
know_test_names.end()); | ||||
EXPECT_NE( | ||||
know_test_names.find("MacroNamingTestNonParametrized.FooSomeTestName"), | ||||
know_test_names.end()); | ||||
} | ||||
// Tests that user supplied custom parameter names are working correctly. | // Tests that user supplied custom parameter names are working correctly. | |||
// Runs the test with a builtin helper method which uses PrintToString, | // Runs the test with a builtin helper method which uses PrintToString, | |||
// as well as a custom function and custom functor to ensure all possible | // as well as a custom function and custom functor to ensure all possible | |||
// uses work correctly. | // uses work correctly. | |||
class CustomFunctorNamingTest : public TestWithParam<std::string> {}; | class CustomFunctorNamingTest : public TestWithParam<std::string> {}; | |||
TEST_P(CustomFunctorNamingTest, CustomTestNames) {} | TEST_P(CustomFunctorNamingTest, CustomTestNames) {} | |||
struct CustomParamNameFunctor { | struct CustomParamNameFunctor { | |||
std::string operator()(const ::testing::TestParamInfo<std::string>& inf) { | std::string operator()(const ::testing::TestParamInfo<std::string>& inf) { | |||
return inf.param; | return inf.param; | |||
skipping to change at line 1039 | skipping to change at line 1071 | |||
ENUM2 = 3, | ENUM2 = 3, | |||
ENUM3 = 8, | ENUM3 = 8, | |||
}; | }; | |||
class MyEnumTest : public testing::TestWithParam<MyEnums> {}; | class MyEnumTest : public testing::TestWithParam<MyEnums> {}; | |||
TEST_P(MyEnumTest, ChecksParamMoreThanZero) { EXPECT_GE(10, GetParam()); } | TEST_P(MyEnumTest, ChecksParamMoreThanZero) { EXPECT_GE(10, GetParam()); } | |||
INSTANTIATE_TEST_SUITE_P(MyEnumTests, MyEnumTest, | INSTANTIATE_TEST_SUITE_P(MyEnumTests, MyEnumTest, | |||
::testing::Values(ENUM1, ENUM2, 0)); | ::testing::Values(ENUM1, ENUM2, 0)); | |||
namespace works_here { | ||||
// Never used not instantiated, this should work. | ||||
class NotUsedTest : public testing::TestWithParam<int> {}; | ||||
/////// | ||||
// Never used not instantiated, this should work. | ||||
template <typename T> | ||||
class NotUsedTypeTest : public testing::Test {}; | ||||
TYPED_TEST_SUITE_P(NotUsedTypeTest); | ||||
// Used but not instantiated, this would fail. but... | ||||
class NotInstantiatedTest : public testing::TestWithParam<int> {}; | ||||
// ... we mark is as allowed. | ||||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NotInstantiatedTest); | ||||
TEST_P(NotInstantiatedTest, Used) { } | ||||
using OtherName = NotInstantiatedTest; | ||||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(OtherName); | ||||
TEST_P(OtherName, Used) { } | ||||
// Used but not instantiated, this would fail. but... | ||||
template <typename T> | ||||
class NotInstantiatedTypeTest : public testing::Test {}; | ||||
TYPED_TEST_SUITE_P(NotInstantiatedTypeTest); | ||||
// ... we mark is as allowed. | ||||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NotInstantiatedTypeTest); | ||||
TYPED_TEST_P(NotInstantiatedTypeTest, Used) { } | ||||
REGISTER_TYPED_TEST_SUITE_P(NotInstantiatedTypeTest, Used); | ||||
} // namespace works_here | ||||
int main(int argc, char **argv) { | int main(int argc, char **argv) { | |||
// Used in TestGenerationTest test suite. | // Used in TestGenerationTest test suite. | |||
AddGlobalTestEnvironment(TestGenerationTest::Environment::Instance()); | AddGlobalTestEnvironment(TestGenerationTest::Environment::Instance()); | |||
// Used in GeneratorEvaluationTest test suite. Tests that the updated value | // Used in GeneratorEvaluationTest test suite. Tests that the updated value | |||
// will be picked up for instantiating tests in GeneratorEvaluationTest. | // will be picked up for instantiating tests in GeneratorEvaluationTest. | |||
GeneratorEvaluationTest::set_param_value(1); | GeneratorEvaluationTest::set_param_value(1); | |||
::testing::InitGoogleTest(&argc, argv); | ::testing::InitGoogleTest(&argc, argv); | |||
// Used in GeneratorEvaluationTest test suite. Tests that value updated | // Used in GeneratorEvaluationTest test suite. Tests that value updated | |||
End of changes. 6 change blocks. | ||||
6 lines changed or deleted | 70 lines changed or added |