From 008e54c1dd407b6edd680fccf78cd194365e0507 Mon Sep 17 00:00:00 2001 From: Martin Oberhuber Date: Sat, 5 Nov 2016 09:25:59 +0100 Subject: Fix #923 - support CMAKE_CROSSCOMPILING_EMULATOR for tests Replaced legacy syntax of cmake add_test() with more modern syntax. This allows running gtests's own tests on remote (cross) systems using CMAKE_CROSSCOMPILING_EMULATOR with cmake-3.3 or newer. --- googletest/cmake/internal_utils.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 8878dc1..93b9e51 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -216,7 +216,7 @@ find_package(PythonInterp) # from the given source files with the given compiler flags. function(cxx_test_with_flags name cxx_flags libs) cxx_executable_with_flags(${name} "${cxx_flags}" "${libs}" ${ARGN}) - add_test(${name} ${name}) + add_test(NAME ${name} COMMAND ${name}) endfunction() # cxx_test(name libs srcs...) -- cgit v0.12 From c958e26fd02d43a916ff297c89eee22166fe7be7 Mon Sep 17 00:00:00 2001 From: Scott Slack-Smith Date: Fri, 30 Jun 2017 17:12:56 +0100 Subject: *Silence false positive memory leaks reported by Microsoft's debug CRT* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a new RAII MemoryIsNotDeallocated class that excludes memory allocations from Microsoft’s debug CRT leak detection report. We use this RAII class to silence 2 false positive leaks that are caused by memory allocations that are intentionally never deallocated. *Background* The MS debug CRT has a lightweight memory leak detection mechanism that can only detect if a memory allocation is missing a matching deallocation. Consequently, it will report a false positive leak for memory that’s intentionally never deallocated. For example, memory that’s reachable for the entire lifetime of a app. Note the MS debug CRT is always tracking memory allocations but the final memory leak report is disabled by default. As you can’t avoid paying for its cost, you may as well use it. The memory leak report can be enabled by calling the following function #ifdef _MSC_VER _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF); #endif // _MSC_VER anywhere before exiting main. For example, the following are the false positive leaks reported before this change; Detected memory leaks! Dumping objects -> {750} normal block at 0x015DF938, 8 bytes long. Data: < ] > 00 F9 5D 01 00 00 00 00 {749} normal block at 0x015DEE60, 32 bytes long. Data: <` ] ` ] ` ] > 60 EE 5D 01 60 EE 5D 01 60 EE 5D 01 01 01 CD CD {748} normal block at 0x015DF900, 12 bytes long. Data: <8 ] ` ] > 38 F9 5D 01 60 EE 5D 01 00 00 00 00 {747} normal block at 0x015DA0F8, 24 bytes long. Data: < > FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 Object dump complete. As you can see from above it’s not easy to identify the above are false positives. Consequently, if false positive leaks are not fixed or silenced, then it becomes impractical to identify real memory leaks. --- googletest/src/gtest-port.cc | 52 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index d80bd80..edd115d 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -279,6 +279,43 @@ void Mutex::AssertHeld() { << "The current thread is not holding the mutex @" << this; } +namespace { + +// Use the RAII idiom to flag mem allocs that are intentionally never +// deallocated. The motivation is to silence the false positive mem leaks +// that are reported by the debug version of MS's CRT which can only detect +// if an alloc is missing a matching deallocation. +// Example: +// MemoryIsNotDeallocated memory_is_not_deallocated; +// critical_section_ = new CRITICAL_SECTION; +// +class MemoryIsNotDeallocated +{ +public: + MemoryIsNotDeallocated() : old_crtdbg_flag_(0) { +#ifdef _MSC_VER + old_crtdbg_flag_ = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); + // Set heap allocation block type to _IGNORE_BLOCK so that MS debug CRT + // doesn't report mem leak if there's no matching deallocation. + _CrtSetDbgFlag(old_crtdbg_flag_ & ~_CRTDBG_ALLOC_MEM_DF); +#endif // _MSC_VER + } + + ~MemoryIsNotDeallocated() { +#ifdef _MSC_VER + // Restore the original _CRTDBG_ALLOC_MEM_DF flag + _CrtSetDbgFlag(old_crtdbg_flag_); +#endif // _MSC_VER + } + +private: + int old_crtdbg_flag_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(MemoryIsNotDeallocated); +}; + +} // namespace + // Initializes owner_thread_id_ and critical_section_ in static mutexes. void Mutex::ThreadSafeLazyInit() { // Dynamic mutexes are initialized in the constructor. @@ -289,7 +326,11 @@ void Mutex::ThreadSafeLazyInit() { // If critical_section_init_phase_ was 0 before the exchange, we // are the first to test it and need to perform the initialization. owner_thread_id_ = 0; - critical_section_ = new CRITICAL_SECTION; + { + // Use RAII to flag that following mem alloc is never deallocated. + MemoryIsNotDeallocated memory_is_not_deallocated; + critical_section_ = new CRITICAL_SECTION; + } ::InitializeCriticalSection(critical_section_); // Updates the critical_section_init_phase_ to 2 to signal // initialization complete. @@ -528,10 +569,17 @@ class ThreadLocalRegistryImpl { return 0; } + // Return a newly constructed ThreadIdToThreadLocals that's intentionally never deleted + static ThreadIdToThreadLocals* NewThreadIdToThreadLocals() { + // Use RAII to flag that following mem alloc is never deallocated. + MemoryIsNotDeallocated memory_is_not_deallocated; + return new ThreadIdToThreadLocals; + } + // Returns map of thread local instances. static ThreadIdToThreadLocals* GetThreadLocalsMapLocked() { mutex_.AssertHeld(); - static ThreadIdToThreadLocals* map = new ThreadIdToThreadLocals; + static ThreadIdToThreadLocals* map = NewThreadIdToThreadLocals(); return map; } -- cgit v0.12 From f9155307911ecdbf344d153adc577e6bb0e0a67c Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Thu, 25 Jan 2018 14:14:33 -0800 Subject: Pass -EHs-c- to disable exceptions with MSVC. --- googletest/cmake/internal_utils.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index c54bc94..acffe0c 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -91,7 +91,7 @@ macro(config_compiler_and_linker) set(cxx_base_flags "${cxx_base_flags} -D_UNICODE -DUNICODE -DWIN32 -D_WIN32") set(cxx_base_flags "${cxx_base_flags} -DSTRICT -DWIN32_LEAN_AND_MEAN") set(cxx_exception_flags "-EHsc -D_HAS_EXCEPTIONS=1") - set(cxx_no_exception_flags "-D_HAS_EXCEPTIONS=0") + set(cxx_no_exception_flags "-EHs-c- -D_HAS_EXCEPTIONS=0") set(cxx_no_rtti_flags "-GR-") elseif (CMAKE_COMPILER_IS_GNUCXX) set(cxx_base_flags "-Wall -Wshadow -Werror") -- cgit v0.12 From 3498a1ac52deb83f30b8170c78bfba9dc6227198 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Wed, 24 Jan 2018 17:15:18 -0800 Subject: Use _CPPUNWIND instead of _HAS_EXCEPTIONS with MSVC. _HAS_EXCEPTIONS is specific to the MSVC STL and defining it to 0 causes problems with libc++, so libc++ users may leave it undefined. This can cause GTEST_HAS_EXCEPTIONS to be defined incorrectly if the user has disabled exceptions via the compiler, which can lead to build errors. _CPPUNWIND is a builtin macro provided by the compiler so it should work with both STLs. --- googletest/include/gtest/internal/gtest-port.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 01ad5da..1a1d9dd 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -464,8 +464,11 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #ifndef GTEST_HAS_EXCEPTIONS // The user didn't tell us whether exceptions are enabled, so we need // to figure it out. -# if defined(_MSC_VER) || defined(__BORLANDC__) -// MSVC's and C++Builder's implementations of the STL use the _HAS_EXCEPTIONS +# if defined(_MSC_VER) && defined(_CPPUNWIND) +// MSVC defines _CPPUNWIND to 1 iff exceptions are enabled. +# define GTEST_HAS_EXCEPTIONS 1 +# elif defined(__BORLANDC__) +// C++Builder's implementation of the STL uses the _HAS_EXCEPTIONS // macro to enable exceptions, so we'll do the same. // Assumes that exceptions are enabled by default. # ifndef _HAS_EXCEPTIONS -- cgit v0.12 From d84f58ab1085802388e240ed3ac072cd86bf5523 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 12 Feb 2018 14:07:45 -0500 Subject: Merging, coniniue --- googletest/src/gtest-death-test.cc | 10 ++++------ googletest/test/gtest-death-test_test.cc | 6 +++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index 00e231b..92a2980 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -983,7 +983,6 @@ static int ExecDeathTestChildMain(void* child_arg) { } # endif // !GTEST_OS_QNX -# if GTEST_HAS_CLONE // Two utility routines that together determine the direction the stack // grows. // This could be accomplished more elegantly by a single recursive @@ -1008,7 +1007,6 @@ static bool StackGrowsDown() { StackLowerThanAddress(&dummy, &result); return result; } -# endif // GTEST_HAS_CLONE // Spawns a child process with the same executable as the current process in // a thread-safe manner and instructs it to run the death test. The @@ -1225,11 +1223,11 @@ bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex, // signals the event, and returns a file descriptor wrapped around the pipe // handle. This function is called in the child process only. static int GetStatusFileDescriptor(unsigned int parent_process_id, - size_t write_handle_as_size_t, - size_t event_handle_as_size_t) { + size_t write_handle_as_size_t, + size_t event_handle_as_size_t) { AutoHandle parent_process_handle(::OpenProcess(PROCESS_DUP_HANDLE, - FALSE, // Non-inheritable. - parent_process_id)); + FALSE, // Non-inheritable. + parent_process_id)); if (parent_process_handle.Get() == INVALID_HANDLE_VALUE) { DeathTestAbort("Unable to open parent process " + StreamableToString(parent_process_id)); diff --git a/googletest/test/gtest-death-test_test.cc b/googletest/test/gtest-death-test_test.cc index b7846b2..21573c7 100644 --- a/googletest/test/gtest-death-test_test.cc +++ b/googletest/test/gtest-death-test_test.cc @@ -617,7 +617,11 @@ TEST_F(TestForDeathTest, ReturnIsFailure) { TEST_F(TestForDeathTest, TestExpectDebugDeath) { int sideeffect = 0; - EXPECT_DEBUG_DEATH(DieInDebugElse12(&sideeffect), "death.*DieInDebugElse12") + // Put the regex in a local variable to make sure we don't get an "unused" + // warning in opt mode. + const char* regex = "death.*DieInDebugElse12"; + + EXPECT_DEBUG_DEATH(DieInDebugElse12(&sideeffect), regex) << "Must accept a streamed message"; # ifdef NDEBUG -- cgit v0.12 From b3a1759eac70b26dc6f16562745c59030c6b927f Mon Sep 17 00:00:00 2001 From: Victor Costan Date: Fri, 9 Feb 2018 22:42:32 -0800 Subject: Fix std::iscntrl use in gtest-printers.cc ContainsUnprintableControlCodes() in gtest-printers.cc passes a char argument to std::iscntrl. Although its argument is an int, std::iscntrl produces undefined behavior if its argument is not representable as an unsigned char. The standard library on Windows asserts that the argument is an unsigned char, resulting in an assertion crash on debug builds. --- googletest/src/gtest-printers.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/googletest/src/gtest-printers.cc b/googletest/src/gtest-printers.cc index fe70edc..d55a5e9 100644 --- a/googletest/src/gtest-printers.cc +++ b/googletest/src/gtest-printers.cc @@ -357,8 +357,10 @@ void PrintTo(const wchar_t* s, ostream* os) { namespace { bool ContainsUnprintableControlCodes(const char* str, size_t length) { + const unsigned char *s = reinterpret_cast(str); + for (size_t i = 0; i < length; i++) { - char ch = *str++; + unsigned char ch = *s++; if (std::iscntrl(ch)) { switch (ch) { case '\t': -- cgit v0.12 From 225e6741acfaa38375589dafcc84254a92313dac Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 12 Feb 2018 16:42:12 -0500 Subject: moving JoinAsTuple to internal --- googlemock/include/gmock/gmock-matchers.h | 4 ---- googlemock/src/gmock-internal-utils.cc | 19 +++++++++++++++++++ googlemock/src/gmock-matchers.cc | 19 ------------------- googlemock/test/gmock-matchers_test.cc | 29 +++-------------------------- 4 files changed, 22 insertions(+), 49 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 94c23d3..fc3fe3a 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -3614,10 +3614,6 @@ BoundSecondMatcher MatcherBindSecond( return BoundSecondMatcher(tm, second); } -// Joins a vector of strings as if they are fields of a tuple; returns -// the joined string. This function is exported for testing. -GTEST_API_ string JoinAsTuple(const Strings& fields); - // Returns the description for a matcher defined using the MATCHER*() // macro where the user-supplied description string is "", if // 'negation' is false; otherwise returns the description of the diff --git a/googlemock/src/gmock-internal-utils.cc b/googlemock/src/gmock-internal-utils.cc index 91bf3fd..658fa62 100644 --- a/googlemock/src/gmock-internal-utils.cc +++ b/googlemock/src/gmock-internal-utils.cc @@ -47,6 +47,25 @@ namespace testing { namespace internal { +// Joins a vector of strings as if they are fields of a tuple; returns +// the joined string. +GTEST_API_ std::string JoinAsTuple(const Strings& fields) { + switch (fields.size()) { + case 0: + return ""; + case 1: + return fields[0]; + default: + std::string result = "(" + fields[0]; + for (size_t i = 1; i < fields.size(); i++) { + result += ", "; + result += fields[i]; + } + result += ")"; + return result; + } +} + // Converts an identifier name to a space-separated list of lower-case // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is // treated as one word. For example, both "FooBar123" and diff --git a/googlemock/src/gmock-matchers.cc b/googlemock/src/gmock-matchers.cc index 6e40e5e..f37d5c2 100644 --- a/googlemock/src/gmock-matchers.cc +++ b/googlemock/src/gmock-matchers.cc @@ -100,25 +100,6 @@ Matcher::Matcher(StringPiece s) { namespace internal { -// Joins a vector of strings as if they are fields of a tuple; returns -// the joined string. -GTEST_API_ string JoinAsTuple(const Strings& fields) { - switch (fields.size()) { - case 0: - return ""; - case 1: - return fields[0]; - default: - string result = "(" + fields[0]; - for (size_t i = 1; i < fields.size(); i++) { - result += ", "; - result += fields[i]; - } - result += ")"; - return result; - } -} - // Returns the description for a matcher defined using the MATCHER*() // macro where the user-supplied description string is "", if // 'negation' is false; otherwise returns the description of the diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 07e5fa6..761c0c2 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -146,7 +146,6 @@ using testing::internal::ExplainMatchFailureTupleTo; using testing::internal::FloatingEqMatcher; using testing::internal::FormatMatcherDescription; using testing::internal::IsReadableTypeName; -using testing::internal::JoinAsTuple; using testing::internal::linked_ptr; using testing::internal::MatchMatrix; using testing::internal::RE; @@ -872,9 +871,9 @@ class Unprintable { char c_; }; -inline bool operator==(const Unprintable& /* lhs */, - const Unprintable& /* rhs */) { - return true; +inline bool operator==(const Unprintable& /* lhs */, + const Unprintable& /* rhs */) { + return true; } TEST(EqTest, CanDescribeSelf) { @@ -5268,28 +5267,6 @@ TEST(IsReadableTypeNameTest, ReturnsFalseForLongFunctionTypeNames) { EXPECT_FALSE(IsReadableTypeName("void (&)(int, bool, char, float)")); } -// Tests JoinAsTuple(). - -TEST(JoinAsTupleTest, JoinsEmptyTuple) { - EXPECT_EQ("", JoinAsTuple(Strings())); -} - -TEST(JoinAsTupleTest, JoinsOneTuple) { - const char* fields[] = {"1"}; - EXPECT_EQ("1", JoinAsTuple(Strings(fields, fields + 1))); -} - -TEST(JoinAsTupleTest, JoinsTwoTuple) { - const char* fields[] = {"1", "a"}; - EXPECT_EQ("(1, a)", JoinAsTuple(Strings(fields, fields + 2))); -} - -TEST(JoinAsTupleTest, JoinsTenTuple) { - const char* fields[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; - EXPECT_EQ("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)", - JoinAsTuple(Strings(fields, fields + 10))); -} - // Tests FormatMatcherDescription(). TEST(FormatMatcherDescriptionTest, WorksForEmptyDescription) { -- cgit v0.12 From 9e072812e3023f8c45593052965998d6646b5e78 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 13 Feb 2018 09:45:12 -0500 Subject: merges --- googletest/test/gtest-param-test_test.cc | 49 ++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/googletest/test/gtest-param-test_test.cc b/googletest/test/gtest-param-test_test.cc index b0aa4f9..60bdfea 100644 --- a/googletest/test/gtest-param-test_test.cc +++ b/googletest/test/gtest-param-test_test.cc @@ -41,8 +41,8 @@ # include # include # include -# include "src/gtest-internal-inl.h" // for UnitTestOptions +# include "src/gtest-internal-inl.h" // for UnitTestOptions # include "test/gtest-param-test_test.h" using ::std::vector; @@ -536,6 +536,48 @@ TEST(CombineTest, CombineWithMaxNumberOfParameters) { VerifyGenerator(gen, expected_values); } +class NonDefaultConstructAssignString { + public: + NonDefaultConstructAssignString(const std::string& str) : str_(str) {} + + const std::string& str() const { return str_; } + + private: + std::string str_; + + // Not default constructible + NonDefaultConstructAssignString(); + // Not assignable + void operator=(const NonDefaultConstructAssignString&); +}; + +TEST(CombineTest, NonDefaultConstructAssign) { + const ParamGenerator> gen = + Combine(Values(0, 1), Values(NonDefaultConstructAssignString("A"), + NonDefaultConstructAssignString("B"))); + + ParamGenerator>::iterator it = + gen.begin(); + + EXPECT_EQ(0, std::get<0>(*it)); + EXPECT_EQ("A", std::get<1>(*it).str()); + ++it; + + EXPECT_EQ(0, std::get<0>(*it)); + EXPECT_EQ("B", std::get<1>(*it).str()); + ++it; + + EXPECT_EQ(1, std::get<0>(*it)); + EXPECT_EQ("A", std::get<1>(*it).str()); + ++it; + + EXPECT_EQ(1, std::get<0>(*it)); + EXPECT_EQ("B", std::get<1>(*it).str()); + ++it; + + EXPECT_TRUE(it == gen.end()); +} + # endif // GTEST_HAS_COMBINE // Tests that an generator produces correct sequence after being @@ -851,8 +893,8 @@ TEST_P(CustomLambdaNamingTest, CustomTestNames) {} INSTANTIATE_TEST_CASE_P(CustomParamNameLambda, CustomLambdaNamingTest, Values(std::string("LambdaName")), - [](const ::testing::TestParamInfo& tpinfo) { - return tpinfo.param; + [](const ::testing::TestParamInfo& info) { + return info.param; }); #endif // GTEST_LANG_CXX11 @@ -1019,6 +1061,7 @@ TEST_F(ParameterizedDeathTest, GetParamDiesFromTestF) { INSTANTIATE_TEST_CASE_P(RangeZeroToFive, ParameterizedDerivedTest, Range(0, 5)); + int main(int argc, char **argv) { // Used in TestGenerationTest test case. AddGlobalTestEnvironment(TestGenerationTest::Environment::Instance()); -- cgit v0.12 From e76f4ee9fd1693429146dc62b27f72a1cb38b2ff Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 13 Feb 2018 10:05:43 -0500 Subject: clang warning https://travis-ci.org/google/googletest/jobs/340978022 --- googletest/test/gtest-param-test_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/test/gtest-param-test_test.cc b/googletest/test/gtest-param-test_test.cc index 60bdfea..11ad853 100644 --- a/googletest/test/gtest-param-test_test.cc +++ b/googletest/test/gtest-param-test_test.cc @@ -538,7 +538,7 @@ TEST(CombineTest, CombineWithMaxNumberOfParameters) { class NonDefaultConstructAssignString { public: - NonDefaultConstructAssignString(const std::string& str) : str_(str) {} + NonDefaultConstructAssignString(const std::string& s) : str_(s) {} const std::string& str() const { return str_; } -- cgit v0.12 From a66d209061ebdcf81ed93c1dd0336944514fd1df Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 13 Feb 2018 10:23:42 -0500 Subject: clang warning 'https://travis-ci.org/google/googletest/jobs/340987201' --- googletest/test/gtest-param-test_test.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/googletest/test/gtest-param-test_test.cc b/googletest/test/gtest-param-test_test.cc index 11ad853..6e62dfa 100644 --- a/googletest/test/gtest-param-test_test.cc +++ b/googletest/test/gtest-param-test_test.cc @@ -853,8 +853,8 @@ class CustomFunctorNamingTest : public TestWithParam {}; TEST_P(CustomFunctorNamingTest, CustomTestNames) {} struct CustomParamNameFunctor { - std::string operator()(const ::testing::TestParamInfo& info) { - return info.param; + std::string operator()(const ::testing::TestParamInfo& inf) { + return inf.param; } }; @@ -893,8 +893,8 @@ TEST_P(CustomLambdaNamingTest, CustomTestNames) {} INSTANTIATE_TEST_CASE_P(CustomParamNameLambda, CustomLambdaNamingTest, Values(std::string("LambdaName")), - [](const ::testing::TestParamInfo& info) { - return info.param; + [](const ::testing::TestParamInfo& inf) { + return inf.param; }); #endif // GTEST_LANG_CXX11 -- cgit v0.12 From 2a23ca00092bbb9c31d7a7b6fa9519bf2d8c70c7 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 13 Feb 2018 11:05:01 -0500 Subject: https://travis-ci.org/google/googletest/jobs/340995238 --- googletest/test/gtest-param-test_test.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/googletest/test/gtest-param-test_test.cc b/googletest/test/gtest-param-test_test.cc index 6e62dfa..9d970d2 100644 --- a/googletest/test/gtest-param-test_test.cc +++ b/googletest/test/gtest-param-test_test.cc @@ -556,7 +556,7 @@ TEST(CombineTest, NonDefaultConstructAssign) { Combine(Values(0, 1), Values(NonDefaultConstructAssignString("A"), NonDefaultConstructAssignString("B"))); - ParamGenerator>::iterator it = + ParamGenerator >::iterator it = gen.begin(); EXPECT_EQ(0, std::get<0>(*it)); @@ -871,8 +871,8 @@ INSTANTIATE_TEST_CASE_P(AllAllowedCharacters, CustomParamNameFunctor()); inline std::string CustomParamNameFunction( - const ::testing::TestParamInfo& info) { - return info.param; + const ::testing::TestParamInfo& inf) { + return inf.param; } class CustomFunctionNamingTest : public TestWithParam {}; @@ -893,8 +893,8 @@ TEST_P(CustomLambdaNamingTest, CustomTestNames) {} INSTANTIATE_TEST_CASE_P(CustomParamNameLambda, CustomLambdaNamingTest, Values(std::string("LambdaName")), - [](const ::testing::TestParamInfo& inf) { - return inf.param; + [](const ::testing::TestParamInfo& info) { + return info.param; }); #endif // GTEST_LANG_CXX11 -- cgit v0.12 From d7c966c4defea40b5f161999e2a6dab9cca9d540 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 13 Feb 2018 11:15:03 -0500 Subject: clang warnings --- googletest/test/gtest-param-test_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/test/gtest-param-test_test.cc b/googletest/test/gtest-param-test_test.cc index 9d970d2..5f6d946 100644 --- a/googletest/test/gtest-param-test_test.cc +++ b/googletest/test/gtest-param-test_test.cc @@ -893,8 +893,8 @@ TEST_P(CustomLambdaNamingTest, CustomTestNames) {} INSTANTIATE_TEST_CASE_P(CustomParamNameLambda, CustomLambdaNamingTest, Values(std::string("LambdaName")), - [](const ::testing::TestParamInfo& info) { - return info.param; + [](const ::testing::TestParamInfo& inf) { + return inf.param; }); #endif // GTEST_LANG_CXX11 -- cgit v0.12 From 3b1fe3ec45276c58aac6522dc009a2e8f193d996 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 13 Feb 2018 11:24:09 -0500 Subject: clang warnings --- googletest/test/gtest-param-test_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/test/gtest-param-test_test.cc b/googletest/test/gtest-param-test_test.cc index 5f6d946..0236e87 100644 --- a/googletest/test/gtest-param-test_test.cc +++ b/googletest/test/gtest-param-test_test.cc @@ -552,7 +552,7 @@ class NonDefaultConstructAssignString { }; TEST(CombineTest, NonDefaultConstructAssign) { - const ParamGenerator> gen = + const ParamGenerator > gen = Combine(Values(0, 1), Values(NonDefaultConstructAssignString("A"), NonDefaultConstructAssignString("B"))); -- cgit v0.12 From 30d276da03468d08bcde1820b6b9ed17e9fffbe6 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 13 Feb 2018 11:48:32 -0500 Subject: cxxx11 --- googletest/test/gtest-param-test_test.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/googletest/test/gtest-param-test_test.cc b/googletest/test/gtest-param-test_test.cc index 0236e87..fb2e44b 100644 --- a/googletest/test/gtest-param-test_test.cc +++ b/googletest/test/gtest-param-test_test.cc @@ -536,6 +536,8 @@ TEST(CombineTest, CombineWithMaxNumberOfParameters) { VerifyGenerator(gen, expected_values); } +#if GTEST_LANG_CXX11 + class NonDefaultConstructAssignString { public: NonDefaultConstructAssignString(const std::string& s) : str_(s) {} @@ -578,6 +580,7 @@ TEST(CombineTest, NonDefaultConstructAssign) { EXPECT_TRUE(it == gen.end()); } +#endif // GTEST_LANG_CXX11 # endif // GTEST_HAS_COMBINE // Tests that an generator produces correct sequence after being -- cgit v0.12 From ab186a8c49a2939cd99565da009ae5c6230b3246 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 13 Feb 2018 13:49:57 -0500 Subject: merges --- googletest/test/gtest-param-test_test.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/googletest/test/gtest-param-test_test.cc b/googletest/test/gtest-param-test_test.cc index fb2e44b..b21cb31 100644 --- a/googletest/test/gtest-param-test_test.cc +++ b/googletest/test/gtest-param-test_test.cc @@ -893,8 +893,7 @@ INSTANTIATE_TEST_CASE_P(CustomParamNameFunction, class CustomLambdaNamingTest : public TestWithParam {}; TEST_P(CustomLambdaNamingTest, CustomTestNames) {} -INSTANTIATE_TEST_CASE_P(CustomParamNameLambda, - CustomLambdaNamingTest, +INSTANTIATE_TEST_CASE_P(CustomParamNameLambda, CustomLambdaNamingTest, Values(std::string("LambdaName")), [](const ::testing::TestParamInfo& inf) { return inf.param; -- cgit v0.12 From 069724197c03e56c0197b80ace8b97187d27c45d Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 13 Feb 2018 14:13:52 -0500 Subject: merging, cleaning up --- googletest/test/gtest_all_test.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/googletest/test/gtest_all_test.cc b/googletest/test/gtest_all_test.cc index 955aa62..e16ef53 100644 --- a/googletest/test/gtest_all_test.cc +++ b/googletest/test/gtest_all_test.cc @@ -33,15 +33,15 @@ // // Sometimes it's desirable to build most of Google Test's own tests // by compiling a single file. This file serves this purpose. -#include "test/gtest-filepath_test.cc" -#include "test/gtest-linked_ptr_test.cc" -#include "test/gtest-message_test.cc" -#include "test/gtest-options_test.cc" -#include "test/gtest-port_test.cc" -#include "test/gtest_pred_impl_unittest.cc" -#include "test/gtest_prod_test.cc" -#include "test/gtest-test-part_test.cc" -#include "test/gtest-typed-test_test.cc" -#include "test/gtest-typed-test2_test.cc" -#include "test/gtest_unittest.cc" -#include "test/production.cc" +#include "gtest-filepath_test.cc" +#include "gtest-linked_ptr_test.cc" +#include "gtest-message_test.cc" +#include "gtest-options_test.cc" +#include "gtest-port_test.cc" +#include "gtest_pred_impl_unittest.cc" +#include "gtest_prod_test.cc" +#include "gtest-test-part_test.cc" +#include "gtest-typed-test_test.cc" +#include "gtest-typed-test2_test.cc" +#include "gtest_unittest.cc" +#include "production.cc" -- cgit v0.12 From 09581b38523a0598d645fb801c31c9baead5d36f Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 13 Feb 2018 14:56:05 -0500 Subject: cleanup/merges --- googletest/include/gtest/gtest-printers.h | 2 +- googletest/include/gtest/gtest_prod.h | 11 +++++++---- googletest/src/gtest-internal-inl.h | 4 ++-- googletest/src/gtest-port.cc | 8 ++++++-- googletest/src/gtest-typed-test.cc | 1 + googletest/src/gtest.cc | 28 ++++++++++++---------------- googletest/test/gtest_env_var_test_.cc | 1 + googletest/test/gtest_main_unittest.cc | 4 ++-- googletest/test/gtest_uninitialized_test_.cc | 2 +- 9 files changed, 33 insertions(+), 28 deletions(-) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 4deaad0..2c83c3f 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -112,8 +112,8 @@ #endif #if GTEST_HAS_ABSL -#include "absl/types/optional.h" #include "absl/strings/string_view.h" +#include "absl/types/optional.h" #endif // GTEST_HAS_ABSL namespace testing { diff --git a/googletest/include/gtest/gtest_prod.h b/googletest/include/gtest/gtest_prod.h index da80ddc..d9ea685 100644 --- a/googletest/include/gtest/gtest_prod.h +++ b/googletest/include/gtest/gtest_prod.h @@ -40,17 +40,20 @@ // // class MyClass { // private: -// void MyMethod(); -// FRIEND_TEST(MyClassTest, MyMethod); +// void PrivateMethod(); +// FRIEND_TEST(MyClassTest, PrivateMethodWorks); // }; // // class MyClassTest : public testing::Test { // // ... // }; // -// TEST_F(MyClassTest, MyMethod) { -// // Can call MyClass::MyMethod() here. +// TEST_F(MyClassTest, PrivateMethodWorks) { +// // Can call MyClass::PrivateMethod() here. // } +// +// Note: The test class must be in the same namespace as the class being tested. +// For example, putting MyClassTest in an anonymous namespace will not work. #define FRIEND_TEST(test_case_name, test_name)\ friend class test_case_name##_##test_name##_Test diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h index 099761a..e77c8b6 100644 --- a/googletest/src/gtest-internal-inl.h +++ b/googletest/src/gtest-internal-inl.h @@ -59,7 +59,7 @@ # include // NOLINT #endif // GTEST_OS_WINDOWS -#include "gtest/gtest.h" // NOLINT +#include "gtest/gtest.h" #include "gtest/gtest-spi.h" namespace testing { @@ -1024,7 +1024,7 @@ class TestResultAccessor { #if GTEST_CAN_STREAM_RESULTS_ // Streams test results to the given port on the given host machine. -class GTEST_API_ StreamingListener : public EmptyTestEventListener { +class StreamingListener : public EmptyTestEventListener { public: // Abstract base class for writing strings to a socket. class AbstractSocketWriter { diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index 01711fd..af0d120 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -915,6 +915,7 @@ GTestLog::~GTestLog() { posix::Abort(); } } + // Disable Microsoft deprecation warnings for POSIX functions called from // this class (creat, dup, dup2, and close) GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996) @@ -1007,8 +1008,7 @@ static CapturedStream* g_captured_stderr = NULL; static CapturedStream* g_captured_stdout = NULL; // Starts capturing an output stream (stdout/stderr). -static void CaptureStream(int fd, - const char* stream_name, +static void CaptureStream(int fd, const char* stream_name, CapturedStream** stream) { if (*stream != NULL) { GTEST_LOG_(FATAL) << "Only one " << stream_name @@ -1049,6 +1049,10 @@ std::string GetCapturedStderr() { #endif // GTEST_HAS_STREAM_REDIRECTION + + + + size_t GetFileSize(FILE* file) { fseek(file, 0, SEEK_END); return static_cast(ftell(file)); diff --git a/googletest/src/gtest-typed-test.cc b/googletest/src/gtest-typed-test.cc index df1eef4..b358243 100644 --- a/googletest/src/gtest-typed-test.cc +++ b/googletest/src/gtest-typed-test.cc @@ -30,6 +30,7 @@ // Author: wan@google.com (Zhanyong Wan) #include "gtest/gtest-typed-test.h" + #include "gtest/gtest.h" namespace testing { diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index ada5849..7afa5a9 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -2571,12 +2571,10 @@ void ReportInvalidTestCaseType(const char* test_case_name, << "probably rename one of the classes to put the tests into different\n" << "test cases."; - GTEST_LOG_(ERROR) - << FormatFileLocation(code_location.file.c_str(), - code_location.line) - << " " << errors.GetString(); + GTEST_LOG_(ERROR) << FormatFileLocation(code_location.file.c_str(), + code_location.line) + << " " << errors.GetString(); } - } // namespace internal namespace { @@ -2898,7 +2896,7 @@ static int GetBitOffset(WORD color_mask) { if (color_mask == 0) return 0; int bitOffset = 0; - while((color_mask & 1) == 0) { + while ((color_mask & 1) == 0) { color_mask >>= 1; ++bitOffset; } @@ -3106,7 +3104,6 @@ void PrettyUnitTestResultPrinter::OnTestIterationStart( "Note: Randomizing tests' orders with a seed of %d .\n", unit_test.random_seed()); } - ColoredPrintf(COLOR_GREEN, "[==========] "); printf("Running %s from %s.\n", FormatTestCount(unit_test.test_to_run_count()).c_str(), @@ -3473,8 +3470,8 @@ void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test, // 3. To interpret the meaning of errno in a thread-safe way, // we need the strerror_r() function, which is not available on // Windows. - GTEST_LOG_(FATAL) << "Unable to open file \"" - << output_file_ << "\""; + + GTEST_LOG_(FATAL) << "Unable to open file \"" << output_file_ << "\""; } std::stringstream stream; PrintXmlUnitTest(&stream, unit_test); @@ -3773,6 +3770,7 @@ std::string XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes( // End XmlUnitTestResultPrinter + #if GTEST_CAN_STREAM_RESULTS_ // Checks if str contains '=', '&', '%' or '\n' characters. If yes, @@ -4401,8 +4399,7 @@ void UnitTestImpl::ConfigureXmlOutput() { UnitTestOptions::GetAbsolutePathToOutputFile().c_str())); } else if (output_format != "") { GTEST_LOG_(WARNING) << "WARNING: unrecognized output format \"" - << output_format - << "\" ignored."; + << output_format << "\" ignored."; } } @@ -4417,8 +4414,7 @@ void UnitTestImpl::ConfigureStreamingOutput() { listeners()->Append(new StreamingListener(target.substr(0, pos), target.substr(pos+1))); } else { - GTEST_LOG_(WARNING) << "unrecognized streaming target \"" - << target + GTEST_LOG_(WARNING) << "unrecognized streaming target \"" << target << "\" ignored."; } } @@ -5255,8 +5251,7 @@ static bool ParseGoogleTestFlag(const char* const arg) { static void LoadFlagsFromFile(const std::string& path) { FILE* flagfile = posix::FOpen(path.c_str(), "r"); if (!flagfile) { - GTEST_LOG_(FATAL) << "Unable to open file \"" - << GTEST_FLAG(flagfile) + GTEST_LOG_(FATAL) << "Unable to open file \"" << GTEST_FLAG(flagfile) << "\""; } std::string contents(ReadEntireFile(flagfile)); @@ -5387,8 +5382,9 @@ void InitGoogleTest(int* argc, wchar_t** argv) { std::string TempDir() { #if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_) - return GTEST_CUSTOM_TEMPDIR_FUNCTION_(); + return GTEST_CUSTOM_TEMPDIR_FUNCTION_(); #endif + #if GTEST_OS_WINDOWS_MOBILE return "\\temp\\"; #elif GTEST_OS_WINDOWS diff --git a/googletest/test/gtest_env_var_test_.cc b/googletest/test/gtest_env_var_test_.cc index ed62372..9b668dc 100644 --- a/googletest/test/gtest_env_var_test_.cc +++ b/googletest/test/gtest_env_var_test_.cc @@ -35,6 +35,7 @@ #include "gtest/gtest.h" #include + #include "src/gtest-internal-inl.h" using ::std::cout; diff --git a/googletest/test/gtest_main_unittest.cc b/googletest/test/gtest_main_unittest.cc index ecd9bb8..c979fce 100644 --- a/googletest/test/gtest_main_unittest.cc +++ b/googletest/test/gtest_main_unittest.cc @@ -41,5 +41,5 @@ TEST(GTestMainTest, ShouldSucceed) { } // namespace -// We are using the main() function defined in src/gtest_main.cc, so -// we don't define it here. +// We are using the main() function defined in gtest_main.cc, so we +// don't define it here. diff --git a/googletest/test/gtest_uninitialized_test_.cc b/googletest/test/gtest_uninitialized_test_.cc index 502b0ad..2ba0e8b 100644 --- a/googletest/test/gtest_uninitialized_test_.cc +++ b/googletest/test/gtest_uninitialized_test_.cc @@ -34,7 +34,7 @@ TEST(DummyTest, Dummy) { // This test doesn't verify anything. We just need it to create a // realistic stage for testing the behavior of Google Test when - // RUN_ALL_TESTS() is called without + // RUN_ALL_TESTS() is called without // testing::InitGoogleTest() being called first. } -- cgit v0.12 From a3e322b24f9a9b728004823cd43c0405ffe8bd7a Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 13 Feb 2018 15:25:57 -0500 Subject: cleanup, merges --- googletest/include/gtest/internal/gtest-filepath.h | 2 +- googletest/include/gtest/internal/gtest-internal.h | 25 ---------------- googletest/include/gtest/internal/gtest-port.h | 33 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-filepath.h b/googletest/include/gtest/internal/gtest-filepath.h index bce50dc..406597a 100644 --- a/googletest/include/gtest/internal/gtest-filepath.h +++ b/googletest/include/gtest/internal/gtest-filepath.h @@ -191,7 +191,7 @@ class GTEST_API_ FilePath { void Normalize(); - // Returns a pointer to the last ioccurrence of a valid path separator in + // Returns a pointer to the last occurence of a valid path separator in // the FilePath. On Windows, for example, both '/' and '\' are valid path // separators. Returns NULL if no path separator was found. const char* FindLastPathSeparator() const; diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 843058f..a8a9a8c 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -803,31 +803,6 @@ struct RemoveConst { #define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \ GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T)) -// Adds reference to a type if it is not a reference type, -// otherwise leaves it unchanged. This is the same as -// tr1::add_reference, which is not widely available yet. -template -struct AddReference { typedef T& type; }; // NOLINT -template -struct AddReference { typedef T& type; }; // NOLINT - -// A handy wrapper around AddReference that works when the argument T -// depends on template parameters. -#define GTEST_ADD_REFERENCE_(T) \ - typename ::testing::internal::AddReference::type - -// Adds a reference to const on top of T as necessary. For example, -// it transforms -// -// char ==> const char& -// const char ==> const char& -// char& ==> const char& -// const char& ==> const char& -// -// The argument T must depend on some template parameters. -#define GTEST_REFERENCE_TO_CONST_(T) \ - GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T)) - // ImplicitlyConvertible::value is a compile-time bool // constant that's true iff type From can be implicitly converted to // type To. diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index c541693..81f047b 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -1366,6 +1366,39 @@ inline void FlushInfoLog() { fflush(NULL); } GTEST_LOG_(FATAL) << #posix_call << "failed with error " \ << gtest_error +// Adds reference to a type if it is not a reference type, +// otherwise leaves it unchanged. This is the same as +// tr1::add_reference, which is not widely available yet. +template +struct AddReference { typedef T& type; }; // NOLINT +template +struct AddReference { typedef T& type; }; // NOLINT + +// A handy wrapper around AddReference that works when the argument T +// depends on template parameters. +#define GTEST_ADD_REFERENCE_(T) \ + typename ::testing::internal::AddReference::type + +// Transforms "T" into "const T&" according to standard reference collapsing +// rules (this is only needed as a backport for C++98 compilers that do not +// support reference collapsing). Specifically, it transforms: +// +// char ==> const char& +// const char ==> const char& +// char& ==> char& +// const char& ==> const char& +// +// Note that the non-const reference will not have "const" added. This is +// standard, and necessary so that "T" can always bind to "const T&". +template +struct ConstRef { typedef const T& type; }; +template +struct ConstRef { typedef T& type; }; + +// The argument T must depend on some template parameters. +#define GTEST_REFERENCE_TO_CONST_(T) \ + typename ::testing::internal::ConstRef::type + #if GTEST_HAS_STD_MOVE_ using std::forward; using std::move; -- cgit v0.12 From 8a6158717bc1587a26e6134179eb9e2a9f1c2185 Mon Sep 17 00:00:00 2001 From: Victor Costan Date: Mon, 19 Feb 2018 01:56:53 -0800 Subject: Fix unused function warning on Mac OS. As of recently, Google Test fails to compile with the warning below when used in projects with strict warning settings. googletest/src/gtest-death-test.cc:1004:13: error: unused function 'StackGrowsDown' [-Werror,-Wunused-function] --- googletest/src/gtest-death-test.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index 92a2980..852912b 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -983,6 +983,7 @@ static int ExecDeathTestChildMain(void* child_arg) { } # endif // !GTEST_OS_QNX +# if GTEST_HAS_CLONE // Two utility routines that together determine the direction the stack // grows. // This could be accomplished more elegantly by a single recursive @@ -1007,6 +1008,7 @@ static bool StackGrowsDown() { StackLowerThanAddress(&dummy, &result); return result; } +# endif // GTEST_HAS_CLONE // Spawns a child process with the same executable as the current process in // a thread-safe manner and instructs it to run the death test. The -- cgit v0.12 From df65632489dcc9ccef50bacd0dfdb0555d0698be Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 22 Feb 2018 15:53:14 -0500 Subject: merges --- googletest/test/BUILD.bazel | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/googletest/test/BUILD.bazel b/googletest/test/BUILD.bazel index 1b81133..6ea18ec 100644 --- a/googletest/test/BUILD.bazel +++ b/googletest/test/BUILD.bazel @@ -119,6 +119,16 @@ cc_test( "//:gtest", ], ) + +cc_test( + name = "gtest_unittest", + size = "small", + srcs = ["gtest_unittest.cc"], + args = ["--heap_check=strict"], + shard_count = 2, + deps = ["//:gtest_main"], +) + # Py tests py_library( -- cgit v0.12 From 06568301ec4adcdce318e4cf717e075c48fc05a5 Mon Sep 17 00:00:00 2001 From: Aleksey Kozin Date: Fri, 23 Feb 2018 01:34:26 +0300 Subject: TEST() arguments are invalid in an example Both names must be valid C++ identifiers, and they should not contain underscore (`_`) --- 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 384d4d6..5e8ee0c 100644 --- a/googletest/docs/Primer.md +++ b/googletest/docs/Primer.md @@ -239,7 +239,7 @@ To create a test: 1. The test's result is determined by the assertions; if any assertion in the test fails (either fatally or non-fatally), or if the test crashes, the entire test fails. Otherwise, it succeeds. ``` -TEST(test_case_name, test_name) { +TEST(testCaseName, testName) { ... test body ... } ``` -- cgit v0.12 From 11e1dd257b805d2cddfbe03bd8de213fb23a4aae Mon Sep 17 00:00:00 2001 From: "Anders Sundman (asum)" Date: Fri, 23 Feb 2018 14:55:24 +0100 Subject: Removed trailing comma in enum --- googletest/include/gtest/internal/gtest-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index a8a9a8c..db5a4ef 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -1050,7 +1050,7 @@ class NativeArray { private: enum { kCheckTypeIsNotConstOrAReference = StaticAssertTypeEqHelper< - Element, GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>::value, + Element, GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>::value }; // Initializes this object with a copy of the input. -- cgit v0.12 From b7e0294c5133a2d5c52a740375a05c7e5e0878fb Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 23 Feb 2018 10:47:11 -0500 Subject: merging unitests --- googletest/test/gtest_unittest.cc | 125 +++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 62 deletions(-) diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 2ea3ca4..a5743fc 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -5454,7 +5454,8 @@ TEST_F(SetUpTestCaseTest, Test2) { EXPECT_STREQ("123", shared_resource_); } -// The InitGoogleTestTest test case tests testing::InitGoogleTest(). + +// The ParseFlagsTest test case tests ParseGoogleTestFlagsOnly. // The Flags struct stores a copy of all Google Test flags. struct Flags { @@ -5540,8 +5541,8 @@ struct Flags { return flags; } - // Creates a Flags struct where the gtest_random_seed flag has - // the given value. + // Creates a Flags struct where the gtest_random_seed flag has the given + // value. static Flags RandomSeed(Int32 random_seed) { Flags flags; flags.random_seed = random_seed; @@ -5556,8 +5557,8 @@ struct Flags { return flags; } - // Creates a Flags struct where the gtest_shuffle flag has - // the given value. + // Creates a Flags struct where the gtest_shuffle flag has the given + // value. static Flags Shuffle(bool shuffle) { Flags flags; flags.shuffle = shuffle; @@ -5605,8 +5606,8 @@ struct Flags { bool throw_on_failure; }; -// Fixture for testing InitGoogleTest(). -class InitGoogleTestTest : public Test { +// Fixture for testing ParseGoogleTestFlagsOnly(). +class ParseFlagsTest : public Test { protected: // Clears the flags before each test. virtual void SetUp() { @@ -5667,16 +5668,16 @@ class InitGoogleTestTest : public Test { const bool saved_help_flag = ::testing::internal::g_help_flag; ::testing::internal::g_help_flag = false; -#if GTEST_HAS_STREAM_REDIRECTION +# if GTEST_HAS_STREAM_REDIRECTION CaptureStdout(); -#endif +# endif // Parses the command line. internal::ParseGoogleTestFlagsOnly(&argc1, const_cast(argv1)); -#if GTEST_HAS_STREAM_REDIRECTION +# if GTEST_HAS_STREAM_REDIRECTION const std::string captured_stdout = GetCapturedStdout(); -#endif +# endif // Verifies the flag values. CheckFlags(expected); @@ -5689,7 +5690,7 @@ class InitGoogleTestTest : public Test { // help message for the flags it recognizes. EXPECT_EQ(should_print_help, ::testing::internal::g_help_flag); -#if GTEST_HAS_STREAM_REDIRECTION +# if GTEST_HAS_STREAM_REDIRECTION const char* const expected_help_fragment = "This program contains tests written using"; if (should_print_help) { @@ -5698,7 +5699,7 @@ class InitGoogleTestTest : public Test { EXPECT_PRED_FORMAT2(IsNotSubstring, expected_help_fragment, captured_stdout); } -#endif // GTEST_HAS_STREAM_REDIRECTION +# endif // GTEST_HAS_STREAM_REDIRECTION ::testing::internal::g_help_flag = saved_help_flag; } @@ -5706,14 +5707,14 @@ class InitGoogleTestTest : public Test { // This macro wraps TestParsingFlags s.t. the user doesn't need // to specify the array sizes. -#define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \ +# define GTEST_TEST_PARSING_FLAGS_(argv1, argv2, expected, should_print_help) \ TestParsingFlags(sizeof(argv1)/sizeof(*argv1) - 1, argv1, \ sizeof(argv2)/sizeof(*argv2) - 1, argv2, \ expected, should_print_help) }; // Tests parsing an empty command line. -TEST_F(InitGoogleTestTest, Empty) { +TEST_F(ParseFlagsTest, Empty) { const char* argv[] = { NULL }; @@ -5726,7 +5727,7 @@ TEST_F(InitGoogleTestTest, Empty) { } // Tests parsing a command line that has no flag. -TEST_F(InitGoogleTestTest, NoFlag) { +TEST_F(ParseFlagsTest, NoFlag) { const char* argv[] = { "foo.exe", NULL @@ -5741,7 +5742,7 @@ TEST_F(InitGoogleTestTest, NoFlag) { } // Tests parsing a bad --gtest_filter flag. -TEST_F(InitGoogleTestTest, FilterBad) { +TEST_F(ParseFlagsTest, FilterBad) { const char* argv[] = { "foo.exe", "--gtest_filter", @@ -5758,7 +5759,7 @@ TEST_F(InitGoogleTestTest, FilterBad) { } // Tests parsing an empty --gtest_filter flag. -TEST_F(InitGoogleTestTest, FilterEmpty) { +TEST_F(ParseFlagsTest, FilterEmpty) { const char* argv[] = { "foo.exe", "--gtest_filter=", @@ -5774,7 +5775,7 @@ TEST_F(InitGoogleTestTest, FilterEmpty) { } // Tests parsing a non-empty --gtest_filter flag. -TEST_F(InitGoogleTestTest, FilterNonEmpty) { +TEST_F(ParseFlagsTest, FilterNonEmpty) { const char* argv[] = { "foo.exe", "--gtest_filter=abc", @@ -5790,7 +5791,7 @@ TEST_F(InitGoogleTestTest, FilterNonEmpty) { } // Tests parsing --gtest_break_on_failure. -TEST_F(InitGoogleTestTest, BreakOnFailureWithoutValue) { +TEST_F(ParseFlagsTest, BreakOnFailureWithoutValue) { const char* argv[] = { "foo.exe", "--gtest_break_on_failure", @@ -5806,7 +5807,7 @@ TEST_F(InitGoogleTestTest, BreakOnFailureWithoutValue) { } // Tests parsing --gtest_break_on_failure=0. -TEST_F(InitGoogleTestTest, BreakOnFailureFalse_0) { +TEST_F(ParseFlagsTest, BreakOnFailureFalse_0) { const char* argv[] = { "foo.exe", "--gtest_break_on_failure=0", @@ -5822,7 +5823,7 @@ TEST_F(InitGoogleTestTest, BreakOnFailureFalse_0) { } // Tests parsing --gtest_break_on_failure=f. -TEST_F(InitGoogleTestTest, BreakOnFailureFalse_f) { +TEST_F(ParseFlagsTest, BreakOnFailureFalse_f) { const char* argv[] = { "foo.exe", "--gtest_break_on_failure=f", @@ -5838,7 +5839,7 @@ TEST_F(InitGoogleTestTest, BreakOnFailureFalse_f) { } // Tests parsing --gtest_break_on_failure=F. -TEST_F(InitGoogleTestTest, BreakOnFailureFalse_F) { +TEST_F(ParseFlagsTest, BreakOnFailureFalse_F) { const char* argv[] = { "foo.exe", "--gtest_break_on_failure=F", @@ -5855,7 +5856,7 @@ TEST_F(InitGoogleTestTest, BreakOnFailureFalse_F) { // Tests parsing a --gtest_break_on_failure flag that has a "true" // definition. -TEST_F(InitGoogleTestTest, BreakOnFailureTrue) { +TEST_F(ParseFlagsTest, BreakOnFailureTrue) { const char* argv[] = { "foo.exe", "--gtest_break_on_failure=1", @@ -5871,7 +5872,7 @@ TEST_F(InitGoogleTestTest, BreakOnFailureTrue) { } // Tests parsing --gtest_catch_exceptions. -TEST_F(InitGoogleTestTest, CatchExceptions) { +TEST_F(ParseFlagsTest, CatchExceptions) { const char* argv[] = { "foo.exe", "--gtest_catch_exceptions", @@ -5887,7 +5888,7 @@ TEST_F(InitGoogleTestTest, CatchExceptions) { } // Tests parsing --gtest_death_test_use_fork. -TEST_F(InitGoogleTestTest, DeathTestUseFork) { +TEST_F(ParseFlagsTest, DeathTestUseFork) { const char* argv[] = { "foo.exe", "--gtest_death_test_use_fork", @@ -5904,7 +5905,7 @@ TEST_F(InitGoogleTestTest, DeathTestUseFork) { // Tests having the same flag twice with different values. The // expected behavior is that the one coming last takes precedence. -TEST_F(InitGoogleTestTest, DuplicatedFlags) { +TEST_F(ParseFlagsTest, DuplicatedFlags) { const char* argv[] = { "foo.exe", "--gtest_filter=a", @@ -5921,7 +5922,7 @@ TEST_F(InitGoogleTestTest, DuplicatedFlags) { } // Tests having an unrecognized flag on the command line. -TEST_F(InitGoogleTestTest, UnrecognizedFlag) { +TEST_F(ParseFlagsTest, UnrecognizedFlag) { const char* argv[] = { "foo.exe", "--gtest_break_on_failure", @@ -5943,7 +5944,7 @@ TEST_F(InitGoogleTestTest, UnrecognizedFlag) { } // Tests having a --gtest_list_tests flag -TEST_F(InitGoogleTestTest, ListTestsFlag) { +TEST_F(ParseFlagsTest, ListTestsFlag) { const char* argv[] = { "foo.exe", "--gtest_list_tests", @@ -5959,7 +5960,7 @@ TEST_F(InitGoogleTestTest, ListTestsFlag) { } // Tests having a --gtest_list_tests flag with a "true" value -TEST_F(InitGoogleTestTest, ListTestsTrue) { +TEST_F(ParseFlagsTest, ListTestsTrue) { const char* argv[] = { "foo.exe", "--gtest_list_tests=1", @@ -5975,7 +5976,7 @@ TEST_F(InitGoogleTestTest, ListTestsTrue) { } // Tests having a --gtest_list_tests flag with a "false" value -TEST_F(InitGoogleTestTest, ListTestsFalse) { +TEST_F(ParseFlagsTest, ListTestsFalse) { const char* argv[] = { "foo.exe", "--gtest_list_tests=0", @@ -5991,7 +5992,7 @@ TEST_F(InitGoogleTestTest, ListTestsFalse) { } // Tests parsing --gtest_list_tests=f. -TEST_F(InitGoogleTestTest, ListTestsFalse_f) { +TEST_F(ParseFlagsTest, ListTestsFalse_f) { const char* argv[] = { "foo.exe", "--gtest_list_tests=f", @@ -6007,7 +6008,7 @@ TEST_F(InitGoogleTestTest, ListTestsFalse_f) { } // Tests parsing --gtest_list_tests=F. -TEST_F(InitGoogleTestTest, ListTestsFalse_F) { +TEST_F(ParseFlagsTest, ListTestsFalse_F) { const char* argv[] = { "foo.exe", "--gtest_list_tests=F", @@ -6023,7 +6024,7 @@ TEST_F(InitGoogleTestTest, ListTestsFalse_F) { } // Tests parsing --gtest_output (invalid). -TEST_F(InitGoogleTestTest, OutputEmpty) { +TEST_F(ParseFlagsTest, OutputEmpty) { const char* argv[] = { "foo.exe", "--gtest_output", @@ -6040,7 +6041,7 @@ TEST_F(InitGoogleTestTest, OutputEmpty) { } // Tests parsing --gtest_output=xml -TEST_F(InitGoogleTestTest, OutputXml) { +TEST_F(ParseFlagsTest, OutputXml) { const char* argv[] = { "foo.exe", "--gtest_output=xml", @@ -6056,7 +6057,7 @@ TEST_F(InitGoogleTestTest, OutputXml) { } // Tests parsing --gtest_output=xml:file -TEST_F(InitGoogleTestTest, OutputXmlFile) { +TEST_F(ParseFlagsTest, OutputXmlFile) { const char* argv[] = { "foo.exe", "--gtest_output=xml:file", @@ -6072,7 +6073,7 @@ TEST_F(InitGoogleTestTest, OutputXmlFile) { } // Tests parsing --gtest_output=xml:directory/path/ -TEST_F(InitGoogleTestTest, OutputXmlDirectory) { +TEST_F(ParseFlagsTest, OutputXmlDirectory) { const char* argv[] = { "foo.exe", "--gtest_output=xml:directory/path/", @@ -6089,7 +6090,7 @@ TEST_F(InitGoogleTestTest, OutputXmlDirectory) { } // Tests having a --gtest_print_time flag -TEST_F(InitGoogleTestTest, PrintTimeFlag) { +TEST_F(ParseFlagsTest, PrintTimeFlag) { const char* argv[] = { "foo.exe", "--gtest_print_time", @@ -6105,7 +6106,7 @@ TEST_F(InitGoogleTestTest, PrintTimeFlag) { } // Tests having a --gtest_print_time flag with a "true" value -TEST_F(InitGoogleTestTest, PrintTimeTrue) { +TEST_F(ParseFlagsTest, PrintTimeTrue) { const char* argv[] = { "foo.exe", "--gtest_print_time=1", @@ -6121,7 +6122,7 @@ TEST_F(InitGoogleTestTest, PrintTimeTrue) { } // Tests having a --gtest_print_time flag with a "false" value -TEST_F(InitGoogleTestTest, PrintTimeFalse) { +TEST_F(ParseFlagsTest, PrintTimeFalse) { const char* argv[] = { "foo.exe", "--gtest_print_time=0", @@ -6137,7 +6138,7 @@ TEST_F(InitGoogleTestTest, PrintTimeFalse) { } // Tests parsing --gtest_print_time=f. -TEST_F(InitGoogleTestTest, PrintTimeFalse_f) { +TEST_F(ParseFlagsTest, PrintTimeFalse_f) { const char* argv[] = { "foo.exe", "--gtest_print_time=f", @@ -6153,7 +6154,7 @@ TEST_F(InitGoogleTestTest, PrintTimeFalse_f) { } // Tests parsing --gtest_print_time=F. -TEST_F(InitGoogleTestTest, PrintTimeFalse_F) { +TEST_F(ParseFlagsTest, PrintTimeFalse_F) { const char* argv[] = { "foo.exe", "--gtest_print_time=F", @@ -6169,7 +6170,7 @@ TEST_F(InitGoogleTestTest, PrintTimeFalse_F) { } // Tests parsing --gtest_random_seed=number -TEST_F(InitGoogleTestTest, RandomSeed) { +TEST_F(ParseFlagsTest, RandomSeed) { const char* argv[] = { "foo.exe", "--gtest_random_seed=1000", @@ -6185,7 +6186,7 @@ TEST_F(InitGoogleTestTest, RandomSeed) { } // Tests parsing --gtest_repeat=number -TEST_F(InitGoogleTestTest, Repeat) { +TEST_F(ParseFlagsTest, Repeat) { const char* argv[] = { "foo.exe", "--gtest_repeat=1000", @@ -6201,7 +6202,7 @@ TEST_F(InitGoogleTestTest, Repeat) { } // Tests having a --gtest_also_run_disabled_tests flag -TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsFlag) { +TEST_F(ParseFlagsTest, AlsoRunDisabledTestsFlag) { const char* argv[] = { "foo.exe", "--gtest_also_run_disabled_tests", @@ -6218,7 +6219,7 @@ TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsFlag) { } // Tests having a --gtest_also_run_disabled_tests flag with a "true" value -TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsTrue) { +TEST_F(ParseFlagsTest, AlsoRunDisabledTestsTrue) { const char* argv[] = { "foo.exe", "--gtest_also_run_disabled_tests=1", @@ -6235,7 +6236,7 @@ TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsTrue) { } // Tests having a --gtest_also_run_disabled_tests flag with a "false" value -TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsFalse) { +TEST_F(ParseFlagsTest, AlsoRunDisabledTestsFalse) { const char* argv[] = { "foo.exe", "--gtest_also_run_disabled_tests=0", @@ -6252,7 +6253,7 @@ TEST_F(InitGoogleTestTest, AlsoRunDisabledTestsFalse) { } // Tests parsing --gtest_shuffle. -TEST_F(InitGoogleTestTest, ShuffleWithoutValue) { +TEST_F(ParseFlagsTest, ShuffleWithoutValue) { const char* argv[] = { "foo.exe", "--gtest_shuffle", @@ -6268,7 +6269,7 @@ TEST_F(InitGoogleTestTest, ShuffleWithoutValue) { } // Tests parsing --gtest_shuffle=0. -TEST_F(InitGoogleTestTest, ShuffleFalse_0) { +TEST_F(ParseFlagsTest, ShuffleFalse_0) { const char* argv[] = { "foo.exe", "--gtest_shuffle=0", @@ -6283,9 +6284,8 @@ TEST_F(InitGoogleTestTest, ShuffleFalse_0) { GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Shuffle(false), false); } -// Tests parsing a --gtest_shuffle flag that has a "true" -// definition. -TEST_F(InitGoogleTestTest, ShuffleTrue) { +// Tests parsing a --gtest_shuffle flag that has a "true" definition. +TEST_F(ParseFlagsTest, ShuffleTrue) { const char* argv[] = { "foo.exe", "--gtest_shuffle=1", @@ -6301,7 +6301,7 @@ TEST_F(InitGoogleTestTest, ShuffleTrue) { } // Tests parsing --gtest_stack_trace_depth=number. -TEST_F(InitGoogleTestTest, StackTraceDepth) { +TEST_F(ParseFlagsTest, StackTraceDepth) { const char* argv[] = { "foo.exe", "--gtest_stack_trace_depth=5", @@ -6316,7 +6316,7 @@ TEST_F(InitGoogleTestTest, StackTraceDepth) { GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::StackTraceDepth(5), false); } -TEST_F(InitGoogleTestTest, StreamResultTo) { +TEST_F(ParseFlagsTest, StreamResultTo) { const char* argv[] = { "foo.exe", "--gtest_stream_result_to=localhost:1234", @@ -6333,7 +6333,7 @@ TEST_F(InitGoogleTestTest, StreamResultTo) { } // Tests parsing --gtest_throw_on_failure. -TEST_F(InitGoogleTestTest, ThrowOnFailureWithoutValue) { +TEST_F(ParseFlagsTest, ThrowOnFailureWithoutValue) { const char* argv[] = { "foo.exe", "--gtest_throw_on_failure", @@ -6349,7 +6349,7 @@ TEST_F(InitGoogleTestTest, ThrowOnFailureWithoutValue) { } // Tests parsing --gtest_throw_on_failure=0. -TEST_F(InitGoogleTestTest, ThrowOnFailureFalse_0) { +TEST_F(ParseFlagsTest, ThrowOnFailureFalse_0) { const char* argv[] = { "foo.exe", "--gtest_throw_on_failure=0", @@ -6366,7 +6366,7 @@ TEST_F(InitGoogleTestTest, ThrowOnFailureFalse_0) { // Tests parsing a --gtest_throw_on_failure flag that has a "true" // definition. -TEST_F(InitGoogleTestTest, ThrowOnFailureTrue) { +TEST_F(ParseFlagsTest, ThrowOnFailureTrue) { const char* argv[] = { "foo.exe", "--gtest_throw_on_failure=1", @@ -6381,9 +6381,9 @@ TEST_F(InitGoogleTestTest, ThrowOnFailureTrue) { GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::ThrowOnFailure(true), false); } -#if GTEST_OS_WINDOWS +# if GTEST_OS_WINDOWS // Tests parsing wide strings. -TEST_F(InitGoogleTestTest, WideStrings) { +TEST_F(ParseFlagsTest, WideStrings) { const wchar_t* argv[] = { L"foo.exe", L"--gtest_filter=Foo*", @@ -6409,10 +6409,10 @@ TEST_F(InitGoogleTestTest, WideStrings) { # endif // GTEST_OS_WINDOWS #if GTEST_USE_OWN_FLAGFILE_FLAG_ -class FlagfileTest : public InitGoogleTestTest { +class FlagfileTest : public ParseFlagsTest { public: virtual void SetUp() { - InitGoogleTestTest::SetUp(); + ParseFlagsTest::SetUp(); testdata_path_.Set(internal::FilePath( testing::TempDir() + internal::GetCurrentExecutableName().string() + @@ -6423,7 +6423,7 @@ class FlagfileTest : public InitGoogleTestTest { virtual void TearDown() { testing::internal::posix::RmDir(testdata_path_.c_str()); - InitGoogleTestTest::TearDown(); + ParseFlagsTest::TearDown(); } internal::FilePath CreateFlagfile(const char* contents) { @@ -6562,6 +6562,7 @@ TEST_F(CurrentTestInfoTest, WorksForSecondTestInATestCase) { } // namespace testing + // These two lines test that we can define tests in a namespace that // has the name "testing" and is nested in another namespace. namespace my_namespace { -- cgit v0.12 From 3299a2386cf2a26b486a0ac7a75e50a94bbd1a4b Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 23 Feb 2018 11:07:18 -0500 Subject: merging unittests - 2 --- googletest/test/gtest_unittest.cc | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index a5743fc..bf7621e 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -2088,7 +2088,7 @@ class UnitTestRecordPropertyTestEnvironment : public Environment { }; // This will test property recording outside of any test or test case. -Environment* record_property_env GTEST_ATTRIBUTE_UNUSED_ = +static Environment* record_property_env = AddGlobalTestEnvironment(new UnitTestRecordPropertyTestEnvironment); // This group of tests is for predicate assertions (ASSERT_PRED*, etc) @@ -3361,7 +3361,7 @@ class NoFatalFailureTest : public Test { void DoAssertNoFatalFailureOnFails() { ASSERT_NO_FATAL_FAILURE(Fails()); - ADD_FAILURE() << "shold not reach here."; + ADD_FAILURE() << "should not reach here."; } void DoExpectNoFatalFailureOnFails() { @@ -6893,14 +6893,6 @@ TEST(StaticAssertTypeEqTest, CompilesForEqualTypes) { StaticAssertTypeEq(); } -TEST(GetCurrentOsStackTraceExceptTopTest, ReturnsTheStackTrace) { - testing::UnitTest* const unit_test = testing::UnitTest::GetInstance(); - - // We don't have a stack walker in Google Test yet. - EXPECT_STREQ("", GetCurrentOsStackTraceExceptTop(unit_test, 0).c_str()); - EXPECT_STREQ("", GetCurrentOsStackTraceExceptTop(unit_test, 1).c_str()); -} - TEST(HasNonfatalFailureTest, ReturnsFalseWhenThereIsNoFailure) { EXPECT_FALSE(HasNonfatalFailure()); } @@ -7660,7 +7652,7 @@ TEST(NativeArrayTest, MethodsWork) { EXPECT_EQ(0, *it); ++it; EXPECT_EQ(1, *it); - ++it; + it++; EXPECT_EQ(2, *it); ++it; EXPECT_EQ(na.end(), it); -- cgit v0.12 From 29e9ca87743400382725bd475f2206ca4b6f1828 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 23 Feb 2018 11:29:35 -0500 Subject: merging unitests, check --- googletest/test/gtest_unittest.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index bf7621e..f62e5b4 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -2421,9 +2421,8 @@ TEST(StringAssertionTest, ASSERT_STREQ) { const char p2[] = "good"; ASSERT_STREQ(p1, p2); - EXPECT_FATAL_FAILURE( - ASSERT_STREQ("bad", "good"), - "Expected equality of these values:\n \"bad\"\n \"good\""); + EXPECT_FATAL_FAILURE(ASSERT_STREQ("bad", "good"), + " \"bad\"\n \"good\""); } // Tests ASSERT_STREQ with NULL arguments. @@ -3698,7 +3697,7 @@ TEST(AssertionTest, ASSERT_EQ_NULL) { // A failure. static int n = 0; EXPECT_FATAL_FAILURE(ASSERT_EQ(NULL, &n), - " &n\n Which is:"); + " &n\n Which is: 0x"); } #endif // GTEST_CAN_COMPARE_NULL -- cgit v0.12 From 004f6a00b20ef92285707702e2ab187092671c2b Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 23 Feb 2018 15:27:11 -0500 Subject: merging unitests - check 4 --- googletest/test/gtest_unittest.cc | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index f62e5b4..38ff19e 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -3697,7 +3697,7 @@ TEST(AssertionTest, ASSERT_EQ_NULL) { // A failure. static int n = 0; EXPECT_FATAL_FAILURE(ASSERT_EQ(NULL, &n), - " &n\n Which is: 0x"); + " &n\n Which is:"); } #endif // GTEST_CAN_COMPARE_NULL @@ -3812,7 +3812,7 @@ void TestEq1(int x) { // Tests calling a test subroutine that's not part of a fixture. TEST(AssertionTest, NonFixtureSubroutine) { EXPECT_FATAL_FAILURE(TestEq1(2), - "Which is: 2"); + " x\n Which is: 2"); } // An uncopyable class. @@ -3951,13 +3951,13 @@ TEST(AssertionTest, AnonymousEnum) { // ICE's in C++Builder. EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseB), - "kCaseB"); + " kCaseB\n Which is: "); EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC), - "Which is: 42"); + "\n Which is: 42"); # endif EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC), - "Which is: -1"); + "\n Which is: -1"); } #endif // !GTEST_OS_MAC && !defined(__SUNPRO_CC) @@ -4441,7 +4441,7 @@ TEST(ExpectTest, EXPECT_EQ_0) { // A failure. EXPECT_NONFATAL_FAILURE(EXPECT_EQ(0, 5.6), - "Expected equality of these values:\n 0\n 5.6"); + " 0\n 5.6"); } // Tests EXPECT_NE. @@ -4541,7 +4541,7 @@ TEST(ExpectTest, EXPECT_ANY_THROW) { TEST(ExpectTest, ExpectPrecedence) { EXPECT_EQ(1 < 2, true); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(true, true && false), - "true && false"); + " true && false\n Which is: false"); } @@ -4688,14 +4688,14 @@ TEST(EqAssertionTest, Bool) { EXPECT_FATAL_FAILURE({ bool false_value = false; ASSERT_EQ(false_value, true); - }, "Which is: false"); + }, " false_value\n Which is: false\n true"); } // Tests using int values in {EXPECT|ASSERT}_EQ. TEST(EqAssertionTest, Int) { ASSERT_EQ(32, 32); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(32, 33), - "33"); + " 32\n 33"); } // Tests using time_t values in {EXPECT|ASSERT}_EQ. @@ -4712,9 +4712,9 @@ TEST(EqAssertionTest, Char) { ASSERT_EQ('z', 'z'); const char ch = 'b'; EXPECT_NONFATAL_FAILURE(EXPECT_EQ('\0', ch), - "ch"); + " ch\n Which is: 'b'"); EXPECT_NONFATAL_FAILURE(EXPECT_EQ('a', ch), - "ch"); + " ch\n Which is: 'b'"); } // Tests using wchar_t values in {EXPECT|ASSERT}_EQ. @@ -4734,7 +4734,7 @@ TEST(EqAssertionTest, WideChar) { "wchar"); wchar = 0x8119; EXPECT_FATAL_FAILURE(ASSERT_EQ(static_cast(0x8120), wchar), - "wchar"); + " wchar\n Which is: L'"); } // Tests using ::std::string values in {EXPECT|ASSERT}_EQ. @@ -4763,8 +4763,7 @@ TEST(EqAssertionTest, StdString) { static ::std::string str3(str1); str3.at(2) = '\0'; EXPECT_FATAL_FAILURE(ASSERT_EQ(str1, str3), - " str3\n" - " Which is: \"A \\0 in the middle\""); + " str3\n Which is: \"A \\0 in the middle\""); } #if GTEST_HAS_STD_WSTRING -- cgit v0.12 From 567b40eeb15338402a204fc15362e553549aadea Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Fri, 23 Feb 2018 12:28:09 -0800 Subject: Try to handle unsigned wchar_t (arm) a bit better --- googlemock/include/gmock/internal/gmock-internal-utils.h | 2 ++ googlemock/test/gmock-actions_test.cc | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 319b389..37ceb54 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -117,9 +117,11 @@ struct LinkedPtrLessThan { // To gcc, // wchar_t == signed wchar_t != unsigned wchar_t == unsigned int #ifdef __GNUC__ +#if !defined(__WCHAR_UNSIGNED__) // signed/unsigned wchar_t are valid types. # define GMOCK_HAS_SIGNED_WCHAR_T_ 1 #endif +#endif // In what follows, we use the term "kind" to indicate whether a type // is bool, an integer type (excluding bool), a floating-point type, diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index f721839..9447c22 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -107,7 +107,11 @@ TEST(BuiltInDefaultValueTest, IsZeroForNumericTypes) { EXPECT_EQ(0, BuiltInDefaultValue::Get()); #endif #if GMOCK_WCHAR_T_IS_NATIVE_ +#if !defined(__WCHAR_UNSIGNED__) EXPECT_EQ(0, BuiltInDefaultValue::Get()); +#else + EXPECT_EQ(0U, BuiltInDefaultValue::Get()); +#endif #endif EXPECT_EQ(0U, BuiltInDefaultValue::Get()); // NOLINT EXPECT_EQ(0, BuiltInDefaultValue::Get()); // NOLINT -- cgit v0.12 From 4dbb4371741c170742b87dcec02b88e61a586888 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 26 Feb 2018 09:51:27 -0500 Subject: merging unittests - 5 --- googletest/test/gtest_unittest.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 38ff19e..11af9c9 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -4425,7 +4425,7 @@ TEST(ExpectTest, EXPECT_EQ_NULL) { // A failure. int n = 0; EXPECT_NONFATAL_FAILURE(EXPECT_EQ(NULL, &n), - "&n\n"); + " &n\n Which is:"); } #endif // GTEST_CAN_COMPARE_NULL @@ -4883,9 +4883,9 @@ TEST(EqAssertionTest, CharPointer) { ASSERT_EQ(p1, p1); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p0, p2), - "p2"); + " p2\n Which is:"); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p1, p2), - "p2"); + " p2\n Which is:"); EXPECT_FATAL_FAILURE(ASSERT_EQ(reinterpret_cast(0x1234), reinterpret_cast(0xABC0)), "ABC0"); @@ -4905,9 +4905,9 @@ TEST(EqAssertionTest, WideCharPointer) { EXPECT_EQ(p0, p0); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p0, p2), - "p2"); + " p2\n Which is:"); EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p1, p2), - "p2"); + " p2\n Which is:"); void* pv3 = (void*)0x1234; // NOLINT void* pv4 = (void*)0xABC0; // NOLINT const wchar_t* p3 = reinterpret_cast(pv3); -- cgit v0.12 From 20074be19a9c1d6568a4554da2fee3f2e3dbac09 Mon Sep 17 00:00:00 2001 From: David Neto Date: Mon, 26 Feb 2018 14:54:16 -0500 Subject: Use DEBUG_POSTFIX instead of CMAKE_DEBUG_POSTFIX CMAKE_DEBUG_POSTFIX is a global configuration parameter, and changing it pollutes the configuration space for other projects that enclose this project. DEBUG_POSTFIX is better to use since it is a target-specific poperty. Fixes #1334 Fixes #1268 --- googletest/CMakeLists.txt | 2 -- googletest/cmake/internal_utils.cmake | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index 77b55ca..5c392e2 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -27,8 +27,6 @@ option( "Build gtest with internal symbols hidden in shared libraries." OFF) -set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Generate debug library name with a postfix.") - # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build(). include(cmake/hermetic_build.cmake OPTIONAL) diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 2c97833..01f9fe5 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -158,6 +158,10 @@ function(cxx_library_with_type name type cxx_flags) set_target_properties(${name} PROPERTIES COMPILE_FLAGS "${cxx_flags}") + # Generate debug library name with a postfix. + set_target_properties(${name} + PROPERTIES + DEBUG_POSTFIX "d") if (BUILD_SHARED_LIBS OR type STREQUAL "SHARED") set_target_properties(${name} PROPERTIES -- cgit v0.12 From 84ec2e0365d791e4ebc7ec249f09078fb5ab6caa Mon Sep 17 00:00:00 2001 From: Victor Costan Date: Fri, 23 Feb 2018 14:55:25 -0800 Subject: Switch default death test style back to "fast". Google Test has recently (02/09/2018) switched the default death test style from "fast" to "threadsafe" in https://github.com/google/googletest/commit/ec7faa943d7817c81ce7bdf71a21ebc9244dc8de Threadsafe death tests have been used internally for a while, and are proven to be a better default. However, adopting this better default can be challenging for large projects with a significant investment in custom infrastructure built on top of Google Test. The same custom infrastructure can make it difficult for large projects to switch back to the old default by passing in --gtest_death_test_style=fast. For the reasons above, the default switch is considered too disruptive, and this CL reverts it. This CL also introduces the GTEST_DEFAULT_DEATH_TEST_STYLE preprocesor macro, which replaces the hard-coded default. The macro can be defined in gtest/internal/custom/gtest-port.h by projects that are ready to migrate to thread-safe death tests. --- googletest/include/gtest/internal/gtest-port.h | 10 ++++++++++ googletest/src/gtest-death-test.cc | 6 +++++- googletest/test/gtest_env_var_test.py | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 81f047b..2c819c9 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -107,6 +107,12 @@ // GTEST_CREATE_SHARED_LIBRARY // - Define to 1 when compiling Google Test itself // as a shared library. +// GTEST_DEFAULT_DEATH_TEST_STYLE +// - The default value of --gtest_death_test_style. +// The legacy default has been "fast" in the open +// source version since 2008. The recommended value +// is "threadsafe", and can be set in +// custom/gtest-port.h. // Platform-indicating macros // -------------------------- @@ -974,6 +980,10 @@ using ::std::tuple_size; # define GTEST_API_ #endif // GTEST_API_ +#ifndef GTEST_DEFAULT_DEATH_TEST_STYLE +# define GTEST_DEFAULT_DEATH_TEST_STYLE "fast" +#endif // GTEST_DEFAULT_DEATH_TEST_STYLE + #ifdef __GNUC__ // Ask the compiler to never inline a given function. # define GTEST_NO_INLINE_ __attribute__((noinline)) diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index 852912b..9ecab8f 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -73,7 +73,11 @@ namespace testing { // Constants. // The default death test style. -static const char kDefaultDeathTestStyle[] = "threadsafe"; +// +// This is defined in internal/gtest-port.h as "fast", but can be overridden by +// a definition in internal/custom/gtest-port.h. The recommended value, which is +// used internally at Google, is "threadsafe". +static const char kDefaultDeathTestStyle[] = GTEST_DEFAULT_DEATH_TEST_STYLE; GTEST_DEFINE_string_( death_test_style, diff --git a/googletest/test/gtest_env_var_test.py b/googletest/test/gtest_env_var_test.py index 2fe9cd5..7af00ce 100755 --- a/googletest/test/gtest_env_var_test.py +++ b/googletest/test/gtest_env_var_test.py @@ -92,7 +92,7 @@ class GTestEnvVarTest(gtest_test_utils.TestCase): TestFlag('print_time', '0', '1') TestFlag('repeat', '999', '1') TestFlag('throw_on_failure', '1', '0') - TestFlag('death_test_style', 'fast', 'threadsafe') + TestFlag('death_test_style', 'threadsafe', 'fast') TestFlag('catch_exceptions', '0', '1') if IS_LINUX: -- cgit v0.12 From 190e2cdd0b55d289136a177638942e1cd1b2d457 Mon Sep 17 00:00:00 2001 From: Xiaoyi Zhang Date: Tue, 27 Feb 2018 11:36:21 -0500 Subject: Add matcher for std::variant. --- googlemock/include/gmock/gmock-matchers.h | 71 +++++++++++++++++++++++++++++++ googlemock/test/gmock-matchers_test.cc | 64 ++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index fc3fe3a..85b5b13 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -3623,6 +3623,66 @@ GTEST_API_ std::string FormatMatcherDescription(bool negation, const char* matcher_name, const Strings& param_values); +namespace variant_matcher { +// Overloads to allow VariantMatcher to do proper ADL lookup. +template +void holds_alternative() {} +template +void get() {} + +// Implements a matcher that checks the value of a variant<> type variable. +template +class VariantMatcher { + public: + explicit VariantMatcher(::testing::Matcher matcher) + : matcher_(internal::move(matcher)) {} + + template + bool MatchAndExplain(const Variant& value, + ::testing::MatchResultListener* listener) const { + if (!listener->IsInterested()) { + return holds_alternative(value) && matcher_.Matches(get(value)); + } + + if (!holds_alternative(value)) { + *listener << "whose value is not of type '" << GetTypeName() << "'"; + return false; + } + + const T& elem = get(value); + StringMatchResultListener elem_listener; + const bool match = matcher_.MatchAndExplain(elem, &elem_listener); + *listener << "whose value " << PrintToString(elem) + << (match ? " matches" : " doesn't match"); + PrintIfNotEmpty(elem_listener.str(), listener->stream()); + return match; + } + + void DescribeTo(std::ostream* os) const { + *os << "is a variant<> with value of type '" << GetTypeName() + << "' and the value "; + matcher_.DescribeTo(os); + } + + void DescribeNegationTo(std::ostream* os) const { + *os << "is a variant<> with value of type other than '" << GetTypeName() + << "' or the value "; + matcher_.DescribeNegationTo(os); + } + + private: + static string GetTypeName() { +#if GTEST_HAS_RTTI + return internal::GetTypeName(); +#endif + return "the element type"; + } + + const ::testing::Matcher matcher_; +}; + +} // namespace variant_matcher + } // namespace internal // ElementsAreArray(first, last) @@ -4397,6 +4457,17 @@ inline internal::AnyOfMatcher AnyOf(const Args&... matchers) { template inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; } +// Returns a matcher that matches the value of a variant<> type variable. +// The matcher implementation uses ADL to find the holds_alternative and get +// functions. +// It is compatible with std::variant. +template +PolymorphicMatcher > VariantWith( + const Matcher& matcher) { + return MakePolymorphicMatcher( + internal::variant_matcher::VariantMatcher(matcher)); +} + // These macros allow using matchers to check values in Google Test // tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher) // succeed iff the value matches the matcher. If the assertion fails, diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 761c0c2..829935e 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -5655,5 +5655,69 @@ TEST(UnorderedPointwiseTest, AllowsMonomorphicInnerMatcher) { EXPECT_THAT(lhs, UnorderedPointwise(m2, rhs)); } +class SampleVariantIntString { + public: + SampleVariantIntString(int i) : i_(i), has_int_(true) {} + SampleVariantIntString(const std::string& s) : s_(s), has_int_(false) {} + + template + friend bool holds_alternative(const SampleVariantIntString& value) { + return value.has_int_ == internal::IsSame::value; + } + + template + friend const T& get(const SampleVariantIntString& value) { + return value.get_impl(static_cast(NULL)); + } + + private: + const int& get_impl(int*) const { return i_; } + const std::string& get_impl(std::string*) const { return s_; } + + int i_; + std::string s_; + bool has_int_; +}; + +TEST(VariantTest, DescribesSelf) { + const Matcher m = VariantWith(Eq(1)); + EXPECT_THAT(Describe(m), ContainsRegex("is a variant<> with value of type " + "'.*' and the value is equal to 1")); +} + +TEST(VariantTest, ExplainsSelf) { + const Matcher m = VariantWith(Eq(1)); + EXPECT_THAT(Explain(m, SampleVariantIntString(1)), + ContainsRegex("whose value 1")); + EXPECT_THAT(Explain(m, SampleVariantIntString("A")), + HasSubstr("whose value is not of type '")); + EXPECT_THAT(Explain(m, SampleVariantIntString(2)), + "whose value 2 doesn't match"); +} + +TEST(VariantTest, FullMatch) { + Matcher m = VariantWith(Eq(1)); + EXPECT_TRUE(m.Matches(SampleVariantIntString(1))); + + m = VariantWith(Eq("1")); + EXPECT_TRUE(m.Matches(SampleVariantIntString("1"))); +} + +TEST(VariantTest, TypeDoesNotMatch) { + Matcher m = VariantWith(Eq(1)); + EXPECT_FALSE(m.Matches(SampleVariantIntString("1"))); + + m = VariantWith(Eq("1")); + EXPECT_FALSE(m.Matches(SampleVariantIntString(1))); +} + +TEST(VariantTest, InnerDoesNotMatch) { + Matcher m = VariantWith(Eq(1)); + EXPECT_FALSE(m.Matches(SampleVariantIntString(2))); + + m = VariantWith(Eq("1")); + EXPECT_FALSE(m.Matches(SampleVariantIntString("2"))); +} + } // namespace gmock_matchers_test } // namespace testing -- cgit v0.12 From 2bd1750ba7bd23038a329ff80613b9a4e9b89497 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 27 Feb 2018 13:51:09 -0500 Subject: gmock merging -2 --- googlemock/include/gmock/gmock-matchers.h | 231 ++++++++++++++++++++++++------ googlemock/src/gmock-matchers.cc | 196 +++++++++++++++---------- googlemock/test/gmock_link_test.h | 24 +++- 3 files changed, 328 insertions(+), 123 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index fc3fe3a..3d2d617 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -514,7 +514,7 @@ template class MatcherCastImpl { public: static Matcher Cast(const M& polymorphic_matcher_or_value) { - // M can be a polymorhic matcher, in which case we want to use + // M can be a polymorphic matcher, in which case we want to use // its conversion operator to create Matcher. Or it can be a value // that should be passed to the Matcher's constructor. // @@ -3303,14 +3303,23 @@ typedef ::std::vector ElementMatcherPairs; GTEST_API_ ElementMatcherPairs FindMaxBipartiteMatching(const MatchMatrix& g); -GTEST_API_ bool FindPairing(const MatchMatrix& matrix, - MatchResultListener* listener); +struct UnorderedMatcherRequire { + enum Flags { + Superset = 1 << 0, + Subset = 1 << 1, + ExactMatch = Superset | Subset, + }; +}; // Untyped base class for implementing UnorderedElementsAre. By // putting logic that's not specific to the element type here, we // reduce binary bloat and increase compilation speed. class GTEST_API_ UnorderedElementsAreMatcherImplBase { protected: + explicit UnorderedElementsAreMatcherImplBase( + UnorderedMatcherRequire::Flags matcher_flags) + : match_flags_(matcher_flags) {} + // A vector of matcher describers, one for each element matcher. // Does not own the describers (and thus can be used only when the // element matchers are alive). @@ -3322,9 +3331,12 @@ class GTEST_API_ UnorderedElementsAreMatcherImplBase { // Describes the negation of this UnorderedElementsAre matcher. void DescribeNegationToImpl(::std::ostream* os) const; - bool VerifyAllElementsAndMatchersAreMatched( - const ::std::vector& element_printouts, - const MatchMatrix& matrix, MatchResultListener* listener) const; + bool VerifyMatchMatrix(const ::std::vector& element_printouts, + const MatchMatrix& matrix, + MatchResultListener* listener) const; + + bool FindPairing(const MatchMatrix& matrix, + MatchResultListener* listener) const; MatcherDescriberVec& matcher_describers() { return matcher_describers_; @@ -3334,13 +3346,17 @@ class GTEST_API_ UnorderedElementsAreMatcherImplBase { return Message() << n << " element" << (n == 1 ? "" : "s"); } + UnorderedMatcherRequire::Flags match_flags() const { return match_flags_; } + private: + UnorderedMatcherRequire::Flags match_flags_; MatcherDescriberVec matcher_describers_; GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImplBase); }; -// Implements unordered ElementsAre and unordered ElementsAreArray. +// Implements UnorderedElementsAre, UnorderedElementsAreArray, IsSubsetOf, and +// IsSupersetOf. template class UnorderedElementsAreMatcherImpl : public MatcherInterface, @@ -3353,10 +3369,10 @@ class UnorderedElementsAreMatcherImpl typedef typename StlContainer::const_iterator StlContainerConstIterator; typedef typename StlContainer::value_type Element; - // Constructs the matcher from a sequence of element values or - // element matchers. template - UnorderedElementsAreMatcherImpl(InputIter first, InputIter last) { + UnorderedElementsAreMatcherImpl(UnorderedMatcherRequire::Flags matcher_flags, + InputIter first, InputIter last) + : UnorderedElementsAreMatcherImplBase(matcher_flags) { for (; first != last; ++first) { matchers_.push_back(MatcherCast(*first)); matcher_describers().push_back(matchers_.back().GetDescriber()); @@ -3377,34 +3393,32 @@ class UnorderedElementsAreMatcherImpl MatchResultListener* listener) const { StlContainerReference stl_container = View::ConstReference(container); ::std::vector element_printouts; - MatchMatrix matrix = AnalyzeElements(stl_container.begin(), - stl_container.end(), - &element_printouts, - listener); + MatchMatrix matrix = + AnalyzeElements(stl_container.begin(), stl_container.end(), + &element_printouts, listener); - const size_t actual_count = matrix.LhsSize(); - if (actual_count == 0 && matchers_.empty()) { + if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) { return true; } - if (actual_count != matchers_.size()) { - // The element count doesn't match. If the container is empty, - // there's no need to explain anything as Google Mock already - // prints the empty container. Otherwise we just need to show - // how many elements there actually are. - if (actual_count != 0 && listener->IsInterested()) { - *listener << "which has " << Elements(actual_count); + + if (match_flags() == UnorderedMatcherRequire::ExactMatch) { + if (matrix.LhsSize() != matrix.RhsSize()) { + // The element count doesn't match. If the container is empty, + // there's no need to explain anything as Google Mock already + // prints the empty container. Otherwise we just need to show + // how many elements there actually are. + if (matrix.LhsSize() != 0 && listener->IsInterested()) { + *listener << "which has " << Elements(matrix.LhsSize()); + } + return false; } - return false; } - return VerifyAllElementsAndMatchersAreMatched(element_printouts, - matrix, listener) && + return VerifyMatchMatrix(element_printouts, matrix, listener) && FindPairing(matrix, listener); } private: - typedef ::std::vector > MatcherVec; - template MatchMatrix AnalyzeElements(ElementIter elem_first, ElementIter elem_last, ::std::vector* element_printouts, @@ -3431,7 +3445,7 @@ class UnorderedElementsAreMatcherImpl return matrix; } - MatcherVec matchers_; + ::std::vector > matchers_; GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImpl); }; @@ -3464,7 +3478,7 @@ class UnorderedElementsAreMatcher { TransformTupleValues(CastAndAppendTransform(), matchers_, ::std::back_inserter(matchers)); return MakeMatcher(new UnorderedElementsAreMatcherImpl( - matchers.begin(), matchers.end())); + UnorderedMatcherRequire::ExactMatch, matchers.begin(), matchers.end())); } private: @@ -3497,24 +3511,23 @@ class ElementsAreMatcher { GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher); }; -// Implements UnorderedElementsAreArray(). +// Implements UnorderedElementsAreArray(), IsSubsetOf(), and IsSupersetOf(). template class UnorderedElementsAreArrayMatcher { public: - UnorderedElementsAreArrayMatcher() {} - template - UnorderedElementsAreArrayMatcher(Iter first, Iter last) - : matchers_(first, last) {} + UnorderedElementsAreArrayMatcher(UnorderedMatcherRequire::Flags match_flags, + Iter first, Iter last) + : match_flags_(match_flags), matchers_(first, last) {} template operator Matcher() const { - return MakeMatcher( - new UnorderedElementsAreMatcherImpl(matchers_.begin(), - matchers_.end())); + return MakeMatcher(new UnorderedElementsAreMatcherImpl( + match_flags_, matchers_.begin(), matchers_.end())); } private: + UnorderedMatcherRequire::Flags match_flags_; ::std::vector matchers_; GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreArrayMatcher); @@ -3625,7 +3638,7 @@ GTEST_API_ std::string FormatMatcherDescription(bool negation, } // namespace internal -// ElementsAreArray(first, last) +// ElementsAreArray(iterator_first, iterator_last) // ElementsAreArray(pointer, count) // ElementsAreArray(array) // ElementsAreArray(container) @@ -3674,20 +3687,26 @@ ElementsAreArray(::std::initializer_list xs) { } #endif -// UnorderedElementsAreArray(first, last) +// UnorderedElementsAreArray(iterator_first, iterator_last) // UnorderedElementsAreArray(pointer, count) // UnorderedElementsAreArray(array) // UnorderedElementsAreArray(container) // UnorderedElementsAreArray({ e1, e2, ..., en }) // -// The UnorderedElementsAreArray() functions are like -// ElementsAreArray(...), but allow matching the elements in any order. +// UnorderedElementsAreArray() verifies that a bijective mapping onto a +// collection of matchers exists. +// +// The matchers can be specified as an array, a pointer and count, a container, +// an initializer list, or an STL iterator range. In each of these cases, the +// underlying matchers can be either values or matchers. + template inline internal::UnorderedElementsAreArrayMatcher< typename ::std::iterator_traits::value_type> UnorderedElementsAreArray(Iter first, Iter last) { typedef typename ::std::iterator_traits::value_type T; - return internal::UnorderedElementsAreArrayMatcher(first, last); + return internal::UnorderedElementsAreArrayMatcher( + internal::UnorderedMatcherRequire::ExactMatch, first, last); } template @@ -3729,7 +3748,9 @@ UnorderedElementsAreArray(::std::initializer_list xs) { const internal::AnythingMatcher _ = {}; // Creates a matcher that matches any value of the given type T. template -inline Matcher A() { return MakeMatcher(new internal::AnyMatcherImpl()); } +inline Matcher A() { + return Matcher(new internal::AnyMatcherImpl()); +} // Creates a matcher that matches any value of the given type T. template @@ -4299,6 +4320,128 @@ inline internal::ContainsMatcher Contains(M matcher) { return internal::ContainsMatcher(matcher); } +// IsSupersetOf(iterator_first, iterator_last) +// IsSupersetOf(pointer, count) +// IsSupersetOf(array) +// IsSupersetOf(container) +// IsSupersetOf({e1, e2, ..., en}) +// +// IsSupersetOf() verifies that a surjective partial mapping onto a collection +// of matchers exists. In other words, a container matches +// IsSupersetOf({e1, ..., en}) if and only if there is a permutation +// {y1, ..., yn} of some of the container's elements where y1 matches e1, +// ..., and yn matches en. Obviously, the size of the container must be >= n +// in order to have a match. Examples: +// +// - {1, 2, 3} matches IsSupersetOf({Ge(3), Ne(0)}), as 3 matches Ge(3) and +// 1 matches Ne(0). +// - {1, 2} doesn't match IsSupersetOf({Eq(1), Lt(2)}), even though 1 matches +// both Eq(1) and Lt(2). The reason is that different matchers must be used +// for elements in different slots of the container. +// - {1, 1, 2} matches IsSupersetOf({Eq(1), Lt(2)}), as (the first) 1 matches +// Eq(1) and (the second) 1 matches Lt(2). +// - {1, 2, 3} matches IsSupersetOf(Gt(1), Gt(1)), as 2 matches (the first) +// Gt(1) and 3 matches (the second) Gt(1). +// +// The matchers can be specified as an array, a pointer and count, a container, +// an initializer list, or an STL iterator range. In each of these cases, the +// underlying matchers can be either values or matchers. + +template +inline internal::UnorderedElementsAreArrayMatcher< + typename ::std::iterator_traits::value_type> +IsSupersetOf(Iter first, Iter last) { + typedef typename ::std::iterator_traits::value_type T; + return internal::UnorderedElementsAreArrayMatcher( + internal::UnorderedMatcherRequire::Superset, first, last); +} + +template +inline internal::UnorderedElementsAreArrayMatcher IsSupersetOf( + const T* pointer, size_t count) { + return IsSupersetOf(pointer, pointer + count); +} + +template +inline internal::UnorderedElementsAreArrayMatcher IsSupersetOf( + const T (&array)[N]) { + return IsSupersetOf(array, N); +} + +template +inline internal::UnorderedElementsAreArrayMatcher< + typename Container::value_type> +IsSupersetOf(const Container& container) { + return IsSupersetOf(container.begin(), container.end()); +} + +#if GTEST_HAS_STD_INITIALIZER_LIST_ +template +inline internal::UnorderedElementsAreArrayMatcher IsSupersetOf( + ::std::initializer_list xs) { + return IsSupersetOf(xs.begin(), xs.end()); +} +#endif + +// IsSubsetOf(iterator_first, iterator_last) +// IsSubsetOf(pointer, count) +// IsSubsetOf(array) +// IsSubsetOf(container) +// IsSubsetOf({e1, e2, ..., en}) +// +// IsSubsetOf() verifies that an injective mapping onto a collection of matchers +// exists. In other words, a container matches IsSubsetOf({e1, ..., en}) if and +// only if there is a subset of matchers {m1, ..., mk} which would match the +// container using UnorderedElementsAre. Obviously, the size of the container +// must be <= n in order to have a match. Examples: +// +// - {1} matches IsSubsetOf({Gt(0), Lt(0)}), as 1 matches Gt(0). +// - {1, -1} matches IsSubsetOf({Lt(0), Gt(0)}), as 1 matches Gt(0) and -1 +// matches Lt(0). +// - {1, 2} doesn't matches IsSubsetOf({Gt(0), Lt(0)}), even though 1 and 2 both +// match Gt(0). The reason is that different matchers must be used for +// elements in different slots of the container. +// +// The matchers can be specified as an array, a pointer and count, a container, +// an initializer list, or an STL iterator range. In each of these cases, the +// underlying matchers can be either values or matchers. + +template +inline internal::UnorderedElementsAreArrayMatcher< + typename ::std::iterator_traits::value_type> +IsSubsetOf(Iter first, Iter last) { + typedef typename ::std::iterator_traits::value_type T; + return internal::UnorderedElementsAreArrayMatcher( + internal::UnorderedMatcherRequire::Subset, first, last); +} + +template +inline internal::UnorderedElementsAreArrayMatcher IsSubsetOf( + const T* pointer, size_t count) { + return IsSubsetOf(pointer, pointer + count); +} + +template +inline internal::UnorderedElementsAreArrayMatcher IsSubsetOf( + const T (&array)[N]) { + return IsSubsetOf(array, N); +} + +template +inline internal::UnorderedElementsAreArrayMatcher< + typename Container::value_type> +IsSubsetOf(const Container& container) { + return IsSubsetOf(container.begin(), container.end()); +} + +#if GTEST_HAS_STD_INITIALIZER_LIST_ +template +inline internal::UnorderedElementsAreArrayMatcher IsSubsetOf( + ::std::initializer_list xs) { + return IsSubsetOf(xs.begin(), xs.end()); +} +#endif + // Matches an STL-style container or a native array that contains only // elements matching the given value or matcher. // diff --git a/googlemock/src/gmock-matchers.cc b/googlemock/src/gmock-matchers.cc index f37d5c2..88e4008 100644 --- a/googlemock/src/gmock-matchers.cc +++ b/googlemock/src/gmock-matchers.cc @@ -38,6 +38,7 @@ #include "gmock/gmock-generated-matchers.h" #include +#include #include #include @@ -181,8 +182,7 @@ class MaxBipartiteMatchState { explicit MaxBipartiteMatchState(const MatchMatrix& graph) : graph_(&graph), left_(graph_->LhsSize(), kUnused), - right_(graph_->RhsSize(), kUnused) { - } + right_(graph_->RhsSize(), kUnused) {} // Returns the edges of a maximal match, each in the form {left, right}. ElementMatcherPairs Compute() { @@ -239,10 +239,8 @@ class MaxBipartiteMatchState { // bool TryAugment(size_t ilhs, ::std::vector* seen) { for (size_t irhs = 0; irhs < graph_->RhsSize(); ++irhs) { - if ((*seen)[irhs]) - continue; - if (!graph_->HasEdge(ilhs, irhs)) - continue; + if ((*seen)[irhs]) continue; + if (!graph_->HasEdge(ilhs, irhs)) continue; // There's an available edge from ilhs to irhs. (*seen)[irhs] = 1; // Next a search is performed to determine whether @@ -285,8 +283,7 @@ class MaxBipartiteMatchState { const size_t MaxBipartiteMatchState::kUnused; -GTEST_API_ ElementMatcherPairs -FindMaxBipartiteMatching(const MatchMatrix& g) { +GTEST_API_ ElementMatcherPairs FindMaxBipartiteMatching(const MatchMatrix& g) { return MaxBipartiteMatchState(g).Compute(); } @@ -295,7 +292,7 @@ static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs, typedef ElementMatcherPairs::const_iterator Iter; ::std::ostream& os = *stream; os << "{"; - const char *sep = ""; + const char* sep = ""; for (Iter it = pairs.begin(); it != pairs.end(); ++it) { os << sep << "\n (" << "element #" << it->first << ", " @@ -305,38 +302,6 @@ static void LogElementMatcherPairVec(const ElementMatcherPairs& pairs, os << "\n}"; } -// Tries to find a pairing, and explains the result. -GTEST_API_ bool FindPairing(const MatchMatrix& matrix, - MatchResultListener* listener) { - ElementMatcherPairs matches = FindMaxBipartiteMatching(matrix); - - size_t max_flow = matches.size(); - bool result = (max_flow == matrix.RhsSize()); - - if (!result) { - if (listener->IsInterested()) { - *listener << "where no permutation of the elements can " - "satisfy all matchers, and the closest match is " - << max_flow << " of " << matrix.RhsSize() - << " matchers with the pairings:\n"; - LogElementMatcherPairVec(matches, listener->stream()); - } - return false; - } - - if (matches.size() > 1) { - if (listener->IsInterested()) { - const char *sep = "where:\n"; - for (size_t mi = 0; mi < matches.size(); ++mi) { - *listener << sep << " - element #" << matches[mi].first - << " is matched by matcher #" << matches[mi].second; - sep = ",\n"; - } - } - } - return true; -} - bool MatchMatrix::NextGraph() { for (size_t ilhs = 0; ilhs < LhsSize(); ++ilhs) { for (size_t irhs = 0; irhs < RhsSize(); ++irhs) { @@ -362,7 +327,7 @@ void MatchMatrix::Randomize() { std::string MatchMatrix::DebugString() const { ::std::stringstream ss; - const char *sep = ""; + const char* sep = ""; for (size_t i = 0; i < LhsSize(); ++i) { ss << sep; for (size_t j = 0; j < RhsSize(); ++j) { @@ -375,44 +340,83 @@ std::string MatchMatrix::DebugString() const { void UnorderedElementsAreMatcherImplBase::DescribeToImpl( ::std::ostream* os) const { - if (matcher_describers_.empty()) { - *os << "is empty"; - return; - } - if (matcher_describers_.size() == 1) { - *os << "has " << Elements(1) << " and that element "; - matcher_describers_[0]->DescribeTo(os); - return; + switch (match_flags()) { + case UnorderedMatcherRequire::ExactMatch: + if (matcher_describers_.empty()) { + *os << "is empty"; + return; + } + if (matcher_describers_.size() == 1) { + *os << "has " << Elements(1) << " and that element "; + matcher_describers_[0]->DescribeTo(os); + return; + } + *os << "has " << Elements(matcher_describers_.size()) + << " and there exists some permutation of elements such that:\n"; + break; + case UnorderedMatcherRequire::Superset: + *os << "a surjection from elements to requirements exists such that:\n"; + break; + case UnorderedMatcherRequire::Subset: + *os << "an injection from elements to requirements exists such that:\n"; + break; } - *os << "has " << Elements(matcher_describers_.size()) - << " and there exists some permutation of elements such that:\n"; + const char* sep = ""; for (size_t i = 0; i != matcher_describers_.size(); ++i) { - *os << sep << " - element #" << i << " "; + *os << sep; + if (match_flags() == UnorderedMatcherRequire::ExactMatch) { + *os << " - element #" << i << " "; + } else { + *os << " - an element "; + } matcher_describers_[i]->DescribeTo(os); - sep = ", and\n"; + if (match_flags() == UnorderedMatcherRequire::ExactMatch) { + sep = ", and\n"; + } else { + sep = "\n"; + } } } void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl( ::std::ostream* os) const { - if (matcher_describers_.empty()) { - *os << "isn't empty"; - return; - } - if (matcher_describers_.size() == 1) { - *os << "doesn't have " << Elements(1) - << ", or has " << Elements(1) << " that "; - matcher_describers_[0]->DescribeNegationTo(os); - return; + switch (match_flags()) { + case UnorderedMatcherRequire::ExactMatch: + if (matcher_describers_.empty()) { + *os << "isn't empty"; + return; + } + if (matcher_describers_.size() == 1) { + *os << "doesn't have " << Elements(1) << ", or has " << Elements(1) + << " that "; + matcher_describers_[0]->DescribeNegationTo(os); + return; + } + *os << "doesn't have " << Elements(matcher_describers_.size()) + << ", or there exists no permutation of elements such that:\n"; + break; + case UnorderedMatcherRequire::Superset: + *os << "no surjection from elements to requirements exists such that:\n"; + break; + case UnorderedMatcherRequire::Subset: + *os << "no injection from elements to requirements exists such that:\n"; + break; } - *os << "doesn't have " << Elements(matcher_describers_.size()) - << ", or there exists no permutation of elements such that:\n"; const char* sep = ""; for (size_t i = 0; i != matcher_describers_.size(); ++i) { - *os << sep << " - element #" << i << " "; + *os << sep; + if (match_flags() == UnorderedMatcherRequire::ExactMatch) { + *os << " - element #" << i << " "; + } else { + *os << " - an element "; + } matcher_describers_[i]->DescribeTo(os); - sep = ", and\n"; + if (match_flags() == UnorderedMatcherRequire::ExactMatch) { + sep = ", and\n"; + } else { + sep = "\n"; + } } } @@ -421,10 +425,9 @@ void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl( // and better error reporting. // Returns false, writing an explanation to 'listener', if and only // if the success criteria are not met. -bool UnorderedElementsAreMatcherImplBase:: - VerifyAllElementsAndMatchersAreMatched( - const ::std::vector& element_printouts, - const MatchMatrix& matrix, MatchResultListener* listener) const { +bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix( + const ::std::vector& element_printouts, + const MatchMatrix& matrix, MatchResultListener* listener) const { bool result = true; ::std::vector element_matched(matrix.LhsSize(), 0); ::std::vector matcher_matched(matrix.RhsSize(), 0); @@ -437,12 +440,11 @@ bool UnorderedElementsAreMatcherImplBase:: } } - { + if (match_flags() & UnorderedMatcherRequire::Superset) { const char* sep = "where the following matchers don't match any elements:\n"; for (size_t mi = 0; mi < matcher_matched.size(); ++mi) { - if (matcher_matched[mi]) - continue; + if (matcher_matched[mi]) continue; result = false; if (listener->IsInterested()) { *listener << sep << "matcher #" << mi << ": "; @@ -452,7 +454,7 @@ bool UnorderedElementsAreMatcherImplBase:: } } - { + if (match_flags() & UnorderedMatcherRequire::Subset) { const char* sep = "where the following elements don't match any matchers:\n"; const char* outer_sep = ""; @@ -460,8 +462,7 @@ bool UnorderedElementsAreMatcherImplBase:: outer_sep = "\nand "; } for (size_t ei = 0; ei < element_matched.size(); ++ei) { - if (element_matched[ei]) - continue; + if (element_matched[ei]) continue; result = false; if (listener->IsInterested()) { *listener << outer_sep << sep << "element #" << ei << ": " @@ -474,5 +475,46 @@ bool UnorderedElementsAreMatcherImplBase:: return result; } +bool UnorderedElementsAreMatcherImplBase::FindPairing( + const MatchMatrix& matrix, MatchResultListener* listener) const { + ElementMatcherPairs matches = FindMaxBipartiteMatching(matrix); + + size_t max_flow = matches.size(); + if ((match_flags() & UnorderedMatcherRequire::Superset) && + max_flow < matrix.RhsSize()) { + if (listener->IsInterested()) { + *listener << "where no permutation of the elements can satisfy all " + "matchers, and the closest match is " + << max_flow << " of " << matrix.RhsSize() + << " matchers with the pairings:\n"; + LogElementMatcherPairVec(matches, listener->stream()); + } + return false; + } + if ((match_flags() & UnorderedMatcherRequire::Subset) && + max_flow < matrix.LhsSize()) { + if (listener->IsInterested()) { + *listener + << "where not all elements can be matched, and the closest match is " + << max_flow << " of " << matrix.RhsSize() + << " matchers with the pairings:\n"; + LogElementMatcherPairVec(matches, listener->stream()); + } + return false; + } + + if (matches.size() > 1) { + if (listener->IsInterested()) { + const char* sep = "where:\n"; + for (size_t mi = 0; mi < matches.size(); ++mi) { + *listener << sep << " - element #" << matches[mi].first + << " is matched by matcher #" << matches[mi].second; + sep = ",\n"; + } + } + } + return true; +} + } // namespace internal } // namespace testing diff --git a/googlemock/test/gmock_link_test.h b/googlemock/test/gmock_link_test.h index 1f55f5b..5f855d1 100644 --- a/googlemock/test/gmock_link_test.h +++ b/googlemock/test/gmock_link_test.h @@ -120,13 +120,15 @@ # include #endif -#include "gmock/internal/gmock-port.h" -#include "gtest/gtest.h" #include #include +#include "gtest/gtest.h" +#include "gtest/internal/gtest-port.h" + using testing::_; using testing::A; +using testing::Action; using testing::AllOf; using testing::AnyOf; using testing::Assign; @@ -148,6 +150,8 @@ using testing::Invoke; using testing::InvokeArgument; using testing::InvokeWithoutArgs; using testing::IsNull; +using testing::IsSubsetOf; +using testing::IsSupersetOf; using testing::Le; using testing::Lt; using testing::Matcher; @@ -592,6 +596,22 @@ TEST(LinkTest, TestMatcherElementsAreArray) { ON_CALL(mock, VoidFromVector(ElementsAreArray(arr))).WillByDefault(Return()); } +// Tests the linkage of the IsSubsetOf matcher. +TEST(LinkTest, TestMatcherIsSubsetOf) { + Mock mock; + char arr[] = {'a', 'b'}; + + ON_CALL(mock, VoidFromVector(IsSubsetOf(arr))).WillByDefault(Return()); +} + +// Tests the linkage of the IsSupersetOf matcher. +TEST(LinkTest, TestMatcherIsSupersetOf) { + Mock mock; + char arr[] = {'a', 'b'}; + + ON_CALL(mock, VoidFromVector(IsSupersetOf(arr))).WillByDefault(Return()); +} + // Tests the linkage of the ContainerEq matcher. TEST(LinkTest, TestMatcherContainerEq) { Mock mock; -- cgit v0.12 From 2eb31c185cfd6c8ae84dd6cad5bc6668901544a8 Mon Sep 17 00:00:00 2001 From: Xiaoyi Zhang Date: Tue, 27 Feb 2018 16:00:42 -0500 Subject: Add documentation for VariantWith. --- googlemock/docs/CheatSheet.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/googlemock/docs/CheatSheet.md b/googlemock/docs/CheatSheet.md index c6367fd..f8bbbfe 100644 --- a/googlemock/docs/CheatSheet.md +++ b/googlemock/docs/CheatSheet.md @@ -178,6 +178,8 @@ divided into several categories: |`Ne(value)` |`argument != value`| |`IsNull()` |`argument` is a `NULL` pointer (raw or smart).| |`NotNull()` |`argument` is a non-null pointer (raw or smart).| +|`VariantWith(m)` |`argument` is `variant<>` that holds the alternative of +type T with a value matching `m`.| |`Ref(variable)` |`argument` is a reference to `variable`.| |`TypedEq(value)`|`argument` has type `type` and is equal to `value`. You may need to use this instead of `Eq(value)` when the mock function is overloaded.| -- cgit v0.12 From 6baf17e9d111a444543e79e4293f75a8d5ae24c6 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Mon, 26 Feb 2018 01:15:50 -0800 Subject: Support JSON output format in addition to XML This change allows emitting output in JSON format in addition to the already supported XML format. The implementation as well as the file structure is intentionally modelled after the XML one. --- googletest/CMakeLists.txt | 2 + googletest/docs/AdvancedGuide.md | 201 +++++++++ googletest/src/gtest.cc | 375 +++++++++++++++- googletest/test/gtest_json_outfiles_test.py | 163 +++++++ googletest/test/gtest_json_output_unittest.py | 612 ++++++++++++++++++++++++++ googletest/test/gtest_json_test_utils.py | 60 +++ 6 files changed, 1403 insertions(+), 10 deletions(-) create mode 100644 googletest/test/gtest_json_outfiles_test.py create mode 100644 googletest/test/gtest_json_output_unittest.py create mode 100644 googletest/test/gtest_json_test_utils.py diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index 77b55ca..575353f 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -306,7 +306,9 @@ if (gtest_build_tests) cxx_executable(gtest_xml_outfile1_test_ test gtest_main) cxx_executable(gtest_xml_outfile2_test_ test gtest_main) py_test(gtest_xml_outfiles_test) + py_test(gtest_json_outfiles_test) cxx_executable(gtest_xml_output_unittest_ test gtest) py_test(gtest_xml_output_unittest) + py_test(gtest_json_output_unittest) endif() diff --git a/googletest/docs/AdvancedGuide.md b/googletest/docs/AdvancedGuide.md index 6605f44..c1a1a4a 100644 --- a/googletest/docs/AdvancedGuide.md +++ b/googletest/docs/AdvancedGuide.md @@ -2060,6 +2060,207 @@ Things to note: _Availability:_ Linux, Windows, Mac. +#### Generating an JSON Report {#JsonReport} + +gUnit can also emit a JSON report as an alternative format to XML. To generate +the JSON report, set the `GUNIT_OUTPUT` environment variable or the +`--gunit_output` flag to the string `"json:path_to_output_file"`, which will +create the file at the given location. You can also just use the string +`"json"`, in which case the output can be found in the `test_detail.json` file +in the current directory. + +The report format conforms to the following JSON Schema: + +```json +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "definitions": { + "TestCase": { + "type": "object", + "properties": { + "name": { "type": "string" }, + "tests": { "type": "integer" }, + "failures": { "type": "integer" }, + "disabled": { "type": "integer" }, + "time": { "type": "string" }, + "testsuite": { + "type": "array", + "items": { + "$ref": "#/definitions/TestInfo" + } + } + } + }, + "TestInfo": { + "type": "object", + "properties": { + "name": { "type": "string" }, + "status": { + "type": "string", + "enum": ["RUN", "NOTRUN"] + }, + "time": { "type": "string" }, + "classname": { "type": "string" }, + "failures": { + "type": "array", + "items": { + "$ref": "#/definitions/Failure" + } + } + } + }, + "Failure": { + "type": "object", + "properties": { + "failures": { "type": "string" }, + "type": { "type": "string" } + } + } + }, + "properties": { + "tests": { "type": "integer" }, + "failures": { "type": "integer" }, + "disabled": { "type": "integer" }, + "errors": { "type": "integer" }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "time": { "type": "string" }, + "name": { "type": "string" }, + "testsuites": { + "type": "array", + "items": { + "$ref": "#/definitions/TestCase" + } + } + } +} +``` + +The report uses the format that conforms to the following Proto3 using the +[JSON encoding](https://developers.google.com/protocol-buffers/docs/proto3#json): + +```proto +syntax = "proto3"; + +package googletest; + +import "google/protobuf/timestamp.proto"; +import "google/protobuf/duration.proto"; + +message UnitTest { + int32 tests = 1; + int32 failures = 2; + int32 disabled = 3; + int32 errors = 4; + google.protobuf.Timestamp timestamp = 5; + google.protobuf.Duration time = 6; + string name = 7; + repeated TestCase testsuites = 8; +} + +message TestCase { + string name = 1; + int32 tests = 2; + int32 failures = 3; + int32 disabled = 4; + int32 errors = 5; + google.protobuf.Duration time = 6; + repeated TestInfo testsuite = 7; +} + +message TestInfo { + string name = 1; + enum Status { + RUN = 0; + NOTRUN = 1; + } + Status status = 2; + google.protobuf.Duration time = 3; + string classname = 4; + message Failure { + string failures = 1; + string type = 2; + } + repeated Failure failures = 5; +} +``` + +For instance, the following program + +```c++ +TEST(MathTest, Addition) { ... } +TEST(MathTest, Subtraction) { ... } +TEST(LogicTest, NonContradiction) { ... } +``` + +could generate this report: + +```json +{ + "tests": 3, + "failures": 1, + "errors": 0, + "time": "0.035s", + "timestamp": "2011-10-31T18:52:42Z" + "name": "AllTests", + "testsuites": [ + { + "name": "MathTest", + "tests": 2, + "failures": 1, + "errors": 0, + "time": "0.015s", + "testsuite": [ + { + "name": "Addition", + "status": "RUN", + "time": "0.007s", + "classname": "", + "failures": [ + { + "message": "Value of: add(1, 1)\x0A Actual: 3\x0AExpected: 2", + "type": "" + }, + { + "message": "Value of: add(1, -1)\x0A Actual: 1\x0AExpected: 0", + "type": "" + } + ] + }, + { + "name": "Subtraction", + "status": "RUN", + "time": "0.005s", + "classname": "" + } + ] + } + { + "name": "LogicTest", + "tests": 1, + "failures": 0, + "errors": 0, + "time": "0.005s", + "testsuite": [ + { + "name": "NonContradiction", + "status": "RUN", + "time": "0.005s", + "classname": "" + } + ] + } + ] +} +``` + +IMPORTANT: The exact format of the JSON document is subject to change. + +**Availability**: Linux, Windows, Mac. + ## Controlling How Failures Are Reported ## ### Turning Assertion Failures into Break-Points ### diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 7afa5a9..15cc907 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -160,8 +160,10 @@ static const char kDeathTestCaseFilter[] = "*DeathTest:*DeathTest/*"; // A test filter that matches everything. static const char kUniversalFilter[] = "*"; -// The default output file for XML output. -static const char kDefaultOutputFile[] = "test_detail.xml"; +// The default output format. +static const char kDefaultOutputFormat[] = "xml"; +// The default output file. +static const char kDefaultOutputFile[] = "test_detail"; // The environment variable name for the test shard index. static const char kTestShardIndex[] = "GTEST_SHARD_INDEX"; @@ -231,9 +233,9 @@ GTEST_DEFINE_bool_(list_tests, false, GTEST_DEFINE_string_( output, internal::StringFromGTestEnv("output", ""), - "A format (currently must be \"xml\"), optionally followed " - "by a colon and an output file name or directory. A directory " - "is indicated by a trailing pathname separator. " + "A format (defaults to \"xml\" but can be specified to be \"json\"), " + "optionally followed by a colon and an output file name or directory. " + "A directory is indicated by a trailing pathname separator. " "Examples: \"xml:filename.xml\", \"xml::directoryname/\". " "If a directory is specified, output files will be created " "within that directory, with file-names based on the test " @@ -428,12 +430,17 @@ std::string UnitTestOptions::GetAbsolutePathToOutputFile() { if (gtest_output_flag == NULL) return ""; + std::string format = GetOutputFormat(); + if (format.empty()) + format = std::string(kDefaultOutputFormat); + const char* const colon = strchr(gtest_output_flag, ':'); if (colon == NULL) - return internal::FilePath::ConcatPaths( + return internal::FilePath::MakeFileName( internal::FilePath( UnitTest::GetInstance()->original_working_dir()), - internal::FilePath(kDefaultOutputFile)).string(); + internal::FilePath(kDefaultOutputFile), 0, + format.c_str()).string(); internal::FilePath output_name(colon + 1); if (!output_name.IsAbsolutePath()) @@ -3771,6 +3778,351 @@ std::string XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes( // End XmlUnitTestResultPrinter +// This class generates an JSON output file. +class JsonUnitTestResultPrinter : public EmptyTestEventListener { + public: + explicit JsonUnitTestResultPrinter(const char* output_file); + + virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration); + + private: + // Returns an JSON-escaped copy of the input string str. + static std::string EscapeJson(const std::string& str); + + //// Verifies that the given attribute belongs to the given element and + //// streams the attribute as JSON. + static void OutputJsonKey(std::ostream* stream, + const std::string& element_name, + const std::string& name, + const std::string& value, + const std::string& indent, + bool comma = true); + static void OutputJsonKey(std::ostream* stream, + const std::string& element_name, + const std::string& name, + int value, + const std::string& indent, + bool comma = true); + + // Streams a JSON representation of a TestInfo object. + static void OutputJsonTestInfo(::std::ostream* stream, + const char* test_case_name, + const TestInfo& test_info); + + // Prints a JSON representation of a TestCase object + static void PrintJsonTestCase(::std::ostream* stream, + const TestCase& test_case); + + // Prints a JSON summary of unit_test to output stream out. + static void PrintJsonUnitTest(::std::ostream* stream, + const UnitTest& unit_test); + + // Produces a string representing the test properties in a result as + // a JSON dictionary. + static std::string TestPropertiesAsJson(const TestResult& result, + const std::string& indent); + + // The output file. + const std::string output_file_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(JsonUnitTestResultPrinter); +}; + +// Creates a new JsonUnitTestResultPrinter. +JsonUnitTestResultPrinter::JsonUnitTestResultPrinter(const char* output_file) + : output_file_(output_file) { + if (output_file_.empty()) { + GTEST_LOG_(FATAL) << "JSON output file may not be null"; + } +} + +void JsonUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test, + int /*iteration*/) { + FILE* jsonout = NULL; + FilePath output_file(output_file_); + FilePath output_dir(output_file.RemoveFileName()); + + if (output_dir.CreateDirectoriesRecursively()) { + jsonout = posix::FOpen(output_file_.c_str(), "w"); + } + if (jsonout == NULL) { + // TODO(phosek): report the reason of the failure. + // + // We don't do it for now as: + // + // 1. There is no urgent need for it. + // 2. It's a bit involved to make the errno variable thread-safe on + // all three operating systems (Linux, Windows, and Mac OS). + // 3. To interpret the meaning of errno in a thread-safe way, + // we need the strerror_r() function, which is not available on + // Windows. + GTEST_LOG_(FATAL) << "Unable to open file \"" + << output_file_ << "\""; + } + std::stringstream stream; + PrintJsonUnitTest(&stream, unit_test); + fprintf(jsonout, "%s", StringStreamToString(&stream).c_str()); + fclose(jsonout); +} + +// Returns an JSON-escaped copy of the input string str. +std::string JsonUnitTestResultPrinter::EscapeJson(const std::string& str) { + Message m; + + for (size_t i = 0; i < str.size(); ++i) { + const char ch = str[i]; + switch (ch) { + case '\\': + case '"': + case '/': + m << '\\' << ch; + break; + case '\b': + m << "\\b"; + break; + case '\t': + m << "\\t"; + break; + case '\n': + m << "\\n"; + break; + case '\f': + m << "\\f"; + break; + case '\r': + m << "\\r"; + break; + default: + if (ch < ' ') { + m << "\\u00" << String::FormatByte(static_cast(ch)); + } else { + m << ch; + } + break; + } + } + + return m.GetString(); +} + +// The following routines generate an JSON representation of a UnitTest +// object. + +// Formats the given time in milliseconds as seconds. +static std::string FormatTimeInMillisAsDuration(TimeInMillis ms) { + ::std::stringstream ss; + ss << (static_cast(ms) * 1e-3) << "s"; + return ss.str(); +} + +// Converts the given epoch time in milliseconds to a date string in the +// RFC3339 format, without the timezone information. +static std::string FormatEpochTimeInMillisAsRFC3339(TimeInMillis ms) { + struct tm time_struct; + if (!PortableLocaltime(static_cast(ms / 1000), &time_struct)) + return ""; + // YYYY-MM-DDThh:mm:ss + return StreamableToString(time_struct.tm_year + 1900) + "-" + + String::FormatIntWidth2(time_struct.tm_mon + 1) + "-" + + String::FormatIntWidth2(time_struct.tm_mday) + "T" + + String::FormatIntWidth2(time_struct.tm_hour) + ":" + + String::FormatIntWidth2(time_struct.tm_min) + ":" + + String::FormatIntWidth2(time_struct.tm_sec) + "Z"; +} + +static inline std::string Indent(int width) { + return std::string(width, ' '); +} + +void JsonUnitTestResultPrinter::OutputJsonKey( + std::ostream* stream, + const std::string& element_name, + const std::string& name, + const std::string& value, + const std::string& indent, + bool comma) { + const std::vector& allowed_names = + GetReservedAttributesForElement(element_name); + + GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) != + allowed_names.end()) + << "Key \"" << name << "\" is not allowed for value \"" << element_name + << "\"."; + + *stream << indent << "\"" << name << "\": \"" << EscapeJson(value) << "\""; + if (comma) + *stream << ",\n"; +} + +void JsonUnitTestResultPrinter::OutputJsonKey( + std::ostream* stream, + const std::string& element_name, + const std::string& name, + int value, + const std::string& indent, + bool comma) { + const std::vector& allowed_names = + GetReservedAttributesForElement(element_name); + + GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) != + allowed_names.end()) + << "Key \"" << name << "\" is not allowed for value \"" << element_name + << "\"."; + + *stream << indent << "\"" << name << "\": " << StreamableToString(value); + if (comma) + *stream << ",\n"; +} + +// Prints a JSON representation of a TestInfo object. +void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream, + const char* test_case_name, + const TestInfo& test_info) { + const TestResult& result = *test_info.result(); + const std::string kTestcase = "testcase"; + const std::string kIndent = Indent(10); + + *stream << Indent(8) << "{\n"; + OutputJsonKey(stream, kTestcase, "name", test_info.name(), kIndent); + + if (test_info.value_param() != NULL) { + OutputJsonKey(stream, kTestcase, "value_param", + test_info.value_param(), kIndent); + } + if (test_info.type_param() != NULL) { + OutputJsonKey(stream, kTestcase, "type_param", test_info.type_param(), + kIndent); + } + + OutputJsonKey(stream, kTestcase, "status", + test_info.should_run() ? "RUN" : "NOTRUN", kIndent); + OutputJsonKey(stream, kTestcase, "time", + FormatTimeInMillisAsDuration(result.elapsed_time()), kIndent); + OutputJsonKey(stream, kTestcase, "classname", test_case_name, kIndent, false); + *stream << TestPropertiesAsJson(result, kIndent); + + int failures = 0; + for (int i = 0; i < result.total_part_count(); ++i) { + const TestPartResult& part = result.GetTestPartResult(i); + if (part.failed()) { + *stream << ",\n"; + if (++failures == 1) { + *stream << kIndent << "\"" << "failures" << "\": [\n"; + } + const std::string location = + internal::FormatCompilerIndependentFileLocation(part.file_name(), + part.line_number()); + const std::string summary = EscapeJson(location + "\n" + part.summary()); + *stream << kIndent << " {\n" + << kIndent << " \"failure\": \"" << summary << "\",\n" + << kIndent << " \"type\": \"\"\n" + << kIndent << " }"; + } + } + + if (failures > 0) + *stream << "\n" << kIndent << "]"; + *stream << "\n" << Indent(8) << "}"; +} + +// Prints an JSON representation of a TestCase object +void JsonUnitTestResultPrinter::PrintJsonTestCase(std::ostream* stream, + const TestCase& test_case) { + const std::string kTestsuite = "testsuite"; + const std::string kIndent = Indent(6); + + *stream << Indent(4) << "{\n"; + OutputJsonKey(stream, kTestsuite, "name", test_case.name(), kIndent); + OutputJsonKey(stream, kTestsuite, "tests", test_case.reportable_test_count(), + kIndent); + OutputJsonKey(stream, kTestsuite, "failures", test_case.failed_test_count(), + kIndent); + OutputJsonKey(stream, kTestsuite, "disabled", + test_case.reportable_disabled_test_count(), kIndent); + OutputJsonKey(stream, kTestsuite, "errors", 0, kIndent); + OutputJsonKey(stream, kTestsuite, "time", + FormatTimeInMillisAsDuration(test_case.elapsed_time()), kIndent, + false); + *stream << TestPropertiesAsJson(test_case.ad_hoc_test_result(), kIndent) + << ",\n"; + + *stream << kIndent << "\"" << kTestsuite << "\": [\n"; + + bool comma = false; + for (int i = 0; i < test_case.total_test_count(); ++i) { + if (test_case.GetTestInfo(i)->is_reportable()) { + if (comma) { + *stream << ",\n"; + } else { + comma = true; + } + OutputJsonTestInfo(stream, test_case.name(), *test_case.GetTestInfo(i)); + } + } + *stream << "\n" << kIndent << "]\n" << Indent(4) << "}"; +} + +// Prints a JSON summary of unit_test to output stream out. +void JsonUnitTestResultPrinter::PrintJsonUnitTest(std::ostream* stream, + const UnitTest& unit_test) { + const std::string kTestsuites = "testsuites"; + const std::string kIndent = Indent(2); + *stream << "{\n"; + + OutputJsonKey(stream, kTestsuites, "tests", unit_test.reportable_test_count(), + kIndent); + OutputJsonKey(stream, kTestsuites, "failures", unit_test.failed_test_count(), + kIndent); + OutputJsonKey(stream, kTestsuites, "disabled", + unit_test.reportable_disabled_test_count(), kIndent); + OutputJsonKey(stream, kTestsuites, "errors", 0, kIndent); + if (GTEST_FLAG(shuffle)) { + OutputJsonKey(stream, kTestsuites, "random_seed", unit_test.random_seed(), + kIndent); + } + OutputJsonKey(stream, kTestsuites, "timestamp", + FormatEpochTimeInMillisAsRFC3339(unit_test.start_timestamp()), + kIndent); + OutputJsonKey(stream, kTestsuites, "time", + FormatTimeInMillisAsDuration(unit_test.elapsed_time()), kIndent, + false); + + *stream << TestPropertiesAsJson(unit_test.ad_hoc_test_result(), kIndent) + << ",\n"; + + OutputJsonKey(stream, kTestsuites, "name", "AllTests", kIndent); + *stream << kIndent << "\"" << kTestsuites << "\": [\n"; + + bool comma = false; + for (int i = 0; i < unit_test.total_test_case_count(); ++i) { + if (unit_test.GetTestCase(i)->reportable_test_count() > 0) { + if (comma) { + *stream << ",\n"; + } else { + comma = true; + } + PrintJsonTestCase(stream, *unit_test.GetTestCase(i)); + } + } + + *stream << "\n" << kIndent << "]\n" << "}\n"; +} + +// Produces a string representing the test properties in a result as +// a JSON dictionary. +std::string JsonUnitTestResultPrinter::TestPropertiesAsJson( + const TestResult& result, const std::string& indent) { + Message attributes; + for (int i = 0; i < result.test_property_count(); ++i) { + const TestProperty& property = result.GetTestProperty(i); + attributes << ",\n" << indent << "\"" << property.key() << "\": " + << "\"" << EscapeJson(property.value()) << "\""; + } + return attributes.GetString(); +} + +// End JsonUnitTestResultPrinter + #if GTEST_CAN_STREAM_RESULTS_ // Checks if str contains '=', '&', '%' or '\n' characters. If yes, @@ -4397,6 +4749,9 @@ void UnitTestImpl::ConfigureXmlOutput() { if (output_format == "xml") { listeners()->SetDefaultXmlGenerator(new XmlUnitTestResultPrinter( UnitTestOptions::GetAbsolutePathToOutputFile().c_str())); + } else if (output_format == "json") { + listeners()->SetDefaultXmlGenerator(new JsonUnitTestResultPrinter( + UnitTestOptions::GetAbsolutePathToOutputFile().c_str())); } else if (output_format != "") { GTEST_LOG_(WARNING) << "WARNING: unrecognized output format \"" << output_format << "\" ignored."; @@ -5182,10 +5537,10 @@ static const char kColorEncodedHelpMessage[] = " Enable/disable colored output. The default is @Gauto@D.\n" " @G--" GTEST_FLAG_PREFIX_ "print_time=0@D\n" " Don't print the elapsed time of each test.\n" -" @G--" GTEST_FLAG_PREFIX_ "output=xml@Y[@G:@YDIRECTORY_PATH@G" +" @G--" GTEST_FLAG_PREFIX_ "output=@Y(@Gjson@Y|@Gxml@Y)[@G:@YDIRECTORY_PATH@G" GTEST_PATH_SEP_ "@Y|@G:@YFILE_PATH]@D\n" -" Generate an XML report in the given directory or with the given file\n" -" name. @YFILE_PATH@D defaults to @Gtest_detail.xml@D.\n" +" Generate a JSON or XML report in the given directory or with the given\n" +" file name. @YFILE_PATH@D defaults to @Gtest_details.xml@D.\n" #if GTEST_CAN_STREAM_RESULTS_ " @G--" GTEST_FLAG_PREFIX_ "stream_result_to=@YHOST@G:@YPORT@D\n" " Stream test results to the given server.\n" diff --git a/googletest/test/gtest_json_outfiles_test.py b/googletest/test/gtest_json_outfiles_test.py new file mode 100644 index 0000000..62ad18e --- /dev/null +++ b/googletest/test/gtest_json_outfiles_test.py @@ -0,0 +1,163 @@ +#!/usr/bin/env python +# Copyright 2018, 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. + +"""Unit test for the gtest_json_output module.""" + +import json +import os +import gtest_test_utils +import gtest_json_test_utils + + +GTEST_OUTPUT_SUBDIR = 'json_outfiles' +GTEST_OUTPUT_1_TEST = 'gtest_xml_outfile1_test_' +GTEST_OUTPUT_2_TEST = 'gtest_xml_outfile2_test_' + +EXPECTED_1 = { + u'tests': 1, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'timestamp': u'*', + u'name': u'AllTests', + u'testsuites': [{ + u'name': u'PropertyOne', + u'tests': 1, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'testsuite': [{ + u'name': u'TestSomeProperties', + u'status': u'RUN', + u'time': u'*', + u'classname': u'PropertyOne', + u'SetUpProp': u'1', + u'TestSomeProperty': u'1', + u'TearDownProp': u'1', + }], + }], +} + +EXPECTED_2 = { + u'tests': 1, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'timestamp': u'*', + u'name': u'AllTests', + u'testsuites': [{ + u'name': u'PropertyTwo', + u'tests': 1, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'testsuite': [{ + u'name': u'TestSomeProperties', + u'status': u'RUN', + u'time': u'*', + u'classname': u'PropertyTwo', + u'SetUpProp': u'2', + u'TestSomeProperty': u'2', + u'TearDownProp': u'2', + }], + }], +} + + +class GTestJsonOutFilesTest(gtest_test_utils.TestCase): + """Unit test for Google Test's JSON output functionality.""" + + def setUp(self): + # We want the trailing '/' that the last "" provides in os.path.join, for + # telling Google Test to create an output directory instead of a single file + # for xml output. + self.output_dir_ = os.path.join(gtest_test_utils.GetTempDir(), + GTEST_OUTPUT_SUBDIR, '') + self.DeleteFilesAndDir() + + def tearDown(self): + self.DeleteFilesAndDir() + + def DeleteFilesAndDir(self): + try: + os.remove(os.path.join(self.output_dir_, GTEST_OUTPUT_1_TEST + '.json')) + except os.error: + pass + try: + os.remove(os.path.join(self.output_dir_, GTEST_OUTPUT_2_TEST + '.json')) + except os.error: + pass + try: + os.rmdir(self.output_dir_) + except os.error: + pass + + def testOutfile1(self): + self._TestOutFile(GTEST_OUTPUT_1_TEST, EXPECTED_1) + + def testOutfile2(self): + self._TestOutFile(GTEST_OUTPUT_2_TEST, EXPECTED_2) + + def _TestOutFile(self, test_name, expected): + gtest_prog_path = gtest_test_utils.GetTestExecutablePath(test_name) + command = [gtest_prog_path, '--gtest_output=json:%s' % self.output_dir_] + p = gtest_test_utils.Subprocess(command, + working_dir=gtest_test_utils.GetTempDir()) + self.assert_(p.exited) + self.assertEquals(0, p.exit_code) + + # TODO(wan@google.com): libtool causes the built test binary to be + # named lt-gtest_xml_outfiles_test_ instead of + # gtest_xml_outfiles_test_. To account for this possibility, we + # allow both names in the following code. We should remove this + # hack when Chandler Carruth's libtool replacement tool is ready. + output_file_name1 = test_name + '.json' + output_file1 = os.path.join(self.output_dir_, output_file_name1) + output_file_name2 = 'lt-' + output_file_name1 + output_file2 = os.path.join(self.output_dir_, output_file_name2) + self.assert_(os.path.isfile(output_file1) or os.path.isfile(output_file2), + output_file1) + + if os.path.isfile(output_file1): + with open(output_file1) as f: + actual = json.load(f) + else: + with open(output_file2) as f: + actual = json.load(f) + self.assertEqual(expected, gtest_json_test_utils.normalize(actual)) + + +if __name__ == '__main__': + os.environ['GTEST_STACK_TRACE_DEPTH'] = '0' + gtest_test_utils.Main() diff --git a/googletest/test/gtest_json_output_unittest.py b/googletest/test/gtest_json_output_unittest.py new file mode 100644 index 0000000..4d23c3a --- /dev/null +++ b/googletest/test/gtest_json_output_unittest.py @@ -0,0 +1,612 @@ +#!/usr/bin/env python +# Copyright 2018, 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. + +"""Unit test for the gtest_json_output module.""" + +import datetime +import errno +import json +import os +import re +import sys + +import gtest_test_utils +import gtest_json_test_utils + + +GTEST_FILTER_FLAG = '--gtest_filter' +GTEST_LIST_TESTS_FLAG = '--gtest_list_tests' +GTEST_OUTPUT_FLAG = '--gtest_output' +GTEST_DEFAULT_OUTPUT_FILE = 'test_detail.json' +GTEST_PROGRAM_NAME = 'gtest_xml_output_unittest_' + +SUPPORTS_STACK_TRACES = False + +if SUPPORTS_STACK_TRACES: + STACK_TRACE_TEMPLATE = '\nStack trace:\n*' +else: + STACK_TRACE_TEMPLATE = '' + +EXPECTED_NON_EMPTY = { + u'tests': 23, + u'failures': 4, + u'disabled': 2, + u'errors': 0, + u'timestamp': u'*', + u'time': u'*', + u'ad_hoc_property': u'42', + u'name': u'AllTests', + u'testsuites': [ + { + u'name': u'SuccessfulTest', + u'tests': 1, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'testsuite': [ + { + u'name': u'Succeeds', + u'status': u'RUN', + u'time': u'*', + u'classname': u'SuccessfulTest' + } + ] + }, + { + u'name': u'FailedTest', + u'tests': 1, + u'failures': 1, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'testsuite': [ + { + u'name': u'Fails', + u'status': u'RUN', + u'time': u'*', + u'classname': u'FailedTest', + u'failures': [ + { + u'failure': + u'gtest_xml_output_unittest_.cc:*\n' + u'Expected equality of these values:\n' + u' 1\n 2' + STACK_TRACE_TEMPLATE, + u'type': u'' + } + ] + } + ] + }, + { + u'name': u'DisabledTest', + u'tests': 1, + u'failures': 0, + u'disabled': 1, + u'errors': 0, + u'time': u'*', + u'testsuite': [ + { + u'name': u'DISABLED_test_not_run', + u'status': u'NOTRUN', + u'time': u'*', + u'classname': u'DisabledTest' + } + ] + }, + { + u'name': u'MixedResultTest', + u'tests': 3, + u'failures': 1, + u'disabled': 1, + u'errors': 0, + u'time': u'*', + u'testsuite': [ + { + u'name': u'Succeeds', + u'status': u'RUN', + u'time': u'*', + u'classname': u'MixedResultTest' + }, + { + u'name': u'Fails', + u'status': u'RUN', + u'time': u'*', + u'classname': u'MixedResultTest', + u'failures': [ + { + u'failure': + u'gtest_xml_output_unittest_.cc:*\n' + u'Expected equality of these values:\n' + u' 1\n 2' + STACK_TRACE_TEMPLATE, + u'type': u'' + }, + { + u'failure': + u'gtest_xml_output_unittest_.cc:*\n' + u'Expected equality of these values:\n' + u' 2\n 3' + STACK_TRACE_TEMPLATE, + u'type': u'' + } + ] + }, + { + u'name': u'DISABLED_test', + u'status': u'NOTRUN', + u'time': u'*', + u'classname': u'MixedResultTest' + } + ] + }, + { + u'name': u'XmlQuotingTest', + u'tests': 1, + u'failures': 1, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'testsuite': [ + { + u'name': u'OutputsCData', + u'status': u'RUN', + u'time': u'*', + u'classname': u'XmlQuotingTest', + u'failures': [ + { + u'failure': + u'gtest_xml_output_unittest_.cc:*\n' + u'Failed\nXML output: ' + u'' + + STACK_TRACE_TEMPLATE, + u'type': u'' + } + ] + } + ] + }, + { + u'name': u'InvalidCharactersTest', + u'tests': 1, + u'failures': 1, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'testsuite': [ + { + u'name': u'InvalidCharactersInMessage', + u'status': u'RUN', + u'time': u'*', + u'classname': u'InvalidCharactersTest', + u'failures': [ + { + u'failure': + u'gtest_xml_output_unittest_.cc:*\n' + u'Failed\nInvalid characters in brackets' + u' [\x01\x02]' + STACK_TRACE_TEMPLATE, + u'type': u'' + } + ] + } + ] + }, + { + u'name': u'PropertyRecordingTest', + u'tests': 4, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'SetUpTestCase': u'yes', + u'TearDownTestCase': u'aye', + u'testsuite': [ + { + u'name': u'OneProperty', + u'status': u'RUN', + u'time': u'*', + u'classname': u'PropertyRecordingTest', + u'key_1': u'1' + }, + { + u'name': u'IntValuedProperty', + u'status': u'RUN', + u'time': u'*', + u'classname': u'PropertyRecordingTest', + u'key_int': u'1' + }, + { + u'name': u'ThreeProperties', + u'status': u'RUN', + u'time': u'*', + u'classname': u'PropertyRecordingTest', + u'key_1': u'1', + u'key_2': u'2', + u'key_3': u'3' + }, + { + u'name': u'TwoValuesForOneKeyUsesLastValue', + u'status': u'RUN', + u'time': u'*', + u'classname': u'PropertyRecordingTest', + u'key_1': u'2' + } + ] + }, + { + u'name': u'NoFixtureTest', + u'tests': 3, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'testsuite': [ + { + u'name': u'RecordProperty', + u'status': u'RUN', + u'time': u'*', + u'classname': u'NoFixtureTest', + u'key': u'1' + }, + { + u'name': u'ExternalUtilityThatCallsRecordIntValuedProperty', + u'status': u'RUN', + u'time': u'*', + u'classname': u'NoFixtureTest', + u'key_for_utility_int': u'1' + }, + { + u'name': + u'ExternalUtilityThatCallsRecordStringValuedProperty', + u'status': u'RUN', + u'time': u'*', + u'classname': u'NoFixtureTest', + u'key_for_utility_string': u'1' + } + ] + }, + { + u'name': u'TypedTest/0', + u'tests': 1, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'testsuite': [ + { + u'name': u'HasTypeParamAttribute', + u'type_param': u'int', + u'status': u'RUN', + u'time': u'*', + u'classname': u'TypedTest/0' + } + ] + }, + { + u'name': u'TypedTest/1', + u'tests': 1, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'testsuite': [ + { + u'name': u'HasTypeParamAttribute', + u'type_param': u'long', + u'status': u'RUN', + u'time': u'*', + u'classname': u'TypedTest/1' + } + ] + }, + { + u'name': u'Single/TypeParameterizedTestCase/0', + u'tests': 1, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'testsuite': [ + { + u'name': u'HasTypeParamAttribute', + u'type_param': u'int', + u'status': u'RUN', + u'time': u'*', + u'classname': u'Single/TypeParameterizedTestCase/0' + } + ] + }, + { + u'name': u'Single/TypeParameterizedTestCase/1', + u'tests': 1, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'testsuite': [ + { + u'name': u'HasTypeParamAttribute', + u'type_param': u'long', + u'status': u'RUN', + u'time': u'*', + u'classname': u'Single/TypeParameterizedTestCase/1' + } + ] + }, + { + u'name': u'Single/ValueParamTest', + u'tests': 4, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'testsuite': [ + { + u'name': u'HasValueParamAttribute/0', + u'value_param': u'33', + u'status': u'RUN', + u'time': u'*', + u'classname': u'Single/ValueParamTest' + }, + { + u'name': u'HasValueParamAttribute/1', + u'value_param': u'42', + u'status': u'RUN', + u'time': u'*', + u'classname': u'Single/ValueParamTest' + }, + { + u'name': u'AnotherTestThatHasValueParamAttribute/0', + u'value_param': u'33', + u'status': u'RUN', + u'time': u'*', + u'classname': u'Single/ValueParamTest' + }, + { + u'name': u'AnotherTestThatHasValueParamAttribute/1', + u'value_param': u'42', + u'status': u'RUN', + u'time': u'*', + u'classname': u'Single/ValueParamTest' + } + ] + } + ] +} + +EXPECTED_FILTERED = { + u'tests': 1, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'timestamp': u'*', + u'name': u'AllTests', + u'ad_hoc_property': u'42', + u'testsuites': [{ + u'name': u'SuccessfulTest', + u'tests': 1, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'testsuite': [{ + u'name': u'Succeeds', + u'status': u'RUN', + u'time': u'*', + u'classname': u'SuccessfulTest', + }] + }], +} + +EXPECTED_EMPTY = { + u'tests': 0, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'timestamp': u'*', + u'name': u'AllTests', + u'testsuites': [], +} + +GTEST_PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME) + +SUPPORTS_TYPED_TESTS = 'TypedTest' in gtest_test_utils.Subprocess( + [GTEST_PROGRAM_PATH, GTEST_LIST_TESTS_FLAG], capture_stderr=False).output + + +class GTestJsonOutputUnitTest(gtest_test_utils.TestCase): + """Unit test for Google Test's JSON output functionality. + """ + + # This test currently breaks on platforms that do not support typed and + # type-parameterized tests, so we don't run it under them. + if SUPPORTS_TYPED_TESTS: + + def testNonEmptyJsonOutput(self): + """Verifies JSON output for a Google Test binary with non-empty output. + + Runs a test program that generates a non-empty JSON output, and + tests that the JSON output is expected. + """ + self._TestJsonOutput(GTEST_PROGRAM_NAME, EXPECTED_NON_EMPTY, 1) + + def testEmptyJsonOutput(self): + """Verifies JSON output for a Google Test binary without actual tests. + + Runs a test program that generates an empty JSON output, and + tests that the JSON output is expected. + """ + + self._TestJsonOutput('gtest_no_test_unittest', EXPECTED_EMPTY, 0) + + def testTimestampValue(self): + """Checks whether the timestamp attribute in the JSON output is valid. + + Runs a test program that generates an empty JSON output, and checks if + the timestamp attribute in the testsuites tag is valid. + """ + actual = self._GetJsonOutput('gtest_no_test_unittest', [], 0) + date_time_str = actual['timestamp'] + # datetime.strptime() is only available in Python 2.5+ so we have to + # parse the expected datetime manually. + match = re.match(r'(\d+)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)', date_time_str) + self.assertTrue( + re.match, + 'JSON datettime string %s has incorrect format' % date_time_str) + date_time_from_json = datetime.datetime( + year=int(match.group(1)), month=int(match.group(2)), + day=int(match.group(3)), hour=int(match.group(4)), + minute=int(match.group(5)), second=int(match.group(6))) + + time_delta = abs(datetime.datetime.now() - date_time_from_json) + # timestamp value should be near the current local time + self.assertTrue(time_delta < datetime.timedelta(seconds=600), + 'time_delta is %s' % time_delta) + + def testDefaultOutputFile(self): + """Verifies the default output file name. + + Confirms that Google Test produces an JSON output file with the expected + default name if no name is explicitly specified. + """ + output_file = os.path.join(gtest_test_utils.GetTempDir(), + GTEST_DEFAULT_OUTPUT_FILE) + gtest_prog_path = gtest_test_utils.GetTestExecutablePath( + 'gtest_no_test_unittest') + try: + os.remove(output_file) + except OSError: + e = sys.exc_info()[1] + if e.errno != errno.ENOENT: + raise + + p = gtest_test_utils.Subprocess( + [gtest_prog_path, '%s=json' % GTEST_OUTPUT_FLAG], + working_dir=gtest_test_utils.GetTempDir()) + self.assert_(p.exited) + self.assertEquals(0, p.exit_code) + self.assert_(os.path.isfile(output_file)) + + def testSuppressedJsonOutput(self): + """Verifies that no JSON output is generated. + + Tests that no JSON file is generated if the default JSON listener is + shut down before RUN_ALL_TESTS is invoked. + """ + + json_path = os.path.join(gtest_test_utils.GetTempDir(), + GTEST_PROGRAM_NAME + 'out.json') + if os.path.isfile(json_path): + os.remove(json_path) + + command = [GTEST_PROGRAM_PATH, + '%s=json:%s' % (GTEST_OUTPUT_FLAG, json_path), + '--shut_down_xml'] + p = gtest_test_utils.Subprocess(command) + if p.terminated_by_signal: + # p.signal is available only if p.terminated_by_signal is True. + self.assertFalse( + p.terminated_by_signal, + '%s was killed by signal %d' % (GTEST_PROGRAM_NAME, p.signal)) + else: + self.assert_(p.exited) + self.assertEquals(1, p.exit_code, + "'%s' exited with code %s, which doesn't match " + 'the expected exit code %s.' + % (command, p.exit_code, 1)) + + self.assert_(not os.path.isfile(json_path)) + + def testFilteredTestJsonOutput(self): + """Verifies JSON output when a filter is applied. + + Runs a test program that executes only some tests and verifies that + non-selected tests do not show up in the JSON output. + """ + + self._TestJsonOutput(GTEST_PROGRAM_NAME, EXPECTED_FILTERED, 0, + extra_args=['%s=SuccessfulTest.*' % GTEST_FILTER_FLAG]) + + def _GetJsonOutput(self, gtest_prog_name, extra_args, expected_exit_code): + """Returns the JSON output generated by running the program gtest_prog_name. + + Furthermore, the program's exit code must be expected_exit_code. + + Args: + gtest_prog_name: Google Test binary name. + extra_args: extra arguments to binary invocation. + expected_exit_code: program's exit code. + """ + json_path = os.path.join(gtest_test_utils.GetTempDir(), + gtest_prog_name + 'out.json') + gtest_prog_path = gtest_test_utils.GetTestExecutablePath(gtest_prog_name) + + command = ( + [gtest_prog_path, '%s=json:%s' % (GTEST_OUTPUT_FLAG, json_path)] + + extra_args + ) + p = gtest_test_utils.Subprocess(command) + if p.terminated_by_signal: + self.assert_(False, + '%s was killed by signal %d' % (gtest_prog_name, p.signal)) + else: + self.assert_(p.exited) + self.assertEquals(expected_exit_code, p.exit_code, + "'%s' exited with code %s, which doesn't match " + 'the expected exit code %s.' + % (command, p.exit_code, expected_exit_code)) + with open(json_path) as f: + actual = json.load(f) + return actual + + def _TestJsonOutput(self, gtest_prog_name, expected, + expected_exit_code, extra_args=None): + """Checks the JSON output generated by the Google Test binary. + + Asserts that the JSON document generated by running the program + gtest_prog_name matches expected_json, a string containing another + JSON document. Furthermore, the program's exit code must be + expected_exit_code. + + Args: + gtest_prog_name: Google Test binary name. + expected: expected output. + expected_exit_code: program's exit code. + extra_args: extra arguments to binary invocation. + """ + + actual = self._GetJsonOutput(gtest_prog_name, extra_args or [], + expected_exit_code) + self.assertEqual(expected, gtest_json_test_utils.normalize(actual)) + + +if __name__ == '__main__': + os.environ['GTEST_STACK_TRACE_DEPTH'] = '1' + gtest_test_utils.Main() diff --git a/googletest/test/gtest_json_test_utils.py b/googletest/test/gtest_json_test_utils.py new file mode 100644 index 0000000..4ef5f6f --- /dev/null +++ b/googletest/test/gtest_json_test_utils.py @@ -0,0 +1,60 @@ +# Copyright 2018, 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. + +"""Unit test utilities for gtest_json_output.""" + +import re + + +def normalize(obj): + """Normalize output object. + + Args: + obj: Google Test's JSON output object to normalize. + + Returns: + Normalized output without any references to transient information that may + change from run to run. + """ + def _normalize(key, value): + if key == 'time': + return re.sub(r'^\d+(\.\d+)?s$', u'*', value) + elif key == 'timestamp': + return re.sub(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ$', '*', value) + elif key == 'failure': + value = re.sub(r'^.*[/\\](.*:)\d+\n', '\\1*\n', value) + return re.sub(r'Stack trace:\n(.|\n)*', 'Stack trace:\n*', value) + else: + return normalize(value) + if isinstance(obj, dict): + return {k: _normalize(k, v) for k, v in obj.items()} + if isinstance(obj, list): + return [normalize(x) for x in obj] + else: + return obj -- cgit v0.12 From 3431b6990980abc12246298644594070e8315f88 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Wed, 28 Feb 2018 11:28:57 -0500 Subject: Add options to parallelize builds. AppVeyor build servers have two cores, so why not use them? --- appveyor.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 8d9cc64..84d9fbc 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -72,7 +72,8 @@ build_script: if ($LastExitCode -ne 0) { throw "Exec: $ErrorMessage" } - & cmake --build . --config $env:configuration + $cmake_parallel = if ($env:generator -eq "MinGW Makefiles") {"-j2"} else {"/m"} + & cmake --build . --config $env:configuration -- $cmake_parallel if ($LastExitCode -ne 0) { throw "Exec: $ErrorMessage" } -- cgit v0.12 From 7a2050d4d7eea672716a7d85c2fee2607879862a Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Thu, 1 Mar 2018 13:19:34 -0800 Subject: Use a full message in the JSON output for failures The full message unlike summary also includes stack trace. --- googletest/src/gtest.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 15cc907..74c43a4 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -4012,9 +4012,9 @@ void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream, const std::string location = internal::FormatCompilerIndependentFileLocation(part.file_name(), part.line_number()); - const std::string summary = EscapeJson(location + "\n" + part.summary()); + const std::string message = EscapeJson(location + "\n" + part.message()); *stream << kIndent << " {\n" - << kIndent << " \"failure\": \"" << summary << "\",\n" + << kIndent << " \"failure\": \"" << message << "\",\n" << kIndent << " \"type\": \"\"\n" << kIndent << " }"; } -- cgit v0.12 From 0d5e01ad7bf0796679417e3acdb0418f5b19fc31 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 5 Mar 2018 12:26:15 -0500 Subject: Merges-1 --- .../include/gmock/internal/custom/gmock-matchers.h | 7 +++---- googlemock/test/gmock_link_test.h | 2 ++ .../gtest/internal/gtest-death-test-internal.h | 20 ++++++++++++-------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/googlemock/include/gmock/internal/custom/gmock-matchers.h b/googlemock/include/gmock/internal/custom/gmock-matchers.h index f2efef9..fe0d9e8 100644 --- a/googlemock/include/gmock/internal/custom/gmock-matchers.h +++ b/googlemock/include/gmock/internal/custom/gmock-matchers.h @@ -33,7 +33,6 @@ // // Adds google3 callback support to CallableTraits. // -#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_CALLBACK_MATCHERS_H_ -#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_CALLBACK_MATCHERS_H_ - -#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_CALLBACK_MATCHERS_H_ +#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_ +#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_ +#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_ diff --git a/googlemock/test/gmock_link_test.h b/googlemock/test/gmock_link_test.h index 5f855d1..06a1cf8 100644 --- a/googlemock/test/gmock_link_test.h +++ b/googlemock/test/gmock_link_test.h @@ -90,8 +90,10 @@ // Field // Property // ResultOf(function) +// ResultOf(callback) // Pointee // Truly(predicate) +// AddressSatisfies // AllOf // AnyOf // Not diff --git a/googletest/include/gtest/internal/gtest-death-test-internal.h b/googletest/include/gtest/internal/gtest-death-test-internal.h index a9e6610..88e7799 100644 --- a/googletest/include/gtest/internal/gtest-death-test-internal.h +++ b/googletest/include/gtest/internal/gtest-death-test-internal.h @@ -217,14 +217,18 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status); // can be streamed. // This macro is for implementing ASSERT/EXPECT_DEBUG_DEATH when compiled in -// NDEBUG mode. In this case we need the statements to be executed, the regex is -// ignored, and the macro must accept a streamed message even though the message -// is never printed. -# define GTEST_EXECUTE_STATEMENT_(statement, regex) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::testing::internal::AlwaysTrue()) { \ - GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ - } else \ +// NDEBUG mode. In this case we need the statements to be executed and the macro +// must accept a streamed message even though the message is never printed. +// The regex object is not evaluated, but it is used to prevent "unused" +// warnings and to avoid an expression that doesn't compile in debug mode. +#define GTEST_EXECUTE_STATEMENT_(statement, regex) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::AlwaysTrue()) { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } else if (!::testing::internal::AlwaysTrue()) { \ + const ::testing::internal::RE& gtest_regex = (regex); \ + static_cast(gtest_regex); \ + } else \ ::testing::Message() // A class representing the parsed contents of the -- cgit v0.12 From dbf63e38a4ebf2f5210648d82641ea304407e993 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 5 Mar 2018 13:28:13 -0500 Subject: merges-2 --- googlemock/src/gmock-internal-utils.cc | 14 ++++++++++++-- googlemock/src/gmock.cc | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/googlemock/src/gmock-internal-utils.cc b/googlemock/src/gmock-internal-utils.cc index 658fa62..20c5a8d 100644 --- a/googlemock/src/gmock-internal-utils.cc +++ b/googlemock/src/gmock-internal-utils.cc @@ -70,8 +70,8 @@ GTEST_API_ std::string JoinAsTuple(const Strings& fields) { // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is // treated as one word. For example, both "FooBar123" and // "foo_bar_123" are converted to "foo bar 123". -GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name) { - string result; +GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name) { + std::string result; char prev_char = '\0'; for (const char* p = id_name; *p != '\0'; prev_char = *(p++)) { // We don't care about the current locale as the input is @@ -188,5 +188,15 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message, std::cout << ::std::flush; } +void IllegalDoDefault(const char* file, int line) { + internal::Assert( + false, file, line, + "You are using DoDefault() inside a composite action like " + "DoAll() or WithArgs(). This is not supported for technical " + "reasons. Please instead spell out the default action, or " + "assign the default action to an Action variable and use " + "the variable in various places."); +} + } // namespace internal } // namespace testing diff --git a/googlemock/src/gmock.cc b/googlemock/src/gmock.cc index 3c37051..2308168 100644 --- a/googlemock/src/gmock.cc +++ b/googlemock/src/gmock.cc @@ -136,8 +136,8 @@ static bool ParseGoogleMockIntFlag(const char* str, const char* flag, if (value_str == NULL) return false; // Sets *value to the value of the flag. - *value = atoi(value_str); - return true; + return ParseInt32(Message() << "The value of flag --" << flag, + value_str, value); } // The internal implementation of InitGoogleMock(). -- cgit v0.12 From 83859284289f4c05bc9d8d98aa7db95fb2c608d6 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 5 Mar 2018 13:51:39 -0500 Subject: merges-3 --- googletest/test/gtest-printers_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/test/gtest-printers_test.cc b/googletest/test/gtest-printers_test.cc index 60a8d03..cd7c5d3 100644 --- a/googletest/test/gtest-printers_test.cc +++ b/googletest/test/gtest-printers_test.cc @@ -239,7 +239,7 @@ using ::testing::internal::UniversalTersePrint; #if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_ using ::testing::internal::UniversalTersePrintTupleFieldsToStrings; #endif -using ::testing::internal::string; + // The hash_* classes are not part of the C++ standard. STLport // defines them in namespace std. MSVC defines them in ::stdext. GCC -- cgit v0.12 From 086825de5d5cd13ad9a71221edcce74363939981 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 5 Mar 2018 14:21:41 -0500 Subject: merges-6 --- googletest/test/gtest_json_outfiles_test.py | 3 +-- googletest/test/gtest_json_output_unittest.py | 3 +-- googletest/test/gtest_json_test_utils.py | 2 +- googletest/test/gtest_test_utils.py | 2 +- googletest/test/gtest_uninitialized_test.py | 1 - 5 files changed, 4 insertions(+), 7 deletions(-) diff --git a/googletest/test/gtest_json_outfiles_test.py b/googletest/test/gtest_json_outfiles_test.py index 62ad18e..46010d8 100644 --- a/googletest/test/gtest_json_outfiles_test.py +++ b/googletest/test/gtest_json_outfiles_test.py @@ -32,9 +32,8 @@ import json import os -import gtest_test_utils import gtest_json_test_utils - +import gtest_test_utils GTEST_OUTPUT_SUBDIR = 'json_outfiles' GTEST_OUTPUT_1_TEST = 'gtest_xml_outfile1_test_' diff --git a/googletest/test/gtest_json_output_unittest.py b/googletest/test/gtest_json_output_unittest.py index 4d23c3a..12047c4 100644 --- a/googletest/test/gtest_json_output_unittest.py +++ b/googletest/test/gtest_json_output_unittest.py @@ -37,9 +37,8 @@ import os import re import sys -import gtest_test_utils import gtest_json_test_utils - +import gtest_test_utils GTEST_FILTER_FLAG = '--gtest_filter' GTEST_LIST_TESTS_FLAG = '--gtest_list_tests' diff --git a/googletest/test/gtest_json_test_utils.py b/googletest/test/gtest_json_test_utils.py index 4ef5f6f..62bbfc2 100644 --- a/googletest/test/gtest_json_test_utils.py +++ b/googletest/test/gtest_json_test_utils.py @@ -44,7 +44,7 @@ def normalize(obj): """ def _normalize(key, value): if key == 'time': - return re.sub(r'^\d+(\.\d+)?s$', u'*', value) + return re.sub(r'^\d+(\.\d+)?s$', '*', value) elif key == 'timestamp': return re.sub(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ$', '*', value) elif key == 'failure': diff --git a/googletest/test/gtest_test_utils.py b/googletest/test/gtest_test_utils.py index cc4ba64..7c48933 100755 --- a/googletest/test/gtest_test_utils.py +++ b/googletest/test/gtest_test_utils.py @@ -227,7 +227,7 @@ class Subprocess: combined in a string. """ - # The subprocess module is the preferable way of running programs + # The subprocess module is the preferrable way of running programs # since it is available and behaves consistently on all platforms, # including Windows. But it is only available starting in python 2.4. # In earlier python versions, we revert to the popen2 module, which is diff --git a/googletest/test/gtest_uninitialized_test.py b/googletest/test/gtest_uninitialized_test.py index 574db77..ae91f2a 100755 --- a/googletest/test/gtest_uninitialized_test.py +++ b/googletest/test/gtest_uninitialized_test.py @@ -33,7 +33,6 @@ __author__ = 'wan@google.com (Zhanyong Wan)' -import os import gtest_test_utils COMMAND = gtest_test_utils.GetTestExecutablePath('gtest_uninitialized_test_') -- cgit v0.12 From 995a9dfa69414ccfe454c9e1c7ac6fd35174fcad Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 5 Mar 2018 15:21:48 -0500 Subject: merges-7 --- googletest/src/gtest.cc | 66 ++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 74c43a4..473a666 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -2912,16 +2912,20 @@ static int GetBitOffset(WORD color_mask) { static WORD GetNewColor(GTestColor color, WORD old_color_attrs) { // Let's reuse the BG - static const WORD background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY; - static const WORD foreground_mask = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY; + static const WORD background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN | + BACKGROUND_RED | BACKGROUND_INTENSITY; + static const WORD foreground_mask = FOREGROUND_BLUE | FOREGROUND_GREEN | + FOREGROUND_RED | FOREGROUND_INTENSITY; const WORD existing_bg = old_color_attrs & background_mask; - WORD new_color = GetColorAttribute(color) | existing_bg | FOREGROUND_INTENSITY; + WORD new_color = + GetColorAttribute(color) | existing_bg | FOREGROUND_INTENSITY; static const int bg_bitOffset = GetBitOffset(background_mask); static const int fg_bitOffset = GetBitOffset(foreground_mask); - if (((new_color & background_mask) >> bg_bitOffset) == ((new_color & foreground_mask) >> fg_bitOffset)) { - new_color ^= FOREGROUND_INTENSITY; //invert intensity + if (((new_color & background_mask) >> bg_bitOffset) == + ((new_color & foreground_mask) >> fg_bitOffset)) { + new_color ^= FOREGROUND_INTENSITY; // invert intensity } return new_color; } @@ -2982,7 +2986,6 @@ bool ShouldUseColor(bool stdout_is_tty) { // cannot simply emit special characters and have the terminal change colors. // This routine must actually emit the characters rather than return a string // that would be colored when printed, as can be done on Linux. -GTEST_ATTRIBUTE_PRINTF_(2, 3) static void ColoredPrintf(GTestColor color, const char* fmt, ...) { va_list args; va_start(args, fmt); @@ -3749,7 +3752,6 @@ void XmlUnitTestResultPrinter::PrintXmlUnitTest(std::ostream* stream, OutputXmlAttribute(stream, kTestsuites, "random_seed", StreamableToString(unit_test.random_seed())); } - *stream << TestPropertiesAsXmlAttributes(unit_test.ad_hoc_test_result()); OutputXmlAttribute(stream, kTestsuites, "name", "AllTests"); @@ -4210,9 +4212,10 @@ void OsStackTraceGetter::UponLeavingGTest() {} class ScopedPrematureExitFile { public: explicit ScopedPrematureExitFile(const char* premature_exit_filepath) - : premature_exit_filepath_(premature_exit_filepath) { + : premature_exit_filepath_(premature_exit_filepath ? + premature_exit_filepath : "") { // If a path to the premature-exit file is specified... - if (premature_exit_filepath != NULL && *premature_exit_filepath != '\0') { + if (!premature_exit_filepath_.empty()) { // create the file with a single "0" character in it. I/O // errors are ignored as there's nothing better we can do and we // don't want to fail the test because of this. @@ -4223,13 +4226,18 @@ class ScopedPrematureExitFile { } ~ScopedPrematureExitFile() { - if (premature_exit_filepath_ != NULL && *premature_exit_filepath_ != '\0') { - remove(premature_exit_filepath_); + if (!premature_exit_filepath_.empty()) { + int retval = remove(premature_exit_filepath_.c_str()); + if (retval) { + GTEST_LOG_(ERROR) << "Failed to remove premature exit filepath \"" + << premature_exit_filepath_ << "\" with error " + << retval; + } } } private: - const char* const premature_exit_filepath_; + const std::string premature_exit_filepath_; GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedPrematureExitFile); }; @@ -4897,13 +4905,8 @@ static void TearDownEnvironment(Environment* env) { env->TearDown(); } // All other functions called from RunAllTests() may safely assume that // parameterized tests are ready to be counted and run. bool UnitTestImpl::RunAllTests() { - // Makes sure InitGoogleTest() was called. - if (!GTestIsInitialized()) { - GTEST_LOG_(ERROR) << - "\nThis test program did NOT call ::testing::InitGoogleTest " - "before calling RUN_ALL_TESTS(). Please fix it."; - return false; - } + // True iff Google Test is initialized before RUN_ALL_TESTS() is called. + const bool gtest_is_initialized_before_run_all_tests = GTestIsInitialized(); // Do not run any test if the --help flag was specified. if (g_help_flag) @@ -5031,6 +5034,20 @@ bool UnitTestImpl::RunAllTests() { repeater->OnTestProgramEnd(*parent_); + if (!gtest_is_initialized_before_run_all_tests) { + ColoredPrintf( + COLOR_RED, + "\nIMPORTANT NOTICE - DO NOT IGNORE:\n" + "This test program did NOT call " GTEST_INIT_GOOGLE_TEST_NAME_ + "() before calling RUN_ALL_TESTS(). This is INVALID. Soon " GTEST_NAME_ + " will start to enforce the valid usage. " + "Please fix it ASAP, or IT WILL START TO FAIL.\n"); // NOLINT +#if GTEST_FOR_GOOGLE_ + ColoredPrintf(COLOR_RED, + "For more details, see http://wiki/Main/ValidGUnitMain.\n"); +#endif // GTEST_FOR_GOOGLE_ + } + return !failed; } @@ -5077,7 +5094,7 @@ bool ShouldShard(const char* total_shards_env, << "Invalid environment variables: you have " << kTestShardIndex << " = " << shard_index << ", but have left " << kTestTotalShards << " unset.\n"; - ColoredPrintf(COLOR_RED, "%s", msg.GetString().c_str()); + ColoredPrintf(COLOR_RED, msg.GetString().c_str()); fflush(stdout); exit(EXIT_FAILURE); } else if (total_shards != -1 && shard_index == -1) { @@ -5085,7 +5102,7 @@ bool ShouldShard(const char* total_shards_env, << "Invalid environment variables: you have " << kTestTotalShards << " = " << total_shards << ", but have left " << kTestShardIndex << " unset.\n"; - ColoredPrintf(COLOR_RED, "%s", msg.GetString().c_str()); + ColoredPrintf(COLOR_RED, msg.GetString().c_str()); fflush(stdout); exit(EXIT_FAILURE); } else if (shard_index < 0 || shard_index >= total_shards) { @@ -5094,7 +5111,7 @@ bool ShouldShard(const char* total_shards_env, << kTestShardIndex << " < " << kTestTotalShards << ", but you have " << kTestShardIndex << "=" << shard_index << ", " << kTestTotalShards << "=" << total_shards << ".\n"; - ColoredPrintf(COLOR_RED, "%s", msg.GetString().c_str()); + ColoredPrintf(COLOR_RED, msg.GetString().c_str()); fflush(stdout); exit(EXIT_FAILURE); } @@ -5361,8 +5378,7 @@ bool SkipPrefix(const char* prefix, const char** pstr) { // part can be omitted. // // Returns the value of the flag, or NULL if the parsing failed. -static const char* ParseFlagValue(const char* str, - const char* flag, +static const char* ParseFlagValue(const char* str, const char* flag, bool def_optional) { // str and flag must not be NULL. if (str == NULL || flag == NULL) return NULL; @@ -5535,7 +5551,7 @@ static const char kColorEncodedHelpMessage[] = "Test Output:\n" " @G--" GTEST_FLAG_PREFIX_ "color=@Y(@Gyes@Y|@Gno@Y|@Gauto@Y)@D\n" " Enable/disable colored output. The default is @Gauto@D.\n" -" @G--" GTEST_FLAG_PREFIX_ "print_time=0@D\n" +" -@G-" GTEST_FLAG_PREFIX_ "print_time=0@D\n" " Don't print the elapsed time of each test.\n" " @G--" GTEST_FLAG_PREFIX_ "output=@Y(@Gjson@Y|@Gxml@Y)[@G:@YDIRECTORY_PATH@G" GTEST_PATH_SEP_ "@Y|@G:@YFILE_PATH]@D\n" -- cgit v0.12 From 89d6f70f34a2bbde33158e1065d964222a7c296c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 5 Mar 2018 15:53:36 -0500 Subject: merges-8 --- googletest/include/gtest/internal/gtest-port.h | 14 +++++++---- googletest/src/gtest-port.cc | 34 ++++++++++++++++++-------- googletest/src/gtest.cc | 26 +++++++++++--------- 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 4d5aa04..97206be 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -1537,14 +1537,18 @@ GTEST_API_ size_t GetFileSize(FILE* file); GTEST_API_ std::string ReadEntireFile(FILE* file); // All command line arguments. -GTEST_API_ const ::std::vector& GetArgvs(); +GTEST_API_ std::vector GetArgvs(); #if GTEST_HAS_DEATH_TEST -const ::std::vector& GetInjectableArgvs(); -void SetInjectableArgvs(const ::std::vector* - new_argvs); - +std::vector GetInjectableArgvs(); +// Deprecated: pass the args vector by value instead. +void SetInjectableArgvs(const std::vector* new_argvs); +void SetInjectableArgvs(const std::vector& new_argvs); +#if GTEST_HAS_GLOBAL_STRING +void SetInjectableArgvs(const std::vector< ::string>& new_argvs); +#endif // GTEST_HAS_GLOBAL_STRING +void ClearInjectableArgvs(); #endif // GTEST_HAS_DEATH_TEST diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index af0d120..99791f9 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -1081,22 +1081,36 @@ std::string ReadEntireFile(FILE* file) { } #if GTEST_HAS_DEATH_TEST +static const std::vector* g_injected_test_argvs = NULL; // Owned. -static const ::std::vector* g_injected_test_argvs = - NULL; // Owned. - -void SetInjectableArgvs(const ::std::vector* argvs) { - if (g_injected_test_argvs != argvs) - delete g_injected_test_argvs; - g_injected_test_argvs = argvs; -} - -const ::std::vector& GetInjectableArgvs() { +std::vector GetInjectableArgvs() { if (g_injected_test_argvs != NULL) { return *g_injected_test_argvs; } return GetArgvs(); } + +void SetInjectableArgvs(const std::vector* new_argvs) { + if (g_injected_test_argvs != new_argvs) delete g_injected_test_argvs; + g_injected_test_argvs = new_argvs; +} + +void SetInjectableArgvs(const std::vector& new_argvs) { + SetInjectableArgvs( + new std::vector(new_argvs.begin(), new_argvs.end())); +} + +#if GTEST_HAS_GLOBAL_STRING +void SetInjectableArgvs(const std::vector< ::string>& new_argvs) { + SetInjectableArgvs( + new std::vector(new_argvs.begin(), new_argvs.end())); +} +#endif // GTEST_HAS_GLOBAL_STRING + +void ClearInjectableArgvs() { + delete g_injected_test_argvs; + g_injected_test_argvs = NULL; +} #endif // GTEST_HAS_DEATH_TEST #if GTEST_OS_WINDOWS_MOBILE diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 473a666..3384c02 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -386,12 +386,15 @@ void AssertHelper::operator=(const Message& message) const { GTEST_API_ GTEST_DEFINE_STATIC_MUTEX_(g_linked_ptr_mutex); // A copy of all command line arguments. Set by InitGoogleTest(). -::std::vector g_argvs; +::std::vector g_argvs; -const ::std::vector& GetArgvs() { +::std::vector GetArgvs() { #if defined(GTEST_CUSTOM_GET_ARGVS_) - return GTEST_CUSTOM_GET_ARGVS_(); -#else // defined(GTEST_CUSTOM_GET_ARGVS_) + // GTEST_CUSTOM_GET_ARGVS_() may return a container of std::string or + // ::string. This code converts it to the appropriate type. + const auto& custom = GTEST_CUSTOM_GET_ARGVS_(); + return ::std::vector(custom.begin(), custom.end()); +#else // defined(GTEST_CUSTOM_GET_ARGVS_) return g_argvs; #endif // defined(GTEST_CUSTOM_GET_ARGVS_) } @@ -3035,7 +3038,7 @@ static void ColoredPrintf(GTestColor color, const char* fmt, ...) { va_end(args); } -// Text printed in Google Test's text output and --gunit_list_tests +// Text printed in Google Test's text output and --gtest_list_tests // output to label the type parameter and value parameter for a test. static const char kTypeParamLabel[] = "TypeParam"; static const char kValueParamLabel[] = "GetParam()"; @@ -5449,9 +5452,8 @@ bool ParseInt32Flag(const char* str, const char* flag, Int32* value) { // // On success, stores the value of the flag in *value, and returns // true. On failure, returns false without changing *value. -static bool ParseStringFlag(const char* str, - const char* flag, - std::string* value) { +template +static bool ParseStringFlag(const char* str, const char* flag, String* value) { // Gets the value of the flag as a string. const char* const value_str = ParseFlagValue(str, flag, false); @@ -5557,16 +5559,16 @@ static const char kColorEncodedHelpMessage[] = GTEST_PATH_SEP_ "@Y|@G:@YFILE_PATH]@D\n" " Generate a JSON or XML report in the given directory or with the given\n" " file name. @YFILE_PATH@D defaults to @Gtest_details.xml@D.\n" -#if GTEST_CAN_STREAM_RESULTS_ +# if GTEST_CAN_STREAM_RESULTS_ " @G--" GTEST_FLAG_PREFIX_ "stream_result_to=@YHOST@G:@YPORT@D\n" " Stream test results to the given server.\n" -#endif // GTEST_CAN_STREAM_RESULTS_ +# endif // GTEST_CAN_STREAM_RESULTS_ "\n" "Assertion Behavior:\n" -#if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS +# if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS " @G--" GTEST_FLAG_PREFIX_ "death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\n" " Set the default death test style.\n" -#endif // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS +# endif // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS " @G--" GTEST_FLAG_PREFIX_ "break_on_failure@D\n" " Turn assertion failures into debugger break-points.\n" " @G--" GTEST_FLAG_PREFIX_ "throw_on_failure@D\n" -- cgit v0.12 From e89190066608137b35dca32e28428126c04366dc Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 7 Mar 2018 15:57:55 -0500 Subject: Merging, XML tests --- googletest/src/gtest.cc | 39 ++++++++++++++++++++-- googletest/test/gtest_xml_outfiles_test.py | 16 +++++++-- googletest/test/gtest_xml_output_unittest.py | 50 +++++++++++++++++++++++----- googletest/test/gtest_xml_test_utils.py | 35 +++++++++++-------- 4 files changed, 114 insertions(+), 26 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 3384c02..74df549 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -3448,6 +3448,11 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener { // to delimit this attribute from prior attributes. static std::string TestPropertiesAsXmlAttributes(const TestResult& result); + // Streams an XML representation of the test properties of a TestResult + // object. + static void OutputXmlTestProperties(std::ostream* stream, + const TestResult& result); + // The output file. const std::string output_file_; @@ -3659,6 +3664,10 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream, const TestResult& result = *test_info.result(); const std::string kTestcase = "testcase"; + if (test_info.is_in_another_shard()) { + return; + } + *stream << " \n"; - else + } else { + if (failures == 0) { + *stream << ">\n"; + } + OutputXmlTestProperties(stream, result); *stream << " \n"; + } } // Prints an XML representation of a TestCase object @@ -3780,6 +3793,26 @@ std::string XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes( return attributes.GetString(); } +void XmlUnitTestResultPrinter::OutputXmlTestProperties( + std::ostream* stream, const TestResult& result) { + const std::string kProperties = "properties"; + const std::string kProperty = "property"; + + if (result.test_property_count() <= 0) { + return; + } + + *stream << "<" << kProperties << ">\n"; + for (int i = 0; i < result.test_property_count(); ++i) { + const TestProperty& property = result.GetTestProperty(i); + *stream << "<" << kProperty; + *stream << " name=\"" << EscapeXmlAttribute(property.key()) << "\""; + *stream << " value=\"" << EscapeXmlAttribute(property.value()) << "\""; + *stream << "/>\n"; + } + *stream << "\n"; +} + // End XmlUnitTestResultPrinter diff --git a/googletest/test/gtest_xml_outfiles_test.py b/googletest/test/gtest_xml_outfiles_test.py index 24c6ee6..c7d3413 100755 --- a/googletest/test/gtest_xml_outfiles_test.py +++ b/googletest/test/gtest_xml_outfiles_test.py @@ -43,7 +43,13 @@ GTEST_OUTPUT_2_TEST = "gtest_xml_outfile2_test_" EXPECTED_XML_1 = """ - + + + + + + + """ @@ -51,7 +57,13 @@ EXPECTED_XML_1 = """ EXPECTED_XML_2 = """ - + + + + + + + """ diff --git a/googletest/test/gtest_xml_output_unittest.py b/googletest/test/gtest_xml_output_unittest.py index 325ca13..6ffb6e3 100755 --- a/googletest/test/gtest_xml_output_unittest.py +++ b/googletest/test/gtest_xml_output_unittest.py @@ -104,15 +104,45 @@ Invalid characters in brackets []%(stack)s]]> - - - - + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + @@ -149,7 +179,11 @@ EXPECTED_SHARDED_TEST_XML = """ - + + + + + diff --git a/googletest/test/gtest_xml_test_utils.py b/googletest/test/gtest_xml_test_utils.py index d303425..1e03585 100755 --- a/googletest/test/gtest_xml_test_utils.py +++ b/googletest/test/gtest_xml_test_utils.py @@ -101,19 +101,22 @@ class GTestXMLTestCase(gtest_test_utils.TestCase): self.AssertEquivalentNodes(child, actual_children[child_id]) identifying_attribute = { - 'testsuites': 'name', - 'testsuite': 'name', - 'testcase': 'name', - 'failure': 'message', - } + 'testsuites': 'name', + 'testsuite': 'name', + 'testcase': 'name', + 'failure': 'message', + 'property': 'name', + } def _GetChildren(self, element): """ Fetches all of the child nodes of element, a DOM Element object. Returns them as the values of a dictionary keyed by the IDs of the - children. For , and elements, the ID - is the value of their "name" attribute; for elements, it is - the value of the "message" attribute; CDATA sections and non-whitespace + children. For , , , and + elements, the ID is the value of their "name" attribute; for + elements, it is the value of the "message" attribute; for + elements, it is the value of their parent's "name" attribute plus the + literal string "properties"; CDATA sections and non-whitespace text nodes are concatenated into a single CDATA section with ID "detail". An exception is raised if any element other than the above four is encountered, if two child elements with the same identifying @@ -123,11 +126,17 @@ class GTestXMLTestCase(gtest_test_utils.TestCase): children = {} for child in element.childNodes: if child.nodeType == Node.ELEMENT_NODE: - self.assert_(child.tagName in self.identifying_attribute, - 'Encountered unknown element <%s>' % child.tagName) - childID = child.getAttribute(self.identifying_attribute[child.tagName]) - self.assert_(childID not in children) - children[childID] = child + if child.tagName == 'properties': + self.assert_(child.parentNode is not None, + 'Encountered element without a parent') + child_id = child.parentNode.getAttribute('name') + '-properties' + else: + self.assert_(child.tagName in self.identifying_attribute, + 'Encountered unknown element <%s>' % child.tagName) + child_id = child.getAttribute( + self.identifying_attribute[child.tagName]) + self.assert_(child_id not in children) + children[child_id] = child elif child.nodeType in [Node.TEXT_NODE, Node.CDATA_SECTION_NODE]: if 'detail' not in children: if (child.nodeType == Node.CDATA_SECTION_NODE or -- cgit v0.12 From cf9d6344d28020b70c634c898fe798c862148668 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 12 Mar 2018 11:51:44 -0400 Subject: merges-port(1) --- googletest/include/gtest/internal/gtest-port.h | 36 ++++++++++++++++---------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 97206be..7a10d90 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -519,7 +519,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; # define GTEST_HAS_STD_STRING 1 #elif !GTEST_HAS_STD_STRING // The user told us that ::std::string isn't available. -# error "Google Test cannot be used where ::std::string isn't available." +# error "::std::string isn't available." #endif // !defined(GTEST_HAS_STD_STRING) #ifndef GTEST_HAS_GLOBAL_STRING @@ -889,6 +889,12 @@ using ::std::tuple_size; # define GTEST_ATTRIBUTE_UNUSED_ #endif +#if GTEST_LANG_CXX11 +# define GTEST_CXX11_EQUALS_DELETE_ = delete +#else // GTEST_LANG_CXX11 +# define GTEST_CXX11_EQUALS_DELETE_ +#endif // GTEST_LANG_CXX11 + // Use this annotation before a function that takes a printf format string. #if (defined(__GNUC__) || defined(__clang__)) && !defined(COMPILER_ICC) # if defined(__MINGW_PRINTF_FORMAT) @@ -906,15 +912,16 @@ using ::std::tuple_size; # define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) #endif + // A macro to disallow operator= // This should be used in the private: declarations for a class. -#define GTEST_DISALLOW_ASSIGN_(type)\ - void operator=(type const &) +#define GTEST_DISALLOW_ASSIGN_(type) \ + void operator=(type const &) GTEST_CXX11_EQUALS_DELETE_ // A macro to disallow copy constructor and operator= // This should be used in the private: declarations for a class. -#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\ - type(type const &);\ +#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type) \ + type(type const &) GTEST_CXX11_EQUALS_DELETE_; \ GTEST_DISALLOW_ASSIGN_(type) // Tell the compiler to warn about unused return values for functions declared @@ -995,10 +1002,12 @@ using ::std::tuple_size; #endif // _LIBCPP_VERSION is defined by the libc++ library from the LLVM project. -#if defined(__GLIBCXX__) || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER)) -# define GTEST_HAS_CXXABI_H_ 1 -#else -# define GTEST_HAS_CXXABI_H_ 0 +#if !defined(GTEST_HAS_CXXABI_H_) +# if defined(__GLIBCXX__) || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER)) +# define GTEST_HAS_CXXABI_H_ 1 +# else +# define GTEST_HAS_CXXABI_H_ 0 +# endif #endif // A function level attribute to disable checking for use of uninitialized @@ -2635,15 +2644,15 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds. # define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name) # define GTEST_DECLARE_int32_(name) \ GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name) -#define GTEST_DECLARE_string_(name) \ +# define GTEST_DECLARE_string_(name) \ GTEST_API_ extern ::std::string GTEST_FLAG(name) // Macros for defining flags. -#define GTEST_DEFINE_bool_(name, default_val, doc) \ +# define GTEST_DEFINE_bool_(name, default_val, doc) \ GTEST_API_ bool GTEST_FLAG(name) = (default_val) -#define GTEST_DEFINE_int32_(name, default_val, doc) \ +# define GTEST_DEFINE_int32_(name, default_val, doc) \ GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val) -#define GTEST_DEFINE_string_(name, default_val, doc) \ +# define GTEST_DEFINE_string_(name, default_val, doc) \ GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val) #endif // !defined(GTEST_DECLARE_bool_) @@ -2669,7 +2678,6 @@ GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val); std::string StringFromGTestEnv(const char* flag, const char* default_val); } // namespace internal - } // namespace testing #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ -- cgit v0.12 From 7b70413e0ca57b3e48d7655f342122f159f52b31 Mon Sep 17 00:00:00 2001 From: Bernhard Bauer Date: Mon, 12 Mar 2018 13:51:04 +0000 Subject: Allow macros inside of parametrized test names. This allows doing things like TEST_P(TestFixture, MAYBE(TestName)) for nicer conditional test disabling. Upstream of cr/188748737. Tested: Added unit tests MacroNamingTest and MacroNamingTestNonParametrized. --- googletest/include/gtest/gtest-param-test.h | 6 ++--- googletest/include/gtest/gtest-param-test.h.pump | 6 ++--- googletest/include/gtest/internal/gtest-internal.h | 3 +++ googletest/test/gtest-param-test_test.cc | 28 ++++++++++++++++++++++ 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index 19fae39..e155763 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -1371,8 +1371,6 @@ internal::CartesianProductHolder10AddTestPattern(\ - #test_case_name, \ - #test_name, \ + GTEST_STRINGIFY_(test_case_name), \ + GTEST_STRINGIFY_(test_name), \ new ::testing::internal::TestMetaFactory< \ GTEST_TEST_CLASS_NAME_(\ test_case_name, test_name)>()); \ diff --git a/googletest/include/gtest/gtest-param-test.h.pump b/googletest/include/gtest/gtest-param-test.h.pump index d8870af..8726fb3 100644 --- a/googletest/include/gtest/gtest-param-test.h.pump +++ b/googletest/include/gtest/gtest-param-test.h.pump @@ -436,8 +436,6 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine( ]] # endif // GTEST_HAS_COMBINE - - # define TEST_P(test_case_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ : public test_case_name { \ @@ -451,8 +449,8 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine( #test_case_name, \ ::testing::internal::CodeLocation(\ __FILE__, __LINE__))->AddTestPattern(\ - #test_case_name, \ - #test_name, \ + GTEST_STRINGIFY_(test_case_name), \ + GTEST_STRINGIFY_(test_name), \ new ::testing::internal::TestMetaFactory< \ GTEST_TEST_CLASS_NAME_(\ test_case_name, test_name)>()); \ diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 843058f..8d6a461 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -75,6 +75,9 @@ #define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar) #define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar +// Stringifies its argument. +#define GTEST_STRINGIFY_(name) #name + class ProtocolMessage; namespace proto2 { class Message; } diff --git a/googletest/test/gtest-param-test_test.cc b/googletest/test/gtest-param-test_test.cc index b0aa4f9..16d1e6e 100644 --- a/googletest/test/gtest-param-test_test.cc +++ b/googletest/test/gtest-param-test_test.cc @@ -803,6 +803,34 @@ TEST_P(NamingTest, TestsReportCorrectNamesAndParameters) { INSTANTIATE_TEST_CASE_P(ZeroToFiveSequence, NamingTest, Range(0, 5)); +// Tests that macros in test names are expanded correctly. +class MacroNamingTest : public TestWithParam {}; + +#define PREFIX_WITH_FOO(test_name) Foo##test_name +#define PREFIX_WITH_MACRO(test_name) Macro##test_name + +TEST_P(PREFIX_WITH_MACRO(NamingTest), PREFIX_WITH_FOO(SomeTestName)) { + const ::testing::TestInfo* const test_info = + ::testing::UnitTest::GetInstance()->current_test_info(); + + EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_case_name()); + EXPECT_STREQ("FooSomeTestName", test_info->name()); +} + +INSTANTIATE_TEST_CASE_P(FortyTwo, MacroNamingTest, Values(42)); + +// Tests the same thing for non-parametrized tests. +class MacroNamingTestNonParametrized : public ::testing::Test {}; + +TEST_F(PREFIX_WITH_MACRO(NamingTestNonParametrized), + PREFIX_WITH_FOO(SomeTestName)) { + const ::testing::TestInfo* const test_info = + ::testing::UnitTest::GetInstance()->current_test_info(); + + EXPECT_STREQ("MacroNamingTestNonParametrized", test_info->test_case_name()); + EXPECT_STREQ("FooSomeTestName", test_info->name()); +} + // Tests that user supplied custom parameter names are working correctly. // Runs the test with a builtin helper method which uses PrintToString, // as well as a custom function and custom functor to ensure all possible -- cgit v0.12 From af463c43ac22279239c1b8065ded7026b9224de1 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 13 Mar 2018 11:13:37 -0400 Subject: More merges, removing old dead code --- googlemock/include/gmock/gmock-actions.h | 11 ++--- googlemock/test/gmock-actions_test.cc | 4 +- googletest/include/gtest/internal/gtest-port.h | 14 +++---- googletest/test/gtest-printers_test.cc | 57 -------------------------- 4 files changed, 14 insertions(+), 72 deletions(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 845c823..90fd2ea 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -46,9 +46,10 @@ #include "gmock/internal/gmock-internal-utils.h" #include "gmock/internal/gmock-port.h" -#if GTEST_HAS_STD_TYPE_TRAITS_ // Defined by gtest-port.h via gmock-port.h. +#if GTEST_LANG_CXX11 // Defined by gtest-port.h via gmock-port.h. +#include #include -#endif +#endif // GTEST_LANG_CXX11 namespace testing { @@ -96,7 +97,7 @@ struct BuiltInDefaultValueGetter { template class BuiltInDefaultValue { public: -#if GTEST_HAS_STD_TYPE_TRAITS_ +#if GTEST_LANG_CXX11 // This function returns true iff type T has a built-in default value. static bool Exists() { return ::std::is_default_constructible::value; @@ -107,7 +108,7 @@ class BuiltInDefaultValue { T, ::std::is_default_constructible::value>::Get(); } -#else // GTEST_HAS_STD_TYPE_TRAITS_ +#else // GTEST_LANG_CXX11 // This function returns true iff type T has a built-in default value. static bool Exists() { return false; @@ -117,7 +118,7 @@ class BuiltInDefaultValue { return BuiltInDefaultValueGetter::Get(); } -#endif // GTEST_HAS_STD_TYPE_TRAITS_ +#endif // GTEST_LANG_CXX11 }; // This partial specialization says that we use the same built-in diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 9447c22..0128663 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -218,7 +218,7 @@ class MyNonDefaultConstructible { int value_; }; -#if GTEST_HAS_STD_TYPE_TRAITS_ +#if GTEST_LANG_CXX11 TEST(BuiltInDefaultValueTest, ExistsForDefaultConstructibleType) { EXPECT_TRUE(BuiltInDefaultValue::Exists()); @@ -228,7 +228,7 @@ TEST(BuiltInDefaultValueTest, IsDefaultConstructedForDefaultConstructibleType) { EXPECT_EQ(42, BuiltInDefaultValue::Get().value()); } -#endif // GTEST_HAS_STD_TYPE_TRAITS_ +#endif // GTEST_LANG_CXX11 TEST(BuiltInDefaultValueTest, DoesNotExistForNonDefaultConstructibleType) { EXPECT_FALSE(BuiltInDefaultValue::Exists()); diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 7a10d90..ccbdb76 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -363,16 +363,14 @@ #if GTEST_STDLIB_CXX11 # define GTEST_HAS_STD_BEGIN_AND_END_ 1 # define GTEST_HAS_STD_FORWARD_LIST_ 1 -# if !defined(_MSC_VER) || (_MSC_FULL_VER >= 190023824) // works only with VS2015U2 and better +# if !defined(_MSC_VER) || (_MSC_FULL_VER >= 190023824) +// works only with VS2015U2 and better # define GTEST_HAS_STD_FUNCTION_ 1 # endif # define GTEST_HAS_STD_INITIALIZER_LIST_ 1 # define GTEST_HAS_STD_MOVE_ 1 -# define GTEST_HAS_STD_SHARED_PTR_ 1 -# define GTEST_HAS_STD_TYPE_TRAITS_ 1 # define GTEST_HAS_STD_UNIQUE_PTR_ 1 -# define GTEST_HAS_UNORDERED_MAP_ 1 -# define GTEST_HAS_UNORDERED_SET_ 1 +# define GTEST_HAS_STD_SHARED_PTR_ 1 #endif // C++11 specifies that provides std::tuple. @@ -982,13 +980,13 @@ using ::std::tuple_size; # endif #elif __GNUC__ >= 4 || defined(__clang__) # define GTEST_API_ __attribute__((visibility ("default"))) -#endif // _MSC_VER +#endif // _MSC_VER -#endif // GTEST_API_ +#endif // GTEST_API_ #ifndef GTEST_API_ # define GTEST_API_ -#endif // GTEST_API_ +#endif // GTEST_API_ #ifndef GTEST_DEFAULT_DEATH_TEST_STYLE # define GTEST_DEFAULT_DEATH_TEST_STYLE "fast" diff --git a/googletest/test/gtest-printers_test.cc b/googletest/test/gtest-printers_test.cc index cd7c5d3..686e62a 100644 --- a/googletest/test/gtest-printers_test.cc +++ b/googletest/test/gtest-printers_test.cc @@ -50,19 +50,6 @@ #include "gtest/gtest.h" -// hash_map and hash_set are available under Visual C++, or on Linux. -#if GTEST_HAS_UNORDERED_MAP_ -# include // NOLINT -#elif GTEST_HAS_HASH_MAP_ -# include // NOLINT -#endif // GTEST_HAS_HASH_MAP_ - -#if GTEST_HAS_UNORDERED_SET_ -# include // NOLINT -#elif GTEST_HAS_HASH_SET_ -# include // NOLINT -#endif // GTEST_HAS_HASH_SET_ - #if GTEST_HAS_STD_FORWARD_LIST_ # include // NOLINT #endif // GTEST_HAS_STD_FORWARD_LIST_ @@ -240,50 +227,6 @@ using ::testing::internal::UniversalTersePrint; using ::testing::internal::UniversalTersePrintTupleFieldsToStrings; #endif - -// The hash_* classes are not part of the C++ standard. STLport -// defines them in namespace std. MSVC defines them in ::stdext. GCC -// defines them in ::. -#if GTEST_HAS_UNORDERED_MAP_ - -#define GTEST_HAS_HASH_MAP_ 1 -template -using hash_map = ::std::unordered_map; -template -using hash_multimap = ::std::unordered_multimap; - -#elif GTEST_HAS_HASH_MAP_ - -#ifdef _STLP_HASH_MAP // We got from STLport. -using ::std::hash_map; -using ::std::hash_multimap; -#elif _MSC_VER -using ::stdext::hash_map; -using ::stdext::hash_multimap; -#endif - -#endif - -#if GTEST_HAS_UNORDERED_SET_ - -#define GTEST_HAS_HASH_SET_ 1 -template -using hash_set = ::std::unordered_set; -template -using hash_multiset = ::std::unordered_multiset; - -#elif GTEST_HAS_HASH_SET_ - -#ifdef _STLP_HASH_MAP // We got from STLport. -using ::std::hash_map; -using ::std::hash_multimap; -#elif _MSC_VER -using ::stdext::hash_map; -using ::stdext::hash_multimap; -#endif - -#endif - // Prints a value to a string using the universal value printer. This // is a helper for testing UniversalPrinter::Print() for various types. template -- cgit v0.12 From a719320a3ce448dad588f0d5506e47fe84fa9d16 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 13 Mar 2018 11:53:27 -0400 Subject: fixing, was removing too much --- googletest/test/gtest-printers_test.cc | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/googletest/test/gtest-printers_test.cc b/googletest/test/gtest-printers_test.cc index 686e62a..1584de4 100644 --- a/googletest/test/gtest-printers_test.cc +++ b/googletest/test/gtest-printers_test.cc @@ -50,6 +50,15 @@ #include "gtest/gtest.h" +// hash_set are available under Visual C++, or on Linux. +#if GTEST_HAS_HASH_MAP_ +# include // NOLINT +#endif // GTEST_HAS_HASH_MAP_ + +#if GTEST_HAS_HASH_SET_ +# include // NOLINT +#endif // GTEST_HAS_HASH_SET_ + #if GTEST_HAS_STD_FORWARD_LIST_ # include // NOLINT #endif // GTEST_HAS_STD_FORWARD_LIST_ @@ -227,6 +236,34 @@ using ::testing::internal::UniversalTersePrint; using ::testing::internal::UniversalTersePrintTupleFieldsToStrings; #endif + +// The hash_* classes are not part of the C++ standard. STLport +// defines them in namespace std. MSVC defines them in ::stdext. GCC +// defines them in ::. +#if GTEST_HAS_HASH_MAP_ + +#ifdef _STLP_HASH_MAP // We got from STLport. +using ::std::hash_map; +using ::std::hash_multimap; +#elif _MSC_VER +using ::stdext::hash_map; +using ::stdext::hash_multimap; +#endif + +#endif + +#if GTEST_HAS_HASH_SET_ + +#ifdef _STLP_HASH_MAP // We got from STLport. +using ::std::hash_map; +using ::std::hash_multimap; +#elif _MSC_VER +using ::stdext::hash_map; +using ::stdext::hash_multimap; +#endif + +#endif + // Prints a value to a string using the universal value printer. This // is a helper for testing UniversalPrinter::Print() for various types. template -- cgit v0.12 From 2814b4b08910d62f8516cd3e4e77ef99ee7360e9 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 13 Mar 2018 16:02:05 -0400 Subject: merging, merging --- googletest/include/gtest/internal/gtest-port.h | 2 + googletest/test/gtest-printers_test.cc | 60 +++++++++----------------- 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index ccbdb76..3e4f7b5 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -371,6 +371,8 @@ # define GTEST_HAS_STD_MOVE_ 1 # define GTEST_HAS_STD_UNIQUE_PTR_ 1 # define GTEST_HAS_STD_SHARED_PTR_ 1 +# define GTEST_HAS_UNORDERED_MAP_ 1 +# define GTEST_HAS_UNORDERED_SET_ 1 #endif // C++11 specifies that provides std::tuple. diff --git a/googletest/test/gtest-printers_test.cc b/googletest/test/gtest-printers_test.cc index 1584de4..cf8bcce 100644 --- a/googletest/test/gtest-printers_test.cc +++ b/googletest/test/gtest-printers_test.cc @@ -50,14 +50,13 @@ #include "gtest/gtest.h" -// hash_set are available under Visual C++, or on Linux. -#if GTEST_HAS_HASH_MAP_ -# include // NOLINT -#endif // GTEST_HAS_HASH_MAP_ +#if GTEST_HAS_UNORDERED_MAP_ +# include // NOLINT +#endif // GTEST_HAS_UNORDERED_MAP_ -#if GTEST_HAS_HASH_SET_ -# include // NOLINT -#endif // GTEST_HAS_HASH_SET_ +#if GTEST_HAS_UNORDERED_SET_ +# include // NOLINT +#endif // GTEST_HAS_UNORDERED_SET_ #if GTEST_HAS_STD_FORWARD_LIST_ # include // NOLINT @@ -236,34 +235,6 @@ using ::testing::internal::UniversalTersePrint; using ::testing::internal::UniversalTersePrintTupleFieldsToStrings; #endif - -// The hash_* classes are not part of the C++ standard. STLport -// defines them in namespace std. MSVC defines them in ::stdext. GCC -// defines them in ::. -#if GTEST_HAS_HASH_MAP_ - -#ifdef _STLP_HASH_MAP // We got from STLport. -using ::std::hash_map; -using ::std::hash_multimap; -#elif _MSC_VER -using ::stdext::hash_map; -using ::stdext::hash_multimap; -#endif - -#endif - -#if GTEST_HAS_HASH_SET_ - -#ifdef _STLP_HASH_MAP // We got from STLport. -using ::std::hash_map; -using ::std::hash_multimap; -#elif _MSC_VER -using ::stdext::hash_map; -using ::stdext::hash_multimap; -#endif - -#endif - // Prints a value to a string using the universal value printer. This // is a helper for testing UniversalPrinter::Print() for various types. template @@ -848,7 +819,13 @@ TEST(PrintStlContainerTest, NonEmptyDeque) { EXPECT_EQ("{ 1, 3 }", Print(non_empty)); } -#if GTEST_HAS_HASH_MAP_ +#if GTEST_HAS_UNORDERED_MAP_ + +template +using hash_map = ::std::unordered_map; +template +using hash_multimap = ::std::unordered_multimap; + TEST(PrintStlContainerTest, OneElementHashMap) { hash_map map1; @@ -868,9 +845,14 @@ TEST(PrintStlContainerTest, HashMultiMap) { << " where Print(map1) returns \"" << result << "\"."; } -#endif // GTEST_HAS_HASH_MAP_ +#endif // GTEST_HAS_UNORDERED_MAP_ + +#if GTEST_HAS_UNORDERED_SET_ -#if GTEST_HAS_HASH_SET_ +template +using hash_set = ::std::unordered_set; +template +using hash_multiset = ::std::unordered_multiset; TEST(PrintStlContainerTest, HashSet) { hash_set set1; @@ -907,7 +889,7 @@ TEST(PrintStlContainerTest, HashMultiSet) { EXPECT_TRUE(std::equal(a, a + kSize, numbers.begin())); } -#endif // GTEST_HAS_HASH_SET_ +#endif // GTEST_HAS_UNORDERED_SET_ TEST(PrintStlContainerTest, List) { const std::string a[] = {"hello", "world"}; -- cgit v0.12 From 262aaf2f1dbf13df1aa0c303595b45981824fc8a Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 14 Mar 2018 10:49:18 -0400 Subject: erging, cont --- googletest/test/gtest-printers_test.cc | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/googletest/test/gtest-printers_test.cc b/googletest/test/gtest-printers_test.cc index cf8bcce..ccac35b 100644 --- a/googletest/test/gtest-printers_test.cc +++ b/googletest/test/gtest-printers_test.cc @@ -821,20 +821,14 @@ TEST(PrintStlContainerTest, NonEmptyDeque) { #if GTEST_HAS_UNORDERED_MAP_ -template -using hash_map = ::std::unordered_map; -template -using hash_multimap = ::std::unordered_multimap; - - TEST(PrintStlContainerTest, OneElementHashMap) { - hash_map map1; + ::std::unordered_map map1; map1[1] = 'a'; EXPECT_EQ("{ (1, 'a' (97, 0x61)) }", Print(map1)); } TEST(PrintStlContainerTest, HashMultiMap) { - hash_multimap map1; + ::std::unordered_multimap map1; map1.insert(make_pair(5, true)); map1.insert(make_pair(5, false)); @@ -849,13 +843,8 @@ TEST(PrintStlContainerTest, HashMultiMap) { #if GTEST_HAS_UNORDERED_SET_ -template -using hash_set = ::std::unordered_set; -template -using hash_multiset = ::std::unordered_multiset; - TEST(PrintStlContainerTest, HashSet) { - hash_set set1; + ::std::unordered_set set1; set1.insert(1); EXPECT_EQ("{ 1 }", Print(set1)); } @@ -863,7 +852,7 @@ TEST(PrintStlContainerTest, HashSet) { TEST(PrintStlContainerTest, HashMultiSet) { const int kSize = 5; int a[kSize] = { 1, 1, 2, 5, 1 }; - hash_multiset set1(a, a + kSize); + ::std::unordered_multiset set1(a, a + kSize); // Elements of hash_multiset can be printed in any order. const std::string result = Print(set1); -- cgit v0.12 From a178cc7ef73ce7e6e7e688d3d5cbccfc3c1d5d6b Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 15 Mar 2018 14:31:37 -0400 Subject: merge, again, IsRecursiveContainer --- googlemock/include/gmock/gmock-spec-builders.h | 1 + googlemock/test/gmock-matchers_test.cc | 1 + googletest/include/gtest/gtest-printers.h | 12 ++-- googletest/include/gtest/internal/gtest-internal.h | 75 ++++++++++++++++++---- googletest/src/gtest.cc | 4 +- googletest/test/gtest_unittest.cc | 50 +++++++++++++++ 6 files changed, 123 insertions(+), 20 deletions(-) diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index c1b6301..f8e1c6a 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -563,6 +563,7 @@ class ExpectationSet { public: // A bidirectional iterator that can read a const element in the set. typedef Expectation::Set::const_iterator const_iterator; + typedef Expectation::Set::iterator iterator; // An object stored in the set. This is an alias of Expectation. typedef Expectation::Set::value_type value_type; diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 829935e..f7bf2a8 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -4526,6 +4526,7 @@ class Streamlike { class ConstIter; public: typedef ConstIter const_iterator; + typedef ConstIter iterator; typedef T value_type; template diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 2c83c3f..36f4042 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -509,17 +509,19 @@ void PrintTo(const T& value, ::std::ostream* os) { // function pointers so that the `*os << p` in the object pointer overload // doesn't cause that warning either. DefaultPrintTo( - WrapPrinterType< - (sizeof(IsContainerTest(0)) == sizeof(IsContainer)) && !IsRecursiveContainer::value - ? kPrintContainer : !is_pointer::value - ? kPrintOther + WrapPrinterType < + (sizeof(IsContainerTest(0)) == sizeof(IsContainer)) && + !IsRecursiveContainer::value + ? kPrintContainer + : !is_pointer::value + ? kPrintOther #if GTEST_LANG_CXX11 : std::is_function::type>::value #else : !internal::ImplicitlyConvertible::value #endif ? kPrintFunctionPointer - : kPrintPointer>(), + : kPrintPointer > (), value, os); } diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index e87f85e..612f8a4 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -875,8 +875,11 @@ struct IsAProtocolMessage // a container class by checking the type of IsContainerTest(0). // The value of the expression is insignificant. // -// Note that we look for both C::iterator and C::const_iterator. The -// reason is that C++ injects the name of a class as a member of the +// In C++11 mode we check the existence of a const_iterator and that an +// iterator is properly implemented for the container. +// +// For pre-C++11 that we look for both C::iterator and C::const_iterator. +// The reason is that C++ injects the name of a class as a member of the // class itself (e.g. you can refer to class iterator as either // 'iterator' or 'iterator::iterator'). If we look for C::iterator // only, for example, we would mistakenly think that a class named @@ -886,20 +889,52 @@ struct IsAProtocolMessage // IsContainerTest(typename C::const_iterator*) and // IsContainerTest(...) doesn't work with Visual Age C++ and Sun C++. typedef int IsContainer; +#if GTEST_LANG_CXX11 +template ().begin()), + class = decltype(::std::declval().end()), + class = decltype(++::std::declval()), + class = decltype(*::std::declval()), + class = typename C::const_iterator> +IsContainer IsContainerTest(int /* dummy */) { + return 0; +} +#else template IsContainer IsContainerTest(int /* dummy */, typename C::iterator* /* it */ = NULL, typename C::const_iterator* /* const_it */ = NULL) { return 0; } +#endif // GTEST_LANG_CXX11 typedef char IsNotContainer; template IsNotContainer IsContainerTest(long /* dummy */) { return '\0'; } -template (0)) == sizeof(IsContainer) -> +// Trait to detect whether a type T is a hash table. +// The heuristic used is that the type contains an inner type `hasher` and does +// not contain an inner type `reverse_iterator`. +// If the container is iterable in reverse, then order might actually matter. +template +struct IsHashTable { + private: + template + static char test(typename U::hasher*, typename U::reverse_iterator*); + template + static int test(typename U::hasher*, ...); + template + static char test(...); + + public: + static const bool value = sizeof(test(0, 0)) == sizeof(int); +}; + +template +const bool IsHashTable::value; + +template (0)) == sizeof(IsContainer)> struct IsRecursiveContainerImpl; template @@ -907,19 +942,34 @@ struct IsRecursiveContainerImpl : public false_type {}; template struct IsRecursiveContainerImpl { - typedef - typename IteratorTraits::value_type - value_type; + template + struct VoidT { + typedef void value_type; + }; + template + struct PathTraits { + typedef typename C1::const_iterator::value_type value_type; + }; + template + struct PathTraits< + C2, typename VoidT::value_type> { + typedef typename C2::iterator::value_type value_type; + }; + typedef typename IteratorTraits::value_type value_type; +#if GTEST_LANG_CXX11 + typedef std::is_same type; +#else typedef is_same type; +#endif }; // IsRecursiveContainer is a unary compile-time predicate that -// evaluates whether C is a recursive container type. A recursive container +// evaluates whether C is a recursive container type. A recursive container // type is a container type whose value_type is equal to the container type -// itself. An example for a recursive container type is -// boost::filesystem::path, whose iterator has a value_type that is equal to +// itself. An example for a recursive container type is +// boost::filesystem::path, whose iterator has a value_type that is equal to // boost::filesystem::path. -template +template struct IsRecursiveContainer : public IsRecursiveContainerImpl::type {}; // EnableIf::type is void when 'Cond' is true, and @@ -1218,4 +1268,3 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ - diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 74df549..d22679f 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -5185,8 +5185,8 @@ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id) { // each TestCase and TestInfo object. // If shard_tests == true, further filters tests based on sharding // variables in the environment - see -// https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md . -// Returns the number of tests that should run. +// https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md +// . Returns the number of tests that should run. int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) { const Int32 total_shards = shard_tests == HONOR_SHARDING_PROTOCOL ? Int32FromEnvOrDie(kTestTotalShards, -1) : -1; diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 11af9c9..3791592 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -64,6 +64,9 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) { #include #include #include +#if GTEST_LANG_CXX11 +#include +#endif // GTEST_LANG_CXX11 #include "gtest/gtest-spi.h" #include "src/gtest-internal-inl.h" @@ -258,6 +261,8 @@ using testing::internal::IsContainer; using testing::internal::IsContainerTest; using testing::internal::IsNotContainer; using testing::internal::NativeArray; +using testing::internal::OsStackTraceGetter; +using testing::internal::OsStackTraceGetterInterface; using testing::internal::ParseInt32Flag; using testing::internal::RelationToSourceCopy; using testing::internal::RelationToSourceReference; @@ -274,6 +279,7 @@ using testing::internal::String; using testing::internal::TestEventListenersAccessor; using testing::internal::TestResultAccessor; using testing::internal::UInt32; +using testing::internal::UnitTestImpl; using testing::internal::WideStringToUtf8; using testing::internal::edit_distance::CalculateOptimalEdits; using testing::internal::edit_distance::CreateUnifiedDiff; @@ -7526,6 +7532,50 @@ TEST(IsContainerTestTest, WorksForContainer) { sizeof(IsContainerTest >(0))); } +#if GTEST_LANG_CXX11 +struct ConstOnlyContainerWithPointerIterator { + using const_iterator = int*; + const_iterator begin() const; + const_iterator end() const; +}; + +struct ConstOnlyContainerWithClassIterator { + struct const_iterator { + const int& operator*() const; + const_iterator& operator++(/* pre-increment */); + }; + const_iterator begin() const; + const_iterator end() const; +}; + +TEST(IsContainerTestTest, ConstOnlyContainer) { + EXPECT_EQ(sizeof(IsContainer), + sizeof(IsContainerTest(0))); + EXPECT_EQ(sizeof(IsContainer), + sizeof(IsContainerTest(0))); +} +#endif // GTEST_LANG_CXX11 + +// Tests IsHashTable. +struct AHashTable { + typedef void hasher; +}; +struct NotReallyAHashTable { + typedef void hasher; + typedef void reverse_iterator; +}; +TEST(IsHashTable, Basic) { + EXPECT_TRUE(testing::internal::IsHashTable::value); + EXPECT_FALSE(testing::internal::IsHashTable::value); +#if GTEST_LANG_CXX11 + EXPECT_FALSE(testing::internal::IsHashTable>::value); + EXPECT_TRUE(testing::internal::IsHashTable>::value); +#endif // GTEST_LANG_CXX11 +#if GTEST_HAS_HASH_SET_ + EXPECT_TRUE(testing::internal::IsHashTable>::value); +#endif // GTEST_HAS_HASH_SET_ +} + // Tests ArrayEq(). TEST(ArrayEqTest, WorksForDegeneratedArrays) { -- cgit v0.12 From 080fcbe0aae28dec00c2903ea04f2d2b022deb12 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 16 Mar 2018 13:36:36 -0400 Subject: cl 189032107 --- googlemock/include/gmock/gmock-spec-builders.h | 1 - googlemock/test/gmock-matchers_test.cc | 1 - googletest/include/gtest/internal/gtest-internal.h | 26 ++++++++-------------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index f8e1c6a..c1b6301 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -563,7 +563,6 @@ class ExpectationSet { public: // A bidirectional iterator that can read a const element in the set. typedef Expectation::Set::const_iterator const_iterator; - typedef Expectation::Set::iterator iterator; // An object stored in the set. This is an alias of Expectation. typedef Expectation::Set::value_type value_type; diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index f7bf2a8..829935e 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -4526,7 +4526,6 @@ class Streamlike { class ConstIter; public: typedef ConstIter const_iterator; - typedef ConstIter iterator; typedef T value_type; template diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 612f8a4..6e904a8 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -940,27 +940,19 @@ struct IsRecursiveContainerImpl; template struct IsRecursiveContainerImpl : public false_type {}; +// Since the IsRecursiveContainerImpl depends on the IsContainerTest we need to +// obey the same inconsistencies as the IsContainerTest, namely check if +// something is a container is relying on only const_iterator in C++11 and +// is relying on both const_iterator and iterator otherwise template struct IsRecursiveContainerImpl { - template - struct VoidT { - typedef void value_type; - }; - template - struct PathTraits { - typedef typename C1::const_iterator::value_type value_type; - }; - template - struct PathTraits< - C2, typename VoidT::value_type> { - typedef typename C2::iterator::value_type value_type; - }; - typedef typename IteratorTraits::value_type value_type; -#if GTEST_LANG_CXX11 - typedef std::is_same type; + #if GTEST_LANG_CXX11 + typedef typename IteratorTraits::value_type + value_type; #else - typedef is_same type; + typedef typename IteratorTraits::value_type value_type; #endif + typedef is_same type; }; // IsRecursiveContainer is a unary compile-time predicate that -- cgit v0.12 From a3c2e107aeb7e821b76164cea366094ce420b656 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 16 Mar 2018 15:56:31 -0400 Subject: cl 189032107, again --- googletest/include/gtest/internal/gtest-internal.h | 23 ++++++++++++++++++---- googletest/test/gtest-printers_test.cc | 1 - 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 6e904a8..ffc22f9 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -933,19 +933,34 @@ struct IsHashTable { template const bool IsHashTable::value; +template +struct VoidT { + typedef void value_type; +}; + +template +struct HasValueType : false_type {}; +template +struct HasValueType > : true_type { +}; + template (0)) == sizeof(IsContainer)> + bool = sizeof(IsContainerTest(0)) == sizeof(IsContainer), + bool = HasValueType::value> struct IsRecursiveContainerImpl; -template -struct IsRecursiveContainerImpl : public false_type {}; +template +struct IsRecursiveContainerImpl : public false_type {}; // Since the IsRecursiveContainerImpl depends on the IsContainerTest we need to // obey the same inconsistencies as the IsContainerTest, namely check if // something is a container is relying on only const_iterator in C++11 and // is relying on both const_iterator and iterator otherwise template -struct IsRecursiveContainerImpl { +struct IsRecursiveContainerImpl : public false_type {}; + +template +struct IsRecursiveContainerImpl { #if GTEST_LANG_CXX11 typedef typename IteratorTraits::value_type value_type; diff --git a/googletest/test/gtest-printers_test.cc b/googletest/test/gtest-printers_test.cc index ccac35b..4487978 100644 --- a/googletest/test/gtest-printers_test.cc +++ b/googletest/test/gtest-printers_test.cc @@ -195,7 +195,6 @@ class PathLike { struct iterator { typedef PathLike value_type; }; - typedef iterator const_iterator; PathLike() {} -- cgit v0.12 From 691e38e518336fa8a9b51915735fe869edb24c08 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 21 Mar 2018 16:31:31 -0400 Subject: More merges --- googletest/include/gtest/internal/gtest-port.h | 3 +- googletest/src/gtest-port.cc | 52 +++++++++++++------------- googletest/src/gtest.cc | 8 +++- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 3e4f7b5..53c1b5f 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -2675,7 +2675,8 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value); // corresponding to the given Google Test flag. bool BoolFromGTestEnv(const char* flag, bool default_val); GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val); -std::string StringFromGTestEnv(const char* flag, const char* default_val); +std::string SpecialCase_Output_Flag_XML_OUTPUT_FILE_Env(); +const char* StringFromGTestEnv(const char* flag, const char* default_val); } // namespace internal } // namespace testing diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index 99791f9..ffea9b3 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -1185,11 +1185,12 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value) { bool BoolFromGTestEnv(const char* flag, bool default_value) { #if defined(GTEST_GET_BOOL_FROM_ENV_) return GTEST_GET_BOOL_FROM_ENV_(flag, default_value); -#endif // defined(GTEST_GET_BOOL_FROM_ENV_) +#else const std::string env_var = FlagToEnvVar(flag); const char* const string_value = posix::GetEnv(env_var.c_str()); return string_value == NULL ? default_value : strcmp(string_value, "0") != 0; +#endif // defined(GTEST_GET_BOOL_FROM_ENV_) } // Reads and returns a 32-bit integer stored in the environment @@ -1198,7 +1199,7 @@ bool BoolFromGTestEnv(const char* flag, bool default_value) { Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) { #if defined(GTEST_GET_INT32_FROM_ENV_) return GTEST_GET_INT32_FROM_ENV_(flag, default_value); -#endif // defined(GTEST_GET_INT32_FROM_ENV_) +#else const std::string env_var = FlagToEnvVar(flag); const char* const string_value = posix::GetEnv(env_var.c_str()); if (string_value == NULL) { @@ -1216,37 +1217,36 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) { } return result; +#endif // defined(GTEST_GET_INT32_FROM_ENV_) +} + +// As a special case for the 'output' flag, if GTEST_OUTPUT is not +// set, we look for XML_OUTPUT_FILE, which is set by the Bazel build +// system. The value of XML_OUTPUT_FILE is a filename without the +// "xml:" prefix of GTEST_OUTPUT. +// Note that this is meant to be called at the call site so it does +// not check that the flag is 'output' +// In essence this checks env. variable called XML_OUTPUT_FILE +// if it is set we prepend "xml:" to its value , if it not set we return "" +std::string SpecialCase_Output_Flag_XML_OUTPUT_FILE_Env(){ + std::string default_value_for_output_flag = ""; + const char* xml_output_file_env = posix::GetEnv("XML_OUTPUT_FILE"); + if (NULL != xml_output_file_env) { + default_value_for_output_flag = std::string("xml:") + xml_output_file_env; + } + return default_value_for_output_flag; } // Reads and returns the string environment variable corresponding to // the given flag; if it's not set, returns default_value. -std::string StringFromGTestEnv(const char* flag, const char* default_value) { +const char* StringFromGTestEnv(const char* flag, const char* default_value) { #if defined(GTEST_GET_STRING_FROM_ENV_) return GTEST_GET_STRING_FROM_ENV_(flag, default_value); -#endif // defined(GTEST_GET_STRING_FROM_ENV_) +#else const std::string env_var = FlagToEnvVar(flag); - const char* value = posix::GetEnv(env_var.c_str()); - if (value != NULL) { - return value; - } - - // As a special case for the 'output' flag, if GTEST_OUTPUT is not - // set, we look for XML_OUTPUT_FILE, which is set by the Bazel build - // system. The value of XML_OUTPUT_FILE is a filename without the - // "xml:" prefix of GTEST_OUTPUT. - // - // The net priority order after flag processing is thus: - // --gtest_output command line flag - // GTEST_OUTPUT environment variable - // XML_OUTPUT_FILE environment variable - // 'default_value' - if (strcmp(flag, "output") == 0) { - value = posix::GetEnv("XML_OUTPUT_FILE"); - if (value != NULL) { - return std::string("xml:") + value; - } - } - return default_value; + const char* const value = posix::GetEnv(env_var.c_str()); + return value == NULL ? default_value : value; +#endif // defined(GTEST_GET_STRING_FROM_ENV_) } } // namespace internal diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index d22679f..07fedd7 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -230,9 +230,15 @@ GTEST_DEFINE_string_( GTEST_DEFINE_bool_(list_tests, false, "List all tests without running them."); +// The net priority order after flag processing is thus: +// --gtest_output command line flag +// GTEST_OUTPUT environment variable +// XML_OUTPUT_FILE environment variable +// '' GTEST_DEFINE_string_( output, - internal::StringFromGTestEnv("output", ""), + internal::StringFromGTestEnv("output", + internal::SpecialCase_Output_Flag_XML_OUTPUT_FILE_Env().c_str()), "A format (defaults to \"xml\" but can be specified to be \"json\"), " "optionally followed by a colon and an output file name or directory. " "A directory is indicated by a trailing pathname separator. " -- cgit v0.12 From 0f6567954f42767e2f4a92d9f3b4afa679a65c16 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 22 Mar 2018 10:56:35 -0400 Subject: more merges --- googletest/include/gtest/internal/gtest-port.h | 2 +- googletest/src/gtest-port.cc | 2 +- googletest/src/gtest.cc | 2 +- googletest/test/gtest_list_tests_unittest.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 53c1b5f..751e176 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -2675,7 +2675,7 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value); // corresponding to the given Google Test flag. bool BoolFromGTestEnv(const char* flag, bool default_val); GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val); -std::string SpecialCase_Output_Flag_XML_OUTPUT_FILE_Env(); +std::string OutputFlagAlsoCheckEnvVar(); const char* StringFromGTestEnv(const char* flag, const char* default_val); } // namespace internal diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index ffea9b3..e710354 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -1228,7 +1228,7 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) { // not check that the flag is 'output' // In essence this checks env. variable called XML_OUTPUT_FILE // if it is set we prepend "xml:" to its value , if it not set we return "" -std::string SpecialCase_Output_Flag_XML_OUTPUT_FILE_Env(){ +std::string OutputFlagAlsoCheckEnvVar(){ std::string default_value_for_output_flag = ""; const char* xml_output_file_env = posix::GetEnv("XML_OUTPUT_FILE"); if (NULL != xml_output_file_env) { diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 07fedd7..9079af8 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -238,7 +238,7 @@ GTEST_DEFINE_bool_(list_tests, false, GTEST_DEFINE_string_( output, internal::StringFromGTestEnv("output", - internal::SpecialCase_Output_Flag_XML_OUTPUT_FILE_Env().c_str()), + internal::OutputFlagAlsoCheckEnvVar().c_str()), "A format (defaults to \"xml\" but can be specified to be \"json\"), " "optionally followed by a colon and an output file name or directory. " "A directory is indicated by a trailing pathname separator. " diff --git a/googletest/test/gtest_list_tests_unittest.py b/googletest/test/gtest_list_tests_unittest.py index ebf1a3c..0844f98 100755 --- a/googletest/test/gtest_list_tests_unittest.py +++ b/googletest/test/gtest_list_tests_unittest.py @@ -70,7 +70,7 @@ FooTest\. TypedTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\. TestA TestB -TypedTest/1\. # TypeParam = int\s*\*( __ptr64)? +TypedTest/1\. # TypeParam = int\s*\* TestA TestB TypedTest/2\. # TypeParam = .*MyArray @@ -79,7 +79,7 @@ TypedTest/2\. # TypeParam = .*MyArray My/TypeParamTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\. TestA TestB -My/TypeParamTest/1\. # TypeParam = int\s*\*( __ptr64)? +My/TypeParamTest/1\. # TypeParam = int\s*\* TestA TestB My/TypeParamTest/2\. # TypeParam = .*MyArray -- cgit v0.12 From da71e8c870d6edfa0822dacb74add4bb19bbf4c3 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 22 Mar 2018 10:58:18 -0400 Subject: more merges --- googletest/test/gtest_env_var_test.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/googletest/test/gtest_env_var_test.py b/googletest/test/gtest_env_var_test.py index 7af00ce..5361508 100755 --- a/googletest/test/gtest_env_var_test.py +++ b/googletest/test/gtest_env_var_test.py @@ -81,13 +81,14 @@ def TestFlag(flag, test_val, default_val): class GTestEnvVarTest(gtest_test_utils.TestCase): + def testEnvVarAffectsFlag(self): """Tests that environment variable should affect the corresponding flag.""" TestFlag('break_on_failure', '1', '0') TestFlag('color', 'yes', 'auto') TestFlag('filter', 'FooTest.Bar', '*') - SetEnvVar('XML_OUTPUT_FILE', None) # For 'output' test + SetEnvVar('XML_OUTPUT_FILE', None) # For 'output' test TestFlag('output', 'xml:tmp/foo.xml', '') TestFlag('print_time', '0', '1') TestFlag('repeat', '999', '1') @@ -107,7 +108,7 @@ class GTestEnvVarTest(gtest_test_utils.TestCase): AssertEq('xml:tmp/bar.xml', GetFlag('output')) def testXmlOutputFileOverride(self): - """Tests that $XML_OUTPUT_FILE is overridden by $GTEST_OUTPUT""" + """Tests that $XML_OUTPUT_FILE is overridden by $GTEST_OUTPUT.""" SetEnvVar('GTEST_OUTPUT', 'xml:tmp/foo.xml') SetEnvVar('XML_OUTPUT_FILE', 'tmp/bar.xml') -- cgit v0.12 From eaaa422c5265e65e9d175d7f3d6e58dad7d69de0 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 22 Mar 2018 11:48:21 -0400 Subject: Update appveyor.yml --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 84d9fbc..94b1c3a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -87,7 +87,7 @@ test_script: if ($env:generator -eq "MinGW Makefiles") { return # No test available for MinGW } - & ctest -C $env:configuration --timeout 300 --output-on-failure + & ctest -C $env:configuration --timeout 600 --output-on-failure if ($LastExitCode -ne 0) { throw "Exec: $ErrorMessage" } -- cgit v0.12 From 4e89c76db83684d4c5b86eb9186af3e33f5f4df0 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 22 Mar 2018 12:37:38 -0400 Subject: reverting gtest_list_tests_unittest.py --- googletest/test/gtest_list_tests_unittest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/test/gtest_list_tests_unittest.py b/googletest/test/gtest_list_tests_unittest.py index 0844f98..ebf1a3c 100755 --- a/googletest/test/gtest_list_tests_unittest.py +++ b/googletest/test/gtest_list_tests_unittest.py @@ -70,7 +70,7 @@ FooTest\. TypedTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\. TestA TestB -TypedTest/1\. # TypeParam = int\s*\* +TypedTest/1\. # TypeParam = int\s*\*( __ptr64)? TestA TestB TypedTest/2\. # TypeParam = .*MyArray @@ -79,7 +79,7 @@ TypedTest/2\. # TypeParam = .*MyArray My/TypeParamTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\. TestA TestB -My/TypeParamTest/1\. # TypeParam = int\s*\* +My/TypeParamTest/1\. # TypeParam = int\s*\*( __ptr64)? TestA TestB My/TypeParamTest/2\. # TypeParam = .*MyArray -- cgit v0.12 From b7c568326c969c59a5f90e4731dc5b91f260c6f0 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 22 Mar 2018 15:35:37 -0400 Subject: merging, gmock -1 --- googlemock/include/gmock/gmock-matchers.h | 69 ++++++++++++++++--------- googlemock/src/gmock-matchers.cc | 77 +++++++++++++++------------- googlemock/test/gmock-internal-utils_test.cc | 28 ++++++++++ googlemock/test/gmock_output_test_.cc | 6 ++- 4 files changed, 120 insertions(+), 60 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 9522c85..044a323 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -323,7 +323,13 @@ class Matcher : public internal::MatcherBase { explicit Matcher() {} // NOLINT // Constructs a matcher from its implementation. - explicit Matcher(const MatcherInterface* impl) + explicit Matcher(const MatcherInterface* impl) + : internal::MatcherBase(impl) {} + + template + explicit Matcher(const MatcherInterface* impl, + typename internal::EnableIf::value>::type* = NULL) : internal::MatcherBase(impl) {} // Implicit constructor here allows people to write @@ -332,64 +338,79 @@ class Matcher : public internal::MatcherBase { }; // The following two specializations allow the user to write str -// instead of Eq(str) and "foo" instead of Eq("foo") when a string +// instead of Eq(str) and "foo" instead of Eq("foo") when a std::string // matcher is expected. template <> -class GTEST_API_ Matcher - : public internal::MatcherBase { +class GTEST_API_ Matcher + : public internal::MatcherBase { public: Matcher() {} - explicit Matcher(const MatcherInterface* impl) - : internal::MatcherBase(impl) {} + explicit Matcher(const MatcherInterface* impl) + : internal::MatcherBase(impl) {} // Allows the user to write str instead of Eq(str) sometimes, where - // str is a string object. - Matcher(const internal::string& s); // NOLINT + // str is a std::string object. + Matcher(const std::string& s); // NOLINT + +#if GTEST_HAS_GLOBAL_STRING + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a ::string object. + Matcher(const ::string& s); // NOLINT +#endif // GTEST_HAS_GLOBAL_STRING // Allows the user to write "foo" instead of Eq("foo") sometimes. Matcher(const char* s); // NOLINT }; template <> -class GTEST_API_ Matcher - : public internal::MatcherBase { +class GTEST_API_ Matcher + : public internal::MatcherBase { public: Matcher() {} - explicit Matcher(const MatcherInterface* impl) - : internal::MatcherBase(impl) {} + explicit Matcher(const MatcherInterface* impl) + : internal::MatcherBase(impl) {} // Allows the user to write str instead of Eq(str) sometimes, where // str is a string object. - Matcher(const internal::string& s); // NOLINT + Matcher(const std::string& s); // NOLINT + +#if GTEST_HAS_GLOBAL_STRING + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a ::string object. + Matcher(const ::string& s); // NOLINT +#endif // GTEST_HAS_GLOBAL_STRING // Allows the user to write "foo" instead of Eq("foo") sometimes. Matcher(const char* s); // NOLINT }; -#if GTEST_HAS_STRING_PIECE_ +#if GTEST_HAS_GLOBAL_STRING // The following two specializations allow the user to write str -// instead of Eq(str) and "foo" instead of Eq("foo") when a StringPiece +// instead of Eq(str) and "foo" instead of Eq("foo") when a ::string // matcher is expected. template <> -class GTEST_API_ Matcher - : public internal::MatcherBase { +class GTEST_API_ Matcher + : public internal::MatcherBase { public: Matcher() {} - explicit Matcher(const MatcherInterface* impl) - : internal::MatcherBase(impl) {} + explicit Matcher(const MatcherInterface* impl) + : internal::MatcherBase(impl) {} // Allows the user to write str instead of Eq(str) sometimes, where - // str is a string object. - Matcher(const internal::string& s); // NOLINT + // str is a std::string object. + Matcher(const std::string& s); // NOLINT + + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a ::string object. + Matcher(const ::string& s); // NOLINT // Allows the user to write "foo" instead of Eq("foo") sometimes. Matcher(const char* s); // NOLINT +}; - // Allows the user to pass StringPieces directly. - Matcher(StringPiece s); // NOLINT }; template <> @@ -1340,7 +1361,7 @@ class MatchesRegexMatcher { // Matches anything that can convert to std::string. // // This is a template, not just a plain function with const std::string&, - // because StringPiece has some interfering non-explicit constructors. + // because absl::string_view has some interfering non-explicit constructors. template bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { diff --git a/googlemock/src/gmock-matchers.cc b/googlemock/src/gmock-matchers.cc index 88e4008..a5ed686 100644 --- a/googlemock/src/gmock-matchers.cc +++ b/googlemock/src/gmock-matchers.cc @@ -44,60 +44,67 @@ namespace testing { -// Constructs a matcher that matches a const string& whose value is +// Constructs a matcher that matches a const std::string& whose value is // equal to s. -Matcher::Matcher(const internal::string& s) { - *this = Eq(s); +Matcher::Matcher(const std::string& s) { *this = Eq(s); } + +#if GTEST_HAS_GLOBAL_STRING +// Constructs a matcher that matches a const std::string& whose value is +// equal to s. +Matcher::Matcher(const ::string& s) { + *this = Eq(static_cast(s)); } +#endif // GTEST_HAS_GLOBAL_STRING -// Constructs a matcher that matches a const string& whose value is +// Constructs a matcher that matches a const std::string& whose value is // equal to s. -Matcher::Matcher(const char* s) { - *this = Eq(internal::string(s)); +Matcher::Matcher(const char* s) { + *this = Eq(std::string(s)); } -// Constructs a matcher that matches a string whose value is equal to s. -Matcher::Matcher(const internal::string& s) { *this = Eq(s); } +// Constructs a matcher that matches a std::string whose value is equal to +// s. +Matcher::Matcher(const std::string& s) { *this = Eq(s); } -// Constructs a matcher that matches a string whose value is equal to s. -Matcher::Matcher(const char* s) { - *this = Eq(internal::string(s)); +#if GTEST_HAS_GLOBAL_STRING +// Constructs a matcher that matches a std::string whose value is equal to +// s. +Matcher::Matcher(const ::string& s) { + *this = Eq(static_cast(s)); } +#endif // GTEST_HAS_GLOBAL_STRING + +// Constructs a matcher that matches a std::string whose value is equal to +// s. +Matcher::Matcher(const char* s) { *this = Eq(std::string(s)); } -#if GTEST_HAS_STRING_PIECE_ -// Constructs a matcher that matches a const StringPiece& whose value is +#if GTEST_HAS_GLOBAL_STRING +// Constructs a matcher that matches a const ::string& whose value is // equal to s. -Matcher::Matcher(const internal::string& s) { - *this = Eq(s); +Matcher::Matcher(const std::string& s) { + *this = Eq(static_cast<::string>(s)); } -// Constructs a matcher that matches a const StringPiece& whose value is +// Constructs a matcher that matches a const ::string& whose value is // equal to s. -Matcher::Matcher(const char* s) { - *this = Eq(internal::string(s)); -} +Matcher::Matcher(const ::string& s) { *this = Eq(s); } -// Constructs a matcher that matches a const StringPiece& whose value is +// Constructs a matcher that matches a const ::string& whose value is // equal to s. -Matcher::Matcher(StringPiece s) { - *this = Eq(s.ToString()); -} +Matcher::Matcher(const char* s) { *this = Eq(::string(s)); } -// Constructs a matcher that matches a StringPiece whose value is equal to s. -Matcher::Matcher(const internal::string& s) { - *this = Eq(s); +// Constructs a matcher that matches a ::string whose value is equal to s. +Matcher<::string>::Matcher(const std::string& s) { + *this = Eq(static_cast<::string>(s)); } -// Constructs a matcher that matches a StringPiece whose value is equal to s. -Matcher::Matcher(const char* s) { - *this = Eq(internal::string(s)); -} +// Constructs a matcher that matches a ::string whose value is equal to s. +Matcher<::string>::Matcher(const ::string& s) { *this = Eq(s); } + +// Constructs a matcher that matches a string whose value is equal to s. +Matcher<::string>::Matcher(const char* s) { *this = Eq(::string(s)); } +#endif // GTEST_HAS_GLOBAL_STRING -// Constructs a matcher that matches a StringPiece whose value is equal to s. -Matcher::Matcher(StringPiece s) { - *this = Eq(s.ToString()); -} -#endif // GTEST_HAS_STRING_PIECE_ namespace internal { diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index c7893ae..f8633df 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -44,7 +44,15 @@ #include "gmock/internal/gmock-port.h" #include "gtest/gtest.h" #include "gtest/gtest-spi.h" + +// Indicates that this translation unit is part of Google Test's +// implementation. It must come before gtest-internal-inl.h is +// included, or there will be a compiler error. This trick is to +// prevent a user from accidentally including gtest-internal-inl.h in +// their code. +#define GTEST_IMPLEMENTATION_ 1 #include "src/gtest-internal-inl.h" +#undef GTEST_IMPLEMENTATION_ #if GTEST_OS_CYGWIN # include // For ssize_t. NOLINT @@ -61,6 +69,26 @@ namespace internal { namespace { +TEST(JoinAsTupleTest, JoinsEmptyTuple) { + EXPECT_EQ("", JoinAsTuple(Strings())); +} + +TEST(JoinAsTupleTest, JoinsOneTuple) { + const char* fields[] = {"1"}; + EXPECT_EQ("1", JoinAsTuple(Strings(fields, fields + 1))); +} + +TEST(JoinAsTupleTest, JoinsTwoTuple) { + const char* fields[] = {"1", "a"}; + EXPECT_EQ("(1, a)", JoinAsTuple(Strings(fields, fields + 2))); +} + +TEST(JoinAsTupleTest, JoinsTenTuple) { + const char* fields[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; + EXPECT_EQ("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)", + JoinAsTuple(Strings(fields, fields + 10))); +} + TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) { EXPECT_EQ("", ConvertIdentifierNameToWords("")); EXPECT_EQ("", ConvertIdentifierNameToWords("_")); diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index 44cba34..d80e2b0 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -47,6 +47,7 @@ using testing::NaggyMock; using testing::Ref; using testing::Return; using testing::Sequence; +using testing::Value; class MockFoo { public: @@ -268,6 +269,10 @@ TEST_F(GMockOutputTest, CatchesLeakedMocks) { // Both foo1 and foo2 are deliberately leaked. } +MATCHER_P2(IsPair, first, second, "") { + return Value(arg.first, first) && Value(arg.second, second); +} + void TestCatchesLeakedMocksInAdHocTests() { MockFoo* foo = new MockFoo; @@ -280,7 +285,6 @@ void TestCatchesLeakedMocksInAdHocTests() { int main(int argc, char **argv) { testing::InitGoogleMock(&argc, argv); - // Ensures that the tests pass no matter what value of // --gmock_catch_leaked_mocks and --gmock_verbose the user specifies. testing::GMOCK_FLAG(catch_leaked_mocks) = true; -- cgit v0.12 From 466a49ae305145cf1fa32d172e4f5e8919ee6f4d Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 23 Mar 2018 11:23:54 -0400 Subject: gmock-matchers merging -2 --- googlemock/include/gmock/gmock-matchers.h | 260 ++++++++++++++++++++++++++++-- 1 file changed, 250 insertions(+), 10 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 044a323..dea1070 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -179,6 +179,35 @@ class MatcherInterface : public MatcherDescriberInterface { // virtual void DescribeNegationTo(::std::ostream* os) const; }; +namespace internal { + +// Converts a MatcherInterface to a MatcherInterface. +template +class MatcherInterfaceAdapter : public MatcherInterface { + public: + explicit MatcherInterfaceAdapter(const MatcherInterface* impl) + : impl_(impl) {} + virtual ~MatcherInterfaceAdapter() { delete impl_; } + + virtual void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); } + + virtual void DescribeNegationTo(::std::ostream* os) const { + impl_->DescribeNegationTo(os); + } + + virtual bool MatchAndExplain(const T& x, + MatchResultListener* listener) const { + return impl_->MatchAndExplain(x, listener); + } + + private: + const MatcherInterface* const impl_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(MatcherInterfaceAdapter); +}; + +} // namespace internal + // A match result listener that stores the explanation in a string. class StringMatchResultListener : public MatchResultListener { public: @@ -290,6 +319,14 @@ class MatcherBase { explicit MatcherBase(const MatcherInterface* impl) : impl_(impl) {} + template + explicit MatcherBase( + const MatcherInterface* impl, + typename internal::EnableIf< + !internal::IsSame::value>::type* = + NULL) + : impl_(new internal::MatcherInterfaceAdapter(impl)) {} + virtual ~MatcherBase() {} private: @@ -551,21 +588,18 @@ class MatcherCastImpl { return CastImpl( polymorphic_matcher_or_value, BooleanConstant< - internal::ImplicitlyConvertible >::value>()); + internal::ImplicitlyConvertible >::value>(), + BooleanConstant< + internal::ImplicitlyConvertible::value>()); } private: - static Matcher CastImpl(const M& value, BooleanConstant) { - // M can't be implicitly converted to Matcher, so M isn't a polymorphic - // matcher. It must be a value then. Use direct initialization to create - // a matcher. - return Matcher(ImplicitCast_(value)); - } - + template static Matcher CastImpl(const M& polymorphic_matcher_or_value, - BooleanConstant) { + BooleanConstant /* convertible_to_matcher */, + BooleanConstant) { // M is implicitly convertible to Matcher, which means that either - // M is a polymorhpic matcher or Matcher has an implicit constructor + // M is a polymorphic matcher or Matcher has an implicit constructor // from M. In both cases using the implicit conversion will produce a // matcher. // @@ -574,6 +608,29 @@ class MatcherCastImpl { // (first to create T from M and then to create Matcher from T). return polymorphic_matcher_or_value; } + + // M can't be implicitly converted to Matcher, so M isn't a polymorphic + // matcher. It's a value of a type implicitly convertible to T. Use direct + // initialization to create a matcher. + static Matcher CastImpl( + const M& value, BooleanConstant /* convertible_to_matcher */, + BooleanConstant /* convertible_to_T */) { + return Matcher(ImplicitCast_(value)); + } + + // M can't be implicitly converted to either Matcher or T. Attempt to use + // polymorphic matcher Eq(value) in this case. + // + // Note that we first attempt to perform an implicit cast on the value and + // only fall back to the polymorphic Eq() matcher afterwards because the + // latter calls bool operator==(const Lhs& lhs, const Rhs& rhs) in the end + // which might be undefined even when Rhs is implicitly convertible to Lhs + // (e.g. std::pair vs. std::pair). + // + // We don't define this method inline as we need the declaration of Eq(). + static Matcher CastImpl( + const M& value, BooleanConstant /* convertible_to_matcher */, + BooleanConstant /* convertible_to_T */); }; // This more specialized version is used when MatcherCast()'s argument @@ -2057,6 +2114,78 @@ class FloatingEqMatcher { GTEST_DISALLOW_ASSIGN_(FloatingEqMatcher); }; +// A 2-tuple ("binary") wrapper around FloatingEqMatcher: +// FloatingEq2Matcher() matches (x, y) by matching FloatingEqMatcher(x, false) +// against y, and FloatingEq2Matcher(e) matches FloatingEqMatcher(x, false, e) +// against y. The former implements "Eq", the latter "Near". At present, there +// is no version that compares NaNs as equal. +template +class FloatingEq2Matcher { + public: + FloatingEq2Matcher() : FloatingEq2Matcher(-1, false) {} + + explicit FloatingEq2Matcher(bool nan_eq_nan) + : FloatingEq2Matcher(-1, nan_eq_nan) {} + + explicit FloatingEq2Matcher(FloatType max_abs_error) + : FloatingEq2Matcher(max_abs_error, false) {} + + FloatingEq2Matcher(FloatType max_abs_error, bool nan_eq_nan) + : max_abs_error_(max_abs_error), + nan_eq_nan_(nan_eq_nan) {} + + template + operator Matcher< ::testing::tuple >() const { + return MakeMatcher( + new Impl< ::testing::tuple >(max_abs_error_, nan_eq_nan_)); + } + template + operator Matcher&>() const { + return MakeMatcher( + new Impl&>(max_abs_error_, nan_eq_nan_)); + } + + private: + static ::std::ostream& GetDesc(::std::ostream& os) { // NOLINT + return os << "an almost-equal pair"; + } + + template + class Impl : public MatcherInterface { + public: + Impl(FloatType max_abs_error, bool nan_eq_nan) : + max_abs_error_(max_abs_error), + nan_eq_nan_(nan_eq_nan) {} + + virtual bool MatchAndExplain(Tuple args, + MatchResultListener* listener) const { + if (max_abs_error_ == -1) { + FloatingEqMatcher fm(::testing::get<0>(args), nan_eq_nan_); + return static_cast >(fm).MatchAndExplain( + ::testing::get<1>(args), listener); + } else { + FloatingEqMatcher fm(::testing::get<0>(args), nan_eq_nan_, + max_abs_error_); + return static_cast >(fm).MatchAndExplain( + ::testing::get<1>(args), listener); + } + } + virtual void DescribeTo(::std::ostream* os) const { + *os << "are " << GetDesc; + } + virtual void DescribeNegationTo(::std::ostream* os) const { + *os << "aren't " << GetDesc; + } + + private: + FloatType max_abs_error_; + const bool nan_eq_nan_; + }; + + FloatType max_abs_error_; + const bool nan_eq_nan_; +}; + // Implements the Pointee(m) matcher for matching a pointer whose // pointee matches matcher m. The pointer can be either raw or smart. template @@ -2953,6 +3082,50 @@ class EachMatcher { GTEST_DISALLOW_ASSIGN_(EachMatcher); }; +struct Rank1 {}; +struct Rank0 : Rank1 {}; + +namespace pair_getters { +#if GTEST_LANG_CXX11 +using std::get; +template +auto First(T& x, Rank1) -> decltype(get<0>(x)) { // NOLINT + return get<0>(x); +} +template +auto First(T& x, Rank0) -> decltype((x.first)) { // NOLINT + return x.first; +} + +template +auto Second(T& x, Rank1) -> decltype(get<1>(x)) { // NOLINT + return get<1>(x); +} +template +auto Second(T& x, Rank0) -> decltype((x.second)) { // NOLINT + return x.second; +} +#else +template +typename T::first_type& First(T& x, Rank0) { // NOLINT + return x.first; +} +template +const typename T::first_type& First(const T& x, Rank0) { + return x.first; +} + +template +typename T::second_type& Second(T& x, Rank0) { // NOLINT + return x.second; +} +template +const typename T::second_type& Second(const T& x, Rank0) { + return x.second; +} +#endif // GTEST_LANG_CXX11 +} // namespace pair_getters + // Implements Key(inner_matcher) for the given argument pair type. // Key(inner_matcher) matches an std::pair whose 'first' field matches // inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an @@ -3717,6 +3890,65 @@ class VariantMatcher { } // namespace variant_matcher +namespace any_cast_matcher { + +// Overloads to allow AnyCastMatcher to do proper ADL lookup. +template +void any_cast() {} + +// Implements a matcher that any_casts the value. +template +class AnyCastMatcher { + public: + explicit AnyCastMatcher(const ::testing::Matcher& matcher) + : matcher_(matcher) {} + + template + bool MatchAndExplain(const AnyType& value, + ::testing::MatchResultListener* listener) const { + if (!listener->IsInterested()) { + const T* ptr = any_cast(&value); + return ptr != NULL && matcher_.Matches(*ptr); + } + + const T* elem = any_cast(&value); + if (elem == NULL) { + *listener << "whose value is not of type '" << GetTypeName() << "'"; + return false; + } + + StringMatchResultListener elem_listener; + const bool match = matcher_.MatchAndExplain(*elem, &elem_listener); + *listener << "whose value " << PrintToString(*elem) + << (match ? " matches" : " doesn't match"); + PrintIfNotEmpty(elem_listener.str(), listener->stream()); + return match; + } + + void DescribeTo(std::ostream* os) const { + *os << "is an 'any' type with value of type '" << GetTypeName() + << "' and the value "; + matcher_.DescribeTo(os); + } + + void DescribeNegationTo(std::ostream* os) const { + *os << "is an 'any' type with value of type other than '" << GetTypeName() + << "' or the value "; + matcher_.DescribeNegationTo(os); + } + + private: + static std::string GetTypeName() { +#if GTEST_HAS_RTTI + return internal::GetTypeName(); +#endif + return "the element type"; + } + + const ::testing::Matcher matcher_; +}; + +} // namespace any_cast_matcher } // namespace internal // ElementsAreArray(iterator_first, iterator_last) @@ -3848,6 +4080,14 @@ inline internal::EqMatcher Eq(T x) { return internal::EqMatcher(x); } template Matcher::Matcher(T value) { *this = Eq(value); } +template +Matcher internal::MatcherCastImpl::CastImpl( + const M& value, + internal::BooleanConstant /* convertible_to_matcher */, + internal::BooleanConstant /* convertible_to_T */) { + return Eq(value); +} + // Creates a monomorphic matcher that matches anything with type Lhs // and equal to rhs. A user may need to use this instead of Eq(...) // in order to resolve an overloading ambiguity. -- cgit v0.12 From b907c26740f593d2089e6eb10b5bde6402b44ecb Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 23 Mar 2018 11:42:41 -0400 Subject: Merging gmock-matchers.h -2 --- googlemock/include/gmock/gmock-matchers.h | 237 ++++++++++++++++++++++++++---- 1 file changed, 208 insertions(+), 29 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index dea1070..b4e23a3 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -651,6 +651,22 @@ class MatcherCastImpl > { // We delegate the matching logic to the source matcher. virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { +#if GTEST_LANG_CXX11 + using FromType = typename std::remove_cv::type>::type>::type; + using ToType = typename std::remove_cv::type>::type>::type; + // Do not allow implicitly converting base*/& to derived*/&. + static_assert( + // Do not trigger if only one of them is a pointer. That implies a + // regular conversion and not a down_cast. + (std::is_pointer::type>::value != + std::is_pointer::type>::value) || + std::is_same::value || + !std::is_base_of::value, + "Can't implicitly convert from to "); +#endif // GTEST_LANG_CXX11 + return source_matcher_.MatchAndExplain(static_cast(x), listener); } @@ -3830,6 +3846,61 @@ GTEST_API_ std::string FormatMatcherDescription(bool negation, const char* matcher_name, const Strings& param_values); +// Implements a matcher that checks the value of a optional<> type variable. +template +class OptionalMatcher { + public: + explicit OptionalMatcher(const ValueMatcher& value_matcher) + : value_matcher_(value_matcher) {} + + template + operator Matcher() const { + return MakeMatcher(new Impl(value_matcher_)); + } + + template + class Impl : public MatcherInterface { + public: + typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Optional) OptionalView; + typedef typename OptionalView::value_type ValueType; + explicit Impl(const ValueMatcher& value_matcher) + : value_matcher_(MatcherCast(value_matcher)) {} + + virtual void DescribeTo(::std::ostream* os) const { + *os << "value "; + value_matcher_.DescribeTo(os); + } + + virtual void DescribeNegationTo(::std::ostream* os) const { + *os << "value "; + value_matcher_.DescribeNegationTo(os); + } + + virtual bool MatchAndExplain(Optional optional, + MatchResultListener* listener) const { + if (!optional) { + *listener << "which is not engaged"; + return false; + } + const ValueType& value = *optional; + StringMatchResultListener value_listener; + const bool match = value_matcher_.MatchAndExplain(value, &value_listener); + *listener << "whose value " << PrintToString(value) + << (match ? " matches" : " doesn't match"); + PrintIfNotEmpty(value_listener.str(), listener->stream()); + return match; + } + + private: + const Matcher value_matcher_; + GTEST_DISALLOW_ASSIGN_(Impl); + }; + + private: + const ValueMatcher value_matcher_; + GTEST_DISALLOW_ASSIGN_(OptionalMatcher); +}; + namespace variant_matcher { // Overloads to allow VariantMatcher to do proper ADL lookup. template @@ -4246,6 +4317,16 @@ inline PolymorphicMatcher< // to compile where bar is an int32 and m is a matcher for int64. } +// Same as Field() but also takes the name of the field to provide better error +// messages. +template +inline PolymorphicMatcher > Field( + const std::string& field_name, FieldType Class::*field, + const FieldMatcher& matcher) { + return MakePolymorphicMatcher(internal::FieldMatcher( + field_name, field, MatcherCast(matcher))); +} + // Creates a matcher that matches an object whose given property // matches 'matcher'. For example, // Property(&Foo::str, StartsWith("hi")) @@ -4294,6 +4375,7 @@ Property(PropertyType (Class::*property)() const &, // concurrent access. // * If it is a function object, it has to define type result_type. // We recommend deriving your functor classes from std::unary_function. +// template internal::ResultOfMatcher ResultOf( Callable callable, const ResultOfMatcher& matcher) { @@ -4384,53 +4466,53 @@ inline PolymorphicMatcher ContainsRegex( // Wide string matchers. // Matches a string equal to str. -inline PolymorphicMatcher > - StrEq(const internal::wstring& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher( - str, true, true)); +inline PolymorphicMatcher > StrEq( + const std::wstring& str) { + return MakePolymorphicMatcher( + internal::StrEqualityMatcher(str, true, true)); } // Matches a string not equal to str. -inline PolymorphicMatcher > - StrNe(const internal::wstring& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher( - str, false, true)); +inline PolymorphicMatcher > StrNe( + const std::wstring& str) { + return MakePolymorphicMatcher( + internal::StrEqualityMatcher(str, false, true)); } // Matches a string equal to str, ignoring case. -inline PolymorphicMatcher > - StrCaseEq(const internal::wstring& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher( - str, true, false)); +inline PolymorphicMatcher > +StrCaseEq(const std::wstring& str) { + return MakePolymorphicMatcher( + internal::StrEqualityMatcher(str, true, false)); } // Matches a string not equal to str, ignoring case. -inline PolymorphicMatcher > - StrCaseNe(const internal::wstring& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher( - str, false, false)); +inline PolymorphicMatcher > +StrCaseNe(const std::wstring& str) { + return MakePolymorphicMatcher( + internal::StrEqualityMatcher(str, false, false)); } -// Creates a matcher that matches any wstring, std::wstring, or C wide string +// Creates a matcher that matches any ::wstring, std::wstring, or C wide string // that contains the given substring. -inline PolymorphicMatcher > - HasSubstr(const internal::wstring& substring) { - return MakePolymorphicMatcher(internal::HasSubstrMatcher( - substring)); +inline PolymorphicMatcher > HasSubstr( + const std::wstring& substring) { + return MakePolymorphicMatcher( + internal::HasSubstrMatcher(substring)); } // Matches a string that starts with 'prefix' (case-sensitive). -inline PolymorphicMatcher > - StartsWith(const internal::wstring& prefix) { - return MakePolymorphicMatcher(internal::StartsWithMatcher( - prefix)); +inline PolymorphicMatcher > +StartsWith(const std::wstring& prefix) { + return MakePolymorphicMatcher( + internal::StartsWithMatcher(prefix)); } // Matches a string that ends with 'suffix' (case-sensitive). -inline PolymorphicMatcher > - EndsWith(const internal::wstring& suffix) { - return MakePolymorphicMatcher(internal::EndsWithMatcher( - suffix)); +inline PolymorphicMatcher > EndsWith( + const std::wstring& suffix) { + return MakePolymorphicMatcher( + internal::EndsWithMatcher(suffix)); } #endif // GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING @@ -4459,6 +4541,58 @@ inline internal::Lt2Matcher Lt() { return internal::Lt2Matcher(); } // first field != the second field. inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); } +// Creates a polymorphic matcher that matches a 2-tuple where +// FloatEq(first field) matches the second field. +inline internal::FloatingEq2Matcher FloatEq() { + return internal::FloatingEq2Matcher(); +} + +// Creates a polymorphic matcher that matches a 2-tuple where +// DoubleEq(first field) matches the second field. +inline internal::FloatingEq2Matcher DoubleEq() { + return internal::FloatingEq2Matcher(); +} + +// Creates a polymorphic matcher that matches a 2-tuple where +// FloatEq(first field) matches the second field with NaN equality. +inline internal::FloatingEq2Matcher NanSensitiveFloatEq() { + return internal::FloatingEq2Matcher(true); +} + +// Creates a polymorphic matcher that matches a 2-tuple where +// DoubleEq(first field) matches the second field with NaN equality. +inline internal::FloatingEq2Matcher NanSensitiveDoubleEq() { + return internal::FloatingEq2Matcher(true); +} + +// Creates a polymorphic matcher that matches a 2-tuple where +// FloatNear(first field, max_abs_error) matches the second field. +inline internal::FloatingEq2Matcher FloatNear(float max_abs_error) { + return internal::FloatingEq2Matcher(max_abs_error); +} + +// Creates a polymorphic matcher that matches a 2-tuple where +// DoubleNear(first field, max_abs_error) matches the second field. +inline internal::FloatingEq2Matcher DoubleNear(double max_abs_error) { + return internal::FloatingEq2Matcher(max_abs_error); +} + +// Creates a polymorphic matcher that matches a 2-tuple where +// FloatNear(first field, max_abs_error) matches the second field with NaN +// equality. +inline internal::FloatingEq2Matcher NanSensitiveFloatNear( + float max_abs_error) { + return internal::FloatingEq2Matcher(max_abs_error, true); +} + +// Creates a polymorphic matcher that matches a 2-tuple where +// DoubleNear(first field, max_abs_error) matches the second field with NaN +// equality. +inline internal::FloatingEq2Matcher NanSensitiveDoubleNear( + double max_abs_error) { + return internal::FloatingEq2Matcher(max_abs_error, true); +} + // Creates a matcher that matches any value of type T that m doesn't // match. template @@ -4836,6 +4970,28 @@ inline bool ExplainMatchResult( return SafeMatcherCast(matcher).MatchAndExplain(value, listener); } +// Returns a string representation of the given matcher. Useful for description +// strings of matchers defined using MATCHER_P* macros that accept matchers as +// their arguments. For example: +// +// MATCHER_P(XAndYThat, matcher, +// "X that " + DescribeMatcher(matcher, negation) + +// " and Y that " + DescribeMatcher(matcher, negation)) { +// return ExplainMatchResult(matcher, arg.x(), result_listener) && +// ExplainMatchResult(matcher, arg.y(), result_listener); +// } +template +std::string DescribeMatcher(const M& matcher, bool negation = false) { + ::std::stringstream ss; + Matcher monomorphic_matcher = SafeMatcherCast(matcher); + if (negation) { + monomorphic_matcher.DescribeNegationTo(&ss); + } else { + monomorphic_matcher.DescribeTo(&ss); + } + return ss.str(); +} + #if GTEST_LANG_CXX11 // Define variadic matcher versions. They are overloaded in // gmock-generated-matchers.h for the cases supported by pre C++11 compilers. @@ -4861,6 +5017,28 @@ inline internal::AnyOfMatcher AnyOf(const Args&... matchers) { template inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; } +// Returns a matcher that matches the value of an optional<> type variable. +// The matcher implementation only uses '!arg' and requires that the optional<> +// type has a 'value_type' member type and that '*arg' is of type 'value_type' +// and is printable using 'PrintToString'. It is compatible with +// std::optional/std::experimental::optional. +// Note that to compare an optional type variable against nullopt you should +// use Eq(nullopt) and not Optional(Eq(nullopt)). The latter implies that the +// optional value contains an optional itself. +template +inline internal::OptionalMatcher Optional( + const ValueMatcher& value_matcher) { + return internal::OptionalMatcher(value_matcher); +} + +// Returns a matcher that matches the value of a absl::any type variable. +template +PolymorphicMatcher > AnyWith( + const Matcher& matcher) { + return MakePolymorphicMatcher( + internal::any_cast_matcher::AnyCastMatcher(matcher)); +} + // Returns a matcher that matches the value of a variant<> type variable. // The matcher implementation uses ADL to find the holds_alternative and get // functions. @@ -4887,4 +5065,5 @@ PolymorphicMatcher > VariantWith( // We must include this header at the end to make sure it can use the // declarations from this file. #include "gmock/internal/custom/gmock-matchers.h" + #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ -- cgit v0.12 From 8ea10d38784abda596bbaf2364351c037d2b30c6 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 26 Mar 2018 09:28:16 -0400 Subject: Upstreaming FloatingEq2Matcher, --- googlemock/include/gmock/gmock-matchers.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index b4e23a3..db15474 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -2138,17 +2138,17 @@ class FloatingEqMatcher { template class FloatingEq2Matcher { public: - FloatingEq2Matcher() : FloatingEq2Matcher(-1, false) {} + FloatingEq2Matcher() { Init(-1, false); } - explicit FloatingEq2Matcher(bool nan_eq_nan) - : FloatingEq2Matcher(-1, nan_eq_nan) {} + explicit FloatingEq2Matcher(bool nan_eq_nan) { Init(-1, nan_eq_nan); } - explicit FloatingEq2Matcher(FloatType max_abs_error) - : FloatingEq2Matcher(max_abs_error, false) {} + explicit FloatingEq2Matcher(FloatType max_abs_error) { + Init(max_abs_error, false); + } - FloatingEq2Matcher(FloatType max_abs_error, bool nan_eq_nan) - : max_abs_error_(max_abs_error), - nan_eq_nan_(nan_eq_nan) {} + FloatingEq2Matcher(FloatType max_abs_error, bool nan_eq_nan) { + Init(max_abs_error, nan_eq_nan); + } template operator Matcher< ::testing::tuple >() const { @@ -2198,8 +2198,12 @@ class FloatingEq2Matcher { const bool nan_eq_nan_; }; + void Init(FloatType max_abs_error_val, bool nan_eq_nan_val) { + max_abs_error_ = max_abs_error_val; + nan_eq_nan_ = nan_eq_nan_val; + } FloatType max_abs_error_; - const bool nan_eq_nan_; + bool nan_eq_nan_; }; // Implements the Pointee(m) matcher for matching a pointer whose -- cgit v0.12 From 23187058e761c2b0f6b11ecc8b30c949afb8eb01 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 26 Mar 2018 10:16:59 -0400 Subject: merging gmock-matchers.h 2 --- googlemock/include/gmock/gmock-matchers.h | 51 ++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index db15474..e67500d 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -2862,6 +2862,10 @@ class WhenSortedByMatcher { // container and the RHS container respectively. template class PointwiseMatcher { + GTEST_COMPILE_ASSERT_( + !IsHashTable::value, + use_UnorderedPointwise_with_hash_tables); + public: typedef internal::StlContainerView RhsView; typedef typename RhsView::type RhsStlContainer; @@ -2879,6 +2883,10 @@ class PointwiseMatcher { template operator Matcher() const { + GTEST_COMPILE_ASSERT_( + !IsHashTable::value, + use_UnorderedPointwise_with_hash_tables); + return MakeMatcher(new Impl(tuple_matcher_, rhs_)); } @@ -2929,12 +2937,15 @@ class PointwiseMatcher { typename LhsStlContainer::const_iterator left = lhs_stl_container.begin(); typename RhsStlContainer::const_iterator right = rhs_.begin(); for (size_t i = 0; i != actual_size; ++i, ++left, ++right) { - const InnerMatcherArg value_pair(*left, *right); - if (listener->IsInterested()) { StringMatchResultListener inner_listener; + // Create InnerMatcherArg as a temporarily object to avoid it outlives + // *left and *right. Dereference or the conversion to `const T&` may + // return temp objects, e.g for vector. if (!mono_tuple_matcher_.MatchAndExplain( - value_pair, &inner_listener)) { + InnerMatcherArg(ImplicitCast_(*left), + ImplicitCast_(*right)), + &inner_listener)) { *listener << "where the value pair ("; UniversalPrint(*left, listener->stream()); *listener << ", "; @@ -2944,7 +2955,9 @@ class PointwiseMatcher { return false; } } else { - if (!mono_tuple_matcher_.Matches(value_pair)) + if (!mono_tuple_matcher_.Matches( + InnerMatcherArg(ImplicitCast_(*left), + ImplicitCast_(*right)))) return false; } } @@ -3166,8 +3179,8 @@ class KeyMatcherImpl : public MatcherInterface { virtual bool MatchAndExplain(PairType key_value, MatchResultListener* listener) const { StringMatchResultListener inner_listener; - const bool match = inner_matcher_.MatchAndExplain(key_value.first, - &inner_listener); + const bool match = inner_matcher_.MatchAndExplain( + pair_getters::First(key_value, Rank0()), &inner_listener); const std::string explanation = inner_listener.str(); if (explanation != "") { *listener << "whose first field is a value " << explanation; @@ -3708,6 +3721,11 @@ class ElementsAreMatcher { template operator Matcher() const { + GTEST_COMPILE_ASSERT_( + !IsHashTable::value || + ::testing::tuple_size::value < 2, + use_UnorderedElementsAre_with_hash_tables); + typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; typedef typename internal::StlContainerView::type View; typedef typename View::value_type Element; @@ -3756,6 +3774,10 @@ class ElementsAreArrayMatcher { template operator Matcher() const { + GTEST_COMPILE_ASSERT_( + !IsHashTable::value, + use_UnorderedElementsAreArray_with_hash_tables); + return MakeMatcher(new ElementsAreMatcherImpl( matchers_.begin(), matchers_.end())); } @@ -3953,7 +3975,7 @@ class VariantMatcher { } private: - static string GetTypeName() { + static std::string GetTypeName() { #if GTEST_HAS_RTTI return internal::GetTypeName(); #endif @@ -4351,6 +4373,21 @@ Property(PropertyType (Class::*property)() const, // to compile where bar() returns an int32 and m is a matcher for int64. } +// Same as Property() above, but also takes the name of the property to provide +// better error messages. +template +inline PolymorphicMatcher > +Property(const std::string& property_name, + PropertyType (Class::*property)() const, + const PropertyMatcher& matcher) { + return MakePolymorphicMatcher( + internal::PropertyMatcher( + property_name, property, + MatcherCast(matcher))); +} + #if GTEST_LANG_CXX11 // The same as above but for reference-qualified member functions. template -- cgit v0.12 From 6aae206bc2970068cf6bbf72a9ad07f8464cd0d0 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 26 Mar 2018 10:36:26 -0400 Subject: merging gmock-matchers.h 3 --- googlemock/include/gmock/gmock-matchers.h | 49 +++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index e67500d..000908a 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -281,7 +281,8 @@ class MatcherBase { public: // Returns true iff the matcher matches x; also explains the match // result to 'listener'. - bool MatchAndExplain(T x, MatchResultListener* listener) const { + bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, + MatchResultListener* listener) const { return impl_->MatchAndExplain(x, listener); } @@ -2351,15 +2352,21 @@ class FieldMatcher { public: FieldMatcher(FieldType Class::*field, const Matcher& matcher) - : field_(field), matcher_(matcher) {} + : field_(field), matcher_(matcher), whose_field_("whose given field ") {} + + FieldMatcher(const std::string& field_name, FieldType Class::*field, + const Matcher& matcher) + : field_(field), + matcher_(matcher), + whose_field_("whose field `" + field_name + "` ") {} void DescribeTo(::std::ostream* os) const { - *os << "is an object whose given field "; + *os << "is an object " << whose_field_; matcher_.DescribeTo(os); } void DescribeNegationTo(::std::ostream* os) const { - *os << "is an object whose given field "; + *os << "is an object " << whose_field_; matcher_.DescribeNegationTo(os); } @@ -2377,7 +2384,7 @@ class FieldMatcher { // true_type iff the Field() matcher is used to match a pointer. bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj, MatchResultListener* listener) const { - *listener << "whose given field is "; + *listener << whose_field_ << "is "; return MatchPrintAndExplain(obj.*field_, matcher_, listener); } @@ -2396,6 +2403,10 @@ class FieldMatcher { const FieldType Class::*field_; const Matcher matcher_; + // Contains either "whose given field " if the name of the field is unknown + // or "whose field `name_of_field` " if the name is known. + const std::string whose_field_; + GTEST_DISALLOW_ASSIGN_(FieldMatcher); }; @@ -2414,15 +2425,23 @@ class PropertyMatcher { typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty; PropertyMatcher(Property property, const Matcher& matcher) - : property_(property), matcher_(matcher) {} + : property_(property), + matcher_(matcher), + whose_property_("whose given property ") {} + + PropertyMatcher(const std::string& property_name, Property property, + const Matcher& matcher) + : property_(property), + matcher_(matcher), + whose_property_("whose property `" + property_name + "` ") {} void DescribeTo(::std::ostream* os) const { - *os << "is an object whose given property "; + *os << "is an object " << whose_property_; matcher_.DescribeTo(os); } void DescribeNegationTo(::std::ostream* os) const { - *os << "is an object whose given property "; + *os << "is an object " << whose_property_; matcher_.DescribeNegationTo(os); } @@ -2440,7 +2459,7 @@ class PropertyMatcher { // true_type iff the Property() matcher is used to match a pointer. bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj, MatchResultListener* listener) const { - *listener << "whose given property is "; + *listener << whose_property_ << "is "; // Cannot pass the return value (for example, int) to MatchPrintAndExplain, // which takes a non-const reference as argument. #if defined(_PREFAST_ ) && _MSC_VER == 1800 @@ -2469,6 +2488,10 @@ class PropertyMatcher { Property property_; const Matcher matcher_; + // Contains either "whose given property " if the name of the property is + // unknown or "whose property `name_of_property` " if the name is known. + const std::string whose_property_; + GTEST_DISALLOW_ASSIGN_(PropertyMatcher); }; @@ -3263,18 +3286,18 @@ class PairMatcherImpl : public MatcherInterface { if (!listener->IsInterested()) { // If the listener is not interested, we don't need to construct the // explanation. - return first_matcher_.Matches(a_pair.first) && - second_matcher_.Matches(a_pair.second); + return first_matcher_.Matches(pair_getters::First(a_pair, Rank0())) && + second_matcher_.Matches(pair_getters::Second(a_pair, Rank0())); } StringMatchResultListener first_inner_listener; - if (!first_matcher_.MatchAndExplain(a_pair.first, + if (!first_matcher_.MatchAndExplain(pair_getters::First(a_pair, Rank0()), &first_inner_listener)) { *listener << "whose first field does not match"; PrintIfNotEmpty(first_inner_listener.str(), listener->stream()); return false; } StringMatchResultListener second_inner_listener; - if (!second_matcher_.MatchAndExplain(a_pair.second, + if (!second_matcher_.MatchAndExplain(pair_getters::Second(a_pair, Rank0()), &second_inner_listener)) { *listener << "whose second field does not match"; PrintIfNotEmpty(second_inner_listener.str(), listener->stream()); -- cgit v0.12 From 3df7cbe6f7377592a8ecc881ef0cde7f20d5c11b Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 26 Mar 2018 13:04:28 -0400 Subject: merges, gtest --- googletest/include/gtest/internal/gtest-port.h | 4 ++++ googletest/scripts/gen_gtest_pred_impl.py | 23 ++++++++++++----------- googletest/src/gtest-port.cc | 4 ++-- googletest/test/gtest_env_var_test.py | 1 + 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 751e176..e8cc5ae 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -1434,6 +1434,8 @@ template const T& move(const T& t) { return t; } +template +GTEST_ADD_REFERENCE_(T) forward(GTEST_ADD_REFERENCE_(T) t) { return t; } template struct RvalueRef { @@ -2338,6 +2340,7 @@ struct is_same : public false_type {}; template struct is_same : public true_type {}; + template struct is_pointer : public false_type {}; @@ -2349,6 +2352,7 @@ struct IteratorTraits { typedef typename Iterator::value_type value_type; }; + template struct IteratorTraits { typedef T value_type; diff --git a/googletest/scripts/gen_gtest_pred_impl.py b/googletest/scripts/gen_gtest_pred_impl.py index 3e7ab04..58d6dc3 100755 --- a/googletest/scripts/gen_gtest_pred_impl.py +++ b/googletest/scripts/gen_gtest_pred_impl.py @@ -115,10 +115,9 @@ def HeaderPreamble(n): #ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_ #define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_ -// Makes sure this header is not included before gtest.h. -#ifndef GTEST_INCLUDE_GTEST_GTEST_H_ -# error Do not include gtest_pred_impl.h directly. Include gtest.h instead. -#endif // GTEST_INCLUDE_GTEST_GTEST_H_ +#include "gtest/gtest.h" + +namespace testing { // This header implements a family of generic predicate assertion // macros: @@ -295,14 +294,16 @@ def HeaderPostamble(): return """ +} // namespace testing + #endif // GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_ """ def GenerateFile(path, content): - """Given a file path and a content string, overwrites it with the - given content.""" - + """Given a file path and a content string + overwrites it with the given content. + """ print 'Updating file %s . . .' % path f = file(path, 'w+') @@ -314,8 +315,8 @@ def GenerateFile(path, content): def GenerateHeader(n): """Given the maximum arity n, updates the header file that implements - the predicate assertions.""" - + the predicate assertions. + """ GenerateFile(HEADER, HeaderPreamble(n) + ''.join([ImplementationForArity(i) for i in OneTo(n)]) @@ -427,7 +428,7 @@ def TestsForArity(n): } tests = ( -"""// Sample functions/functors for testing %(arity)s predicate assertions. + """// Sample functions/functors for testing %(arity)s predicate assertions. // A %(arity)s predicate function. template <%(types)s> @@ -588,7 +589,7 @@ typedef Predicate%(n)sTest ASSERT_PRED%(n)sTest; if use_assert: assrt = 'ASSERT' # 'assert' is reserved, so we cannot use - # that identifier here. + # that identifier here. else: assrt = 'EXPECT' diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index e710354..d32afb1 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -1226,8 +1226,8 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) { // "xml:" prefix of GTEST_OUTPUT. // Note that this is meant to be called at the call site so it does // not check that the flag is 'output' -// In essence this checks env. variable called XML_OUTPUT_FILE -// if it is set we prepend "xml:" to its value , if it not set we return "" +// In essence this checks an env variable called XML_OUTPUT_FILE +// and if it is set we prepend "xml:" to its value, if it not set we return "" std::string OutputFlagAlsoCheckEnvVar(){ std::string default_value_for_output_flag = ""; const char* xml_output_file_env = posix::GetEnv("XML_OUTPUT_FILE"); diff --git a/googletest/test/gtest_env_var_test.py b/googletest/test/gtest_env_var_test.py index 5361508..beb2a8b 100755 --- a/googletest/test/gtest_env_var_test.py +++ b/googletest/test/gtest_env_var_test.py @@ -100,6 +100,7 @@ class GTestEnvVarTest(gtest_test_utils.TestCase): TestFlag('death_test_use_fork', '1', '0') TestFlag('stack_trace_depth', '0', '100') + def testXmlOutputFile(self): """Tests that $XML_OUTPUT_FILE affects the output flag.""" -- cgit v0.12 From a75a5c9706b46285620cb81774ef94bb1e3aacea Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 26 Mar 2018 13:14:00 -0400 Subject: merges 1 --- googletest/scripts/gen_gtest_pred_impl.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/googletest/scripts/gen_gtest_pred_impl.py b/googletest/scripts/gen_gtest_pred_impl.py index 58d6dc3..b43efdf 100755 --- a/googletest/scripts/gen_gtest_pred_impl.py +++ b/googletest/scripts/gen_gtest_pred_impl.py @@ -305,7 +305,6 @@ def GenerateFile(path, content): overwrites it with the given content. """ print 'Updating file %s . . .' % path - f = file(path, 'w+') print >>f, content, f.close() @@ -428,7 +427,7 @@ def TestsForArity(n): } tests = ( - """// Sample functions/functors for testing %(arity)s predicate assertions. +"""// Sample functions/functors for testing %(arity)s predicate assertions. // A %(arity)s predicate function. template <%(types)s> @@ -589,7 +588,7 @@ typedef Predicate%(n)sTest ASSERT_PRED%(n)sTest; if use_assert: assrt = 'ASSERT' # 'assert' is reserved, so we cannot use - # that identifier here. + # that identifier here. else: assrt = 'EXPECT' -- cgit v0.12 From aea6fc32aaceaf4a6ad5af715f1bc4d2b55d281b Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 27 Mar 2018 15:19:40 -0400 Subject: merging gtest-port 1 of N --- googletest/include/gtest/internal/gtest-port.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index e8cc5ae..8da15c8 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -228,9 +228,9 @@ // // Regular expressions: // RE - a simple regular expression class using the POSIX -// Extended Regular Expression syntax on UNIX-like -// platforms, or a reduced regular exception syntax on -// other platforms, including Windows. +// Extended Regular Expression syntax on UNIX-like platforms +// or a reduced regular exception syntax on other +// platforms, including Windows. // // Logging: // GTEST_LOG_() - logs messages at the specified severity level. @@ -651,8 +651,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; # if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) // STLport, provided with the Android NDK, has neither or . # define GTEST_HAS_TR1_TUPLE 0 -# elif defined(_MSC_VER) && (_MSC_VER >= 1910) -// Prevent `warning C4996: 'std::tr1': warning STL4002: The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be REMOVED.` +# elif defined(_LIBCPP_VERSION) || (defined(_MSC_VER) && (_MSC_VER >= 1910)) +// libc++ doesn't support TR1, and MCVS causes warning C4996 # define GTEST_HAS_TR1_TUPLE 0 # else // The user didn't tell us not to do it, so we assume it's OK. @@ -696,9 +696,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #endif // GTEST_USE_OWN_TR1_TUPLE -// To avoid conditional compilation everywhere, we make it -// gtest-port.h's responsibility to #include the header implementing -// tuple. +// To avoid conditional compilation we make it gtest-port.h's responsibility +// to #include the header implementing tuple. #if GTEST_HAS_STD_TUPLE_ # include // IWYU pragma: export # define GTEST_TUPLE_NAMESPACE_ ::std @@ -767,6 +766,7 @@ using ::std::tuple_size; // If the compiler is not GCC 4.0+, we assume the user is using a // spec-conforming TR1 implementation. # include // IWYU pragma: export // NOLINT + # endif // GTEST_USE_OWN_TR1_TUPLE #endif // GTEST_HAS_TR1_TUPLE @@ -2093,8 +2093,13 @@ class MutexBase { extern ::testing::internal::MutexBase mutex // Defines and statically (i.e. at link time) initializes a static mutex. +// The initialization list here does not explicitly initialize each field, +// instead relying on default initialization for the unspecified fields. In +// particular, the owner_ field (a pthread_t) is not explicitly initialized. +// This allows initialization to work whether pthread_t is a scalar or struct. +// The flag -Wmissing-field-initializers must not be specified for this to work. # define GTEST_DEFINE_STATIC_MUTEX_(mutex) \ - ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false, pthread_t() } + ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false } // The Mutex class can only be used for mutexes created at runtime. It // shares its API with MutexBase otherwise. -- cgit v0.12 From 11855d8ef08567c7961fb3c6562fbe6f9b479092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Lei=C3=9Fa?= Date: Wed, 28 Mar 2018 23:45:51 +0200 Subject: provide alternative for DebugBreak() This uses asm("int3") for clang/gcc on x86 as alternative for DebugBreak() --- googletest/src/gtest.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 9079af8..74067bc 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -4549,6 +4549,9 @@ void UnitTest::AddTestPartResult( // when a failure happens and both the --gtest_break_on_failure and // the --gtest_catch_exceptions flags are specified. DebugBreak(); +#elif (defined(__clang__) || defined(__GNUC__)) && (defined(__x86_64__) || defined(__i386__)) + // with clang/gcc we can acchieve the same effect on x86 by invoking int3 + asm("int3"); #else // Dereference NULL through a volatile pointer to prevent the compiler // from removing. We use this rather than abort() or __builtin_trap() for -- cgit v0.12 From 8e0364a37b68433cd468b68e9d1e44cc7df3c742 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 29 Mar 2018 09:46:13 -0400 Subject: merging gtest-port, 2 --- googletest/include/gtest/internal/gtest-port.h | 46 +++++--------------------- 1 file changed, 9 insertions(+), 37 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 8da15c8..0455658 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -663,6 +663,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // Determines whether Google Test's own tr1 tuple implementation // should be used. #ifndef GTEST_USE_OWN_TR1_TUPLE + // The user didn't tell us, so we need to figure it out. // We use our own TR1 tuple if we aren't sure the user has an @@ -694,6 +695,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; # define GTEST_USE_OWN_TR1_TUPLE 1 # endif + +# if GTEST_OS_SYMBIAN +# define GTEST_USE_OWN_TR1_TUPLE 1 +# endif // GTEST_OS_SYMBIAN #endif // GTEST_USE_OWN_TR1_TUPLE // To avoid conditional compilation we make it gtest-port.h's responsibility @@ -712,22 +717,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; # if GTEST_USE_OWN_TR1_TUPLE # include "gtest/internal/gtest-tuple.h" // IWYU pragma: export // NOLINT -# elif GTEST_ENV_HAS_STD_TUPLE_ -# include -// C++11 puts its tuple into the ::std namespace rather than -// ::std::tr1. gtest expects tuple to live in ::std::tr1, so put it there. -// This causes undefined behavior, but supported compilers react in -// the way we intend. -namespace std { -namespace tr1 { -using ::std::get; -using ::std::make_tuple; -using ::std::tuple; -using ::std::tuple_element; -using ::std::tuple_size; -} -} - # elif GTEST_OS_SYMBIAN // On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to @@ -744,29 +733,12 @@ using ::std::tuple_size; # define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED # include // IWYU pragma: export // NOLINT -# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000) -// GCC 4.0+ implements tr1/tuple in the header. This does -// not conform to the TR1 spec, which requires the header to be . - -# if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 -// Until version 4.3.2, gcc has a bug that causes , -// which is #included by , to not compile when RTTI is -// disabled. _TR1_FUNCTIONAL is the header guard for -// . Hence the following #define is a hack to prevent -// from being included. -# define _TR1_FUNCTIONAL 1 -# include -# undef _TR1_FUNCTIONAL // Allows the user to #include - // if they choose to. -# else -# include // NOLINT -# endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 - -# else -// If the compiler is not GCC 4.0+, we assume the user is using a -// spec-conforming TR1 implementation. +// VS 2010 now has tr1 support. +# elif _MSC_VER >= 1600 # include // IWYU pragma: export // NOLINT +# else // GTEST_USE_OWN_TR1_TUPLE +# include // IWYU pragma: export // NOLINT # endif // GTEST_USE_OWN_TR1_TUPLE #endif // GTEST_HAS_TR1_TUPLE -- cgit v0.12 From d04bf07fadd204881df4c7114906fa63b1b80c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Lei=C3=9Fa?= Date: Thu, 29 Mar 2018 16:38:23 +0200 Subject: typo --- googletest/src/gtest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 74067bc..725aa08 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -4550,7 +4550,7 @@ void UnitTest::AddTestPartResult( // the --gtest_catch_exceptions flags are specified. DebugBreak(); #elif (defined(__clang__) || defined(__GNUC__)) && (defined(__x86_64__) || defined(__i386__)) - // with clang/gcc we can acchieve the same effect on x86 by invoking int3 + // with clang/gcc we can achieve the same effect on x86 by invoking int3 asm("int3"); #else // Dereference NULL through a volatile pointer to prevent the compiler -- cgit v0.12 From 54bb165ffd0aa4f68a4f93be7d6b5b372c75ad7c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 29 Mar 2018 13:27:11 -0400 Subject: Revert "merging gtest-port, 2" --- googletest/include/gtest/internal/gtest-port.h | 46 +++++++++++++++++++++----- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 0455658..8da15c8 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -663,7 +663,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // Determines whether Google Test's own tr1 tuple implementation // should be used. #ifndef GTEST_USE_OWN_TR1_TUPLE - // The user didn't tell us, so we need to figure it out. // We use our own TR1 tuple if we aren't sure the user has an @@ -695,10 +694,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; # define GTEST_USE_OWN_TR1_TUPLE 1 # endif - -# if GTEST_OS_SYMBIAN -# define GTEST_USE_OWN_TR1_TUPLE 1 -# endif // GTEST_OS_SYMBIAN #endif // GTEST_USE_OWN_TR1_TUPLE // To avoid conditional compilation we make it gtest-port.h's responsibility @@ -717,6 +712,22 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; # if GTEST_USE_OWN_TR1_TUPLE # include "gtest/internal/gtest-tuple.h" // IWYU pragma: export // NOLINT +# elif GTEST_ENV_HAS_STD_TUPLE_ +# include +// C++11 puts its tuple into the ::std namespace rather than +// ::std::tr1. gtest expects tuple to live in ::std::tr1, so put it there. +// This causes undefined behavior, but supported compilers react in +// the way we intend. +namespace std { +namespace tr1 { +using ::std::get; +using ::std::make_tuple; +using ::std::tuple; +using ::std::tuple_element; +using ::std::tuple_size; +} +} + # elif GTEST_OS_SYMBIAN // On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to @@ -733,12 +744,29 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; # define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED # include // IWYU pragma: export // NOLINT -// VS 2010 now has tr1 support. -# elif _MSC_VER >= 1600 +# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000) +// GCC 4.0+ implements tr1/tuple in the header. This does +// not conform to the TR1 spec, which requires the header to be . + +# if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 +// Until version 4.3.2, gcc has a bug that causes , +// which is #included by , to not compile when RTTI is +// disabled. _TR1_FUNCTIONAL is the header guard for +// . Hence the following #define is a hack to prevent +// from being included. +# define _TR1_FUNCTIONAL 1 +# include +# undef _TR1_FUNCTIONAL // Allows the user to #include + // if they choose to. +# else +# include // NOLINT +# endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 + +# else +// If the compiler is not GCC 4.0+, we assume the user is using a +// spec-conforming TR1 implementation. # include // IWYU pragma: export // NOLINT -# else // GTEST_USE_OWN_TR1_TUPLE -# include // IWYU pragma: export // NOLINT # endif // GTEST_USE_OWN_TR1_TUPLE #endif // GTEST_HAS_TR1_TUPLE -- cgit v0.12 From b2373c6f51632701dcde3bd2fa1851a1b7e0585c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 29 Mar 2018 13:28:29 -0400 Subject: Revert "merging gtest-port 1 of N" --- googletest/include/gtest/internal/gtest-port.h | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 8da15c8..e8cc5ae 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -228,9 +228,9 @@ // // Regular expressions: // RE - a simple regular expression class using the POSIX -// Extended Regular Expression syntax on UNIX-like platforms -// or a reduced regular exception syntax on other -// platforms, including Windows. +// Extended Regular Expression syntax on UNIX-like +// platforms, or a reduced regular exception syntax on +// other platforms, including Windows. // // Logging: // GTEST_LOG_() - logs messages at the specified severity level. @@ -651,8 +651,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; # if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) // STLport, provided with the Android NDK, has neither or . # define GTEST_HAS_TR1_TUPLE 0 -# elif defined(_LIBCPP_VERSION) || (defined(_MSC_VER) && (_MSC_VER >= 1910)) -// libc++ doesn't support TR1, and MCVS causes warning C4996 +# elif defined(_MSC_VER) && (_MSC_VER >= 1910) +// Prevent `warning C4996: 'std::tr1': warning STL4002: The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be REMOVED.` # define GTEST_HAS_TR1_TUPLE 0 # else // The user didn't tell us not to do it, so we assume it's OK. @@ -696,8 +696,9 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #endif // GTEST_USE_OWN_TR1_TUPLE -// To avoid conditional compilation we make it gtest-port.h's responsibility -// to #include the header implementing tuple. +// To avoid conditional compilation everywhere, we make it +// gtest-port.h's responsibility to #include the header implementing +// tuple. #if GTEST_HAS_STD_TUPLE_ # include // IWYU pragma: export # define GTEST_TUPLE_NAMESPACE_ ::std @@ -766,7 +767,6 @@ using ::std::tuple_size; // If the compiler is not GCC 4.0+, we assume the user is using a // spec-conforming TR1 implementation. # include // IWYU pragma: export // NOLINT - # endif // GTEST_USE_OWN_TR1_TUPLE #endif // GTEST_HAS_TR1_TUPLE @@ -2093,13 +2093,8 @@ class MutexBase { extern ::testing::internal::MutexBase mutex // Defines and statically (i.e. at link time) initializes a static mutex. -// The initialization list here does not explicitly initialize each field, -// instead relying on default initialization for the unspecified fields. In -// particular, the owner_ field (a pthread_t) is not explicitly initialized. -// This allows initialization to work whether pthread_t is a scalar or struct. -// The flag -Wmissing-field-initializers must not be specified for this to work. # define GTEST_DEFINE_STATIC_MUTEX_(mutex) \ - ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false } + ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false, pthread_t() } // The Mutex class can only be used for mutexes created at runtime. It // shares its API with MutexBase otherwise. -- cgit v0.12 From 7888184f28509dba839e3683409443e0b5bb8948 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 29 Mar 2018 13:50:32 -0400 Subject: Include OSX builds back into PR builds Had an instance where the breakage was not detected until the actual merge. Need to be better than that --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2fbb3b1..8913e89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,6 @@ matrix: - os: osx compiler: gcc env: BUILD_TYPE=Debug VERBOSE=1 - if: type != pull_request - os: osx compiler: gcc env: BUILD_TYPE=Release VERBOSE=1 CXX_FLAGS=-std=c++11 @@ -50,7 +49,6 @@ matrix: env: BUILD_TYPE=Debug VERBOSE=1 if: type != pull_request - os: osx - compiler: clang env: BUILD_TYPE=Release VERBOSE=1 CXX_FLAGS=-std=c++11 if: type != pull_request -- cgit v0.12 From 87a4cdddd09515e39e4adecbe3d6897df8d089c1 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 2 Apr 2018 14:22:24 -0400 Subject: merging gtest-port.h, again - 1 --- googletest/include/gtest/internal/gtest-port.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index e8cc5ae..c94ccdd 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -228,10 +228,9 @@ // // Regular expressions: // RE - a simple regular expression class using the POSIX -// Extended Regular Expression syntax on UNIX-like -// platforms, or a reduced regular exception syntax on -// other platforms, including Windows. -// +// Extended Regular Expression syntax on UNIX-like platforms +// or a reduced regular exception syntax on other +// platforms, including Windows. // Logging: // GTEST_LOG_() - logs messages at the specified severity level. // LogToStderr() - directs all log messages to stderr. @@ -2093,8 +2092,13 @@ class MutexBase { extern ::testing::internal::MutexBase mutex // Defines and statically (i.e. at link time) initializes a static mutex. +// The initialization list here does not explicitly initialize each field, +// instead relying on default initialization for the unspecified fields. In +// particular, the owner_ field (a pthread_t) is not explicitly initialized. +// This allows initialization to work whether pthread_t is a scalar or struct. +// The flag -Wmissing-field-initializers must not be specified for this to work. # define GTEST_DEFINE_STATIC_MUTEX_(mutex) \ - ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false, pthread_t() } + ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false } // The Mutex class can only be used for mutexes created at runtime. It // shares its API with MutexBase otherwise. -- cgit v0.12 From df5a48da0384c096b34eb70d91ad4245e0bdbb78 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 3 Apr 2018 09:31:10 -0400 Subject: Testing, gtest-port.h merge --- googletest/include/gtest/internal/gtest-port.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index c94ccdd..d6d1b9a 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -653,6 +653,9 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; # elif defined(_MSC_VER) && (_MSC_VER >= 1910) // Prevent `warning C4996: 'std::tr1': warning STL4002: The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be REMOVED.` # define GTEST_HAS_TR1_TUPLE 0 +# elif defined(_LIBCPP_VERSION) +// libc++ doesn't support TR1. +# define GTEST_HAS_TR1_TUPLE 0 # else // The user didn't tell us not to do it, so we assume it's OK. # define GTEST_HAS_TR1_TUPLE 1 -- cgit v0.12 From 5beb452bbebace154128cf284efc301f3f55d603 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 3 Apr 2018 09:45:49 -0400 Subject: testing, merge --- googletest/include/gtest/internal/gtest-port.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index d6d1b9a..afef50e 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -653,7 +653,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; # elif defined(_MSC_VER) && (_MSC_VER >= 1910) // Prevent `warning C4996: 'std::tr1': warning STL4002: The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be REMOVED.` # define GTEST_HAS_TR1_TUPLE 0 -# elif defined(_LIBCPP_VERSION) +# elif GTEST_LANG_CXX11 && defined(_LIBCPP_VERSION) // libc++ doesn't support TR1. # define GTEST_HAS_TR1_TUPLE 0 # else -- cgit v0.12 From 04d1e56bd23d4e1a1dc168f0eea96b81f6f5df40 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 3 Apr 2018 09:56:23 -0400 Subject: merging, just comments format --- googletest/include/gtest/internal/gtest-port.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index afef50e..74be06b 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -651,7 +651,9 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // STLport, provided with the Android NDK, has neither or . # define GTEST_HAS_TR1_TUPLE 0 # elif defined(_MSC_VER) && (_MSC_VER >= 1910) -// Prevent `warning C4996: 'std::tr1': warning STL4002: The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be REMOVED.` +// Prevent `warning C4996: 'std::tr1': warning STL4002: +// The non-Standard std::tr1 namespace and TR1-only machinery +// are deprecated and will be REMOVED.` # define GTEST_HAS_TR1_TUPLE 0 # elif GTEST_LANG_CXX11 && defined(_LIBCPP_VERSION) // libc++ doesn't support TR1. -- cgit v0.12 From 2cedd5b9c1815610da3adebbea8c94c30570c96c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 3 Apr 2018 11:06:20 -0400 Subject: merging gtest-port.h , 191439094 --- googletest/include/gtest/internal/gtest-port.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 74be06b..f7a8d9d 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -667,6 +667,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // Determines whether Google Test's own tr1 tuple implementation // should be used. #ifndef GTEST_USE_OWN_TR1_TUPLE +// We use our own tuple implementation on Symbian. +# if GTEST_OS_SYMBIAN +# define GTEST_USE_OWN_TR1_TUPLE 1 +# else // The user didn't tell us, so we need to figure it out. // We use our own TR1 tuple if we aren't sure the user has an @@ -697,12 +701,11 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; # else # define GTEST_USE_OWN_TR1_TUPLE 1 # endif - +# endif // GTEST_OS_SYMBIAN #endif // GTEST_USE_OWN_TR1_TUPLE -// To avoid conditional compilation everywhere, we make it -// gtest-port.h's responsibility to #include the header implementing -// tuple. +// To avoid conditional compilation we make it gtest-port.h's responsibility +// to #include the header implementing tuple. #if GTEST_HAS_STD_TUPLE_ # include // IWYU pragma: export # define GTEST_TUPLE_NAMESPACE_ ::std -- cgit v0.12 From aa349acb07d713a70091e6372c219c8ca18f663d Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 3 Apr 2018 11:23:54 -0400 Subject: merging, cont - 2 --- googletest/include/gtest/internal/gtest-port.h | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index f7a8d9d..12c91e1 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -720,22 +720,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; # if GTEST_USE_OWN_TR1_TUPLE # include "gtest/internal/gtest-tuple.h" // IWYU pragma: export // NOLINT -# elif GTEST_ENV_HAS_STD_TUPLE_ -# include -// C++11 puts its tuple into the ::std namespace rather than -// ::std::tr1. gtest expects tuple to live in ::std::tr1, so put it there. -// This causes undefined behavior, but supported compilers react in -// the way we intend. -namespace std { -namespace tr1 { -using ::std::get; -using ::std::make_tuple; -using ::std::tuple; -using ::std::tuple_element; -using ::std::tuple_size; -} -} - # elif GTEST_OS_SYMBIAN // On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to -- cgit v0.12 From a2dd136578f17eaafb358242ba2e9812f01777b0 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 3 Apr 2018 11:38:30 -0400 Subject: merging port, cont. 191443078 --- googletest/include/gtest/internal/gtest-port.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 12c91e1..e677cd9 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -754,10 +754,12 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; # include // NOLINT # endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 -# else -// If the compiler is not GCC 4.0+, we assume the user is using a -// spec-conforming TR1 implementation. +// VS 2010 now has tr1 support. +# elif _MSC_VER >= 1600 # include // IWYU pragma: export // NOLINT + +# else // GTEST_USE_OWN_TR1_TUPLE +# include // IWYU pragma: export // NOLINT # endif // GTEST_USE_OWN_TR1_TUPLE #endif // GTEST_HAS_TR1_TUPLE -- cgit v0.12 From d52aaee8ebfb17098e4dc8859c7c6a10cf902e22 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 3 Apr 2018 16:14:35 -0400 Subject: Upstreaming, cl 191344765 --- googletest/test/gtest_unittest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 3791592..58995a4 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -7572,7 +7572,7 @@ TEST(IsHashTable, Basic) { EXPECT_TRUE(testing::internal::IsHashTable>::value); #endif // GTEST_LANG_CXX11 #if GTEST_HAS_HASH_SET_ - EXPECT_TRUE(testing::internal::IsHashTable>::value); + EXPECT_TRUE(testing::internal::IsHashTable<__gnu_cxx::hash_set>::value); #endif // GTEST_HAS_HASH_SET_ } -- cgit v0.12 From 1776ed8c1e9db8cfef66f79229a039023a7ceca0 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 4 Apr 2018 11:06:09 -0400 Subject: Tweaking https://github.com/google/googletest/pull/1523 to exclude nacl --- googletest/src/gtest.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 725aa08..73e9bf8 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -4549,7 +4549,9 @@ void UnitTest::AddTestPartResult( // when a failure happens and both the --gtest_break_on_failure and // the --gtest_catch_exceptions flags are specified. DebugBreak(); -#elif (defined(__clang__) || defined(__GNUC__)) && (defined(__x86_64__) || defined(__i386__)) +#elif (!defined(__native_client__)) && \ + ((defined(__clang__) || defined(__GNUC__)) && \ + (defined(__x86_64__) || defined(__i386__))) // with clang/gcc we can achieve the same effect on x86 by invoking int3 asm("int3"); #else -- cgit v0.12 From a0c27bd8a5357f2c5f1438b551816a1f9e5668c6 Mon Sep 17 00:00:00 2001 From: fo40225 Date: Wed, 4 Apr 2018 23:16:16 +0800 Subject: fix build break on locale windows --- googletest/include/gtest/internal/gtest-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index ffc22f9..c050da7 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -157,7 +157,7 @@ namespace edit_distance { // Returns the optimal edits to go from 'left' to 'right'. // All edits cost the same, with replace having lower priority than // add/remove. -// Simple implementation of the Wagner–Fischer algorithm. +// Simple implementation of the Wagner-Fischer algorithm. // See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm enum EditType { kMatch, kAdd, kRemove, kReplace }; GTEST_API_ std::vector CalculateOptimalEdits( -- cgit v0.12 From e55089ec115db3eb1877e49c9351d096b37583df Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 4 Apr 2018 14:05:00 -0400 Subject: merging gmock matchers 1 --- googlemock/include/gmock/gmock-matchers.h | 198 +++++++++++++++++--- googlemock/src/gmock-matchers.cc | 58 +++++- googlemock/test/gmock-matchers_test.cc | 299 ++++++++++++++++++++++++++---- 3 files changed, 483 insertions(+), 72 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 000908a..0ac3b29 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -287,7 +287,7 @@ class MatcherBase { } // Returns true iff this matcher matches x. - bool Matches(T x) const { + bool Matches(GTEST_REFERENCE_TO_CONST_(T) x) const { DummyMatchResultListener dummy; return MatchAndExplain(x, &dummy); } @@ -301,7 +301,8 @@ class MatcherBase { } // Explains why x matches, or doesn't match, the matcher. - void ExplainMatchResultTo(T x, ::std::ostream* os) const { + void ExplainMatchResultTo(GTEST_REFERENCE_TO_CONST_(T) x, + ::std::ostream* os) const { StreamMatchResultListener listener(os); MatchAndExplain(x, &listener); } @@ -317,7 +318,8 @@ class MatcherBase { MatcherBase() {} // Constructs a matcher from its implementation. - explicit MatcherBase(const MatcherInterface* impl) + explicit MatcherBase( + const MatcherInterface* impl) : impl_(impl) {} template @@ -342,7 +344,9 @@ class MatcherBase { // // If performance becomes a problem, we should see if using // shared_ptr helps. - ::testing::internal::linked_ptr > impl_; + ::testing::internal::linked_ptr< + const MatcherInterface > + impl_; }; } // namespace internal @@ -407,6 +411,8 @@ class GTEST_API_ Matcher public: Matcher() {} + explicit Matcher(const MatcherInterface* impl) + : internal::MatcherBase(impl) {} explicit Matcher(const MatcherInterface* impl) : internal::MatcherBase(impl) {} @@ -449,28 +455,95 @@ class GTEST_API_ Matcher Matcher(const char* s); // NOLINT }; +template <> +class GTEST_API_ Matcher< ::string> + : public internal::MatcherBase< ::string> { + public: + Matcher() {} + + explicit Matcher(const MatcherInterface* impl) + : internal::MatcherBase< ::string>(impl) {} + explicit Matcher(const MatcherInterface< ::string>* impl) + : internal::MatcherBase< ::string>(impl) {} + + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a std::string object. + Matcher(const std::string& s); // NOLINT + + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a ::string object. + Matcher(const ::string& s); // NOLINT + + // Allows the user to write "foo" instead of Eq("foo") sometimes. + Matcher(const char* s); // NOLINT }; +#endif // GTEST_HAS_GLOBAL_STRING +#if GTEST_HAS_ABSL +// The following two specializations allow the user to write str +// instead of Eq(str) and "foo" instead of Eq("foo") when a absl::string_view +// matcher is expected. template <> -class GTEST_API_ Matcher - : public internal::MatcherBase { +class GTEST_API_ Matcher + : public internal::MatcherBase { public: Matcher() {} - explicit Matcher(const MatcherInterface* impl) - : internal::MatcherBase(impl) {} + explicit Matcher(const MatcherInterface* impl) + : internal::MatcherBase(impl) {} // Allows the user to write str instead of Eq(str) sometimes, where - // str is a string object. - Matcher(const internal::string& s); // NOLINT + // str is a std::string object. + Matcher(const std::string& s); // NOLINT + +#if GTEST_HAS_GLOBAL_STRING + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a ::string object. + Matcher(const ::string& s); // NOLINT +#endif // GTEST_HAS_GLOBAL_STRING // Allows the user to write "foo" instead of Eq("foo") sometimes. Matcher(const char* s); // NOLINT - // Allows the user to pass StringPieces directly. - Matcher(StringPiece s); // NOLINT + // Allows the user to pass absl::string_views directly. + Matcher(absl::string_view s); // NOLINT }; -#endif // GTEST_HAS_STRING_PIECE_ + +template <> +class GTEST_API_ Matcher + : public internal::MatcherBase { + public: + Matcher() {} + + explicit Matcher(const MatcherInterface* impl) + : internal::MatcherBase(impl) {} + explicit Matcher(const MatcherInterface* impl) + : internal::MatcherBase(impl) {} + + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a std::string object. + Matcher(const std::string& s); // NOLINT + +#if GTEST_HAS_GLOBAL_STRING + // Allows the user to write str instead of Eq(str) sometimes, where + // str is a ::string object. + Matcher(const ::string& s); // NOLINT +#endif // GTEST_HAS_GLOBAL_STRING + + // Allows the user to write "foo" instead of Eq("foo") sometimes. + Matcher(const char* s); // NOLINT + + // Allows the user to pass absl::string_views directly. + Matcher(absl::string_view s); // NOLINT +}; +#endif // GTEST_HAS_ABSL + +// Prints a matcher in a human-readable format. +template +std::ostream& operator<<(std::ostream& os, const Matcher& matcher) { + matcher.DescribeTo(&os); + return os; +} // The PolymorphicMatcher class template makes it easy to implement a // polymorphic matcher (i.e. a matcher that can match values of more @@ -499,7 +572,7 @@ class PolymorphicMatcher { template operator Matcher() const { - return Matcher(new MonomorphicImpl(impl_)); + return Matcher(new MonomorphicImpl(impl_)); } private: @@ -845,7 +918,7 @@ class TuplePrefix { typename tuple_element::type matcher = get(matchers); typedef typename tuple_element::type Value; - Value value = get(values); + GTEST_REFERENCE_TO_CONST_(Value) value = get(values); StringMatchResultListener listener; if (!matcher.MatchAndExplain(value, &listener)) { // TODO(wan): include in the message the name of the parameter @@ -950,10 +1023,12 @@ OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) { // Implements A(). template -class AnyMatcherImpl : public MatcherInterface { +class AnyMatcherImpl : public MatcherInterface { public: - virtual bool MatchAndExplain( - T /* x */, MatchResultListener* /* listener */) const { return true; } + virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) /* x */, + MatchResultListener* /* listener */) const { + return true; + } virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; } virtual void DescribeNegationTo(::std::ostream* os) const { // This is mostly for completeness' safe, as it's not very useful @@ -1223,6 +1298,19 @@ class StrEqualityMatcher { bool case_sensitive) : string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {} +#if GTEST_HAS_ABSL + bool MatchAndExplain(const absl::string_view& s, + MatchResultListener* listener) const { + if (s.data() == NULL) { + return !expect_eq_; + } + // This should fail to compile if absl::string_view is used with wide + // strings. + const StringType& str = string(s); + return MatchAndExplain(str, listener); + } +#endif // GTEST_HAS_ABSL + // Accepts pointer types, particularly: // const char* // char* @@ -1239,7 +1327,7 @@ class StrEqualityMatcher { // Matches anything that can convert to StringType. // // This is a template, not just a plain function with const StringType&, - // because StringPiece has some interfering non-explicit constructors. + // because absl::string_view has some interfering non-explicit constructors. template bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { @@ -1283,6 +1371,19 @@ class HasSubstrMatcher { explicit HasSubstrMatcher(const StringType& substring) : substring_(substring) {} +#if GTEST_HAS_ABSL + bool MatchAndExplain(const absl::string_view& s, + MatchResultListener* listener) const { + if (s.data() == NULL) { + return false; + } + // This should fail to compile if absl::string_view is used with wide + // strings. + const StringType& str = string(s); + return MatchAndExplain(str, listener); + } +#endif // GTEST_HAS_ABSL + // Accepts pointer types, particularly: // const char* // char* @@ -1296,7 +1397,7 @@ class HasSubstrMatcher { // Matches anything that can convert to StringType. // // This is a template, not just a plain function with const StringType&, - // because StringPiece has some interfering non-explicit constructors. + // because absl::string_view has some interfering non-explicit constructors. template bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { @@ -1330,6 +1431,19 @@ class StartsWithMatcher { explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) { } +#if GTEST_HAS_ABSL + bool MatchAndExplain(const absl::string_view& s, + MatchResultListener* listener) const { + if (s.data() == NULL) { + return false; + } + // This should fail to compile if absl::string_view is used with wide + // strings. + const StringType& str = string(s); + return MatchAndExplain(str, listener); + } +#endif // GTEST_HAS_ABSL + // Accepts pointer types, particularly: // const char* // char* @@ -1343,7 +1457,7 @@ class StartsWithMatcher { // Matches anything that can convert to StringType. // // This is a template, not just a plain function with const StringType&, - // because StringPiece has some interfering non-explicit constructors. + // because absl::string_view has some interfering non-explicit constructors. template bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { @@ -1376,6 +1490,19 @@ class EndsWithMatcher { public: explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {} +#if GTEST_HAS_ABSL + bool MatchAndExplain(const absl::string_view& s, + MatchResultListener* listener) const { + if (s.data() == NULL) { + return false; + } + // This should fail to compile if absl::string_view is used with wide + // strings. + const StringType& str = string(s); + return MatchAndExplain(str, listener); + } +#endif // GTEST_HAS_ABSL + // Accepts pointer types, particularly: // const char* // char* @@ -1389,7 +1516,7 @@ class EndsWithMatcher { // Matches anything that can convert to StringType. // // This is a template, not just a plain function with const StringType&, - // because StringPiece has some interfering non-explicit constructors. + // because absl::string_view has some interfering non-explicit constructors. template bool MatchAndExplain(const MatcheeStringType& s, MatchResultListener* /* listener */) const { @@ -1422,6 +1549,13 @@ class MatchesRegexMatcher { MatchesRegexMatcher(const RE* regex, bool full_match) : regex_(regex), full_match_(full_match) {} +#if GTEST_HAS_ABSL + bool MatchAndExplain(const absl::string_view& s, + MatchResultListener* listener) const { + return s.data() && MatchAndExplain(string(s), listener); + } +#endif // GTEST_HAS_ABSL + // Accepts pointer types, particularly: // const char* // char* @@ -1535,12 +1669,13 @@ class Ge2Matcher : public PairMatchBase { // will prevent different instantiations of NotMatcher from sharing // the same NotMatcherImpl class. template -class NotMatcherImpl : public MatcherInterface { +class NotMatcherImpl : public MatcherInterface { public: explicit NotMatcherImpl(const Matcher& matcher) : matcher_(matcher) {} - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { + virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, + MatchResultListener* listener) const { return !matcher_.MatchAndExplain(x, listener); } @@ -1583,7 +1718,8 @@ class NotMatcher { // that will prevent different instantiations of BothOfMatcher from // sharing the same BothOfMatcherImpl class. template -class BothOfMatcherImpl : public MatcherInterface { +class BothOfMatcherImpl + : public MatcherInterface { public: BothOfMatcherImpl(const Matcher& matcher1, const Matcher& matcher2) : matcher1_(matcher1), matcher2_(matcher2) {} @@ -1604,7 +1740,8 @@ class BothOfMatcherImpl : public MatcherInterface { *os << ")"; } - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { + virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, + MatchResultListener* listener) const { // If either matcher1_ or matcher2_ doesn't match x, we only need // to explain why one of them fails. StringMatchResultListener listener1; @@ -1755,7 +1892,8 @@ class BothOfMatcher { // that will prevent different instantiations of AnyOfMatcher from // sharing the same EitherOfMatcherImpl class. template -class EitherOfMatcherImpl : public MatcherInterface { +class EitherOfMatcherImpl + : public MatcherInterface { public: EitherOfMatcherImpl(const Matcher& matcher1, const Matcher& matcher2) : matcher1_(matcher1), matcher2_(matcher2) {} @@ -1776,7 +1914,8 @@ class EitherOfMatcherImpl : public MatcherInterface { *os << ")"; } - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { + virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, + MatchResultListener* listener) const { // If either matcher1_ or matcher2_ matches x, we just need to // explain why *one* of them matches. StringMatchResultListener listener1; @@ -2224,7 +2363,8 @@ class PointeeMatcher { // enough for implementing the DescribeTo() method of Pointee(). template operator Matcher() const { - return MakeMatcher(new Impl(matcher_)); + return Matcher( + new Impl(matcher_)); } private: diff --git a/googlemock/src/gmock-matchers.cc b/googlemock/src/gmock-matchers.cc index a5ed686..194d992 100644 --- a/googlemock/src/gmock-matchers.cc +++ b/googlemock/src/gmock-matchers.cc @@ -105,6 +105,53 @@ Matcher<::string>::Matcher(const ::string& s) { *this = Eq(s); } Matcher<::string>::Matcher(const char* s) { *this = Eq(::string(s)); } #endif // GTEST_HAS_GLOBAL_STRING +#if GTEST_HAS_ABSL +// Constructs a matcher that matches a const absl::string_view& whose value is +// equal to s. +Matcher::Matcher(const std::string& s) { + *this = Eq(s); +} + +#if GTEST_HAS_GLOBAL_STRING +// Constructs a matcher that matches a const absl::string_view& whose value is +// equal to s. +Matcher::Matcher(const ::string& s) { *this = Eq(s); } +#endif // GTEST_HAS_GLOBAL_STRING + +// Constructs a matcher that matches a const absl::string_view& whose value is +// equal to s. +Matcher::Matcher(const char* s) { + *this = Eq(std::string(s)); +} + +// Constructs a matcher that matches a const absl::string_view& whose value is +// equal to s. +Matcher::Matcher(absl::string_view s) { + *this = Eq(std::string(s)); +} + +// Constructs a matcher that matches a absl::string_view whose value is equal to +// s. +Matcher::Matcher(const std::string& s) { *this = Eq(s); } + +#if GTEST_HAS_GLOBAL_STRING +// Constructs a matcher that matches a absl::string_view whose value is equal to +// s. +Matcher::Matcher(const ::string& s) { *this = Eq(s); } +#endif // GTEST_HAS_GLOBAL_STRING + +// Constructs a matcher that matches a absl::string_view whose value is equal to +// s. +Matcher::Matcher(const char* s) { + *this = Eq(std::string(s)); +} + +// Constructs a matcher that matches a absl::string_view whose value is equal to +// s. +Matcher::Matcher(absl::string_view s) { + *this = Eq(std::string(s)); +} +#endif // GTEST_HAS_ABSL namespace internal { @@ -113,12 +160,11 @@ namespace internal { // 'negation' is false; otherwise returns the description of the // negation of the matcher. 'param_values' contains a list of strings // that are the print-out of the matcher's parameters. -GTEST_API_ string FormatMatcherDescription(bool negation, - const char* matcher_name, - const Strings& param_values) { - string result = ConvertIdentifierNameToWords(matcher_name); - if (param_values.size() >= 1) - result += " " + JoinAsTuple(param_values); +GTEST_API_ std::string FormatMatcherDescription(bool negation, + const char* matcher_name, + const Strings& param_values) { + std::string result = ConvertIdentifierNameToWords(matcher_name); + if (param_values.size() >= 1) result += " " + JoinAsTuple(param_values); return negation ? "not (" + result + ")" : result; } diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 829935e..cc16134 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -58,13 +59,11 @@ # include // NOLINT #endif -// Disable MSVC2015 warning for std::pair: "decorated name length exceeded, name was truncated". -#if defined(_MSC_VER) && (_MSC_VER == 1900) -# pragma warning(disable:4503) +#if GTEST_LANG_CXX11 +# include #endif namespace testing { - namespace gmock_matchers_test { using std::greater; @@ -200,17 +199,13 @@ std::string OfType(const std::string& type_name) { // Returns the description of the given matcher. template std::string Describe(const Matcher& m) { - stringstream ss; - m.DescribeTo(&ss); - return ss.str(); + return DescribeMatcher(m); } // Returns the description of the negation of the given matcher. template std::string DescribeNegation(const Matcher& m) { - stringstream ss; - m.DescribeNegationTo(&ss); - return ss.str(); + return DescribeMatcher(m, true); } // Returns the reason why x matches, or doesn't match, m. @@ -221,6 +216,12 @@ std::string Explain(const MatcherType& m, const Value& x) { return listener.str(); } +TEST(MonotonicMatcherTest, IsPrintable) { + stringstream ss; + ss << GreaterThan(5); + EXPECT_EQ("is > 5", ss.str()); +} + TEST(MatchResultListenerTest, StreamingWorks) { StringMatchResultListener listener; listener << "hi" << 5; @@ -332,6 +333,22 @@ TEST(MatcherTest, CanBeImplicitlyConstructedFromNULL) { EXPECT_FALSE(m1.Matches(&n)); } +// Tests that matchers can be constructed from a variable that is not properly +// defined. This should be illegal, but many users rely on this accidentally. +struct Undefined { + virtual ~Undefined() = 0; + static const int kInt = 1; +}; + +TEST(MatcherTest, CanBeConstructedFromUndefinedVariable) { + Matcher m1 = Undefined::kInt; + EXPECT_TRUE(m1.Matches(1)); + EXPECT_FALSE(m1.Matches(2)); +} + +// Test that a matcher parameterized with an abstract class compiles. +TEST(MatcherTest, CanAcceptAbstractClass) { Matcher m = _; } + // Tests that matchers are copyable. TEST(MatcherTest, IsCopyable) { // Tests the copy constructor. @@ -365,66 +382,132 @@ TEST(MatcherTest, MatchAndExplain) { } // Tests that a C-string literal can be implicitly converted to a -// Matcher or Matcher. +// Matcher or Matcher. TEST(StringMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) { - Matcher m1 = "hi"; + Matcher m1 = "hi"; EXPECT_TRUE(m1.Matches("hi")); EXPECT_FALSE(m1.Matches("hello")); - Matcher m2 = "hi"; + Matcher m2 = "hi"; EXPECT_TRUE(m2.Matches("hi")); EXPECT_FALSE(m2.Matches("hello")); } // Tests that a string object can be implicitly converted to a -// Matcher or Matcher. +// Matcher or Matcher. TEST(StringMatcherTest, CanBeImplicitlyConstructedFromString) { - Matcher m1 = string("hi"); + Matcher m1 = std::string("hi"); + EXPECT_TRUE(m1.Matches("hi")); + EXPECT_FALSE(m1.Matches("hello")); + + Matcher m2 = std::string("hi"); + EXPECT_TRUE(m2.Matches("hi")); + EXPECT_FALSE(m2.Matches("hello")); +} + +#if GTEST_HAS_GLOBAL_STRING +// Tests that a ::string object can be implicitly converted to a +// Matcher or Matcher. +TEST(StringMatcherTest, CanBeImplicitlyConstructedFromGlobalString) { + Matcher m1 = ::string("hi"); + EXPECT_TRUE(m1.Matches("hi")); + EXPECT_FALSE(m1.Matches("hello")); + + Matcher m2 = ::string("hi"); + EXPECT_TRUE(m2.Matches("hi")); + EXPECT_FALSE(m2.Matches("hello")); +} +#endif // GTEST_HAS_GLOBAL_STRING + +#if GTEST_HAS_GLOBAL_STRING +// Tests that a C-string literal can be implicitly converted to a +// Matcher<::string> or Matcher. +TEST(GlobalStringMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) { + Matcher< ::string> m1 = "hi"; + EXPECT_TRUE(m1.Matches("hi")); + EXPECT_FALSE(m1.Matches("hello")); + + Matcher m2 = "hi"; + EXPECT_TRUE(m2.Matches("hi")); + EXPECT_FALSE(m2.Matches("hello")); +} + +// Tests that a std::string object can be implicitly converted to a +// Matcher<::string> or Matcher. +TEST(GlobalStringMatcherTest, CanBeImplicitlyConstructedFromString) { + Matcher< ::string> m1 = std::string("hi"); + EXPECT_TRUE(m1.Matches("hi")); + EXPECT_FALSE(m1.Matches("hello")); + + Matcher m2 = std::string("hi"); + EXPECT_TRUE(m2.Matches("hi")); + EXPECT_FALSE(m2.Matches("hello")); +} + +// Tests that a ::string object can be implicitly converted to a +// Matcher<::string> or Matcher. +TEST(GlobalStringMatcherTest, CanBeImplicitlyConstructedFromGlobalString) { + Matcher< ::string> m1 = ::string("hi"); EXPECT_TRUE(m1.Matches("hi")); EXPECT_FALSE(m1.Matches("hello")); - Matcher m2 = string("hi"); + Matcher m2 = ::string("hi"); EXPECT_TRUE(m2.Matches("hi")); EXPECT_FALSE(m2.Matches("hello")); } +#endif // GTEST_HAS_GLOBAL_STRING -#if GTEST_HAS_STRING_PIECE_ +#if GTEST_HAS_ABSL // Tests that a C-string literal can be implicitly converted to a -// Matcher or Matcher. -TEST(StringPieceMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) { - Matcher m1 = "cats"; +// Matcher or Matcher. +TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) { + Matcher m1 = "cats"; EXPECT_TRUE(m1.Matches("cats")); EXPECT_FALSE(m1.Matches("dogs")); - Matcher m2 = "cats"; + Matcher m2 = "cats"; EXPECT_TRUE(m2.Matches("cats")); EXPECT_FALSE(m2.Matches("dogs")); } -// Tests that a string object can be implicitly converted to a -// Matcher or Matcher. -TEST(StringPieceMatcherTest, CanBeImplicitlyConstructedFromString) { - Matcher m1 = string("cats"); +// Tests that a std::string object can be implicitly converted to a +// Matcher or Matcher. +TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromString) { + Matcher m1 = std::string("cats"); + EXPECT_TRUE(m1.Matches("cats")); + EXPECT_FALSE(m1.Matches("dogs")); + + Matcher m2 = std::string("cats"); + EXPECT_TRUE(m2.Matches("cats")); + EXPECT_FALSE(m2.Matches("dogs")); +} + +#if GTEST_HAS_GLOBAL_STRING +// Tests that a ::string object can be implicitly converted to a +// Matcher or Matcher. +TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromGlobalString) { + Matcher m1 = ::string("cats"); EXPECT_TRUE(m1.Matches("cats")); EXPECT_FALSE(m1.Matches("dogs")); - Matcher m2 = string("cats"); + Matcher m2 = ::string("cats"); EXPECT_TRUE(m2.Matches("cats")); EXPECT_FALSE(m2.Matches("dogs")); } +#endif // GTEST_HAS_GLOBAL_STRING -// Tests that a StringPiece object can be implicitly converted to a -// Matcher or Matcher. -TEST(StringPieceMatcherTest, CanBeImplicitlyConstructedFromStringPiece) { - Matcher m1 = StringPiece("cats"); +// Tests that a absl::string_view object can be implicitly converted to a +// Matcher or Matcher. +TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromStringView) { + Matcher m1 = absl::string_view("cats"); EXPECT_TRUE(m1.Matches("cats")); EXPECT_FALSE(m1.Matches("dogs")); - Matcher m2 = StringPiece("cats"); + Matcher m2 = absl::string_view("cats"); EXPECT_TRUE(m2.Matches("cats")); EXPECT_FALSE(m2.Matches("dogs")); } -#endif // GTEST_HAS_STRING_PIECE_ +#endif // GTEST_HAS_ABSL // Tests that MakeMatcher() constructs a Matcher from a // MatcherInterface* without requiring the user to explicitly @@ -613,7 +696,7 @@ TEST(MatcherCastTest, FromSameType) { struct ConvertibleFromAny { ConvertibleFromAny(int a_value) : value(a_value) {} template - explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) { + ConvertibleFromAny(const T& /*a_value*/) : value(-1) { ADD_FAILURE() << "Conversion constructor called"; } int value; @@ -1177,6 +1260,13 @@ TEST(StrEqTest, MatchesEqualString) { Matcher m2 = StrEq("Hello"); EXPECT_TRUE(m2.Matches("Hello")); EXPECT_FALSE(m2.Matches("Hi")); + +#if GTEST_HAS_ABSL + Matcher m3 = StrEq("Hello"); + EXPECT_TRUE(m3.Matches(absl::string_view("Hello"))); + EXPECT_FALSE(m3.Matches(absl::string_view("hello"))); + EXPECT_FALSE(m3.Matches(absl::string_view())); +#endif // GTEST_HAS_ABSL } TEST(StrEqTest, CanDescribeSelf) { @@ -1202,6 +1292,13 @@ TEST(StrNeTest, MatchesUnequalString) { Matcher m2 = StrNe(std::string("Hello")); EXPECT_TRUE(m2.Matches("hello")); EXPECT_FALSE(m2.Matches("Hello")); + +#if GTEST_HAS_ABSL + Matcher m3 = StrNe("Hello"); + EXPECT_TRUE(m3.Matches(absl::string_view(""))); + EXPECT_TRUE(m3.Matches(absl::string_view())); + EXPECT_FALSE(m3.Matches(absl::string_view("Hello"))); +#endif // GTEST_HAS_ABSL } TEST(StrNeTest, CanDescribeSelf) { @@ -1210,15 +1307,23 @@ TEST(StrNeTest, CanDescribeSelf) { } TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) { - Matcher m = StrCaseEq(string("Hello")); + Matcher m = StrCaseEq(std::string("Hello")); EXPECT_TRUE(m.Matches("Hello")); EXPECT_TRUE(m.Matches("hello")); EXPECT_FALSE(m.Matches("Hi")); EXPECT_FALSE(m.Matches(NULL)); - Matcher m2 = StrCaseEq("Hello"); + Matcher m2 = StrCaseEq("Hello"); EXPECT_TRUE(m2.Matches("hello")); EXPECT_FALSE(m2.Matches("Hi")); + +#if GTEST_HAS_ABSL + Matcher m3 = StrCaseEq(std::string("Hello")); + EXPECT_TRUE(m3.Matches(absl::string_view("Hello"))); + EXPECT_TRUE(m3.Matches(absl::string_view("hello"))); + EXPECT_FALSE(m3.Matches(absl::string_view("Hi"))); + EXPECT_FALSE(m3.Matches(absl::string_view())); +#endif // GTEST_HAS_ABSL } TEST(StrCaseEqTest, MatchesEqualStringWith0IgnoringCase) { @@ -1261,6 +1366,14 @@ TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) { Matcher m2 = StrCaseNe(std::string("Hello")); EXPECT_TRUE(m2.Matches("")); EXPECT_FALSE(m2.Matches("Hello")); + +#if GTEST_HAS_ABSL + Matcher m3 = StrCaseNe("Hello"); + EXPECT_TRUE(m3.Matches(absl::string_view("Hi"))); + EXPECT_TRUE(m3.Matches(absl::string_view())); + EXPECT_FALSE(m3.Matches(absl::string_view("Hello"))); + EXPECT_FALSE(m3.Matches(absl::string_view("hello"))); +#endif // GTEST_HAS_ABSL } TEST(StrCaseNeTest, CanDescribeSelf) { @@ -1292,6 +1405,25 @@ TEST(HasSubstrTest, WorksForCStrings) { EXPECT_FALSE(m2.Matches(NULL)); } +#if GTEST_HAS_ABSL +// Tests that HasSubstr() works for matching absl::string_view-typed values. +TEST(HasSubstrTest, WorksForStringViewClasses) { + const Matcher m1 = HasSubstr("foo"); + EXPECT_TRUE(m1.Matches(absl::string_view("I love food."))); + EXPECT_FALSE(m1.Matches(absl::string_view("tofo"))); + EXPECT_FALSE(m1.Matches(absl::string_view())); + + const Matcher m2 = HasSubstr("foo"); + EXPECT_TRUE(m2.Matches(absl::string_view("I love food."))); + EXPECT_FALSE(m2.Matches(absl::string_view("tofo"))); + EXPECT_FALSE(m2.Matches(absl::string_view())); + + const Matcher m3 = HasSubstr(""); + EXPECT_TRUE(m3.Matches(absl::string_view("foo"))); + EXPECT_FALSE(m3.Matches(absl::string_view())); +} +#endif // GTEST_HAS_ABSL + // Tests that HasSubstr(s) describes itself properly. TEST(HasSubstrTest, CanDescribeSelf) { Matcher m = HasSubstr("foo\n\""); @@ -1320,6 +1452,35 @@ TEST(KeyTest, MatchesCorrectly) { EXPECT_THAT(p, Not(Key(Lt(25)))); } +#if GTEST_LANG_CXX11 +template +struct Tag {}; + +struct PairWithGet { + int member_1; + string member_2; + using first_type = int; + using second_type = string; + + const int& GetImpl(Tag<0>) const { return member_1; } + const string& GetImpl(Tag<1>) const { return member_2; } +}; +template +auto get(const PairWithGet& value) -> decltype(value.GetImpl(Tag())) { + return value.GetImpl(Tag()); +} +TEST(PairTest, MatchesPairWithGetCorrectly) { + PairWithGet p{25, "foo"}; + EXPECT_THAT(p, Key(25)); + EXPECT_THAT(p, Not(Key(42))); + EXPECT_THAT(p, Key(Ge(20))); + EXPECT_THAT(p, Not(Key(Lt(25)))); + + std::vector v = {{11, "Foo"}, {29, "gMockIsBestMock"}}; + EXPECT_THAT(v, Contains(Key(29))); +} +#endif // GTEST_LANG_CXX11 + TEST(KeyTest, SafelyCastsInnerMatcher) { Matcher is_positive = Gt(0); Matcher is_negative = Lt(0); @@ -1423,7 +1584,7 @@ TEST(PairTest, MatchesCorrectly) { EXPECT_THAT(p, Pair(25, "foo")); EXPECT_THAT(p, Pair(Ge(20), HasSubstr("o"))); - // 'first' does not match, but 'second' matches. + // 'first' doesnt' match, but 'second' matches. EXPECT_THAT(p, Not(Pair(42, "foo"))); EXPECT_THAT(p, Not(Pair(Lt(25), "foo"))); @@ -1457,6 +1618,18 @@ TEST(PairTest, InsideContainsUsingMap) { EXPECT_THAT(container, Not(Contains(Pair(3, _)))); } +#if GTEST_LANG_CXX11 +TEST(PairTest, UseGetInsteadOfMembers) { + PairWithGet pair{7, "ABC"}; + EXPECT_THAT(pair, Pair(7, "ABC")); + EXPECT_THAT(pair, Pair(Ge(7), HasSubstr("AB"))); + EXPECT_THAT(pair, Not(Pair(Lt(7), "ABC"))); + + std::vector v = {{11, "Foo"}, {29, "gMockIsBestMock"}}; + EXPECT_THAT(v, ElementsAre(Pair(11, string("Foo")), Pair(Ge(10), Not("")))); +} +#endif // GTEST_LANG_CXX11 + // Tests StartsWith(s). TEST(StartsWithTest, MatchesStringWithGivenPrefix) { @@ -1486,12 +1659,30 @@ TEST(EndsWithTest, MatchesStringWithGivenSuffix) { EXPECT_TRUE(m1.Matches("")); EXPECT_FALSE(m1.Matches(NULL)); - const Matcher m2 = EndsWith(string("Hi")); + const Matcher m2 = EndsWith(std::string("Hi")); EXPECT_TRUE(m2.Matches("Hi")); EXPECT_TRUE(m2.Matches("Wow Hi Hi")); EXPECT_TRUE(m2.Matches("Super Hi")); EXPECT_FALSE(m2.Matches("i")); EXPECT_FALSE(m2.Matches("Hi ")); + +#if GTEST_HAS_GLOBAL_STRING + const Matcher m3 = EndsWith(::string("Hi")); + EXPECT_TRUE(m3.Matches("Hi")); + EXPECT_TRUE(m3.Matches("Wow Hi Hi")); + EXPECT_TRUE(m3.Matches("Super Hi")); + EXPECT_FALSE(m3.Matches("i")); + EXPECT_FALSE(m3.Matches("Hi ")); +#endif // GTEST_HAS_GLOBAL_STRING + +#if GTEST_HAS_ABSL + const Matcher m4 = EndsWith(""); + EXPECT_TRUE(m4.Matches("Hi")); + EXPECT_TRUE(m4.Matches("")); + // Default-constructed absl::string_view should not match anything, in order + // to distinguish it from an empty string. + EXPECT_FALSE(m4.Matches(absl::string_view())); +#endif // GTEST_HAS_ABSL } TEST(EndsWithTest, CanDescribeSelf) { @@ -1511,6 +1702,18 @@ TEST(MatchesRegexTest, MatchesStringMatchingGivenRegex) { EXPECT_TRUE(m2.Matches("azbz")); EXPECT_FALSE(m2.Matches("az1")); EXPECT_FALSE(m2.Matches("1az")); + +#if GTEST_HAS_ABSL + const Matcher m3 = MatchesRegex("a.*z"); + EXPECT_TRUE(m3.Matches(absl::string_view("az"))); + EXPECT_TRUE(m3.Matches(absl::string_view("abcz"))); + EXPECT_FALSE(m3.Matches(absl::string_view("1az"))); + // Default-constructed absl::string_view should not match anything, in order + // to distinguish it from an empty string. + EXPECT_FALSE(m3.Matches(absl::string_view())); + const Matcher m4 = MatchesRegex(""); + EXPECT_FALSE(m4.Matches(absl::string_view())); +#endif // GTEST_HAS_ABSL } TEST(MatchesRegexTest, CanDescribeSelf) { @@ -1519,6 +1722,11 @@ TEST(MatchesRegexTest, CanDescribeSelf) { Matcher m2 = MatchesRegex(new RE("a.*")); EXPECT_EQ("matches regular expression \"a.*\"", Describe(m2)); + +#if GTEST_HAS_ABSL + Matcher m3 = MatchesRegex(new RE("0.*")); + EXPECT_EQ("matches regular expression \"0.*\"", Describe(m3)); +#endif // GTEST_HAS_ABSL } // Tests ContainsRegex(). @@ -1533,6 +1741,18 @@ TEST(ContainsRegexTest, MatchesStringContainingGivenRegex) { EXPECT_TRUE(m2.Matches("azbz")); EXPECT_TRUE(m2.Matches("az1")); EXPECT_FALSE(m2.Matches("1a")); + +#if GTEST_HAS_ABSL + const Matcher m3 = ContainsRegex(new RE("a.*z")); + EXPECT_TRUE(m3.Matches(absl::string_view("azbz"))); + EXPECT_TRUE(m3.Matches(absl::string_view("az1"))); + EXPECT_FALSE(m3.Matches(absl::string_view("1a"))); + // Default-constructed absl::string_view should not match anything, in order + // to distinguish it from an empty string. + EXPECT_FALSE(m3.Matches(absl::string_view())); + const Matcher m4 = ContainsRegex(""); + EXPECT_FALSE(m4.Matches(absl::string_view())); +#endif // GTEST_HAS_ABSL } TEST(ContainsRegexTest, CanDescribeSelf) { @@ -1541,6 +1761,11 @@ TEST(ContainsRegexTest, CanDescribeSelf) { Matcher m2 = ContainsRegex(new RE("a.*")); EXPECT_EQ("contains regular expression \"a.*\"", Describe(m2)); + +#if GTEST_HAS_ABSL + Matcher m3 = ContainsRegex(new RE("0.*")); + EXPECT_EQ("contains regular expression \"0.*\"", Describe(m3)); +#endif // GTEST_HAS_ABSL } // Tests for wide strings. -- cgit v0.12 From aa14cc42858a7aec2605b27e0a221e9a4dac8921 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 4 Apr 2018 14:48:06 -0400 Subject: Fixing build break on MSVC --- 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 cc16134..f2ce8f2 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -696,7 +696,7 @@ TEST(MatcherCastTest, FromSameType) { struct ConvertibleFromAny { ConvertibleFromAny(int a_value) : value(a_value) {} template - ConvertibleFromAny(const T& /*a_value*/) : value(-1) { +explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) { ADD_FAILURE() << "Conversion constructor called"; } int value; -- cgit v0.12 From 5b3d27729b118f2c8b5e74039409db0c517651fa Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 4 Apr 2018 15:07:52 -0400 Subject: Address MSVC warning C4503, decorated name length exceeded, name was truncated --- googlemock/test/gmock-matchers_test.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index f2ce8f2..62defe5 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -5459,6 +5459,7 @@ TEST_P(BipartiteRandomTest, LargerNets) { } // Test argument is a std::pair representing (nodes, iters). +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4503) INSTANTIATE_TEST_CASE_P(Samples, BipartiteRandomTest, testing::Values( std::make_pair(5, 10000), @@ -5466,6 +5467,7 @@ INSTANTIATE_TEST_CASE_P(Samples, BipartiteRandomTest, std::make_pair(7, 2000), std::make_pair(8, 500), std::make_pair(9, 100))); +GTEST_DISABLE_MSC_WARNINGS_POP_() // Tests IsReadableTypeName(). -- cgit v0.12 From 6f4e93943a9e24e7bd619e76e68c513b7a992780 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 4 Apr 2018 15:29:05 -0400 Subject: More on MSVC warning C4503, decorated name length exceeded --- 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 62defe5..190cedd 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -5382,6 +5382,7 @@ INSTANTIATE_TEST_CASE_P(AllGraphs, BipartiteTest, ::testing::Range(0, 5)); // Parameterized by a pair interpreted as (LhsSize, RhsSize). +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4503) class BipartiteNonSquareTest : public ::testing::TestWithParam > { }; @@ -5459,7 +5460,6 @@ TEST_P(BipartiteRandomTest, LargerNets) { } // Test argument is a std::pair representing (nodes, iters). -GTEST_DISABLE_MSC_WARNINGS_PUSH_(4503) INSTANTIATE_TEST_CASE_P(Samples, BipartiteRandomTest, testing::Values( std::make_pair(5, 10000), -- cgit v0.12 From a608d4a36274d4bcbae3ed1216cb22f289348b57 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 4 Apr 2018 15:44:27 -0400 Subject: More on MSVC warning C4503, decorated name length exceeded --- googlemock/test/gmock-matchers_test.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 190cedd..4140754 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -59,6 +59,12 @@ # include // NOLINT #endif +// Disable MSVC2015 warning for std::pair: +// "decorated name length exceeded, name was truncated". +#if defined(_MSC_VER) && (_MSC_VER == 1900) +# include +# pragma warning(disable:4503) +#endif + #if GTEST_LANG_CXX11 # include #endif @@ -5382,7 +5388,6 @@ INSTANTIATE_TEST_CASE_P(AllGraphs, BipartiteTest, ::testing::Range(0, 5)); // Parameterized by a pair interpreted as (LhsSize, RhsSize). -GTEST_DISABLE_MSC_WARNINGS_PUSH_(4503) class BipartiteNonSquareTest : public ::testing::TestWithParam > { }; @@ -5467,7 +5472,6 @@ INSTANTIATE_TEST_CASE_P(Samples, BipartiteRandomTest, std::make_pair(7, 2000), std::make_pair(8, 500), std::make_pair(9, 100))); -GTEST_DISABLE_MSC_WARNINGS_POP_() // Tests IsReadableTypeName(). -- cgit v0.12 From d81b6a0c4cecbe087fae28bd6a3a40d1f5f45df4 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 4 Apr 2018 15:46:04 -0400 Subject: bad cut/paste --- 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 4140754..3cc5d35 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -61,7 +61,7 @@ // Disable MSVC2015 warning for std::pair: // "decorated name length exceeded, name was truncated". -#if defined(_MSC_VER) && (_MSC_VER == 1900) +# include +#if defined(_MSC_VER) && (_MSC_VER == 1900) # pragma warning(disable:4503) #endif -- cgit v0.12 From b22e8dec408935a7f76420026a738eeb61f8af38 Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Thu, 5 Apr 2018 13:38:33 +0200 Subject: Clean up cache non-advanced variable for subproject --- googlemock/CMakeLists.txt | 18 ++++++++++++++---- googletest/CMakeLists.txt | 25 ++++++++++++++++++++----- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/googlemock/CMakeLists.txt b/googlemock/CMakeLists.txt index bac2e3b..7d66eb2 100644 --- a/googlemock/CMakeLists.txt +++ b/googlemock/CMakeLists.txt @@ -5,10 +5,6 @@ # ctest. You can select which tests to run using 'ctest -R regex'. # For more options, run 'ctest --help'. -# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to -# make it prominent in the GUI. -option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) - option(gmock_build_tests "Build all of Google Mock's own tests." OFF) # A directory to find Google Test sources. @@ -55,6 +51,20 @@ endif() # if they are the same (the default). add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/gtest") + +# These commands only run if this is the main project +if(CMAKE_PROJECT_NAME STREQUAL "gmock" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution") + + # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to + # make it prominent in the GUI. + option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) + +else() + + mark_as_advanced(gmock_build_tests) + +endif() + # Although Google Test's CMakeLists.txt calls this function, the # changes there don't affect the current scope. Therefore we have to # call it again here. diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index b09c46e..2a9b989 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -5,10 +5,6 @@ # ctest. You can select which tests to run using 'ctest -R regex'. # For more options, run 'ctest --help'. -# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to -# make it prominent in the GUI. -option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) - # When other libraries are using a shared version of runtime libraries, # Google Test also has to use one. option( @@ -60,6 +56,25 @@ if (COMMAND set_up_hermetic_build) set_up_hermetic_build() endif() +# These commands only run if this is the main project +if(CMAKE_PROJECT_NAME STREQUAL "gtest" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution") + + # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to + # make it prominent in the GUI. + option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) + +else() + + mark_as_advanced( + gtest_force_shared_crt + gtest_build_tests + gtest_build_samples + gtest_disable_pthreads + gtest_hide_internal_symbols) + +endif() + + if (gtest_hide_internal_symbols) set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) @@ -86,7 +101,7 @@ include_directories( if (MSVC AND MSVC_VERSION EQUAL 1700) add_definitions(/D _VARIADIC_MAX=10) endif() - + ######################################################################## # # Defines the gtest & gtest_main libraries. User tests should link -- cgit v0.12 From 0cd6a4f5f585f4a58a24254dc4cc81675edba16c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 5 Apr 2018 11:34:19 -0400 Subject: Merging matchers test --- googlemock/test/gmock-matchers_test.cc | 819 +++++++++++++++++++++++++++++++-- 1 file changed, 779 insertions(+), 40 deletions(-) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 3cc5d35..d97889e 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -157,9 +157,6 @@ using testing::internal::RE; using testing::internal::scoped_ptr; using testing::internal::StreamMatchResultListener; using testing::internal::Strings; -using testing::internal::linked_ptr; -using testing::internal::scoped_ptr; -using testing::internal::string; using testing::make_tuple; using testing::tuple; @@ -698,11 +695,69 @@ TEST(MatcherCastTest, FromSameType) { EXPECT_FALSE(m2.Matches(1)); } +// Tests that MatcherCast(m) works when m is a value of the same type as the +// value type of the Matcher. +TEST(MatcherCastTest, FromAValue) { + Matcher m = MatcherCast(42); + EXPECT_TRUE(m.Matches(42)); + EXPECT_FALSE(m.Matches(239)); +} + +// Tests that MatcherCast(m) works when m is a value of the type implicitly +// convertible to the value type of the Matcher. +TEST(MatcherCastTest, FromAnImplicitlyConvertibleValue) { + const int kExpected = 'c'; + Matcher m = MatcherCast('c'); + EXPECT_TRUE(m.Matches(kExpected)); + EXPECT_FALSE(m.Matches(kExpected + 1)); +} + +struct NonImplicitlyConstructibleTypeWithOperatorEq { + friend bool operator==( + const NonImplicitlyConstructibleTypeWithOperatorEq& /* ignored */, + int rhs) { + return 42 == rhs; + } + friend bool operator==( + int lhs, + const NonImplicitlyConstructibleTypeWithOperatorEq& /* ignored */) { + return lhs == 42; + } +}; + +// Tests that MatcherCast(m) works when m is a neither a matcher nor +// implicitly convertible to the value type of the Matcher, but the value type +// of the matcher has operator==() overload accepting m. +TEST(MatcherCastTest, NonImplicitlyConstructibleTypeWithOperatorEq) { + Matcher m1 = + MatcherCast(42); + EXPECT_TRUE(m1.Matches(NonImplicitlyConstructibleTypeWithOperatorEq())); + + Matcher m2 = + MatcherCast(239); + EXPECT_FALSE(m2.Matches(NonImplicitlyConstructibleTypeWithOperatorEq())); + + // When updating the following lines please also change the comment to + // namespace convertible_from_any. + Matcher m3 = + MatcherCast(NonImplicitlyConstructibleTypeWithOperatorEq()); + EXPECT_TRUE(m3.Matches(42)); + EXPECT_FALSE(m3.Matches(239)); +} + +// The below ConvertibleFromAny struct is implicitly constructible from anything +// and when in the same namespace can interact with other tests. In particular, +// if it is in the same namespace as other tests and one removes +// NonImplicitlyConstructibleTypeWithOperatorEq::operator==(int lhs, ...); +// then the corresponding test still compiles (and it should not!) by implicitly +// converting NonImplicitlyConstructibleTypeWithOperatorEq to ConvertibleFromAny +// in m3.Matcher(). +namespace convertible_from_any { // Implicitly convertible from any type. struct ConvertibleFromAny { ConvertibleFromAny(int a_value) : value(a_value) {} template -explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) { + ConvertibleFromAny(const T& /*a_value*/) : value(-1) { ADD_FAILURE() << "Conversion constructor called"; } int value; @@ -728,6 +783,7 @@ TEST(MatcherCastTest, FromConvertibleFromAny) { EXPECT_TRUE(m.Matches(ConvertibleFromAny(1))); EXPECT_FALSE(m.Matches(ConvertibleFromAny(2))); } +} // namespace convertible_from_any struct IntReferenceWrapper { IntReferenceWrapper(const int& a_value) : value(&a_value) {} @@ -833,6 +889,7 @@ TEST(SafeMatcherCastTest, FromSameType) { EXPECT_FALSE(m2.Matches(1)); } +namespace convertible_from_any { TEST(SafeMatcherCastTest, ConversionConstructorIsUsed) { Matcher m = SafeMatcherCast(1); EXPECT_TRUE(m.Matches(ConvertibleFromAny(1))); @@ -845,6 +902,7 @@ TEST(SafeMatcherCastTest, FromConvertibleFromAny) { EXPECT_TRUE(m.Matches(ConvertibleFromAny(1))); EXPECT_FALSE(m.Matches(ConvertibleFromAny(2))); } +} // namespace convertible_from_any TEST(SafeMatcherCastTest, ValueIsNotCopied) { int n = 42; @@ -856,7 +914,7 @@ TEST(SafeMatcherCastTest, ValueIsNotCopied) { TEST(ExpectThat, TakesLiterals) { EXPECT_THAT(1, 1); EXPECT_THAT(1.0, 1.0); - EXPECT_THAT(string(), ""); + EXPECT_THAT(std::string(), ""); } TEST(ExpectThat, TakesFunctions) { @@ -956,15 +1014,11 @@ class Unprintable { public: Unprintable() : c_('a') {} + bool operator==(const Unprintable& /* rhs */) const { return true; } private: char c_; }; -inline bool operator==(const Unprintable& /* lhs */, - const Unprintable& /* rhs */) { - return true; -} - TEST(EqTest, CanDescribeSelf) { Matcher m = Eq(Unprintable()); EXPECT_EQ("is equal to 1-byte object <61>", Describe(m)); @@ -1135,14 +1189,14 @@ TEST(IsNullTest, ReferenceToConstLinkedPtr) { EXPECT_FALSE(m.Matches(non_null_p)); } -#if GTEST_HAS_STD_FUNCTION_ +#if GTEST_LANG_CXX11 TEST(IsNullTest, StdFunction) { const Matcher> m = IsNull(); EXPECT_TRUE(m.Matches(std::function())); EXPECT_FALSE(m.Matches([]{})); } -#endif // GTEST_HAS_STD_FUNCTION_ +#endif // GTEST_LANG_CXX11 // Tests that IsNull() describes itself properly. TEST(IsNullTest, CanDescribeSelf) { @@ -1183,14 +1237,14 @@ TEST(NotNullTest, ReferenceToConstLinkedPtr) { EXPECT_TRUE(m.Matches(non_null_p)); } -#if GTEST_HAS_STD_FUNCTION_ +#if GTEST_LANG_CXX11 TEST(NotNullTest, StdFunction) { const Matcher> m = NotNull(); EXPECT_TRUE(m.Matches([]{})); EXPECT_FALSE(m.Matches(std::function())); } -#endif // GTEST_HAS_STD_FUNCTION_ +#endif // GTEST_LANG_CXX11 // Tests that NotNull() describes itself properly. TEST(NotNullTest, CanDescribeSelf) { @@ -2249,6 +2303,150 @@ TEST(Ne2Test, CanDescribeSelf) { EXPECT_EQ("are an unequal pair", Describe(m)); } +// Tests that FloatEq() matches a 2-tuple where +// FloatEq(first field) matches the second field. +TEST(FloatEq2Test, MatchesEqualArguments) { + typedef ::testing::tuple Tpl; + Matcher m = FloatEq(); + EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); + EXPECT_TRUE(m.Matches(Tpl(0.3f, 0.1f + 0.1f + 0.1f))); + EXPECT_FALSE(m.Matches(Tpl(1.1f, 1.0f))); +} + +// Tests that FloatEq() describes itself properly. +TEST(FloatEq2Test, CanDescribeSelf) { + Matcher&> m = FloatEq(); + EXPECT_EQ("are an almost-equal pair", Describe(m)); +} + +// Tests that NanSensitiveFloatEq() matches a 2-tuple where +// NanSensitiveFloatEq(first field) matches the second field. +TEST(NanSensitiveFloatEqTest, MatchesEqualArgumentsWithNaN) { + typedef ::testing::tuple Tpl; + Matcher m = NanSensitiveFloatEq(); + EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); + EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN()))); + EXPECT_FALSE(m.Matches(Tpl(1.1f, 1.0f))); + EXPECT_FALSE(m.Matches(Tpl(1.0f, std::numeric_limits::quiet_NaN()))); + EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), 1.0f))); +} + +// Tests that NanSensitiveFloatEq() describes itself properly. +TEST(NanSensitiveFloatEqTest, CanDescribeSelfWithNaNs) { + Matcher&> m = NanSensitiveFloatEq(); + EXPECT_EQ("are an almost-equal pair", Describe(m)); +} + +// Tests that DoubleEq() matches a 2-tuple where +// DoubleEq(first field) matches the second field. +TEST(DoubleEq2Test, MatchesEqualArguments) { + typedef ::testing::tuple Tpl; + Matcher m = DoubleEq(); + EXPECT_TRUE(m.Matches(Tpl(1.0, 1.0))); + EXPECT_TRUE(m.Matches(Tpl(0.3, 0.1 + 0.1 + 0.1))); + EXPECT_FALSE(m.Matches(Tpl(1.1, 1.0))); +} + +// Tests that DoubleEq() describes itself properly. +TEST(DoubleEq2Test, CanDescribeSelf) { + Matcher&> m = DoubleEq(); + EXPECT_EQ("are an almost-equal pair", Describe(m)); +} + +// Tests that NanSensitiveDoubleEq() matches a 2-tuple where +// NanSensitiveDoubleEq(first field) matches the second field. +TEST(NanSensitiveDoubleEqTest, MatchesEqualArgumentsWithNaN) { + typedef ::testing::tuple Tpl; + Matcher m = NanSensitiveDoubleEq(); + EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); + EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN()))); + EXPECT_FALSE(m.Matches(Tpl(1.1f, 1.0f))); + EXPECT_FALSE(m.Matches(Tpl(1.0f, std::numeric_limits::quiet_NaN()))); + EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), 1.0f))); +} + +// Tests that DoubleEq() describes itself properly. +TEST(NanSensitiveDoubleEqTest, CanDescribeSelfWithNaNs) { + Matcher&> m = NanSensitiveDoubleEq(); + EXPECT_EQ("are an almost-equal pair", Describe(m)); +} + +// Tests that FloatEq() matches a 2-tuple where +// FloatNear(first field, max_abs_error) matches the second field. +TEST(FloatNear2Test, MatchesEqualArguments) { + typedef ::testing::tuple Tpl; + Matcher m = FloatNear(0.5f); + EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); + EXPECT_TRUE(m.Matches(Tpl(1.3f, 1.0f))); + EXPECT_FALSE(m.Matches(Tpl(1.8f, 1.0f))); +} + +// Tests that FloatNear() describes itself properly. +TEST(FloatNear2Test, CanDescribeSelf) { + Matcher&> m = FloatNear(0.5f); + EXPECT_EQ("are an almost-equal pair", Describe(m)); +} + +// Tests that NanSensitiveFloatNear() matches a 2-tuple where +// NanSensitiveFloatNear(first field) matches the second field. +TEST(NanSensitiveFloatNearTest, MatchesNearbyArgumentsWithNaN) { + typedef ::testing::tuple Tpl; + Matcher m = NanSensitiveFloatNear(0.5f); + EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); + EXPECT_TRUE(m.Matches(Tpl(1.1f, 1.0f))); + EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN()))); + EXPECT_FALSE(m.Matches(Tpl(1.6f, 1.0f))); + EXPECT_FALSE(m.Matches(Tpl(1.0f, std::numeric_limits::quiet_NaN()))); + EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), 1.0f))); +} + +// Tests that NanSensitiveFloatNear() describes itself properly. +TEST(NanSensitiveFloatNearTest, CanDescribeSelfWithNaNs) { + Matcher&> m = + NanSensitiveFloatNear(0.5f); + EXPECT_EQ("are an almost-equal pair", Describe(m)); +} + +// Tests that FloatEq() matches a 2-tuple where +// DoubleNear(first field, max_abs_error) matches the second field. +TEST(DoubleNear2Test, MatchesEqualArguments) { + typedef ::testing::tuple Tpl; + Matcher m = DoubleNear(0.5); + EXPECT_TRUE(m.Matches(Tpl(1.0, 1.0))); + EXPECT_TRUE(m.Matches(Tpl(1.3, 1.0))); + EXPECT_FALSE(m.Matches(Tpl(1.8, 1.0))); +} + +// Tests that DoubleNear() describes itself properly. +TEST(DoubleNear2Test, CanDescribeSelf) { + Matcher&> m = DoubleNear(0.5); + EXPECT_EQ("are an almost-equal pair", Describe(m)); +} + +// Tests that NanSensitiveDoubleNear() matches a 2-tuple where +// NanSensitiveDoubleNear(first field) matches the second field. +TEST(NanSensitiveDoubleNearTest, MatchesNearbyArgumentsWithNaN) { + typedef ::testing::tuple Tpl; + Matcher m = NanSensitiveDoubleNear(0.5f); + EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); + EXPECT_TRUE(m.Matches(Tpl(1.1f, 1.0f))); + EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN()))); + EXPECT_FALSE(m.Matches(Tpl(1.6f, 1.0f))); + EXPECT_FALSE(m.Matches(Tpl(1.0f, std::numeric_limits::quiet_NaN()))); + EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), 1.0f))); +} + +// Tests that NanSensitiveDoubleNear() describes itself properly. +TEST(NanSensitiveDoubleNearTest, CanDescribeSelfWithNaNs) { + Matcher&> m = + NanSensitiveDoubleNear(0.5f); + EXPECT_EQ("are an almost-equal pair", Describe(m)); +} + // Tests that Not(m) matches any value that doesn't match m. TEST(NotTest, NegatesMatcher) { Matcher m; @@ -2814,6 +3012,22 @@ TEST(ExplainMatchResultTest, WorksInsideMATCHER) { EXPECT_THAT(0, Really(Eq(0))); } +TEST(DescribeMatcherTest, WorksWithValue) { + EXPECT_EQ("is equal to 42", DescribeMatcher(42)); + EXPECT_EQ("isn't equal to 42", DescribeMatcher(42, true)); +} + +TEST(DescribeMatcherTest, WorksWithMonomorphicMatcher) { + const Matcher monomorphic = Le(0); + EXPECT_EQ("is <= 0", DescribeMatcher(monomorphic)); + EXPECT_EQ("isn't <= 0", DescribeMatcher(monomorphic, true)); +} + +TEST(DescribeMatcherTest, WorksWithPolymorphicMatcher) { + EXPECT_EQ("is even", DescribeMatcher(PolymorphicIsEven())); + EXPECT_EQ("is odd", DescribeMatcher(PolymorphicIsEven(), true)); +} + TEST(AllArgsTest, WorksForTuple) { EXPECT_THAT(make_tuple(1, 2L), AllArgs(Lt())); EXPECT_THAT(make_tuple(2L, 1), Not(AllArgs(Lt()))); @@ -2943,18 +3157,22 @@ class FloatingPointTest : public testing::Test { zero_bits_(Floating(0).bits()), one_bits_(Floating(1).bits()), infinity_bits_(Floating(Floating::Infinity()).bits()), - close_to_positive_zero_(AsBits(zero_bits_ + max_ulps_/2)), - close_to_negative_zero_(AsBits(zero_bits_ + max_ulps_ - max_ulps_/2)), - further_from_negative_zero_(-AsBits( + close_to_positive_zero_( + Floating::ReinterpretBits(zero_bits_ + max_ulps_/2)), + close_to_negative_zero_( + -Floating::ReinterpretBits(zero_bits_ + max_ulps_ - max_ulps_/2)), + further_from_negative_zero_(-Floating::ReinterpretBits( zero_bits_ + max_ulps_ + 1 - max_ulps_/2)), - close_to_one_(AsBits(one_bits_ + max_ulps_)), - further_from_one_(AsBits(one_bits_ + max_ulps_ + 1)), + close_to_one_(Floating::ReinterpretBits(one_bits_ + max_ulps_)), + further_from_one_(Floating::ReinterpretBits(one_bits_ + max_ulps_ + 1)), infinity_(Floating::Infinity()), - close_to_infinity_(AsBits(infinity_bits_ - max_ulps_)), - further_from_infinity_(AsBits(infinity_bits_ - max_ulps_ - 1)), + close_to_infinity_( + Floating::ReinterpretBits(infinity_bits_ - max_ulps_)), + further_from_infinity_( + Floating::ReinterpretBits(infinity_bits_ - max_ulps_ - 1)), max_(Floating::Max()), - nan1_(AsBits(Floating::kExponentBitMask | 1)), - nan2_(AsBits(Floating::kExponentBitMask | 200)) { + nan1_(Floating::ReinterpretBits(Floating::kExponentBitMask | 1)), + nan2_(Floating::ReinterpretBits(Floating::kExponentBitMask | 200)) { } void TestSize() { @@ -3009,7 +3227,7 @@ class FloatingPointTest : public testing::Test { // Pre-calculated numbers to be used by the tests. - const size_t max_ulps_; + const Bits max_ulps_; const Bits zero_bits_; // The bits that represent 0.0. const Bits one_bits_; // The bits that represent 1.0. @@ -3035,12 +3253,6 @@ class FloatingPointTest : public testing::Test { // Some NaNs. const RawType nan1_; const RawType nan2_; - - private: - template - static RawType AsBits(T value) { - return Floating::ReinterpretBits(static_cast(value)); - } }; // Tests floating-point matchers with fixed epsilons. @@ -3417,8 +3629,6 @@ MATCHER_P(FieldIIs, inner_matcher, "") { return ExplainMatchResult(inner_matcher, arg.i, result_listener); } -#if GTEST_HAS_RTTI - TEST(WhenDynamicCastToTest, SameType) { Derived derived; derived.i = 4; @@ -3476,8 +3686,12 @@ TEST(WhenDynamicCastToTest, AmbiguousCast) { TEST(WhenDynamicCastToTest, Describe) { Matcher matcher = WhenDynamicCastTo(Pointee(_)); - const string prefix = +#if GTEST_HAS_RTTI + const std::string prefix = "when dynamic_cast to " + internal::GetTypeName() + ", "; +#else // GTEST_HAS_RTTI + const std::string prefix = "when dynamic_cast, "; +#endif // GTEST_HAS_RTTI EXPECT_EQ(prefix + "points to a value that is anything", Describe(matcher)); EXPECT_EQ(prefix + "does not point to a value that is anything", DescribeNegation(matcher)); @@ -3511,8 +3725,6 @@ TEST(WhenDynamicCastToTest, BadReference) { EXPECT_THAT(as_base_ref, Not(WhenDynamicCastTo(_))); } -#endif // GTEST_HAS_RTTI - // Minimal const-propagating pointer. template class ConstPropagatingPtr { @@ -3632,11 +3844,14 @@ struct DerivedStruct : public AStruct { // Tests that Field(&Foo::field, ...) works when field is non-const. TEST(FieldTest, WorksForNonConstField) { Matcher m = Field(&AStruct::x, Ge(0)); + Matcher m_with_name = Field("x", &AStruct::x, Ge(0)); AStruct a; EXPECT_TRUE(m.Matches(a)); + EXPECT_TRUE(m_with_name.Matches(a)); a.x = -1; EXPECT_FALSE(m.Matches(a)); + EXPECT_FALSE(m_with_name.Matches(a)); } // Tests that Field(&Foo::field, ...) works when field is const. @@ -3644,9 +3859,13 @@ TEST(FieldTest, WorksForConstField) { AStruct a; Matcher m = Field(&AStruct::y, Ge(0.0)); + Matcher m_with_name = Field("y", &AStruct::y, Ge(0.0)); EXPECT_TRUE(m.Matches(a)); + EXPECT_TRUE(m_with_name.Matches(a)); m = Field(&AStruct::y, Le(0.0)); + m_with_name = Field("y", &AStruct::y, Le(0.0)); EXPECT_FALSE(m.Matches(a)); + EXPECT_FALSE(m_with_name.Matches(a)); } // Tests that Field(&Foo::field, ...) works when field is not copyable. @@ -3720,6 +3939,14 @@ TEST(FieldTest, CanDescribeSelf) { EXPECT_EQ("is an object whose given field isn't >= 0", DescribeNegation(m)); } +TEST(FieldTest, CanDescribeSelfWithFieldName) { + Matcher m = Field("field_name", &AStruct::x, Ge(0)); + + EXPECT_EQ("is an object whose field `field_name` is >= 0", Describe(m)); + EXPECT_EQ("is an object whose field `field_name` isn't >= 0", + DescribeNegation(m)); +} + // Tests that Field() can explain the match result. TEST(FieldTest, CanExplainMatchResult) { Matcher m = Field(&AStruct::x, Ge(0)); @@ -3734,6 +3961,19 @@ TEST(FieldTest, CanExplainMatchResult) { Explain(m, a)); } +TEST(FieldTest, CanExplainMatchResultWithFieldName) { + Matcher m = Field("field_name", &AStruct::x, Ge(0)); + + AStruct a; + a.x = 1; + EXPECT_EQ("whose field `field_name` is 1" + OfType("int"), Explain(m, a)); + + m = Field("field_name", &AStruct::x, GreaterThan(0)); + EXPECT_EQ("whose field `field_name` is 1" + OfType("int") + + ", which is 1 more than 0", + Explain(m, a)); +} + // Tests that Field() works when the argument is a pointer to const. TEST(FieldForPointerTest, WorksForPointerToConst) { Matcher m = Field(&AStruct::x, Ge(0)); @@ -3791,6 +4031,14 @@ TEST(FieldForPointerTest, CanDescribeSelf) { EXPECT_EQ("is an object whose given field isn't >= 0", DescribeNegation(m)); } +TEST(FieldForPointerTest, CanDescribeSelfWithFieldName) { + Matcher m = Field("field_name", &AStruct::x, Ge(0)); + + EXPECT_EQ("is an object whose field `field_name` is >= 0", Describe(m)); + EXPECT_EQ("is an object whose field `field_name` isn't >= 0", + DescribeNegation(m)); +} + // Tests that Field() can explain the result of matching a pointer. TEST(FieldForPointerTest, CanExplainMatchResult) { Matcher m = Field(&AStruct::x, Ge(0)); @@ -3806,6 +4054,22 @@ TEST(FieldForPointerTest, CanExplainMatchResult) { ", which is 1 more than 0", Explain(m, &a)); } +TEST(FieldForPointerTest, CanExplainMatchResultWithFieldName) { + Matcher m = Field("field_name", &AStruct::x, Ge(0)); + + AStruct a; + a.x = 1; + EXPECT_EQ("", Explain(m, static_cast(NULL))); + EXPECT_EQ( + "which points to an object whose field `field_name` is 1" + OfType("int"), + Explain(m, &a)); + + m = Field("field_name", &AStruct::x, GreaterThan(0)); + EXPECT_EQ("which points to an object whose field `field_name` is 1" + + OfType("int") + ", which is 1 more than 0", + Explain(m, &a)); +} + // A user-defined class for testing Property(). class AClass { public: @@ -3849,26 +4113,33 @@ class DerivedClass : public AClass { // returns a non-reference. TEST(PropertyTest, WorksForNonReferenceProperty) { Matcher m = Property(&AClass::n, Ge(0)); + Matcher m_with_name = Property("n", &AClass::n, Ge(0)); AClass a; a.set_n(1); EXPECT_TRUE(m.Matches(a)); + EXPECT_TRUE(m_with_name.Matches(a)); a.set_n(-1); EXPECT_FALSE(m.Matches(a)); + EXPECT_FALSE(m_with_name.Matches(a)); } // Tests that Property(&Foo::property, ...) works when property() // returns a reference to const. TEST(PropertyTest, WorksForReferenceToConstProperty) { Matcher m = Property(&AClass::s, StartsWith("hi")); + Matcher m_with_name = + Property("s", &AClass::s, StartsWith("hi")); AClass a; a.set_s("hill"); EXPECT_TRUE(m.Matches(a)); + EXPECT_TRUE(m_with_name.Matches(a)); a.set_s("hole"); EXPECT_FALSE(m.Matches(a)); + EXPECT_FALSE(m_with_name.Matches(a)); } #if GTEST_LANG_CXX11 @@ -3934,10 +4205,15 @@ TEST(PropertyTest, WorksForCompatibleMatcherType) { Matcher m = Property(&AClass::n, Matcher(Ge(0))); + Matcher m_with_name = + Property("n", &AClass::n, Matcher(Ge(0))); + AClass a; EXPECT_TRUE(m.Matches(a)); + EXPECT_TRUE(m_with_name.Matches(a)); a.set_n(-1); EXPECT_FALSE(m.Matches(a)); + EXPECT_FALSE(m_with_name.Matches(a)); } // Tests that Property() can describe itself. @@ -3949,6 +4225,14 @@ TEST(PropertyTest, CanDescribeSelf) { DescribeNegation(m)); } +TEST(PropertyTest, CanDescribeSelfWithPropertyName) { + Matcher m = Property("fancy_name", &AClass::n, Ge(0)); + + EXPECT_EQ("is an object whose property `fancy_name` is >= 0", Describe(m)); + EXPECT_EQ("is an object whose property `fancy_name` isn't >= 0", + DescribeNegation(m)); +} + // Tests that Property() can explain the match result. TEST(PropertyTest, CanExplainMatchResult) { Matcher m = Property(&AClass::n, Ge(0)); @@ -3963,6 +4247,19 @@ TEST(PropertyTest, CanExplainMatchResult) { Explain(m, a)); } +TEST(PropertyTest, CanExplainMatchResultWithPropertyName) { + Matcher m = Property("fancy_name", &AClass::n, Ge(0)); + + AClass a; + a.set_n(1); + EXPECT_EQ("whose property `fancy_name` is 1" + OfType("int"), Explain(m, a)); + + m = Property("fancy_name", &AClass::n, GreaterThan(0)); + EXPECT_EQ("whose property `fancy_name` is 1" + OfType("int") + + ", which is 1 more than 0", + Explain(m, a)); +} + // Tests that Property() works when the argument is a pointer to const. TEST(PropertyForPointerTest, WorksForPointerToConst) { Matcher m = Property(&AClass::n, Ge(0)); @@ -4030,6 +4327,14 @@ TEST(PropertyForPointerTest, CanDescribeSelf) { DescribeNegation(m)); } +TEST(PropertyForPointerTest, CanDescribeSelfWithPropertyDescription) { + Matcher m = Property("fancy_name", &AClass::n, Ge(0)); + + EXPECT_EQ("is an object whose property `fancy_name` is >= 0", Describe(m)); + EXPECT_EQ("is an object whose property `fancy_name` isn't >= 0", + DescribeNegation(m)); +} + // Tests that Property() can explain the result of matching a pointer. TEST(PropertyForPointerTest, CanExplainMatchResult) { Matcher m = Property(&AClass::n, Ge(0)); @@ -4047,6 +4352,22 @@ TEST(PropertyForPointerTest, CanExplainMatchResult) { Explain(m, &a)); } +TEST(PropertyForPointerTest, CanExplainMatchResultWithPropertyName) { + Matcher m = Property("fancy_name", &AClass::n, Ge(0)); + + AClass a; + a.set_n(1); + EXPECT_EQ("", Explain(m, static_cast(NULL))); + EXPECT_EQ("which points to an object whose property `fancy_name` is 1" + + OfType("int"), + Explain(m, &a)); + + m = Property("fancy_name", &AClass::n, GreaterThan(0)); + EXPECT_EQ("which points to an object whose property `fancy_name` is 1" + + OfType("int") + ", which is 1 more than 0", + Explain(m, &a)); +} + // Tests ResultOf. // Tests that ResultOf(f, ...) compiles and works as expected when f is a @@ -4162,11 +4483,8 @@ TEST(ResultOfTest, WorksForFunctionReferences) { // Tests that ResultOf(f, ...) compiles and works as expected when f is a // function object. -struct Functor { - typedef std::string result_type; - typedef int argument_type; - - std::string operator()(int input) const { +struct Functor : public ::std::unary_function { + result_type operator()(argument_type input) const { return IntToStringFunction(input); } }; @@ -4360,6 +4678,44 @@ TEST(IsEmptyTest, ExplainsResult) { EXPECT_EQ("whose size is 1", Explain(m, container)); } +TEST(IsTrueTest, IsTrueIsFalse) { + EXPECT_THAT(true, IsTrue()); + EXPECT_THAT(false, IsFalse()); + EXPECT_THAT(true, Not(IsFalse())); + EXPECT_THAT(false, Not(IsTrue())); + EXPECT_THAT(0, Not(IsTrue())); + EXPECT_THAT(0, IsFalse()); + EXPECT_THAT(NULL, Not(IsTrue())); + EXPECT_THAT(NULL, IsFalse()); + EXPECT_THAT(-1, IsTrue()); + EXPECT_THAT(-1, Not(IsFalse())); + EXPECT_THAT(1, IsTrue()); + EXPECT_THAT(1, Not(IsFalse())); + EXPECT_THAT(2, IsTrue()); + EXPECT_THAT(2, Not(IsFalse())); + int a = 42; + EXPECT_THAT(a, IsTrue()); + EXPECT_THAT(a, Not(IsFalse())); + EXPECT_THAT(&a, IsTrue()); + EXPECT_THAT(&a, Not(IsFalse())); + EXPECT_THAT(false, Not(IsTrue())); + EXPECT_THAT(true, Not(IsFalse())); +#if GTEST_LANG_CXX11 + EXPECT_THAT(std::true_type(), IsTrue()); + EXPECT_THAT(std::true_type(), Not(IsFalse())); + EXPECT_THAT(std::false_type(), IsFalse()); + EXPECT_THAT(std::false_type(), Not(IsTrue())); + EXPECT_THAT(nullptr, Not(IsTrue())); + EXPECT_THAT(nullptr, IsFalse()); + std::unique_ptr null_unique; + std::unique_ptr nonnull_unique(new int(0)); + EXPECT_THAT(null_unique, Not(IsTrue())); + EXPECT_THAT(null_unique, IsFalse()); + EXPECT_THAT(nonnull_unique, IsTrue()); + EXPECT_THAT(nonnull_unique, Not(IsFalse())); +#endif // GTEST_LANG_CXX11 +} + TEST(SizeIsTest, ImplementsSizeIs) { vector container; EXPECT_THAT(container, SizeIs(0)); @@ -4914,6 +5270,250 @@ TEST(WhenSortedTest, WorksForVectorConstRefMatcherOnStreamlike) { EXPECT_THAT(s, Not(WhenSorted(ElementsAre(2, 1, 4, 5, 3)))); } +TEST(IsSupersetOfTest, WorksForNativeArray) { + const int subset[] = {1, 4}; + const int superset[] = {1, 2, 4}; + const int disjoint[] = {1, 0, 3}; + EXPECT_THAT(subset, IsSupersetOf(subset)); + EXPECT_THAT(subset, Not(IsSupersetOf(superset))); + EXPECT_THAT(superset, IsSupersetOf(subset)); + EXPECT_THAT(subset, Not(IsSupersetOf(disjoint))); + EXPECT_THAT(disjoint, Not(IsSupersetOf(subset))); +} + +TEST(IsSupersetOfTest, WorksWithDuplicates) { + const int not_enough[] = {1, 2}; + const int enough[] = {1, 1, 2}; + const int expected[] = {1, 1}; + EXPECT_THAT(not_enough, Not(IsSupersetOf(expected))); + EXPECT_THAT(enough, IsSupersetOf(expected)); +} + +TEST(IsSupersetOfTest, WorksForEmpty) { + vector numbers; + vector expected; + EXPECT_THAT(numbers, IsSupersetOf(expected)); + expected.push_back(1); + EXPECT_THAT(numbers, Not(IsSupersetOf(expected))); + expected.clear(); + numbers.push_back(1); + numbers.push_back(2); + EXPECT_THAT(numbers, IsSupersetOf(expected)); + expected.push_back(1); + EXPECT_THAT(numbers, IsSupersetOf(expected)); + expected.push_back(2); + EXPECT_THAT(numbers, IsSupersetOf(expected)); + expected.push_back(3); + EXPECT_THAT(numbers, Not(IsSupersetOf(expected))); +} + +TEST(IsSupersetOfTest, WorksForStreamlike) { + const int a[5] = {1, 2, 3, 4, 5}; + Streamlike s(a, a + GTEST_ARRAY_SIZE_(a)); + + vector expected; + expected.push_back(1); + expected.push_back(2); + expected.push_back(5); + EXPECT_THAT(s, IsSupersetOf(expected)); + + expected.push_back(0); + EXPECT_THAT(s, Not(IsSupersetOf(expected))); +} + +TEST(IsSupersetOfTest, TakesStlContainer) { + const int actual[] = {3, 1, 2}; + + ::std::list expected; + expected.push_back(1); + expected.push_back(3); + EXPECT_THAT(actual, IsSupersetOf(expected)); + + expected.push_back(4); + EXPECT_THAT(actual, Not(IsSupersetOf(expected))); +} + +TEST(IsSupersetOfTest, Describe) { + typedef std::vector IntVec; + IntVec expected; + expected.push_back(111); + expected.push_back(222); + expected.push_back(333); + EXPECT_THAT( + Describe(IsSupersetOf(expected)), + Eq("a surjection from elements to requirements exists such that:\n" + " - an element is equal to 111\n" + " - an element is equal to 222\n" + " - an element is equal to 333")); +} + +TEST(IsSupersetOfTest, DescribeNegation) { + typedef std::vector IntVec; + IntVec expected; + expected.push_back(111); + expected.push_back(222); + expected.push_back(333); + EXPECT_THAT( + DescribeNegation(IsSupersetOf(expected)), + Eq("no surjection from elements to requirements exists such that:\n" + " - an element is equal to 111\n" + " - an element is equal to 222\n" + " - an element is equal to 333")); +} + +TEST(IsSupersetOfTest, MatchAndExplain) { + std::vector v; + v.push_back(2); + v.push_back(3); + std::vector expected; + expected.push_back(1); + expected.push_back(2); + StringMatchResultListener listener; + ASSERT_FALSE(ExplainMatchResult(IsSupersetOf(expected), v, &listener)) + << listener.str(); + EXPECT_THAT(listener.str(), + Eq("where the following matchers don't match any elements:\n" + "matcher #0: is equal to 1")); + + v.push_back(1); + listener.Clear(); + ASSERT_TRUE(ExplainMatchResult(IsSupersetOf(expected), v, &listener)) + << listener.str(); + EXPECT_THAT(listener.str(), Eq("where:\n" + " - element #0 is matched by matcher #1,\n" + " - element #2 is matched by matcher #0")); +} + +#if GTEST_HAS_STD_INITIALIZER_LIST_ +TEST(IsSupersetOfTest, WorksForRhsInitializerList) { + const int numbers[] = {1, 3, 6, 2, 4, 5}; + EXPECT_THAT(numbers, IsSupersetOf({1, 2})); + EXPECT_THAT(numbers, Not(IsSupersetOf({3, 0}))); +} +#endif + +TEST(IsSubsetOfTest, WorksForNativeArray) { + const int subset[] = {1, 4}; + const int superset[] = {1, 2, 4}; + const int disjoint[] = {1, 0, 3}; + EXPECT_THAT(subset, IsSubsetOf(subset)); + EXPECT_THAT(subset, IsSubsetOf(superset)); + EXPECT_THAT(superset, Not(IsSubsetOf(subset))); + EXPECT_THAT(subset, Not(IsSubsetOf(disjoint))); + EXPECT_THAT(disjoint, Not(IsSubsetOf(subset))); +} + +TEST(IsSubsetOfTest, WorksWithDuplicates) { + const int not_enough[] = {1, 2}; + const int enough[] = {1, 1, 2}; + const int actual[] = {1, 1}; + EXPECT_THAT(actual, Not(IsSubsetOf(not_enough))); + EXPECT_THAT(actual, IsSubsetOf(enough)); +} + +TEST(IsSubsetOfTest, WorksForEmpty) { + vector numbers; + vector expected; + EXPECT_THAT(numbers, IsSubsetOf(expected)); + expected.push_back(1); + EXPECT_THAT(numbers, IsSubsetOf(expected)); + expected.clear(); + numbers.push_back(1); + numbers.push_back(2); + EXPECT_THAT(numbers, Not(IsSubsetOf(expected))); + expected.push_back(1); + EXPECT_THAT(numbers, Not(IsSubsetOf(expected))); + expected.push_back(2); + EXPECT_THAT(numbers, IsSubsetOf(expected)); + expected.push_back(3); + EXPECT_THAT(numbers, IsSubsetOf(expected)); +} + +TEST(IsSubsetOfTest, WorksForStreamlike) { + const int a[5] = {1, 2}; + Streamlike s(a, a + GTEST_ARRAY_SIZE_(a)); + + vector expected; + expected.push_back(1); + EXPECT_THAT(s, Not(IsSubsetOf(expected))); + expected.push_back(2); + expected.push_back(5); + EXPECT_THAT(s, IsSubsetOf(expected)); +} + +TEST(IsSubsetOfTest, TakesStlContainer) { + const int actual[] = {3, 1, 2}; + + ::std::list expected; + expected.push_back(1); + expected.push_back(3); + EXPECT_THAT(actual, Not(IsSubsetOf(expected))); + + expected.push_back(2); + expected.push_back(4); + EXPECT_THAT(actual, IsSubsetOf(expected)); +} + +TEST(IsSubsetOfTest, Describe) { + typedef std::vector IntVec; + IntVec expected; + expected.push_back(111); + expected.push_back(222); + expected.push_back(333); + + EXPECT_THAT( + Describe(IsSubsetOf(expected)), + Eq("an injection from elements to requirements exists such that:\n" + " - an element is equal to 111\n" + " - an element is equal to 222\n" + " - an element is equal to 333")); +} + +TEST(IsSubsetOfTest, DescribeNegation) { + typedef std::vector IntVec; + IntVec expected; + expected.push_back(111); + expected.push_back(222); + expected.push_back(333); + EXPECT_THAT( + DescribeNegation(IsSubsetOf(expected)), + Eq("no injection from elements to requirements exists such that:\n" + " - an element is equal to 111\n" + " - an element is equal to 222\n" + " - an element is equal to 333")); +} + +TEST(IsSubsetOfTest, MatchAndExplain) { + std::vector v; + v.push_back(2); + v.push_back(3); + std::vector expected; + expected.push_back(1); + expected.push_back(2); + StringMatchResultListener listener; + ASSERT_FALSE(ExplainMatchResult(IsSubsetOf(expected), v, &listener)) + << listener.str(); + EXPECT_THAT(listener.str(), + Eq("where the following elements don't match any matchers:\n" + "element #1: 3")); + + expected.push_back(3); + listener.Clear(); + ASSERT_TRUE(ExplainMatchResult(IsSubsetOf(expected), v, &listener)) + << listener.str(); + EXPECT_THAT(listener.str(), Eq("where:\n" + " - element #0 is matched by matcher #1,\n" + " - element #1 is matched by matcher #2")); +} + +#if GTEST_HAS_STD_INITIALIZER_LIST_ +TEST(IsSubsetOfTest, WorksForRhsInitializerList) { + const int numbers[] = {1, 2, 3}; + EXPECT_THAT(numbers, IsSubsetOf({1, 2, 3, 4})); + EXPECT_THAT(numbers, Not(IsSubsetOf({1, 2}))); +} +#endif + // Tests using ElementsAre() and ElementsAreArray() with stream-like // "containers". @@ -5721,6 +6321,16 @@ TEST(PointwiseTest, WorksForRhsNativeArray) { EXPECT_THAT(lhs, Not(Pointwise(Lt(), rhs))); } +// Test is effective only with sanitizers. +TEST(PointwiseTest, WorksForVectorOfBool) { + vector rhs(3, false); + rhs[1] = true; + vector lhs = rhs; + EXPECT_THAT(lhs, Pointwise(Eq(), rhs)); + rhs[0] = true; + EXPECT_THAT(lhs, Not(Pointwise(Eq(), rhs))); +} + #if GTEST_HAS_STD_INITIALIZER_LIST_ TEST(PointwiseTest, WorksForRhsInitializerList) { @@ -5886,6 +6496,51 @@ TEST(UnorderedPointwiseTest, AllowsMonomorphicInnerMatcher) { EXPECT_THAT(lhs, UnorderedPointwise(m2, rhs)); } +// Sample optional type implementation with minimal requirements for use with +// Optional matcher. +class SampleOptionalInt { + public: + typedef int value_type; + explicit SampleOptionalInt(int value) : value_(value), has_value_(true) {} + SampleOptionalInt() : value_(0), has_value_(false) {} + operator bool() const { + return has_value_; + } + const int& operator*() const { + return value_; + } + private: + int value_; + bool has_value_; +}; + +TEST(OptionalTest, DescribesSelf) { + const Matcher m = Optional(Eq(1)); + EXPECT_EQ("value is equal to 1", Describe(m)); +} + +TEST(OptionalTest, ExplainsSelf) { + const Matcher m = Optional(Eq(1)); + EXPECT_EQ("whose value 1 matches", Explain(m, SampleOptionalInt(1))); + EXPECT_EQ("whose value 2 doesn't match", Explain(m, SampleOptionalInt(2))); +} + +TEST(OptionalTest, MatchesNonEmptyOptional) { + const Matcher m1 = Optional(1); + const Matcher m2 = Optional(Eq(2)); + const Matcher m3 = Optional(Lt(3)); + SampleOptionalInt opt(1); + EXPECT_TRUE(m1.Matches(opt)); + EXPECT_FALSE(m2.Matches(opt)); + EXPECT_TRUE(m3.Matches(opt)); +} + +TEST(OptionalTest, DoesNotMatchNullopt) { + const Matcher m = Optional(1); + SampleOptionalInt empty; + EXPECT_FALSE(m.Matches(empty)); +} + class SampleVariantIntString { public: SampleVariantIntString(int i) : i_(i), has_int_(true) {} @@ -5950,5 +6605,89 @@ TEST(VariantTest, InnerDoesNotMatch) { EXPECT_FALSE(m.Matches(SampleVariantIntString("2"))); } +class SampleAnyType { + public: + explicit SampleAnyType(int i) : index_(0), i_(i) {} + explicit SampleAnyType(const std::string& s) : index_(1), s_(s) {} + + template + friend const T* any_cast(const SampleAnyType* any) { + return any->get_impl(static_cast(NULL)); + } + + private: + int index_; + int i_; + std::string s_; + + const int* get_impl(int*) const { return index_ == 0 ? &i_ : NULL; } + const std::string* get_impl(std::string*) const { + return index_ == 1 ? &s_ : NULL; + } +}; + +TEST(AnyWithTest, FullMatch) { + Matcher m = AnyWith(Eq(1)); + EXPECT_TRUE(m.Matches(SampleAnyType(1))); +} + +TEST(AnyWithTest, TestBadCastType) { + Matcher m = AnyWith(Eq("fail")); + EXPECT_FALSE(m.Matches(SampleAnyType(1))); +} + +#if GTEST_LANG_CXX11 +TEST(AnyWithTest, TestUseInContainers) { + std::vector a; + a.emplace_back(1); + a.emplace_back(2); + a.emplace_back(3); + EXPECT_THAT( + a, ElementsAreArray({AnyWith(1), AnyWith(2), AnyWith(3)})); + + std::vector b; + b.emplace_back("hello"); + b.emplace_back("merhaba"); + b.emplace_back("salut"); + EXPECT_THAT(b, ElementsAreArray({AnyWith("hello"), + AnyWith("merhaba"), + AnyWith("salut")})); +} +#endif // GTEST_LANG_CXX11 +TEST(AnyWithTest, TestCompare) { + EXPECT_THAT(SampleAnyType(1), AnyWith(Gt(0))); +} + +TEST(AnyWithTest, DescribesSelf) { + const Matcher m = AnyWith(Eq(1)); + EXPECT_THAT(Describe(m), ContainsRegex("is an 'any' type with value of type " + "'.*' and the value is equal to 1")); +} + +TEST(AnyWithTest, ExplainsSelf) { + const Matcher m = AnyWith(Eq(1)); + + EXPECT_THAT(Explain(m, SampleAnyType(1)), ContainsRegex("whose value 1")); + EXPECT_THAT(Explain(m, SampleAnyType("A")), + HasSubstr("whose value is not of type '")); + EXPECT_THAT(Explain(m, SampleAnyType(2)), "whose value 2 doesn't match"); +} + +#if GTEST_LANG_CXX11 + +TEST(PointeeTest, WorksOnMoveOnlyType) { + std::unique_ptr p(new int(3)); + EXPECT_THAT(p, Pointee(Eq(3))); + EXPECT_THAT(p, Not(Pointee(Eq(2)))); +} + +TEST(NotTest, WorksOnMoveOnlyType) { + std::unique_ptr p(new int(3)); + EXPECT_THAT(p, Pointee(Eq(3))); + EXPECT_THAT(p, Not(Pointee(Eq(2)))); +} + +#endif // GTEST_LANG_CXX11 + } // namespace gmock_matchers_test } // namespace testing -- cgit v0.12 From af93d59eb7b3b2b4d678d999a6f302f0cd28d841 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 5 Apr 2018 11:35:20 -0400 Subject: Merging matchers test --- googlemock/test/gmock-matchers_test.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index d97889e..f0e42f5 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -157,6 +157,9 @@ using testing::internal::RE; using testing::internal::scoped_ptr; using testing::internal::StreamMatchResultListener; using testing::internal::Strings; +using testing::internal::linked_ptr; +using testing::internal::scoped_ptr; +using testing::internal::string; using testing::make_tuple; using testing::tuple; -- cgit v0.12 From 66eaf9f0eb894851f22544297f26aab39fe110d1 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 5 Apr 2018 11:55:25 -0400 Subject: Have to wait for this one --- 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 f0e42f5..daac032 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -758,7 +758,7 @@ TEST(MatcherCastTest, NonImplicitlyConstructibleTypeWithOperatorEq) { namespace convertible_from_any { // Implicitly convertible from any type. struct ConvertibleFromAny { - ConvertibleFromAny(int a_value) : value(a_value) {} + explicit ConvertibleFromAny(int a_value) : value(a_value) {} template ConvertibleFromAny(const T& /*a_value*/) : value(-1) { ADD_FAILURE() << "Conversion constructor called"; -- cgit v0.12 From 7045138a0d4fdc4c3d0bb582c3def9b3cbea9a26 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 5 Apr 2018 11:59:59 -0400 Subject: Have to wait for this one --- 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 daac032..33be41a 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -758,9 +758,9 @@ TEST(MatcherCastTest, NonImplicitlyConstructibleTypeWithOperatorEq) { namespace convertible_from_any { // Implicitly convertible from any type. struct ConvertibleFromAny { - explicit ConvertibleFromAny(int a_value) : value(a_value) {} + ConvertibleFromAny(int a_value) : value(a_value) {} template - ConvertibleFromAny(const T& /*a_value*/) : value(-1) { + explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) { ADD_FAILURE() << "Conversion constructor called"; } int value; -- cgit v0.12 From e0f4cf05614a90133b5912f149c1f59fdaf3aff6 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 5 Apr 2018 14:00:14 -0400 Subject: fixing MCVS warn --- googlemock/include/gmock/gmock-more-matchers.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/googlemock/include/gmock/gmock-more-matchers.h b/googlemock/include/gmock/gmock-more-matchers.h index a5a8bfa..85bc3c0 100644 --- a/googlemock/include/gmock/gmock-more-matchers.h +++ b/googlemock/include/gmock/gmock-more-matchers.h @@ -43,6 +43,16 @@ namespace testing { +// The macros trigger warning C4100 (unreferenced formal +// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in +// the macro definition, as the warnings are generated when the macro +// is expanded and macro expansion cannot contain #pragma. Therefore +// we suppress them here. +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:4100) +#endif + // Defines a matcher that matches an empty container. The container must // support both size() and empty(), which all STL-like containers provide. MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") { -- cgit v0.12 From 928636135b28d05f8f6a90cc8c015b01d8c63e30 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 5 Apr 2018 14:24:12 -0400 Subject: And more MCVS warnings --- googlemock/include/gmock/gmock-more-matchers.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/googlemock/include/gmock/gmock-more-matchers.h b/googlemock/include/gmock/gmock-more-matchers.h index 85bc3c0..bbfac0d 100644 --- a/googlemock/include/gmock/gmock-more-matchers.h +++ b/googlemock/include/gmock/gmock-more-matchers.h @@ -44,13 +44,12 @@ namespace testing { // The macros trigger warning C4100 (unreferenced formal -// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in -// the macro definition, as the warnings are generated when the macro -// is expanded and macro expansion cannot contain #pragma. Therefore -// we suppress them here. +// parameter) in MSVC with -W4. #ifdef _MSC_VER -# pragma warning(push) # pragma warning(disable:4100) +#if (_MSC_VER == 1900) +# pragma warning(disable:4800) + #endif #endif // Defines a matcher that matches an empty container. The container must -- cgit v0.12 From 7e5f90d3780d553cb86771141fb81349f3a63508 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 5 Apr 2018 14:41:16 -0400 Subject: formatting --- googlemock/include/gmock/gmock-more-matchers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googlemock/include/gmock/gmock-more-matchers.h b/googlemock/include/gmock/gmock-more-matchers.h index bbfac0d..01298cf 100644 --- a/googlemock/include/gmock/gmock-more-matchers.h +++ b/googlemock/include/gmock/gmock-more-matchers.h @@ -43,8 +43,8 @@ namespace testing { -// The macros trigger warning C4100 (unreferenced formal -// parameter) in MSVC with -W4. +// Silence C4100 (unreferenced formal +// parameter) for MSVC #ifdef _MSC_VER # pragma warning(disable:4100) #if (_MSC_VER == 1900) -- cgit v0.12 From fe402c27790ff1cc9a7e17c5d0aea4ebe7fd8a71 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 5 Apr 2018 16:09:17 -0400 Subject: Merging gMock, 2 --- .../gmock/gmock-generated-function-mockers.h | 373 ++++++++++++--------- .../gmock/gmock-generated-function-mockers.h.pump | 4 +- .../include/gmock/gmock-generated-nice-strict.h | 370 ++++++++++---------- googlemock/include/gmock/gmock-spec-builders.h | 107 +++--- googlemock/src/gmock-spec-builders.cc | 122 ++++--- googlemock/test/gmock-actions_test.cc | 1 + googlemock/test/gmock-spec-builders_test.cc | 2 - googlemock/test/gmock_output_test_.cc | 5 + googlemock/test/gmock_output_test_golden.txt | 9 +- 9 files changed, 573 insertions(+), 420 deletions(-) diff --git a/googlemock/include/gmock/gmock-generated-function-mockers.h b/googlemock/include/gmock/gmock-generated-function-mockers.h index 4fa5ca9..550cfd2 100644 --- a/googlemock/include/gmock/gmock-generated-function-mockers.h +++ b/googlemock/include/gmock/gmock-generated-function-mockers.h @@ -68,8 +68,8 @@ class FunctionMocker : public typedef R F(); typedef typename internal::Function::ArgumentTuple ArgumentTuple; - MockSpec& With() { - return this->current_spec(); + MockSpec With() { + return MockSpec(this, ::testing::make_tuple()); } R Invoke() { @@ -88,9 +88,8 @@ class FunctionMocker : public typedef R F(A1); typedef typename internal::Function::ArgumentTuple ArgumentTuple; - MockSpec& With(const Matcher& m1) { - this->current_spec().SetMatchers(::testing::make_tuple(m1)); - return this->current_spec(); + MockSpec With(const Matcher& m1) { + return MockSpec(this, ::testing::make_tuple(m1)); } R Invoke(A1 a1) { @@ -98,7 +97,7 @@ class FunctionMocker : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1)); + return this->InvokeWith(ArgumentTuple(internal::forward(a1))); } }; @@ -109,9 +108,8 @@ class FunctionMocker : public typedef R F(A1, A2); typedef typename internal::Function::ArgumentTuple ArgumentTuple; - MockSpec& With(const Matcher& m1, const Matcher& m2) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2)); - return this->current_spec(); + MockSpec With(const Matcher& m1, const Matcher& m2) { + return MockSpec(this, ::testing::make_tuple(m1, m2)); } R Invoke(A1 a1, A2 a2) { @@ -119,7 +117,8 @@ class FunctionMocker : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2)); + return this->InvokeWith(ArgumentTuple(internal::forward(a1), + internal::forward(a2))); } }; @@ -130,10 +129,9 @@ class FunctionMocker : public typedef R F(A1, A2, A3); typedef typename internal::Function::ArgumentTuple ArgumentTuple; - MockSpec& With(const Matcher& m1, const Matcher& m2, + MockSpec With(const Matcher& m1, const Matcher& m2, const Matcher& m3) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3)); - return this->current_spec(); + return MockSpec(this, ::testing::make_tuple(m1, m2, m3)); } R Invoke(A1 a1, A2 a2, A3 a3) { @@ -141,7 +139,8 @@ class FunctionMocker : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3)); + return this->InvokeWith(ArgumentTuple(internal::forward(a1), + internal::forward(a2), internal::forward(a3))); } }; @@ -152,10 +151,9 @@ class FunctionMocker : public typedef R F(A1, A2, A3, A4); typedef typename internal::Function::ArgumentTuple ArgumentTuple; - MockSpec& With(const Matcher& m1, const Matcher& m2, + MockSpec With(const Matcher& m1, const Matcher& m2, const Matcher& m3, const Matcher& m4) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4)); - return this->current_spec(); + return MockSpec(this, ::testing::make_tuple(m1, m2, m3, m4)); } R Invoke(A1 a1, A2 a2, A3 a3, A4 a4) { @@ -163,7 +161,9 @@ class FunctionMocker : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4)); + return this->InvokeWith(ArgumentTuple(internal::forward(a1), + internal::forward(a2), internal::forward(a3), + internal::forward(a4))); } }; @@ -175,10 +175,9 @@ class FunctionMocker : public typedef R F(A1, A2, A3, A4, A5); typedef typename internal::Function::ArgumentTuple ArgumentTuple; - MockSpec& With(const Matcher& m1, const Matcher& m2, + MockSpec With(const Matcher& m1, const Matcher& m2, const Matcher& m3, const Matcher& m4, const Matcher& m5) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5)); - return this->current_spec(); + return MockSpec(this, ::testing::make_tuple(m1, m2, m3, m4, m5)); } R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { @@ -186,7 +185,9 @@ class FunctionMocker : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5)); + return this->InvokeWith(ArgumentTuple(internal::forward(a1), + internal::forward(a2), internal::forward(a3), + internal::forward(a4), internal::forward(a5))); } }; @@ -198,12 +199,10 @@ class FunctionMocker : public typedef R F(A1, A2, A3, A4, A5, A6); typedef typename internal::Function::ArgumentTuple ArgumentTuple; - MockSpec& With(const Matcher& m1, const Matcher& m2, + MockSpec With(const Matcher& m1, const Matcher& m2, const Matcher& m3, const Matcher& m4, const Matcher& m5, const Matcher& m6) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5, - m6)); - return this->current_spec(); + return MockSpec(this, ::testing::make_tuple(m1, m2, m3, m4, m5, m6)); } R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { @@ -211,7 +210,10 @@ class FunctionMocker : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6)); + return this->InvokeWith(ArgumentTuple(internal::forward(a1), + internal::forward(a2), internal::forward(a3), + internal::forward(a4), internal::forward(a5), + internal::forward(a6))); } }; @@ -223,12 +225,10 @@ class FunctionMocker : public typedef R F(A1, A2, A3, A4, A5, A6, A7); typedef typename internal::Function::ArgumentTuple ArgumentTuple; - MockSpec& With(const Matcher& m1, const Matcher& m2, + MockSpec With(const Matcher& m1, const Matcher& m2, const Matcher& m3, const Matcher& m4, const Matcher& m5, const Matcher& m6, const Matcher& m7) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5, - m6, m7)); - return this->current_spec(); + return MockSpec(this, ::testing::make_tuple(m1, m2, m3, m4, m5, m6, m7)); } R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { @@ -236,7 +236,10 @@ class FunctionMocker : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7)); + return this->InvokeWith(ArgumentTuple(internal::forward(a1), + internal::forward(a2), internal::forward(a3), + internal::forward(a4), internal::forward(a5), + internal::forward(a6), internal::forward(a7))); } }; @@ -248,12 +251,11 @@ class FunctionMocker : public typedef R F(A1, A2, A3, A4, A5, A6, A7, A8); typedef typename internal::Function::ArgumentTuple ArgumentTuple; - MockSpec& With(const Matcher& m1, const Matcher& m2, + MockSpec With(const Matcher& m1, const Matcher& m2, const Matcher& m3, const Matcher& m4, const Matcher& m5, const Matcher& m6, const Matcher& m7, const Matcher& m8) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5, - m6, m7, m8)); - return this->current_spec(); + return MockSpec(this, ::testing::make_tuple(m1, m2, m3, m4, m5, m6, m7, + m8)); } R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) { @@ -261,7 +263,11 @@ class FunctionMocker : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8)); + return this->InvokeWith(ArgumentTuple(internal::forward(a1), + internal::forward(a2), internal::forward(a3), + internal::forward(a4), internal::forward(a5), + internal::forward(a6), internal::forward(a7), + internal::forward(a8))); } }; @@ -273,13 +279,12 @@ class FunctionMocker : public typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9); typedef typename internal::Function::ArgumentTuple ArgumentTuple; - MockSpec& With(const Matcher& m1, const Matcher& m2, + MockSpec With(const Matcher& m1, const Matcher& m2, const Matcher& m3, const Matcher& m4, const Matcher& m5, const Matcher& m6, const Matcher& m7, const Matcher& m8, const Matcher& m9) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5, - m6, m7, m8, m9)); - return this->current_spec(); + return MockSpec(this, ::testing::make_tuple(m1, m2, m3, m4, m5, m6, m7, + m8, m9)); } R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) { @@ -287,7 +292,11 @@ class FunctionMocker : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9)); + return this->InvokeWith(ArgumentTuple(internal::forward(a1), + internal::forward(a2), internal::forward(a3), + internal::forward(a4), internal::forward(a5), + internal::forward(a6), internal::forward(a7), + internal::forward(a8), internal::forward(a9))); } }; @@ -300,13 +309,12 @@ class FunctionMocker : public typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); typedef typename internal::Function::ArgumentTuple ArgumentTuple; - MockSpec& With(const Matcher& m1, const Matcher& m2, + MockSpec With(const Matcher& m1, const Matcher& m2, const Matcher& m3, const Matcher& m4, const Matcher& m5, const Matcher& m6, const Matcher& m7, const Matcher& m8, const Matcher& m9, const Matcher& m10) { - this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5, - m6, m7, m8, m9, m10)); - return this->current_spec(); + return MockSpec(this, ::testing::make_tuple(m1, m2, m3, m4, m5, m6, m7, + m8, m9, m10)); } R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, @@ -315,8 +323,12 @@ class FunctionMocker : public // by the C++ standard [14.6.4] here, as the base class type is // dependent on the template argument (and thus shouldn't be // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9, - a10)); + return this->InvokeWith(ArgumentTuple(internal::forward(a1), + internal::forward(a2), internal::forward(a3), + internal::forward(a4), internal::forward(a5), + internal::forward(a6), internal::forward(a7), + internal::forward(a8), internal::forward(a9), + internal::forward(a10))); } }; @@ -363,7 +375,7 @@ using internal::FunctionMocker; GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \ return GMOCK_MOCKER_(0, constness, Method).Invoke(); \ } \ - ::testing::MockSpec<__VA_ARGS__>& \ + ::testing::MockSpec<__VA_ARGS__> \ gmock_##Method() constness { \ GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \ return GMOCK_MOCKER_(0, constness, Method).With(); \ @@ -380,9 +392,11 @@ using internal::FunctionMocker; == 1), \ this_method_does_not_take_1_argument); \ GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(1, constness, Method).Invoke(gmock_a1); \ + return GMOCK_MOCKER_(1, constness, \ + Method).Invoke(::testing::internal::forward(gmock_a1)); \ } \ - ::testing::MockSpec<__VA_ARGS__>& \ + ::testing::MockSpec<__VA_ARGS__> \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \ return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \ @@ -393,16 +407,19 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2) constness { \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ + __VA_ARGS__) gmock_a2) constness { \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ == 2), \ this_method_does_not_take_2_arguments); \ GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(2, constness, Method).Invoke(gmock_a1, gmock_a2); \ + return GMOCK_MOCKER_(2, constness, \ + Method).Invoke(::testing::internal::forward(gmock_a1), \ + ::testing::internal::forward(gmock_a2)); \ } \ - ::testing::MockSpec<__VA_ARGS__>& \ + ::testing::MockSpec<__VA_ARGS__> \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \ GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \ @@ -414,18 +431,21 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3) constness { \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ + __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, \ + __VA_ARGS__) gmock_a3) constness { \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ == 3), \ this_method_does_not_take_3_arguments); \ GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(3, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3); \ + return GMOCK_MOCKER_(3, constness, \ + Method).Invoke(::testing::internal::forward(gmock_a1), \ + ::testing::internal::forward(gmock_a2), \ + ::testing::internal::forward(gmock_a3)); \ } \ - ::testing::MockSpec<__VA_ARGS__>& \ + ::testing::MockSpec<__VA_ARGS__> \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \ @@ -439,19 +459,22 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ + __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ == 4), \ this_method_does_not_take_4_arguments); \ GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(4, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4); \ + return GMOCK_MOCKER_(4, constness, \ + Method).Invoke(::testing::internal::forward(gmock_a1), \ + ::testing::internal::forward(gmock_a2), \ + ::testing::internal::forward(gmock_a3), \ + ::testing::internal::forward(gmock_a4)); \ } \ - ::testing::MockSpec<__VA_ARGS__>& \ + ::testing::MockSpec<__VA_ARGS__> \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ @@ -466,20 +489,24 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5) constness { \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ + __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ + __VA_ARGS__) gmock_a5) constness { \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ == 5), \ this_method_does_not_take_5_arguments); \ GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(5, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5); \ + return GMOCK_MOCKER_(5, constness, \ + Method).Invoke(::testing::internal::forward(gmock_a1), \ + ::testing::internal::forward(gmock_a2), \ + ::testing::internal::forward(gmock_a3), \ + ::testing::internal::forward(gmock_a4), \ + ::testing::internal::forward(gmock_a5)); \ } \ - ::testing::MockSpec<__VA_ARGS__>& \ + ::testing::MockSpec<__VA_ARGS__> \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ @@ -495,21 +522,26 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6) constness { \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ + __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ + __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, \ + __VA_ARGS__) gmock_a6) constness { \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ == 6), \ this_method_does_not_take_6_arguments); \ GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(6, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ + return GMOCK_MOCKER_(6, constness, \ + Method).Invoke(::testing::internal::forward(gmock_a1), \ + ::testing::internal::forward(gmock_a2), \ + ::testing::internal::forward(gmock_a3), \ + ::testing::internal::forward(gmock_a4), \ + ::testing::internal::forward(gmock_a5), \ + ::testing::internal::forward(gmock_a6)); \ } \ - ::testing::MockSpec<__VA_ARGS__>& \ + ::testing::MockSpec<__VA_ARGS__> \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ @@ -526,22 +558,27 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ + __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ + __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ == 7), \ this_method_does_not_take_7_arguments); \ GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(7, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ + return GMOCK_MOCKER_(7, constness, \ + Method).Invoke(::testing::internal::forward(gmock_a1), \ + ::testing::internal::forward(gmock_a2), \ + ::testing::internal::forward(gmock_a3), \ + ::testing::internal::forward(gmock_a4), \ + ::testing::internal::forward(gmock_a5), \ + ::testing::internal::forward(gmock_a6), \ + ::testing::internal::forward(gmock_a7)); \ } \ - ::testing::MockSpec<__VA_ARGS__>& \ + ::testing::MockSpec<__VA_ARGS__> \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ @@ -559,23 +596,29 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ - GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8) constness { \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ + __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ + __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \ + __VA_ARGS__) gmock_a8) constness { \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ == 8), \ this_method_does_not_take_8_arguments); \ GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(8, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ + return GMOCK_MOCKER_(8, constness, \ + Method).Invoke(::testing::internal::forward(gmock_a1), \ + ::testing::internal::forward(gmock_a2), \ + ::testing::internal::forward(gmock_a3), \ + ::testing::internal::forward(gmock_a4), \ + ::testing::internal::forward(gmock_a5), \ + ::testing::internal::forward(gmock_a6), \ + ::testing::internal::forward(gmock_a7), \ + ::testing::internal::forward(gmock_a8)); \ } \ - ::testing::MockSpec<__VA_ARGS__>& \ + ::testing::MockSpec<__VA_ARGS__> \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ @@ -594,25 +637,31 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ - GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \ - GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9) constness { \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ + __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ + __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \ + __VA_ARGS__) gmock_a8, GMOCK_ARG_(tn, 9, \ + __VA_ARGS__) gmock_a9) constness { \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ == 9), \ this_method_does_not_take_9_arguments); \ GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(9, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \ - gmock_a9); \ + return GMOCK_MOCKER_(9, constness, \ + Method).Invoke(::testing::internal::forward(gmock_a1), \ + ::testing::internal::forward(gmock_a2), \ + ::testing::internal::forward(gmock_a3), \ + ::testing::internal::forward(gmock_a4), \ + ::testing::internal::forward(gmock_a5), \ + ::testing::internal::forward(gmock_a6), \ + ::testing::internal::forward(gmock_a7), \ + ::testing::internal::forward(gmock_a8), \ + ::testing::internal::forward(gmock_a9)); \ } \ - ::testing::MockSpec<__VA_ARGS__>& \ + ::testing::MockSpec<__VA_ARGS__> \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ @@ -633,26 +682,32 @@ using internal::FunctionMocker; // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ - GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \ - GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \ - GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \ + GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ + __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ + __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \ + __VA_ARGS__) gmock_a8, GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \ + GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ == 10), \ this_method_does_not_take_10_arguments); \ GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(10, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \ - gmock_a10); \ + return GMOCK_MOCKER_(10, constness, \ + Method).Invoke(::testing::internal::forward(gmock_a1), \ + ::testing::internal::forward(gmock_a2), \ + ::testing::internal::forward(gmock_a3), \ + ::testing::internal::forward(gmock_a4), \ + ::testing::internal::forward(gmock_a5), \ + ::testing::internal::forward(gmock_a6), \ + ::testing::internal::forward(gmock_a7), \ + ::testing::internal::forward(gmock_a8), \ + ::testing::internal::forward(gmock_a9), \ + ::testing::internal::forward(gmock_a10)); \ } \ - ::testing::MockSpec<__VA_ARGS__>& \ + ::testing::MockSpec<__VA_ARGS__> \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ @@ -880,7 +935,7 @@ class MockFunction { MOCK_METHOD0_T(Call, R()); #if GTEST_HAS_STD_FUNCTION_ - std::function AsStdFunction() { + ::std::function AsStdFunction() { return [this]() -> R { return this->Call(); }; @@ -899,9 +954,9 @@ class MockFunction { MOCK_METHOD1_T(Call, R(A0)); #if GTEST_HAS_STD_FUNCTION_ - std::function AsStdFunction() { + ::std::function AsStdFunction() { return [this](A0 a0) -> R { - return this->Call(a0); + return this->Call(::std::move(a0)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -918,9 +973,9 @@ class MockFunction { MOCK_METHOD2_T(Call, R(A0, A1)); #if GTEST_HAS_STD_FUNCTION_ - std::function AsStdFunction() { + ::std::function AsStdFunction() { return [this](A0 a0, A1 a1) -> R { - return this->Call(a0, a1); + return this->Call(::std::move(a0), ::std::move(a1)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -937,9 +992,9 @@ class MockFunction { MOCK_METHOD3_T(Call, R(A0, A1, A2)); #if GTEST_HAS_STD_FUNCTION_ - std::function AsStdFunction() { + ::std::function AsStdFunction() { return [this](A0 a0, A1 a1, A2 a2) -> R { - return this->Call(a0, a1, a2); + return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -956,9 +1011,10 @@ class MockFunction { MOCK_METHOD4_T(Call, R(A0, A1, A2, A3)); #if GTEST_HAS_STD_FUNCTION_ - std::function AsStdFunction() { + ::std::function AsStdFunction() { return [this](A0 a0, A1 a1, A2 a2, A3 a3) -> R { - return this->Call(a0, a1, a2, a3); + return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2), + ::std::move(a3)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -976,9 +1032,10 @@ class MockFunction { MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4)); #if GTEST_HAS_STD_FUNCTION_ - std::function AsStdFunction() { + ::std::function AsStdFunction() { return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) -> R { - return this->Call(a0, a1, a2, a3, a4); + return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2), + ::std::move(a3), ::std::move(a4)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -996,9 +1053,10 @@ class MockFunction { MOCK_METHOD6_T(Call, R(A0, A1, A2, A3, A4, A5)); #if GTEST_HAS_STD_FUNCTION_ - std::function AsStdFunction() { + ::std::function AsStdFunction() { return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) -> R { - return this->Call(a0, a1, a2, a3, a4, a5); + return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2), + ::std::move(a3), ::std::move(a4), ::std::move(a5)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -1016,9 +1074,10 @@ class MockFunction { MOCK_METHOD7_T(Call, R(A0, A1, A2, A3, A4, A5, A6)); #if GTEST_HAS_STD_FUNCTION_ - std::function AsStdFunction() { + ::std::function AsStdFunction() { return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) -> R { - return this->Call(a0, a1, a2, a3, a4, a5, a6); + return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2), + ::std::move(a3), ::std::move(a4), ::std::move(a5), ::std::move(a6)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -1036,9 +1095,11 @@ class MockFunction { MOCK_METHOD8_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7)); #if GTEST_HAS_STD_FUNCTION_ - std::function AsStdFunction() { + ::std::function AsStdFunction() { return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) -> R { - return this->Call(a0, a1, a2, a3, a4, a5, a6, a7); + return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2), + ::std::move(a3), ::std::move(a4), ::std::move(a5), ::std::move(a6), + ::std::move(a7)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -1056,10 +1117,12 @@ class MockFunction { MOCK_METHOD9_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8)); #if GTEST_HAS_STD_FUNCTION_ - std::function AsStdFunction() { + ::std::function AsStdFunction() { return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) -> R { - return this->Call(a0, a1, a2, a3, a4, a5, a6, a7, a8); + return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2), + ::std::move(a3), ::std::move(a4), ::std::move(a5), ::std::move(a6), + ::std::move(a7), ::std::move(a8)); }; } #endif // GTEST_HAS_STD_FUNCTION_ @@ -1078,10 +1141,12 @@ class MockFunction { MOCK_METHOD10_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)); #if GTEST_HAS_STD_FUNCTION_ - std::function AsStdFunction() { + ::std::function AsStdFunction() { return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) -> R { - return this->Call(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); + return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2), + ::std::move(a3), ::std::move(a4), ::std::move(a5), ::std::move(a6), + ::std::move(a7), ::std::move(a8), ::std::move(a9)); }; } #endif // GTEST_HAS_STD_FUNCTION_ diff --git a/googlemock/include/gmock/gmock-generated-function-mockers.h.pump b/googlemock/include/gmock/gmock-generated-function-mockers.h.pump index 811502d..55dc6c5 100644 --- a/googlemock/include/gmock/gmock-generated-function-mockers.h.pump +++ b/googlemock/include/gmock/gmock-generated-function-mockers.h.pump @@ -1,6 +1,6 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to -$$ gmock-generated-function-mockers.h. +$$ This is a Pump source file. Please use Pump to convert +$$ it to gmock-generated-function-mockers.h. $$ $var n = 10 $$ The maximum arity we support. // Copyright 2007, Google Inc. diff --git a/googlemock/include/gmock/gmock-generated-nice-strict.h b/googlemock/include/gmock/gmock-generated-nice-strict.h index 4095f4d..af71fbd 100644 --- a/googlemock/include/gmock/gmock-generated-nice-strict.h +++ b/googlemock/include/gmock/gmock-generated-nice-strict.h @@ -51,10 +51,9 @@ // NiceMock. // // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of -// their respective base class, with up-to 10 arguments. Therefore -// you can write NiceMock(5, "a") to construct a nice mock -// where MockFoo has a constructor that accepts (int, const char*), -// for example. +// their respective base class. Therefore you can write +// NiceMock(5, "a") to construct a nice mock where MockFoo +// has a constructor that accepts (int, const char*), for example. // // A known limitation is that NiceMock, NaggyMock, // and StrictMock only works for mock methods defined using @@ -63,10 +62,6 @@ // or "strict" modifier may not affect it, depending on the compiler. // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT // supported. -// -// Another known limitation is that the constructors of the base mock -// cannot have arguments passed by non-const reference, which are -// banned by the Google C++ style guide anyway. #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ @@ -76,294 +71,329 @@ namespace testing { +namespace internal { + +// NiceMockBase serves as a mix-in to establish the "uninteresting call" +// behavior for NiceMock on construction. It accomplishes this via CRTP to get +// access to the derived MockClass. +template +class NiceMockBase { + protected: + NiceMockBase(); + + ~NiceMockBase(); +}; + +} // namespace internal + template -class NiceMock : public MockClass { +class NiceMock : public MockClass, public internal::NiceMockBase { public: - // We don't factor out the constructor body to a common method, as - // we have to avoid a possible clash with members of MockClass. - NiceMock() { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } - - // C++ doesn't (yet) allow inheritance of constructors, so we have - // to define it for each arity. + NiceMock() : MockClass() {} + +#if GTEST_LANG_CXX11 + // Ideally, we would inherit base class's constructors through a using + // declaration, which would preserve their visibility. However, many existing + // tests rely on the fact that current implementation reexports protected + // constructors as public. These tests would need to be cleaned up first. + + // Single argument constructor is special-cased so that it can be + // made explicit. + template + explicit NiceMock(A&& arg) : MockClass(std::forward(arg)) {} + + template + NiceMock(A1&& arg1, A2&& arg2, An&&... args) + : MockClass(std::forward(arg1), std::forward(arg2), + std::forward(args)...) {} +#else + // C++98 doesn't have variadic templates, so we have to define one + // for each arity. template - explicit NiceMock(const A1& a1) : MockClass(a1) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } + explicit NiceMock(const A1& a1) : MockClass(a1) {} template - NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } + NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {} template - NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } + NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {} template NiceMock(const A1& a1, const A2& a2, const A3& a3, - const A4& a4) : MockClass(a1, a2, a3, a4) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } + const A4& a4) : MockClass(a1, a2, a3, a4) {} template NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5) : MockClass(a1, a2, a3, a4, a5) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } + const A5& a5) : MockClass(a1, a2, a3, a4, a5) {} template NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } + const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {} template NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, - a6, a7) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } + a6, a7) {} template NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, - a2, a3, a4, a5, a6, a7, a8) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } + a2, a3, a4, a5, a6, a7, a8) {} template NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, - const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } + const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {} template NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, - const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } + const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {} - virtual ~NiceMock() { - ::testing::Mock::UnregisterCallReaction( - internal::ImplicitCast_(this)); - } +#endif // GTEST_LANG_CXX11 private: GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock); }; +namespace internal { + +template +NiceMockBase::NiceMockBase() { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_( + static_cast *>(this))); +} + +template +NiceMockBase::~NiceMockBase() { + ::testing::Mock::UnregisterCallReaction( + internal::ImplicitCast_( + static_cast*>(this))); +} + +} // namespace internal + +namespace internal { + +// NaggyMockBase serves as a mix-in to establish the "uninteresting call" +// behavior for NaggyMock on construction. It accomplishes this via CRTP to get +// access to the derived MockClass. +template +class NaggyMockBase { + protected: + NaggyMockBase(); + + ~NaggyMockBase(); +}; + +} // namespace internal + template -class NaggyMock : public MockClass { +class NaggyMock : public MockClass, public internal::NaggyMockBase { public: - // We don't factor out the constructor body to a common method, as - // we have to avoid a possible clash with members of MockClass. - NaggyMock() { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_(this)); - } - - // C++ doesn't (yet) allow inheritance of constructors, so we have - // to define it for each arity. + NaggyMock() : MockClass() {} + +#if GTEST_LANG_CXX11 + // Ideally, we would inherit base class's constructors through a using + // declaration, which would preserve their visibility. However, many existing + // tests rely on the fact that current implementation reexports protected + // constructors as public. These tests would need to be cleaned up first. + + // Single argument constructor is special-cased so that it can be + // made explicit. + template + explicit NaggyMock(A&& arg) : MockClass(std::forward(arg)) {} + + template + NaggyMock(A1&& arg1, A2&& arg2, An&&... args) + : MockClass(std::forward(arg1), std::forward(arg2), + std::forward(args)...) {} +#else + // C++98 doesn't have variadic templates, so we have to define one + // for each arity. template - explicit NaggyMock(const A1& a1) : MockClass(a1) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_(this)); - } + explicit NaggyMock(const A1& a1) : MockClass(a1) {} template - NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_(this)); - } + NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {} template - NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_(this)); - } + NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {} template NaggyMock(const A1& a1, const A2& a2, const A3& a3, - const A4& a4) : MockClass(a1, a2, a3, a4) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_(this)); - } + const A4& a4) : MockClass(a1, a2, a3, a4) {} template NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5) : MockClass(a1, a2, a3, a4, a5) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_(this)); - } + const A5& a5) : MockClass(a1, a2, a3, a4, a5) {} template NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_(this)); - } + const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {} template NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, - a6, a7) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_(this)); - } + a6, a7) {} template NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, - a2, a3, a4, a5, a6, a7, a8) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_(this)); - } + a2, a3, a4, a5, a6, a7, a8) {} template NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, - const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_(this)); - } + const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {} template NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, - const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_(this)); - } + const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {} - virtual ~NaggyMock() { - ::testing::Mock::UnregisterCallReaction( - internal::ImplicitCast_(this)); - } +#endif // GTEST_LANG_CXX11 private: GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock); }; +namespace internal { + +template +NaggyMockBase::NaggyMockBase() { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_( + static_cast *>(this))); +} + +template +NaggyMockBase::~NaggyMockBase() { + ::testing::Mock::UnregisterCallReaction( + internal::ImplicitCast_( + static_cast*>(this))); +} + +} // namespace internal + +namespace internal { + +// StrictMockBase serves as a mix-in to establish the "uninteresting call" +// behavior for StrictMock on construction. It accomplishes this via CRTP to get +// access to the derived MockClass. +template +class StrictMockBase { + protected: + StrictMockBase(); + + ~StrictMockBase(); +}; + +} // namespace internal + template -class StrictMock : public MockClass { +class StrictMock : public MockClass, + public internal::StrictMockBase { public: - // We don't factor out the constructor body to a common method, as - // we have to avoid a possible clash with members of MockClass. - StrictMock() { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } - - // C++ doesn't (yet) allow inheritance of constructors, so we have - // to define it for each arity. + StrictMock() : MockClass() {} + +#if GTEST_LANG_CXX11 + // Ideally, we would inherit base class's constructors through a using + // declaration, which would preserve their visibility. However, many existing + // tests rely on the fact that current implementation reexports protected + // constructors as public. These tests would need to be cleaned up first. + + // Single argument constructor is special-cased so that it can be + // made explicit. + template + explicit StrictMock(A&& arg) : MockClass(std::forward(arg)) {} + + template + StrictMock(A1&& arg1, A2&& arg2, An&&... args) + : MockClass(std::forward(arg1), std::forward(arg2), + std::forward(args)...) {} +#else + // C++98 doesn't have variadic templates, so we have to define one + // for each arity. template - explicit StrictMock(const A1& a1) : MockClass(a1) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } + explicit StrictMock(const A1& a1) : MockClass(a1) {} template - StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } + StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {} template - StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } + StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, + a3) {} template StrictMock(const A1& a1, const A2& a2, const A3& a3, - const A4& a4) : MockClass(a1, a2, a3, a4) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } + const A4& a4) : MockClass(a1, a2, a3, a4) {} template StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5) : MockClass(a1, a2, a3, a4, a5) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } + const A5& a5) : MockClass(a1, a2, a3, a4, a5) {} template StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } + const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {} template StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, - a6, a7) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } + a6, a7) {} template StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, - a2, a3, a4, a5, a6, a7, a8) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } + a2, a3, a4, a5, a6, a7, a8) {} template StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, - const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } + const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {} template StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, - const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } + const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {} - virtual ~StrictMock() { - ::testing::Mock::UnregisterCallReaction( - internal::ImplicitCast_(this)); - } +#endif // GTEST_LANG_CXX11 private: GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock); }; +namespace internal { + +template +StrictMockBase::StrictMockBase() { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_( + static_cast *>(this))); +} + +template +StrictMockBase::~StrictMockBase() { + ::testing::Mock::UnregisterCallReaction( + internal::ImplicitCast_( + static_cast*>(this))); +} + +} // namespace internal + // The following specializations catch some (relatively more common) // user errors of nesting nice and strict mocks. They do NOT catch // all possible errors. diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index c1b6301..6d7f920 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -103,6 +103,11 @@ class ExpectationTester; // Base class for function mockers. template class FunctionMockerBase; +// Uninteresting call behavior mixins. +template class NiceMockBase; +template class NaggyMockBase; +template class StrictMockBase; + // Protects the mock object registry (in class Mock), all function // mockers, and all expectations. // @@ -147,14 +152,13 @@ class GTEST_API_ UntypedFunctionMockerBase { // action fails. // L = * virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( - const void* untyped_args, const std::string& call_description) const = 0; + void* untyped_args, const std::string& call_description) const = 0; // Performs the given action with the given arguments and returns // the action's result. // L = * virtual UntypedActionResultHolderBase* UntypedPerformAction( - const void* untyped_action, - const void* untyped_args) const = 0; + const void* untyped_action, void* untyped_args) const = 0; // Writes a message that the call is uninteresting (i.e. neither // explicitly expected nor explicitly unexpected) to the given @@ -209,9 +213,8 @@ class GTEST_API_ UntypedFunctionMockerBase { // arguments. This function can be safely called from multiple // threads concurrently. The caller is responsible for deleting the // result. - UntypedActionResultHolderBase* UntypedInvokeWith( - const void* untyped_args) - GTEST_LOCK_EXCLUDED_(g_gmock_mutex); + UntypedActionResultHolderBase* UntypedInvokeWith(void* untyped_args) + GTEST_LOCK_EXCLUDED_(g_gmock_mutex); protected: typedef std::vector UntypedOnCallSpecs; @@ -236,6 +239,14 @@ class GTEST_API_ UntypedFunctionMockerBase { UntypedOnCallSpecs untyped_on_call_specs_; // All expectations for this function mocker. + // + // It's undefined behavior to interleave expectations (EXPECT_CALLs + // or ON_CALLs) and mock function calls. Also, the order of + // expectations is important. Therefore it's a logic race condition + // to read/write untyped_expectations_ concurrently. In order for + // tools like tsan to catch concurrent read/write accesses to + // untyped_expectations, we deliberately leave accesses to it + // unprotected. UntypedExpectations untyped_expectations_; }; // class UntypedFunctionMockerBase @@ -397,13 +408,13 @@ class GTEST_API_ Mock { friend class internal::FunctionMockerBase; template - friend class NiceMock; + friend class internal::NiceMockBase; template - friend class NaggyMock; + friend class internal::NaggyMockBase; template - friend class StrictMock; + friend class internal::StrictMockBase; // Tells Google Mock to allow uninteresting calls on the given mock // object. @@ -1252,8 +1263,9 @@ class MockSpec { // Constructs a MockSpec object, given the function mocker object // that the spec is associated with. - explicit MockSpec(internal::FunctionMockerBase* function_mocker) - : function_mocker_(function_mocker) {} + MockSpec(internal::FunctionMockerBase* function_mocker, + const ArgumentMatcherTuple& matchers) + : function_mocker_(function_mocker), matchers_(matchers) {} // Adds a new default action spec to the function mocker and returns // the newly created spec. @@ -1279,10 +1291,6 @@ class MockSpec { template friend class internal::FunctionMocker; - void SetMatchers(const ArgumentMatcherTuple& matchers) { - matchers_ = matchers; - } - // The function mocker that owns this spec. internal::FunctionMockerBase* const function_mocker_; // The argument matchers specified in the spec. @@ -1390,19 +1398,20 @@ class ActionResultHolder : public UntypedActionResultHolderBase { template static ActionResultHolder* PerformDefaultAction( const FunctionMockerBase* func_mocker, - const typename Function::ArgumentTuple& args, + typename RvalueRef::ArgumentTuple>::type args, const std::string& call_description) { - return new ActionResultHolder(Wrapper( - func_mocker->PerformDefaultAction(args, call_description))); + return new ActionResultHolder(Wrapper(func_mocker->PerformDefaultAction( + internal::move(args), call_description))); } // Performs the given action and returns the result in a new-ed // ActionResultHolder. template - static ActionResultHolder* - PerformAction(const Action& action, - const typename Function::ArgumentTuple& args) { - return new ActionResultHolder(Wrapper(action.Perform(args))); + static ActionResultHolder* PerformAction( + const Action& action, + typename RvalueRef::ArgumentTuple>::type args) { + return new ActionResultHolder( + Wrapper(action.Perform(internal::move(args)))); } private: @@ -1430,9 +1439,9 @@ class ActionResultHolder : public UntypedActionResultHolderBase { template static ActionResultHolder* PerformDefaultAction( const FunctionMockerBase* func_mocker, - const typename Function::ArgumentTuple& args, + typename RvalueRef::ArgumentTuple>::type args, const std::string& call_description) { - func_mocker->PerformDefaultAction(args, call_description); + func_mocker->PerformDefaultAction(internal::move(args), call_description); return new ActionResultHolder; } @@ -1441,8 +1450,8 @@ class ActionResultHolder : public UntypedActionResultHolderBase { template static ActionResultHolder* PerformAction( const Action& action, - const typename Function::ArgumentTuple& args) { - action.Perform(args); + typename RvalueRef::ArgumentTuple>::type args) { + action.Perform(internal::move(args)); return new ActionResultHolder; } @@ -1461,7 +1470,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { typedef typename Function::ArgumentTuple ArgumentTuple; typedef typename Function::ArgumentMatcherTuple ArgumentMatcherTuple; - FunctionMockerBase() : current_spec_(this) {} + FunctionMockerBase() {} // The destructor verifies that all expectations on this mock // function have been satisfied. If not, it will report Google Test @@ -1497,12 +1506,13 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // mutable state of this object, and thus can be called concurrently // without locking. // L = * - Result PerformDefaultAction(const ArgumentTuple& args, - const std::string& call_description) const { + Result PerformDefaultAction( + typename RvalueRef::ArgumentTuple>::type args, + const std::string& call_description) const { const OnCallSpec* const spec = this->FindOnCallSpec(args); if (spec != NULL) { - return spec->GetAction().Perform(args); + return spec->GetAction().Perform(internal::move(args)); } const std::string message = call_description + @@ -1524,11 +1534,11 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // action fails. The caller is responsible for deleting the result. // L = * virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( - const void* untyped_args, // must point to an ArgumentTuple + void* untyped_args, // must point to an ArgumentTuple const std::string& call_description) const { - const ArgumentTuple& args = - *static_cast(untyped_args); - return ResultHolder::PerformDefaultAction(this, args, call_description); + ArgumentTuple* args = static_cast(untyped_args); + return ResultHolder::PerformDefaultAction(this, internal::move(*args), + call_description); } // Performs the given action with the given arguments and returns @@ -1536,13 +1546,12 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // result. // L = * virtual UntypedActionResultHolderBase* UntypedPerformAction( - const void* untyped_action, const void* untyped_args) const { + const void* untyped_action, void* untyped_args) const { // Make a copy of the action before performing it, in case the // action deletes the mock object (and thus deletes itself). const Action action = *static_cast*>(untyped_action); - const ArgumentTuple& args = - *static_cast(untyped_args); - return ResultHolder::PerformAction(action, args); + ArgumentTuple* args = static_cast(untyped_args); + return ResultHolder::PerformAction(action, internal::move(*args)); } // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked(): @@ -1582,10 +1591,14 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // Returns the result of invoking this mock function with the given // arguments. This function can be safely called from multiple // threads concurrently. - Result InvokeWith(const ArgumentTuple& args) - GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { + Result InvokeWith( + typename RvalueRef::ArgumentTuple>::type args) + GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { + // const_cast is required since in C++98 we still pass ArgumentTuple around + // by const& instead of rvalue reference. + void* untyped_args = const_cast(static_cast(&args)); scoped_ptr holder( - DownCast_(this->UntypedInvokeWith(&args))); + DownCast_(this->UntypedInvokeWith(untyped_args))); return holder->Unwrap(); } @@ -1609,6 +1622,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { TypedExpectation* const expectation = new TypedExpectation(this, file, line, source_text, m); const linked_ptr untyped_expectation(expectation); + // See the definition of untyped_expectations_ for why access to + // it is unprotected here. untyped_expectations_.push_back(untyped_expectation); // Adds this expectation into the implicit sequence if there is one. @@ -1620,10 +1635,6 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { return *expectation; } - // The current spec (either default action spec or expectation spec) - // being described on this function mocker. - MockSpec& current_spec() { return current_spec_; } - private: template friend class TypedExpectation; @@ -1716,6 +1727,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { const ArgumentTuple& args) const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { g_gmock_mutex.AssertHeld(); + // See the definition of untyped_expectations_ for why access to + // it is unprotected here. for (typename UntypedExpectations::const_reverse_iterator it = untyped_expectations_.rbegin(); it != untyped_expectations_.rend(); ++it) { @@ -1766,10 +1779,6 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { } } - // The current spec (either default action spec or expectation spec) - // being described on this function mocker. - MockSpec current_spec_; - // There is no generally useful and implementable semantics of // copying a mock object, so copying a mock is usually a user error. // Thus we disallow copying function mockers. If the user really diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 93a83ae..b97bad0 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -41,6 +41,7 @@ #include #include #include +#include #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -99,12 +100,19 @@ void ExpectationBase::RetireAllPreRequisites() return; } - for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin(); - it != immediate_prerequisites_.end(); ++it) { - ExpectationBase* const prerequisite = it->expectation_base().get(); - if (!prerequisite->is_retired()) { - prerequisite->RetireAllPreRequisites(); - prerequisite->Retire(); + ::std::vector expectations(1, this); + while (!expectations.empty()) { + ExpectationBase* exp = expectations.back(); + expectations.pop_back(); + + for (ExpectationSet::const_iterator it = + exp->immediate_prerequisites_.begin(); + it != exp->immediate_prerequisites_.end(); ++it) { + ExpectationBase* next = it->expectation_base().get(); + if (!next->is_retired()) { + next->Retire(); + expectations.push_back(next); + } } } } @@ -114,11 +122,18 @@ void ExpectationBase::RetireAllPreRequisites() bool ExpectationBase::AllPrerequisitesAreSatisfied() const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { g_gmock_mutex.AssertHeld(); - for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin(); - it != immediate_prerequisites_.end(); ++it) { - if (!(it->expectation_base()->IsSatisfied()) || - !(it->expectation_base()->AllPrerequisitesAreSatisfied())) - return false; + ::std::vector expectations(1, this); + while (!expectations.empty()) { + const ExpectationBase* exp = expectations.back(); + expectations.pop_back(); + + for (ExpectationSet::const_iterator it = + exp->immediate_prerequisites_.begin(); + it != exp->immediate_prerequisites_.end(); ++it) { + const ExpectationBase* next = it->expectation_base().get(); + if (!next->IsSatisfied()) return false; + expectations.push_back(next); + } } return true; } @@ -127,19 +142,28 @@ bool ExpectationBase::AllPrerequisitesAreSatisfied() const void ExpectationBase::FindUnsatisfiedPrerequisites(ExpectationSet* result) const GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { g_gmock_mutex.AssertHeld(); - for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin(); - it != immediate_prerequisites_.end(); ++it) { - if (it->expectation_base()->IsSatisfied()) { - // If *it is satisfied and has a call count of 0, some of its - // pre-requisites may not be satisfied yet. - if (it->expectation_base()->call_count_ == 0) { - it->expectation_base()->FindUnsatisfiedPrerequisites(result); + ::std::vector expectations(1, this); + while (!expectations.empty()) { + const ExpectationBase* exp = expectations.back(); + expectations.pop_back(); + + for (ExpectationSet::const_iterator it = + exp->immediate_prerequisites_.begin(); + it != exp->immediate_prerequisites_.end(); ++it) { + const ExpectationBase* next = it->expectation_base().get(); + + if (next->IsSatisfied()) { + // If *it is satisfied and has a call count of 0, some of its + // pre-requisites may not be satisfied yet. + if (next->call_count_ == 0) { + expectations.push_back(next); + } + } else { + // Now that we know next is unsatisfied, we are not so interested + // in whether its pre-requisites are satisfied. Therefore we + // don't iterate into it here. + *result += *it; } - } else { - // Now that we know *it is unsatisfied, we are not so interested - // in whether its pre-requisites are satisfied. Therefore we - // don't recursively call FindUnsatisfiedPrerequisites() here. - *result += *it; } } } @@ -254,11 +278,13 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) { case kWarn: Log(kWarning, msg + - "\nNOTE: You can safely ignore the above warning unless this " - "call should not happen. Do not suppress it by blindly adding " - "an EXPECT_CALL() if you don't mean to enforce the call. " - "See https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#" - "knowing-when-to-expect for details.\n", + "\nNOTE: You can safely ignore the above warning unless this " + "call should not happen. Do not suppress it by blindly adding " + "an EXPECT_CALL() if you don't mean to enforce the call. " + "See " + "https://github.com/google/googletest/blob/master/googlemock/" + "docs/CookBook.md#" + "knowing-when-to-expect for details.\n", stack_frames_to_skip); break; default: // FAIL @@ -334,9 +360,10 @@ const char* UntypedFunctionMockerBase::Name() const // Calculates the result of invoking this mock function with the given // arguments, prints it, and returns it. The caller is responsible // for deleting the result. -UntypedActionResultHolderBase* -UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args) - GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { +UntypedActionResultHolderBase* UntypedFunctionMockerBase::UntypedInvokeWith( + void* const untyped_args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { + // See the definition of untyped_expectations_ for why access to it + // is unprotected here. if (untyped_expectations_.size() == 0) { // No expectation is set on this mock method - we have an // uninteresting call. @@ -355,16 +382,19 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args) // If the user allows this uninteresting call, we print it // only when they want informational messages. reaction == kAllow ? LogIsVisible(kInfo) : - // If the user wants this to be a warning, we print it only - // when they want to see warnings. - reaction == kWarn ? LogIsVisible(kWarning) : - // Otherwise, the user wants this to be an error, and we - // should always print detailed information in the error. - true; + // If the user wants this to be a warning, we print + // it only when they want to see warnings. + reaction == kWarn + ? LogIsVisible(kWarning) + : + // Otherwise, the user wants this to be an error, and we + // should always print detailed information in the error. + true; if (!need_to_report_uninteresting_call) { // Perform the action without printing the call information. - return this->UntypedPerformDefaultAction(untyped_args, "Function call: " + std::string(Name())); + return this->UntypedPerformDefaultAction( + untyped_args, "Function call: " + std::string(Name())); } // Warns about the uninteresting call. @@ -446,6 +476,8 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args) // Returns an Expectation object that references and co-owns exp, // which must be an expectation on this mock function. Expectation UntypedFunctionMockerBase::GetHandleOf(ExpectationBase* exp) { + // See the definition of untyped_expectations_ for why access to it + // is unprotected here. for (UntypedExpectations::const_iterator it = untyped_expectations_.begin(); it != untyped_expectations_.end(); ++it) { @@ -508,7 +540,7 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked() return expectations_met; } -static CallReaction intToCallReaction(int mock_behavior) { +CallReaction intToCallReaction(int mock_behavior) { if (mock_behavior >= kAllow && mock_behavior <= kFail) { return static_cast(mock_behavior); } @@ -582,9 +614,15 @@ class MockObjectRegistry { leaked_count++; } if (leaked_count > 0) { - std::cout << "\nERROR: " << leaked_count - << " leaked mock " << (leaked_count == 1 ? "object" : "objects") - << " found at program exit.\n"; + std::cout << "\nERROR: " << leaked_count << " leaked mock " + << (leaked_count == 1 ? "object" : "objects") + << " found at program exit. Expectations on a mock object is " + "verified when the object is destructed. Leaking a mock " + "means that its expectations aren't verified, which is " + "usually a test bug. If you really intend to leak a mock, " + "you can suppress this error using " + "testing::Mock::AllowLeak(mock_object), or you may use a " + "fake or stub instead of a mock.\n"; std::cout.flush(); ::std::cerr.flush(); // RUN_ALL_TESTS() has already returned when this destructor is diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 0128663..4601157 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -704,6 +704,7 @@ class MockClass { MOCK_METHOD0(MakeUnique, std::unique_ptr()); MOCK_METHOD0(MakeUniqueBase, std::unique_ptr()); MOCK_METHOD0(MakeVectorUnique, std::vector>()); + MOCK_METHOD1(TakeUnique, int(std::unique_ptr)); #endif private: diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index a7bf03e..6001582 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -748,7 +748,6 @@ TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) { testing::GMOCK_FLAG(default_mock_behavior) = original_behavior; } - #endif // GTEST_HAS_STREAM_REDIRECTION // Tests the semantics of ON_CALL(). @@ -2691,7 +2690,6 @@ int gmock_main(int argc, char **argv) { int main(int argc, char **argv) { #endif // GMOCK_RENAME_MAIN testing::InitGoogleMock(&argc, argv); - // Ensures that the tests pass no matter what value of // --gmock_catch_leaked_mocks and --gmock_verbose the user specifies. testing::GMOCK_FLAG(catch_leaked_mocks) = true; diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index d80e2b0..ca628df 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -273,6 +273,11 @@ MATCHER_P2(IsPair, first, second, "") { return Value(arg.first, first) && Value(arg.second, second); } +TEST_F(GMockOutputTest, PrintsMatcher) { + const testing::Matcher m1 = Ge(48); + EXPECT_THAT((std::pair(42, true)), IsPair(m1, true)); +} + void TestCatchesLeakedMocksInAdHocTests() { MockFoo* foo = new MockFoo; diff --git a/googlemock/test/gmock_output_test_golden.txt b/googlemock/test/gmock_output_test_golden.txt index 689d5ee..dbcb211 100644 --- a/googlemock/test/gmock_output_test_golden.txt +++ b/googlemock/test/gmock_output_test_golden.txt @@ -288,6 +288,12 @@ Stack trace: [ OK ] GMockOutputTest.ExplicitActionsRunOutWithDefaultAction [ RUN ] GMockOutputTest.CatchesLeakedMocks [ OK ] GMockOutputTest.CatchesLeakedMocks +[ RUN ] GMockOutputTest.PrintsMatcher +FILE:#: Failure +Value of: (std::pair(42, true)) +Expected: is pair (is >= 48, true) + Actual: (42, true) (of type std::pair) +[ FAILED ] GMockOutputTest.PrintsMatcher [ FAILED ] GMockOutputTest.UnexpectedCall [ FAILED ] GMockOutputTest.UnexpectedCallToVoidFunction [ FAILED ] GMockOutputTest.ExcessiveCall @@ -302,9 +308,10 @@ Stack trace: [ FAILED ] GMockOutputTest.MismatchArgumentsAndWith [ FAILED ] GMockOutputTest.UnexpectedCallWithDefaultAction [ FAILED ] GMockOutputTest.ExcessiveCallWithDefaultAction +[ FAILED ] GMockOutputTest.PrintsMatcher FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#. FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#. FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#. -ERROR: 3 leaked mock objects found at program exit. +ERROR: 3 leaked mock objects found at program exit. Expectations on a mock object is verified when the object is destructed. Leaking a mock means that its expectations aren't verified, which is usually a test bug. If you really intend to leak a mock, you can suppress this error using testing::Mock::AllowLeak(mock_object), or you may use a fake or stub instead of a mock. -- cgit v0.12 From 88fc7d7552ead9d9c224b06bf0d2c1f17e21d612 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 6 Apr 2018 09:50:01 -0400 Subject: merging gmock-actions 2 --- googlemock/include/gmock/gmock-actions.h | 90 +++++++++++++++---- googlemock/test/gmock-actions_test.cc | 144 ++++++++++++++++++++++++++++++- 2 files changed, 216 insertions(+), 18 deletions(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 90fd2ea..a2784f6 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -360,14 +360,20 @@ class Action { // Constructs a null Action. Needed for storing Action objects in // STL containers. - Action() : impl_(NULL) {} + Action() {} - // Constructs an Action from its implementation. A NULL impl is - // used to represent the "do-default" action. - explicit Action(ActionInterface* impl) : impl_(impl) {} +#if GTEST_LANG_CXX11 + // Construct an Action from a specified callable. + // This cannot take std::function directly, because then Action would not be + // directly constructible from lambda (it would require two conversions). + template , G>::value>::type> + Action(G&& fun) : fun_(::std::forward(fun)) {} // NOLINT +#endif - // Copy constructor. - Action(const Action& action) : impl_(action.impl_) {} + // Constructs an Action from its implementation. + explicit Action(ActionInterface* impl) : impl_(impl) {} // This constructor allows us to turn an Action object into an // Action, as long as F's arguments can be implicitly converted @@ -377,7 +383,13 @@ class Action { explicit Action(const Action& action); // Returns true iff this is the DoDefault() action. - bool IsDoDefault() const { return impl_.get() == NULL; } + bool IsDoDefault() const { +#if GTEST_LANG_CXX11 + return impl_ == nullptr && fun_ == nullptr; +#else + return impl_ == NULL; +#endif + } // Performs the action. Note that this method is const even though // the corresponding method in ActionInterface is not. The reason @@ -385,14 +397,15 @@ class Action { // another concrete action, not that the concrete action it binds to // cannot change state. (Think of the difference between a const // pointer and a pointer to const.) - Result Perform(const ArgumentTuple& args) const { - internal::Assert( - !IsDoDefault(), __FILE__, __LINE__, - "You are using DoDefault() inside a composite action like " - "DoAll() or WithArgs(). This is not supported for technical " - "reasons. Please instead spell out the default action, or " - "assign the default action to an Action variable and use " - "the variable in various places."); + Result Perform(ArgumentTuple args) const { + if (IsDoDefault()) { + internal::IllegalDoDefault(__FILE__, __LINE__); + } +#if GTEST_LANG_CXX11 + if (fun_ != nullptr) { + return internal::Apply(fun_, ::std::move(args)); + } +#endif return impl_->Perform(args); } @@ -400,6 +413,18 @@ class Action { template friend class internal::ActionAdaptor; + template + friend class Action; + + // In C++11, Action can be implemented either as a generic functor (through + // std::function), or legacy ActionInterface. In C++98, only ActionInterface + // is available. The invariants are as follows: + // * in C++98, impl_ is null iff this is the default action + // * in C++11, at most one of fun_ & impl_ may be nonnull; both are null iff + // this is the default action +#if GTEST_LANG_CXX11 + ::std::function fun_; +#endif internal::linked_ptr > impl_; }; @@ -531,6 +556,9 @@ struct ByMoveWrapper { // statement, and conversion of the result of Return to Action is a // good place for that. // +// The real life example of the above scenario happens when an invocation +// of gtl::Container() is passed into Return. +// template class ReturnAction { public: @@ -750,7 +778,7 @@ class DoDefaultAction { // This template type conversion operator allows DoDefault() to be // used in any function. template - operator Action() const { return Action(NULL); } + operator Action() const { return Action(); } // NOLINT }; // Implements the Assign action to set a given pointer referent to a @@ -886,6 +914,28 @@ class InvokeMethodWithoutArgsAction { GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction); }; +// Implements the InvokeWithoutArgs(callback) action. +template +class InvokeCallbackWithoutArgsAction { + public: + // The c'tor takes ownership of the callback. + explicit InvokeCallbackWithoutArgsAction(CallbackType* callback) + : callback_(callback) { + callback->CheckIsRepeatable(); // Makes sure the callback is permanent. + } + + // This type conversion operator template allows Invoke(callback) to + // be used wherever the callback's return type can be implicitly + // converted to that of the mock function. + template + Result Perform(const ArgumentTuple&) const { return callback_->Run(); } + + private: + const internal::linked_ptr callback_; + + GTEST_DISALLOW_ASSIGN_(InvokeCallbackWithoutArgsAction); +}; + // Implements the IgnoreResult(action) action. template class IgnoreResultAction { @@ -1053,7 +1103,13 @@ typedef internal::IgnoredValue Unused; template template Action::Action(const Action& from) - : impl_(new internal::ActionAdaptor(from)) {} + : +#if GTEST_LANG_CXX11 + fun_(from.fun_), +#endif + impl_(from.impl_ == NULL ? NULL + : new internal::ActionAdaptor(from)) { +} // Creates an action that returns 'value'. 'value' is passed by value // instead of const reference - otherwise Return("string literal") diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 4601157..ea6129d 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -65,6 +65,7 @@ using testing::ReturnRef; using testing::ReturnRefOfCopy; using testing::SetArgPointee; using testing::SetArgumentPointee; +using testing::Unused; using testing::_; using testing::get; using testing::internal::BuiltInDefaultValue; @@ -705,6 +706,8 @@ class MockClass { MOCK_METHOD0(MakeUniqueBase, std::unique_ptr()); MOCK_METHOD0(MakeVectorUnique, std::vector>()); MOCK_METHOD1(TakeUnique, int(std::unique_ptr)); + MOCK_METHOD2(TakeUnique, + int(const std::unique_ptr&, std::unique_ptr)); #endif private: @@ -756,7 +759,7 @@ TEST(DoDefaultDeathTest, DiesIfUsedInCompositeAction) { } // Tests that DoDefault() returns the default value set by -// DefaultValue::Set() when it's not overridden by an ON_CALL(). +// DefaultValue::Set() when it's not overriden by an ON_CALL(). TEST(DoDefaultTest, ReturnsUserSpecifiedPerTypeDefaultValueWhenThereIsOne) { DefaultValue::Set(1); MockClass mock; @@ -1411,6 +1414,145 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) { EXPECT_EQ(7, *vresult[0]); } +TEST(MockMethodTest, CanTakeMoveOnlyValue) { + MockClass mock; + auto make = [](int i) { return std::unique_ptr(new int(i)); }; + + EXPECT_CALL(mock, TakeUnique(_)).WillRepeatedly([](std::unique_ptr i) { + return *i; + }); + // DoAll() does not compile, since it would move from its arguments twice. + // EXPECT_CALL(mock, TakeUnique(_, _)) + // .WillRepeatedly(DoAll(Invoke([](std::unique_ptr j) {}), + // Return(1))); + EXPECT_CALL(mock, TakeUnique(testing::Pointee(7))) + .WillOnce(Return(-7)) + .RetiresOnSaturation(); + EXPECT_CALL(mock, TakeUnique(testing::IsNull())) + .WillOnce(Return(-1)) + .RetiresOnSaturation(); + + EXPECT_EQ(5, mock.TakeUnique(make(5))); + EXPECT_EQ(-7, mock.TakeUnique(make(7))); + EXPECT_EQ(7, mock.TakeUnique(make(7))); + EXPECT_EQ(7, mock.TakeUnique(make(7))); + EXPECT_EQ(-1, mock.TakeUnique({})); + + // Some arguments are moved, some passed by reference. + auto lvalue = make(6); + EXPECT_CALL(mock, TakeUnique(_, _)) + .WillOnce([](const std::unique_ptr& i, std::unique_ptr j) { + return *i * *j; + }); + EXPECT_EQ(42, mock.TakeUnique(lvalue, make(7))); + + // The unique_ptr can be saved by the action. + std::unique_ptr saved; + EXPECT_CALL(mock, TakeUnique(_)).WillOnce([&saved](std::unique_ptr i) { + saved = std::move(i); + return 0; + }); + EXPECT_EQ(0, mock.TakeUnique(make(42))); + EXPECT_EQ(42, *saved); +} + #endif // GTEST_HAS_STD_UNIQUE_PTR_ +#if GTEST_LANG_CXX11 +// Tests for std::function based action. + +int Add(int val, int& ref, int* ptr) { // NOLINT + int result = val + ref + *ptr; + ref = 42; + *ptr = 43; + return result; +} + +int Deref(std::unique_ptr ptr) { return *ptr; } + +struct Double { + template + T operator()(T t) { return 2 * t; } +}; + +std::unique_ptr UniqueInt(int i) { + return std::unique_ptr(new int(i)); +} + +TEST(FunctorActionTest, ActionFromFunction) { + Action a = &Add; + int x = 1, y = 2, z = 3; + EXPECT_EQ(6, a.Perform(std::forward_as_tuple(x, y, &z))); + EXPECT_EQ(42, y); + EXPECT_EQ(43, z); + + Action)> a1 = &Deref; + EXPECT_EQ(7, a1.Perform(std::make_tuple(UniqueInt(7)))); +} + +TEST(FunctorActionTest, ActionFromLambda) { + Action a1 = [](bool b, int i) { return b ? i : 0; }; + EXPECT_EQ(5, a1.Perform(make_tuple(true, 5))); + EXPECT_EQ(0, a1.Perform(make_tuple(false, 5))); + + std::unique_ptr saved; + Action)> a2 = [&saved](std::unique_ptr p) { + saved = std::move(p); + }; + a2.Perform(make_tuple(UniqueInt(5))); + EXPECT_EQ(5, *saved); +} + +TEST(FunctorActionTest, PolymorphicFunctor) { + Action ai = Double(); + EXPECT_EQ(2, ai.Perform(make_tuple(1))); + Action ad = Double(); // Double? Double double! + EXPECT_EQ(3.0, ad.Perform(make_tuple(1.5))); +} + +TEST(FunctorActionTest, TypeConversion) { + // Numeric promotions are allowed. + const Action a1 = [](int i) { return i > 1; }; + const Action a2 = Action(a1); + EXPECT_EQ(1, a1.Perform(make_tuple(42))); + EXPECT_EQ(0, a2.Perform(make_tuple(42))); + + // Implicit constructors are allowed. + const Action s1 = [](std::string s) { return !s.empty(); }; + const Action s2 = Action(s1); + EXPECT_EQ(0, s2.Perform(make_tuple(""))); + EXPECT_EQ(1, s2.Perform(make_tuple("hello"))); + + // Also between the lambda and the action itself. + const Action x = [](Unused) { return 42; }; + EXPECT_TRUE(x.Perform(make_tuple("hello"))); +} + +TEST(FunctorActionTest, UnusedArguments) { + // Verify that users can ignore uninteresting arguments. + Action, const int&)> a = + [](int i, Unused, Unused) { return 2 * i; }; + EXPECT_EQ(6, a.Perform(make_tuple(3, UniqueInt(7), 9))); +} + +// Test that basic built-in actions work with move-only arguments. +// TODO(rburny): Currently, almost all ActionInterface-based actions will not +// work, even if they only try to use other, copyable arguments. Implement them +// if necessary (but note that DoAll cannot work on non-copyable types anyway - +// so maybe it's better to make users use lambdas instead. +TEST(MoveOnlyArgumentsTest, ReturningActions) { + Action)> a = Return(1); + EXPECT_EQ(1, a.Perform(make_tuple(nullptr))); + + a = testing::WithoutArgs([]() { return 7; }); + EXPECT_EQ(7, a.Perform(make_tuple(nullptr))); + + Action, int*)> a2 = testing::SetArgPointee<1>(3); + int x = 0; + a2.Perform(make_tuple(nullptr, &x)); + EXPECT_EQ(x, 3); +} + +#endif // GTEST_LANG_CXX11 + } // Unnamed namespace -- cgit v0.12 From b5c87fbcb6b708026bc83c01e38a43691c9064a0 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 6 Apr 2018 10:01:40 -0400 Subject: Deal with MCVS warnings --- googlemock/include/gmock/internal/gmock-internal-utils.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 37ceb54..030a1d6 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -48,6 +48,12 @@ namespace testing { namespace internal { +// Silence C4100 (unreferenced formal +// parameter) for MSVC +#ifdef _MSC_VER +# pragma warning(disable:4100) +#endif + // Joins a vector of strings as if they are fields of a tuple; returns // the joined string. GTEST_API_ std::string JoinAsTuple(const Strings& fields); -- cgit v0.12 From 50c0bcd7e36374d6c3d0359c2160d8493e67527e Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 6 Apr 2018 10:15:00 -0400 Subject: Cont. deal with MCVS warnings --- googlemock/include/gmock/gmock-more-matchers.h | 6 ++++++ googlemock/include/gmock/internal/gmock-internal-utils.h | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/googlemock/include/gmock/gmock-more-matchers.h b/googlemock/include/gmock/gmock-more-matchers.h index 01298cf..4c24832 100644 --- a/googlemock/include/gmock/gmock-more-matchers.h +++ b/googlemock/include/gmock/gmock-more-matchers.h @@ -46,6 +46,7 @@ namespace testing { // Silence C4100 (unreferenced formal // parameter) for MSVC #ifdef _MSC_VER +# pragma warning(push) # pragma warning(disable:4100) #if (_MSC_VER == 1900) # pragma warning(disable:4800) @@ -78,6 +79,11 @@ MATCHER(IsFalse, negation ? "is true" : "is false") { return !static_cast(arg); } +#ifdef _MSC_VER +# pragma warning(pop) +#endif + + } // namespace testing #endif // GMOCK_GMOCK_MORE_MATCHERS_H_ diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 030a1d6..85becb5 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -48,10 +48,12 @@ namespace testing { namespace internal { -// Silence C4100 (unreferenced formal -// parameter) for MSVC +// Silence MSVC C4100 (unreferenced formal parameter) and +// C4805('==': unsafe mix of type 'const int' and type 'const bool') #ifdef _MSC_VER +# pragma warning(push) # pragma warning(disable:4100) +# pragma warning(disable:C4805) #endif // Joins a vector of strings as if they are fields of a tuple; returns @@ -545,6 +547,12 @@ auto Apply(F&& f, Tuple&& args) make_int_pack::value>()); } #endif + + +#ifdef _MSC_VER +# pragma warning(pop) +#endif + } // namespace internal } // namespace testing -- cgit v0.12 From eb3e4aac2e7f740a207f2bb3207cb925b9270c0e Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 6 Apr 2018 10:24:49 -0400 Subject: deal with MSVC warn, cont 1 --- googlemock/include/gmock/internal/gmock-internal-utils.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 85becb5..29b6992 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -52,8 +52,7 @@ namespace internal { // C4805('==': unsafe mix of type 'const int' and type 'const bool') #ifdef _MSC_VER # pragma warning(push) -# pragma warning(disable:4100) -# pragma warning(disable:C4805) +# pragma warning(disable: 4100 C4805) #endif // Joins a vector of strings as if they are fields of a tuple; returns -- cgit v0.12 From 1831ac93611ab478e8bbaf0f6ce8048fd9560835 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 6 Apr 2018 10:35:09 -0400 Subject: more warnings --- googlemock/include/gmock/internal/gmock-internal-utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 29b6992..76df2e5 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -52,7 +52,7 @@ namespace internal { // C4805('==': unsafe mix of type 'const int' and type 'const bool') #ifdef _MSC_VER # pragma warning(push) -# pragma warning(disable: 4100 C4805) +# pragma warning(disable: 4100, C4805) #endif // Joins a vector of strings as if they are fields of a tuple; returns -- cgit v0.12 From 32ac9492544cf099859492038093cd5819056946 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 6 Apr 2018 10:43:11 -0400 Subject: cont --- googlemock/include/gmock/internal/gmock-internal-utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 76df2e5..7f76134 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -52,7 +52,7 @@ namespace internal { // C4805('==': unsafe mix of type 'const int' and type 'const bool') #ifdef _MSC_VER # pragma warning(push) -# pragma warning(disable: 4100, C4805) +# pragma warning(disable: 4100 4805;) #endif // Joins a vector of strings as if they are fields of a tuple; returns -- cgit v0.12 From 04e31881fcc21a23b552584062b672055fb288c0 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 6 Apr 2018 10:52:49 -0400 Subject: cont - 2 --- googlemock/include/gmock/internal/gmock-internal-utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 7f76134..00c6cc3 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -52,7 +52,7 @@ namespace internal { // C4805('==': unsafe mix of type 'const int' and type 'const bool') #ifdef _MSC_VER # pragma warning(push) -# pragma warning(disable: 4100 4805;) +# pragma warning(disable:4100 4805;) #endif // Joins a vector of strings as if they are fields of a tuple; returns -- cgit v0.12 From c75b76e20ae06e506ef72a3339208f14fd376493 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 6 Apr 2018 11:00:13 -0400 Subject: warnings --- googlemock/include/gmock/internal/gmock-internal-utils.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 00c6cc3..ef150e0 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -52,7 +52,8 @@ namespace internal { // C4805('==': unsafe mix of type 'const int' and type 'const bool') #ifdef _MSC_VER # pragma warning(push) -# pragma warning(disable:4100 4805;) +# pragma warning(disable:4100) +# pragma warning(disable:4805) #endif // Joins a vector of strings as if they are fields of a tuple; returns -- cgit v0.12 From d9f3611a227cf51eb8028b07e58ba330d3a04092 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 6 Apr 2018 11:17:45 -0400 Subject: more MSVC warnings --- googletest/include/gtest/gtest.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 26e787d..3de5fca 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -82,6 +82,13 @@ namespace testing { +// Silence C4100 (unreferenced formal parameter) for MSVC +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:4100) +#endif + + // Declares the flags. // This flag temporary enables the disabled tests. @@ -2298,6 +2305,10 @@ bool StaticAssertTypeEq() { // Tries to determine an appropriate directory for the platform. GTEST_API_ std::string TempDir(); +#ifdef _MSC_VER +# pragma warning(pop) +#endif + } // namespace testing // Use this function in main() to run all tests. It returns 0 if all -- cgit v0.12 From cb13dc759c4697becda3b2ede7f3ba3e5c2765f2 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 6 Apr 2018 11:26:12 -0400 Subject: more warnings --- googletest/include/gtest/gtest.h | 1 + 1 file changed, 1 insertion(+) diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 3de5fca..cbab121 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -86,6 +86,7 @@ namespace testing { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable:4100) +# pragma warning(disable:4805) #endif -- cgit v0.12 From 5fe8de5ded685541a63b0ac22b1cfb4c59406dfd Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 6 Apr 2018 11:40:04 -0400 Subject: more warnings --- googlemock/test/gmock_output_test_.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index ca628df..d5f909d 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -39,6 +39,14 @@ #include "gtest/gtest.h" + +// Silence C4100 (unreferenced formal parameter) for MSVC +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:4100) +#endif + + using testing::_; using testing::AnyNumber; using testing::Ge; @@ -298,3 +306,7 @@ int main(int argc, char **argv) { TestCatchesLeakedMocksInAdHocTests(); return RUN_ALL_TESTS(); } + +#ifdef _MSC_VER +# pragma warning(pop) +#endif -- cgit v0.12 From 2d4d4ef7392bc577449ade669b282853cb7adb39 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 6 Apr 2018 16:31:11 -0400 Subject: fixing MSVC --- googlemock/include/gmock/gmock-more-matchers.h | 2 ++ googlemock/src/gmock-internal-utils.cc | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/googlemock/include/gmock/gmock-more-matchers.h b/googlemock/include/gmock/gmock-more-matchers.h index 4c24832..6d810eb 100644 --- a/googlemock/include/gmock/gmock-more-matchers.h +++ b/googlemock/include/gmock/gmock-more-matchers.h @@ -49,6 +49,8 @@ namespace testing { # pragma warning(push) # pragma warning(disable:4100) #if (_MSC_VER == 1900) +// and silence C4800 (C4800: 'int *const ': forcing value +// to bool 'true' or 'false') for MSVC 14 # pragma warning(disable:4800) #endif #endif diff --git a/googlemock/src/gmock-internal-utils.cc b/googlemock/src/gmock-internal-utils.cc index 20c5a8d..3fca3f2 100644 --- a/googlemock/src/gmock-internal-utils.cc +++ b/googlemock/src/gmock-internal-utils.cc @@ -188,7 +188,7 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message, std::cout << ::std::flush; } -void IllegalDoDefault(const char* file, int line) { +GTEST_API_ void IllegalDoDefault(const char* file, int line) { internal::Assert( false, file, line, "You are using DoDefault() inside a composite action like " -- cgit v0.12 From 701e1e5dc1ccd25e7a55891d2dd6b4edb8f1f442 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 6 Apr 2018 16:43:35 -0400 Subject: linkage, fixing MSVC --- googlemock/include/gmock/internal/gmock-internal-utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index ef150e0..20c95c6 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -518,7 +518,7 @@ struct BooleanConstant {}; // Emit an assertion failure due to incorrect DoDefault() usage. Out-of-lined to // reduce code size. -void IllegalDoDefault(const char* file, int line); +GTEST_API_ void IllegalDoDefault(const char* file, int line); #if GTEST_LANG_CXX11 // Helper types for Apply() below. -- cgit v0.12 From dbd206e3d9aecf4a0abe11e051b71a098252c9d2 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 6 Apr 2018 16:55:46 -0400 Subject: more mcvs fixing --- googlemock/src/gmock-spec-builders.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index b97bad0..39a3fe7 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -49,6 +49,14 @@ # include // NOLINT #endif +// Silence C4800 (C4800: 'int *const ': forcing value +// to bool 'true' or 'false') for MSVC 14 +#ifdef _MSC_VER && _MSC_VER == 1900 +# pragma warning(push) +# pragma warning(disable:4800) +#endif + + namespace testing { namespace internal { @@ -866,3 +874,7 @@ InSequence::~InSequence() { } } // namespace testing + +#ifdef _MSC_VER && _MSC_VER == 1900 +# pragma warning(pop) +#endif -- cgit v0.12 From 51f8ad47df298964f48cb89e1d7bf953f49e6731 Mon Sep 17 00:00:00 2001 From: Victor Costan Date: Fri, 6 Apr 2018 17:17:35 -0700 Subject: Sync gmock-generated-nice-strict.h.pump with gmock-generated-nice-strict.h. Commit fe402c27790ff1cc9a7e17c5d0aea4ebe7fd8a71 published the changes in internal CL 156157936, but missed the diff in gmock-generated-nice-strict.h.pump. This makes it difficult to reason about the change, because the .pump file is more concise than the generated file. This PR was tested by re-generating the .h file using the command below and checking the git diff. ./googletest/scripts/pump.py \ googlemock/include/gmock/gmock-generated-nice-strict.h.pump --- .../gmock/gmock-generated-nice-strict.h.pump | 90 ++++++++++++++-------- 1 file changed, 60 insertions(+), 30 deletions(-) diff --git a/googlemock/include/gmock/gmock-generated-nice-strict.h.pump b/googlemock/include/gmock/gmock-generated-nice-strict.h.pump index 3ee1ce7..4973c35 100644 --- a/googlemock/include/gmock/gmock-generated-nice-strict.h.pump +++ b/googlemock/include/gmock/gmock-generated-nice-strict.h.pump @@ -52,10 +52,9 @@ $var n = 10 $$ The maximum arity we support. // NiceMock. // // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of -// their respective base class, with up-to $n arguments. Therefore -// you can write NiceMock(5, "a") to construct a nice mock -// where MockFoo has a constructor that accepts (int, const char*), -// for example. +// their respective base class. Therefore you can write +// NiceMock(5, "a") to construct a nice mock where MockFoo +// has a constructor that accepts (int, const char*), for example. // // A known limitation is that NiceMock, NaggyMock, // and StrictMock only works for mock methods defined using @@ -64,10 +63,6 @@ $var n = 10 $$ The maximum arity we support. // or "strict" modifier may not affect it, depending on the compiler. // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT // supported. -// -// Another known limitation is that the constructors of the base mock -// cannot have arguments passed by non-const reference, which are -// banned by the Google C++ style guide anyway. #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ @@ -88,44 +83,79 @@ $var method=[[$if kind==0 [[AllowUninterestingCalls]] $elif kind==1 [[WarnUninterestingCalls]] $else [[FailUninterestingCalls]]]] +namespace internal { + +// $clazz[[]]Base serves as a mix-in to establish the "uninteresting call" +// behavior for $clazz on construction. It accomplishes this via CRTP to get +// access to the derived MockClass. +template +class $clazz[[]]Base { + protected: + $clazz[[]]Base(); + + ~$clazz[[]]Base(); +}; + +} // namespace internal + template -class $clazz : public MockClass { +class $clazz : public MockClass, public internal::$clazz[[]]Base { public: - // We don't factor out the constructor body to a common method, as - // we have to avoid a possible clash with members of MockClass. - $clazz() { - ::testing::Mock::$method( - internal::ImplicitCast_(this)); - } - - // C++ doesn't (yet) allow inheritance of constructors, so we have - // to define it for each arity. + $clazz() : MockClass() {} + +#if GTEST_LANG_CXX11 + // Ideally, we would inherit base class's constructors through a using + // declaration, which would preserve their visibility. However, many existing + // tests rely on the fact that current implementation reexports protected + // constructors as public. These tests would need to be cleaned up first. + + // Single argument constructor is special-cased so that it can be + // made explicit. + template + explicit $clazz(A&& arg) : MockClass(std::forward(arg)) {} + + template + $clazz(A1&& arg1, A2&& arg2, An&&... args) + : MockClass(std::forward(arg1), std::forward(arg2), + std::forward(args)...) {} +#else + // C++98 doesn't have variadic templates, so we have to define one + // for each arity. template - explicit $clazz(const A1& a1) : MockClass(a1) { - ::testing::Mock::$method( - internal::ImplicitCast_(this)); - } + explicit $clazz(const A1& a1) : MockClass(a1) {} $range i 2..n $for i [[ $range j 1..i template <$for j, [[typename A$j]]> - $clazz($for j, [[const A$j& a$j]]) : MockClass($for j, [[a$j]]) { - ::testing::Mock::$method( - internal::ImplicitCast_(this)); - } + $clazz($for j, [[const A$j& a$j]]) : MockClass($for j, [[a$j]]) {} ]] - virtual ~$clazz() { - ::testing::Mock::UnregisterCallReaction( - internal::ImplicitCast_(this)); - } +#endif // GTEST_LANG_CXX11 private: GTEST_DISALLOW_COPY_AND_ASSIGN_($clazz); }; +namespace internal { + +template +$clazz[[]]Base::$clazz[[]]Base() { + ::testing::Mock::$method( + internal::ImplicitCast_( + static_cast<$clazz *>(this))); +} + +template +$clazz[[]]Base::~$clazz[[]]Base() { + ::testing::Mock::UnregisterCallReaction( + internal::ImplicitCast_( + static_cast<$clazz*>(this))); +} + +} // namespace internal + ]] // The following specializations catch some (relatively more common) -- cgit v0.12 From e0b3c269c23e152ed44e0f4db585319e4e5d5630 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 09:51:02 -0400 Subject: continued --- googlemock/include/gmock/gmock-generated-actions.h | 4 +++- googlemock/include/gmock/gmock-generated-actions.h.pump | 2 +- googlemock/include/gmock/gmock-generated-matchers.h.pump | 4 ++-- googlemock/include/gmock/gmock-generated-nice-strict.h.pump | 4 ++-- googlemock/src/gmock-spec-builders.cc | 1 - 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/googlemock/include/gmock/gmock-generated-actions.h b/googlemock/include/gmock/gmock-generated-actions.h index be4ebe4..b35303e 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h +++ b/googlemock/include/gmock/gmock-generated-actions.h @@ -1,4 +1,6 @@ -// This file was GENERATED by a script. DO NOT EDIT BY HAND!!! +// This file was GENERATED by command: +// pump.py gmock-generated-actions.h.pump +// DO NOT EDIT BY HAND!!! // Copyright 2007, Google Inc. // All rights reserved. diff --git a/googlemock/include/gmock/gmock-generated-actions.h.pump b/googlemock/include/gmock/gmock-generated-actions.h.pump index 712f65d..e0c2135 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h.pump +++ b/googlemock/include/gmock/gmock-generated-actions.h.pump @@ -1,5 +1,5 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to +$$ This is a Pump source file. Please use Pump to convert it to $$ gmock-generated-actions.h. $$ $var n = 10 $$ The maximum arity we support. diff --git a/googlemock/include/gmock/gmock-generated-matchers.h.pump b/googlemock/include/gmock/gmock-generated-matchers.h.pump index 25d2da9..4fe0a61 100644 --- a/googlemock/include/gmock/gmock-generated-matchers.h.pump +++ b/googlemock/include/gmock/gmock-generated-matchers.h.pump @@ -1,6 +1,6 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to -$$ gmock-generated-actions.h. +$$ This is a Pump source file. Please use Pump to convert +$$ it to gmock-generated-matchers.h. $$ $var n = 10 $$ The maximum arity we support. $$ }} This line fixes auto-indentation of the following code in Emacs. diff --git a/googlemock/include/gmock/gmock-generated-nice-strict.h.pump b/googlemock/include/gmock/gmock-generated-nice-strict.h.pump index 4973c35..378c40f 100644 --- a/googlemock/include/gmock/gmock-generated-nice-strict.h.pump +++ b/googlemock/include/gmock/gmock-generated-nice-strict.h.pump @@ -1,6 +1,6 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to -$$ gmock-generated-nice-strict.h. +$$ This is a Pump source file. Please use Pump to convert +$$ it to gmock-generated-nice-strict.h. $$ $var n = 10 $$ The maximum arity we support. // Copyright 2008, Google Inc. diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 39a3fe7..2ae94df 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -56,7 +56,6 @@ # pragma warning(disable:4800) #endif - namespace testing { namespace internal { -- cgit v0.12 From 03be5df17cc7e377a2cad4e110f2f6270d212eb9 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 09:59:09 -0400 Subject: cont. --- googlemock/src/gmock-spec-builders.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 2ae94df..7189212 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -51,7 +51,7 @@ // Silence C4800 (C4800: 'int *const ': forcing value // to bool 'true' or 'false') for MSVC 14 -#ifdef _MSC_VER && _MSC_VER == 1900 +#ifdef (_MSC_VER && _MSC_VER == 1900) # pragma warning(push) # pragma warning(disable:4800) #endif @@ -874,6 +874,6 @@ InSequence::~InSequence() { } // namespace testing -#ifdef _MSC_VER && _MSC_VER == 1900 +#ifdef (_MSC_VER && _MSC_VER == 1900) # pragma warning(pop) #endif -- cgit v0.12 From 61e8a0b10b800ab527ecd19f913b2f6c850db541 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 10:08:12 -0400 Subject: syntax --- googlemock/src/gmock-spec-builders.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 7189212..8f8a2d7 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -51,7 +51,7 @@ // Silence C4800 (C4800: 'int *const ': forcing value // to bool 'true' or 'false') for MSVC 14 -#ifdef (_MSC_VER && _MSC_VER == 1900) +#ifdef _MSC_VER && (_MSC_VER == 1900) # pragma warning(push) # pragma warning(disable:4800) #endif @@ -874,6 +874,6 @@ InSequence::~InSequence() { } // namespace testing -#ifdef (_MSC_VER && _MSC_VER == 1900) +#ifdef _MSC_VER && (_MSC_VER == 1900) # pragma warning(pop) #endif -- cgit v0.12 From 35a709a701cbebfcc685e35d0732dca10bac7763 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 10:25:59 -0400 Subject: preproc syntax ( I can never remember it) --- googlemock/src/gmock-spec-builders.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 8f8a2d7..c8241c3 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -51,9 +51,11 @@ // Silence C4800 (C4800: 'int *const ': forcing value // to bool 'true' or 'false') for MSVC 14 -#ifdef _MSC_VER && (_MSC_VER == 1900) -# pragma warning(push) -# pragma warning(disable:4800) +#ifdef _MSC_VER +#if _MSC_VER == 1900 +# pragma warning(push) +# pragma warning(disable:4800) +#endif #endif namespace testing { @@ -874,6 +876,8 @@ InSequence::~InSequence() { } // namespace testing -#ifdef _MSC_VER && (_MSC_VER == 1900) -# pragma warning(pop) +#ifdef _MSC_VER +#if _MSC_VER == 1900 +# pragma warning(pop) +#endif #endif -- cgit v0.12 From 6525044ce20c22974d9eeaa1726b826c521fa84e Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 10:51:15 -0400 Subject: And also silence for MSVS14 --- googlemock/src/gmock-spec-builders.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index c8241c3..619c0c5 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -50,9 +50,9 @@ #endif // Silence C4800 (C4800: 'int *const ': forcing value -// to bool 'true' or 'false') for MSVC 14 +// to bool 'true' or 'false') for MSVC 14,15 #ifdef _MSC_VER -#if _MSC_VER == 1900 +#if _MSC_VER <= 1900 # pragma warning(push) # pragma warning(disable:4800) #endif -- cgit v0.12 From c4e3d77ddc155a32e9f98f64ea1e111a5cce0e43 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 11:22:11 -0400 Subject: More msvc 14 --- googlemock/test/gmock-actions_test.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index ea6129d..f8b9a1e 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -43,6 +43,16 @@ #include "gtest/gtest.h" #include "gtest/gtest-spi.h" +// Silence C4800 (C4800: 'int *const ': forcing value +// to bool 'true' or 'false') for MSVC 14,15 +#ifdef _MSC_VER +#if _MSC_VER <= 1900 +# pragma warning(push) +# pragma warning(disable:4800) +#endif +#endif + + namespace { // This list should be kept sorted. @@ -1556,3 +1566,9 @@ TEST(MoveOnlyArgumentsTest, ReturningActions) { #endif // GTEST_LANG_CXX11 } // Unnamed namespace + +#ifdef _MSC_VER +#if _MSC_VER == 1900 +# pragma warning(pop) +#endif +#endif -- cgit v0.12 From 8bc7c631e848e7fc9eef2d95eeac12966caefb43 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 11:35:01 -0400 Subject: testing msvc again --- googlemock/test/gmock-actions_test.cc | 16 ---------------- googlemock/test/gmock-more-actions_test.cc | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index f8b9a1e..ea6129d 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -43,16 +43,6 @@ #include "gtest/gtest.h" #include "gtest/gtest-spi.h" -// Silence C4800 (C4800: 'int *const ': forcing value -// to bool 'true' or 'false') for MSVC 14,15 -#ifdef _MSC_VER -#if _MSC_VER <= 1900 -# pragma warning(push) -# pragma warning(disable:4800) -#endif -#endif - - namespace { // This list should be kept sorted. @@ -1566,9 +1556,3 @@ TEST(MoveOnlyArgumentsTest, ReturningActions) { #endif // GTEST_LANG_CXX11 } // Unnamed namespace - -#ifdef _MSC_VER -#if _MSC_VER == 1900 -# pragma warning(pop) -#endif -#endif diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index f5e28ea..e9b272b 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -42,6 +42,15 @@ #include "gtest/gtest.h" #include "gtest/internal/gtest-linked_ptr.h" +// Silence C4800 (C4800: 'int *const ': forcing value +// to bool 'true' or 'false') for MSVC 14,15 +#ifdef _MSC_VER +#if _MSC_VER <= 1900 +# pragma warning(push) +# pragma warning(disable:4800) +#endif +#endif + namespace testing { namespace gmock_more_actions_test { @@ -709,3 +718,8 @@ TEST(ReturnPointeeTest, Works) { } // namespace gmock_generated_actions_test } // namespace testing +#ifdef _MSC_VER +#if _MSC_VER == 1900 +# pragma warning(pop) +#endif +#endif -- cgit v0.12 From 431bfdcaf4a0f08c7ebd571291bf41d06195c20d Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 11:48:02 -0400 Subject: msvc 14 --- googlemock/src/gmock-all.cc | 16 ++++++++++++++++ googlemock/test/gmock-more-actions_test.cc | 14 -------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/googlemock/src/gmock-all.cc b/googlemock/src/gmock-all.cc index 7aebce7..203bdb9 100644 --- a/googlemock/src/gmock-all.cc +++ b/googlemock/src/gmock-all.cc @@ -37,6 +37,16 @@ // This line ensures that gmock.h can be compiled on its own, even // when it's fused. + +// Silence C4800 (C4800: 'int *const ': forcing value +// to bool 'true' or 'false') for MSVC 14,15 +#ifdef _MSC_VER +#if _MSC_VER <= 1900 +# pragma warning(push) +# pragma warning(disable:4800) +#endif +#endif + #include "gmock/gmock.h" // The following lines pull in the real gmock *.cc files. @@ -45,3 +55,9 @@ #include "src/gmock-matchers.cc" #include "src/gmock-spec-builders.cc" #include "src/gmock.cc" + +#ifdef _MSC_VER +#if _MSC_VER == 1900 +# pragma warning(pop) +#endif +#endif diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index e9b272b..f5e28ea 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -42,15 +42,6 @@ #include "gtest/gtest.h" #include "gtest/internal/gtest-linked_ptr.h" -// Silence C4800 (C4800: 'int *const ': forcing value -// to bool 'true' or 'false') for MSVC 14,15 -#ifdef _MSC_VER -#if _MSC_VER <= 1900 -# pragma warning(push) -# pragma warning(disable:4800) -#endif -#endif - namespace testing { namespace gmock_more_actions_test { @@ -718,8 +709,3 @@ TEST(ReturnPointeeTest, Works) { } // namespace gmock_generated_actions_test } // namespace testing -#ifdef _MSC_VER -#if _MSC_VER == 1900 -# pragma warning(pop) -#endif -#endif -- cgit v0.12 From c4684b49cf0d4334dfb522fcb3c8012cb63a4f61 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 12:03:40 -0400 Subject: more msvc --- googlemock/src/gmock-all.cc | 16 ---------------- googlemock/test/gmock_all_test.cc | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/googlemock/src/gmock-all.cc b/googlemock/src/gmock-all.cc index 203bdb9..7aebce7 100644 --- a/googlemock/src/gmock-all.cc +++ b/googlemock/src/gmock-all.cc @@ -37,16 +37,6 @@ // This line ensures that gmock.h can be compiled on its own, even // when it's fused. - -// Silence C4800 (C4800: 'int *const ': forcing value -// to bool 'true' or 'false') for MSVC 14,15 -#ifdef _MSC_VER -#if _MSC_VER <= 1900 -# pragma warning(push) -# pragma warning(disable:4800) -#endif -#endif - #include "gmock/gmock.h" // The following lines pull in the real gmock *.cc files. @@ -55,9 +45,3 @@ #include "src/gmock-matchers.cc" #include "src/gmock-spec-builders.cc" #include "src/gmock.cc" - -#ifdef _MSC_VER -#if _MSC_VER == 1900 -# pragma warning(pop) -#endif -#endif diff --git a/googlemock/test/gmock_all_test.cc b/googlemock/test/gmock_all_test.cc index 56d6c49..bb87729 100644 --- a/googlemock/test/gmock_all_test.cc +++ b/googlemock/test/gmock_all_test.cc @@ -36,6 +36,15 @@ // includes most such tests, making it easier for these users to maintain // their build scripts (they just need to build this file, even though the // below list of actual *_test.cc files might change). +// Silence C4800 (C4800: 'int *const ': forcing value +// to bool 'true' or 'false') for MSVC 14,15 +#ifdef _MSC_VER +#if _MSC_VER <= 1900 +# pragma warning(push) +# pragma warning(disable:4800) +#endif +#endif + #include "test/gmock-actions_test.cc" #include "test/gmock-cardinalities_test.cc" #include "test/gmock-generated-actions_test.cc" @@ -49,3 +58,9 @@ #include "test/gmock-port_test.cc" #include "test/gmock-spec-builders_test.cc" #include "test/gmock_test.cc" + +#ifdef _MSC_VER +#if _MSC_VER == 1900 +# pragma warning(pop) +#endif +#endif -- cgit v0.12 From e93a0ece26844351da7cdc675a55a2520412134d Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 13:51:01 -0400 Subject: msvc --- googlemock/test/gmock-actions_test.cc | 13 +++++++++++++ googlemock/test/gmock_all_test.cc | 12 ------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index ea6129d..cd517a7 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -33,6 +33,13 @@ // // This file tests the built-in actions. +#ifdef _MSC_VER +#if _MSC_VER <= 1900 +# pragma warning(push) +# pragma warning(disable:4800) +#endif +#endif + #include "gmock/gmock-actions.h" #include #include @@ -1556,3 +1563,9 @@ TEST(MoveOnlyArgumentsTest, ReturningActions) { #endif // GTEST_LANG_CXX11 } // Unnamed namespace + +#ifdef _MSC_VER +#if _MSC_VER == 1900 +# pragma warning(pop) +#endif +#endif diff --git a/googlemock/test/gmock_all_test.cc b/googlemock/test/gmock_all_test.cc index bb87729..fa9d84b 100644 --- a/googlemock/test/gmock_all_test.cc +++ b/googlemock/test/gmock_all_test.cc @@ -38,13 +38,6 @@ // below list of actual *_test.cc files might change). // Silence C4800 (C4800: 'int *const ': forcing value // to bool 'true' or 'false') for MSVC 14,15 -#ifdef _MSC_VER -#if _MSC_VER <= 1900 -# pragma warning(push) -# pragma warning(disable:4800) -#endif -#endif - #include "test/gmock-actions_test.cc" #include "test/gmock-cardinalities_test.cc" #include "test/gmock-generated-actions_test.cc" @@ -59,8 +52,3 @@ #include "test/gmock-spec-builders_test.cc" #include "test/gmock_test.cc" -#ifdef _MSC_VER -#if _MSC_VER == 1900 -# pragma warning(pop) -#endif -#endif -- cgit v0.12 From 44da2b9ac5dff919966d7bf488c7058bc8563023 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 15:23:00 -0400 Subject: cont --- googlemock/test/gmock_all_test.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/googlemock/test/gmock_all_test.cc b/googlemock/test/gmock_all_test.cc index fa9d84b..56d6c49 100644 --- a/googlemock/test/gmock_all_test.cc +++ b/googlemock/test/gmock_all_test.cc @@ -36,8 +36,6 @@ // includes most such tests, making it easier for these users to maintain // their build scripts (they just need to build this file, even though the // below list of actual *_test.cc files might change). -// Silence C4800 (C4800: 'int *const ': forcing value -// to bool 'true' or 'false') for MSVC 14,15 #include "test/gmock-actions_test.cc" #include "test/gmock-cardinalities_test.cc" #include "test/gmock-generated-actions_test.cc" @@ -51,4 +49,3 @@ #include "test/gmock-port_test.cc" #include "test/gmock-spec-builders_test.cc" #include "test/gmock_test.cc" - -- cgit v0.12 From 57d6e824b44be45a084fe6baffdfc27b8f8d623f Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 15:33:56 -0400 Subject: more --- googletest/include/gtest/gtest.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index cbab121..16183e1 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -82,14 +82,15 @@ namespace testing { -// Silence C4100 (unreferenced formal parameter) for MSVC +// Silence C4100 (unreferenced formal parameter) for MSVC 14 and 15 #ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable:4100) -# pragma warning(disable:4805) +# if _MSC_VER <= 1900 +# pragma warning(push) +# pragma warning(disable:4100) +# pragma warning(disable:4805) +# endif #endif - // Declares the flags. // This flag temporary enables the disabled tests. @@ -2307,7 +2308,9 @@ bool StaticAssertTypeEq() { GTEST_API_ std::string TempDir(); #ifdef _MSC_VER -# pragma warning(pop) +# if _MSC_VER <= 1900 +# pragma warning(pop) +# endif #endif } // namespace testing -- cgit v0.12 From 055f32199a81a159eebeaabb6666d6de11127064 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 15:38:38 -0400 Subject: tuning --- googlemock/test/gmock_output_test_.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index d5f909d..4166c6c 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -42,8 +42,10 @@ // Silence C4100 (unreferenced formal parameter) for MSVC #ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable:4100) +# if _MSC_VER <= 1900 +# pragma warning(push) +# pragma warning(disable:4100) +# endif #endif @@ -308,5 +310,7 @@ int main(int argc, char **argv) { } #ifdef _MSC_VER -# pragma warning(pop) +# if _MSC_VER <= 1900 +# pragma warning(pop) +# endif #endif -- cgit v0.12 From 2de24fbf7a26e679e8dc7d185addd3dc820f347c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 15:39:12 -0400 Subject: tuning --- googlemock/test/gmock_output_test_.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index 4166c6c..56a00b2 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -40,7 +40,7 @@ #include "gtest/gtest.h" -// Silence C4100 (unreferenced formal parameter) for MSVC +// Silence C4100 (unreferenced formal parameter) for MSVC 14 and 15 #ifdef _MSC_VER # if _MSC_VER <= 1900 # pragma warning(push) -- cgit v0.12 From 05b5a53898c2466e49f37e84324644949d279b34 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 15:50:19 -0400 Subject: formatting --- googlemock/src/gmock-spec-builders.cc | 2 +- googlemock/test/gmock-actions_test.cc | 3 +++ googlemock/test/gmock_output_test_.cc | 2 -- googletest/include/gtest/gtest.h | 4 +++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 619c0c5..22d002f 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -877,7 +877,7 @@ InSequence::~InSequence() { } // namespace testing #ifdef _MSC_VER -#if _MSC_VER == 1900 +#if _MSC_VER <= 1900 # pragma warning(pop) #endif #endif diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index cd517a7..5dd4846 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -33,6 +33,8 @@ // // This file tests the built-in actions. +// Silence C4800 (C4800: 'int *const ': forcing value +// to bool 'true' or 'false') for MSVC 14,15 #ifdef _MSC_VER #if _MSC_VER <= 1900 # pragma warning(push) @@ -1569,3 +1571,4 @@ TEST(MoveOnlyArgumentsTest, ReturningActions) { # pragma warning(pop) #endif #endif + diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index 56a00b2..a01b95e 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -39,7 +39,6 @@ #include "gtest/gtest.h" - // Silence C4100 (unreferenced formal parameter) for MSVC 14 and 15 #ifdef _MSC_VER # if _MSC_VER <= 1900 @@ -48,7 +47,6 @@ # endif #endif - using testing::_; using testing::AnyNumber; using testing::Ge; diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 16183e1..c5d1b7c 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -82,7 +82,8 @@ namespace testing { -// Silence C4100 (unreferenced formal parameter) for MSVC 14 and 15 +// Silence C4100 (unreferenced formal parameter) and 4805 +// unsafe mix of bool and type int for MSVC 14 and 15 #ifdef _MSC_VER # if _MSC_VER <= 1900 # pragma warning(push) @@ -91,6 +92,7 @@ namespace testing { # endif #endif + // Declares the flags. // This flag temporary enables the disabled tests. -- cgit v0.12 From f5871009e6d8db73c0516efeb2955436b7134fb4 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 16:04:48 -0400 Subject: yet more --- .../include/gmock/internal/custom/gmock-generated-actions.h.pump | 2 +- googletest/include/gtest/gtest.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump b/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump index d26c8a0..03cfd8c 100644 --- a/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump +++ b/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump @@ -1,5 +1,5 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file (http://go/pump). Please use Pump to convert +$$ This is a Pump source file. Please use Pump to convert $$ it to callback-actions.h. $$ $var max_callback_arity = 5 diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index c5d1b7c..efa98d5 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -83,12 +83,12 @@ namespace testing { // Silence C4100 (unreferenced formal parameter) and 4805 -// unsafe mix of bool and type int for MSVC 14 and 15 +// unsafe mix of type 'const int' and type 'const bool' #ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:4805) # if _MSC_VER <= 1900 -# pragma warning(push) # pragma warning(disable:4100) -# pragma warning(disable:4805) # endif #endif -- cgit v0.12 From c1d4c34233e05bbcd4ba4abd72198327f550818f Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 16:13:45 -0400 Subject: this should be it --- googletest/include/gtest/gtest.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index efa98d5..1c39310 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -87,9 +87,7 @@ namespace testing { #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable:4805) -# if _MSC_VER <= 1900 # pragma warning(disable:4100) -# endif #endif @@ -2310,9 +2308,7 @@ bool StaticAssertTypeEq() { GTEST_API_ std::string TempDir(); #ifdef _MSC_VER -# if _MSC_VER <= 1900 # pragma warning(pop) -# endif #endif } // namespace testing -- cgit v0.12 From 64d24b810f37681680a84d615f2601ac73dea78a Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 16:24:30 -0400 Subject: ... and this --- googlemock/test/gmock_output_test_.cc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index a01b95e..1b59eb3 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -39,12 +39,10 @@ #include "gtest/gtest.h" -// Silence C4100 (unreferenced formal parameter) for MSVC 14 and 15 +// Silence C4100 (unreferenced formal parameter) #ifdef _MSC_VER -# if _MSC_VER <= 1900 -# pragma warning(push) -# pragma warning(disable:4100) -# endif +# pragma warning(push) +# pragma warning(disable:4100) #endif using testing::_; @@ -308,7 +306,5 @@ int main(int argc, char **argv) { } #ifdef _MSC_VER -# if _MSC_VER <= 1900 -# pragma warning(pop) -# endif +# pragma warning(pop) #endif -- cgit v0.12 From ca54b673034f6f182ff22ac554efcd1176f5808c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 22:10:12 -0400 Subject: Revert "gmock actions 2" --- googlemock/include/gmock/gmock-actions.h | 90 +++--------- googlemock/include/gmock/gmock-generated-actions.h | 4 +- .../include/gmock/gmock-generated-actions.h.pump | 2 +- .../include/gmock/gmock-generated-matchers.h.pump | 4 +- .../gmock/gmock-generated-nice-strict.h.pump | 4 +- googlemock/include/gmock/gmock-more-matchers.h | 8 -- .../internal/custom/gmock-generated-actions.h.pump | 2 +- .../include/gmock/internal/gmock-internal-utils.h | 16 +-- googlemock/src/gmock-internal-utils.cc | 2 +- googlemock/src/gmock-spec-builders.cc | 15 -- googlemock/test/gmock-actions_test.cc | 160 +-------------------- googlemock/test/gmock_output_test_.cc | 10 -- googletest/include/gtest/gtest.h | 13 -- 13 files changed, 27 insertions(+), 303 deletions(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index a2784f6..90fd2ea 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -360,21 +360,15 @@ class Action { // Constructs a null Action. Needed for storing Action objects in // STL containers. - Action() {} + Action() : impl_(NULL) {} -#if GTEST_LANG_CXX11 - // Construct an Action from a specified callable. - // This cannot take std::function directly, because then Action would not be - // directly constructible from lambda (it would require two conversions). - template , G>::value>::type> - Action(G&& fun) : fun_(::std::forward(fun)) {} // NOLINT -#endif - - // Constructs an Action from its implementation. + // Constructs an Action from its implementation. A NULL impl is + // used to represent the "do-default" action. explicit Action(ActionInterface* impl) : impl_(impl) {} + // Copy constructor. + Action(const Action& action) : impl_(action.impl_) {} + // This constructor allows us to turn an Action object into an // Action, as long as F's arguments can be implicitly converted // to Func's and Func's return type can be implicitly converted to @@ -383,13 +377,7 @@ class Action { explicit Action(const Action& action); // Returns true iff this is the DoDefault() action. - bool IsDoDefault() const { -#if GTEST_LANG_CXX11 - return impl_ == nullptr && fun_ == nullptr; -#else - return impl_ == NULL; -#endif - } + bool IsDoDefault() const { return impl_.get() == NULL; } // Performs the action. Note that this method is const even though // the corresponding method in ActionInterface is not. The reason @@ -397,15 +385,14 @@ class Action { // another concrete action, not that the concrete action it binds to // cannot change state. (Think of the difference between a const // pointer and a pointer to const.) - Result Perform(ArgumentTuple args) const { - if (IsDoDefault()) { - internal::IllegalDoDefault(__FILE__, __LINE__); - } -#if GTEST_LANG_CXX11 - if (fun_ != nullptr) { - return internal::Apply(fun_, ::std::move(args)); - } -#endif + Result Perform(const ArgumentTuple& args) const { + internal::Assert( + !IsDoDefault(), __FILE__, __LINE__, + "You are using DoDefault() inside a composite action like " + "DoAll() or WithArgs(). This is not supported for technical " + "reasons. Please instead spell out the default action, or " + "assign the default action to an Action variable and use " + "the variable in various places."); return impl_->Perform(args); } @@ -413,18 +400,6 @@ class Action { template friend class internal::ActionAdaptor; - template - friend class Action; - - // In C++11, Action can be implemented either as a generic functor (through - // std::function), or legacy ActionInterface. In C++98, only ActionInterface - // is available. The invariants are as follows: - // * in C++98, impl_ is null iff this is the default action - // * in C++11, at most one of fun_ & impl_ may be nonnull; both are null iff - // this is the default action -#if GTEST_LANG_CXX11 - ::std::function fun_; -#endif internal::linked_ptr > impl_; }; @@ -556,9 +531,6 @@ struct ByMoveWrapper { // statement, and conversion of the result of Return to Action is a // good place for that. // -// The real life example of the above scenario happens when an invocation -// of gtl::Container() is passed into Return. -// template class ReturnAction { public: @@ -778,7 +750,7 @@ class DoDefaultAction { // This template type conversion operator allows DoDefault() to be // used in any function. template - operator Action() const { return Action(); } // NOLINT + operator Action() const { return Action(NULL); } }; // Implements the Assign action to set a given pointer referent to a @@ -914,28 +886,6 @@ class InvokeMethodWithoutArgsAction { GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction); }; -// Implements the InvokeWithoutArgs(callback) action. -template -class InvokeCallbackWithoutArgsAction { - public: - // The c'tor takes ownership of the callback. - explicit InvokeCallbackWithoutArgsAction(CallbackType* callback) - : callback_(callback) { - callback->CheckIsRepeatable(); // Makes sure the callback is permanent. - } - - // This type conversion operator template allows Invoke(callback) to - // be used wherever the callback's return type can be implicitly - // converted to that of the mock function. - template - Result Perform(const ArgumentTuple&) const { return callback_->Run(); } - - private: - const internal::linked_ptr callback_; - - GTEST_DISALLOW_ASSIGN_(InvokeCallbackWithoutArgsAction); -}; - // Implements the IgnoreResult(action) action. template class IgnoreResultAction { @@ -1103,13 +1053,7 @@ typedef internal::IgnoredValue Unused; template template Action::Action(const Action& from) - : -#if GTEST_LANG_CXX11 - fun_(from.fun_), -#endif - impl_(from.impl_ == NULL ? NULL - : new internal::ActionAdaptor(from)) { -} + : impl_(new internal::ActionAdaptor(from)) {} // Creates an action that returns 'value'. 'value' is passed by value // instead of const reference - otherwise Return("string literal") diff --git a/googlemock/include/gmock/gmock-generated-actions.h b/googlemock/include/gmock/gmock-generated-actions.h index b35303e..be4ebe4 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h +++ b/googlemock/include/gmock/gmock-generated-actions.h @@ -1,6 +1,4 @@ -// This file was GENERATED by command: -// pump.py gmock-generated-actions.h.pump -// DO NOT EDIT BY HAND!!! +// This file was GENERATED by a script. DO NOT EDIT BY HAND!!! // Copyright 2007, Google Inc. // All rights reserved. diff --git a/googlemock/include/gmock/gmock-generated-actions.h.pump b/googlemock/include/gmock/gmock-generated-actions.h.pump index e0c2135..712f65d 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h.pump +++ b/googlemock/include/gmock/gmock-generated-actions.h.pump @@ -1,5 +1,5 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to +$$ This is a Pump source file. Please use Pump to convert it to $$ gmock-generated-actions.h. $$ $var n = 10 $$ The maximum arity we support. diff --git a/googlemock/include/gmock/gmock-generated-matchers.h.pump b/googlemock/include/gmock/gmock-generated-matchers.h.pump index 4fe0a61..25d2da9 100644 --- a/googlemock/include/gmock/gmock-generated-matchers.h.pump +++ b/googlemock/include/gmock/gmock-generated-matchers.h.pump @@ -1,6 +1,6 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert -$$ it to gmock-generated-matchers.h. +$$ This is a Pump source file. Please use Pump to convert it to +$$ gmock-generated-actions.h. $$ $var n = 10 $$ The maximum arity we support. $$ }} This line fixes auto-indentation of the following code in Emacs. diff --git a/googlemock/include/gmock/gmock-generated-nice-strict.h.pump b/googlemock/include/gmock/gmock-generated-nice-strict.h.pump index 378c40f..4973c35 100644 --- a/googlemock/include/gmock/gmock-generated-nice-strict.h.pump +++ b/googlemock/include/gmock/gmock-generated-nice-strict.h.pump @@ -1,6 +1,6 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert -$$ it to gmock-generated-nice-strict.h. +$$ This is a Pump source file. Please use Pump to convert it to +$$ gmock-generated-nice-strict.h. $$ $var n = 10 $$ The maximum arity we support. // Copyright 2008, Google Inc. diff --git a/googlemock/include/gmock/gmock-more-matchers.h b/googlemock/include/gmock/gmock-more-matchers.h index 6d810eb..01298cf 100644 --- a/googlemock/include/gmock/gmock-more-matchers.h +++ b/googlemock/include/gmock/gmock-more-matchers.h @@ -46,11 +46,8 @@ namespace testing { // Silence C4100 (unreferenced formal // parameter) for MSVC #ifdef _MSC_VER -# pragma warning(push) # pragma warning(disable:4100) #if (_MSC_VER == 1900) -// and silence C4800 (C4800: 'int *const ': forcing value -// to bool 'true' or 'false') for MSVC 14 # pragma warning(disable:4800) #endif #endif @@ -81,11 +78,6 @@ MATCHER(IsFalse, negation ? "is true" : "is false") { return !static_cast(arg); } -#ifdef _MSC_VER -# pragma warning(pop) -#endif - - } // namespace testing #endif // GMOCK_GMOCK_MORE_MATCHERS_H_ diff --git a/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump b/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump index 03cfd8c..d26c8a0 100644 --- a/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump +++ b/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump @@ -1,5 +1,5 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert +$$ This is a Pump source file (http://go/pump). Please use Pump to convert $$ it to callback-actions.h. $$ $var max_callback_arity = 5 diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 20c95c6..37ceb54 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -48,14 +48,6 @@ namespace testing { namespace internal { -// Silence MSVC C4100 (unreferenced formal parameter) and -// C4805('==': unsafe mix of type 'const int' and type 'const bool') -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable:4100) -# pragma warning(disable:4805) -#endif - // Joins a vector of strings as if they are fields of a tuple; returns // the joined string. GTEST_API_ std::string JoinAsTuple(const Strings& fields); @@ -518,7 +510,7 @@ struct BooleanConstant {}; // Emit an assertion failure due to incorrect DoDefault() usage. Out-of-lined to // reduce code size. -GTEST_API_ void IllegalDoDefault(const char* file, int line); +void IllegalDoDefault(const char* file, int line); #if GTEST_LANG_CXX11 // Helper types for Apply() below. @@ -547,12 +539,6 @@ auto Apply(F&& f, Tuple&& args) make_int_pack::value>()); } #endif - - -#ifdef _MSC_VER -# pragma warning(pop) -#endif - } // namespace internal } // namespace testing diff --git a/googlemock/src/gmock-internal-utils.cc b/googlemock/src/gmock-internal-utils.cc index 3fca3f2..20c5a8d 100644 --- a/googlemock/src/gmock-internal-utils.cc +++ b/googlemock/src/gmock-internal-utils.cc @@ -188,7 +188,7 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message, std::cout << ::std::flush; } -GTEST_API_ void IllegalDoDefault(const char* file, int line) { +void IllegalDoDefault(const char* file, int line) { internal::Assert( false, file, line, "You are using DoDefault() inside a composite action like " diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 22d002f..b97bad0 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -49,15 +49,6 @@ # include // NOLINT #endif -// Silence C4800 (C4800: 'int *const ': forcing value -// to bool 'true' or 'false') for MSVC 14,15 -#ifdef _MSC_VER -#if _MSC_VER <= 1900 -# pragma warning(push) -# pragma warning(disable:4800) -#endif -#endif - namespace testing { namespace internal { @@ -875,9 +866,3 @@ InSequence::~InSequence() { } } // namespace testing - -#ifdef _MSC_VER -#if _MSC_VER <= 1900 -# pragma warning(pop) -#endif -#endif diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 5dd4846..4601157 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -33,15 +33,6 @@ // // This file tests the built-in actions. -// Silence C4800 (C4800: 'int *const ': forcing value -// to bool 'true' or 'false') for MSVC 14,15 -#ifdef _MSC_VER -#if _MSC_VER <= 1900 -# pragma warning(push) -# pragma warning(disable:4800) -#endif -#endif - #include "gmock/gmock-actions.h" #include #include @@ -74,7 +65,6 @@ using testing::ReturnRef; using testing::ReturnRefOfCopy; using testing::SetArgPointee; using testing::SetArgumentPointee; -using testing::Unused; using testing::_; using testing::get; using testing::internal::BuiltInDefaultValue; @@ -715,8 +705,6 @@ class MockClass { MOCK_METHOD0(MakeUniqueBase, std::unique_ptr()); MOCK_METHOD0(MakeVectorUnique, std::vector>()); MOCK_METHOD1(TakeUnique, int(std::unique_ptr)); - MOCK_METHOD2(TakeUnique, - int(const std::unique_ptr&, std::unique_ptr)); #endif private: @@ -768,7 +756,7 @@ TEST(DoDefaultDeathTest, DiesIfUsedInCompositeAction) { } // Tests that DoDefault() returns the default value set by -// DefaultValue::Set() when it's not overriden by an ON_CALL(). +// DefaultValue::Set() when it's not overridden by an ON_CALL(). TEST(DoDefaultTest, ReturnsUserSpecifiedPerTypeDefaultValueWhenThereIsOne) { DefaultValue::Set(1); MockClass mock; @@ -1423,152 +1411,6 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) { EXPECT_EQ(7, *vresult[0]); } -TEST(MockMethodTest, CanTakeMoveOnlyValue) { - MockClass mock; - auto make = [](int i) { return std::unique_ptr(new int(i)); }; - - EXPECT_CALL(mock, TakeUnique(_)).WillRepeatedly([](std::unique_ptr i) { - return *i; - }); - // DoAll() does not compile, since it would move from its arguments twice. - // EXPECT_CALL(mock, TakeUnique(_, _)) - // .WillRepeatedly(DoAll(Invoke([](std::unique_ptr j) {}), - // Return(1))); - EXPECT_CALL(mock, TakeUnique(testing::Pointee(7))) - .WillOnce(Return(-7)) - .RetiresOnSaturation(); - EXPECT_CALL(mock, TakeUnique(testing::IsNull())) - .WillOnce(Return(-1)) - .RetiresOnSaturation(); - - EXPECT_EQ(5, mock.TakeUnique(make(5))); - EXPECT_EQ(-7, mock.TakeUnique(make(7))); - EXPECT_EQ(7, mock.TakeUnique(make(7))); - EXPECT_EQ(7, mock.TakeUnique(make(7))); - EXPECT_EQ(-1, mock.TakeUnique({})); - - // Some arguments are moved, some passed by reference. - auto lvalue = make(6); - EXPECT_CALL(mock, TakeUnique(_, _)) - .WillOnce([](const std::unique_ptr& i, std::unique_ptr j) { - return *i * *j; - }); - EXPECT_EQ(42, mock.TakeUnique(lvalue, make(7))); - - // The unique_ptr can be saved by the action. - std::unique_ptr saved; - EXPECT_CALL(mock, TakeUnique(_)).WillOnce([&saved](std::unique_ptr i) { - saved = std::move(i); - return 0; - }); - EXPECT_EQ(0, mock.TakeUnique(make(42))); - EXPECT_EQ(42, *saved); -} - #endif // GTEST_HAS_STD_UNIQUE_PTR_ -#if GTEST_LANG_CXX11 -// Tests for std::function based action. - -int Add(int val, int& ref, int* ptr) { // NOLINT - int result = val + ref + *ptr; - ref = 42; - *ptr = 43; - return result; -} - -int Deref(std::unique_ptr ptr) { return *ptr; } - -struct Double { - template - T operator()(T t) { return 2 * t; } -}; - -std::unique_ptr UniqueInt(int i) { - return std::unique_ptr(new int(i)); -} - -TEST(FunctorActionTest, ActionFromFunction) { - Action a = &Add; - int x = 1, y = 2, z = 3; - EXPECT_EQ(6, a.Perform(std::forward_as_tuple(x, y, &z))); - EXPECT_EQ(42, y); - EXPECT_EQ(43, z); - - Action)> a1 = &Deref; - EXPECT_EQ(7, a1.Perform(std::make_tuple(UniqueInt(7)))); -} - -TEST(FunctorActionTest, ActionFromLambda) { - Action a1 = [](bool b, int i) { return b ? i : 0; }; - EXPECT_EQ(5, a1.Perform(make_tuple(true, 5))); - EXPECT_EQ(0, a1.Perform(make_tuple(false, 5))); - - std::unique_ptr saved; - Action)> a2 = [&saved](std::unique_ptr p) { - saved = std::move(p); - }; - a2.Perform(make_tuple(UniqueInt(5))); - EXPECT_EQ(5, *saved); -} - -TEST(FunctorActionTest, PolymorphicFunctor) { - Action ai = Double(); - EXPECT_EQ(2, ai.Perform(make_tuple(1))); - Action ad = Double(); // Double? Double double! - EXPECT_EQ(3.0, ad.Perform(make_tuple(1.5))); -} - -TEST(FunctorActionTest, TypeConversion) { - // Numeric promotions are allowed. - const Action a1 = [](int i) { return i > 1; }; - const Action a2 = Action(a1); - EXPECT_EQ(1, a1.Perform(make_tuple(42))); - EXPECT_EQ(0, a2.Perform(make_tuple(42))); - - // Implicit constructors are allowed. - const Action s1 = [](std::string s) { return !s.empty(); }; - const Action s2 = Action(s1); - EXPECT_EQ(0, s2.Perform(make_tuple(""))); - EXPECT_EQ(1, s2.Perform(make_tuple("hello"))); - - // Also between the lambda and the action itself. - const Action x = [](Unused) { return 42; }; - EXPECT_TRUE(x.Perform(make_tuple("hello"))); -} - -TEST(FunctorActionTest, UnusedArguments) { - // Verify that users can ignore uninteresting arguments. - Action, const int&)> a = - [](int i, Unused, Unused) { return 2 * i; }; - EXPECT_EQ(6, a.Perform(make_tuple(3, UniqueInt(7), 9))); -} - -// Test that basic built-in actions work with move-only arguments. -// TODO(rburny): Currently, almost all ActionInterface-based actions will not -// work, even if they only try to use other, copyable arguments. Implement them -// if necessary (but note that DoAll cannot work on non-copyable types anyway - -// so maybe it's better to make users use lambdas instead. -TEST(MoveOnlyArgumentsTest, ReturningActions) { - Action)> a = Return(1); - EXPECT_EQ(1, a.Perform(make_tuple(nullptr))); - - a = testing::WithoutArgs([]() { return 7; }); - EXPECT_EQ(7, a.Perform(make_tuple(nullptr))); - - Action, int*)> a2 = testing::SetArgPointee<1>(3); - int x = 0; - a2.Perform(make_tuple(nullptr, &x)); - EXPECT_EQ(x, 3); -} - -#endif // GTEST_LANG_CXX11 - } // Unnamed namespace - -#ifdef _MSC_VER -#if _MSC_VER == 1900 -# pragma warning(pop) -#endif -#endif - diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index 1b59eb3..ca628df 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -39,12 +39,6 @@ #include "gtest/gtest.h" -// Silence C4100 (unreferenced formal parameter) -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable:4100) -#endif - using testing::_; using testing::AnyNumber; using testing::Ge; @@ -304,7 +298,3 @@ int main(int argc, char **argv) { TestCatchesLeakedMocksInAdHocTests(); return RUN_ALL_TESTS(); } - -#ifdef _MSC_VER -# pragma warning(pop) -#endif diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 1c39310..26e787d 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -82,15 +82,6 @@ namespace testing { -// Silence C4100 (unreferenced formal parameter) and 4805 -// unsafe mix of type 'const int' and type 'const bool' -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable:4805) -# pragma warning(disable:4100) -#endif - - // Declares the flags. // This flag temporary enables the disabled tests. @@ -2307,10 +2298,6 @@ bool StaticAssertTypeEq() { // Tries to determine an appropriate directory for the platform. GTEST_API_ std::string TempDir(); -#ifdef _MSC_VER -# pragma warning(pop) -#endif - } // namespace testing // Use this function in main() to run all tests. It returns 0 if all -- cgit v0.12 From 8fbb4194709cc9fd3de3deb2b406461a173bab15 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 10 Apr 2018 11:28:16 -0400 Subject: Include gcc on mac into PR matrix There was an error that slipped through and only showed up on PR merge (https://travis-ci.org/google/googletest/jobs/364304396/config ) , we dont want that again --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8913e89..aa91439 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,6 @@ matrix: - os: osx compiler: gcc env: BUILD_TYPE=Release VERBOSE=1 CXX_FLAGS=-std=c++11 - if: type != pull_request - os: osx compiler: clang env: BUILD_TYPE=Debug VERBOSE=1 -- cgit v0.12 From e1071eb9497304a38e69737e90a88b4877b8b736 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 10 Apr 2018 15:57:16 -0400 Subject: RE-Doing the merge, this time with gcc on mac in the PR so I can catch errors before merging the PR --- googlemock/include/gmock/gmock-generated-actions.h | 328 ++++++++++++++++----- .../include/gmock/gmock-generated-actions.h.pump | 49 ++- .../include/gmock/gmock-generated-matchers.h.pump | 4 +- .../gmock/gmock-generated-nice-strict.h.pump | 4 +- .../internal/custom/gmock-generated-actions.h.pump | 2 +- googlemock/src/gmock-spec-builders.cc | 17 +- googlemock/test/gmock-actions_test.cc | 16 + googlemock/test/gmock-generated-actions_test.cc | 11 +- googlemock/test/gmock_output_test_.cc | 4 +- googletest/include/gtest/gtest.h | 7 +- 10 files changed, 346 insertions(+), 96 deletions(-) diff --git a/googlemock/include/gmock/gmock-generated-actions.h b/googlemock/include/gmock/gmock-generated-actions.h index be4ebe4..7728d74 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h +++ b/googlemock/include/gmock/gmock-generated-actions.h @@ -1,4 +1,6 @@ -// This file was GENERATED by a script. DO NOT EDIT BY HAND!!! +// This file was GENERATED by command: +// pump.py gmock-generated-actions.h.pump +// DO NOT EDIT BY HAND!!! // Copyright 2007, Google Inc. // All rights reserved. @@ -45,8 +47,8 @@ namespace testing { namespace internal { // InvokeHelper knows how to unpack an N-tuple and invoke an N-ary -// function or method with the unpacked values, where F is a function -// type that takes N arguments. +// function, method, or callback with the unpacked values, where F is +// a function type that takes N arguments. template class InvokeHelper; @@ -64,6 +66,12 @@ class InvokeHelper > { const ::testing::tuple<>&) { return (obj_ptr->*method_ptr)(); } + + template + static R InvokeCallback(CallbackType* callback, + const ::testing::tuple<>&) { + return callback->Run(); + } }; template @@ -80,6 +88,12 @@ class InvokeHelper > { const ::testing::tuple& args) { return (obj_ptr->*method_ptr)(get<0>(args)); } + + template + static R InvokeCallback(CallbackType* callback, + const ::testing::tuple& args) { + return callback->Run(get<0>(args)); + } }; template @@ -96,6 +110,12 @@ class InvokeHelper > { const ::testing::tuple& args) { return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args)); } + + template + static R InvokeCallback(CallbackType* callback, + const ::testing::tuple& args) { + return callback->Run(get<0>(args), get<1>(args)); + } }; template @@ -113,6 +133,12 @@ class InvokeHelper > { return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args)); } + + template + static R InvokeCallback(CallbackType* callback, + const ::testing::tuple& args) { + return callback->Run(get<0>(args), get<1>(args), get<2>(args)); + } }; template @@ -132,6 +158,13 @@ class InvokeHelper > { return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), get<3>(args)); } + + template + static R InvokeCallback(CallbackType* callback, + const ::testing::tuple& args) { + return callback->Run(get<0>(args), get<1>(args), get<2>(args), + get<3>(args)); + } }; template > { return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args)); } + + template + static R InvokeCallback(CallbackType* callback, + const ::testing::tuple& args) { + return callback->Run(get<0>(args), get<1>(args), get<2>(args), + get<3>(args), get<4>(args)); + } }; template > { return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args), get<5>(args)); } + + // There is no InvokeCallback() for 6-tuples, as google3 callbacks + // support 5 arguments at most. }; template > { get<2>(args), get<3>(args), get<4>(args), get<5>(args), get<6>(args)); } + + // There is no InvokeCallback() for 7-tuples, as google3 callbacks + // support 5 arguments at most. }; template > { get<2>(args), get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args)); } + + // There is no InvokeCallback() for 8-tuples, as google3 callbacks + // support 5 arguments at most. }; template > { get<2>(args), get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args)); } + + // There is no InvokeCallback() for 9-tuples, as google3 callbacks + // support 5 arguments at most. }; template (args), get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args), get<9>(args)); } + + // There is no InvokeCallback() for 10-tuples, as google3 callbacks + // support 5 arguments at most. +}; + +// Implements the Invoke(callback) action. +template +class InvokeCallbackAction { + public: + // The c'tor takes ownership of the callback. + explicit InvokeCallbackAction(CallbackType* callback) + : callback_(callback) { + callback->CheckIsRepeatable(); // Makes sure the callback is permanent. + } + + // This type conversion operator template allows Invoke(callback) to + // be used wherever the callback's type is compatible with that of + // the mock function, i.e. if the mock function's arguments can be + // implicitly converted to the callback's arguments and the + // callback's result can be implicitly converted to the mock + // function's result. + template + Result Perform(const ArgumentTuple& args) const { + return InvokeHelper::InvokeCallback( + callback_.get(), args); + } + private: + const linked_ptr callback_; }; // An INTERNAL macro for extracting the type of a tuple field. It's @@ -1073,52 +1153,90 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, #define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\ () #define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\ - (p0##_type gmock_p0) : p0(gmock_p0) + (p0##_type gmock_p0) : p0(::testing::internal::move(gmock_p0)) #define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\ - (p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), p1(gmock_p1) + (p0##_type gmock_p0, \ + p1##_type gmock_p1) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)) #define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\ (p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) + p2##_type gmock_p2) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)) #define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\ (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3) + p3##_type gmock_p3) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)) #define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\ (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) + p3##_type gmock_p3, \ + p4##_type gmock_p4) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)) #define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\ (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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) + p5##_type gmock_p5) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)) #define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\ (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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) + p6##_type gmock_p6) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)) #define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\ (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(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ - p7(gmock_p7) + p6##_type gmock_p6, \ + p7##_type gmock_p7) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)) #define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ p7, p8)\ (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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ - p8(gmock_p8) + p8##_type gmock_p8) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)), \ + p8(::testing::internal::move(gmock_p8)) #define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ p7, p8, p9)\ (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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ - p8(gmock_p8), p9(gmock_p9) + p9##_type gmock_p9) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)), \ + p8(::testing::internal::move(gmock_p8)), \ + p9(::testing::internal::move(gmock_p9)) // Declares the fields for storing the value parameters. #define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS() @@ -1354,7 +1472,8 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, template \ class name##ActionP {\ public:\ - explicit name##ActionP(p0##_type gmock_p0) : p0(gmock_p0) {}\ + explicit name##ActionP(p0##_type gmock_p0) : \ + p0(::testing::internal::forward(gmock_p0)) {}\ template \ class gmock_Impl : public ::testing::ActionInterface {\ public:\ @@ -1362,7 +1481,8 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, typedef typename ::testing::internal::Function::Result return_type;\ typedef typename ::testing::internal::Function::ArgumentTuple\ args_type;\ - explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\ + explicit gmock_Impl(p0##_type gmock_p0) : \ + p0(::testing::internal::forward(gmock_p0)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper::\ Perform(this, args);\ @@ -1404,8 +1524,9 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, template \ class name##ActionP2 {\ public:\ - name##ActionP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ - p1(gmock_p1) {}\ + name##ActionP2(p0##_type gmock_p0, \ + p1##_type gmock_p1) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)) {}\ template \ class gmock_Impl : public ::testing::ActionInterface {\ public:\ @@ -1413,8 +1534,9 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 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(gmock_p0), \ - p1(gmock_p1) {}\ + gmock_Impl(p0##_type gmock_p0, \ + p1##_type gmock_p1) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper::\ Perform(this, args);\ @@ -1460,7 +1582,9 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, class name##ActionP3 {\ public:\ name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ + p2##_type gmock_p2) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)), \ + p2(::testing::internal::forward(gmock_p2)) {}\ template \ class gmock_Impl : public ::testing::ActionInterface {\ public:\ @@ -1469,7 +1593,9 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, typedef typename ::testing::internal::Function::ArgumentTuple\ args_type;\ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ + p2##_type gmock_p2) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)), \ + p2(::testing::internal::forward(gmock_p2)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper::\ Perform(this, args);\ @@ -1519,8 +1645,11 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, class name##ActionP4 {\ public:\ name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3) {}\ + p2##_type gmock_p2, \ + p3##_type gmock_p3) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)), \ + p2(::testing::internal::forward(gmock_p2)), \ + p3(::testing::internal::forward(gmock_p3)) {}\ template \ class gmock_Impl : public ::testing::ActionInterface {\ public:\ @@ -1529,8 +1658,10 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3) {}\ + p3##_type gmock_p3) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)), \ + p2(::testing::internal::forward(gmock_p2)), \ + p3(::testing::internal::forward(gmock_p3)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper::\ Perform(this, args);\ @@ -1587,8 +1718,11 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, public:\ name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \ p2##_type gmock_p2, p3##_type gmock_p3, \ - p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4) {}\ + p4##_type gmock_p4) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)), \ + p2(::testing::internal::forward(gmock_p2)), \ + p3(::testing::internal::forward(gmock_p3)), \ + p4(::testing::internal::forward(gmock_p4)) {}\ template \ class gmock_Impl : public ::testing::ActionInterface {\ public:\ @@ -1597,8 +1731,12 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 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(gmock_p0), \ - p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\ + p3##_type gmock_p3, \ + p4##_type gmock_p4) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)), \ + p2(::testing::internal::forward(gmock_p2)), \ + p3(::testing::internal::forward(gmock_p3)), \ + p4(::testing::internal::forward(gmock_p4)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper::\ Perform(this, args);\ @@ -1657,8 +1795,12 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, public:\ name##ActionP6(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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\ + p5##_type gmock_p5) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)), \ + p2(::testing::internal::forward(gmock_p2)), \ + p3(::testing::internal::forward(gmock_p3)), \ + p4(::testing::internal::forward(gmock_p4)), \ + p5(::testing::internal::forward(gmock_p5)) {}\ template \ class gmock_Impl : public ::testing::ActionInterface {\ public:\ @@ -1668,8 +1810,12 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\ + p5##_type gmock_p5) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)), \ + p2(::testing::internal::forward(gmock_p2)), \ + p3(::testing::internal::forward(gmock_p3)), \ + p4(::testing::internal::forward(gmock_p4)), \ + p5(::testing::internal::forward(gmock_p5)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper::\ Perform(this, args);\ @@ -1731,9 +1877,14 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, public:\ name##ActionP7(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(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \ - p6(gmock_p6) {}\ + p5##_type gmock_p5, \ + p6##_type gmock_p6) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)), \ + p2(::testing::internal::forward(gmock_p2)), \ + p3(::testing::internal::forward(gmock_p3)), \ + p4(::testing::internal::forward(gmock_p4)), \ + p5(::testing::internal::forward(gmock_p5)), \ + p6(::testing::internal::forward(gmock_p6)) {}\ template \ class gmock_Impl : public ::testing::ActionInterface {\ public:\ @@ -1743,8 +1894,13 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\ + p6##_type gmock_p6) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)), \ + p2(::testing::internal::forward(gmock_p2)), \ + p3(::testing::internal::forward(gmock_p3)), \ + p4(::testing::internal::forward(gmock_p4)), \ + p5(::testing::internal::forward(gmock_p5)), \ + p6(::testing::internal::forward(gmock_p6)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper::\ Perform(this, args);\ @@ -1813,9 +1969,14 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, name##ActionP8(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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ - p7(gmock_p7) {}\ + p7##_type gmock_p7) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)), \ + p2(::testing::internal::forward(gmock_p2)), \ + p3(::testing::internal::forward(gmock_p3)), \ + p4(::testing::internal::forward(gmock_p4)), \ + p5(::testing::internal::forward(gmock_p5)), \ + p6(::testing::internal::forward(gmock_p6)), \ + p7(::testing::internal::forward(gmock_p7)) {}\ template \ class gmock_Impl : public ::testing::ActionInterface {\ public:\ @@ -1825,9 +1986,15 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 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(gmock_p0), \ - p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), \ - p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\ + p6##_type gmock_p6, \ + p7##_type gmock_p7) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)), \ + p2(::testing::internal::forward(gmock_p2)), \ + p3(::testing::internal::forward(gmock_p3)), \ + p4(::testing::internal::forward(gmock_p4)), \ + p5(::testing::internal::forward(gmock_p5)), \ + p6(::testing::internal::forward(gmock_p6)), \ + p7(::testing::internal::forward(gmock_p7)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper::\ Perform(this, args);\ @@ -1900,9 +2067,15 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, name##ActionP9(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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ - p8(gmock_p8) {}\ + p8##_type gmock_p8) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)), \ + p2(::testing::internal::forward(gmock_p2)), \ + p3(::testing::internal::forward(gmock_p3)), \ + p4(::testing::internal::forward(gmock_p4)), \ + p5(::testing::internal::forward(gmock_p5)), \ + p6(::testing::internal::forward(gmock_p6)), \ + p7(::testing::internal::forward(gmock_p7)), \ + p8(::testing::internal::forward(gmock_p8)) {}\ template \ class gmock_Impl : public ::testing::ActionInterface {\ public:\ @@ -1913,9 +2086,15 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ - p7(gmock_p7), p8(gmock_p8) {}\ + p8##_type gmock_p8) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)), \ + p2(::testing::internal::forward(gmock_p2)), \ + p3(::testing::internal::forward(gmock_p3)), \ + p4(::testing::internal::forward(gmock_p4)), \ + p5(::testing::internal::forward(gmock_p5)), \ + p6(::testing::internal::forward(gmock_p6)), \ + p7(::testing::internal::forward(gmock_p7)), \ + p8(::testing::internal::forward(gmock_p8)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper::\ Perform(this, args);\ @@ -1992,9 +2171,17 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, name##ActionP10(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(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ - p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\ + p8##_type gmock_p8, \ + p9##_type gmock_p9) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)), \ + p2(::testing::internal::forward(gmock_p2)), \ + p3(::testing::internal::forward(gmock_p3)), \ + p4(::testing::internal::forward(gmock_p4)), \ + p5(::testing::internal::forward(gmock_p5)), \ + p6(::testing::internal::forward(gmock_p6)), \ + p7(::testing::internal::forward(gmock_p7)), \ + p8(::testing::internal::forward(gmock_p8)), \ + p9(::testing::internal::forward(gmock_p9)) {}\ template \ class gmock_Impl : public ::testing::ActionInterface {\ public:\ @@ -2005,9 +2192,16 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, 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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ - p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\ + p9##_type gmock_p9) : p0(::testing::internal::forward(gmock_p0)), \ + p1(::testing::internal::forward(gmock_p1)), \ + p2(::testing::internal::forward(gmock_p2)), \ + p3(::testing::internal::forward(gmock_p3)), \ + p4(::testing::internal::forward(gmock_p4)), \ + p5(::testing::internal::forward(gmock_p5)), \ + p6(::testing::internal::forward(gmock_p6)), \ + p7(::testing::internal::forward(gmock_p7)), \ + p8(::testing::internal::forward(gmock_p8)), \ + p9(::testing::internal::forward(gmock_p9)) {}\ virtual return_type Perform(const args_type& args) {\ return ::testing::internal::ActionHelper::\ Perform(this, args);\ @@ -2369,7 +2563,7 @@ ACTION_TEMPLATE(ReturnNew, } // namespace testing -// Include any custom actions added by the local installation. +// Include any custom callback actions added by the local installation. // We must include this header at the end to make sure it can use the // declarations from this file. #include "gmock/internal/custom/gmock-generated-actions.h" diff --git a/googlemock/include/gmock/gmock-generated-actions.h.pump b/googlemock/include/gmock/gmock-generated-actions.h.pump index 712f65d..8bafa47 100644 --- a/googlemock/include/gmock/gmock-generated-actions.h.pump +++ b/googlemock/include/gmock/gmock-generated-actions.h.pump @@ -1,5 +1,5 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to +$$ This is a Pump source file. Please use Pump to convert it to $$ gmock-generated-actions.h. $$ $var n = 10 $$ The maximum arity we support. @@ -49,12 +49,13 @@ namespace testing { namespace internal { // InvokeHelper knows how to unpack an N-tuple and invoke an N-ary -// function or method with the unpacked values, where F is a function -// type that takes N arguments. +// function, method, or callback with the unpacked values, where F is +// a function type that takes N arguments. template class InvokeHelper; +$var max_callback_arity = 5 $range i 0..n $for i [[ $range j 1..i @@ -76,10 +77,48 @@ class InvokeHelper > { const ::testing::tuple<$as>&$args) { return (obj_ptr->*method_ptr)($gets); } + + +$if i <= max_callback_arity [[ + template + static R InvokeCallback(CallbackType* callback, + const ::testing::tuple<$as>&$args) { + return callback->Run($gets); + } +]] $else [[ + // There is no InvokeCallback() for $i-tuples, as google3 callbacks + // support $max_callback_arity arguments at most. +]] + }; ]] +// Implements the Invoke(callback) action. +template +class InvokeCallbackAction { + public: + // The c'tor takes ownership of the callback. + explicit InvokeCallbackAction(CallbackType* callback) + : callback_(callback) { + callback->CheckIsRepeatable(); // Makes sure the callback is permanent. + } + + // This type conversion operator template allows Invoke(callback) to + // be used wherever the callback's type is compatible with that of + // the mock function, i.e. if the mock function's arguments can be + // implicitly converted to the callback's arguments and the + // callback's result can be implicitly converted to the mock + // function's result. + template + Result Perform(const ArgumentTuple& args) const { + return InvokeHelper::InvokeCallback( + callback_.get(), args); + } + private: + const linked_ptr callback_; +}; + // An INTERNAL macro for extracting the type of a tuple field. It's // subject to change without notice - DO NOT USE IN USER CODE! #define GMOCK_FIELD_(Tuple, N) \ @@ -486,7 +525,7 @@ _VALUE_PARAMS($for j, [[p$j]]) $for j [[, typename p$j##_type]] $for i [[ $range j 0..i-1 #define GMOCK_INTERNAL_INIT_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])\ - ($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(gmock_p$j)]] + ($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(::testing::internal::move(gmock_p$j))]] ]] @@ -619,7 +658,7 @@ $var class_name = [[name##Action[[$if i==0 [[]] $elif i==1 [[P]] $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(gmock_p$j)]]]]]] +$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::forward(gmock_p$j))]]]]]] $var param_field_decls = [[$for j [[ diff --git a/googlemock/include/gmock/gmock-generated-matchers.h.pump b/googlemock/include/gmock/gmock-generated-matchers.h.pump index 25d2da9..4fe0a61 100644 --- a/googlemock/include/gmock/gmock-generated-matchers.h.pump +++ b/googlemock/include/gmock/gmock-generated-matchers.h.pump @@ -1,6 +1,6 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to -$$ gmock-generated-actions.h. +$$ This is a Pump source file. Please use Pump to convert +$$ it to gmock-generated-matchers.h. $$ $var n = 10 $$ The maximum arity we support. $$ }} This line fixes auto-indentation of the following code in Emacs. diff --git a/googlemock/include/gmock/gmock-generated-nice-strict.h.pump b/googlemock/include/gmock/gmock-generated-nice-strict.h.pump index 4973c35..378c40f 100644 --- a/googlemock/include/gmock/gmock-generated-nice-strict.h.pump +++ b/googlemock/include/gmock/gmock-generated-nice-strict.h.pump @@ -1,6 +1,6 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to -$$ gmock-generated-nice-strict.h. +$$ This is a Pump source file. Please use Pump to convert +$$ it to gmock-generated-nice-strict.h. $$ $var n = 10 $$ The maximum arity we support. // Copyright 2008, Google Inc. diff --git a/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump b/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump index d26c8a0..03cfd8c 100644 --- a/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump +++ b/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump @@ -1,5 +1,5 @@ $$ -*- mode: c++; -*- -$$ This is a Pump source file (http://go/pump). Please use Pump to convert +$$ This is a Pump source file. Please use Pump to convert $$ it to callback-actions.h. $$ $var max_callback_arity = 5 diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 39a3fe7..22d002f 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -50,12 +50,13 @@ #endif // Silence C4800 (C4800: 'int *const ': forcing value -// to bool 'true' or 'false') for MSVC 14 -#ifdef _MSC_VER && _MSC_VER == 1900 -# pragma warning(push) -# pragma warning(disable:4800) +// to bool 'true' or 'false') for MSVC 14,15 +#ifdef _MSC_VER +#if _MSC_VER <= 1900 +# pragma warning(push) +# pragma warning(disable:4800) +#endif #endif - namespace testing { namespace internal { @@ -875,6 +876,8 @@ InSequence::~InSequence() { } // namespace testing -#ifdef _MSC_VER && _MSC_VER == 1900 -# pragma warning(pop) +#ifdef _MSC_VER +#if _MSC_VER <= 1900 +# pragma warning(pop) +#endif #endif diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index ea6129d..5dd4846 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -33,6 +33,15 @@ // // This file tests the built-in actions. +// Silence C4800 (C4800: 'int *const ': forcing value +// to bool 'true' or 'false') for MSVC 14,15 +#ifdef _MSC_VER +#if _MSC_VER <= 1900 +# pragma warning(push) +# pragma warning(disable:4800) +#endif +#endif + #include "gmock/gmock-actions.h" #include #include @@ -1556,3 +1565,10 @@ TEST(MoveOnlyArgumentsTest, ReturningActions) { #endif // GTEST_LANG_CXX11 } // Unnamed namespace + +#ifdef _MSC_VER +#if _MSC_VER == 1900 +# pragma warning(pop) +#endif +#endif + diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index 80bcb31..b821e5a 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -374,10 +374,9 @@ class SubstractAction : public ActionInterface { // NOLINT }; TEST(WithArgsTest, NonInvokeAction) { - Action a = // NOLINT + Action a = // NOLINT WithArgs<2, 1>(MakeAction(new SubstractAction)); - string s("hello"); - EXPECT_EQ(8, a.Perform(tuple(s, 2, 10))); + EXPECT_EQ(8, a.Perform(make_tuple(std::string("hi"), 2, 10))); } // Tests using WithArgs to pass all original arguments in the original order. @@ -754,7 +753,7 @@ TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) { TEST(ActionPMacroTest, WorksInCompatibleMockFunction) { Action a1 = Plus("tail"); const std::string re = "re"; - EXPECT_EQ("retail", a1.Perform(tuple(re))); + EXPECT_EQ("retail", a1.Perform(make_tuple(re))); } // Tests that we can use ACTION*() to define actions overloaded on the @@ -796,7 +795,7 @@ TEST(ActionPnMacroTest, WorksFor3Parameters) { Action a2 = Plus("tail", "-", ">"); const std::string re = "re"; - EXPECT_EQ("retail->", a2.Perform(tuple(re))); + EXPECT_EQ("retail->", a2.Perform(make_tuple(re))); } ACTION_P4(Plus, p0, p1, p2, p3) { return arg0 + p0 + p1 + p2 + p3; } @@ -1120,7 +1119,7 @@ TEST(ActionTemplateTest, WorksForIntegralTemplateParams) { EXPECT_FALSE(b); // Verifies that resetter is deleted. } -// Tests that ACTION_TEMPLATE works for a template with template parameters. +// Tests that ACTION_TEMPLATES works for template template parameters. ACTION_TEMPLATE(ReturnSmartPointer, HAS_1_TEMPLATE_PARAMS(template class, Pointer), diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index d5f909d..1b59eb3 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -39,14 +39,12 @@ #include "gtest/gtest.h" - -// Silence C4100 (unreferenced formal parameter) for MSVC +// Silence C4100 (unreferenced formal parameter) #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable:4100) #endif - using testing::_; using testing::AnyNumber; using testing::Ge; diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index cbab121..1c39310 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -82,11 +82,12 @@ namespace testing { -// Silence C4100 (unreferenced formal parameter) for MSVC +// Silence C4100 (unreferenced formal parameter) and 4805 +// unsafe mix of type 'const int' and type 'const bool' #ifdef _MSC_VER # pragma warning(push) -# pragma warning(disable:4100) # pragma warning(disable:4805) +# pragma warning(disable:4100) #endif @@ -2307,7 +2308,7 @@ bool StaticAssertTypeEq() { GTEST_API_ std::string TempDir(); #ifdef _MSC_VER -# pragma warning(pop) +# pragma warning(pop) #endif } // namespace testing -- cgit v0.12 From 25d8176e4fc8988367fbe3ce1a8ca0b92b79bbfa Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 10 Apr 2018 16:18:23 -0400 Subject: merging --- googlemock/src/gmock-spec-builders.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 39a3fe7..22d002f 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -50,12 +50,13 @@ #endif // Silence C4800 (C4800: 'int *const ': forcing value -// to bool 'true' or 'false') for MSVC 14 -#ifdef _MSC_VER && _MSC_VER == 1900 -# pragma warning(push) -# pragma warning(disable:4800) +// to bool 'true' or 'false') for MSVC 14,15 +#ifdef _MSC_VER +#if _MSC_VER <= 1900 +# pragma warning(push) +# pragma warning(disable:4800) +#endif #endif - namespace testing { namespace internal { @@ -875,6 +876,8 @@ InSequence::~InSequence() { } // namespace testing -#ifdef _MSC_VER && _MSC_VER == 1900 -# pragma warning(pop) +#ifdef _MSC_VER +#if _MSC_VER <= 1900 +# pragma warning(pop) +#endif #endif -- cgit v0.12 From 9bc82ce7251b01ac3abfb28efc9793b56fa835d6 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 10 Apr 2018 16:22:50 -0400 Subject: merging --- googlemock/test/gmock_output_test_.cc | 8 +++++--- googletest/include/gtest/gtest.h | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index 59ea51b..1b59eb3 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -39,14 +39,12 @@ #include "gtest/gtest.h" - -// Silence C4100 (unreferenced formal parameter) for MSVC +// Silence C4100 (unreferenced formal parameter) #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable:4100) #endif - using testing::_; using testing::AnyNumber; using testing::Ge; @@ -306,3 +304,7 @@ int main(int argc, char **argv) { TestCatchesLeakedMocksInAdHocTests(); return RUN_ALL_TESTS(); } + +#ifdef _MSC_VER +# pragma warning(pop) +#endif diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index cbab121..a0592a8 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -82,11 +82,12 @@ namespace testing { -// Silence C4100 (unreferenced formal parameter) for MSVC +// Silence C4100 (unreferenced formal parameter) and 4805 +// unsafe mix of type 'const int' and type 'const bool' #ifdef _MSC_VER # pragma warning(push) -# pragma warning(disable:4100) # pragma warning(disable:4805) +# pragma warning(disable:4100) #endif @@ -2307,7 +2308,7 @@ bool StaticAssertTypeEq() { GTEST_API_ std::string TempDir(); #ifdef _MSC_VER -# pragma warning(pop) +# pragma warning(pop) #endif } // namespace testing -- cgit v0.12 From 6f9db26159f8a568b9af4410a7936f7018d30886 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 10 Apr 2018 16:34:21 -0400 Subject: merging --- googletest/include/gtest/internal/gtest-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index c050da7..a0f2771 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -1155,7 +1155,7 @@ class NativeArray { #define GTEST_SUCCESS_(message) \ GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess) -// Suppresses MSVC warnings 4072 (unreachable code) for the code following +// Suppress MSVC warning 4702 (unreachable code) for the code following // statement if it returns or throws (or doesn't return or throw in some // situations). #define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \ -- cgit v0.12 From b15be9a819ee3e0a36fcc8172a00ecf41e79f230 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 11 Apr 2018 09:20:48 -0400 Subject: fixing osx pizza --- googlemock/test/gmock-generated-actions_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index b821e5a..1d685e5 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -376,7 +376,8 @@ class SubstractAction : public ActionInterface { // NOLINT TEST(WithArgsTest, NonInvokeAction) { Action a = // NOLINT WithArgs<2, 1>(MakeAction(new SubstractAction)); - EXPECT_EQ(8, a.Perform(make_tuple(std::string("hi"), 2, 10))); + tuple dummy = make_tuple(std::string("hi"), 2, 10); + EXPECT_EQ(8, a.Perform(dummy)); } // Tests using WithArgs to pass all original arguments in the original order. -- cgit v0.12 From f15fd9610b8a462b19a259b4b7ae279b9e97a77c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 11 Apr 2018 09:33:51 -0400 Subject: osx pizzas, cont --- googlemock/test/gmock-generated-actions_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index 1d685e5..6ddd57f 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -754,7 +754,8 @@ TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) { TEST(ActionPMacroTest, WorksInCompatibleMockFunction) { Action a1 = Plus("tail"); const std::string re = "re"; - EXPECT_EQ("retail", a1.Perform(make_tuple(re))); + tuple dummy = make_tuple(re); + EXPECT_EQ("retail", a1.Perform(dummy)); } // Tests that we can use ACTION*() to define actions overloaded on the -- cgit v0.12 From 039d9b54c25829915679992671030caaa706f8fc Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 11 Apr 2018 09:47:38 -0400 Subject: pizza work, cont --- googlemock/test/gmock-generated-actions_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index 6ddd57f..11d12dc 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -797,7 +797,8 @@ TEST(ActionPnMacroTest, WorksFor3Parameters) { Action a2 = Plus("tail", "-", ">"); const std::string re = "re"; - EXPECT_EQ("retail->", a2.Perform(make_tuple(re))); + tuple dummy = make_tuple(re); + EXPECT_EQ("retail->", a2.Perform(dummy)); } ACTION_P4(Plus, p0, p1, p2, p3) { return arg0 + p0 + p1 + p2 + p3; } -- cgit v0.12 From 6a7573a7de99501ac928a058cc4732598f45be69 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 11 Apr 2018 09:55:36 -0400 Subject: more --- googlemock/test/gmock-generated-actions_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index 11d12dc..40bbe6d 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -797,7 +797,7 @@ TEST(ActionPnMacroTest, WorksFor3Parameters) { Action a2 = Plus("tail", "-", ">"); const std::string re = "re"; - tuple dummy = make_tuple(re); + tuple dummy = make_tuple(re); EXPECT_EQ("retail->", a2.Perform(dummy)); } -- cgit v0.12 From 5cd213ea5ed6de0ba2b79b9403a0b5ccf48f8984 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 11 Apr 2018 10:10:24 -0400 Subject: ..and this should be it --- googlemock/include/gmock/internal/gmock-internal-utils.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 37ceb54..20c95c6 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -48,6 +48,14 @@ namespace testing { namespace internal { +// Silence MSVC C4100 (unreferenced formal parameter) and +// C4805('==': unsafe mix of type 'const int' and type 'const bool') +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:4100) +# pragma warning(disable:4805) +#endif + // Joins a vector of strings as if they are fields of a tuple; returns // the joined string. GTEST_API_ std::string JoinAsTuple(const Strings& fields); @@ -510,7 +518,7 @@ struct BooleanConstant {}; // Emit an assertion failure due to incorrect DoDefault() usage. Out-of-lined to // reduce code size. -void IllegalDoDefault(const char* file, int line); +GTEST_API_ void IllegalDoDefault(const char* file, int line); #if GTEST_LANG_CXX11 // Helper types for Apply() below. @@ -539,6 +547,12 @@ auto Apply(F&& f, Tuple&& args) make_int_pack::value>()); } #endif + + +#ifdef _MSC_VER +# pragma warning(pop) +#endif + } // namespace internal } // namespace testing -- cgit v0.12 From c13ab6003be734fe2119496d8ed6a8d4ecb8b902 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 11 Apr 2018 13:20:36 -0400 Subject: merging --- googletest/test/gtest-port_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/test/gtest-port_test.cc b/googletest/test/gtest-port_test.cc index 4ed4afc..51956f0 100644 --- a/googletest/test/gtest-port_test.cc +++ b/googletest/test/gtest-port_test.cc @@ -67,8 +67,8 @@ TEST(IsXDigitTest, WorksForNarrowAscii) { } TEST(IsXDigitTest, ReturnsFalseForNarrowNonAscii) { - EXPECT_FALSE(IsXDigit(static_cast(0x80))); - EXPECT_FALSE(IsXDigit(static_cast('0' | 0x80))); + EXPECT_FALSE(IsXDigit(static_cast('\x80'))); + EXPECT_FALSE(IsXDigit(static_cast('0' | '\x80'))); } TEST(IsXDigitTest, WorksForWideAscii) { -- cgit v0.12 From ab84d14281889a59f16a5c04c14b911d8c79d288 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 11 Apr 2018 15:24:04 -0400 Subject: Upstream cl/192179348 --- googlemock/include/gmock/gmock-matchers.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 0ac3b29..fcb45ac 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -4140,7 +4140,8 @@ class VariantMatcher { private: static std::string GetTypeName() { #if GTEST_HAS_RTTI - return internal::GetTypeName(); + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_( + return internal::GetTypeName()); #endif return "the element type"; } @@ -4200,7 +4201,8 @@ class AnyCastMatcher { private: static std::string GetTypeName() { #if GTEST_HAS_RTTI - return internal::GetTypeName(); + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_( + return internal::GetTypeName()); #endif return "the element type"; } -- cgit v0.12 From 8654c1ca10a1fff1ab6778bc0a4545b3e68c7f41 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 11 Apr 2018 15:33:31 -0400 Subject: merging --- googlemock/include/gmock/gmock-actions.h | 90 ++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 17 deletions(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 90fd2ea..a2784f6 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -360,14 +360,20 @@ class Action { // Constructs a null Action. Needed for storing Action objects in // STL containers. - Action() : impl_(NULL) {} + Action() {} - // Constructs an Action from its implementation. A NULL impl is - // used to represent the "do-default" action. - explicit Action(ActionInterface* impl) : impl_(impl) {} +#if GTEST_LANG_CXX11 + // Construct an Action from a specified callable. + // This cannot take std::function directly, because then Action would not be + // directly constructible from lambda (it would require two conversions). + template , G>::value>::type> + Action(G&& fun) : fun_(::std::forward(fun)) {} // NOLINT +#endif - // Copy constructor. - Action(const Action& action) : impl_(action.impl_) {} + // Constructs an Action from its implementation. + explicit Action(ActionInterface* impl) : impl_(impl) {} // This constructor allows us to turn an Action object into an // Action, as long as F's arguments can be implicitly converted @@ -377,7 +383,13 @@ class Action { explicit Action(const Action& action); // Returns true iff this is the DoDefault() action. - bool IsDoDefault() const { return impl_.get() == NULL; } + bool IsDoDefault() const { +#if GTEST_LANG_CXX11 + return impl_ == nullptr && fun_ == nullptr; +#else + return impl_ == NULL; +#endif + } // Performs the action. Note that this method is const even though // the corresponding method in ActionInterface is not. The reason @@ -385,14 +397,15 @@ class Action { // another concrete action, not that the concrete action it binds to // cannot change state. (Think of the difference between a const // pointer and a pointer to const.) - Result Perform(const ArgumentTuple& args) const { - internal::Assert( - !IsDoDefault(), __FILE__, __LINE__, - "You are using DoDefault() inside a composite action like " - "DoAll() or WithArgs(). This is not supported for technical " - "reasons. Please instead spell out the default action, or " - "assign the default action to an Action variable and use " - "the variable in various places."); + Result Perform(ArgumentTuple args) const { + if (IsDoDefault()) { + internal::IllegalDoDefault(__FILE__, __LINE__); + } +#if GTEST_LANG_CXX11 + if (fun_ != nullptr) { + return internal::Apply(fun_, ::std::move(args)); + } +#endif return impl_->Perform(args); } @@ -400,6 +413,18 @@ class Action { template friend class internal::ActionAdaptor; + template + friend class Action; + + // In C++11, Action can be implemented either as a generic functor (through + // std::function), or legacy ActionInterface. In C++98, only ActionInterface + // is available. The invariants are as follows: + // * in C++98, impl_ is null iff this is the default action + // * in C++11, at most one of fun_ & impl_ may be nonnull; both are null iff + // this is the default action +#if GTEST_LANG_CXX11 + ::std::function fun_; +#endif internal::linked_ptr > impl_; }; @@ -531,6 +556,9 @@ struct ByMoveWrapper { // statement, and conversion of the result of Return to Action is a // good place for that. // +// The real life example of the above scenario happens when an invocation +// of gtl::Container() is passed into Return. +// template class ReturnAction { public: @@ -750,7 +778,7 @@ class DoDefaultAction { // This template type conversion operator allows DoDefault() to be // used in any function. template - operator Action() const { return Action(NULL); } + operator Action() const { return Action(); } // NOLINT }; // Implements the Assign action to set a given pointer referent to a @@ -886,6 +914,28 @@ class InvokeMethodWithoutArgsAction { GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction); }; +// Implements the InvokeWithoutArgs(callback) action. +template +class InvokeCallbackWithoutArgsAction { + public: + // The c'tor takes ownership of the callback. + explicit InvokeCallbackWithoutArgsAction(CallbackType* callback) + : callback_(callback) { + callback->CheckIsRepeatable(); // Makes sure the callback is permanent. + } + + // This type conversion operator template allows Invoke(callback) to + // be used wherever the callback's return type can be implicitly + // converted to that of the mock function. + template + Result Perform(const ArgumentTuple&) const { return callback_->Run(); } + + private: + const internal::linked_ptr callback_; + + GTEST_DISALLOW_ASSIGN_(InvokeCallbackWithoutArgsAction); +}; + // Implements the IgnoreResult(action) action. template class IgnoreResultAction { @@ -1053,7 +1103,13 @@ typedef internal::IgnoredValue Unused; template template Action::Action(const Action& from) - : impl_(new internal::ActionAdaptor(from)) {} + : +#if GTEST_LANG_CXX11 + fun_(from.fun_), +#endif + impl_(from.impl_ == NULL ? NULL + : new internal::ActionAdaptor(from)) { +} // Creates an action that returns 'value'. 'value' is passed by value // instead of const reference - otherwise Return("string literal") -- cgit v0.12 From 373481c5a9b9bf08c158703d6dc5ab58d4dee0cc Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 11 Apr 2018 15:46:57 -0400 Subject: ...merging --- googlemock/src/gmock-internal-utils.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/src/gmock-internal-utils.cc b/googlemock/src/gmock-internal-utils.cc index 20c5a8d..3fca3f2 100644 --- a/googlemock/src/gmock-internal-utils.cc +++ b/googlemock/src/gmock-internal-utils.cc @@ -188,7 +188,7 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message, std::cout << ::std::flush; } -void IllegalDoDefault(const char* file, int line) { +GTEST_API_ void IllegalDoDefault(const char* file, int line) { internal::Assert( false, file, line, "You are using DoDefault() inside a composite action like " -- cgit v0.12 From 1324e2d706d739217cceae361259a5cc01d1ff41 Mon Sep 17 00:00:00 2001 From: Victor Costan Date: Mon, 9 Apr 2018 21:57:54 -0700 Subject: Remove multiple inheritance from "unintesting call" mock classes. Internal CL 156157936, which was published in commit fe402c27790ff1cc9a7e17c5d0aea4ebe7fd8a71, introduced undefined behavior by casting a base class (internal::{Naggy,Nice,Strict}Base, using the curiously recurring template pattern) pointer to a derived class ({Naggy,Nice,Strict}Mock), in the base class' constructor. At that point, the object isn't guaranteed to have taken on the shape of the derived class, and casting is undefined behavior. The undefined behavior was caught by Chrome's CFI build bot [1], and prevents rolling googletest past that commit / CL. This commit simplifies the {Naggy,Nice,Strict}Mock class hierarchy in a way that removes the undefined behavior. [1] https://www.chromium.org/developers/testing/control-flow-integrity --- .../include/gmock/gmock-generated-nice-strict.h | 332 +++++++++++---------- .../gmock/gmock-generated-nice-strict.h.pump | 70 ++--- googlemock/include/gmock/gmock-spec-builders.h | 11 +- googlemock/test/gmock-nice-strict_test.cc | 21 ++ 4 files changed, 224 insertions(+), 210 deletions(-) diff --git a/googlemock/include/gmock/gmock-generated-nice-strict.h b/googlemock/include/gmock/gmock-generated-nice-strict.h index af71fbd..5e1386b 100644 --- a/googlemock/include/gmock/gmock-generated-nice-strict.h +++ b/googlemock/include/gmock/gmock-generated-nice-strict.h @@ -71,329 +71,345 @@ namespace testing { -namespace internal { - -// NiceMockBase serves as a mix-in to establish the "uninteresting call" -// behavior for NiceMock on construction. It accomplishes this via CRTP to get -// access to the derived MockClass. -template -class NiceMockBase { - protected: - NiceMockBase(); - - ~NiceMockBase(); -}; - -} // namespace internal - template -class NiceMock : public MockClass, public internal::NiceMockBase { +class NiceMock : public MockClass { public: - NiceMock() : MockClass() {} + NiceMock() : MockClass() { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } #if GTEST_LANG_CXX11 - // Ideally, we would inherit base class's constructors through a using - // declaration, which would preserve their visibility. However, many existing - // tests rely on the fact that current implementation reexports protected - // constructors as public. These tests would need to be cleaned up first. - // Single argument constructor is special-cased so that it can be // made explicit. template - explicit NiceMock(A&& arg) : MockClass(std::forward(arg)) {} + explicit NiceMock(A&& arg) : MockClass(std::forward(arg)) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } template NiceMock(A1&& arg1, A2&& arg2, An&&... args) : MockClass(std::forward(arg1), std::forward(arg2), - std::forward(args)...) {} + std::forward(args)...) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } #else // C++98 doesn't have variadic templates, so we have to define one // for each arity. template - explicit NiceMock(const A1& a1) : MockClass(a1) {} + explicit NiceMock(const A1& a1) : MockClass(a1) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } template - NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {} + NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } template - NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {} + NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } template NiceMock(const A1& a1, const A2& a2, const A3& a3, - const A4& a4) : MockClass(a1, a2, a3, a4) {} + const A4& a4) : MockClass(a1, a2, a3, a4) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } template NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5) : MockClass(a1, a2, a3, a4, a5) {} + const A5& a5) : MockClass(a1, a2, a3, a4, a5) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } template NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {} + const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } template NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, - a6, a7) {} + a6, a7) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } template NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, - a2, a3, a4, a5, a6, a7, a8) {} + a2, a3, a4, a5, a6, a7, a8) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } template NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, - const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {} + const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } template NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, - const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {} + const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { + ::testing::Mock::AllowUninterestingCalls( + internal::ImplicitCast_(this)); + } #endif // GTEST_LANG_CXX11 + ~NiceMock() { + ::testing::Mock::UnregisterCallReaction( + internal::ImplicitCast_(this)); + } + private: GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock); }; -namespace internal { - -template -NiceMockBase::NiceMockBase() { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_( - static_cast *>(this))); -} - -template -NiceMockBase::~NiceMockBase() { - ::testing::Mock::UnregisterCallReaction( - internal::ImplicitCast_( - static_cast*>(this))); -} - -} // namespace internal - -namespace internal { - -// NaggyMockBase serves as a mix-in to establish the "uninteresting call" -// behavior for NaggyMock on construction. It accomplishes this via CRTP to get -// access to the derived MockClass. -template -class NaggyMockBase { - protected: - NaggyMockBase(); - - ~NaggyMockBase(); -}; - -} // namespace internal - template -class NaggyMock : public MockClass, public internal::NaggyMockBase { +class NaggyMock : public MockClass { public: - NaggyMock() : MockClass() {} + NaggyMock() : MockClass() { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } #if GTEST_LANG_CXX11 - // Ideally, we would inherit base class's constructors through a using - // declaration, which would preserve their visibility. However, many existing - // tests rely on the fact that current implementation reexports protected - // constructors as public. These tests would need to be cleaned up first. - // Single argument constructor is special-cased so that it can be // made explicit. template - explicit NaggyMock(A&& arg) : MockClass(std::forward(arg)) {} + explicit NaggyMock(A&& arg) : MockClass(std::forward(arg)) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } template NaggyMock(A1&& arg1, A2&& arg2, An&&... args) : MockClass(std::forward(arg1), std::forward(arg2), - std::forward(args)...) {} + std::forward(args)...) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } #else // C++98 doesn't have variadic templates, so we have to define one // for each arity. template - explicit NaggyMock(const A1& a1) : MockClass(a1) {} + explicit NaggyMock(const A1& a1) : MockClass(a1) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } template - NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {} + NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } template - NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {} + NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } template NaggyMock(const A1& a1, const A2& a2, const A3& a3, - const A4& a4) : MockClass(a1, a2, a3, a4) {} + const A4& a4) : MockClass(a1, a2, a3, a4) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } template NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5) : MockClass(a1, a2, a3, a4, a5) {} + const A5& a5) : MockClass(a1, a2, a3, a4, a5) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } template NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {} + const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } template NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, - a6, a7) {} + a6, a7) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } template NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, - a2, a3, a4, a5, a6, a7, a8) {} + a2, a3, a4, a5, a6, a7, a8) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } template NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, - const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {} + const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } template NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, - const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {} + const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { + ::testing::Mock::WarnUninterestingCalls( + internal::ImplicitCast_(this)); + } #endif // GTEST_LANG_CXX11 + ~NaggyMock() { + ::testing::Mock::UnregisterCallReaction( + internal::ImplicitCast_(this)); + } + private: GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock); }; -namespace internal { - -template -NaggyMockBase::NaggyMockBase() { - ::testing::Mock::WarnUninterestingCalls( - internal::ImplicitCast_( - static_cast *>(this))); -} - -template -NaggyMockBase::~NaggyMockBase() { - ::testing::Mock::UnregisterCallReaction( - internal::ImplicitCast_( - static_cast*>(this))); -} - -} // namespace internal - -namespace internal { - -// StrictMockBase serves as a mix-in to establish the "uninteresting call" -// behavior for StrictMock on construction. It accomplishes this via CRTP to get -// access to the derived MockClass. template -class StrictMockBase { - protected: - StrictMockBase(); - - ~StrictMockBase(); -}; - -} // namespace internal - -template -class StrictMock : public MockClass, - public internal::StrictMockBase { +class StrictMock : public MockClass { public: - StrictMock() : MockClass() {} + StrictMock() : MockClass() { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } #if GTEST_LANG_CXX11 - // Ideally, we would inherit base class's constructors through a using - // declaration, which would preserve their visibility. However, many existing - // tests rely on the fact that current implementation reexports protected - // constructors as public. These tests would need to be cleaned up first. - // Single argument constructor is special-cased so that it can be // made explicit. template - explicit StrictMock(A&& arg) : MockClass(std::forward(arg)) {} + explicit StrictMock(A&& arg) : MockClass(std::forward(arg)) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } template StrictMock(A1&& arg1, A2&& arg2, An&&... args) : MockClass(std::forward(arg1), std::forward(arg2), - std::forward(args)...) {} + std::forward(args)...) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } #else // C++98 doesn't have variadic templates, so we have to define one // for each arity. template - explicit StrictMock(const A1& a1) : MockClass(a1) {} + explicit StrictMock(const A1& a1) : MockClass(a1) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } template - StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {} + StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } template - StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, - a3) {} + StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } template StrictMock(const A1& a1, const A2& a2, const A3& a3, - const A4& a4) : MockClass(a1, a2, a3, a4) {} + const A4& a4) : MockClass(a1, a2, a3, a4) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } template StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5) : MockClass(a1, a2, a3, a4, a5) {} + const A5& a5) : MockClass(a1, a2, a3, a4, a5) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } template StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {} + const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } template StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, - a6, a7) {} + a6, a7) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } template StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, - a2, a3, a4, a5, a6, a7, a8) {} + a2, a3, a4, a5, a6, a7, a8) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } template StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, - const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {} + const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } template StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, - const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {} + const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { + ::testing::Mock::FailUninterestingCalls( + internal::ImplicitCast_(this)); + } #endif // GTEST_LANG_CXX11 + ~StrictMock() { + ::testing::Mock::UnregisterCallReaction( + internal::ImplicitCast_(this)); + } + private: GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock); }; -namespace internal { - -template -StrictMockBase::StrictMockBase() { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_( - static_cast *>(this))); -} - -template -StrictMockBase::~StrictMockBase() { - ::testing::Mock::UnregisterCallReaction( - internal::ImplicitCast_( - static_cast*>(this))); -} - -} // namespace internal - // The following specializations catch some (relatively more common) // user errors of nesting nice and strict mocks. They do NOT catch // all possible errors. diff --git a/googlemock/include/gmock/gmock-generated-nice-strict.h.pump b/googlemock/include/gmock/gmock-generated-nice-strict.h.pump index 378c40f..2e50e98 100644 --- a/googlemock/include/gmock/gmock-generated-nice-strict.h.pump +++ b/googlemock/include/gmock/gmock-generated-nice-strict.h.pump @@ -83,79 +83,61 @@ $var method=[[$if kind==0 [[AllowUninterestingCalls]] $elif kind==1 [[WarnUninterestingCalls]] $else [[FailUninterestingCalls]]]] -namespace internal { - -// $clazz[[]]Base serves as a mix-in to establish the "uninteresting call" -// behavior for $clazz on construction. It accomplishes this via CRTP to get -// access to the derived MockClass. template -class $clazz[[]]Base { - protected: - $clazz[[]]Base(); - - ~$clazz[[]]Base(); -}; - -} // namespace internal - -template -class $clazz : public MockClass, public internal::$clazz[[]]Base { +class $clazz : public MockClass { public: - $clazz() : MockClass() {} + $clazz() : MockClass() { + ::testing::Mock::$method( + internal::ImplicitCast_(this)); + } #if GTEST_LANG_CXX11 - // Ideally, we would inherit base class's constructors through a using - // declaration, which would preserve their visibility. However, many existing - // tests rely on the fact that current implementation reexports protected - // constructors as public. These tests would need to be cleaned up first. - // Single argument constructor is special-cased so that it can be // made explicit. template - explicit $clazz(A&& arg) : MockClass(std::forward(arg)) {} + explicit $clazz(A&& arg) : MockClass(std::forward(arg)) { + ::testing::Mock::$method( + internal::ImplicitCast_(this)); + } template $clazz(A1&& arg1, A2&& arg2, An&&... args) : MockClass(std::forward(arg1), std::forward(arg2), - std::forward(args)...) {} + std::forward(args)...) { + ::testing::Mock::$method( + internal::ImplicitCast_(this)); + } #else // C++98 doesn't have variadic templates, so we have to define one // for each arity. template - explicit $clazz(const A1& a1) : MockClass(a1) {} + explicit $clazz(const A1& a1) : MockClass(a1) { + ::testing::Mock::$method( + internal::ImplicitCast_(this)); + } $range i 2..n $for i [[ $range j 1..i template <$for j, [[typename A$j]]> - $clazz($for j, [[const A$j& a$j]]) : MockClass($for j, [[a$j]]) {} + $clazz($for j, [[const A$j& a$j]]) : MockClass($for j, [[a$j]]) { + ::testing::Mock::$method( + internal::ImplicitCast_(this)); + } ]] #endif // GTEST_LANG_CXX11 + ~$clazz() { + ::testing::Mock::UnregisterCallReaction( + internal::ImplicitCast_(this)); + } + private: GTEST_DISALLOW_COPY_AND_ASSIGN_($clazz); }; -namespace internal { - -template -$clazz[[]]Base::$clazz[[]]Base() { - ::testing::Mock::$method( - internal::ImplicitCast_( - static_cast<$clazz *>(this))); -} - -template -$clazz[[]]Base::~$clazz[[]]Base() { - ::testing::Mock::UnregisterCallReaction( - internal::ImplicitCast_( - static_cast<$clazz*>(this))); -} - -} // namespace internal - ]] // The following specializations catch some (relatively more common) diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index 6d7f920..a7be7d1 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -103,11 +103,6 @@ class ExpectationTester; // Base class for function mockers. template class FunctionMockerBase; -// Uninteresting call behavior mixins. -template class NiceMockBase; -template class NaggyMockBase; -template class StrictMockBase; - // Protects the mock object registry (in class Mock), all function // mockers, and all expectations. // @@ -408,13 +403,13 @@ class GTEST_API_ Mock { friend class internal::FunctionMockerBase; template - friend class internal::NiceMockBase; + friend class NiceMock; template - friend class internal::NaggyMockBase; + friend class NaggyMock; template - friend class internal::StrictMockBase; + friend class StrictMock; // Tells Google Mock to allow uninteresting calls on the given mock // object. diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index 0eac643..7812f62 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -259,6 +259,13 @@ TEST(NiceMockTest, NonDefaultConstructor10) { nice_bar.That(5, true); } +TEST(NiceMockTest, AllowLeak) { + NiceMock* leaked = new NiceMock; + Mock::AllowLeak(leaked); + EXPECT_CALL(*leaked, DoThis()); + leaked->DoThis(); +} + #if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE // Tests that NiceMock compiles where Mock is a user-defined // class (as opposed to ::testing::Mock). We had to work around an @@ -352,6 +359,13 @@ TEST(NaggyMockTest, NonDefaultConstructor10) { naggy_bar.That(5, true); } +TEST(NaggyMockTest, AllowLeak) { + NaggyMock* leaked = new NaggyMock; + Mock::AllowLeak(leaked); + EXPECT_CALL(*leaked, DoThis()); + leaked->DoThis(); +} + #if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE // Tests that NaggyMock compiles where Mock is a user-defined // class (as opposed to ::testing::Mock). We had to work around an @@ -426,6 +440,13 @@ TEST(StrictMockTest, NonDefaultConstructor10) { "Uninteresting mock function call"); } +TEST(StrictMockTest, AllowLeak) { + StrictMock* leaked = new StrictMock; + Mock::AllowLeak(leaked); + EXPECT_CALL(*leaked, DoThis()); + leaked->DoThis(); +} + #if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE // Tests that StrictMock compiles where Mock is a user-defined // class (as opposed to ::testing::Mock). We had to work around an -- cgit v0.12 From e77deb29a65444247343c3ace800782de3706fd1 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 09:12:02 -0400 Subject: small cleanup --- googlemock/include/gmock/gmock-more-matchers.h | 8 ++++++++ googlemock/test/gmock-matchers_test.cc | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/googlemock/include/gmock/gmock-more-matchers.h b/googlemock/include/gmock/gmock-more-matchers.h index 01298cf..6d810eb 100644 --- a/googlemock/include/gmock/gmock-more-matchers.h +++ b/googlemock/include/gmock/gmock-more-matchers.h @@ -46,8 +46,11 @@ namespace testing { // Silence C4100 (unreferenced formal // parameter) for MSVC #ifdef _MSC_VER +# pragma warning(push) # pragma warning(disable:4100) #if (_MSC_VER == 1900) +// and silence C4800 (C4800: 'int *const ': forcing value +// to bool 'true' or 'false') for MSVC 14 # pragma warning(disable:4800) #endif #endif @@ -78,6 +81,11 @@ MATCHER(IsFalse, negation ? "is true" : "is false") { return !static_cast(arg); } +#ifdef _MSC_VER +# pragma warning(pop) +#endif + + } // namespace testing #endif // GMOCK_GMOCK_MORE_MATCHERS_H_ diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 33be41a..4f7d0ec 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -62,6 +62,7 @@ // Disable MSVC2015 warning for std::pair: // "decorated name length exceeded, name was truncated". #if defined(_MSC_VER) && (_MSC_VER == 1900) +# pragma warning(push) # pragma warning(disable:4503) #endif @@ -6656,7 +6657,7 @@ TEST(AnyWithTest, TestUseInContainers) { AnyWith("merhaba"), AnyWith("salut")})); } -#endif // GTEST_LANG_CXX11 +#endif // GTEST_LANG_CXX11 TEST(AnyWithTest, TestCompare) { EXPECT_THAT(SampleAnyType(1), AnyWith(Gt(0))); } @@ -6694,3 +6695,8 @@ TEST(NotTest, WorksOnMoveOnlyType) { } // namespace gmock_matchers_test } // namespace testing + +#if defined(_MSC_VER) && (_MSC_VER == 1900) +# pragma warning(pop) +#endif + -- cgit v0.12 From b2d81b4fb2a229d01655afabec9679197cc2c1f4 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 09:45:07 -0400 Subject: merge, ... gmock-matchers test --- googlemock/test/gmock-matchers_test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 4f7d0ec..0e40df3 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -61,7 +61,7 @@ // Disable MSVC2015 warning for std::pair: // "decorated name length exceeded, name was truncated". -#if defined(_MSC_VER) && (_MSC_VER == 1900) +#if defined(_MSC_VER) && (_MSC_VER <= 1900) # pragma warning(push) # pragma warning(disable:4503) #endif @@ -761,7 +761,7 @@ namespace convertible_from_any { struct ConvertibleFromAny { ConvertibleFromAny(int a_value) : value(a_value) {} template - explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) { + ConvertibleFromAny(const T& /*a_value*/) : value(-1) { ADD_FAILURE() << "Conversion constructor called"; } int value; @@ -6696,7 +6696,7 @@ TEST(NotTest, WorksOnMoveOnlyType) { } // namespace gmock_matchers_test } // namespace testing -#if defined(_MSC_VER) && (_MSC_VER == 1900) +#if defined(_MSC_VER) && (_MSC_VER <= 1900) # pragma warning(pop) #endif -- cgit v0.12 From 9b5940e040c9e0f45bb3dfe3ab457d1e6ec022b0 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 10:28:02 -0400 Subject: revert this one --- 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 0e40df3..3162a05 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -761,7 +761,7 @@ namespace convertible_from_any { struct ConvertibleFromAny { ConvertibleFromAny(int a_value) : value(a_value) {} template - ConvertibleFromAny(const T& /*a_value*/) : value(-1) { + explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) { ADD_FAILURE() << "Conversion constructor called"; } int value; -- cgit v0.12 From c67f51b5dc1a7e2b614d50b60061bb143be71d45 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 11:32:17 -0400 Subject: msvc --- 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 3162a05..16116b5 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -61,7 +61,7 @@ // Disable MSVC2015 warning for std::pair: // "decorated name length exceeded, name was truncated". -#if defined(_MSC_VER) && (_MSC_VER <= 1900) +#if defined _MSC_VER # pragma warning(push) # pragma warning(disable:4503) #endif @@ -6696,7 +6696,7 @@ TEST(NotTest, WorksOnMoveOnlyType) { } // namespace gmock_matchers_test } // namespace testing -#if defined(_MSC_VER) && (_MSC_VER <= 1900) +#if defined_MSC_VER # pragma warning(pop) #endif -- cgit v0.12 From fa658e0cc08075b134b5ed35808f31a557616c9c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 13:42:47 -0400 Subject: merging --- .../gmock/gmock-generated-function-mockers.h.pump | 32 ++++++++++------------ .../test/gmock-generated-function-mockers_test.cc | 23 ++++++++++++++++ 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/googlemock/include/gmock/gmock-generated-function-mockers.h.pump b/googlemock/include/gmock/gmock-generated-function-mockers.h.pump index 55dc6c5..277003b 100644 --- a/googlemock/include/gmock/gmock-generated-function-mockers.h.pump +++ b/googlemock/include/gmock/gmock-generated-function-mockers.h.pump @@ -68,7 +68,7 @@ $for i [[ $range j 1..i $var typename_As = [[$for j [[, typename A$j]]]] $var As = [[$for j, [[A$j]]]] -$var as = [[$for j, [[a$j]]]] +$var as = [[$for j, [[internal::forward(a$j)]]]] $var Aas = [[$for j, [[A$j a$j]]]] $var ms = [[$for j, [[m$j]]]] $var matchers = [[$for j, [[const Matcher& m$j]]]] @@ -79,13 +79,8 @@ class FunctionMocker : public typedef R F($As); typedef typename internal::Function::ArgumentTuple ArgumentTuple; - MockSpec& With($matchers) { - -$if i >= 1 [[ - this->current_spec().SetMatchers(::testing::make_tuple($ms)); - -]] - return this->current_spec(); + MockSpec With($matchers) { + return MockSpec(this, ::testing::make_tuple($ms)); } R Invoke($Aas) { @@ -134,11 +129,12 @@ using internal::FunctionMocker; $for i [[ $range j 1..i -$var arg_as = [[$for j, \ - [[GMOCK_ARG_(tn, $j, __VA_ARGS__) gmock_a$j]]]] -$var as = [[$for j, [[gmock_a$j]]]] -$var matcher_as = [[$for j, \ +$var arg_as = [[$for j, [[GMOCK_ARG_(tn, $j, __VA_ARGS__) gmock_a$j]]]] +$var as = [[$for j, \ + [[::testing::internal::forward(gmock_a$j)]]]] +$var matcher_arg_as = [[$for j, \ [[GMOCK_MATCHER_(tn, $j, __VA_ARGS__) gmock_a$j]]]] +$var matcher_as = [[$for j, [[gmock_a$j]]]] // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, ...) \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ @@ -149,10 +145,10 @@ $var matcher_as = [[$for j, \ GMOCK_MOCKER_($i, constness, Method).SetOwnerAndName(this, #Method); \ return GMOCK_MOCKER_($i, constness, Method).Invoke($as); \ } \ - ::testing::MockSpec<__VA_ARGS__>& \ - gmock_##Method($matcher_as) constness { \ + ::testing::MockSpec<__VA_ARGS__> \ + gmock_##Method($matcher_arg_as) constness { \ GMOCK_MOCKER_($i, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_($i, constness, Method).With($as); \ + return GMOCK_MOCKER_($i, constness, Method).With($matcher_as); \ } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_($i, constness, Method) @@ -263,7 +259,7 @@ class MockFunction; $for i [[ $range j 0..i-1 $var ArgTypes = [[$for j, [[A$j]]]] -$var ArgNames = [[$for j, [[a$j]]]] +$var ArgValues = [[$for j, [[::std::move(a$j)]]]] $var ArgDecls = [[$for j, [[A$j a$j]]]] template class MockFunction { @@ -273,9 +269,9 @@ class MockFunction { MOCK_METHOD$i[[]]_T(Call, R($ArgTypes)); #if GTEST_HAS_STD_FUNCTION_ - std::function AsStdFunction() { + ::std::function AsStdFunction() { return [this]($ArgDecls) -> R { - return this->Call($ArgNames); + return this->Call($ArgValues); }; } #endif // GTEST_HAS_STD_FUNCTION_ diff --git a/googlemock/test/gmock-generated-function-mockers_test.cc b/googlemock/test/gmock-generated-function-mockers_test.cc index 08e5eba..0ff3755 100644 --- a/googlemock/test/gmock-generated-function-mockers_test.cc +++ b/googlemock/test/gmock-generated-function-mockers_test.cc @@ -620,5 +620,28 @@ TEST(MockFunctionTest, AsStdFunctionReturnsReference) { } #endif // GTEST_HAS_STD_FUNCTION_ +struct MockMethodSizes0 { + MOCK_METHOD0(func, void()); +}; +struct MockMethodSizes1 { + MOCK_METHOD1(func, void(int)); +}; +struct MockMethodSizes2 { + MOCK_METHOD2(func, void(int, int)); +}; +struct MockMethodSizes3 { + MOCK_METHOD3(func, void(int, int, int)); +}; +struct MockMethodSizes4 { + MOCK_METHOD4(func, void(int, int, int, int)); +}; + +TEST(MockFunctionTest, MockMethodSizeOverhead) { + EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes1)); + EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes2)); + EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes3)); + EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes4)); +} + } // namespace gmock_generated_function_mockers_test } // namespace testing -- cgit v0.12 From a79851f2c26755324bf0340eed3538d3a047b7a7 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 14:00:38 -0400 Subject: merging --- .../include/gmock/gmock-generated-nice-strict.h | 15 +++++++ .../gmock/gmock-generated-nice-strict.h.pump | 5 +++ googlemock/test/gmock-nice-strict_test.cc | 50 ++++++++++++++++++++-- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/googlemock/include/gmock/gmock-generated-nice-strict.h b/googlemock/include/gmock/gmock-generated-nice-strict.h index 5e1386b..8e56873 100644 --- a/googlemock/include/gmock/gmock-generated-nice-strict.h +++ b/googlemock/include/gmock/gmock-generated-nice-strict.h @@ -80,6 +80,11 @@ class NiceMock : public MockClass { } #if GTEST_LANG_CXX11 + // Ideally, we would inherit base class's constructors through a using + // declaration, which would preserve their visibility. However, many existing + // tests rely on the fact that current implementation reexports protected + // constructors as public. These tests would need to be cleaned up first. + // Single argument constructor is special-cased so that it can be // made explicit. template @@ -193,6 +198,11 @@ class NaggyMock : public MockClass { } #if GTEST_LANG_CXX11 + // Ideally, we would inherit base class's constructors through a using + // declaration, which would preserve their visibility. However, many existing + // tests rely on the fact that current implementation reexports protected + // constructors as public. These tests would need to be cleaned up first. + // Single argument constructor is special-cased so that it can be // made explicit. template @@ -306,6 +316,11 @@ class StrictMock : public MockClass { } #if GTEST_LANG_CXX11 + // Ideally, we would inherit base class's constructors through a using + // declaration, which would preserve their visibility. However, many existing + // tests rely on the fact that current implementation reexports protected + // constructors as public. These tests would need to be cleaned up first. + // Single argument constructor is special-cased so that it can be // made explicit. template diff --git a/googlemock/include/gmock/gmock-generated-nice-strict.h.pump b/googlemock/include/gmock/gmock-generated-nice-strict.h.pump index 2e50e98..2f443ae 100644 --- a/googlemock/include/gmock/gmock-generated-nice-strict.h.pump +++ b/googlemock/include/gmock/gmock-generated-nice-strict.h.pump @@ -92,6 +92,11 @@ class $clazz : public MockClass { } #if GTEST_LANG_CXX11 + // Ideally, we would inherit base class's constructors through a using + // declaration, which would preserve their visibility. However, many existing + // tests rely on the fact that current implementation reexports protected + // constructors as public. These tests would need to be cleaned up first. + // Single argument constructor is special-cased so that it can be // made explicit. template diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index 7812f62..c419494 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -32,9 +32,10 @@ #include "gmock/gmock-generated-nice-strict.h" #include +#include #include "gmock/gmock.h" -#include "gtest/gtest.h" #include "gtest/gtest-spi.h" +#include "gtest/gtest.h" // This must not be defined inside the ::testing namespace, or it will // clash with ::testing::Mock. @@ -114,6 +115,24 @@ class MockBar { GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar); }; +#if GTEST_GTEST_LANG_CXX11 + +class MockBaz { + public: + class MoveOnly { + MoveOnly() = default; + + MoveOnly(const MoveOnly&) = delete; + operator=(const MoveOnly&) = delete; + + MoveOnly(MoveOnly&&) = default; + operator=(MoveOnly&&) = default; + }; + + MockBaz(MoveOnly) {} +} +#endif // GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_ + #if GTEST_HAS_STREAM_REDIRECTION // Tests that a raw mock generates warnings for uninteresting calls. @@ -214,8 +233,9 @@ TEST(NiceMockTest, AllowsExpectedCall) { nice_foo.DoThis(); } -// Tests that an unexpected call on a nice mock which returns a not-default-constructible -// type throws an exception and the exception contains the method's name. +// Tests that an unexpected call on a nice mock which returns a +// not-default-constructible type throws an exception and the exception contains +// the method's name. TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) { NiceMock nice_foo; #if GTEST_HAS_EXCEPTIONS @@ -266,6 +286,14 @@ TEST(NiceMockTest, AllowLeak) { leaked->DoThis(); } +#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_ + +TEST(NiceMockTest, MoveOnlyConstructor) { + NiceMock nice_baz(MockBaz::MoveOnly()); +} + +#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_ + #if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE // Tests that NiceMock compiles where Mock is a user-defined // class (as opposed to ::testing::Mock). We had to work around an @@ -366,6 +394,14 @@ TEST(NaggyMockTest, AllowLeak) { leaked->DoThis(); } +#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_ + +TEST(NaggyMockTest, MoveOnlyConstructor) { + NaggyMock naggy_baz(MockBaz::MoveOnly()); +} + +#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_ + #if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE // Tests that NaggyMock compiles where Mock is a user-defined // class (as opposed to ::testing::Mock). We had to work around an @@ -447,6 +483,14 @@ TEST(StrictMockTest, AllowLeak) { leaked->DoThis(); } +#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_ + +TEST(StrictMockTest, MoveOnlyConstructor) { + StrictMock strict_baz(MockBaz::MoveOnly()); +} + +#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_ + #if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE // Tests that StrictMock compiles where Mock is a user-defined // class (as opposed to ::testing::Mock). We had to work around an -- cgit v0.12 From 092ca91072bfca56da3f7c19d4a07f0f5074f0ba Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 14:46:57 -0400 Subject: merging --- googlemock/test/gmock-more-actions_test.cc | 14 +++++--------- googlemock/test/gmock-spec-builders_test.cc | 4 +++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index f5e28ea..ed83fad 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -327,11 +327,8 @@ TEST(InvokeTest, FunctionThatTakes10Arguments) { // Tests using Invoke() with functions with parameters declared as Unused. TEST(InvokeTest, FunctionWithUnusedParameters) { - Action a1 = - Invoke(SumOfFirst2); - string s("hi"); - EXPECT_EQ(12, a1.Perform( - tuple(10, 2, 5.6, s))); + Action a1 = Invoke(SumOfFirst2); + EXPECT_EQ(12, a1.Perform(make_tuple(10, 2, 5.6, std::string("hi")))); Action a2 = Invoke(SumOfFirst2); @@ -380,10 +377,9 @@ TEST(InvokeMethodTest, Unary) { // Tests using Invoke() with a binary method. TEST(InvokeMethodTest, Binary) { Foo foo; - Action a = Invoke(&foo, &Foo::Binary); - string s("Hell"); - EXPECT_EQ("Hello", a.Perform( - tuple(s, 'o'))); + Action a = Invoke(&foo, &Foo::Binary); + std::string s("Hell"); + EXPECT_EQ("Hello", a.Perform(make_tuple(s, 'o'))); } // Tests using Invoke() with a ternary method. diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index 6001582..f1d571b 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -2173,7 +2173,9 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture { "NOTE: You can safely ignore the above warning unless this " "call should not happen. Do not suppress it by blindly adding " "an EXPECT_CALL() if you don't mean to enforce the call. " - "See https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#" + "See " + "https://github.com/google/googletest/blob/master/googlemock/docs/" + "CookBook.md#" "knowing-when-to-expect for details."; // A void-returning function. -- cgit v0.12 From dc4f5638c2d0365ae464bff03ce297955e5393a9 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 15:45:21 -0400 Subject: merging, fix OSX issue --- googlemock/test/gmock-internal-utils_test.cc | 1 - googlemock/test/gmock-more-actions_test.cc | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index f8633df..6c898cd 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -36,7 +36,6 @@ #include "gmock/internal/gmock-internal-utils.h" #include #include -#include #include #include #include diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index ed83fad..7145a04 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -379,7 +379,8 @@ TEST(InvokeMethodTest, Binary) { Foo foo; Action a = Invoke(&foo, &Foo::Binary); std::string s("Hell"); - EXPECT_EQ("Hello", a.Perform(make_tuple(s, 'o'))); + tuple dummy = make_tuple(s, 'o'); + EXPECT_EQ("Hello", a.Perform(dummy)); } // Tests using Invoke() with a ternary method. -- cgit v0.12 From 65380492b2b43fe3f6ddb7e85a1a01b833f0c6da Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 16:32:03 -0400 Subject: fixing --- googlemock/test/gmock-internal-utils_test.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index 6c898cd..f8633df 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -36,6 +36,7 @@ #include "gmock/internal/gmock-internal-utils.h" #include #include +#include #include #include #include -- cgit v0.12 From f7330f9f14e8860bbec0620eb1d06f9c812cf561 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 17:00:31 -0400 Subject: more fixing osx libstd++ bugs --- googlemock/test/gmock-more-actions_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index 7145a04..911d034 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -328,7 +328,8 @@ TEST(InvokeTest, FunctionThatTakes10Arguments) { // Tests using Invoke() with functions with parameters declared as Unused. TEST(InvokeTest, FunctionWithUnusedParameters) { Action a1 = Invoke(SumOfFirst2); - EXPECT_EQ(12, a1.Perform(make_tuple(10, 2, 5.6, std::string("hi")))); + tuple dummy = make_tuple(10, 2, 5.6, std::string("hi")); + EXPECT_EQ(12, a1.Perform(dummy)); Action a2 = Invoke(SumOfFirst2); -- cgit v0.12 From 2dc576ec55aede9e8a5df571cf60d42de5a48105 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 13 Apr 2018 09:16:40 -0400 Subject: merging --- .../test/gmock-generated-internal-utils_test.cc | 20 +++++++++++--------- googlemock/test/gmock-more-actions_test.cc | 3 ++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/googlemock/test/gmock-generated-internal-utils_test.cc b/googlemock/test/gmock-generated-internal-utils_test.cc index e0a535a..2e5abe5 100644 --- a/googlemock/test/gmock-generated-internal-utils_test.cc +++ b/googlemock/test/gmock-generated-internal-utils_test.cc @@ -63,10 +63,10 @@ TEST(MatcherTupleTest, ForSize2) { } TEST(MatcherTupleTest, ForSize5) { - CompileAssertTypesEqual, Matcher, Matcher, - Matcher, Matcher >, - MatcherTuple - >::type>(); + CompileAssertTypesEqual< + tuple, Matcher, Matcher, Matcher, + Matcher >, + MatcherTuple >::type>(); } // Tests the Function template struct. @@ -97,8 +97,9 @@ TEST(FunctionTest, Binary) { CompileAssertTypesEqual(); CompileAssertTypesEqual(); // NOLINT CompileAssertTypesEqual, F::ArgumentTuple>(); // NOLINT - CompileAssertTypesEqual, Matcher >, // NOLINT - F::ArgumentMatcherTuple>(); + CompileAssertTypesEqual< + tuple, Matcher >, // NOLINT + F::ArgumentMatcherTuple>(); CompileAssertTypesEqual(); // NOLINT CompileAssertTypesEqual(); @@ -114,9 +115,10 @@ TEST(FunctionTest, LongArgumentList) { CompileAssertTypesEqual(); // NOLINT CompileAssertTypesEqual, // NOLINT F::ArgumentTuple>(); - CompileAssertTypesEqual, Matcher, Matcher, - Matcher, Matcher >, // NOLINT - F::ArgumentMatcherTuple>(); + CompileAssertTypesEqual< + tuple, Matcher, Matcher, Matcher, + Matcher >, // NOLINT + F::ArgumentMatcherTuple>(); CompileAssertTypesEqual(); CompileAssertTypesEqual< diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index 911d034..b13518a 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -328,7 +328,8 @@ TEST(InvokeTest, FunctionThatTakes10Arguments) { // Tests using Invoke() with functions with parameters declared as Unused. TEST(InvokeTest, FunctionWithUnusedParameters) { Action a1 = Invoke(SumOfFirst2); - tuple dummy = make_tuple(10, 2, 5.6, std::string("hi")); + tuple dummy = + make_tuple(10, 2, 5.6, std::string("hi")); EXPECT_EQ(12, a1.Perform(dummy)); Action a2 = -- cgit v0.12 From 0bfa8237855a2a56ae676fd703a8c2147771680d Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 13 Apr 2018 11:02:25 -0400 Subject: merging, gmock actions test --- googlemock/test/gmock-actions_test.cc | 143 +++++++++++++++++++++++++++++++++- 1 file changed, 142 insertions(+), 1 deletion(-) diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 2cbf0ee..da7cc0d 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -714,6 +714,8 @@ class MockClass { MOCK_METHOD0(MakeUniqueBase, std::unique_ptr()); MOCK_METHOD0(MakeVectorUnique, std::vector>()); MOCK_METHOD1(TakeUnique, int(std::unique_ptr)); + MOCK_METHOD2(TakeUnique, + int(const std::unique_ptr&, std::unique_ptr)); #endif private: @@ -765,7 +767,7 @@ TEST(DoDefaultDeathTest, DiesIfUsedInCompositeAction) { } // Tests that DoDefault() returns the default value set by -// DefaultValue::Set() when it's not overridden by an ON_CALL(). +// DefaultValue::Set() when it's not overriden by an ON_CALL(). TEST(DoDefaultTest, ReturnsUserSpecifiedPerTypeDefaultValueWhenThereIsOne) { DefaultValue::Set(1); MockClass mock; @@ -1420,8 +1422,147 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) { EXPECT_EQ(7, *vresult[0]); } +TEST(MockMethodTest, CanTakeMoveOnlyValue) { + MockClass mock; + auto make = [](int i) { return std::unique_ptr(new int(i)); }; + + EXPECT_CALL(mock, TakeUnique(_)).WillRepeatedly([](std::unique_ptr i) { + return *i; + }); + // DoAll() does not compile, since it would move from its arguments twice. + // EXPECT_CALL(mock, TakeUnique(_, _)) + // .WillRepeatedly(DoAll(Invoke([](std::unique_ptr j) {}), + // Return(1))); + EXPECT_CALL(mock, TakeUnique(testing::Pointee(7))) + .WillOnce(Return(-7)) + .RetiresOnSaturation(); + EXPECT_CALL(mock, TakeUnique(testing::IsNull())) + .WillOnce(Return(-1)) + .RetiresOnSaturation(); + + EXPECT_EQ(5, mock.TakeUnique(make(5))); + EXPECT_EQ(-7, mock.TakeUnique(make(7))); + EXPECT_EQ(7, mock.TakeUnique(make(7))); + EXPECT_EQ(7, mock.TakeUnique(make(7))); + EXPECT_EQ(-1, mock.TakeUnique({})); + + // Some arguments are moved, some passed by reference. + auto lvalue = make(6); + EXPECT_CALL(mock, TakeUnique(_, _)) + .WillOnce([](const std::unique_ptr& i, std::unique_ptr j) { + return *i * *j; + }); + EXPECT_EQ(42, mock.TakeUnique(lvalue, make(7))); + + // The unique_ptr can be saved by the action. + std::unique_ptr saved; + EXPECT_CALL(mock, TakeUnique(_)).WillOnce([&saved](std::unique_ptr i) { + saved = std::move(i); + return 0; + }); + EXPECT_EQ(0, mock.TakeUnique(make(42))); + EXPECT_EQ(42, *saved); +} + #endif // GTEST_HAS_STD_UNIQUE_PTR_ +#if GTEST_LANG_CXX11 +// Tests for std::function based action. + +int Add(int val, int& ref, int* ptr) { // NOLINT + int result = val + ref + *ptr; + ref = 42; + *ptr = 43; + return result; +} + +int Deref(std::unique_ptr ptr) { return *ptr; } + +struct Double { + template + T operator()(T t) { return 2 * t; } +}; + +std::unique_ptr UniqueInt(int i) { + return std::unique_ptr(new int(i)); +} + +TEST(FunctorActionTest, ActionFromFunction) { + Action a = &Add; + int x = 1, y = 2, z = 3; + EXPECT_EQ(6, a.Perform(std::forward_as_tuple(x, y, &z))); + EXPECT_EQ(42, y); + EXPECT_EQ(43, z); + + Action)> a1 = &Deref; + EXPECT_EQ(7, a1.Perform(std::make_tuple(UniqueInt(7)))); +} + +TEST(FunctorActionTest, ActionFromLambda) { + Action a1 = [](bool b, int i) { return b ? i : 0; }; + EXPECT_EQ(5, a1.Perform(make_tuple(true, 5))); + EXPECT_EQ(0, a1.Perform(make_tuple(false, 5))); + + std::unique_ptr saved; + Action)> a2 = [&saved](std::unique_ptr p) { + saved = std::move(p); + }; + a2.Perform(make_tuple(UniqueInt(5))); + EXPECT_EQ(5, *saved); +} + +TEST(FunctorActionTest, PolymorphicFunctor) { + Action ai = Double(); + EXPECT_EQ(2, ai.Perform(make_tuple(1))); + Action ad = Double(); // Double? Double double! + EXPECT_EQ(3.0, ad.Perform(make_tuple(1.5))); +} + +TEST(FunctorActionTest, TypeConversion) { + // Numeric promotions are allowed. + const Action a1 = [](int i) { return i > 1; }; + const Action a2 = Action(a1); + EXPECT_EQ(1, a1.Perform(make_tuple(42))); + EXPECT_EQ(0, a2.Perform(make_tuple(42))); + + // Implicit constructors are allowed. + const Action s1 = [](std::string s) { return !s.empty(); }; + const Action s2 = Action(s1); + EXPECT_EQ(0, s2.Perform(make_tuple(""))); + EXPECT_EQ(1, s2.Perform(make_tuple("hello"))); + + // Also between the lambda and the action itself. + const Action x = [](Unused) { return 42; }; + EXPECT_TRUE(x.Perform(make_tuple("hello"))); +} + +TEST(FunctorActionTest, UnusedArguments) { + // Verify that users can ignore uninteresting arguments. + Action, const int&)> a = + [](int i, Unused, Unused) { return 2 * i; }; + EXPECT_EQ(6, a.Perform(make_tuple(3, UniqueInt(7), 9))); +} + +// Test that basic built-in actions work with move-only arguments. +// TODO(rburny): Currently, almost all ActionInterface-based actions will not +// work, even if they only try to use other, copyable arguments. Implement them +// if necessary (but note that DoAll cannot work on non-copyable types anyway - +// so maybe it's better to make users use lambdas instead. +TEST(MoveOnlyArgumentsTest, ReturningActions) { + Action)> a = Return(1); + EXPECT_EQ(1, a.Perform(make_tuple(nullptr))); + + a = testing::WithoutArgs([]() { return 7; }); + EXPECT_EQ(7, a.Perform(make_tuple(nullptr))); + + Action, int*)> a2 = testing::SetArgPointee<1>(3); + int x = 0; + a2.Perform(make_tuple(nullptr, &x)); + EXPECT_EQ(x, 3); +} + +#endif // GTEST_LANG_CXX11 + } // Unnamed namespace #ifdef _MSC_VER -- cgit v0.12 From f9bd6180debc46d59fa0ddd0e08bb361e3ca18bc Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 13 Apr 2018 11:02:55 -0400 Subject: merging gmock actions test --- googlemock/test/gmock-actions_test.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index da7cc0d..5dd4846 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -74,6 +74,7 @@ using testing::ReturnRef; using testing::ReturnRefOfCopy; using testing::SetArgPointee; using testing::SetArgumentPointee; +using testing::Unused; using testing::_; using testing::get; using testing::internal::BuiltInDefaultValue; -- cgit v0.12 From b74a1af00f17cd52c426c08e0d1a1b4ea93f78dd Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 13 Apr 2018 11:49:37 -0400 Subject: osx pizzas --- googlemock/test/gmock-actions_test.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 5dd4846..c8b62fc 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -1539,9 +1539,10 @@ TEST(FunctorActionTest, TypeConversion) { TEST(FunctorActionTest, UnusedArguments) { // Verify that users can ignore uninteresting arguments. - Action, const int&)> a = + Action a = [](int i, Unused, Unused) { return 2 * i; }; - EXPECT_EQ(6, a.Perform(make_tuple(3, UniqueInt(7), 9))); + tuple dummy = make_tuple(3, 7.3, 9); + EXPECT_EQ(6, a.Perform(dummy)); } // Test that basic built-in actions work with move-only arguments. -- cgit v0.12 From f45728a5ac69bcbc5c713938ee63591df40e35bb Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 13 Apr 2018 15:48:57 -0400 Subject: more OSX pizzas --- googlemock/test/gmock-actions_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index c8b62fc..646a10c 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -1541,7 +1541,8 @@ TEST(FunctorActionTest, UnusedArguments) { // Verify that users can ignore uninteresting arguments. Action a = [](int i, Unused, Unused) { return 2 * i; }; - tuple dummy = make_tuple(3, 7.3, 9); + int nine = 9; + tuple dummy = make_tuple(3, 7.3, nine); EXPECT_EQ(6, a.Perform(dummy)); } -- cgit v0.12 From d84eb86df5d129f39064e2f3349699e84faf8493 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 13 Apr 2018 16:04:34 -0400 Subject: more pizza --- googlemock/test/gmock-actions_test.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 646a10c..08f2a55 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -1539,10 +1539,9 @@ TEST(FunctorActionTest, TypeConversion) { TEST(FunctorActionTest, UnusedArguments) { // Verify that users can ignore uninteresting arguments. - Action a = + Action a = [](int i, Unused, Unused) { return 2 * i; }; - int nine = 9; - tuple dummy = make_tuple(3, 7.3, nine); + tuple dummy = make_tuple(3, 7.3, 9); EXPECT_EQ(6, a.Perform(dummy)); } -- cgit v0.12 From 26c10dc7e6505b5880c6d3bd87e033864ce23eab Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 10:16:48 -0400 Subject: merging --- googlemock/test/gmock-actions_test.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 08f2a55..646a10c 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -1539,9 +1539,10 @@ TEST(FunctorActionTest, TypeConversion) { TEST(FunctorActionTest, UnusedArguments) { // Verify that users can ignore uninteresting arguments. - Action a = + Action a = [](int i, Unused, Unused) { return 2 * i; }; - tuple dummy = make_tuple(3, 7.3, 9); + int nine = 9; + tuple dummy = make_tuple(3, 7.3, nine); EXPECT_EQ(6, a.Perform(dummy)); } -- cgit v0.12 From 1c6e68cf6cdd800a8183b54a3dd1a22e5932f1c6 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 10:34:07 -0400 Subject: merging --- googlemock/test/gmock-actions_test.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 646a10c..e391428 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -1539,10 +1539,9 @@ TEST(FunctorActionTest, TypeConversion) { TEST(FunctorActionTest, UnusedArguments) { // Verify that users can ignore uninteresting arguments. - Action a = + Action a = [](int i, Unused, Unused) { return 2 * i; }; - int nine = 9; - tuple dummy = make_tuple(3, 7.3, nine); + tuple dummy = make_tuple(3, 7.3, 9.44); EXPECT_EQ(6, a.Perform(dummy)); } -- cgit v0.12 From 9fba10315628d4e93d2975ae9c9a214b9665cc59 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 10:42:08 -0400 Subject: merging, testing, this should be it --- googlemock/test/gmock-actions_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index e391428..7fbb50d 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -1541,7 +1541,7 @@ TEST(FunctorActionTest, UnusedArguments) { // Verify that users can ignore uninteresting arguments. Action a = [](int i, Unused, Unused) { return 2 * i; }; - tuple dummy = make_tuple(3, 7.3, 9.44); + tuple dummy = make_tuple(3, 7.3, 9.44); EXPECT_EQ(6, a.Perform(dummy)); } -- cgit v0.12 From bd2a1aed03c8319f43ee01ed675d2a2365aac7c5 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 11:18:49 -0400 Subject: merging gmock generated matchers --- .../include/gmock/gmock-generated-matchers.h | 601 ++++++++++++--------- .../include/gmock/gmock-generated-matchers.h.pump | 30 +- googlemock/test/gmock-generated-matchers_test.cc | 51 +- 3 files changed, 414 insertions(+), 268 deletions(-) diff --git a/googlemock/include/gmock/gmock-generated-matchers.h b/googlemock/include/gmock/gmock-generated-matchers.h index 1655bcd..169ea57 100644 --- a/googlemock/include/gmock/gmock-generated-matchers.h +++ b/googlemock/include/gmock/gmock-generated-matchers.h @@ -779,6 +779,9 @@ ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, // UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension // that matches n elements in any order. We support up to n=10 arguments. +// +// If you have >10 elements, consider UnorderedElementsAreArray() or +// UnorderedPointwise() instead. inline internal::UnorderedElementsAreMatcher< ::testing::tuple<> > @@ -994,6 +997,40 @@ UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, e6, e7, e8, e9, e10)); } +template +inline internal::UnorderedElementsAreMatcher< + ::testing::tuple::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> > +UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, + const T5& e5, const T6& e6, const T7& e7, const T8& e8, + const T9& e9, const T10& e10, const T11& e11) { + typedef ::testing::tuple::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type, + typename internal::DecayArray::type> + Args; + return internal::UnorderedElementsAreMatcher( + Args(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11)); +} + // AllOf(m1, m2, ..., mk) matches any value that matches all of the given // sub-matchers. AllOf is called fully qualified to prevent ADL from firing. @@ -1268,7 +1305,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { // using testing::PrintToString; // // MATCHER_P2(InClosedRange, low, hi, -// string(negation ? "is not" : "is") + " in range [" + +// std::string(negation ? "is not" : "is") + " in range [" + // PrintToString(low) + ", " + PrintToString(hi) + "]") { // return low <= arg && arg <= hi; // } @@ -1383,12 +1420,14 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##Matcher {\ public:\ template \ - class gmock_Impl : public ::testing::MatcherInterface {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ gmock_Impl()\ {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ @@ -1396,17 +1435,15 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { *gmock_os << FormatDescription(true);\ }\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ - if (!gmock_description.empty()) {\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ + if (!gmock_description.empty())\ return gmock_description;\ - }\ return ::testing::internal::FormatMatcherDescription(\ negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::tuple<>()));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ @@ -1416,14 +1453,13 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { name##Matcher() {\ }\ private:\ - GTEST_DISALLOW_ASSIGN_(name##Matcher);\ };\ inline name##Matcher name() {\ return name##Matcher();\ }\ template \ bool name##Matcher::gmock_Impl::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1432,42 +1468,42 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP {\ public:\ template \ - class gmock_Impl : public ::testing::MatcherInterface {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ explicit gmock_Impl(p0##_type gmock_p0)\ - : p0(gmock_p0) {}\ + : p0(::testing::internal::move(gmock_p0)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - p0##_type p0;\ + p0##_type const p0;\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ - if (!gmock_description.empty()) {\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ + if (!gmock_description.empty())\ return gmock_description;\ - }\ return ::testing::internal::FormatMatcherDescription(\ negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::tuple(p0)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ return ::testing::Matcher(\ new gmock_Impl(p0));\ }\ - explicit name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\ + explicit name##MatcherP(p0##_type gmock_p0) : \ + p0(::testing::internal::move(gmock_p0)) {\ }\ - p0##_type p0;\ + p0##_type const p0;\ private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP);\ };\ template \ inline name##MatcherP name(p0##_type p0) {\ @@ -1476,7 +1512,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { template \ template \ bool name##MatcherP::gmock_Impl::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1485,45 +1521,46 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP2 {\ public:\ template \ - class gmock_Impl : public ::testing::MatcherInterface {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\ - : p0(gmock_p0), p1(gmock_p1) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - p0##_type p0;\ - p1##_type p1;\ + p0##_type const p0;\ + p1##_type const p1;\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ - if (!gmock_description.empty()) {\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ + if (!gmock_description.empty())\ return gmock_description;\ - }\ return ::testing::internal::FormatMatcherDescription(\ negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::tuple(p0, p1)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ return ::testing::Matcher(\ new gmock_Impl(p0, p1));\ }\ - name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ - p1(gmock_p1) {\ + name##MatcherP2(p0##_type gmock_p0, \ + p1##_type gmock_p1) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)) {\ }\ - p0##_type p0;\ - p1##_type p1;\ + p0##_type const p0;\ + p1##_type const p1;\ private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP2);\ };\ template \ inline name##MatcherP2 name(p0##_type p0, \ @@ -1534,7 +1571,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { template \ bool name##MatcherP2::gmock_Impl::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1543,34 +1580,36 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP3 {\ public:\ template \ - class gmock_Impl : public ::testing::MatcherInterface {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\ - : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ - if (!gmock_description.empty()) {\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ + if (!gmock_description.empty())\ return gmock_description;\ - }\ return ::testing::internal::FormatMatcherDescription(\ negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::tuple(p0, p1, \ p2)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ @@ -1578,13 +1617,14 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { new gmock_Impl(p0, p1, p2));\ }\ name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\ + p2##_type gmock_p2) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)) {\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP3);\ };\ template \ inline name##MatcherP3 name(p0##_type p0, \ @@ -1595,7 +1635,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { template \ bool name##MatcherP3::gmock_Impl::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1605,36 +1645,39 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP4 {\ public:\ template \ - class gmock_Impl : public ::testing::MatcherInterface {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ p3##_type gmock_p3)\ - : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ - if (!gmock_description.empty()) {\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ + if (!gmock_description.empty())\ return gmock_description;\ - }\ return ::testing::internal::FormatMatcherDescription(\ negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::tuple(p0, p1, p2, p3)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ @@ -1642,15 +1685,17 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { 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(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3) {\ + p2##_type gmock_p2, \ + p3##_type gmock_p3) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)) {\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP4);\ };\ template \ @@ -1665,7 +1710,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { template \ bool name##MatcherP4::gmock_Impl::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1675,38 +1720,41 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP5 {\ public:\ template \ - class gmock_Impl : public ::testing::MatcherInterface {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ p3##_type gmock_p3, p4##_type gmock_p4)\ - : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ + p4##_type const p4;\ private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ - if (!gmock_description.empty()) {\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ + if (!gmock_description.empty())\ return gmock_description;\ - }\ return ::testing::internal::FormatMatcherDescription(\ negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::tuple(p0, p1, p2, p3, p4)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ @@ -1715,16 +1763,18 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { }\ name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \ p2##_type gmock_p2, p3##_type gmock_p3, \ - p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4) {\ + p4##_type gmock_p4) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)) {\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ + p0##_type const p0;\ + p1##_type const p1;\ + p2##_type const p2;\ + p3##_type const p3;\ + p4##_type const p4;\ private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP5);\ };\ template \ @@ -1739,7 +1789,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { template \ bool name##MatcherP5::gmock_Impl::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1749,39 +1799,43 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP6 {\ public:\ template \ - class gmock_Impl : public ::testing::MatcherInterface {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ 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(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4), p5(gmock_p5) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type 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:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ - if (!gmock_description.empty()) {\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ + if (!gmock_description.empty())\ return gmock_description;\ - }\ return ::testing::internal::FormatMatcherDescription(\ negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::tuple(p0, p1, p2, p3, p4, p5)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ @@ -1790,17 +1844,20 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { }\ 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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\ + p5##_type gmock_p5) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)) {\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type 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:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP6);\ };\ template \ @@ -1815,7 +1872,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { template \ bool name##MatcherP6::gmock_Impl::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1826,34 +1883,40 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP7 {\ public:\ template \ - class gmock_Impl : public ::testing::MatcherInterface {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ 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(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type 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:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ - if (!gmock_description.empty()) {\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ + if (!gmock_description.empty())\ return gmock_description;\ - }\ return ::testing::internal::FormatMatcherDescription(\ negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ @@ -1861,7 +1924,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, \ p6)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ @@ -1870,19 +1932,23 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { }\ 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(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \ - p6(gmock_p6) {\ + p5##_type gmock_p5, \ + p6##_type gmock_p6) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)) {\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type 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:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP7);\ };\ template \ bool name##MatcherP7::gmock_Impl::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -1911,35 +1977,42 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP8 {\ public:\ template \ - class gmock_Impl : public ::testing::MatcherInterface {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ 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(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type 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:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ - if (!gmock_description.empty()) {\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ + if (!gmock_description.empty())\ return gmock_description;\ - }\ return ::testing::internal::FormatMatcherDescription(\ negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ @@ -1947,7 +2020,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \ p3, p4, p5, p6, p7)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ @@ -1957,20 +2029,24 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { 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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ - p7(gmock_p7) {\ + p7##_type gmock_p7) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)) {\ }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type 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:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP8);\ };\ template ::gmock_Impl::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -2001,37 +2077,44 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP9 {\ public:\ template \ - class gmock_Impl : public ::testing::MatcherInterface {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ 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(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ - p8(gmock_p8) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)), \ + p8(::testing::internal::move(gmock_p8)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - 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;\ + 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:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ - if (!gmock_description.empty()) {\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ + if (!gmock_description.empty())\ return gmock_description;\ - }\ return ::testing::internal::FormatMatcherDescription(\ negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ @@ -2039,7 +2122,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { p4##_type, p5##_type, p6##_type, p7##_type, \ p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ @@ -2049,21 +2131,26 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { 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(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ - p8(gmock_p8) {\ + p8##_type gmock_p8) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)), \ + p8(::testing::internal::move(gmock_p8)) {\ }\ - 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;\ + 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:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP9);\ };\ template ::gmock_Impl::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const @@ -2096,39 +2183,47 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { class name##MatcherP10 {\ public:\ template \ - class gmock_Impl : public ::testing::MatcherInterface {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ 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(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ - p8(gmock_p8), p9(gmock_p9) {}\ + : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)), \ + p8(::testing::internal::move(gmock_p8)), \ + p9(::testing::internal::move(gmock_p9)) {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(true);\ }\ - 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;\ + 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:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ - if (!gmock_description.empty()) {\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ + if (!gmock_description.empty())\ return gmock_description;\ - }\ return ::testing::internal::FormatMatcherDescription(\ negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ @@ -2136,7 +2231,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \ p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ @@ -2146,22 +2240,29 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) { 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(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ - p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\ + p8##_type gmock_p8, \ + p9##_type gmock_p9) : p0(::testing::internal::move(gmock_p0)), \ + p1(::testing::internal::move(gmock_p1)), \ + p2(::testing::internal::move(gmock_p2)), \ + p3(::testing::internal::move(gmock_p3)), \ + p4(::testing::internal::move(gmock_p4)), \ + p5(::testing::internal::move(gmock_p5)), \ + p6(::testing::internal::move(gmock_p6)), \ + p7(::testing::internal::move(gmock_p7)), \ + p8(::testing::internal::move(gmock_p8)), \ + p9(::testing::internal::move(gmock_p9)) {\ }\ - 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;\ + 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:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP10);\ };\ template ::gmock_Impl::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const diff --git a/googlemock/include/gmock/gmock-generated-matchers.h.pump b/googlemock/include/gmock/gmock-generated-matchers.h.pump index 4fe0a61..4b62844 100644 --- a/googlemock/include/gmock/gmock-generated-matchers.h.pump +++ b/googlemock/include/gmock/gmock-generated-matchers.h.pump @@ -303,6 +303,9 @@ $for j, [[ // UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension // that matches n elements in any order. We support up to n=$n arguments. +// +// If you have >$n elements, consider UnorderedElementsAreArray() or +// UnorderedPointwise() instead. $range i 0..n $for i [[ @@ -479,7 +482,7 @@ $$ // show up in the generated code. // using testing::PrintToString; // // MATCHER_P2(InClosedRange, low, hi, -// string(negation ? "is not" : "is") + " in range [" + +// std::string(negation ? "is not" : "is") + " in range [" + // PrintToString(low) + ", " + PrintToString(hi) + "]") { // return low <= arg && arg <= hi; // } @@ -604,32 +607,34 @@ $var template = [[$if i==0 [[]] $else [[ ]]]] $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(gmock_p$j)]]]]]] -$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]] +$var impl_inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::move(gmock_p$j))]]]]]] +$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::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]]]] $var param_field_decls = [[$for j [[ - p$j##_type p$j;\ + p$j##_type const p$j;\ ]]]] $var param_field_decls2 = [[$for j [[ - p$j##_type p$j;\ + p$j##_type const p$j;\ ]]]] #define $macro_name(name$for j [[, p$j]], description)\$template class $class_name {\ public:\ template \ - class gmock_Impl : public ::testing::MatcherInterface {\ + class gmock_Impl : public ::testing::MatcherInterface<\ + GTEST_REFERENCE_TO_CONST_(arg_type)> {\ public:\ [[$if i==1 [[explicit ]]]]gmock_Impl($impl_ctor_param_list)\ $impl_inits {}\ virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ + ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ *gmock_os << FormatDescription(false);\ }\ @@ -637,17 +642,15 @@ $var param_field_decls2 = [[$for j *gmock_os << FormatDescription(true);\ }\$param_field_decls private:\ - ::testing::internal::string FormatDescription(bool negation) const {\ - const ::testing::internal::string gmock_description = (description);\ - if (!gmock_description.empty()) {\ + ::std::string FormatDescription(bool negation) const {\ + ::std::string gmock_description = (description);\ + if (!gmock_description.empty())\ return gmock_description;\ - }\ return ::testing::internal::FormatMatcherDescription(\ negation, #name, \ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]])));\ }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ @@ -657,14 +660,13 @@ $var param_field_decls2 = [[$for j [[$if i==1 [[explicit ]]]]$class_name($ctor_param_list)$inits {\ }\$param_field_decls2 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 \ bool $class_name$param_types::gmock_Impl::MatchAndExplain(\ - arg_type arg, \ + GTEST_REFERENCE_TO_CONST_(arg_type) arg,\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ const ]] diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc index 6cba726..f24d7c8 100644 --- a/googlemock/test/gmock-generated-matchers_test.cc +++ b/googlemock/test/gmock-generated-matchers_test.cc @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -57,6 +58,8 @@ using testing::get; using testing::make_tuple; using testing::tuple; using testing::_; +using testing::AllOf; +using testing::AnyOf; using testing::Args; using testing::Contains; using testing::ElementsAre; @@ -120,7 +123,7 @@ TEST(ArgsTest, AcceptsOneTemplateArg) { } TEST(ArgsTest, AcceptsTwoTemplateArgs) { - const tuple t(static_cast(4), 5, 6L); // NOLINT + const tuple t(4, 5, 6L); // NOLINT EXPECT_THAT(t, (Args<0, 1>(Lt()))); EXPECT_THAT(t, (Args<1, 2>(Lt()))); @@ -128,13 +131,13 @@ TEST(ArgsTest, AcceptsTwoTemplateArgs) { } TEST(ArgsTest, AcceptsRepeatedTemplateArgs) { - const tuple t(static_cast(4), 5, 6L); // NOLINT + const tuple t(4, 5, 6L); // NOLINT EXPECT_THAT(t, (Args<0, 0>(Eq()))); EXPECT_THAT(t, Not(Args<1, 1>(Ne()))); } TEST(ArgsTest, AcceptsDecreasingTemplateArgs) { - const tuple t(static_cast(4), 5, 6L); // NOLINT + const tuple t(4, 5, 6L); // NOLINT EXPECT_THAT(t, (Args<2, 0>(Gt()))); EXPECT_THAT(t, Not(Args<2, 1>(Lt()))); } @@ -159,7 +162,7 @@ TEST(ArgsTest, AcceptsMoreTemplateArgsThanArityOfOriginalTuple) { } TEST(ArgsTest, CanBeNested) { - const tuple t(static_cast(4), 5, 6L, 6); // NOLINT + const tuple t(4, 5, 6L, 6); // NOLINT EXPECT_THAT(t, (Args<1, 2, 3>(Args<1, 2>(Eq())))); EXPECT_THAT(t, (Args<0, 1, 3>(Args<0, 2>(Lt())))); } @@ -1283,4 +1286,44 @@ TEST(AnyOfTest, DoesNotCallAnyOfUnqualified) { # pragma warning(pop) #endif +#if GTEST_LANG_CXX11 + +TEST(AllOfTest, WorksOnMoveOnlyType) { + std::unique_ptr p(new int(3)); + EXPECT_THAT(p, AllOf(Pointee(Eq(3)), Pointee(Gt(0)), Pointee(Lt(5)))); + EXPECT_THAT(p, Not(AllOf(Pointee(Eq(3)), Pointee(Gt(0)), Pointee(Lt(3))))); +} + +TEST(AnyOfTest, WorksOnMoveOnlyType) { + std::unique_ptr p(new int(3)); + EXPECT_THAT(p, AnyOf(Pointee(Eq(5)), Pointee(Lt(0)), Pointee(Lt(5)))); + EXPECT_THAT(p, Not(AnyOf(Pointee(Eq(5)), Pointee(Lt(0)), Pointee(Gt(5))))); +} + +MATCHER(IsNotNull, "") { + return arg != nullptr; +} + +// Verifies that a matcher defined using MATCHER() can work on +// move-only types. +TEST(MatcherMacroTest, WorksOnMoveOnlyType) { + std::unique_ptr p(new int(3)); + EXPECT_THAT(p, IsNotNull()); + EXPECT_THAT(std::unique_ptr(), Not(IsNotNull())); +} + +MATCHER_P(UniquePointee, pointee, "") { + return *arg == pointee; +} + +// Verifies that a matcher defined using MATCHER_P*() can work on +// move-only types. +TEST(MatcherPMacroTest, WorksOnMoveOnlyType) { + std::unique_ptr p(new int(3)); + EXPECT_THAT(p, UniquePointee(3)); + EXPECT_THAT(p, Not(UniquePointee(2))); +} + +#endif // GTEST_LASNG_CXX11 + } // namespace -- cgit v0.12 From e9eff488f9a41e95773d2c361294a0ffee5bbe65 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 11:32:16 -0400 Subject: msvc warnings --- googlemock/test/gmock-generated-matchers_test.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc index f24d7c8..9190522 100644 --- a/googlemock/test/gmock-generated-matchers_test.cc +++ b/googlemock/test/gmock-generated-matchers_test.cc @@ -31,6 +31,13 @@ // // This file tests the built-in matchers generated by a script. +// Silence warning C4244: 'initializing': conversion from 'int' to 'short', +// possible loss of data +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:C4244) +#endif + #include "gmock/gmock-generated-matchers.h" #include @@ -1327,3 +1334,7 @@ TEST(MatcherPMacroTest, WorksOnMoveOnlyType) { #endif // GTEST_LASNG_CXX11 } // namespace + +#ifdef _MSC_VER +# pragma warning(pop) +#endif -- cgit v0.12 From 1944bc0f510fa631b8d35075b4ff95c3efeacf39 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 11:41:36 -0400 Subject: typo --- googlemock/test/gmock-generated-matchers_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc index 9190522..8510855 100644 --- a/googlemock/test/gmock-generated-matchers_test.cc +++ b/googlemock/test/gmock-generated-matchers_test.cc @@ -35,7 +35,7 @@ // possible loss of data #ifdef _MSC_VER # pragma warning(push) -# pragma warning(disable:C4244) +# pragma warning(disable:4244) #endif #include "gmock/gmock-generated-matchers.h" -- cgit v0.12 From e4ab316c85c172de3717bebd68fcb1d4eb420ccf Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 11:52:22 -0400 Subject: more msvc --- googlemock/test/gmock-generated-matchers_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc index 8510855..bc9df72 100644 --- a/googlemock/test/gmock-generated-matchers_test.cc +++ b/googlemock/test/gmock-generated-matchers_test.cc @@ -32,10 +32,11 @@ // This file tests the built-in matchers generated by a script. // Silence warning C4244: 'initializing': conversion from 'int' to 'short', -// possible loss of data +// possible loss of data C4100: : unreferenced formal parameter #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable:4244) +# pragma warning(disable:4100) #endif #include "gmock/gmock-generated-matchers.h" -- cgit v0.12 From ec425d71601ddf5ee6272f22c670fe6f959afbf4 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 12:00:37 -0400 Subject: typo --- googlemock/test/gmock-generated-matchers_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc index bc9df72..0ebd470 100644 --- a/googlemock/test/gmock-generated-matchers_test.cc +++ b/googlemock/test/gmock-generated-matchers_test.cc @@ -32,7 +32,7 @@ // This file tests the built-in matchers generated by a script. // Silence warning C4244: 'initializing': conversion from 'int' to 'short', -// possible loss of data C4100: : unreferenced formal parameter +// possible loss of data and C4100, unreferenced local parameter #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable:4244) -- cgit v0.12 From 3f88bb1831e48029e52fefcf654bfab5cf3a952c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 15:52:47 -0400 Subject: test-meerging --- .../include/gmock/gmock-generated-matchers.h | 34 ---------------------- googlemock/include/gmock/gmock-matchers.h | 6 ++++ 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/googlemock/include/gmock/gmock-generated-matchers.h b/googlemock/include/gmock/gmock-generated-matchers.h index 169ea57..21af61b 100644 --- a/googlemock/include/gmock/gmock-generated-matchers.h +++ b/googlemock/include/gmock/gmock-generated-matchers.h @@ -997,40 +997,6 @@ UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, e6, e7, e8, e9, e10)); } -template -inline internal::UnorderedElementsAreMatcher< - ::testing::tuple::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type> > -UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, - const T5& e5, const T6& e6, const T7& e7, const T8& e8, - const T9& e9, const T10& e10, const T11& e11) { - typedef ::testing::tuple::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type, - typename internal::DecayArray::type> - Args; - return internal::UnorderedElementsAreMatcher( - Args(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11)); -} - // AllOf(m1, m2, ..., mk) matches any value that matches all of the given // sub-matchers. AllOf is called fully qualified to prevent ADL from firing. diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index fcb45ac..62e9233 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -5211,6 +5211,12 @@ inline internal::AnyOfMatcher AnyOf(const Args&... matchers) { return internal::AnyOfMatcher(matchers...); } +template +inline internal::UnorderedElementsAreMatcher +UnorderedElementsAreMatcher(const Args&... matchers) { + return internal::UnorderedElementsAreMatcher(matchers...); +} + #endif // GTEST_LANG_CXX11 // AllArgs(m) is a synonym of m. This is useful in -- cgit v0.12 From dff32aff97a682dfc603ac99bedc639b959e24a8 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 17 Apr 2018 16:12:04 -0400 Subject: http://cl/193060888 --- googlemock/include/gmock/gmock-matchers.h | 18 +++++++++---- googlemock/test/gmock-matchers_test.cc | 42 +++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 62e9233..7c70775 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -5202,19 +5202,27 @@ std::string DescribeMatcher(const M& matcher, bool negation = false) { // Define variadic matcher versions. They are overloaded in // gmock-generated-matchers.h for the cases supported by pre C++11 compilers. template -inline internal::AllOfMatcher AllOf(const Args&... matchers) { +internal::AllOfMatcher AllOf(const Args&... matchers) { return internal::AllOfMatcher(matchers...); } template -inline internal::AnyOfMatcher AnyOf(const Args&... matchers) { +internal::AnyOfMatcher AnyOf(const Args&... matchers) { return internal::AnyOfMatcher(matchers...); } template -inline internal::UnorderedElementsAreMatcher -UnorderedElementsAreMatcher(const Args&... matchers) { - return internal::UnorderedElementsAreMatcher(matchers...); +internal::ElementsAreMatcher::type...>> +ElementsAre(const Args&... matchers) { + return internal::ElementsAreMatcher< + tuple::type...>>(make_tuple(matchers...)); +} + +template +internal::UnorderedElementsAreMatcher::type...>> +UnorderedElementsAre(const Args&... matchers) { + return internal::UnorderedElementsAreMatcher< + tuple::type...>>(make_tuple(matchers...)); } #endif // GTEST_LANG_CXX11 diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 16116b5..c2738c3 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2742,6 +2742,48 @@ TEST(AnyOfTest, VariadicMatchesWhenAnyMatches) { 41, 42, 43, 44, 45, 46, 47, 48, 49, 50)); } +// Tests the variadic version of the ElementsAreMatcher +TEST(ElementsAreTest, HugeMatcher) { + vector test_vector; + test_vector.push_back(1); + test_vector.push_back(2); + test_vector.push_back(3); + test_vector.push_back(4); + test_vector.push_back(5); + test_vector.push_back(6); + test_vector.push_back(7); + test_vector.push_back(8); + test_vector.push_back(9); + test_vector.push_back(10); + test_vector.push_back(11); + test_vector.push_back(12); + + EXPECT_THAT(test_vector, + ElementsAre(Eq(1), Eq(2), Lt(13), Eq(4), Eq(5), Eq(6), Eq(7), + Eq(8), Eq(9), Eq(10), Gt(1), Eq(12) )); +} + +// Tests the variadic version of the UnorderedElementsAreMatcher +TEST(ElementsAreTest, HugeMatcherUnordered) { + vector test_vector; + test_vector.push_back(1); + test_vector.push_back(2); + test_vector.push_back(3); + test_vector.push_back(4); + test_vector.push_back(5); + test_vector.push_back(6); + test_vector.push_back(7); + test_vector.push_back(8); + test_vector.push_back(9); + test_vector.push_back(10); + test_vector.push_back(11); + test_vector.push_back(12); + + EXPECT_THAT(test_vector, + UnorderedElementsAre(Eq(1), Eq(2), Eq(3), Eq(4), Eq(5), Eq(6), Eq(7), + Eq(8), Eq(9), Eq(10), Eq(11), Ne(122) )); +} + #endif // GTEST_LANG_CXX11 // Tests that AnyOf(m1, ..., mn) describes itself properly. -- cgit v0.12 From 5dccf6b79eb55fbbfb4783e2ac15fcc40f66e5bf Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 17 Apr 2018 16:22:35 -0400 Subject: http://cl/193060888 --- googlemock/test/gmock-matchers_test.cc | 36 ++++++---------------------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index c2738c3..a76b331 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2744,44 +2744,20 @@ TEST(AnyOfTest, VariadicMatchesWhenAnyMatches) { // Tests the variadic version of the ElementsAreMatcher TEST(ElementsAreTest, HugeMatcher) { - vector test_vector; - test_vector.push_back(1); - test_vector.push_back(2); - test_vector.push_back(3); - test_vector.push_back(4); - test_vector.push_back(5); - test_vector.push_back(6); - test_vector.push_back(7); - test_vector.push_back(8); - test_vector.push_back(9); - test_vector.push_back(10); - test_vector.push_back(11); - test_vector.push_back(12); + vector test_vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; EXPECT_THAT(test_vector, ElementsAre(Eq(1), Eq(2), Lt(13), Eq(4), Eq(5), Eq(6), Eq(7), - Eq(8), Eq(9), Eq(10), Gt(1), Eq(12) )); + Eq(8), Eq(9), Eq(10), Gt(1), Eq(12))); } // Tests the variadic version of the UnorderedElementsAreMatcher TEST(ElementsAreTest, HugeMatcherUnordered) { - vector test_vector; - test_vector.push_back(1); - test_vector.push_back(2); - test_vector.push_back(3); - test_vector.push_back(4); - test_vector.push_back(5); - test_vector.push_back(6); - test_vector.push_back(7); - test_vector.push_back(8); - test_vector.push_back(9); - test_vector.push_back(10); - test_vector.push_back(11); - test_vector.push_back(12); + vector test_vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; - EXPECT_THAT(test_vector, - UnorderedElementsAre(Eq(1), Eq(2), Eq(3), Eq(4), Eq(5), Eq(6), Eq(7), - Eq(8), Eq(9), Eq(10), Eq(11), Ne(122) )); + EXPECT_THAT(test_vector, UnorderedElementsAre( + Eq(1), Eq(2), Eq(3), Eq(4), Eq(5), Eq(6), Eq(7), + Eq(8), Eq(9), Eq(10), Eq(11), Ne(122))); } #endif // GTEST_LANG_CXX11 -- cgit v0.12 From 80d6e26a9c170812614f2e29c53f0893446d8cee Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 17 Apr 2018 19:32:15 -0400 Subject: cl/193060888 --- googlemock/test/gmock-matchers_test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index a76b331..c40944b 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2753,11 +2753,11 @@ TEST(ElementsAreTest, HugeMatcher) { // Tests the variadic version of the UnorderedElementsAreMatcher TEST(ElementsAreTest, HugeMatcherUnordered) { - vector test_vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; + vector test_vector{2, 1, 8, 5, 4, 6, 7, 3, 9, 12, 11, 10}; EXPECT_THAT(test_vector, UnorderedElementsAre( - Eq(1), Eq(2), Eq(3), Eq(4), Eq(5), Eq(6), Eq(7), - Eq(8), Eq(9), Eq(10), Eq(11), Ne(122))); + Eq(2), Eq(1), Gt(7), Eq(5), Eq(4), Eq(6), Eq(7), + Eq(3), Eq(9), Eq(12), Eq(11), Ne(122))); } #endif // GTEST_LANG_CXX11 -- cgit v0.12 From 4707c0ffd4385e7195170a427e4a0471bb5335a6 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 18 Apr 2018 10:36:12 -0400 Subject: 193353312 --- googlemock/include/gmock/gmock-matchers.h | 11 +++++++---- googlemock/test/gmock-matchers_test.cc | 9 +++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 7c70775..3a2b944 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -5212,17 +5212,20 @@ internal::AnyOfMatcher AnyOf(const Args&... matchers) { } template -internal::ElementsAreMatcher::type...>> +internal::ElementsAreMatcher::type...>> ElementsAre(const Args&... matchers) { return internal::ElementsAreMatcher< - tuple::type...>>(make_tuple(matchers...)); + tuple::type...>>( + make_tuple(matchers...)); } template -internal::UnorderedElementsAreMatcher::type...>> +internal::UnorderedElementsAreMatcher< + tuple::type...>> UnorderedElementsAre(const Args&... matchers) { return internal::UnorderedElementsAreMatcher< - tuple::type...>>(make_tuple(matchers...)); + tuple::type...>>( + make_tuple(matchers...)); } #endif // GTEST_LANG_CXX11 diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index c40944b..8b115cd 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2752,6 +2752,15 @@ TEST(ElementsAreTest, HugeMatcher) { } // Tests the variadic version of the UnorderedElementsAreMatcher +TEST(ElementsAreTest, HugeMatcherStr) { + vector test_vector{ + "literal_string", "", "", "", "", "", "", "", "", "", "", ""}; + + EXPECT_THAT(test_vector, UnorderedElementsAre("literal_string", _, _, _, _, _, + _, _, _, _, _, _)); +} + +// Tests the variadic version of the UnorderedElementsAreMatcher TEST(ElementsAreTest, HugeMatcherUnordered) { vector test_vector{2, 1, 8, 5, 4, 6, 7, 3, 9, 12, 11, 10}; -- cgit v0.12 From c56ba73a23e19527d1e0afc40988ce727686bd9e Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 18 Apr 2018 11:05:00 -0400 Subject: merge, explicit, ( should be it) --- 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 8b115cd..ebb88cc 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -761,7 +761,7 @@ namespace convertible_from_any { struct ConvertibleFromAny { ConvertibleFromAny(int a_value) : value(a_value) {} template - explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) { + ConvertibleFromAny(const T& /*a_value*/) : value(-1) { ADD_FAILURE() << "Conversion constructor called"; } int value; -- cgit v0.12 From 78d73814fae5df61868bea45f22c5f8cd2af9a32 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 18 Apr 2018 14:21:28 -0400 Subject: http://cl/193386206 --- googlemock/test/gmock-matchers_test.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index ebb88cc..59efe64 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -749,6 +749,13 @@ TEST(MatcherCastTest, NonImplicitlyConstructibleTypeWithOperatorEq) { EXPECT_FALSE(m3.Matches(239)); } +// ConvertibleFromAny does not work with MSVC. resulting in +// error C2440: 'initializing': cannot convert from 'Eq' to 'M' +// No constructor could take the source type, or constructor overload +// resolution was ambiguous + +#if !defined _MSC_VER + // The below ConvertibleFromAny struct is implicitly constructible from anything // and when in the same namespace can interact with other tests. In particular, // if it is in the same namespace as other tests and one removes @@ -789,6 +796,8 @@ TEST(MatcherCastTest, FromConvertibleFromAny) { } } // namespace convertible_from_any +#endif // !defined _MSC_VER + struct IntReferenceWrapper { IntReferenceWrapper(const int& a_value) : value(&a_value) {} const int* value; -- cgit v0.12 From b4cbf531e9200f1731e43b299e2c341f2eecbef7 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 18 Apr 2018 14:25:58 -0400 Subject: typo --- 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 59efe64..a7bed48 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -6732,7 +6732,7 @@ TEST(NotTest, WorksOnMoveOnlyType) { } // namespace gmock_matchers_test } // namespace testing -#if defined_MSC_VER +#if defined _MSC_VER # pragma warning(pop) #endif -- cgit v0.12 From 4d554c391b664f3296ce04b70d9045226beb413c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 18 Apr 2018 15:02:47 -0400 Subject: typo --- googlemock/test/gmock-matchers_test.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index a7bed48..72dff85 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -902,6 +902,8 @@ TEST(SafeMatcherCastTest, FromSameType) { EXPECT_FALSE(m2.Matches(1)); } +#if !defined _MSC_VER + namespace convertible_from_any { TEST(SafeMatcherCastTest, ConversionConstructorIsUsed) { Matcher m = SafeMatcherCast(1); @@ -917,6 +919,8 @@ TEST(SafeMatcherCastTest, FromConvertibleFromAny) { } } // namespace convertible_from_any +#endif // !defined _MSC_VER + TEST(SafeMatcherCastTest, ValueIsNotCopied) { int n = 42; Matcher m = SafeMatcherCast(n); -- cgit v0.12 From 10e8ec2714a38cee7ec39118042e6a3fac589767 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 18 Apr 2018 15:10:07 -0400 Subject: move only types docs --- googlemock/docs/CookBook.md | 205 ++++++++++++++++++++------------------------ 1 file changed, 93 insertions(+), 112 deletions(-) diff --git a/googlemock/docs/CookBook.md b/googlemock/docs/CookBook.md index c2565f1..3737d03 100644 --- a/googlemock/docs/CookBook.md +++ b/googlemock/docs/CookBook.md @@ -2229,13 +2229,20 @@ versus ## Mocking Methods That Use Move-Only Types ## -C++11 introduced move-only types. A move-only-typed value can be moved from one object to another, but cannot be copied. `std::unique_ptr` is probably the most commonly used move-only type. +C++11 introduced *move-only types*. A move-only-typed value can be moved from +one object to another, but cannot be copied. `std::unique_ptr` is +probably the most commonly used move-only type. -Mocking a method that takes and/or returns move-only types presents some challenges, but nothing insurmountable. This recipe shows you how you can do it. +Mocking a method that takes and/or returns move-only types presents some +challenges, but nothing insurmountable. This recipe shows you how you can do it. +Note that the support for move-only method arguments was only introduced to +gMock in April 2017; in older code, you may find more complex +[workarounds](#LegacyMoveOnly) for lack of this feature. -Let’s say we are working on a fictional project that lets one post and share snippets called “buzzes”. Your code uses these types: +Let’s say we are working on a fictional project that lets one post and share +snippets called “buzzes”. Your code uses these types: -``` +```cpp enum class AccessLevel { kInternal, kPublic }; class Buzz { @@ -2247,59 +2254,46 @@ class Buzz { class Buzzer { public: virtual ~Buzzer() {} - virtual std::unique_ptr MakeBuzz(const std::string& text) = 0; - virtual bool ShareBuzz(std::unique_ptr buzz, Time timestamp) = 0; + virtual std::unique_ptr MakeBuzz(StringPiece text) = 0; + virtual bool ShareBuzz(std::unique_ptr buzz, int64_t timestamp) = 0; ... }; ``` -A `Buzz` object represents a snippet being posted. A class that implements the `Buzzer` interface is capable of creating and sharing `Buzz`. Methods in `Buzzer` may return a `unique_ptr` or take a `unique_ptr`. Now we need to mock `Buzzer` in our tests. - -To mock a method that returns a move-only type, you just use the familiar `MOCK_METHOD` syntax as usual: - -``` -class MockBuzzer : public Buzzer { - public: - MOCK_METHOD1(MakeBuzz, std::unique_ptr(const std::string& text)); - … -}; -``` - -However, if you attempt to use the same `MOCK_METHOD` pattern to mock a method that takes a move-only parameter, you’ll get a compiler error currently: - -``` - // Does NOT compile! - MOCK_METHOD2(ShareBuzz, bool(std::unique_ptr buzz, Time timestamp)); -``` - -While it’s highly desirable to make this syntax just work, it’s not trivial and the work hasn’t been done yet. Fortunately, there is a trick you can apply today to get something that works nearly as well as this. +A `Buzz` object represents a snippet being posted. A class that implements the +`Buzzer` interface is capable of creating and sharing `Buzz`es. Methods in +`Buzzer` may return a `unique_ptr` or take a +`unique_ptr`. Now we need to mock `Buzzer` in our tests. -The trick, is to delegate the `ShareBuzz()` method to a mock method (let’s call it `DoShareBuzz()`) that does not take move-only parameters: +To mock a method that accepts or returns move-only types, you just use the +familiar `MOCK_METHOD` syntax as usual: -``` +```cpp class MockBuzzer : public Buzzer { public: - MOCK_METHOD1(MakeBuzz, std::unique_ptr(const std::string& text)); - MOCK_METHOD2(DoShareBuzz, bool(Buzz* buzz, Time timestamp)); - bool ShareBuzz(std::unique_ptr buzz, Time timestamp) { - return DoShareBuzz(buzz.get(), timestamp); - } + MOCK_METHOD1(MakeBuzz, std::unique_ptr(StringPiece text)); + MOCK_METHOD2(ShareBuzz, bool(std::unique_ptr buzz, int64_t timestamp)); }; ``` -Note that there's no need to define or declare `DoShareBuzz()` in a base class. You only need to define it as a `MOCK_METHOD` in the mock class. - -Now that we have the mock class defined, we can use it in tests. In the following code examples, we assume that we have defined a `MockBuzzer` object named `mock_buzzer_`: +Now that we have the mock class defined, we can use it in tests. In the +following code examples, we assume that we have defined a `MockBuzzer` object +named `mock_buzzer_`: -``` +```cpp MockBuzzer mock_buzzer_; ``` -First let’s see how we can set expectations on the `MakeBuzz()` method, which returns a `unique_ptr`. +First let’s see how we can set expectations on the `MakeBuzz()` method, which +returns a `unique_ptr`. -As usual, if you set an expectation without an action (i.e. the `.WillOnce()` or `.WillRepeated()` clause), when that expectation fires, the default action for that method will be taken. Since `unique_ptr<>` has a default constructor that returns a null `unique_ptr`, that’s what you’ll get if you don’t specify an action: +As usual, if you set an expectation without an action (i.e. the `.WillOnce()` or +`.WillRepeated()` clause), when that expectation fires, the default action for +that method will be taken. Since `unique_ptr<>` has a default constructor +that returns a null `unique_ptr`, that’s what you’ll get if you don’t specify an +action: -``` +```cpp // Use the default action. EXPECT_CALL(mock_buzzer_, MakeBuzz("hello")); @@ -2307,32 +2301,13 @@ As usual, if you set an expectation without an action (i.e. the `.WillOnce()` or EXPECT_EQ(nullptr, mock_buzzer_.MakeBuzz("hello")); ``` -If you are not happy with the default action, you can tweak it. Depending on what you need, you may either tweak the default action for a specific (mock object, mock method) combination using `ON_CALL()`, or you may tweak the default action for all mock methods that return a specific type. The usage of `ON_CALL()` is similar to `EXPECT_CALL()`, so we’ll skip it and just explain how to do the latter (tweaking the default action for a specific return type). You do this via the `DefaultValue<>::SetFactory()` and `DefaultValue<>::Clear()` API: - -``` - // Sets the default action for return type std::unique_ptr to - // creating a new Buzz every time. - DefaultValue>::SetFactory( - [] { return MakeUnique(AccessLevel::kInternal); }); - - // When this fires, the default action of MakeBuzz() will run, which - // will return a new Buzz object. - EXPECT_CALL(mock_buzzer_, MakeBuzz("hello")).Times(AnyNumber()); +If you are not happy with the default action, you can tweak it as usual; see +[Setting Default Actions](#OnCall). - auto buzz1 = mock_buzzer_.MakeBuzz("hello"); - auto buzz2 = mock_buzzer_.MakeBuzz("hello"); - EXPECT_NE(nullptr, buzz1); - EXPECT_NE(nullptr, buzz2); - EXPECT_NE(buzz1, buzz2); +If you just need to return a pre-defined move-only value, you can use the +`Return(ByMove(...))` action: - // Resets the default action for return type std::unique_ptr, - // to avoid interfere with other tests. - DefaultValue>::Clear(); -``` - -What if you want the method to do something other than the default action? If you just need to return a pre-defined move-only value, you can use the `Return(ByMove(...))` action: - -``` +```cpp // When this fires, the unique_ptr<> specified by ByMove(...) will // be returned. EXPECT_CALL(mock_buzzer_, MakeBuzz("world")) @@ -2343,81 +2318,87 @@ What if you want the method to do something other than the default action? If y Note that `ByMove()` is essential here - if you drop it, the code won’t compile. -Quiz time! What do you think will happen if a `Return(ByMove(...))` action is performed more than once (e.g. you write `….WillRepeatedly(Return(ByMove(...)));`)? Come think of it, after the first time the action runs, the source value will be consumed (since it’s a move-only value), so the next time around, there’s no value to move from -- you’ll get a run-time error that `Return(ByMove(...))` can only be run once. +Quiz time! What do you think will happen if a `Return(ByMove(...))` action is +performed more than once (e.g. you write +`….WillRepeatedly(Return(ByMove(...)));`)? Come think of it, after the first +time the action runs, the source value will be consumed (since it’s a move-only +value), so the next time around, there’s no value to move from -- you’ll get a +run-time error that `Return(ByMove(...))` can only be run once. -If you need your mock method to do more than just moving a pre-defined value, remember that you can always use `Invoke()` to call a lambda or a callable object, which can do pretty much anything you want: +If you need your mock method to do more than just moving a pre-defined value, +remember that you can always use a lambda or a callable object, which can do +pretty much anything you want: -``` +```cpp EXPECT_CALL(mock_buzzer_, MakeBuzz("x")) - .WillRepeatedly(Invoke([](const std::string& text) { - return std::make_unique(AccessLevel::kInternal); - })); + .WillRepeatedly([](StringPiece text) { + return MakeUnique(AccessLevel::kInternal); + }); EXPECT_NE(nullptr, mock_buzzer_.MakeBuzz("x")); EXPECT_NE(nullptr, mock_buzzer_.MakeBuzz("x")); ``` -Every time this `EXPECT_CALL` fires, a new `unique_ptr` will be created and returned. You cannot do this with `Return(ByMove(...))`. +Every time this `EXPECT_CALL` fires, a new `unique_ptr` will be +created and returned. You cannot do this with `Return(ByMove(...))`. -Now there’s one topic we haven’t covered: how do you set expectations on `ShareBuzz()`, which takes a move-only-typed parameter? The answer is you don’t. Instead, you set expectations on the `DoShareBuzz()` mock method (remember that we defined a `MOCK_METHOD` for `DoShareBuzz()`, not `ShareBuzz()`): +That covers returning move-only values; but how do we work with methods +accepting move-only arguments? The answer is that they work normally, although +some actions will not compile when any of method's arguments are move-only. You +can always use `Return`, or a [lambda or functor](#FunctionsAsActions): -``` - EXPECT_CALL(mock_buzzer_, DoShareBuzz(NotNull(), _)); +```cpp + using ::testing::Unused; - // When one calls ShareBuzz() on the MockBuzzer like this, the call is - // forwarded to DoShareBuzz(), which is mocked. Therefore this statement - // will trigger the above EXPECT_CALL. - mock_buzzer_.ShareBuzz(MakeUnique(AccessLevel::kInternal), - ::base::Now()); + EXPECT_CALL(mock_buzzer_, ShareBuzz(NotNull(), _)) .WillOnce(Return(true)); + EXPECT_TRUE(mock_buzzer_.ShareBuzz(MakeUnique(AccessLevel::kInternal)), + 0); + + EXPECT_CALL(mock_buzzer_, ShareBuzz(_, _)) .WillOnce( + [](std::unique_ptr buzz, Unused) { return buzz != nullptr; }); + EXPECT_FALSE(mock_buzzer_.ShareBuzz(nullptr, 0)); ``` -Some of you may have spotted one problem with this approach: the `DoShareBuzz()` mock method differs from the real `ShareBuzz()` method in that it cannot take ownership of the buzz parameter - `ShareBuzz()` will always delete buzz after `DoShareBuzz()` returns. What if you need to save the buzz object somewhere for later use when `ShareBuzz()` is called? Indeed, you'd be stuck. +Many built-in actions (`WithArgs`, `WithoutArgs`,`DeleteArg`, `SaveArg`, ...) +could in principle support move-only arguments, but the support for this is not +implemented yet. If this is blocking you, please file a bug. -Another problem with the `DoShareBuzz()` we had is that it can surprise people reading or maintaining the test, as one would expect that `DoShareBuzz()` has (logically) the same contract as `ShareBuzz()`. +A few actions (e.g. `DoAll`) copy their arguments internally, so they can never +work with non-copyable objects; you'll have to use functors instead. -Fortunately, these problems can be fixed with a bit more code. Let's try to get it right this time: +##### Legacy workarounds for move-only types {#LegacyMoveOnly} -``` +Support for move-only function arguments was only introduced to gMock in April +2017. In older code, you may encounter the following workaround for the lack of +this feature (it is no longer necessary - we're including it just for +reference): + +```cpp class MockBuzzer : public Buzzer { public: - MockBuzzer() { - // Since DoShareBuzz(buzz, time) is supposed to take ownership of - // buzz, define a default behavior for DoShareBuzz(buzz, time) to - // delete buzz. - ON_CALL(*this, DoShareBuzz(_, _)) - .WillByDefault(Invoke([](Buzz* buzz, Time timestamp) { - delete buzz; - return true; - })); - } - - MOCK_METHOD1(MakeBuzz, std::unique_ptr(const std::string& text)); - - // Takes ownership of buzz. MOCK_METHOD2(DoShareBuzz, bool(Buzz* buzz, Time timestamp)); - bool ShareBuzz(std::unique_ptr buzz, Time timestamp) { - return DoShareBuzz(buzz.release(), timestamp); + bool ShareBuzz(std::unique_ptr buzz, Time timestamp) override { + return DoShareBuzz(buzz.get(), timestamp); } }; ``` -Now, the mock `DoShareBuzz()` method is free to save the buzz argument for later use if this is what you want: +The trick is to delegate the `ShareBuzz()` method to a mock method (let’s call +it `DoShareBuzz()`) that does not take move-only parameters. Then, instead of +setting expectations on `ShareBuzz()`, you set them on the `DoShareBuzz()` mock +method: -``` - std::unique_ptr intercepted_buzz; - EXPECT_CALL(mock_buzzer_, DoShareBuzz(NotNull(), _)) - .WillOnce(Invoke([&intercepted_buzz](Buzz* buzz, Time timestamp) { - // Save buzz in intercepted_buzz for analysis later. - intercepted_buzz.reset(buzz); - return false; - })); +```cpp + MockBuzzer mock_buzzer_; + EXPECT_CALL(mock_buzzer_, DoShareBuzz(NotNull(), _)); - mock_buzzer_.ShareBuzz(std::make_unique(AccessLevel::kInternal), - Now()); - EXPECT_NE(nullptr, intercepted_buzz); + // When one calls ShareBuzz() on the MockBuzzer like this, the call is + // forwarded to DoShareBuzz(), which is mocked. Therefore this statement + // will trigger the above EXPECT_CALL. + mock_buzzer_.ShareBuzz(MakeUnique(AccessLevel::kInternal), 0); ``` -Using the tricks covered in this recipe, you are now able to mock methods that take and/or return move-only types. Put your newly-acquired power to good use - when you design a new API, you can now feel comfortable using `unique_ptrs` as appropriate, without fearing that doing so will compromise your tests. + ## Making the Compilation Faster ## -- cgit v0.12 From 881ee307a7602a826a76209b121ae30aabdc9f21 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 18 Apr 2018 15:18:03 -0400 Subject: typo --- googlemock/test/gmock-matchers_test.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 72dff85..de02929 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -33,6 +33,13 @@ // // This file tests some commonly used argument matchers. +// Disable MSVC2015 warning for std::pair: +// "decorated name length exceeded, name was truncated". +#if defined _MSC_VER +# pragma warning(push) +# pragma warning(disable:4503) +#endif + #include "gmock/gmock-matchers.h" #include "gmock/gmock-more-matchers.h" @@ -59,13 +66,6 @@ # include // NOLINT #endif -// Disable MSVC2015 warning for std::pair: -// "decorated name length exceeded, name was truncated". -#if defined _MSC_VER -# pragma warning(push) -# pragma warning(disable:4503) -#endif - #if GTEST_LANG_CXX11 # include #endif -- cgit v0.12 From b00e281078c3623b9022d8bf037a756f47eb7d21 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 18 Apr 2018 16:43:11 -0400 Subject: more typos --- googlemock/test/gmock-matchers_test.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index de02929..05c6eb6 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -35,7 +35,7 @@ // Disable MSVC2015 warning for std::pair: // "decorated name length exceeded, name was truncated". -#if defined _MSC_VER +#ifdef _MSC_VER # pragma warning(push) # pragma warning(disable:4503) #endif @@ -6736,7 +6736,6 @@ TEST(NotTest, WorksOnMoveOnlyType) { } // namespace gmock_matchers_test } // namespace testing -#if defined _MSC_VER +#ifdef _MSC_VER # pragma warning(pop) #endif - -- cgit v0.12 From a0fd742639d87dcc442adf44c3800377a4547c37 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 18 Apr 2018 17:03:42 -0400 Subject: msvc --- googlemock/test/gmock-matchers_test.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 05c6eb6..b8e2798 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -33,11 +33,13 @@ // // This file tests some commonly used argument matchers. -// Disable MSVC2015 warning for std::pair: +// Disable MSVC2014 warning for std::pair: // "decorated name length exceeded, name was truncated". -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable:4503) +ifdef _MSC_VER +#if _MSC_VER < 1900 +# pragma warning(push) +# pragma warning(disable:4503) +#endif #endif #include "gmock/gmock-matchers.h" @@ -6735,7 +6737,3 @@ TEST(NotTest, WorksOnMoveOnlyType) { } // namespace gmock_matchers_test } // namespace testing - -#ifdef _MSC_VER -# pragma warning(pop) -#endif -- cgit v0.12 From f31243503276fff49dfdc8e74076a0552c298c20 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 18 Apr 2018 17:13:23 -0400 Subject: more typos --- 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 b8e2798..aede415 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -35,7 +35,7 @@ // Disable MSVC2014 warning for std::pair: // "decorated name length exceeded, name was truncated". -ifdef _MSC_VER +#ifdef _MSC_VER #if _MSC_VER < 1900 # pragma warning(push) # pragma warning(disable:4503) -- cgit v0.12 From f437f8ca0d4d13d6b1b6279ee40dc61121873a94 Mon Sep 17 00:00:00 2001 From: David Sunderland Date: Wed, 18 Apr 2018 19:28:56 -0400 Subject: Clone of unsubmitted cr/176529515. Introduce parameterless expectations. --- .../gmock/gmock-generated-function-mockers.h | 163 +++++++++++++++++++++ .../gmock/gmock-generated-function-mockers.h.pump | 60 ++++++++ googlemock/include/gmock/gmock-spec-builders.h | 90 ++++++++++-- .../include/gmock/internal/gmock-internal-utils.h | 15 ++ googlemock/src/gmock-internal-utils.cc | 2 + googlemock/test/gmock-matchers_test.cc | 39 ++++- googlemock/test/gmock-spec-builders_test.cc | 70 +++++++++ 7 files changed, 426 insertions(+), 13 deletions(-) diff --git a/googlemock/include/gmock/gmock-generated-function-mockers.h b/googlemock/include/gmock/gmock-generated-function-mockers.h index 550cfd2..83abdca 100644 --- a/googlemock/include/gmock/gmock-generated-function-mockers.h +++ b/googlemock/include/gmock/gmock-generated-function-mockers.h @@ -332,6 +332,58 @@ class FunctionMocker : public } }; +// Removes the given pointer; this is a helper for the expectation setter method +// for parameterless matchers. +// +// We want to make sure that the user cannot set a parameterless expectation on +// overloaded methods, including methods which are overloaded on const. Example: +// +// class MockClass { +// MOCK_METHOD0(GetName, string&()); +// MOCK_CONST_METHOD0(GetName, const string&()); +// }; +// +// TEST() { +// // This should be an error, as it's not clear which overload is expected. +// EXPECT_CALL(mock, GetName).WillOnce(ReturnRef(value)); +// } +// +// Here are the generated expectation-setter methods: +// +// class MockClass { +// // Overload 1 +// MockSpec gmock_GetName() { … } +// // Overload 2. Declared const so that the compiler will generate an +// // error when trying to resolve between this and overload 4 in +// // 'gmock_GetName(WithoutMatchers(), nullptr)'. +// MockSpec gmock_GetName( +// const WithoutMatchers&, const Function*) const { +// // Removes const from this, calls overload 1 +// return AdjustConstness_(this)->gmock_GetName(); +// } +// +// // Overload 3 +// const string& gmock_GetName() const { … } +// // Overload 4 +// MockSpec gmock_GetName( +// const WithoutMatchers&, const Function*) const { +// // Does not remove const, calls overload 3 +// return AdjustConstness_const(this)->gmock_GetName(); +// } +// } +// +template +const MockType* AdjustConstness_const(const MockType* mock) { + return mock; +} + +// Removes const from and returns the given pointer; this is a helper for the +// expectation setter method for parameterless matchers. +template +MockType* AdjustConstness_(const MockType* mock) { + return const_cast(mock); +} + } // namespace internal // The style guide prohibits "using" statements in a namespace scope @@ -380,6 +432,12 @@ using internal::FunctionMocker; GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \ return GMOCK_MOCKER_(0, constness, Method).With(); \ } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ + return ::testing::internal::AdjustConstness_##constness(this)-> \ + gmock_##Method(); \ + } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(0, constness, \ Method) @@ -401,6 +459,12 @@ using internal::FunctionMocker; GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \ return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \ } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ + return ::testing::internal::AdjustConstness_##constness(this)-> \ + gmock_##Method(::testing::A()); \ + } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(1, constness, \ Method) @@ -425,6 +489,13 @@ using internal::FunctionMocker; GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \ return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \ } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ + return ::testing::internal::AdjustConstness_##constness(this)-> \ + gmock_##Method(::testing::A(), \ + ::testing::A()); \ + } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(2, constness, \ Method) @@ -453,6 +524,14 @@ using internal::FunctionMocker; return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \ gmock_a3); \ } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ + return ::testing::internal::AdjustConstness_##constness(this)-> \ + gmock_##Method(::testing::A(), \ + ::testing::A(), \ + ::testing::A()); \ + } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(3, constness, \ Method) @@ -483,6 +562,15 @@ using internal::FunctionMocker; return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \ gmock_a3, gmock_a4); \ } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ + return ::testing::internal::AdjustConstness_##constness(this)-> \ + gmock_##Method(::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A()); \ + } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(4, constness, \ Method) @@ -516,6 +604,16 @@ using internal::FunctionMocker; return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \ gmock_a3, gmock_a4, gmock_a5); \ } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ + return ::testing::internal::AdjustConstness_##constness(this)-> \ + gmock_##Method(::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A()); \ + } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(5, constness, \ Method) @@ -552,6 +650,17 @@ using internal::FunctionMocker; return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \ gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ + return ::testing::internal::AdjustConstness_##constness(this)-> \ + gmock_##Method(::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A()); \ + } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(6, constness, \ Method) @@ -590,6 +699,18 @@ using internal::FunctionMocker; return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \ gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ + return ::testing::internal::AdjustConstness_##constness(this)-> \ + gmock_##Method(::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A()); \ + } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(7, constness, \ Method) @@ -631,6 +752,19 @@ using internal::FunctionMocker; return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \ gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ + return ::testing::internal::AdjustConstness_##constness(this)-> \ + gmock_##Method(::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A()); \ + } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(8, constness, \ Method) @@ -676,6 +810,20 @@ using internal::FunctionMocker; gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \ gmock_a9); \ } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ + return ::testing::internal::AdjustConstness_##constness(this)-> \ + gmock_##Method(::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A()); \ + } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(9, constness, \ Method) @@ -724,6 +872,21 @@ using internal::FunctionMocker; gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \ gmock_a10); \ } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ + return ::testing::internal::AdjustConstness_##constness(this)-> \ + gmock_##Method(::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A()); \ + } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(10, constness, \ Method) diff --git a/googlemock/include/gmock/gmock-generated-function-mockers.h.pump b/googlemock/include/gmock/gmock-generated-function-mockers.h.pump index 277003b..e55ef99 100644 --- a/googlemock/include/gmock/gmock-generated-function-mockers.h.pump +++ b/googlemock/include/gmock/gmock-generated-function-mockers.h.pump @@ -94,6 +94,58 @@ class FunctionMocker : public ]] +// Removes the given pointer; this is a helper for the expectation setter method +// for parameterless matchers. +// +// We want to make sure that the user cannot set a parameterless expectation on +// overloaded methods, including methods which are overloaded on const. Example: +// +// class MockClass { +// MOCK_METHOD0(GetName, string&()); +// MOCK_CONST_METHOD0(GetName, const string&()); +// }; +// +// TEST() { +// // This should be an error, as it's not clear which overload is expected. +// EXPECT_CALL(mock, GetName).WillOnce(ReturnRef(value)); +// } +// +// Here are the generated expectation-setter methods: +// +// class MockClass { +// // Overload 1 +// MockSpec gmock_GetName() { … } +// // Overload 2. Declared const so that the compiler will generate an +// // error when trying to resolve between this and overload 4 in +// // 'gmock_GetName(WithoutMatchers(), nullptr)'. +// MockSpec gmock_GetName( +// const WithoutMatchers&, const Function*) const { +// // Removes const from this, calls overload 1 +// return AdjustConstness_(this)->gmock_GetName(); +// } +// +// // Overload 3 +// const string& gmock_GetName() const { … } +// // Overload 4 +// MockSpec gmock_GetName( +// const WithoutMatchers&, const Function*) const { +// // Does not remove const, calls overload 3 +// return AdjustConstness_const(this)->gmock_GetName(); +// } +// } +// +template +const MockType* AdjustConstness_const(const MockType* mock) { + return mock; +} + +// Removes const from and returns the given pointer; this is a helper for the +// expectation setter method for parameterless matchers. +template +MockType* AdjustConstness_(const MockType* mock) { + return const_cast(mock); +} + } // namespace internal // The style guide prohibits "using" statements in a namespace scope @@ -135,6 +187,8 @@ $var as = [[$for j, \ $var matcher_arg_as = [[$for j, \ [[GMOCK_MATCHER_(tn, $j, __VA_ARGS__) gmock_a$j]]]] $var matcher_as = [[$for j, [[gmock_a$j]]]] +$var anything_matchers = [[$for j, \ + [[::testing::A()]]]] // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, ...) \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ @@ -150,6 +204,12 @@ $var matcher_as = [[$for j, [[gmock_a$j]]]] GMOCK_MOCKER_($i, constness, Method).RegisterOwner(this); \ return GMOCK_MOCKER_($i, constness, Method).With($matcher_as); \ } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ + return ::testing::internal::AdjustConstness_##constness(this)-> \ + gmock_##Method($anything_matchers); \ + } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_($i, constness, Method) diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index a7be7d1..cf1e7e2 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -1282,6 +1282,13 @@ class MockSpec { file, line, source_text, matchers_); } + // This operator overload is used to swallow the superfluous parameter list + // introduced by the ON/EXPECT_CALL macros. See the macro comments for more + // explanation. + MockSpec& operator()(const internal::WithoutMatchers&, void* const) { + return *this; + } + private: template friend class internal::FunctionMocker; @@ -1836,17 +1843,76 @@ inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT } // namespace testing -// A separate macro is required to avoid compile errors when the name -// of the method used in call is a result of macro expansion. -// See CompilesWithMethodNameExpandedFromMacro tests in -// internal/gmock-spec-builders_test.cc for more details. -#define GMOCK_ON_CALL_IMPL_(obj, call) \ - ((obj).gmock_##call).InternalDefaultActionSetAt(__FILE__, __LINE__, \ - #obj, #call) -#define ON_CALL(obj, call) GMOCK_ON_CALL_IMPL_(obj, call) - -#define GMOCK_EXPECT_CALL_IMPL_(obj, call) \ - ((obj).gmock_##call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call) -#define EXPECT_CALL(obj, call) GMOCK_EXPECT_CALL_IMPL_(obj, call) +// Implementation for ON_CALL and EXPECT_CALL macros. A separate macro is +// required to avoid compile errors when the name of the method used in call is +// a result of macro expansion. See CompilesWithMethodNameExpandedFromMacro +// tests in internal/gmock-spec-builders_test.cc for more details. +// +// This macro supports statements both with and without parameter matchers. If +// the parameter list is omitted, gMock will accept any parameters, which allows +// tests to be written that don't need to encode the number of method +// parameter. This technique may only be used for non-overloaded methods. +// +// // These are the same: +// ON_CALL(mock, NoArgsMethod()).WillByDefault(…); +// ON_CALL(mock, NoArgsMethod).WillByDefault(…); +// +// // As are these: +// ON_CALL(mock, TwoArgsMethod(_, _)).WillByDefault(…); +// ON_CALL(mock, TwoArgsMethod).WillByDefault(…); +// +// // Can also specify args if you want, of course: +// ON_CALL(mock, TwoArgsMethod(_, 45)).WillByDefault(…); +// +// // Overloads work as long as you specify parameters: +// ON_CALL(mock, OverloadedMethod(_)).WillByDefault(…); +// ON_CALL(mock, OverloadedMethod(_, _)).WillByDefault(…); +// +// // Oops! Which overload did you want? +// ON_CALL(mock, OverloadedMethod).WillByDefault(…); +// => ERROR: call to member function 'gmock_OverloadedMethod' is ambiguous +// +// How this works: The mock class uses two overloads of the gmock_Method +// expectation setter method plus an operator() overload on the MockSpec object. +// In the matcher list form, the macro expands to: +// +// // This statement: +// ON_CALL(mock, TwoArgsMethod(_, 45))… +// +// // …expands to: +// mock.gmock_TwoArgsMethod(_, 45)(WithoutMatchers(), nullptr)… +// |-------------v---------------||------------v-------------| +// invokes first overload swallowed by operator() +// +// // …which is essentially: +// mock.gmock_TwoArgsMethod(_, 45)… +// +// Whereas the form without a matcher list: +// +// // This statement: +// ON_CALL(mock, TwoArgsMethod)… +// +// // …expands to: +// mock.gmock_TwoArgsMethod(WithoutMatchers(), nullptr)… +// |-----------------------v--------------------------| +// invokes second overload +// +// // …which is essentially: +// mock.gmock_TwoArgsMethod(_, _)… +// +// The WithoutMatchers() argument is used to disambiguate overloads and to +// block the caller from accidentally invoking the second overload directly. The +// second argument is an internal type derived from the method signature. The +// failure to disambiguate two overloads of this method in the ON_CALL statement +// is how we block callers from setting expectations on overloaded methods. +#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call) \ + ((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), NULL) \ + .Setter(__FILE__, __LINE__, #mock_expr, #call) + +#define ON_CALL(obj, call) \ + GMOCK_ON_CALL_IMPL_(obj, InternalDefaultActionSetAt, call) + +#define EXPECT_CALL(obj, call) \ + GMOCK_ON_CALL_IMPL_(obj, InternalExpectedAt, call) #endif // GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 20c95c6..c43dac0 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -344,6 +344,21 @@ GTEST_API_ bool LogIsVisible(LogSeverity severity); GTEST_API_ void Log(LogSeverity severity, const std::string& message, int stack_frames_to_skip); +// A marker class that is used to resolve parameterless expectations to the +// correct overload. This must not be instantiable, to prevent client code from +// accidentally resolving to the overload; for example: +// +// ON_CALL(mock, Method({}, nullptr))… +// +class WithoutMatchers { + private: + WithoutMatchers() {} + friend WithoutMatchers GetWithoutMatchers(); +}; + +// Internal use only: access the singleton instance of WithoutMatchers. +WithoutMatchers GetWithoutMatchers(); + // TODO(wan@google.com): group all type utilities together. // Type traits. diff --git a/googlemock/src/gmock-internal-utils.cc b/googlemock/src/gmock-internal-utils.cc index 3fca3f2..aeff800 100644 --- a/googlemock/src/gmock-internal-utils.cc +++ b/googlemock/src/gmock-internal-utils.cc @@ -188,6 +188,8 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message, std::cout << ::std::flush; } +WithoutMatchers GetWithoutMatchers() { return {}; } + GTEST_API_ void IllegalDoDefault(const char* file, int line) { internal::Assert( false, file, line, diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 16116b5..8170bdb 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -3066,6 +3066,44 @@ TEST(AllArgsTest, WorksInWithClause) { EXPECT_EQ(2, helper.Helper('a', 1)); } +class OptionalMatchersHelper { + public: + OptionalMatchersHelper() {} + + MOCK_METHOD0(NoArgs, int()); + + MOCK_METHOD1(OneArg, int(int y)); + + MOCK_METHOD2(TwoArgs, int(char x, int y)); + + MOCK_METHOD1(Overloaded, int(char x)); + MOCK_METHOD2(Overloaded, int(char x, int y)); + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(OptionalMatchersHelper); +}; + +TEST(AllArgsTest, WorksWithoutMatchers) { + OptionalMatchersHelper helper; + + ON_CALL(helper, NoArgs).WillByDefault(Return(10)); + ON_CALL(helper, OneArg).WillByDefault(Return(20)); + ON_CALL(helper, TwoArgs).WillByDefault(Return(30)); + + EXPECT_EQ(10, helper.NoArgs()); + EXPECT_EQ(20, helper.OneArg(1)); + EXPECT_EQ(30, helper.TwoArgs('\1', 2)); + + EXPECT_CALL(helper, NoArgs).Times(1); + EXPECT_CALL(helper, OneArg).WillOnce(Return(100)); + EXPECT_CALL(helper, OneArg(17)).WillOnce(Return(200)); + EXPECT_CALL(helper, TwoArgs).Times(0); + + EXPECT_EQ(10, helper.NoArgs()); + EXPECT_EQ(100, helper.OneArg(1)); + EXPECT_EQ(200, helper.OneArg(17)); +} + // Tests that ASSERT_THAT() and EXPECT_THAT() work when the value // matches the matcher. TEST(MatcherAssertionTest, WorksWhenMatcherIsSatisfied) { @@ -6699,4 +6737,3 @@ TEST(NotTest, WorksOnMoveOnlyType) { #if defined_MSC_VER # pragma warning(pop) #endif - diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index f1d571b..715aac8 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -89,6 +89,7 @@ using testing::Mock; using testing::NaggyMock; using testing::Ne; using testing::Return; +using testing::SaveArg; using testing::Sequence; using testing::SetArgPointee; using testing::internal::ExpectationTester; @@ -2681,6 +2682,75 @@ TEST(SynchronizationTest, CanCallMockMethodInAction) { // EXPECT_CALL() did not specify an action. } +TEST(ParameterlessExpectationsTest, CanSetExpectationsWithoutMatchers) { + MockA a; + int do_a_arg0 = 0; + ON_CALL(a, DoA).WillByDefault(SaveArg<0>(&do_a_arg0)); + int do_a_47_arg0 = 0; + ON_CALL(a, DoA(47)).WillByDefault(SaveArg<0>(&do_a_47_arg0)); + + a.DoA(17); + EXPECT_THAT(do_a_arg0, 17); + EXPECT_THAT(do_a_47_arg0, 0); + a.DoA(47); + EXPECT_THAT(do_a_arg0, 17); + EXPECT_THAT(do_a_47_arg0, 47); + + ON_CALL(a, Binary).WillByDefault(Return(true)); + ON_CALL(a, Binary(_, 14)).WillByDefault(Return(false)); + EXPECT_THAT(a.Binary(14, 17), true); + EXPECT_THAT(a.Binary(17, 14), false); +} + +TEST(ParameterlessExpectationsTest, CanSetExpectationsForOverloadedMethods) { + MockB b; + ON_CALL(b, DoB()).WillByDefault(Return(9)); + ON_CALL(b, DoB(5)).WillByDefault(Return(11)); + + EXPECT_THAT(b.DoB(), 9); + EXPECT_THAT(b.DoB(1), 0); // default value + EXPECT_THAT(b.DoB(5), 11); +} + +struct MockWithConstMethods { + public: + MOCK_CONST_METHOD1(Foo, int(int)); + MOCK_CONST_METHOD2(Bar, int(int, const char*)); +}; + +TEST(ParameterlessExpectationsTest, CanSetExpectationsForConstMethods) { + MockWithConstMethods mock; + ON_CALL(mock, Foo).WillByDefault(Return(7)); + ON_CALL(mock, Bar).WillByDefault(Return(33)); + + EXPECT_THAT(mock.Foo(17), 7); + EXPECT_THAT(mock.Bar(27, "purple"), 33); +} + +class MockConstOverload { + public: + MOCK_METHOD1(Overloaded, int(int)); + MOCK_CONST_METHOD1(Overloaded, int(int)); +}; + +TEST(ParameterlessExpectationsTest, + CanSetExpectationsForConstOverloadedMethods) { + MockConstOverload mock; + ON_CALL(mock, Overloaded(_)).WillByDefault(Return(7)); + ON_CALL(mock, Overloaded(5)).WillByDefault(Return(9)); + ON_CALL(Const(mock), Overloaded(5)).WillByDefault(Return(11)); + ON_CALL(Const(mock), Overloaded(7)).WillByDefault(Return(13)); + + EXPECT_THAT(mock.Overloaded(1), 7); + EXPECT_THAT(mock.Overloaded(5), 9); + EXPECT_THAT(mock.Overloaded(7), 7); + + const MockConstOverload& const_mock = mock; + EXPECT_THAT(const_mock.Overloaded(1), 0); + EXPECT_THAT(const_mock.Overloaded(5), 11); + EXPECT_THAT(const_mock.Overloaded(7), 13); +} + } // namespace // Allows the user to define their own main and then invoke gmock_main -- cgit v0.12 From f6551f2d45387d42dbdd5742cf2284b8d616f0b8 Mon Sep 17 00:00:00 2001 From: David Sunderland Date: Wed, 18 Apr 2018 19:37:33 -0400 Subject: Don't use generalized initializer list; is C++11 extension. --- googlemock/src/gmock-internal-utils.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/src/gmock-internal-utils.cc b/googlemock/src/gmock-internal-utils.cc index aeff800..ce75a5f 100644 --- a/googlemock/src/gmock-internal-utils.cc +++ b/googlemock/src/gmock-internal-utils.cc @@ -188,7 +188,7 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message, std::cout << ::std::flush; } -WithoutMatchers GetWithoutMatchers() { return {}; } +WithoutMatchers GetWithoutMatchers() { return WithoutMatchers(); } GTEST_API_ void IllegalDoDefault(const char* file, int line) { internal::Assert( -- cgit v0.12 From d5725da96894fcb93c1c3e4b87ad45372707a26b Mon Sep 17 00:00:00 2001 From: David Sunderland Date: Wed, 18 Apr 2018 20:25:31 -0400 Subject: Mark new GetWithoutMatchers method as part of the exported API, to address MSVC linker errors. --- googlemock/include/gmock/internal/gmock-internal-utils.h | 2 +- googlemock/src/gmock-internal-utils.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index c43dac0..3e858e7 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -357,7 +357,7 @@ class WithoutMatchers { }; // Internal use only: access the singleton instance of WithoutMatchers. -WithoutMatchers GetWithoutMatchers(); +GTEST_API_ WithoutMatchers GetWithoutMatchers(); // TODO(wan@google.com): group all type utilities together. diff --git a/googlemock/src/gmock-internal-utils.cc b/googlemock/src/gmock-internal-utils.cc index ce75a5f..77caf2b 100644 --- a/googlemock/src/gmock-internal-utils.cc +++ b/googlemock/src/gmock-internal-utils.cc @@ -188,7 +188,7 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message, std::cout << ::std::flush; } -WithoutMatchers GetWithoutMatchers() { return WithoutMatchers(); } +GTEST_API_ WithoutMatchers GetWithoutMatchers() { return WithoutMatchers(); } GTEST_API_ void IllegalDoDefault(const char* file, int line) { internal::Assert( -- cgit v0.12 From 1c79ad7a56de952bdbba196c4e893a05bc30d306 Mon Sep 17 00:00:00 2001 From: David Sunderland Date: Wed, 18 Apr 2018 20:59:49 -0400 Subject: Add GTEST_API_ tag to WithoutMatchers class. Hopefully that fixes the problem on MSVC? --- googlemock/include/gmock/internal/gmock-internal-utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 3e858e7..3d39296 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -350,7 +350,7 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message, // // ON_CALL(mock, Method({}, nullptr))… // -class WithoutMatchers { +class GTEST_API_ WithoutMatchers { private: WithoutMatchers() {} friend WithoutMatchers GetWithoutMatchers(); -- cgit v0.12 From b2f97ab3179fbc435fb0f98eae793fe84476c7b8 Mon Sep 17 00:00:00 2001 From: David Sunderland Date: Thu, 19 Apr 2018 01:10:22 -0400 Subject: Revert useless use of GTEST_API_ on WithoutMatchers decl. --- googlemock/include/gmock/internal/gmock-internal-utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 3d39296..3e858e7 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -350,7 +350,7 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message, // // ON_CALL(mock, Method({}, nullptr))… // -class GTEST_API_ WithoutMatchers { +class WithoutMatchers { private: WithoutMatchers() {} friend WithoutMatchers GetWithoutMatchers(); -- cgit v0.12 From 2d3024f5bdc40aa0dfa764e924becfbbb096a795 Mon Sep 17 00:00:00 2001 From: David Sunderland Date: Thu, 19 Apr 2018 01:11:50 -0400 Subject: Fix friend declaration to use GTEST_API_ decl spec. --- googlemock/include/gmock/internal/gmock-internal-utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 3e858e7..4751788 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -353,7 +353,7 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message, class WithoutMatchers { private: WithoutMatchers() {} - friend WithoutMatchers GetWithoutMatchers(); + friend GTEST_API_ WithoutMatchers GetWithoutMatchers(); }; // Internal use only: access the singleton instance of WithoutMatchers. -- cgit v0.12 From 62a7c140a72a6eba42ce87b66884c7eb6a8ccb82 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 19 Apr 2018 10:19:59 -0400 Subject: testing --- googlemock/test/gmock-matchers_test.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index aede415..eafcaae 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -33,15 +33,6 @@ // // This file tests some commonly used argument matchers. -// Disable MSVC2014 warning for std::pair: -// "decorated name length exceeded, name was truncated". -#ifdef _MSC_VER -#if _MSC_VER < 1900 -# pragma warning(push) -# pragma warning(disable:4503) -#endif -#endif - #include "gmock/gmock-matchers.h" #include "gmock/gmock-more-matchers.h" @@ -68,6 +59,13 @@ # include // NOLINT #endif +// Disable MSVC2015 warning for std::pair: +// "decorated name length exceeded, name was truncated". +#if defined _MSC_VER +# pragma warning(push) +# pragma warning(disable:4503) +#endif + #if GTEST_LANG_CXX11 # include #endif @@ -756,8 +754,6 @@ TEST(MatcherCastTest, NonImplicitlyConstructibleTypeWithOperatorEq) { // No constructor could take the source type, or constructor overload // resolution was ambiguous -#if !defined _MSC_VER - // The below ConvertibleFromAny struct is implicitly constructible from anything // and when in the same namespace can interact with other tests. In particular, // if it is in the same namespace as other tests and one removes @@ -798,7 +794,6 @@ TEST(MatcherCastTest, FromConvertibleFromAny) { } } // namespace convertible_from_any -#endif // !defined _MSC_VER struct IntReferenceWrapper { IntReferenceWrapper(const int& a_value) : value(&a_value) {} @@ -6737,3 +6732,8 @@ TEST(NotTest, WorksOnMoveOnlyType) { } // namespace gmock_matchers_test } // namespace testing + +#if defined _MSC_VER +# pragma warning(pop) +#endif + -- cgit v0.12 From 7b4ee66f5f8228a40ee6f39844a73ab6e7447db8 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 19 Apr 2018 11:14:17 -0400 Subject: reverting just to test --- 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 eafcaae..37fcbfa 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -764,7 +764,7 @@ TEST(MatcherCastTest, NonImplicitlyConstructibleTypeWithOperatorEq) { namespace convertible_from_any { // Implicitly convertible from any type. struct ConvertibleFromAny { - ConvertibleFromAny(int a_value) : value(a_value) {} +explicit ConvertibleFromAny(int a_value) : value(a_value) {} template ConvertibleFromAny(const T& /*a_value*/) : value(-1) { ADD_FAILURE() << "Conversion constructor called"; -- cgit v0.12 From bb7a018348828024cff90bec67cc93a43ff20ee4 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 19 Apr 2018 11:28:46 -0400 Subject: reverting, test --- googlemock/test/gmock-matchers_test.cc | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 37fcbfa..8b115cd 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -749,11 +749,6 @@ TEST(MatcherCastTest, NonImplicitlyConstructibleTypeWithOperatorEq) { EXPECT_FALSE(m3.Matches(239)); } -// ConvertibleFromAny does not work with MSVC. resulting in -// error C2440: 'initializing': cannot convert from 'Eq' to 'M' -// No constructor could take the source type, or constructor overload -// resolution was ambiguous - // The below ConvertibleFromAny struct is implicitly constructible from anything // and when in the same namespace can interact with other tests. In particular, // if it is in the same namespace as other tests and one removes @@ -764,9 +759,9 @@ TEST(MatcherCastTest, NonImplicitlyConstructibleTypeWithOperatorEq) { namespace convertible_from_any { // Implicitly convertible from any type. struct ConvertibleFromAny { -explicit ConvertibleFromAny(int a_value) : value(a_value) {} + ConvertibleFromAny(int a_value) : value(a_value) {} template - ConvertibleFromAny(const T& /*a_value*/) : value(-1) { + explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) { ADD_FAILURE() << "Conversion constructor called"; } int value; @@ -794,7 +789,6 @@ TEST(MatcherCastTest, FromConvertibleFromAny) { } } // namespace convertible_from_any - struct IntReferenceWrapper { IntReferenceWrapper(const int& a_value) : value(&a_value) {} const int* value; @@ -899,8 +893,6 @@ TEST(SafeMatcherCastTest, FromSameType) { EXPECT_FALSE(m2.Matches(1)); } -#if !defined _MSC_VER - namespace convertible_from_any { TEST(SafeMatcherCastTest, ConversionConstructorIsUsed) { Matcher m = SafeMatcherCast(1); @@ -916,8 +908,6 @@ TEST(SafeMatcherCastTest, FromConvertibleFromAny) { } } // namespace convertible_from_any -#endif // !defined _MSC_VER - TEST(SafeMatcherCastTest, ValueIsNotCopied) { int n = 42; Matcher m = SafeMatcherCast(n); @@ -6733,7 +6723,7 @@ TEST(NotTest, WorksOnMoveOnlyType) { } // namespace gmock_matchers_test } // namespace testing -#if defined _MSC_VER +#if defined_MSC_VER # pragma warning(pop) #endif -- cgit v0.12 From b539167cf0254f521b791e908f6d3a5ff3f30245 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 25 Apr 2018 13:10:41 -0400 Subject: merging, --- .../gmock/gmock-generated-function-mockers.h | 899 +++++++++++++-------- .../gmock/gmock-generated-function-mockers.h.pump | 60 ++ googlemock/include/gmock/gmock-matchers.h | 219 +++-- googlemock/include/gmock/gmock-spec-builders.h | 90 ++- .../include/gmock/internal/gmock-internal-utils.h | 15 + googlemock/src/gmock-internal-utils.cc | 2 + googlemock/test/gmock-matchers_test.cc | 67 +- googlemock/test/gmock-spec-builders_test.cc | 70 ++ 8 files changed, 929 insertions(+), 493 deletions(-) diff --git a/googlemock/include/gmock/gmock-generated-function-mockers.h b/googlemock/include/gmock/gmock-generated-function-mockers.h index 550cfd2..126c48c 100644 --- a/googlemock/include/gmock/gmock-generated-function-mockers.h +++ b/googlemock/include/gmock/gmock-generated-function-mockers.h @@ -332,6 +332,58 @@ class FunctionMocker : public } }; +// Removes the given pointer; this is a helper for the expectation setter method +// for parameterless matchers. +// +// We want to make sure that the user cannot set a parameterless expectation on +// overloaded methods, including methods which are overloaded on const. Example: +// +// class MockClass { +// MOCK_METHOD0(GetName, string&()); +// MOCK_CONST_METHOD0(GetName, const string&()); +// }; +// +// TEST() { +// // This should be an error, as it's not clear which overload is expected. +// EXPECT_CALL(mock, GetName).WillOnce(ReturnRef(value)); +// } +// +// Here are the generated expectation-setter methods: +// +// class MockClass { +// // Overload 1 +// MockSpec gmock_GetName() { … } +// // Overload 2. Declared const so that the compiler will generate an +// // error when trying to resolve between this and overload 4 in +// // 'gmock_GetName(WithoutMatchers(), nullptr)'. +// MockSpec gmock_GetName( +// const WithoutMatchers&, const Function*) const { +// // Removes const from this, calls overload 1 +// return AdjustConstness_(this)->gmock_GetName(); +// } +// +// // Overload 3 +// const string& gmock_GetName() const { … } +// // Overload 4 +// MockSpec gmock_GetName( +// const WithoutMatchers&, const Function*) const { +// // Does not remove const, calls overload 3 +// return AdjustConstness_const(this)->gmock_GetName(); +// } +// } +// +template +const MockType* AdjustConstness_const(const MockType* mock) { + return mock; +} + +// Removes const from and returns the given pointer; this is a helper for the +// expectation setter method for parameterless matchers. +template +MockType* AdjustConstness_(const MockType* mock) { + return const_cast(mock); +} + } // namespace internal // The style guide prohibits "using" statements in a namespace scope @@ -365,367 +417,534 @@ using internal::FunctionMocker; GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD0_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - ) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 0), \ - this_method_does_not_take_0_arguments); \ - GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(0, constness, Method).Invoke(); \ - } \ - ::testing::MockSpec<__VA_ARGS__> \ - gmock_##Method() constness { \ - GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(0, constness, Method).With(); \ - } \ +#define GMOCK_METHOD0_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) ct Method() constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size::ArgumentTuple>::value == 0), \ + this_method_does_not_take_0_arguments); \ + GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(0, constness, Method).Invoke(); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method() constness { \ + GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(0, constness, Method).With(); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(); \ + } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(0, constness, \ - Method) + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD1_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 1), \ - this_method_does_not_take_1_argument); \ - GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(1, constness, \ - Method).Invoke(::testing::internal::forward(gmock_a1)); \ - } \ - ::testing::MockSpec<__VA_ARGS__> \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ - GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(1, constness, \ - Method) +#define GMOCK_METHOD1_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size::ArgumentTuple>::value == 1), \ + this_method_does_not_take_1_argument); \ + GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(1, constness, Method) \ + .Invoke(::testing::internal::forward( \ + gmock_a1)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ + GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(1, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ - __VA_ARGS__) gmock_a2) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 2), \ - this_method_does_not_take_2_arguments); \ - GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(2, constness, \ - Method).Invoke(::testing::internal::forward(gmock_a1), \ - ::testing::internal::forward(gmock_a2)); \ - } \ - ::testing::MockSpec<__VA_ARGS__> \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \ - GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(2, constness, \ - Method) +#define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size::ArgumentTuple>::value == 2), \ + this_method_does_not_take_2_arguments); \ + GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(2, constness, Method) \ + .Invoke(::testing::internal::forward( \ + gmock_a1), \ + ::testing::internal::forward( \ + gmock_a2)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \ + GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A(), \ + ::testing::A()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(2, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ - __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, \ - __VA_ARGS__) gmock_a3) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 3), \ - this_method_does_not_take_3_arguments); \ - GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(3, constness, \ - Method).Invoke(::testing::internal::forward(gmock_a1), \ - ::testing::internal::forward(gmock_a2), \ - ::testing::internal::forward(gmock_a3)); \ - } \ - ::testing::MockSpec<__VA_ARGS__> \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \ - GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(3, constness, \ - Method) +#define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size::ArgumentTuple>::value == 3), \ + this_method_does_not_take_3_arguments); \ + GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(3, constness, Method) \ + .Invoke(::testing::internal::forward( \ + gmock_a1), \ + ::testing::internal::forward( \ + gmock_a2), \ + ::testing::internal::forward( \ + gmock_a3)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \ + GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(3, constness, Method) \ + .With(gmock_a1, gmock_a2, gmock_a3); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A(), \ + ::testing::A(), \ + ::testing::A()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(3, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ - __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 4), \ - this_method_does_not_take_4_arguments); \ - GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(4, constness, \ - Method).Invoke(::testing::internal::forward(gmock_a1), \ - ::testing::internal::forward(gmock_a2), \ - ::testing::internal::forward(gmock_a3), \ - ::testing::internal::forward(gmock_a4)); \ - } \ - ::testing::MockSpec<__VA_ARGS__> \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4) constness { \ - GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(4, constness, \ - Method) +#define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size::ArgumentTuple>::value == 4), \ + this_method_does_not_take_4_arguments); \ + GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(4, constness, Method) \ + .Invoke(::testing::internal::forward( \ + gmock_a1), \ + ::testing::internal::forward( \ + gmock_a2), \ + ::testing::internal::forward( \ + gmock_a3), \ + ::testing::internal::forward( \ + gmock_a4)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4) constness { \ + GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(4, constness, Method) \ + .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(4, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ - __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ - __VA_ARGS__) gmock_a5) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 5), \ - this_method_does_not_take_5_arguments); \ - GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(5, constness, \ - Method).Invoke(::testing::internal::forward(gmock_a1), \ - ::testing::internal::forward(gmock_a2), \ - ::testing::internal::forward(gmock_a3), \ - ::testing::internal::forward(gmock_a4), \ - ::testing::internal::forward(gmock_a5)); \ - } \ - ::testing::MockSpec<__VA_ARGS__> \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5) constness { \ - GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(5, constness, \ - Method) +#define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size::ArgumentTuple>::value == 5), \ + this_method_does_not_take_5_arguments); \ + GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(5, constness, Method) \ + .Invoke(::testing::internal::forward( \ + gmock_a1), \ + ::testing::internal::forward( \ + gmock_a2), \ + ::testing::internal::forward( \ + gmock_a3), \ + ::testing::internal::forward( \ + gmock_a4), \ + ::testing::internal::forward( \ + gmock_a5)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5) constness { \ + GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(5, constness, Method) \ + .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(5, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ - __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ - __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, \ - __VA_ARGS__) gmock_a6) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 6), \ - this_method_does_not_take_6_arguments); \ - GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(6, constness, \ - Method).Invoke(::testing::internal::forward(gmock_a1), \ - ::testing::internal::forward(gmock_a2), \ - ::testing::internal::forward(gmock_a3), \ - ::testing::internal::forward(gmock_a4), \ - ::testing::internal::forward(gmock_a5), \ - ::testing::internal::forward(gmock_a6)); \ - } \ - ::testing::MockSpec<__VA_ARGS__> \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6) constness { \ - GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(6, constness, \ - Method) +#define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size::ArgumentTuple>::value == 6), \ + this_method_does_not_take_6_arguments); \ + GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(6, constness, Method) \ + .Invoke(::testing::internal::forward( \ + gmock_a1), \ + ::testing::internal::forward( \ + gmock_a2), \ + ::testing::internal::forward( \ + gmock_a3), \ + ::testing::internal::forward( \ + gmock_a4), \ + ::testing::internal::forward( \ + gmock_a5), \ + ::testing::internal::forward( \ + gmock_a6)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6) constness { \ + GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(6, constness, Method) \ + .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(6, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ - __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ - __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 7), \ - this_method_does_not_take_7_arguments); \ - GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(7, constness, \ - Method).Invoke(::testing::internal::forward(gmock_a1), \ - ::testing::internal::forward(gmock_a2), \ - ::testing::internal::forward(gmock_a3), \ - ::testing::internal::forward(gmock_a4), \ - ::testing::internal::forward(gmock_a5), \ - ::testing::internal::forward(gmock_a6), \ - ::testing::internal::forward(gmock_a7)); \ - } \ - ::testing::MockSpec<__VA_ARGS__> \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7) constness { \ - GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(7, constness, \ - Method) +#define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size::ArgumentTuple>::value == 7), \ + this_method_does_not_take_7_arguments); \ + GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(7, constness, Method) \ + .Invoke(::testing::internal::forward( \ + gmock_a1), \ + ::testing::internal::forward( \ + gmock_a2), \ + ::testing::internal::forward( \ + gmock_a3), \ + ::testing::internal::forward( \ + gmock_a4), \ + ::testing::internal::forward( \ + gmock_a5), \ + ::testing::internal::forward( \ + gmock_a6), \ + ::testing::internal::forward( \ + gmock_a7)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7) constness { \ + GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(7, constness, Method) \ + .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5, gmock_a6, \ + gmock_a7); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(7, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ - __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ - __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \ - __VA_ARGS__) gmock_a8) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 8), \ - this_method_does_not_take_8_arguments); \ - GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(8, constness, \ - Method).Invoke(::testing::internal::forward(gmock_a1), \ - ::testing::internal::forward(gmock_a2), \ - ::testing::internal::forward(gmock_a3), \ - ::testing::internal::forward(gmock_a4), \ - ::testing::internal::forward(gmock_a5), \ - ::testing::internal::forward(gmock_a6), \ - ::testing::internal::forward(gmock_a7), \ - ::testing::internal::forward(gmock_a8)); \ - } \ - ::testing::MockSpec<__VA_ARGS__> \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ - GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8) constness { \ - GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(8, constness, \ - Method) +#define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size::ArgumentTuple>::value == 8), \ + this_method_does_not_take_8_arguments); \ + GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(8, constness, Method) \ + .Invoke(::testing::internal::forward( \ + gmock_a1), \ + ::testing::internal::forward( \ + gmock_a2), \ + ::testing::internal::forward( \ + gmock_a3), \ + ::testing::internal::forward( \ + gmock_a4), \ + ::testing::internal::forward( \ + gmock_a5), \ + ::testing::internal::forward( \ + gmock_a6), \ + ::testing::internal::forward( \ + gmock_a7), \ + ::testing::internal::forward( \ + gmock_a8)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8) constness { \ + GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(8, constness, Method) \ + .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5, gmock_a6, \ + gmock_a7, gmock_a8); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(8, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ - __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ - __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \ - __VA_ARGS__) gmock_a8, GMOCK_ARG_(tn, 9, \ - __VA_ARGS__) gmock_a9) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 9), \ - this_method_does_not_take_9_arguments); \ - GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(9, constness, \ - Method).Invoke(::testing::internal::forward(gmock_a1), \ - ::testing::internal::forward(gmock_a2), \ - ::testing::internal::forward(gmock_a3), \ - ::testing::internal::forward(gmock_a4), \ - ::testing::internal::forward(gmock_a5), \ - ::testing::internal::forward(gmock_a6), \ - ::testing::internal::forward(gmock_a7), \ - ::testing::internal::forward(gmock_a8), \ - ::testing::internal::forward(gmock_a9)); \ - } \ - ::testing::MockSpec<__VA_ARGS__> \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ - GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \ - GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9) constness { \ - GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(9, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \ - gmock_a9); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(9, constness, \ - Method) +#define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \ + GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size::ArgumentTuple>::value == 9), \ + this_method_does_not_take_9_arguments); \ + GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(9, constness, Method) \ + .Invoke(::testing::internal::forward( \ + gmock_a1), \ + ::testing::internal::forward( \ + gmock_a2), \ + ::testing::internal::forward( \ + gmock_a3), \ + ::testing::internal::forward( \ + gmock_a4), \ + ::testing::internal::forward( \ + gmock_a5), \ + ::testing::internal::forward( \ + gmock_a6), \ + ::testing::internal::forward( \ + gmock_a7), \ + ::testing::internal::forward( \ + gmock_a8), \ + ::testing::internal::forward( \ + gmock_a9)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \ + GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9) constness { \ + GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(9, constness, Method) \ + .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5, gmock_a6, \ + gmock_a7, gmock_a8, gmock_a9); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(9, constness, \ + Method) // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \ - GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ - GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ - __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ - __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \ - __VA_ARGS__) gmock_a8, GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \ - GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \ - GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ - tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ - == 10), \ - this_method_does_not_take_10_arguments); \ - GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(10, constness, \ - Method).Invoke(::testing::internal::forward(gmock_a1), \ - ::testing::internal::forward(gmock_a2), \ - ::testing::internal::forward(gmock_a3), \ - ::testing::internal::forward(gmock_a4), \ - ::testing::internal::forward(gmock_a5), \ - ::testing::internal::forward(gmock_a6), \ - ::testing::internal::forward(gmock_a7), \ - ::testing::internal::forward(gmock_a8), \ - ::testing::internal::forward(gmock_a9), \ - ::testing::internal::forward(gmock_a10)); \ - } \ - ::testing::MockSpec<__VA_ARGS__> \ - gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ - GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ - GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ - GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ - GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ - GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ - GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ - GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \ - GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9, \ - GMOCK_MATCHER_(tn, 10, \ - __VA_ARGS__) gmock_a10) constness { \ - GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(10, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \ - gmock_a10); \ - } \ - mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(10, constness, \ - Method) +#define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \ + GMOCK_RESULT_(tn, __VA_ARGS__) \ + ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \ + GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \ + GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \ + GTEST_COMPILE_ASSERT_( \ + (::testing::tuple_size::ArgumentTuple>::value == 10), \ + this_method_does_not_take_10_arguments); \ + GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \ + return GMOCK_MOCKER_(10, constness, Method) \ + .Invoke(::testing::internal::forward( \ + gmock_a1), \ + ::testing::internal::forward( \ + gmock_a2), \ + ::testing::internal::forward( \ + gmock_a3), \ + ::testing::internal::forward( \ + gmock_a4), \ + ::testing::internal::forward( \ + gmock_a5), \ + ::testing::internal::forward( \ + gmock_a6), \ + ::testing::internal::forward( \ + gmock_a7), \ + ::testing::internal::forward( \ + gmock_a8), \ + ::testing::internal::forward( \ + gmock_a9), \ + ::testing::internal::forward( \ + gmock_a10)); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ + GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ + GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ + GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ + GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ + GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ + GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ + GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \ + GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9, \ + GMOCK_MATCHER_(tn, 10, __VA_ARGS__) gmock_a10) constness { \ + GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \ + return GMOCK_MOCKER_(10, constness, Method) \ + .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5, gmock_a6, \ + gmock_a7, gmock_a8, gmock_a9, gmock_a10); \ + } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>*) const { \ + return ::testing::internal::AdjustConstness_##constness(this) \ + ->gmock_##Method(::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A(), \ + ::testing::A()); \ + } \ + mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(10, constness, \ + Method) #define MOCK_METHOD0(m, ...) GMOCK_METHOD0_(, , , m, __VA_ARGS__) #define MOCK_METHOD1(m, ...) GMOCK_METHOD1_(, , , m, __VA_ARGS__) diff --git a/googlemock/include/gmock/gmock-generated-function-mockers.h.pump b/googlemock/include/gmock/gmock-generated-function-mockers.h.pump index 277003b..efcb3e8 100644 --- a/googlemock/include/gmock/gmock-generated-function-mockers.h.pump +++ b/googlemock/include/gmock/gmock-generated-function-mockers.h.pump @@ -94,6 +94,58 @@ class FunctionMocker : public ]] +// Removes the given pointer; this is a helper for the expectation setter method +// for parameterless matchers. +// +// We want to make sure that the user cannot set a parameterless expectation on +// overloaded methods, including methods which are overloaded on const. Example: +// +// class MockClass { +// MOCK_METHOD0(GetName, string&()); +// MOCK_CONST_METHOD0(GetName, const string&()); +// }; +// +// TEST() { +// // This should be an error, as it's not clear which overload is expected. +// EXPECT_CALL(mock, GetName).WillOnce(ReturnRef(value)); +// } +// +// Here are the generated expectation-setter methods: +// +// class MockClass { +// // Overload 1 +// MockSpec gmock_GetName() { … } +// // Overload 2. Declared const so that the compiler will generate an +// // error when trying to resolve between this and overload 4 in +// // 'gmock_GetName(WithoutMatchers(), nullptr)'. +// MockSpec gmock_GetName( +// const WithoutMatchers&, const Function*) const { +// // Removes const from this, calls overload 1 +// return AdjustConstness_(this)->gmock_GetName(); +// } +// +// // Overload 3 +// const string& gmock_GetName() const { … } +// // Overload 4 +// MockSpec gmock_GetName( +// const WithoutMatchers&, const Function*) const { +// // Does not remove const, calls overload 3 +// return AdjustConstness_const(this)->gmock_GetName(); +// } +// } +// +template +const MockType* AdjustConstness_const(const MockType* mock) { + return mock; +} + +// Removes const from and returns the given pointer; this is a helper for the +// expectation setter method for parameterless matchers. +template +MockType* AdjustConstness_(const MockType* mock) { + return const_cast(mock); +} + } // namespace internal // The style guide prohibits "using" statements in a namespace scope @@ -135,6 +187,8 @@ $var as = [[$for j, \ $var matcher_arg_as = [[$for j, \ [[GMOCK_MATCHER_(tn, $j, __VA_ARGS__) gmock_a$j]]]] $var matcher_as = [[$for j, [[gmock_a$j]]]] +$var anything_matchers = [[$for j, \ + [[::testing::A()]]]] // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! #define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, ...) \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ @@ -150,6 +204,12 @@ $var matcher_as = [[$for j, [[gmock_a$j]]]] GMOCK_MOCKER_($i, constness, Method).RegisterOwner(this); \ return GMOCK_MOCKER_($i, constness, Method).With($matcher_as); \ } \ + ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ + const ::testing::internal::WithoutMatchers&, \ + constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ + return ::testing::internal::AdjustConstness_##constness(this)-> \ + gmock_##Method($anything_matchers); \ + } \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_($i, constness, Method) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 3a2b944..e0a7864 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -1718,25 +1718,27 @@ class NotMatcher { // that will prevent different instantiations of BothOfMatcher from // sharing the same BothOfMatcherImpl class. template -class BothOfMatcherImpl +class AllOfMatcherImpl : public MatcherInterface { public: - BothOfMatcherImpl(const Matcher& matcher1, const Matcher& matcher2) - : matcher1_(matcher1), matcher2_(matcher2) {} + explicit AllOfMatcherImpl(std::vector > matchers) + : matchers_(internal::move(matchers)) {} virtual void DescribeTo(::std::ostream* os) const { *os << "("; - matcher1_.DescribeTo(os); - *os << ") and ("; - matcher2_.DescribeTo(os); + for (size_t i = 0; i < matchers_.size(); ++i) { + if (i != 0) *os << ") and ("; + matchers_[i].DescribeTo(os); + } *os << ")"; } virtual void DescribeNegationTo(::std::ostream* os) const { *os << "("; - matcher1_.DescribeNegationTo(os); - *os << ") or ("; - matcher2_.DescribeNegationTo(os); + for (size_t i = 0; i < matchers_.size(); ++i) { + if (i != 0) *os << ") or ("; + matchers_[i].DescribeNegationTo(os); + } *os << ")"; } @@ -1744,93 +1746,38 @@ class BothOfMatcherImpl MatchResultListener* listener) const { // If either matcher1_ or matcher2_ doesn't match x, we only need // to explain why one of them fails. - StringMatchResultListener listener1; - if (!matcher1_.MatchAndExplain(x, &listener1)) { - *listener << listener1.str(); - return false; - } + std::string all_match_result; - StringMatchResultListener listener2; - if (!matcher2_.MatchAndExplain(x, &listener2)) { - *listener << listener2.str(); - return false; + for (size_t i = 0; i < matchers_.size(); ++i) { + StringMatchResultListener slistener; + if (matchers_[i].MatchAndExplain(x, &slistener)) { + if (all_match_result.empty()) { + all_match_result = slistener.str(); + } else { + std::string result = slistener.str(); + if (!result.empty()) { + all_match_result += ", and "; + all_match_result += result; + } + } + } else { + *listener << slistener.str(); + return false; + } } // Otherwise we need to explain why *both* of them match. - const std::string s1 = listener1.str(); - const std::string s2 = listener2.str(); - - if (s1 == "") { - *listener << s2; - } else { - *listener << s1; - if (s2 != "") { - *listener << ", and " << s2; - } - } + *listener << all_match_result; return true; } private: - const Matcher matcher1_; - const Matcher matcher2_; + const std::vector > matchers_; - GTEST_DISALLOW_ASSIGN_(BothOfMatcherImpl); + GTEST_DISALLOW_ASSIGN_(AllOfMatcherImpl); }; #if GTEST_LANG_CXX11 -// MatcherList provides mechanisms for storing a variable number of matchers in -// a list structure (ListType) and creating a combining matcher from such a -// list. -// The template is defined recursively using the following template parameters: -// * kSize is the length of the MatcherList. -// * Head is the type of the first matcher of the list. -// * Tail denotes the types of the remaining matchers of the list. -template -struct MatcherList { - typedef MatcherList MatcherListTail; - typedef ::std::pair ListType; - - // BuildList stores variadic type values in a nested pair structure. - // Example: - // MatcherList<3, int, string, float>::BuildList(5, "foo", 2.0) will return - // the corresponding result of type pair>. - static ListType BuildList(const Head& matcher, const Tail&... tail) { - return ListType(matcher, MatcherListTail::BuildList(tail...)); - } - - // CreateMatcher creates a Matcher from a given list of matchers (built - // by BuildList()). CombiningMatcher is used to combine the matchers of the - // list. CombiningMatcher must implement MatcherInterface and have a - // constructor taking two Matchers as input. - template class CombiningMatcher> - static Matcher CreateMatcher(const ListType& matchers) { - return Matcher(new CombiningMatcher( - SafeMatcherCast(matchers.first), - MatcherListTail::template CreateMatcher( - matchers.second))); - } -}; - -// The following defines the base case for the recursive definition of -// MatcherList. -template -struct MatcherList<2, Matcher1, Matcher2> { - typedef ::std::pair ListType; - - static ListType BuildList(const Matcher1& matcher1, - const Matcher2& matcher2) { - return ::std::pair(matcher1, matcher2); - } - - template class CombiningMatcher> - static Matcher CreateMatcher(const ListType& matchers) { - return Matcher(new CombiningMatcher( - SafeMatcherCast(matchers.first), - SafeMatcherCast(matchers.second))); - } -}; - // VariadicMatcher is used for the variadic implementation of // AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...). // CombiningMatcher is used to recursively combine the provided matchers @@ -1839,27 +1786,40 @@ template