From 9571b28675a5a602ed3c8a7acf270d03aca69c96 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 7 Aug 2009 07:15:56 +0000 Subject: [PATCH] Removes duplicated definition of SetArgumentPointee (by Vlad Losev); Makes gmock compilable on platforms that don't have ::abort() (by Acadeli Checa); Fixes compatibility with Symbian's STLport (by Acadeli Checa). --- include/gmock/gmock-actions.h | 43 ----------------------------- include/gmock/internal/gmock-port.h | 2 +- src/gmock-internal-utils.cc | 2 +- src/gmock-spec-builders.cc | 18 ++++++------ test/gmock-spec-builders_test.cc | 15 ++++++++++ 5 files changed, 27 insertions(+), 53 deletions(-) diff --git a/include/gmock/gmock-actions.h b/include/gmock/gmock-actions.h index 49d5532d..c8edc8ab 100644 --- a/include/gmock/gmock-actions.h +++ b/include/gmock/gmock-actions.h @@ -669,39 +669,6 @@ class SetArgumentPointeeAction { const internal::linked_ptr proto_; }; -// Implements the SetArrayArgument(first, last) action for any function -// whose N-th argument (0-based) is a pointer or iterator to a type that can be -// implicitly converted from *first. -template -class SetArrayArgumentAction { - public: - // Constructs an action that sets the variable pointed to by the - // N-th function argument to 'value'. - explicit SetArrayArgumentAction(InputIterator first, InputIterator last) - : first_(first), last_(last) { - } - - template - void Perform(const ArgumentTuple& args) const { - CompileAssertTypesEqual(); - - // Microsoft compiler deprecates ::std::copy, so we want to suppress warning - // 4996 (Function call with parameters that may be unsafe) there. -#if GTEST_OS_WINDOWS -#pragma warning(push) // Saves the current warning state. -#pragma warning(disable:4996) // Temporarily disables warning 4996. -#endif // GTEST_OS_WINDOWS - ::std::copy(first_, last_, ::std::tr1::get(args)); -#if GTEST_OS_WINDOWS -#pragma warning(pop) // Restores the warning state. -#endif // GTEST_OS_WINDOWS - } - - private: - const InputIterator first_; - const InputIterator last_; -}; - // Implements the InvokeWithoutArgs(f) action. The template argument // FunctionImpl is the implementation type of f, which can be either a // function pointer or a functor. InvokeWithoutArgs(f) can be used as an @@ -939,16 +906,6 @@ SetArgumentPointee(const T& x) { N, T, internal::IsAProtocolMessage::value>(x)); } -// Creates an action that sets the elements of the array pointed to by the N-th -// (0-based) function argument, which can be either a pointer or an iterator, -// to the values of the elements in the source range [first, last). -template -PolymorphicAction > -SetArrayArgument(InputIterator first, InputIterator last) { - return MakePolymorphicAction(internal::SetArrayArgumentAction< - N, InputIterator>(first, last)); -} - // Creates an action that sets a pointer referent to a given value. template PolymorphicAction > Assign(T1* ptr, T2 val) { diff --git a/include/gmock/internal/gmock-port.h b/include/gmock/internal/gmock-port.h index 9ee8f728..5b00a41a 100644 --- a/include/gmock/internal/gmock-port.h +++ b/include/gmock/internal/gmock-port.h @@ -274,7 +274,7 @@ class GMockCheckProvider { } ~GMockCheckProvider() { ::std::cerr << ::std::endl; - abort(); + posix::Abort(); } ::std::ostream& GetStream() { return ::std::cerr; } }; diff --git a/src/gmock-internal-utils.cc b/src/gmock-internal-utils.cc index 0e693c70..e72e019b 100644 --- a/src/gmock-internal-utils.cc +++ b/src/gmock-internal-utils.cc @@ -80,7 +80,7 @@ class GoogleTestFailureReporter : public FailureReporterInterface { AssertHelper(type == FATAL ? TPRT_FATAL_FAILURE : TPRT_NONFATAL_FAILURE, file, line, message.c_str()) = Message(); if (type == FATAL) { - abort(); + posix::Abort(); } } }; diff --git a/src/gmock-spec-builders.cc b/src/gmock-spec-builders.cc index 00d16918..94ba24bb 100644 --- a/src/gmock-spec-builders.cc +++ b/src/gmock-spec-builders.cc @@ -186,7 +186,9 @@ class MockObjectRegistry { // object alive. Therefore we report any living object as test // failure, unless the user explicitly asked us to ignore it. ~MockObjectRegistry() { - using ::std::cout; + + // "using ::std::cout;" doesn't work with Symbian's STLport, where cout is + // a macro. if (!GMOCK_FLAG(catch_leaked_mocks)) return; @@ -199,24 +201,24 @@ class MockObjectRegistry { // TODO(wan@google.com): Print the type of the leaked object. // This can help the user identify the leaked object. - cout << "\n"; + std::cout << "\n"; const MockObjectState& state = it->second; internal::FormatFileLocation( - state.first_used_file, state.first_used_line, &cout); - cout << " ERROR: this mock object"; + state.first_used_file, state.first_used_line, &std::cout); + std::cout << " ERROR: this mock object"; if (state.first_used_test != "") { - cout << " (used in test " << state.first_used_test_case << "." + std::cout << " (used in test " << state.first_used_test_case << "." << state.first_used_test << ")"; } - cout << " should be deleted but never is. Its address is @" + std::cout << " should be deleted but never is. Its address is @" << it->first << "."; leaked_count++; } if (leaked_count > 0) { - cout << "\nERROR: " << leaked_count + std::cout << "\nERROR: " << leaked_count << " leaked mock " << (leaked_count == 1 ? "object" : "objects") << " found at program exit.\n"; - cout.flush(); + std::cout.flush(); ::std::cerr.flush(); // RUN_ALL_TESTS() has already returned when this destructor is // called. Therefore we cannot use the normal Google Test diff --git a/test/gmock-spec-builders_test.cc b/test/gmock-spec-builders_test.cc index f6c3141b..de05c574 100644 --- a/test/gmock-spec-builders_test.cc +++ b/test/gmock-spec-builders_test.cc @@ -1429,6 +1429,8 @@ TEST(AfterTest, SucceedsWhenTotalOrderIsSatisfied) { a.DoA(2); } +#if GTEST_HAS_DEATH_TEST + // Calls must be in strict order when specified so. TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo) { MockA a; @@ -1496,6 +1498,8 @@ TEST(AfterTest, CanBeUsedWithInSequence) { a.ReturnResult(3); } +#endif // GTEST_HAS_DEATH_TEST + // .After() can be called multiple times. TEST(AfterTest, CanBeCalledManyTimes) { MockA a; @@ -1532,6 +1536,8 @@ TEST(AfterTest, AcceptsUpToFiveArguments) { a.DoA(6); } +#if GTEST_HAS_DEATH_TEST + // .After() allows input to contain duplicated Expectations. TEST(AfterTest, AcceptsDuplicatedInput) { MockA a; @@ -1551,6 +1557,8 @@ TEST(AfterTest, AcceptsDuplicatedInput) { a.ReturnResult(3); } +#endif // GTEST_HAS_DEATH_TEST + // An Expectation added to an ExpectationSet after it has been used in // an .After() has no effect. TEST(AfterTest, ChangesToExpectationSetHaveNoEffectAfterwards) { @@ -2327,7 +2335,14 @@ void Helper(MockC* c) { } // namespace +// Allows the user to define his own main and then invoke gmock_main +// from it. This might be necessary on some platforms which require +// specific setup and teardown. +#if GMOCK_RENAME_MAIN +int gmock_main(int argc, char **argv) { +#else int main(int argc, char **argv) { +#endif // GMOCK_RENAME_MAIN testing::InitGoogleMock(&argc, argv); // Ensures that the tests pass no matter what value of