From dee725b05332ca59a679c7b7dde5297c502d34b4 Mon Sep 17 00:00:00 2001 From: Krystian Kuzniarek Date: Mon, 11 Nov 2019 17:17:52 +0100 Subject: [PATCH 001/586] add documentation for the premature-exit-file protocol --- googletest/docs/advanced.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/googletest/docs/advanced.md b/googletest/docs/advanced.md index ce8644e4..217d527a 100644 --- a/googletest/docs/advanced.md +++ b/googletest/docs/advanced.md @@ -2541,6 +2541,18 @@ IMPORTANT: The exact format of the JSON document is subject to change. ### Controlling How Failures Are Reported +#### Detecting Test Premature Exit + +Google Test implements the _premature-exit-file_ protocol for test runners +to catch any kind of unexpected exits of test programs. Upon start, +Google Test creates the file which will be automatically deleted after +all work has been finished. Then, the test runner can check if this file +exists. In case the file remains undeleted, the inspected test has exited +prematurely. + +This feature is enabled only if the `TEST_PREMATURE_EXIT_FILE` environment +variable has been set. + #### Turning Assertion Failures into Break-Points When running test programs under a debugger, it's very convenient if the From 3aa538cbfcc65989721632d2a8d79539512ebdb7 Mon Sep 17 00:00:00 2001 From: Muhammad Hilman Beyri Date: Sun, 12 Jan 2020 16:53:09 -0500 Subject: [PATCH 002/586] fix unit test failure on NoShortCircuitOnFailure and DetectsFlakyShortCircuit when GTEST_HAS_RTTI is 1 --- googlemock/test/gmock-matchers_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index e6e8c8f4..98b814ba 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -6885,7 +6885,7 @@ TEST_F(PredicateFormatterFromMatcherTest, NoShortCircuitOnFailure) { EXPECT_FALSE(result); // Implicit cast to bool. std::string expect = "Value of: dummy-name\nExpected: [DescribeTo]\n" - " Actual: 1, [MatchAndExplain]"; + " Actual: 1" + OfType(internal::GetTypeName()) + ", [MatchAndExplain]"; EXPECT_EQ(expect, result.message()); } @@ -6896,7 +6896,7 @@ TEST_F(PredicateFormatterFromMatcherTest, DetectsFlakyShortCircuit) { "Value of: dummy-name\nExpected: [DescribeTo]\n" " The matcher failed on the initial attempt; but passed when rerun to " "generate the explanation.\n" - " Actual: 2, [MatchAndExplain]"; + " Actual: 2" + OfType(internal::GetTypeName()) + ", [MatchAndExplain]"; EXPECT_EQ(expect, result.message()); } From c7137f0b8422cb4544a8adb2ebc1de0ea71cae55 Mon Sep 17 00:00:00 2001 From: Muhammad Hilman Beyri Date: Sun, 12 Jan 2020 21:29:54 -0500 Subject: [PATCH 003/586] Use IsReadableTypeName IsReadableTypeName in OfType function in gmock-matchers_test.cc --- googlemock/test/gmock-matchers_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 98b814ba..96ca8959 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -140,7 +140,7 @@ Matcher GreaterThan(int n) { std::string OfType(const std::string& type_name) { #if GTEST_HAS_RTTI - return " (of type " + type_name + ")"; + return IsReadableTypeName(type_name) ? " (of type " + type_name + ")" : ""; #else return ""; #endif From aa4315646b2217f30a537121e044aa14b33248e5 Mon Sep 17 00:00:00 2001 From: Ivan Oliveira Tarifa <36923279+ivan1993br@users.noreply.github.com> Date: Wed, 15 Jan 2020 08:45:14 -0300 Subject: [PATCH 004/586] Remove exclusion of *-main and*-all targets Removing exclusion of *-main and*-all targets from the library.json used on platformio. --- library.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/library.json b/library.json index 91169b7f..f61bf003 100644 --- a/library.json +++ b/library.json @@ -25,14 +25,10 @@ "ci", "googlemock/cmake", "googlemock/scripts", - "googlemock/src/gmock-all.cc", - "googlemock/src/gmock_main.cc", "googlemock/test", "googlemock/CMakeLists.txt", "googletest/cmake", "googletest/scripts", - "googletest/src/gtest-all.cc", - "googletest/src/gtest_main.cc", "googletest/test", "googletest/CMakeLists.txt" ] From ed16134fb31382fd41e8fe513a0e9e940d04cd31 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 10 Jan 2020 11:57:33 -0500 Subject: [PATCH 005/586] Googletest export Change testing::TempDir() return value for Android PiperOrigin-RevId: 289102017 --- googletest/src/gtest.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 07015cba..2df647ba 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -6289,7 +6289,11 @@ std::string TempDir() { else return std::string(temp_dir) + "\\"; #elif GTEST_OS_LINUX_ANDROID - return "/sdcard/"; + const char* temp_dir = internal::posix::GetEnv("TEST_TMPDIR"); + if (temp_dir == nullptr || temp_dir[0] == '\0') + return "/data/local/tmp/"; + else + return temp_dir; #else return "/tmp/"; #endif // GTEST_OS_WINDOWS_MOBILE From 0b024bd91a14a77a7e7d6072ccd88e09c86ddeaa Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 14 Jan 2020 00:41:46 -0500 Subject: [PATCH 006/586] Googletest export Add GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST to mark a paramaterized test as allowed to be un-instantiated. This allows test suites, that are defined in libraries and, for other reasons, get linked in (which should probably be avoided, but isn't always possible) to be marked as allowed to go uninstantiated. This can also be used to grandfather existing issues and expedite adoption of the checks with regards to new cases before they can be fixed. PiperOrigin-RevId: 289581573 --- googletest/docs/advanced.md | 11 +++++++++++ googletest/include/gtest/gtest-param-test.h | 7 +++++++ googletest/include/gtest/gtest.h | 2 ++ .../include/gtest/internal/gtest-param-util.h | 8 ++++++++ googletest/src/gtest-internal-inl.h | 8 ++++++++ googletest/src/gtest.cc | 19 ++++++++++++++++++- .../googletest-output-test-golden-lin.txt | 4 ++++ googletest/test/googletest-param-test-test.cc | 11 +++++++++++ 8 files changed, 69 insertions(+), 1 deletion(-) diff --git a/googletest/docs/advanced.md b/googletest/docs/advanced.md index 10af769e..5631e8ea 100644 --- a/googletest/docs/advanced.md +++ b/googletest/docs/advanced.md @@ -1377,6 +1377,17 @@ function scope. NOTE: Don't forget this step! If you do your test will silently pass, but none of its suites will ever run! +There is work in progress to make omitting `INSTANTIATE_TEST_SUITE_P` show up +under the `GoogleTestVerification` test suite and to then make that an error. +If you have a test suite where that omission is not an error, for example it is +in a library that may be linked in for other reason or where the list of test +cases is dynamic and may be empty, then this check can be suppressed by tagging +the test suite: + +```c++ +GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(FooTest); +``` + To distinguish different instances of the pattern (yes, you can instantiate it more than once), the first argument to `INSTANTIATE_TEST_SUITE_P` is a prefix that will be added to the actual test suite name. Remember to pick unique diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index 70593da5..37417a98 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -491,6 +491,13 @@ internal::CartesianProductHolder Combine(const Generator&... g) { >est_##prefix##test_suite_name##_EvalGenerateName_, \ __FILE__, __LINE__) + +// Allow Marking a Parameterized test class as not needing to be instantiated. +#define GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(T) \ + namespace gtest_do_not_use_outside_namespace_scope {} \ + static const ::testing::internal::MarkAsIgnored gtest_allow_ignore_##T( \ + GTEST_STRINGIFY_(T)) + // Legacy API is deprecated but still available #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ #define INSTANTIATE_TEST_CASE_P \ diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index eb44c4cd..464b3169 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -177,6 +177,7 @@ class FuchsiaDeathTest; class UnitTestImpl* GetUnitTestImpl(); void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string& message); +std::set* GetIgnoredParameterizedTestSuites(); } // namespace internal @@ -1418,6 +1419,7 @@ class GTEST_API_ UnitTest { friend class internal::StreamingListenerTest; friend class internal::UnitTestRecordPropertyTestHelper; friend Environment* AddGlobalTestEnvironment(Environment* env); + friend std::set* internal::GetIgnoredParameterizedTestSuites(); friend internal::UnitTestImpl* internal::GetUnitTestImpl(); friend void internal::ReportFailureInUnknownLocation( TestPartResult::Type result_type, diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h index ffa7d72c..65aa9568 100644 --- a/googletest/include/gtest/internal/gtest-param-util.h +++ b/googletest/include/gtest/internal/gtest-param-util.h @@ -474,6 +474,14 @@ class ParameterizedTestSuiteInfoBase { GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfoBase); }; +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Report a the name of a test_suit as safe to ignore +// as the side effect of construction of this type. +struct MarkAsIgnored { + explicit MarkAsIgnored(const char* test_suite); +}; + GTEST_API_ void InsertSyntheticTestCase(const std::string& name, CodeLocation location); diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h index d0ebe0c5..e42ff475 100644 --- a/googletest/src/gtest-internal-inl.h +++ b/googletest/src/gtest-internal-inl.h @@ -698,6 +698,10 @@ class GTEST_API_ UnitTestImpl { return parameterized_test_registry_; } + std::set* ignored_parameterized_test_suites() { + return &ignored_parameterized_test_suites_; + } + // Returns TypeParameterizedTestSuiteRegistry object used to keep track of // type-parameterized tests and instantiations of them. internal::TypeParameterizedTestSuiteRegistry& @@ -884,6 +888,10 @@ class GTEST_API_ UnitTestImpl { internal::TypeParameterizedTestSuiteRegistry type_parameterized_test_registry_; + // The set holding the name of parameterized + // test suites that may go uninstantiated. + std::set ignored_parameterized_test_suites_; + // Indicates whether RegisterParameterizedTests() has been called already. bool parameterized_tests_registered_; diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 2df647ba..1abc664f 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -444,9 +444,21 @@ class FailureTest : public Test { } // namespace +std::set* GetIgnoredParameterizedTestSuites() { + return UnitTest::GetInstance()->impl()->ignored_parameterized_test_suites(); +} + +// Add a given test_suit to the list of them allow to go un-instantiated. +MarkAsIgnored::MarkAsIgnored(const char* test_suite) { + GetIgnoredParameterizedTestSuites()->insert(test_suite); +} + // If this parameterized test suite has no instantiations (and that // has not been marked as okay), emit a test case reporting that. void InsertSyntheticTestCase(const std::string &name, CodeLocation location) { + const auto& ignored = *GetIgnoredParameterizedTestSuites(); + if (ignored.find(name) != ignored.end()) return; + std::string message = "Paramaterized test suite " + name + " is defined via TEST_P, but never instantiated. None of the test cases " @@ -455,7 +467,12 @@ void InsertSyntheticTestCase(const std::string &name, CodeLocation location) { "\n\n" "Ideally, TEST_P definitions should only ever be included as part of " "binaries that intend to use them. (As opposed to, for example, being " - "placed in a library that may be linked in to get other utilities.)"; + "placed in a library that may be linked in to get other utilities.)" + "\n\n" + "To suppress this error for this test suite, insert the following line " + "(in a non-header) in the namespace it is defined in:" + "\n\n" + "GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(" + name + ");"; std::string full_name = "UninstantiatedParamaterizedTestSuite<" + name + ">"; RegisterTest( // diff --git a/googletest/test/googletest-output-test-golden-lin.txt b/googletest/test/googletest-output-test-golden-lin.txt index c1db004c..72490816 100644 --- a/googletest/test/googletest-output-test-golden-lin.txt +++ b/googletest/test/googletest-output-test-golden-lin.txt @@ -987,6 +987,10 @@ Stack trace: (omitted) Paramaterized test suite DetectNotInstantiatedTest is defined via TEST_P, but never instantiated. None of the test cases will run. Either no INSTANTIATE_TEST_SUITE_P is provided or the only ones provided expand to nothing. Ideally, TEST_P definitions should only ever be included as part of binaries that intend to use them. (As opposed to, for example, being placed in a library that may be linked in to get other utilities.) + +To suppress this error for this test suite, insert the following line (in a non-header) in the namespace it is defined in: + +GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(DetectNotInstantiatedTest); [ OK ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite [ RUN ] GoogleTestVerification.UninstantiatedTypeParamaterizedTestSuite Type paramaterized test suite DetectNotInstantiatedTypesTest is defined via REGISTER_TYPED_TEST_SUITE_P, but never instantiated via INSTANTIATE_TYPED_TEST_SUITE_P. None of the test cases will run. diff --git a/googletest/test/googletest-param-test-test.cc b/googletest/test/googletest-param-test-test.cc index f92eb316..b3b8140d 100644 --- a/googletest/test/googletest-param-test-test.cc +++ b/googletest/test/googletest-param-test-test.cc @@ -1077,6 +1077,17 @@ class NotUsedTest : public testing::TestWithParam {}; template class NotUsedTypeTest : public testing::Test {}; TYPED_TEST_SUITE_P(NotUsedTypeTest); + +// Used but not instantiated, this would fail. but... +class NotInstantiatedTest : public testing::TestWithParam {}; +// ... we mark is as allowed. +GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(NotInstantiatedTest); + +TEST_P(NotInstantiatedTest, Used) { } + +using OtherName = NotInstantiatedTest; +GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(OtherName); +TEST_P(OtherName, Used) { } } // namespace works_here int main(int argc, char **argv) { From 7a8591e6e4e206b748feb052f620c45278e686d0 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 14 Jan 2020 11:20:24 -0500 Subject: [PATCH 007/586] Googletest export Use GMOCK_PP to generate args boilerplate. Move common args describing part to separate macroses that uses GMOCK_PP to generate sequences. PiperOrigin-RevId: 289655624 --- googlemock/include/gmock/gmock-actions.h | 16 ++ .../include/gmock/gmock-generated-actions.h | 217 +++--------------- .../gmock/gmock-generated-actions.h.pump | 23 +- 3 files changed, 58 insertions(+), 198 deletions(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index a7b84d1b..7b1a14c7 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -50,6 +50,7 @@ #include "gmock/internal/gmock-internal-utils.h" #include "gmock/internal/gmock-port.h" +#include "gmock/internal/gmock-pp.h" #ifdef _MSC_VER # pragma warning(push) @@ -1275,6 +1276,21 @@ auto InvokeArgumentAdl(AdlTag, F f, Args... args) -> decltype(f(args...)) { } } // namespace invoke_argument + +#define GMOCK_INTERNAL_ARG_UNUSED(N, data, el) \ + , const arg##N##_type& arg##N GTEST_ATTRIBUTE_UNUSED_ +#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_ \ + const args_type& args GTEST_ATTRIBUTE_UNUSED_ GMOCK_PP_REPEAT( \ + GMOCK_INTERNAL_ARG_UNUSED, , 10) + +#define GMOCK_INTERNAL_ARG(N, data, el) , const arg##N##_type& arg##N +#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_ \ + const args_type& args GMOCK_PP_REPEAT(GMOCK_INTERNAL_ARG, , 10) + +#define GMOCK_INTERNAL_TEMPLATE_ARG(N, data, el) , typename arg##N##_type +#define GMOCK_ACTION_TEMPLATE_ARGS_NAMES_ \ + GMOCK_PP_TAIL(GMOCK_PP_REPEAT(GMOCK_INTERNAL_TEMPLATE_ARG, , 10)) + } // namespace internal } // namespace testing diff --git a/googlemock/include/gmock/gmock-generated-actions.h b/googlemock/include/gmock/gmock-generated-actions.h index 2db4b3c1..8c20eee0 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h +++ b/googlemock/include/gmock/gmock-generated-actions.h @@ -142,19 +142,6 @@ // To learn more about using these macros, please search for 'ACTION' on // https://github.com/google/googletest/blob/master/googlemock/docs/cook_book.md -// An internal macro needed for implementing ACTION*(). -#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\ - const args_type& args GTEST_ATTRIBUTE_UNUSED_, \ - const arg0_type& arg0 GTEST_ATTRIBUTE_UNUSED_, \ - const arg1_type& arg1 GTEST_ATTRIBUTE_UNUSED_, \ - const arg2_type& arg2 GTEST_ATTRIBUTE_UNUSED_, \ - const arg3_type& arg3 GTEST_ATTRIBUTE_UNUSED_, \ - const arg4_type& arg4 GTEST_ATTRIBUTE_UNUSED_, \ - const arg5_type& arg5 GTEST_ATTRIBUTE_UNUSED_, \ - const arg6_type& arg6 GTEST_ATTRIBUTE_UNUSED_, \ - const arg7_type& arg7 GTEST_ATTRIBUTE_UNUSED_, \ - const arg8_type& arg8 GTEST_ATTRIBUTE_UNUSED_, \ - const arg9_type& arg9 GTEST_ATTRIBUTE_UNUSED_ // Sometimes you want to give an action explicit template parameters // that cannot be inferred from its value parameters. ACTION() and @@ -540,16 +527,8 @@ return ::testing::internal::ActionHelper::\ Perform(this, args);\ }\ - template \ - return_type gmock_PerformImpl(const args_type& args, \ - const arg0_type& arg0, const arg1_type& arg1, \ - const arg2_type& arg2, const arg3_type& arg3, \ - const arg4_type& arg4, const arg5_type& arg5, \ - const arg6_type& arg6, const arg7_type& arg7, \ - const arg8_type& arg8, const arg9_type& arg9) const;\ + template \ + return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ GMOCK_INTERNAL_DEFN_##value_params\ private:\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ @@ -576,10 +555,7 @@ template \ template \ - template \ + template \ typename ::testing::internal::Function::Result\ GMOCK_ACTION_CLASS_(name, value_params)<\ GMOCK_INTERNAL_LIST_##template_params\ @@ -604,16 +580,8 @@ return ::testing::internal::ActionHelper::\ Perform(this, args);\ }\ - template \ - return_type gmock_PerformImpl(const args_type& args, \ - const arg0_type& arg0, const arg1_type& arg1, \ - const arg2_type& arg2, const arg3_type& arg3, \ - const arg4_type& arg4, const arg5_type& arg5, \ - const arg6_type& arg6, const arg7_type& arg7, \ - const arg8_type& arg8, const arg9_type& arg9) const;\ + template \ + return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ private:\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ @@ -624,10 +592,7 @@ return name##Action();\ }\ template \ - template \ + template \ typename ::testing::internal::Function::Result\ name##Action::gmock_Impl::gmock_PerformImpl(\ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const @@ -652,16 +617,8 @@ return ::testing::internal::ActionHelper::\ Perform(this, args);\ }\ - template \ - return_type gmock_PerformImpl(const args_type& args, \ - const arg0_type& arg0, const arg1_type& arg1, \ - const arg2_type& arg2, const arg3_type& arg3, \ - const arg4_type& arg4, const arg5_type& arg5, \ - const arg6_type& arg6, const arg7_type& arg7, \ - const arg8_type& arg8, const arg9_type& arg9) const;\ + template \ + return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ p0##_type p0;\ private:\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ @@ -675,10 +632,7 @@ }\ template \ template \ - template \ + template \ typename ::testing::internal::Function::Result\ name##ActionP::gmock_Impl::gmock_PerformImpl(\ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const @@ -705,16 +659,8 @@ return ::testing::internal::ActionHelper::\ Perform(this, args);\ }\ - template \ - return_type gmock_PerformImpl(const args_type& args, \ - const arg0_type& arg0, const arg1_type& arg1, \ - const arg2_type& arg2, const arg3_type& arg3, \ - const arg4_type& arg4, const arg5_type& arg5, \ - const arg6_type& arg6, const arg7_type& arg7, \ - const arg8_type& arg8, const arg9_type& arg9) const;\ + template \ + return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ p0##_type p0;\ p1##_type p1;\ private:\ @@ -730,10 +676,7 @@ }\ template \ template \ - template \ + template \ typename ::testing::internal::Function::Result\ name##ActionP2::gmock_Impl::gmock_PerformImpl(\ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const @@ -761,16 +704,8 @@ return ::testing::internal::ActionHelper::\ Perform(this, args);\ }\ - template \ - return_type gmock_PerformImpl(const args_type& args, \ - const arg0_type& arg0, const arg1_type& arg1, \ - const arg2_type& arg2, const arg3_type& arg3, \ - const arg4_type& arg4, const arg5_type& arg5, \ - const arg6_type& arg6, const arg7_type& arg7, \ - const arg8_type& arg8, const arg9_type& arg9) const;\ + template \ + return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ p0##_type p0;\ p1##_type p1;\ p2##_type p2;\ @@ -787,10 +722,7 @@ }\ template \ template \ - template \ + template \ typename ::testing::internal::Function::Result\ name##ActionP3::gmock_Impl::gmock_PerformImpl(\ @@ -821,16 +753,8 @@ return ::testing::internal::ActionHelper::\ Perform(this, args);\ }\ - template \ - return_type gmock_PerformImpl(const args_type& args, \ - const arg0_type& arg0, const arg1_type& arg1, \ - const arg2_type& arg2, const arg3_type& arg3, \ - const arg4_type& arg4, const arg5_type& arg5, \ - const arg6_type& arg6, const arg7_type& arg7, \ - const arg8_type& arg8, const arg9_type& arg9) const;\ + template \ + return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ p0##_type p0;\ p1##_type p1;\ p2##_type p2;\ @@ -852,10 +776,7 @@ template \ template \ - template \ + template \ typename ::testing::internal::Function::Result\ name##ActionP4::gmock_Impl::gmock_PerformImpl(\ @@ -888,16 +809,8 @@ return ::testing::internal::ActionHelper::\ Perform(this, args);\ }\ - template \ - return_type gmock_PerformImpl(const args_type& args, \ - const arg0_type& arg0, const arg1_type& arg1, \ - const arg2_type& arg2, const arg3_type& arg3, \ - const arg4_type& arg4, const arg5_type& arg5, \ - const arg6_type& arg6, const arg7_type& arg7, \ - const arg8_type& arg8, const arg9_type& arg9) const;\ + template \ + return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ p0##_type p0;\ p1##_type p1;\ p2##_type p2;\ @@ -920,10 +833,7 @@ template \ template \ - template \ + template \ typename ::testing::internal::Function::Result\ name##ActionP5::gmock_Impl::gmock_PerformImpl(\ @@ -957,16 +867,8 @@ return ::testing::internal::ActionHelper::\ Perform(this, args);\ }\ - template \ - return_type gmock_PerformImpl(const args_type& args, \ - const arg0_type& arg0, const arg1_type& arg1, \ - const arg2_type& arg2, const arg3_type& arg3, \ - const arg4_type& arg4, const arg5_type& arg5, \ - const arg6_type& arg6, const arg7_type& arg7, \ - const arg8_type& arg8, const arg9_type& arg9) const;\ + template \ + return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ p0##_type p0;\ p1##_type p1;\ p2##_type p2;\ @@ -990,10 +892,7 @@ template \ template \ - template \ + template \ typename ::testing::internal::Function::Result\ name##ActionP6::gmock_Impl::gmock_PerformImpl(\ @@ -1029,16 +928,8 @@ return ::testing::internal::ActionHelper::\ Perform(this, args);\ }\ - template \ - return_type gmock_PerformImpl(const args_type& args, \ - const arg0_type& arg0, const arg1_type& arg1, \ - const arg2_type& arg2, const arg3_type& arg3, \ - const arg4_type& arg4, const arg5_type& arg5, \ - const arg6_type& arg6, const arg7_type& arg7, \ - const arg8_type& arg8, const arg9_type& arg9) const;\ + template \ + return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ p0##_type p0;\ p1##_type p1;\ p2##_type p2;\ @@ -1066,10 +957,7 @@ typename p3##_type, typename p4##_type, typename p5##_type, \ typename p6##_type>\ template \ - template \ + template \ typename ::testing::internal::Function::Result\ name##ActionP7::gmock_Impl::gmock_PerformImpl(\ @@ -1107,16 +995,8 @@ return ::testing::internal::ActionHelper::\ Perform(this, args);\ }\ - template \ - return_type gmock_PerformImpl(const args_type& args, \ - const arg0_type& arg0, const arg1_type& arg1, \ - const arg2_type& arg2, const arg3_type& arg3, \ - const arg4_type& arg4, const arg5_type& arg5, \ - const arg6_type& arg6, const arg7_type& arg7, \ - const arg8_type& arg8, const arg9_type& arg9) const;\ + template \ + return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ p0##_type p0;\ p1##_type p1;\ p2##_type p2;\ @@ -1146,10 +1026,7 @@ typename p3##_type, typename p4##_type, typename p5##_type, \ typename p6##_type, typename p7##_type>\ template \ - template \ + template \ typename ::testing::internal::Function::Result\ name##ActionP8::\ Perform(this, args);\ }\ - template \ - return_type gmock_PerformImpl(const args_type& args, \ - const arg0_type& arg0, const arg1_type& arg1, \ - const arg2_type& arg2, const arg3_type& arg3, \ - const arg4_type& arg4, const arg5_type& arg5, \ - const arg6_type& arg6, const arg7_type& arg7, \ - const arg8_type& arg8, const arg9_type& arg9) const;\ + template \ + return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ p0##_type p0;\ p1##_type p1;\ p2##_type p2;\ @@ -1231,10 +1100,7 @@ typename p3##_type, typename p4##_type, typename p5##_type, \ typename p6##_type, typename p7##_type, typename p8##_type>\ template \ - template \ + template \ typename ::testing::internal::Function::Result\ name##ActionP9::\ Perform(this, args);\ }\ - template \ - return_type gmock_PerformImpl(const args_type& args, \ - const arg0_type& arg0, const arg1_type& arg1, \ - const arg2_type& arg2, const arg3_type& arg3, \ - const arg4_type& arg4, const arg5_type& arg5, \ - const arg6_type& arg6, const arg7_type& arg7, \ - const arg8_type& arg8, const arg9_type& arg9) const;\ + template \ + return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ p0##_type p0;\ p1##_type p1;\ p2##_type p2;\ @@ -1321,10 +1179,7 @@ typename p6##_type, typename p7##_type, typename p8##_type, \ typename p9##_type>\ template \ - template \ + template \ typename ::testing::internal::Function::Result\ name##ActionP10::\ Perform(this, args);\ }\ - template <$for k, [[typename arg$k[[]]_type]]>\ - return_type gmock_PerformImpl(const args_type& args[[]] -$for k [[, const arg$k[[]]_type& arg$k]]) const;\ + template \ + return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ GMOCK_INTERNAL_DEFN_##value_params\ private:\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ @@ -380,10 +373,7 @@ $for k [[, const arg$k[[]]_type& arg$k]]) const;\ template \ template \ - template \ + template \ typename ::testing::internal::Function::Result\ GMOCK_ACTION_CLASS_(name, value_params)<\ GMOCK_INTERNAL_LIST_##template_params\ @@ -439,9 +429,8 @@ $var macro_name = [[$if i==0 [[ACTION]] $elif i==1 [[ACTION_P]] return ::testing::internal::ActionHelper::\ Perform(this, args);\ }\ - template <$typename_arg_types>\ - return_type gmock_PerformImpl(const args_type& args, [[]] -$arg_types_and_names) const;\$param_field_decls + template \ + return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\$param_field_decls private:\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ @@ -452,7 +441,7 @@ $arg_types_and_names) const;\$param_field_decls return $class_name$param_types($params);\ }\$template template \ - template <$typename_arg_types>\ + template \ typename ::testing::internal::Function::Result\ $class_name$param_types::gmock_Impl::gmock_PerformImpl(\ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const From 3e79d366e380ec85b7de9409211b184bc8529655 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 14 Jan 2020 14:56:23 -0500 Subject: [PATCH 008/586] Googletest export Wire up things to support marking a type paramaterized test as allowed to be un-instantiated. PiperOrigin-RevId: 289699939 --- googletest/src/gtest.cc | 9 ++++++++- googletest/test/googletest-output-test-golden-lin.txt | 4 ++++ googletest/test/googletest-param-test-test.cc | 10 ++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 1abc664f..8e68c04e 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -515,8 +515,10 @@ void TypeParameterizedTestSuiteRegistry::RegisterInstantiation( } void TypeParameterizedTestSuiteRegistry::CheckForInstantiations() { + const auto& ignored = *GetIgnoredParameterizedTestSuites(); for (const auto& testcase : suites_) { if (testcase.second.instantiated) continue; + if (ignored.find(testcase.first) != ignored.end()) continue; std::string message = "Type paramaterized test suite " + testcase.first + @@ -526,7 +528,12 @@ void TypeParameterizedTestSuiteRegistry::CheckForInstantiations() { "Ideally, TYPED_TEST_P definitions should only ever be included as " "part of binaries that intend to use them. (As opposed to, for " "example, being placed in a library that may be linked in to get other " - "utilities.)"; + "utilities.)" + "\n\n" + "To suppress this error for this test suite, insert the following line " + "(in a non-header) in the namespace it is definedin in:" + "\n\n" + "GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(" + testcase.first + ");"; std::string full_name = "UninstantiatedTypeParamaterizedTestSuite<" + testcase.first + ">"; diff --git a/googletest/test/googletest-output-test-golden-lin.txt b/googletest/test/googletest-output-test-golden-lin.txt index 72490816..a4a096e4 100644 --- a/googletest/test/googletest-output-test-golden-lin.txt +++ b/googletest/test/googletest-output-test-golden-lin.txt @@ -996,6 +996,10 @@ GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(DetectNotInstantiatedTest); Type paramaterized test suite DetectNotInstantiatedTypesTest is defined via REGISTER_TYPED_TEST_SUITE_P, but never instantiated via INSTANTIATE_TYPED_TEST_SUITE_P. None of the test cases will run. Ideally, TYPED_TEST_P definitions should only ever be included as part of binaries that intend to use them. (As opposed to, for example, being placed in a library that may be linked in to get other utilities.) + +To suppress this error for this test suite, insert the following line (in a non-header) in the namespace it is definedin in: + +GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(DetectNotInstantiatedTypesTest); [ OK ] GoogleTestVerification.UninstantiatedTypeParamaterizedTestSuite [----------] Global test environment tear-down BarEnvironment::TearDown() called. diff --git a/googletest/test/googletest-param-test-test.cc b/googletest/test/googletest-param-test-test.cc index b3b8140d..72a48375 100644 --- a/googletest/test/googletest-param-test-test.cc +++ b/googletest/test/googletest-param-test-test.cc @@ -1088,6 +1088,16 @@ TEST_P(NotInstantiatedTest, Used) { } using OtherName = NotInstantiatedTest; GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(OtherName); TEST_P(OtherName, Used) { } + +// Used but not instantiated, this would fail. but... +template +class NotInstantiatedTypeTest : public testing::Test {}; +TYPED_TEST_SUITE_P(NotInstantiatedTypeTest); +// ... we mark is as allowed. +GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(NotInstantiatedTypeTest); + +TYPED_TEST_P(NotInstantiatedTypeTest, Used) { } +REGISTER_TYPED_TEST_SUITE_P(NotInstantiatedTypeTest, Used); } // namespace works_here int main(int argc, char **argv) { From 5336106b66db4726174da8c2bdd5d4e80c55897e Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 15 Jan 2020 04:39:34 -0500 Subject: [PATCH 009/586] Googletest export Use GMOCK_PP to create GMOCK_INTERNAL_ACTION macro. Create GMOCK_INTERNAL_ACTION macro that generates ACTION_P* macroses using GMOCK_PP. PiperOrigin-RevId: 289815906 --- googlemock/include/gmock/gmock-actions.h | 243 +++++- .../include/gmock/gmock-generated-actions.h | 717 ------------------ .../gmock/gmock-generated-actions.h.pump | 163 ---- 3 files changed, 238 insertions(+), 885 deletions(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 7b1a14c7..88011798 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -30,7 +30,100 @@ // Google Mock - a framework for writing C++ mock classes. // -// This file implements some commonly used actions. +// The ACTION* family of macros can be used in a namespace scope to +// define custom actions easily. The syntax: +// +// ACTION(name) { statements; } +// +// will define an action with the given name that executes the +// statements. The value returned by the statements will be used as +// the return value of the action. Inside the statements, you can +// refer to the K-th (0-based) argument of the mock function by +// 'argK', and refer to its type by 'argK_type'. For example: +// +// ACTION(IncrementArg1) { +// arg1_type temp = arg1; +// return ++(*temp); +// } +// +// allows you to write +// +// ...WillOnce(IncrementArg1()); +// +// You can also refer to the entire argument tuple and its type by +// 'args' and 'args_type', and refer to the mock function type and its +// return type by 'function_type' and 'return_type'. +// +// Note that you don't need to specify the types of the mock function +// arguments. However rest assured that your code is still type-safe: +// you'll get a compiler error if *arg1 doesn't support the ++ +// operator, or if the type of ++(*arg1) isn't compatible with the +// mock function's return type, for example. +// +// Sometimes you'll want to parameterize the action. For that you can use +// another macro: +// +// ACTION_P(name, param_name) { statements; } +// +// For example: +// +// ACTION_P(Add, n) { return arg0 + n; } +// +// will allow you to write: +// +// ...WillOnce(Add(5)); +// +// Note that you don't need to provide the type of the parameter +// either. If you need to reference the type of a parameter named +// 'foo', you can write 'foo_type'. For example, in the body of +// ACTION_P(Add, n) above, you can write 'n_type' to refer to the type +// of 'n'. +// +// We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support +// multi-parameter actions. +// +// For the purpose of typing, you can view +// +// ACTION_Pk(Foo, p1, ..., pk) { ... } +// +// as shorthand for +// +// template +// FooActionPk Foo(p1_type p1, ..., pk_type pk) { ... } +// +// In particular, you can provide the template type arguments +// explicitly when invoking Foo(), as in Foo(5, false); +// although usually you can rely on the compiler to infer the types +// for you automatically. You can assign the result of expression +// Foo(p1, ..., pk) to a variable of type FooActionPk. This can be useful when composing actions. +// +// You can also overload actions with different numbers of parameters: +// +// ACTION_P(Plus, a) { ... } +// ACTION_P2(Plus, a, b) { ... } +// +// While it's tempting to always use the ACTION* macros when defining +// a new action, you should also consider implementing ActionInterface +// or using MakePolymorphicAction() instead, especially if you need to +// use the action a lot. While these approaches require more work, +// they give you more control on the types of the mock function +// arguments and the action parameters, which in general leads to +// better compiler error messages that pay off in the long run. They +// also allow overloading actions based on parameter types (as opposed +// to just based on the number of parameters). +// +// CAVEAT: +// +// ACTION*() can only be used in a namespace scope as templates cannot be +// declared inside of a local class. +// Users can, however, define any local functors (e.g. a lambda) that +// can be used as actions. +// +// MORE INFORMATION: +// +// To learn more about using these macros, please search for 'ACTION' on +// https://github.com/google/googletest/blob/master/googlemock/docs/cook_book.md // GOOGLETEST_CM0002 DO NOT DELETE @@ -1277,22 +1370,162 @@ auto InvokeArgumentAdl(AdlTag, F f, Args... args) -> decltype(f(args...)) { } // namespace invoke_argument -#define GMOCK_INTERNAL_ARG_UNUSED(N, data, el) \ - , const arg##N##_type& arg##N GTEST_ATTRIBUTE_UNUSED_ +#define GMOCK_INTERNAL_ARG_UNUSED(i, data, el) \ + , const arg##i##_type& arg##i GTEST_ATTRIBUTE_UNUSED_ #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_ \ const args_type& args GTEST_ATTRIBUTE_UNUSED_ GMOCK_PP_REPEAT( \ GMOCK_INTERNAL_ARG_UNUSED, , 10) -#define GMOCK_INTERNAL_ARG(N, data, el) , const arg##N##_type& arg##N +#define GMOCK_INTERNAL_ARG(i, data, el) , const arg##i##_type& arg##i #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_ \ const args_type& args GMOCK_PP_REPEAT(GMOCK_INTERNAL_ARG, , 10) -#define GMOCK_INTERNAL_TEMPLATE_ARG(N, data, el) , typename arg##N##_type +#define GMOCK_INTERNAL_TEMPLATE_ARG(i, data, el) , typename arg##i##_type #define GMOCK_ACTION_TEMPLATE_ARGS_NAMES_ \ GMOCK_PP_TAIL(GMOCK_PP_REPEAT(GMOCK_INTERNAL_TEMPLATE_ARG, , 10)) +#define GMOCK_INTERNAL_TYPENAME_PARAM(i, data, param) , typename param##_type +#define GMOCK_ACTION_TYPENAME_PARAMS_(params) \ + GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPENAME_PARAM, , params)) + +#define GMOCK_INTERNAL_TYPE_PARAM(i, data, param) , param##_type +#define GMOCK_ACTION_TYPE_PARAMS_(params) \ + GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPE_PARAM, , params)) + +#define GMOCK_INTERNAL_TYPE_GVALUE_PARAM(i, data, param) \ + , param##_type gmock_p##i +#define GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params) \ + GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_TYPE_GVALUE_PARAM, , params)) + +#define GMOCK_INTERNAL_GVALUE_PARAM(i, data, param) \ + , std::forward(gmock_p##i) +#define GMOCK_ACTION_GVALUE_PARAMS_(params) \ + GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GVALUE_PARAM, , params)) + +#define GMOCK_INTERNAL_INIT_PARAM(i, data, param) \ + , param(::std::forward(gmock_p##i)) +#define GMOCK_ACTION_INIT_PARAMS_(params) \ + GMOCK_PP_TAIL(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_INIT_PARAM, , params)) + +#define GMOCK_INTERNAL_FIELD_PARAM(i, data, param) param##_type param; +#define GMOCK_ACTION_FIELD_PARAMS_(params) \ + GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_FIELD_PARAM, , params) + +#define GMOCK_INTERNAL_ACTION(name, full_name, params) \ + template \ + class full_name : public ::testing::internal::ActionImpl< \ + full_name> { \ + using base_type = ::testing::internal::ActionImpl; \ + \ + public: \ + using base_type::base_type; \ + template \ + class gmock_Impl : public ::testing::ActionInterface { \ + public: \ + typedef F function_type; \ + typedef typename ::testing::internal::Function::Result return_type; \ + typedef \ + typename ::testing::internal::Function::ArgumentTuple args_type; \ + gmock_Impl(GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) \ + : GMOCK_ACTION_INIT_PARAMS_(params) {} \ + return_type Perform(const args_type& args) override { \ + return ::testing::internal::ActionHelper::Perform(this, \ + args); \ + } \ + template \ + return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \ + GMOCK_ACTION_FIELD_PARAMS_(params) \ + \ + private: \ + GTEST_DISALLOW_ASSIGN_(gmock_Impl); \ + }; \ + \ + private: \ + GTEST_DISALLOW_ASSIGN_(full_name); \ + }; \ + template \ + inline full_name name( \ + GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) { \ + return full_name( \ + GMOCK_ACTION_GVALUE_PARAMS_(params)); \ + } \ + template \ + template \ + template \ + typename ::testing::internal::Function::Result \ + full_name::gmock_Impl< \ + F>::gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) \ + const + } // namespace internal +#define ACTION(name) \ + class name##Action : public ::testing::internal::ActionImpl { \ + using base_type = ::testing::internal::ActionImpl; \ + \ + public: \ + using base_type::base_type; \ + template \ + class gmock_Impl : public ::testing::ActionInterface { \ + public: \ + typedef F function_type; \ + typedef typename ::testing::internal::Function::Result return_type; \ + typedef \ + typename ::testing::internal::Function::ArgumentTuple args_type; \ + gmock_Impl() {} \ + return_type Perform(const args_type& args) override { \ + return ::testing::internal::ActionHelper::Perform(this, \ + args); \ + } \ + template \ + return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const; \ + \ + private: \ + GTEST_DISALLOW_ASSIGN_(gmock_Impl); \ + }; \ + \ + private: \ + GTEST_DISALLOW_ASSIGN_(name##Action); \ + }; \ + inline name##Action name() { return name##Action(); } \ + template \ + template \ + typename ::testing::internal::Function::Result \ + name##Action::gmock_Impl::gmock_PerformImpl( \ + GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const + +#define ACTION_P(name, ...) \ + GMOCK_INTERNAL_ACTION(name, name##ActionP, (__VA_ARGS__)) + +#define ACTION_P2(name, ...) \ + GMOCK_INTERNAL_ACTION(name, name##ActionP2, (__VA_ARGS__)) + +#define ACTION_P3(name, ...) \ + GMOCK_INTERNAL_ACTION(name, name##ActionP3, (__VA_ARGS__)) + +#define ACTION_P4(name, ...) \ + GMOCK_INTERNAL_ACTION(name, name##ActionP4, (__VA_ARGS__)) + +#define ACTION_P5(name, ...) \ + GMOCK_INTERNAL_ACTION(name, name##ActionP5, (__VA_ARGS__)) + +#define ACTION_P6(name, ...) \ + GMOCK_INTERNAL_ACTION(name, name##ActionP6, (__VA_ARGS__)) + +#define ACTION_P7(name, ...) \ + GMOCK_INTERNAL_ACTION(name, name##ActionP7, (__VA_ARGS__)) + +#define ACTION_P8(name, ...) \ + GMOCK_INTERNAL_ACTION(name, name##ActionP8, (__VA_ARGS__)) + +#define ACTION_P9(name, ...) \ + GMOCK_INTERNAL_ACTION(name, name##ActionP9, (__VA_ARGS__)) + +#define ACTION_P10(name, ...) \ + GMOCK_INTERNAL_ACTION(name, name##ActionP10, (__VA_ARGS__)) + } // namespace testing #ifdef _MSC_VER diff --git a/googlemock/include/gmock/gmock-generated-actions.h b/googlemock/include/gmock/gmock-generated-actions.h index 8c20eee0..c78debef 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h +++ b/googlemock/include/gmock/gmock-generated-actions.h @@ -47,101 +47,6 @@ #include "gmock/gmock-actions.h" #include "gmock/internal/gmock-port.h" -// The ACTION* family of macros can be used in a namespace scope to -// define custom actions easily. The syntax: -// -// ACTION(name) { statements; } -// -// will define an action with the given name that executes the -// statements. The value returned by the statements will be used as -// the return value of the action. Inside the statements, you can -// refer to the K-th (0-based) argument of the mock function by -// 'argK', and refer to its type by 'argK_type'. For example: -// -// ACTION(IncrementArg1) { -// arg1_type temp = arg1; -// return ++(*temp); -// } -// -// allows you to write -// -// ...WillOnce(IncrementArg1()); -// -// You can also refer to the entire argument tuple and its type by -// 'args' and 'args_type', and refer to the mock function type and its -// return type by 'function_type' and 'return_type'. -// -// Note that you don't need to specify the types of the mock function -// arguments. However rest assured that your code is still type-safe: -// you'll get a compiler error if *arg1 doesn't support the ++ -// operator, or if the type of ++(*arg1) isn't compatible with the -// mock function's return type, for example. -// -// Sometimes you'll want to parameterize the action. For that you can use -// another macro: -// -// ACTION_P(name, param_name) { statements; } -// -// For example: -// -// ACTION_P(Add, n) { return arg0 + n; } -// -// will allow you to write: -// -// ...WillOnce(Add(5)); -// -// Note that you don't need to provide the type of the parameter -// either. If you need to reference the type of a parameter named -// 'foo', you can write 'foo_type'. For example, in the body of -// ACTION_P(Add, n) above, you can write 'n_type' to refer to the type -// of 'n'. -// -// We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support -// multi-parameter actions. -// -// For the purpose of typing, you can view -// -// ACTION_Pk(Foo, p1, ..., pk) { ... } -// -// as shorthand for -// -// template -// FooActionPk Foo(p1_type p1, ..., pk_type pk) { ... } -// -// In particular, you can provide the template type arguments -// explicitly when invoking Foo(), as in Foo(5, false); -// although usually you can rely on the compiler to infer the types -// for you automatically. You can assign the result of expression -// Foo(p1, ..., pk) to a variable of type FooActionPk. This can be useful when composing actions. -// -// You can also overload actions with different numbers of parameters: -// -// ACTION_P(Plus, a) { ... } -// ACTION_P2(Plus, a, b) { ... } -// -// While it's tempting to always use the ACTION* macros when defining -// a new action, you should also consider implementing ActionInterface -// or using MakePolymorphicAction() instead, especially if you need to -// use the action a lot. While these approaches require more work, -// they give you more control on the types of the mock function -// arguments and the action parameters, which in general leads to -// better compiler error messages that pay off in the long run. They -// also allow overloading actions based on parameter types (as opposed -// to just based on the number of parameters). -// -// CAVEAT: -// -// ACTION*() can only be used in a namespace scope as templates cannot be -// declared inside of a local class. -// Users can, however, define any local functors (e.g. a lambda) that -// can be used as actions. -// -// MORE INFORMATION: -// -// To learn more about using these macros, please search for 'ACTION' on -// https://github.com/google/googletest/blob/master/googlemock/docs/cook_book.md - // Sometimes you want to give an action explicit template parameters // that cannot be inferred from its value parameters. ACTION() and @@ -563,628 +468,6 @@ gmock_PerformImpl(\ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const -#define ACTION(name)\ - class name##Action : public ::testing::internal::ActionImpl {\ - using base_type = ::testing::internal::ActionImpl;\ - public:\ - using base_type::base_type;\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - gmock_Impl() {}\ - return_type Perform(const args_type& args) override {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##Action);\ - };\ - inline name##Action name() {\ - return name##Action();\ - }\ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##Action::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P(name, p0)\ - template \ - class name##ActionP : public \ - ::testing::internal::ActionImpl> {\ - using base_type = ::testing::internal::ActionImpl;\ - public:\ - using base_type::base_type;\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - explicit gmock_Impl(p0##_type gmock_p0) : \ - p0(::std::forward(gmock_p0)) {}\ - return_type Perform(const args_type& args) override {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ - p0##_type p0;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP);\ - };\ - template \ - inline name##ActionP name(p0##_type p0) {\ - return name##ActionP(p0);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P2(name, p0, p1)\ - template \ - class name##ActionP2 : public \ - ::testing::internal::ActionImpl> {\ - using base_type = ::testing::internal::ActionImpl;\ - public:\ - using base_type::base_type;\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - gmock_Impl(p0##_type gmock_p0, \ - p1##_type gmock_p1) : p0(::std::forward(gmock_p0)), \ - p1(::std::forward(gmock_p1)) {}\ - return_type Perform(const args_type& args) override {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ - p0##_type p0;\ - p1##_type p1;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP2);\ - };\ - template \ - inline name##ActionP2 name(p0##_type p0, \ - p1##_type p1) {\ - return name##ActionP2(p0, p1);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP2::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P3(name, p0, p1, p2)\ - template \ - class name##ActionP3 : public \ - ::testing::internal::ActionImpl> {\ - using base_type = ::testing::internal::ActionImpl;\ - public:\ - using base_type::base_type;\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2) : p0(::std::forward(gmock_p0)), \ - p1(::std::forward(gmock_p1)), \ - p2(::std::forward(gmock_p2)) {}\ - return_type Perform(const args_type& args) override {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP3);\ - };\ - template \ - inline name##ActionP3 name(p0##_type p0, \ - p1##_type p1, p2##_type p2) {\ - return name##ActionP3(p0, p1, p2);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP3::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P4(name, p0, p1, p2, p3)\ - template \ - class name##ActionP4 : public \ - ::testing::internal::ActionImpl> {\ - using base_type = ::testing::internal::ActionImpl;\ - public:\ - using base_type::base_type;\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3) : p0(::std::forward(gmock_p0)), \ - p1(::std::forward(gmock_p1)), \ - p2(::std::forward(gmock_p2)), \ - p3(::std::forward(gmock_p3)) {}\ - return_type Perform(const args_type& args) override {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP4);\ - };\ - template \ - inline name##ActionP4 name(p0##_type p0, p1##_type p1, p2##_type p2, \ - p3##_type p3) {\ - return name##ActionP4(p0, p1, \ - p2, p3);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP4::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P5(name, p0, p1, p2, p3, p4)\ - template \ - class name##ActionP5 : public \ - ::testing::internal::ActionImpl> {\ - using base_type = ::testing::internal::ActionImpl;\ - public:\ - using base_type::base_type;\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, \ - p4##_type gmock_p4) : p0(::std::forward(gmock_p0)), \ - p1(::std::forward(gmock_p1)), \ - p2(::std::forward(gmock_p2)), \ - p3(::std::forward(gmock_p3)), \ - p4(::std::forward(gmock_p4)) {}\ - return_type Perform(const args_type& args) override {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP5);\ - };\ - template \ - inline name##ActionP5 name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ - p4##_type p4) {\ - return name##ActionP5(p0, p1, p2, p3, p4);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP5::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\ - template \ - class name##ActionP6 : public \ - ::testing::internal::ActionImpl> {\ - using base_type = ::testing::internal::ActionImpl;\ - public:\ - using base_type::base_type;\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, p4##_type gmock_p4, \ - p5##_type gmock_p5) : p0(::std::forward(gmock_p0)), \ - p1(::std::forward(gmock_p1)), \ - p2(::std::forward(gmock_p2)), \ - p3(::std::forward(gmock_p3)), \ - p4(::std::forward(gmock_p4)), \ - p5(::std::forward(gmock_p5)) {}\ - return_type Perform(const args_type& args) override {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP6);\ - };\ - template \ - inline name##ActionP6 name(p0##_type p0, p1##_type p1, p2##_type p2, \ - p3##_type p3, p4##_type p4, p5##_type p5) {\ - return name##ActionP6(p0, p1, p2, p3, p4, p5);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP6::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P7(name, p0, p1, p2, p3, p4, p5, p6)\ - template \ - class name##ActionP7 : public \ - ::testing::internal::ActionImpl> {\ - using base_type = ::testing::internal::ActionImpl;\ - public:\ - using base_type::base_type;\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ - p6##_type gmock_p6) : p0(::std::forward(gmock_p0)), \ - p1(::std::forward(gmock_p1)), \ - p2(::std::forward(gmock_p2)), \ - p3(::std::forward(gmock_p3)), \ - p4(::std::forward(gmock_p4)), \ - p5(::std::forward(gmock_p5)), \ - p6(::std::forward(gmock_p6)) {}\ - return_type Perform(const args_type& args) override {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP7);\ - };\ - template \ - inline name##ActionP7 name(p0##_type p0, p1##_type p1, \ - p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ - p6##_type p6) {\ - return name##ActionP7(p0, p1, p2, p3, p4, p5, p6);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP7::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P8(name, p0, p1, p2, p3, p4, p5, p6, p7)\ - template \ - class name##ActionP8 : public \ - ::testing::internal::ActionImpl> {\ - using base_type = ::testing::internal::ActionImpl;\ - public:\ - using base_type::base_type;\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ - p6##_type gmock_p6, \ - p7##_type gmock_p7) : p0(::std::forward(gmock_p0)), \ - p1(::std::forward(gmock_p1)), \ - p2(::std::forward(gmock_p2)), \ - p3(::std::forward(gmock_p3)), \ - p4(::std::forward(gmock_p4)), \ - p5(::std::forward(gmock_p5)), \ - p6(::std::forward(gmock_p6)), \ - p7(::std::forward(gmock_p7)) {}\ - return_type Perform(const args_type& args) override {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type p7;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP8);\ - };\ - template \ - inline name##ActionP8 name(p0##_type p0, \ - p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ - p6##_type p6, p7##_type p7) {\ - return name##ActionP8(p0, p1, p2, p3, p4, p5, \ - p6, p7);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP8::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\ - template \ - class name##ActionP9 : public \ - ::testing::internal::ActionImpl> {\ - using base_type = ::testing::internal::ActionImpl;\ - public:\ - using base_type::base_type;\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ - p6##_type gmock_p6, p7##_type gmock_p7, \ - p8##_type gmock_p8) : p0(::std::forward(gmock_p0)), \ - p1(::std::forward(gmock_p1)), \ - p2(::std::forward(gmock_p2)), \ - p3(::std::forward(gmock_p3)), \ - p4(::std::forward(gmock_p4)), \ - p5(::std::forward(gmock_p5)), \ - p6(::std::forward(gmock_p6)), \ - p7(::std::forward(gmock_p7)), \ - p8(::std::forward(gmock_p8)) {}\ - return_type Perform(const args_type& args) override {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type p7;\ - p8##_type p8;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP9);\ - };\ - template \ - inline name##ActionP9 name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ - p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \ - p8##_type p8) {\ - return name##ActionP9(p0, p1, p2, \ - p3, p4, p5, p6, p7, p8);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP9::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\ - template \ - class name##ActionP10 : public \ - ::testing::internal::ActionImpl> {\ - using base_type = ::testing::internal::ActionImpl;\ - public:\ - using base_type::base_type;\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ - p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ - p9##_type gmock_p9) : p0(::std::forward(gmock_p0)), \ - p1(::std::forward(gmock_p1)), \ - p2(::std::forward(gmock_p2)), \ - p3(::std::forward(gmock_p3)), \ - p4(::std::forward(gmock_p4)), \ - p5(::std::forward(gmock_p5)), \ - p6(::std::forward(gmock_p6)), \ - p7(::std::forward(gmock_p7)), \ - p8(::std::forward(gmock_p8)), \ - p9(::std::forward(gmock_p9)) {}\ - return_type Perform(const args_type& args) override {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type p7;\ - p8##_type p8;\ - p9##_type p9;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP10);\ - };\ - template \ - inline name##ActionP10 name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ - p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ - p9##_type p9) {\ - return name##ActionP10(p0, \ - p1, p2, p3, p4, p5, p6, p7, p8, p9);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP10::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const namespace testing { diff --git a/googlemock/include/gmock/gmock-generated-actions.h.pump b/googlemock/include/gmock/gmock-generated-actions.h.pump index 23c0a23b..be9d99fe 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h.pump +++ b/googlemock/include/gmock/gmock-generated-actions.h.pump @@ -49,101 +49,6 @@ $$}} This meta comment fixes auto-indentation in editors. #include "gmock/gmock-actions.h" #include "gmock/internal/gmock-port.h" -// The ACTION* family of macros can be used in a namespace scope to -// define custom actions easily. The syntax: -// -// ACTION(name) { statements; } -// -// will define an action with the given name that executes the -// statements. The value returned by the statements will be used as -// the return value of the action. Inside the statements, you can -// refer to the K-th (0-based) argument of the mock function by -// 'argK', and refer to its type by 'argK_type'. For example: -// -// ACTION(IncrementArg1) { -// arg1_type temp = arg1; -// return ++(*temp); -// } -// -// allows you to write -// -// ...WillOnce(IncrementArg1()); -// -// You can also refer to the entire argument tuple and its type by -// 'args' and 'args_type', and refer to the mock function type and its -// return type by 'function_type' and 'return_type'. -// -// Note that you don't need to specify the types of the mock function -// arguments. However rest assured that your code is still type-safe: -// you'll get a compiler error if *arg1 doesn't support the ++ -// operator, or if the type of ++(*arg1) isn't compatible with the -// mock function's return type, for example. -// -// Sometimes you'll want to parameterize the action. For that you can use -// another macro: -// -// ACTION_P(name, param_name) { statements; } -// -// For example: -// -// ACTION_P(Add, n) { return arg0 + n; } -// -// will allow you to write: -// -// ...WillOnce(Add(5)); -// -// Note that you don't need to provide the type of the parameter -// either. If you need to reference the type of a parameter named -// 'foo', you can write 'foo_type'. For example, in the body of -// ACTION_P(Add, n) above, you can write 'n_type' to refer to the type -// of 'n'. -// -// We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P$n to support -// multi-parameter actions. -// -// For the purpose of typing, you can view -// -// ACTION_Pk(Foo, p1, ..., pk) { ... } -// -// as shorthand for -// -// template -// FooActionPk Foo(p1_type p1, ..., pk_type pk) { ... } -// -// In particular, you can provide the template type arguments -// explicitly when invoking Foo(), as in Foo(5, false); -// although usually you can rely on the compiler to infer the types -// for you automatically. You can assign the result of expression -// Foo(p1, ..., pk) to a variable of type FooActionPk. This can be useful when composing actions. -// -// You can also overload actions with different numbers of parameters: -// -// ACTION_P(Plus, a) { ... } -// ACTION_P2(Plus, a, b) { ... } -// -// While it's tempting to always use the ACTION* macros when defining -// a new action, you should also consider implementing ActionInterface -// or using MakePolymorphicAction() instead, especially if you need to -// use the action a lot. While these approaches require more work, -// they give you more control on the types of the mock function -// arguments and the action parameters, which in general leads to -// better compiler error messages that pay off in the long run. They -// also allow overloading actions based on parameter types (as opposed -// to just based on the number of parameters). -// -// CAVEAT: -// -// ACTION*() can only be used in a namespace scope as templates cannot be -// declared inside of a local class. -// Users can, however, define any local functors (e.g. a lambda) that -// can be used as actions. -// -// MORE INFORMATION: -// -// To learn more about using these macros, please search for 'ACTION' on -// https://github.com/google/googletest/blob/master/googlemock/docs/cook_book.md - $range i 0..n $range k 0..n-1 @@ -381,74 +286,6 @@ $range k 0..n-1 gmock_PerformImpl(\ GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const -$for i - -[[ -$var template = [[$if i==0 [[]] $else [[ -$range j 0..i-1 - - template <$for j, [[typename p$j##_type]]>\ -]]]] -$var class_name = [[name##Action[[$if i==0 [[]] $elif i==1 [[P]] - $else [[P$i]]]]]] -$range j 0..i-1 -$var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]] -$var param_types_and_names = [[$for j, [[p$j##_type p$j]]]] -$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::std::forward(gmock_p$j))]]]]]] -$var param_field_decls = [[$for j -[[ - - p$j##_type p$j;\ -]]]] -$var param_field_decls2 = [[$for j -[[ - - p$j##_type p$j;\ -]]]] -$var params = [[$for j, [[p$j]]]] -$var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]] -$var typename_arg_types = [[$for k, [[typename arg$k[[]]_type]]]] -$var arg_types_and_names = [[$for k, [[const arg$k[[]]_type& arg$k]]]] -$var macro_name = [[$if i==0 [[ACTION]] $elif i==1 [[ACTION_P]] - $else [[ACTION_P$i]]]] - -#define $macro_name(name$for j [[, p$j]])\$template - class $class_name : public ::testing::internal::ActionImpl<$class_name$param_types> {\ - using base_type = ::testing::internal::ActionImpl<$class_name>;\ - public:\ - using base_type::base_type;\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - [[$if i==1 [[explicit ]]]]gmock_Impl($ctor_param_list)$inits {}\ - return_type Perform(const args_type& args) override {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\$param_field_decls - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - private:\ - GTEST_DISALLOW_ASSIGN_($class_name);\ - };\$template - inline $class_name$param_types name($param_types_and_names) {\ - return $class_name$param_types($params);\ - }\$template - template \ - template \ - typename ::testing::internal::Function::Result\ - $class_name$param_types::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const -]] -$$ } // This meta comment fixes auto-indentation in Emacs. It won't -$$ // show up in the generated code. - namespace testing { From 8b4817e3df3746a20502a84580f661ac448821be Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 15 Jan 2020 14:14:57 -0500 Subject: [PATCH 010/586] Googletest export Correct the spelling of PARAMETERIZED. PiperOrigin-RevId: 289897278 --- googletest/docs/advanced.md | 2 +- googletest/include/gtest/gtest-param-test.h | 2 +- googletest/src/gtest.cc | 5 +++-- googletest/test/googletest-output-test-golden-lin.txt | 4 ++-- googletest/test/googletest-param-test-test.cc | 6 +++--- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/googletest/docs/advanced.md b/googletest/docs/advanced.md index 5631e8ea..dd28df34 100644 --- a/googletest/docs/advanced.md +++ b/googletest/docs/advanced.md @@ -1385,7 +1385,7 @@ cases is dynamic and may be empty, then this check can be suppressed by tagging the test suite: ```c++ -GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(FooTest); +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FooTest); ``` To distinguish different instances of the pattern (yes, you can instantiate it diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index 37417a98..5b039df9 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -493,7 +493,7 @@ internal::CartesianProductHolder Combine(const Generator&... g) { // Allow Marking a Parameterized test class as not needing to be instantiated. -#define GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(T) \ +#define GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(T) \ namespace gtest_do_not_use_outside_namespace_scope {} \ static const ::testing::internal::MarkAsIgnored gtest_allow_ignore_##T( \ GTEST_STRINGIFY_(T)) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 8e68c04e..1f8a68e3 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -472,7 +472,7 @@ void InsertSyntheticTestCase(const std::string &name, CodeLocation location) { "To suppress this error for this test suite, insert the following line " "(in a non-header) in the namespace it is defined in:" "\n\n" - "GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(" + name + ");"; + "GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(" + name + ");"; std::string full_name = "UninstantiatedParamaterizedTestSuite<" + name + ">"; RegisterTest( // @@ -533,7 +533,8 @@ void TypeParameterizedTestSuiteRegistry::CheckForInstantiations() { "To suppress this error for this test suite, insert the following line " "(in a non-header) in the namespace it is definedin in:" "\n\n" - "GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(" + testcase.first + ");"; + "GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(" + + testcase.first + ");"; std::string full_name = "UninstantiatedTypeParamaterizedTestSuite<" + testcase.first + ">"; diff --git a/googletest/test/googletest-output-test-golden-lin.txt b/googletest/test/googletest-output-test-golden-lin.txt index a4a096e4..2b34aad3 100644 --- a/googletest/test/googletest-output-test-golden-lin.txt +++ b/googletest/test/googletest-output-test-golden-lin.txt @@ -990,7 +990,7 @@ Ideally, TEST_P definitions should only ever be included as part of binaries tha To suppress this error for this test suite, insert the following line (in a non-header) in the namespace it is defined in: -GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(DetectNotInstantiatedTest); +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DetectNotInstantiatedTest); [ OK ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite [ RUN ] GoogleTestVerification.UninstantiatedTypeParamaterizedTestSuite Type paramaterized test suite DetectNotInstantiatedTypesTest is defined via REGISTER_TYPED_TEST_SUITE_P, but never instantiated via INSTANTIATE_TYPED_TEST_SUITE_P. None of the test cases will run. @@ -999,7 +999,7 @@ Ideally, TYPED_TEST_P definitions should only ever be included as part of binari To suppress this error for this test suite, insert the following line (in a non-header) in the namespace it is definedin in: -GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(DetectNotInstantiatedTypesTest); +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DetectNotInstantiatedTypesTest); [ OK ] GoogleTestVerification.UninstantiatedTypeParamaterizedTestSuite [----------] Global test environment tear-down BarEnvironment::TearDown() called. diff --git a/googletest/test/googletest-param-test-test.cc b/googletest/test/googletest-param-test-test.cc index 72a48375..6ba89654 100644 --- a/googletest/test/googletest-param-test-test.cc +++ b/googletest/test/googletest-param-test-test.cc @@ -1081,12 +1081,12 @@ TYPED_TEST_SUITE_P(NotUsedTypeTest); // Used but not instantiated, this would fail. but... class NotInstantiatedTest : public testing::TestWithParam {}; // ... we mark is as allowed. -GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(NotInstantiatedTest); +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NotInstantiatedTest); TEST_P(NotInstantiatedTest, Used) { } using OtherName = NotInstantiatedTest; -GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(OtherName); +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(OtherName); TEST_P(OtherName, Used) { } // Used but not instantiated, this would fail. but... @@ -1094,7 +1094,7 @@ template class NotInstantiatedTypeTest : public testing::Test {}; TYPED_TEST_SUITE_P(NotInstantiatedTypeTest); // ... we mark is as allowed. -GTEST_ALLOW_UNINSTANTIATED_PARAMTERIZED_TEST(NotInstantiatedTypeTest); +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NotInstantiatedTypeTest); TYPED_TEST_P(NotInstantiatedTypeTest, Used) { } REGISTER_TYPED_TEST_SUITE_P(NotInstantiatedTypeTest, Used); From 18b67bfc58b1c5657198e5d7e5cc9a99049b154e Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 16 Jan 2020 14:58:28 -0500 Subject: [PATCH 011/586] Googletest export Add extra filtering so that the reported message differentiates between the case where INSTANTIATE_TEST_SUITE_P is missing vs. the case where TEST_P is missing. PiperOrigin-RevId: 290114508 --- .../include/gtest/internal/gtest-param-util.h | 5 +++-- googletest/src/gtest.cc | 21 +++++++++++++++---- .../googletest-output-test-golden-lin.txt | 17 +++++++++++---- googletest/test/googletest-output-test_.cc | 4 ++++ 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h index 65aa9568..7f7a13bf 100644 --- a/googletest/include/gtest/internal/gtest-param-util.h +++ b/googletest/include/gtest/internal/gtest-param-util.h @@ -483,7 +483,7 @@ struct MarkAsIgnored { }; GTEST_API_ void InsertSyntheticTestCase(const std::string& name, - CodeLocation location); + CodeLocation location, bool has_test_p); // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. // @@ -600,7 +600,8 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { if (!generated_instantiations) { // There are no generaotrs, or they all generate nothing ... - InsertSyntheticTestCase(GetTestSuiteName(), code_location_); + InsertSyntheticTestCase(GetTestSuiteName(), code_location_, + !tests_.empty()); } } // RegisterTests diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 1f8a68e3..095778e6 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -455,19 +455,32 @@ MarkAsIgnored::MarkAsIgnored(const char* test_suite) { // If this parameterized test suite has no instantiations (and that // has not been marked as okay), emit a test case reporting that. -void InsertSyntheticTestCase(const std::string &name, CodeLocation location) { +void InsertSyntheticTestCase(const std::string& name, CodeLocation location, + bool has_test_p) { const auto& ignored = *GetIgnoredParameterizedTestSuites(); if (ignored.find(name) != ignored.end()) return; - std::string message = - "Paramaterized test suite " + name + + const char kMissingInstantiation[] = // " is defined via TEST_P, but never instantiated. None of the test cases " "will run. Either no INSTANTIATE_TEST_SUITE_P is provided or the only " "ones provided expand to nothing." "\n\n" "Ideally, TEST_P definitions should only ever be included as part of " "binaries that intend to use them. (As opposed to, for example, being " - "placed in a library that may be linked in to get other utilities.)" + "placed in a library that may be linked in to get other utilities.)"; + + const char kMissingTestCase[] = // + " is instantiated via INSTANTIATE_TEST_SUITE_P, but no tests are " + "defined via TEST_P . No test cases will run." + "\n\n" + "Ideally, INSTANTIATE_TEST_SUITE_P should only ever be invoked from " + "code that always depend on code that provides TEST_P. Failing to do " + "so is often an indication of dead code, e.g. the last TEST_P was " + "removed but the rest got left behind."; + + std::string message = + "Paramaterized test suite " + name + + (has_test_p ? kMissingInstantiation : kMissingTestCase) + "\n\n" "To suppress this error for this test suite, insert the following line " "(in a non-header) in the namespace it is defined in:" diff --git a/googletest/test/googletest-output-test-golden-lin.txt b/googletest/test/googletest-output-test-golden-lin.txt index 2b34aad3..8bc45800 100644 --- a/googletest/test/googletest-output-test-golden-lin.txt +++ b/googletest/test/googletest-output-test-golden-lin.txt @@ -12,7 +12,7 @@ Expected equality of these values: 3 Stack trace: (omitted) -[==========] Running 87 tests from 41 test suites. +[==========] Running 88 tests from 41 test suites. [----------] Global test environment set-up. FooEnvironment::SetUp() called. BarEnvironment::SetUp() called. @@ -982,7 +982,16 @@ Expected failure Stack trace: (omitted) [ FAILED ] PrintingStrings/ParamTest.Failure/a, where GetParam() = "a" -[----------] 2 tests from GoogleTestVerification +[----------] 3 tests from GoogleTestVerification +[ RUN ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite +Paramaterized test suite NoTests is instantiated via INSTANTIATE_TEST_SUITE_P, but no tests are defined via TEST_P . No test cases will run. + +Ideally, INSTANTIATE_TEST_SUITE_P should only ever be invoked from code that always depend on code that provides TEST_P. Failing to do so is often an indication of dead code, e.g. the last TEST_P was removed but the rest got left behind. + +To suppress this error for this test suite, insert the following line (in a non-header) in the namespace it is defined in: + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NoTests); +[ OK ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite [ RUN ] GoogleTestVerification.UninstantiatedParamaterizedTestSuite Paramaterized test suite DetectNotInstantiatedTest is defined via TEST_P, but never instantiated. None of the test cases will run. Either no INSTANTIATE_TEST_SUITE_P is provided or the only ones provided expand to nothing. @@ -1014,8 +1023,8 @@ Failed Expected fatal failure. Stack trace: (omitted) -[==========] 87 tests from 41 test suites ran. -[ PASSED ] 33 tests. +[==========] 88 tests from 41 test suites ran. +[ PASSED ] 34 tests. [ FAILED ] 54 tests, listed below: [ FAILED ] NonfatalFailureTest.EscapesStringOperands [ FAILED ] NonfatalFailureTest.DiffForLongStrings diff --git a/googletest/test/googletest-output-test_.cc b/googletest/test/googletest-output-test_.cc index b1d66f9f..76af5bca 100644 --- a/googletest/test/googletest-output-test_.cc +++ b/googletest/test/googletest-output-test_.cc @@ -790,6 +790,10 @@ INSTANTIATE_TEST_SUITE_P(PrintingStrings, testing::Values(std::string("a")), ParamNameFunc); +// The case where a suite has INSTANTIATE_TEST_SUITE_P but not TEST_P. +using NoTests = ParamTest; +INSTANTIATE_TEST_SUITE_P(ThisIsOdd, NoTests, ::testing::Values("Hello")); + // fails under kErrorOnUninstantiatedParameterizedTest=true class DetectNotInstantiatedTest : public testing::TestWithParam {}; TEST_P(DetectNotInstantiatedTest, Used) { } From d01e356e155a84b196cf17435b7ebea35ccf9668 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 17 Jan 2020 13:53:01 -0500 Subject: [PATCH 012/586] Googletest export Allow copying of the string in MatchAndExplain. Otherwise, conversions from std::string_view to std::string will fail as being explicit PiperOrigin-RevId: 290301103 --- googlemock/include/gmock/gmock-matchers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 67bd7e27..4baeb1bd 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -678,7 +678,7 @@ class StrEqualityMatcher { template bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { - const StringType& s2(s); + const StringType s2(s); const bool eq = case_sensitive_ ? s2 == string_ : CaseInsensitiveStringEquals(s2, string_); return expect_eq_ == eq; From 10b1902d893ea8cc43c69541d70868f91af3646b Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 21 Jan 2020 15:37:23 -0500 Subject: [PATCH 013/586] Googletest export Fix SCOPED_TRACE() message header in example PiperOrigin-RevId: 290800241 --- googletest/docs/advanced.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/docs/advanced.md b/googletest/docs/advanced.md index dd28df34..8ce1f3e7 100644 --- a/googletest/docs/advanced.md +++ b/googletest/docs/advanced.md @@ -955,7 +955,7 @@ path/to/foo_test.cc:11: Failure Value of: Bar(n) Expected: 1 Actual: 2 - Trace: +Google Test trace: path/to/foo_test.cc:17: A path/to/foo_test.cc:12: Failure From 44517f9888def81f75c1114a0a881bd716331132 Mon Sep 17 00:00:00 2001 From: Mark Jan van Kampen Date: Wed, 22 Jan 2020 22:29:28 +0100 Subject: [PATCH 014/586] Fixes extensions missing for QNX --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 755b8b72..4c8188aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ if (CMAKE_VERSION VERSION_LESS "3.1") else() set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) - if(NOT CYGWIN AND NOT MSYS) + if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX) set(CMAKE_CXX_EXTENSIONS OFF) endif() endif() From c09fbb239338da11d81e4a854ae805b8e87b381b Mon Sep 17 00:00:00 2001 From: Hosein Ghahramanzadeh Date: Fri, 17 Jan 2020 02:55:08 +0330 Subject: [PATCH 015/586] Fix always false condition and clean function body An always false condition was remove from Normalize member function of FilePath and the body of the function which was poorly writen is improved. --- googletest/src/gtest-filepath.cc | 38 ++++++++++---------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/googletest/src/gtest-filepath.cc b/googletest/src/gtest-filepath.cc index 9aad12fb..478a4153 100644 --- a/googletest/src/gtest-filepath.cc +++ b/googletest/src/gtest-filepath.cc @@ -349,33 +349,19 @@ FilePath FilePath::RemoveTrailingPathSeparator() const { // For example, "bar///foo" becomes "bar/foo". Does not eliminate other // redundancies that might be in a pathname involving "." or "..". void FilePath::Normalize() { - if (pathname_.c_str() == nullptr) { - pathname_ = ""; - return; - } - const char* src = pathname_.c_str(); - char* const dest = new char[pathname_.length() + 1]; - char* dest_ptr = dest; - memset(dest_ptr, 0, pathname_.length() + 1); + std::string normalized_pathname; + normalized_pathname.reserve(pathname_.length()); - while (*src != '\0') { - *dest_ptr = *src; - if (!IsPathSeparator(*src)) { - src++; - } else { -#if GTEST_HAS_ALT_PATH_SEP_ - if (*dest_ptr == kAlternatePathSeparator) { - *dest_ptr = kPathSeparator; - } -#endif - while (IsPathSeparator(*src)) - src++; - } - dest_ptr++; - } - *dest_ptr = '\0'; - pathname_ = dest; - delete[] dest; + for (const auto character : pathname_) + if (!IsPathSeparator(character)) + normalized_pathname.push_back(character); + else if (normalized_pathname.empty() || + normalized_pathname.back() != kPathSeparator) + normalized_pathname.push_back(kPathSeparator); + else + continue; + + pathname_ = normalized_pathname; } } // namespace internal From c378d7eb93080e3b5ca322b1767bfb5cadf9c942 Mon Sep 17 00:00:00 2001 From: Krystian Kuzniarek Date: Wed, 29 Jan 2020 11:42:59 +0100 Subject: [PATCH 016/586] remove a dead reference to the Autotools script --- googletest/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/googletest/README.md b/googletest/README.md index 904048f4..8520549c 100644 --- a/googletest/README.md +++ b/googletest/README.md @@ -189,9 +189,9 @@ or When Google Test uses pthread, you may need to add flags to your compiler and/or linker to select the pthread library, or you'll get link errors. If you use the -CMake script or the deprecated Autotools script, this is taken care of for you. -If you use your own build script, you'll need to read your compiler and linker's -manual to figure out what flags to add. +CMake script, this is taken care of for you. If you use your own build script, +you'll need to read your compiler and linker's manual to figure out what flags +to add. ### As a Shared Library (DLL) From 461bd03fc718c7e7ac3d30336d024d9a75e18810 Mon Sep 17 00:00:00 2001 From: aribibek <59134746+aribibek@users.noreply.github.com> Date: Thu, 6 Feb 2020 18:41:20 +0600 Subject: [PATCH 017/586] fix a link to documentation fix a documentation link on "how to customize the printing of the arguments" --- googletest/docs/primer.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/docs/primer.md b/googletest/docs/primer.md index f581d77a..2f459fd7 100644 --- a/googletest/docs/primer.md +++ b/googletest/docs/primer.md @@ -169,7 +169,7 @@ you'll get a compiler error. We used to require the arguments to support the `<<` is supported, it will be called to print the arguments when the assertion fails; otherwise googletest will attempt to print them in the best way it can. For more details and how to customize the printing of the arguments, see the -[documentation](../../googlemock/docs/cook_book.md#teaching-gmock-how-to-print-your-values). +[documentation](./advanced.md#teaching-googletest-how-to-print-your-values). These assertions can work with a user-defined type, but only if you define the corresponding comparison operator (e.g., `==` or `<`). Since this is discouraged From 22397f28ef576daf9f3dbfac381bdfdf3be58a86 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 23 Jan 2020 10:06:23 -0500 Subject: [PATCH 018/586] Googletest export Add missing explicit keyword for gmock_Impl constructor. When switching to using GMOCK_PP in ACTION* macroses `explicit` keyword was missed in gmock_Impl constructor causing ClangTidy warnings in ACTION_P macro. PiperOrigin-RevId: 291159975 --- googlemock/include/gmock/gmock-actions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 88011798..e46bcaa7 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -1426,7 +1426,7 @@ auto InvokeArgumentAdl(AdlTag, F f, Args... args) -> decltype(f(args...)) { typedef typename ::testing::internal::Function::Result return_type; \ typedef \ typename ::testing::internal::Function::ArgumentTuple args_type; \ - gmock_Impl(GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) \ + explicit gmock_Impl(GMOCK_ACTION_TYPE_GVALUE_PARAMS_(params)) \ : GMOCK_ACTION_INIT_PARAMS_(params) {} \ return_type Perform(const args_type& args) override { \ return ::testing::internal::ActionHelper Date: Fri, 24 Jan 2020 13:34:47 -0500 Subject: [PATCH 019/586] Googletest export Deleted an orphaned duplicate file and exclude another that shouldn't be part of :gtest_all_test. This showed up while trying to debug the presubmit failure for: https://github.com/google/googletest/pull/2683 PiperOrigin-RevId: 291398123 --- googletest/test/BUILD.bazel | 1 + googletest/test/googletest-test2_test.cc | 61 ------------------------ 2 files changed, 1 insertion(+), 61 deletions(-) delete mode 100644 googletest/test/googletest-test2_test.cc diff --git a/googletest/test/BUILD.bazel b/googletest/test/BUILD.bazel index 15f7eef8..456cc6f4 100644 --- a/googletest/test/BUILD.bazel +++ b/googletest/test/BUILD.bazel @@ -56,6 +56,7 @@ cc_test( "gtest-listener_test.cc", "gtest-unittest-api_test.cc", "googletest-param-test-test.cc", + "googletest-param-test2-test.cc", "googletest-catch-exceptions-test_.cc", "googletest-color-test_.cc", "googletest-env-var-test_.cc", diff --git a/googletest/test/googletest-test2_test.cc b/googletest/test/googletest-test2_test.cc deleted file mode 100644 index 2e425dae..00000000 --- a/googletest/test/googletest-test2_test.cc +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// -// Tests for Google Test itself. This verifies that the basic constructs of -// Google Test work. - -#include "gtest/gtest.h" -#include "googletest-param-test-test.h" - -using ::testing::Values; -using ::testing::internal::ParamGenerator; - -// Tests that generators defined in a different translation unit -// are functional. The test using extern_gen_2 is defined -// in googletest-param-test-test.cc. -ParamGenerator extern_gen_2 = Values(33); - -// Tests that a parameterized test case can be defined in one translation unit -// and instantiated in another. The test is defined in -// googletest-param-test-test.cc and ExternalInstantiationTest fixture class is -// defined in gtest-param-test_test.h. -INSTANTIATE_TEST_SUITE_P(MultiplesOf33, - ExternalInstantiationTest, - Values(33, 66)); - -// Tests that a parameterized test case can be instantiated -// in multiple translation units. Another instantiation is defined -// in googletest-param-test-test.cc and -// InstantiationInMultipleTranslationUnitsTest fixture is defined in -// gtest-param-test_test.h -INSTANTIATE_TEST_SUITE_P(Sequence2, - InstantiationInMultipleTranslationUnitsTest, - Values(42*3, 42*4, 42*5)); - From 87061810f4c744cdc1abb8f1cd98970a986eea75 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 24 Jan 2020 14:09:22 -0500 Subject: [PATCH 020/586] Googletest export Move part of functionality of Matcher* class to the base one. Reduce copypaste. Make constructor and conversion operator of Matcher* class independent of pump. PiperOrigin-RevId: 291405510 --- .../include/gmock/gmock-generated-matchers.h | 264 +++++------------- .../gmock/gmock-generated-matchers.h.pump | 14 +- googlemock/include/gmock/gmock-matchers.h | 52 ++++ 3 files changed, 122 insertions(+), 208 deletions(-) diff --git a/googlemock/include/gmock/gmock-generated-matchers.h b/googlemock/include/gmock/gmock-generated-matchers.h index 61892380..4234b267 100644 --- a/googlemock/include/gmock/gmock-generated-matchers.h +++ b/googlemock/include/gmock/gmock-generated-matchers.h @@ -261,8 +261,12 @@ // https://github.com/google/googletest/blob/master/googlemock/docs/cook_book.md #define MATCHER(name, description)\ - class name##Matcher {\ + class name##Matcher : public \ + ::testing::internal::MatcherBaseImpl {\ + using __internal_base_type = \ + ::testing::internal::MatcherBaseImpl;\ public:\ + using __internal_base_type::__internal_base_type;\ template \ class gmock_Impl : public ::testing::MatcherInterface<\ GTEST_REFERENCE_TO_CONST_(arg_type)> {\ @@ -290,14 +294,6 @@ ::std::tuple<>()));\ }\ };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl());\ - }\ - name##Matcher() {\ - }\ - private:\ };\ inline name##Matcher name() {\ return name##Matcher();\ @@ -310,8 +306,12 @@ #define MATCHER_P(name, p0, description)\ template \ - class name##MatcherP {\ + class name##MatcherP : public \ + ::testing::internal::MatcherBaseImpl> {\ + using __internal_base_type = \ + ::testing::internal::MatcherBaseImpl;\ public:\ + using __internal_base_type::__internal_base_type;\ template \ class gmock_Impl : public ::testing::MatcherInterface<\ GTEST_REFERENCE_TO_CONST_(arg_type)> {\ @@ -340,15 +340,6 @@ ::std::tuple(p0)));\ }\ };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0));\ - }\ - explicit name##MatcherP(p0##_type gmock_p0) : p0(::std::move(gmock_p0)) {\ - }\ - p0##_type const p0;\ - private:\ };\ template \ inline name##MatcherP name(p0##_type p0) {\ @@ -363,8 +354,13 @@ #define MATCHER_P2(name, p0, p1, description)\ template \ - class name##MatcherP2 {\ + class name##MatcherP2 : public \ + ::testing::internal::MatcherBaseImpl> {\ + using __internal_base_type = \ + ::testing::internal::MatcherBaseImpl;\ public:\ + using __internal_base_type::__internal_base_type;\ template \ class gmock_Impl : public ::testing::MatcherInterface<\ GTEST_REFERENCE_TO_CONST_(arg_type)> {\ @@ -394,18 +390,6 @@ ::std::tuple(p0, p1)));\ }\ };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1));\ - }\ - name##MatcherP2(p0##_type gmock_p0, \ - p1##_type gmock_p1) : p0(::std::move(gmock_p0)), \ - p1(::std::move(gmock_p1)) {\ - }\ - p0##_type const p0;\ - p1##_type const p1;\ - private:\ };\ template \ inline name##MatcherP2 name(p0##_type p0, \ @@ -422,8 +406,13 @@ #define MATCHER_P3(name, p0, p1, p2, description)\ template \ - class name##MatcherP3 {\ + class name##MatcherP3 : public \ + ::testing::internal::MatcherBaseImpl> {\ + using __internal_base_type = \ + ::testing::internal::MatcherBaseImpl;\ public:\ + using __internal_base_type::__internal_base_type;\ template \ class gmock_Impl : public ::testing::MatcherInterface<\ GTEST_REFERENCE_TO_CONST_(arg_type)> {\ @@ -455,19 +444,6 @@ ::std::tuple(p0, p1, p2)));\ }\ };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2));\ - }\ - name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2) : p0(::std::move(gmock_p0)), \ - p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)) {\ - }\ - p0##_type const p0;\ - p1##_type const p1;\ - p2##_type const p2;\ - private:\ };\ template \ inline name##MatcherP3 name(p0##_type p0, \ @@ -485,8 +461,13 @@ #define MATCHER_P4(name, p0, p1, p2, p3, description)\ template \ - class name##MatcherP4 {\ + class name##MatcherP4 : public \ + ::testing::internal::MatcherBaseImpl> {\ + using __internal_base_type = \ + ::testing::internal::MatcherBaseImpl;\ public:\ + using __internal_base_type::__internal_base_type;\ template \ class gmock_Impl : public ::testing::MatcherInterface<\ GTEST_REFERENCE_TO_CONST_(arg_type)> {\ @@ -521,21 +502,6 @@ p1, p2, p3)));\ }\ };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3));\ - }\ - name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3) : p0(::std::move(gmock_p0)), \ - p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ - p3(::std::move(gmock_p3)) {\ - }\ - p0##_type const p0;\ - p1##_type const p1;\ - p2##_type const p2;\ - p3##_type const p3;\ - private:\ };\ template \ @@ -557,8 +523,13 @@ #define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\ template \ - class name##MatcherP5 {\ + class name##MatcherP5 : public \ + ::testing::internal::MatcherBaseImpl> {\ + using __internal_base_type = \ + ::testing::internal::MatcherBaseImpl;\ public:\ + using __internal_base_type::__internal_base_type;\ template \ class gmock_Impl : public ::testing::MatcherInterface<\ GTEST_REFERENCE_TO_CONST_(arg_type)> {\ @@ -595,23 +566,6 @@ p4##_type>(p0, p1, p2, p3, p4)));\ }\ };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4));\ - }\ - name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3, \ - p4##_type gmock_p4) : p0(::std::move(gmock_p0)), \ - p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ - p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)) {\ - }\ - p0##_type const p0;\ - p1##_type const p1;\ - p2##_type const p2;\ - p3##_type const p3;\ - p4##_type const p4;\ - private:\ };\ template \ @@ -633,8 +587,13 @@ #define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\ template \ - class name##MatcherP6 {\ + class name##MatcherP6 : public \ + ::testing::internal::MatcherBaseImpl> {\ + using __internal_base_type = \ + ::testing::internal::MatcherBaseImpl;\ public:\ + using __internal_base_type::__internal_base_type;\ template \ class gmock_Impl : public ::testing::MatcherInterface<\ GTEST_REFERENCE_TO_CONST_(arg_type)> {\ @@ -672,25 +631,6 @@ p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5)));\ }\ };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4, p5));\ - }\ - name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ - p5##_type gmock_p5) : p0(::std::move(gmock_p0)), \ - p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ - p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ - p5(::std::move(gmock_p5)) {\ - }\ - p0##_type const p0;\ - p1##_type const p1;\ - p2##_type const p2;\ - p3##_type const p3;\ - p4##_type const p4;\ - p5##_type const p5;\ - private:\ };\ template \ @@ -713,8 +653,13 @@ template \ - class name##MatcherP7 {\ + class name##MatcherP7 : public \ + ::testing::internal::MatcherBaseImpl> {\ + using __internal_base_type = \ + ::testing::internal::MatcherBaseImpl;\ public:\ + using __internal_base_type::__internal_base_type;\ template \ class gmock_Impl : public ::testing::MatcherInterface<\ GTEST_REFERENCE_TO_CONST_(arg_type)> {\ @@ -756,26 +701,6 @@ p6)));\ }\ };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4, p5, p6));\ - }\ - name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ - p5##_type gmock_p5, p6##_type gmock_p6) : p0(::std::move(gmock_p0)), \ - p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ - p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ - p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)) {\ - }\ - p0##_type const p0;\ - p1##_type const p1;\ - p2##_type const p2;\ - p3##_type const p3;\ - p4##_type const p4;\ - p5##_type const p5;\ - p6##_type const p6;\ - private:\ };\ template \ - class name##MatcherP8 {\ + class name##MatcherP8 : public \ + ::testing::internal::MatcherBaseImpl> {\ + using __internal_base_type = \ + ::testing::internal::MatcherBaseImpl;\ public:\ + using __internal_base_type::__internal_base_type;\ template \ class gmock_Impl : public ::testing::MatcherInterface<\ GTEST_REFERENCE_TO_CONST_(arg_type)> {\ @@ -845,29 +776,6 @@ p3, p4, p5, p6, p7)));\ }\ };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4, p5, p6, p7));\ - }\ - name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ - p5##_type gmock_p5, p6##_type gmock_p6, \ - p7##_type gmock_p7) : p0(::std::move(gmock_p0)), \ - p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ - p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ - p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \ - p7(::std::move(gmock_p7)) {\ - }\ - p0##_type const p0;\ - p1##_type const p1;\ - p2##_type const p2;\ - p3##_type const p3;\ - p4##_type const p4;\ - p5##_type const p5;\ - p6##_type const p6;\ - p7##_type const p7;\ - private:\ };\ template \ - class name##MatcherP9 {\ + class name##MatcherP9 : public \ + ::testing::internal::MatcherBaseImpl> {\ + using __internal_base_type = \ + ::testing::internal::MatcherBaseImpl;\ public:\ + using __internal_base_type::__internal_base_type;\ template \ class gmock_Impl : public ::testing::MatcherInterface<\ GTEST_REFERENCE_TO_CONST_(arg_type)> {\ @@ -941,30 +855,6 @@ p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\ }\ };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4, p5, p6, p7, p8));\ - }\ - name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ - p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ - p8##_type gmock_p8) : p0(::std::move(gmock_p0)), \ - p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ - p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ - p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \ - p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)) {\ - }\ - p0##_type const p0;\ - p1##_type const p1;\ - p2##_type const p2;\ - p3##_type const p3;\ - p4##_type const p4;\ - p5##_type const p5;\ - p6##_type const p6;\ - p7##_type const p7;\ - p8##_type const p8;\ - private:\ };\ template \ - class name##MatcherP10 {\ + class name##MatcherP10 : public \ + ::testing::internal::MatcherBaseImpl> {\ + using __internal_base_type = \ + ::testing::internal::MatcherBaseImpl;\ public:\ + using __internal_base_type::__internal_base_type;\ template \ class gmock_Impl : public ::testing::MatcherInterface<\ GTEST_REFERENCE_TO_CONST_(arg_type)> {\ @@ -1042,32 +938,6 @@ p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\ }\ };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\ - }\ - name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ - p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ - p8##_type gmock_p8, p9##_type gmock_p9) : p0(::std::move(gmock_p0)), \ - p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \ - p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \ - p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \ - p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)), \ - p9(::std::move(gmock_p9)) {\ - }\ - p0##_type const p0;\ - p1##_type const p1;\ - p2##_type const p2;\ - p3##_type const p3;\ - p4##_type const p4;\ - p5##_type const p5;\ - p6##_type const p6;\ - p7##_type const p7;\ - p8##_type const p8;\ - p9##_type const p9;\ - private:\ };\ template \ ]]]] -$var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]] $var impl_ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]] $var impl_inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::std::move(gmock_p$j))]]]]]] -$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::std::move(gmock_p$j))]]]]]] $var params = [[$for j, [[p$j]]]] $var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]] $var param_types_and_names = [[$for j, [[p$j##_type p$j]]]] @@ -294,8 +292,10 @@ $var param_field_decls2 = [[$for j ]]]] #define $macro_name(name$for j [[, p$j]], description)\$template - class $class_name {\ + class $class_name : public ::testing::internal::MatcherBaseImpl<$class_name$param_types> {\ + using __internal_base_type = ::testing::internal::MatcherBaseImpl<$class_name>;\ public:\ + using __internal_base_type::__internal_base_type;\ template \ class gmock_Impl : public ::testing::MatcherInterface<\ GTEST_REFERENCE_TO_CONST_(arg_type)> {\ @@ -323,14 +323,6 @@ $var param_field_decls2 = [[$for j ::std::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]])));\ }\ };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl($params));\ - }\ - [[$if i==1 [[explicit ]]]]$class_name($ctor_param_list)$inits {\ - }\$param_field_decls2 - private:\ };\$template inline $class_name$param_types name($param_types_and_names) {\ return $class_name$param_types($params);\ diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 4baeb1bd..f1805dbb 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -236,6 +236,58 @@ class MatcherCastImpl > { static Matcher Cast(const Matcher& matcher) { return matcher; } }; +// Template specialization for parameterless Matcher. +template +class MatcherBaseImpl { + public: + MatcherBaseImpl() = default; + + template + operator ::testing::Matcher() const { // NOLINT(runtime/explicit) + return ::testing::Matcher(new + typename Derived::template gmock_Impl()); + } +}; + +// Template specialization for Matcher with 1 parameter. +template