From a50e4f05b3d84c6a014c59a24263328242cc8236 Mon Sep 17 00:00:00 2001 From: misterg Date: Wed, 24 Oct 2018 17:02:11 -0400 Subject: Googletest export Remove linked_ptr and use std::shared_ptr instead PiperOrigin-RevId: 218571466 --- googlemock/test/gmock-generated-actions_test.cc | 16 ++--- googlemock/test/gmock-internal-utils_test.cc | 8 +-- googlemock/test/gmock-matchers_test.cc | 32 ++-------- googlemock/test/gmock-more-actions_test.cc | 11 +--- googlemock/test/gmock-spec-builders_test.cc | 8 +-- googlemock/test/gmock_stress_test.cc | 81 ------------------------- 6 files changed, 20 insertions(+), 136 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index 2d663a5e..3111d859 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -35,6 +35,7 @@ #include "gmock/gmock-generated-actions.h" #include +#include #include #include #include "gmock/gmock.h" @@ -1129,9 +1130,9 @@ ACTION_TEMPLATE(ReturnSmartPointer, } TEST(ActionTemplateTest, WorksForTemplateTemplateParameters) { - using ::testing::internal::linked_ptr; - const Action()> a = ReturnSmartPointer(42); - linked_ptr p = a.Perform(std::make_tuple()); + const Action()> a = + ReturnSmartPointer(42); + std::shared_ptr p = a.Perform(std::make_tuple()); EXPECT_EQ(42, *p); } @@ -1161,11 +1162,10 @@ ACTION_TEMPLATE(ReturnGiant, } TEST(ActionTemplateTest, WorksFor10TemplateParameters) { - using ::testing::internal::linked_ptr; - typedef GiantTemplate, bool, double, 5, - true, 6, char, unsigned, int> Giant; - const Action a = ReturnGiant< - int, bool, double, 5, true, 6, char, unsigned, int, linked_ptr>(42); + using Giant = GiantTemplate, bool, double, 5, true, 6, + char, unsigned, int>; + const Action a = ReturnGiant(42); Giant giant = a.Perform(std::make_tuple()); EXPECT_EQ(42, giant.value); } diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index 41498f0e..aa0162b8 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -123,8 +123,6 @@ TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) { } TEST(PointeeOfTest, WorksForSmartPointers) { - CompileAssertTypesEqual >::type>(); #if GTEST_HAS_STD_UNIQUE_PTR_ CompileAssertTypesEqual >::type>(); #endif // GTEST_HAS_STD_UNIQUE_PTR_ @@ -151,10 +149,6 @@ TEST(GetRawPointerTest, WorksForSmartPointers) { const std::shared_ptr p2(raw_p2); EXPECT_EQ(raw_p2, GetRawPointer(p2)); #endif // GTEST_HAS_STD_SHARED_PTR_ - - const char* const raw_p4 = new const char('a'); // NOLINT - const internal::linked_ptr p4(raw_p4); - EXPECT_EQ(raw_p4, GetRawPointer(p4)); } TEST(GetRawPointerTest, WorksForRawPointers) { @@ -687,7 +681,7 @@ TEST(StlContainerViewTest, WorksForDynamicNativeArray) { StlContainerView >::type>(); StaticAssertTypeEq< NativeArray, - StlContainerView, int> >::type>(); + StlContainerView, int> >::type>(); StaticAssertTypeEq< const NativeArray, diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index f4e9e9f7..45006bfb 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -143,13 +143,11 @@ using testing::internal::ExplainMatchFailureTupleTo; using testing::internal::FloatingEqMatcher; using testing::internal::FormatMatcherDescription; using testing::internal::IsReadableTypeName; -using testing::internal::linked_ptr; using testing::internal::MatchMatrix; 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; @@ -1177,24 +1175,6 @@ TEST(IsNullTest, MatchesNullPointer) { #endif } -TEST(IsNullTest, LinkedPtr) { - const Matcher > m = IsNull(); - const linked_ptr null_p; - const linked_ptr non_null_p(new int); - - EXPECT_TRUE(m.Matches(null_p)); - EXPECT_FALSE(m.Matches(non_null_p)); -} - -TEST(IsNullTest, ReferenceToConstLinkedPtr) { - const Matcher&> m = IsNull(); - const linked_ptr null_p; - const linked_ptr non_null_p(new double); - - EXPECT_TRUE(m.Matches(null_p)); - EXPECT_FALSE(m.Matches(non_null_p)); -} - #if GTEST_LANG_CXX11 TEST(IsNullTest, StdFunction) { const Matcher> m = IsNull(); @@ -1226,18 +1206,18 @@ TEST(NotNullTest, MatchesNonNullPointer) { } TEST(NotNullTest, LinkedPtr) { - const Matcher > m = NotNull(); - const linked_ptr null_p; - const linked_ptr non_null_p(new int); + const Matcher> m = NotNull(); + const std::shared_ptr null_p; + const std::shared_ptr non_null_p(new int); EXPECT_FALSE(m.Matches(null_p)); EXPECT_TRUE(m.Matches(non_null_p)); } TEST(NotNullTest, ReferenceToConstLinkedPtr) { - const Matcher&> m = NotNull(); - const linked_ptr null_p; - const linked_ptr non_null_p(new double); + const Matcher&> m = NotNull(); + const std::shared_ptr null_p; + const std::shared_ptr non_null_p(new double); EXPECT_FALSE(m.Matches(null_p)); EXPECT_TRUE(m.Matches(non_null_p)); diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index 521f3058..b4e0fc30 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -35,11 +35,11 @@ #include "gmock/gmock-more-actions.h" #include +#include #include #include #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "gtest/internal/gtest-linked_ptr.h" namespace testing { namespace gmock_more_actions_test { @@ -61,7 +61,6 @@ using testing::StaticAssertTypeEq; using testing::Unused; using testing::WithArg; using testing::WithoutArgs; -using testing::internal::linked_ptr; // For suppressing compiler warnings on conversion possibly losing precision. inline short Short(short n) { return n; } // NOLINT @@ -529,14 +528,6 @@ TEST(SaveArgPointeeActionTest, WorksForCompatibleType) { EXPECT_EQ('a', result); } -TEST(SaveArgPointeeActionTest, WorksForLinkedPtr) { - int result = 0; - linked_ptr value(new int(5)); - const Action)> a1 = SaveArgPointee<0>(&result); - a1.Perform(std::make_tuple(value)); - EXPECT_EQ(5, result); -} - TEST(SetArgRefereeActionTest, WorksForSameType) { int value = 0; const Action a1 = SetArgReferee<0>(1); diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index 65c9fcc4..6502be74 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -34,6 +34,7 @@ #include "gmock/gmock-spec-builders.h" +#include #include // NOLINT #include #include @@ -99,7 +100,6 @@ using testing::internal::kFail; using testing::internal::kInfoVerbosity; using testing::internal::kWarn; using testing::internal::kWarningVerbosity; -using testing::internal::linked_ptr; #if GTEST_HAS_STREAM_REDIRECTION using testing::HasSubstr; @@ -172,7 +172,7 @@ class ReferenceHoldingMock { public: ReferenceHoldingMock() {} - MOCK_METHOD1(AcceptReference, void(linked_ptr*)); + MOCK_METHOD1(AcceptReference, void(std::shared_ptr*)); private: GTEST_DISALLOW_COPY_AND_ASSIGN_(ReferenceHoldingMock); @@ -2619,7 +2619,7 @@ TEST(VerifyAndClearTest, DoesNotAffectOtherMockObjects) { TEST(VerifyAndClearTest, DestroyingChainedMocksDoesNotDeadlockThroughExpectations) { - linked_ptr a(new MockA); + std::shared_ptr a(new MockA); ReferenceHoldingMock test_mock; // EXPECT_CALL stores a reference to a inside test_mock. @@ -2639,7 +2639,7 @@ TEST(VerifyAndClearTest, TEST(VerifyAndClearTest, DestroyingChainedMocksDoesNotDeadlockThroughDefaultAction) { - linked_ptr a(new MockA); + std::shared_ptr a(new MockA); ReferenceHoldingMock test_mock; // ON_CALL stores a reference to a inside test_mock. diff --git a/googlemock/test/gmock_stress_test.cc b/googlemock/test/gmock_stress_test.cc index 9ae0b1e5..20725d69 100644 --- a/googlemock/test/gmock_stress_test.cc +++ b/googlemock/test/gmock_stress_test.cc @@ -60,87 +60,8 @@ void JoinAndDelete(ThreadWithParam* t) { delete t; } -using internal::linked_ptr; - -// Helper classes for testing using linked_ptr concurrently. - -class Base { - public: - explicit Base(int a_x) : x_(a_x) {} - virtual ~Base() {} - int x() const { return x_; } - private: - int x_; -}; - -class Derived1 : public Base { - public: - Derived1(int a_x, int a_y) : Base(a_x), y_(a_y) {} - int y() const { return y_; } - private: - int y_; -}; - -class Derived2 : public Base { - public: - Derived2(int a_x, int a_z) : Base(a_x), z_(a_z) {} - int z() const { return z_; } - private: - int z_; -}; - -linked_ptr pointer1(new Derived1(1, 2)); -linked_ptr pointer2(new Derived2(3, 4)); - struct Dummy {}; -// Tests that we can copy from a linked_ptr and read it concurrently. -void TestConcurrentCopyAndReadLinkedPtr(Dummy /* dummy */) { - // Reads pointer1 and pointer2 while they are being copied from in - // another thread. - EXPECT_EQ(1, pointer1->x()); - EXPECT_EQ(2, pointer1->y()); - EXPECT_EQ(3, pointer2->x()); - EXPECT_EQ(4, pointer2->z()); - - // Copies from pointer1. - linked_ptr p1(pointer1); - EXPECT_EQ(1, p1->x()); - EXPECT_EQ(2, p1->y()); - - // Assigns from pointer2 where the LHS was empty. - linked_ptr p2; - p2 = pointer1; - EXPECT_EQ(1, p2->x()); - - // Assigns from pointer2 where the LHS was not empty. - p2 = pointer2; - EXPECT_EQ(3, p2->x()); -} - -const linked_ptr p0(new Derived1(1, 2)); - -// Tests that we can concurrently modify two linked_ptrs that point to -// the same object. -void TestConcurrentWriteToEqualLinkedPtr(Dummy /* dummy */) { - // p1 and p2 point to the same, shared thing. One thread resets p1. - // Another thread assigns to p2. This will cause the same - // underlying "ring" to be updated concurrently. - linked_ptr p1(p0); - linked_ptr p2(p0); - - EXPECT_EQ(1, p1->x()); - EXPECT_EQ(2, p1->y()); - - EXPECT_EQ(1, p2->x()); - EXPECT_EQ(2, p2->y()); - - p1.reset(); - p2 = p0; - - EXPECT_EQ(1, p2->x()); - EXPECT_EQ(2, p2->y()); -} // Tests that different mock objects can be used in their respective // threads. This should generate no Google Test failure. @@ -275,8 +196,6 @@ void TestPartiallyOrderedExpectationsWithThreads(Dummy /* dummy */) { // Tests using Google Mock constructs in many threads concurrently. TEST(StressTest, CanUseGMockWithThreads) { void (*test_routines[])(Dummy dummy) = { - &TestConcurrentCopyAndReadLinkedPtr, - &TestConcurrentWriteToEqualLinkedPtr, &TestConcurrentMockObjects, &TestConcurrentCallsOnSameObject, &TestPartiallyOrderedExpectationsWithThreads, -- cgit v1.2.3