From e857f9cdd998136b9aad634272301f5b2d0476ea Mon Sep 17 00:00:00 2001 From: misterg Date: Tue, 30 Oct 2018 09:49:22 -0400 Subject: Googletest export Remove scoped_ptr replace with std::unique_ptr PiperOrigin-RevId: 219291284 --- googlemock/include/gmock/gmock-spec-builders.h | 2 +- googlemock/test/gmock-matchers_test.cc | 2 - googletest/include/gtest/gtest-message.h | 3 +- googletest/include/gtest/gtest.h | 11 ++--- .../gtest/internal/gtest-death-test-internal.h | 3 +- .../include/gtest/internal/gtest-param-util.h | 8 ++-- googletest/include/gtest/internal/gtest-port.h | 52 +++------------------- googletest/src/gtest-internal-inl.h | 7 +-- googletest/src/gtest-port.cc | 4 +- googletest/test/googletest-output-test_.cc | 3 +- googletest/test/googletest-port-test.cc | 11 +---- googletest/test/googletest-shuffle-test_.cc | 1 - googletest/test/gtest_stress_test.cc | 3 +- 13 files changed, 30 insertions(+), 80 deletions(-) diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index c0df5cc..e58adfc 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -1598,7 +1598,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { // 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( + std::unique_ptr holder( DownCast_(this->UntypedInvokeWith(untyped_args))); return holder->Unwrap(); } diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 6f04248..347c2c7 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -145,10 +145,8 @@ using testing::internal::FormatMatcherDescription; using testing::internal::IsReadableTypeName; using testing::internal::MatchMatrix; using testing::internal::RE; -using testing::internal::scoped_ptr; using testing::internal::StreamMatchResultListener; using testing::internal::Strings; -using testing::internal::scoped_ptr; using testing::internal::string; // For testing ExplainMatchResultTo(). diff --git a/googletest/include/gtest/gtest-message.h b/googletest/include/gtest/gtest-message.h index 4d8373c..79d208a 100644 --- a/googletest/include/gtest/gtest-message.h +++ b/googletest/include/gtest/gtest-message.h @@ -48,6 +48,7 @@ #define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ #include +#include #include "gtest/internal/gtest-port.h" @@ -224,7 +225,7 @@ class GTEST_API_ Message { #endif // GTEST_OS_SYMBIAN // We'll hold the text streamed to this object here. - const internal::scoped_ptr< ::std::stringstream> ss_; + const std::unique_ptr< ::std::stringstream> ss_; // We declare (but don't implement) this to prevent the compiler // from implementing the assignment operator. diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index c19ee2b..e5979a9 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -53,6 +53,7 @@ #define GTEST_INCLUDE_GTEST_GTEST_H_ #include +#include #include #include @@ -361,7 +362,7 @@ class GTEST_API_ AssertionResult { // construct is not satisfied with the predicate's outcome. // Referenced via a pointer to avoid taking too much stack frame space // with test assertions. - internal::scoped_ptr< ::std::string> message_; + std::unique_ptr< ::std::string> message_; }; // Makes a successful assertion result. @@ -493,7 +494,7 @@ class GTEST_API_ Test { // internal method to avoid clashing with names used in user TESTs. void DeleteSelf_() { delete this; } - const internal::scoped_ptr< GTEST_FLAG_SAVER_ > gtest_flag_saver_; + const std::unique_ptr gtest_flag_saver_; // Often a user misspells SetUp() as Setup() and spends a long time // wondering why it is never called by Google Test. The declaration of @@ -796,10 +797,10 @@ class GTEST_API_ TestInfo { const std::string name_; // Test name // Name of the parameter type, or NULL if this is not a typed or a // type-parameterized test. - const internal::scoped_ptr type_param_; + const std::unique_ptr type_param_; // Text representation of the value parameter, or NULL if this is not a // value-parameterized test. - const internal::scoped_ptr value_param_; + const std::unique_ptr value_param_; internal::CodeLocation location_; const internal::TypeId fixture_class_id_; // ID of the test fixture class bool should_run_; // True iff this test should run @@ -983,7 +984,7 @@ class GTEST_API_ TestCase { std::string name_; // Name of the parameter type, or NULL if this is not a typed or a // type-parameterized test. - const internal::scoped_ptr type_param_; + const std::unique_ptr type_param_; // The vector of TestInfos in their original order. It owns the // elements in the vector. std::vector test_info_list_; diff --git a/googletest/include/gtest/internal/gtest-death-test-internal.h b/googletest/include/gtest/internal/gtest-death-test-internal.h index f06cef2..c9d5908 100644 --- a/googletest/include/gtest/internal/gtest-death-test-internal.h +++ b/googletest/include/gtest/internal/gtest-death-test-internal.h @@ -39,6 +39,7 @@ #include "gtest/internal/gtest-internal.h" #include +#include namespace testing { namespace internal { @@ -196,7 +197,7 @@ GTEST_API_ bool ExitedUnsuccessfully(int exit_status); goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \ } \ if (gtest_dt != nullptr) { \ - ::testing::internal::scoped_ptr< ::testing::internal::DeathTest> \ + std::unique_ptr< ::testing::internal::DeathTest> \ gtest_dt_ptr(gtest_dt); \ switch (gtest_dt->AssumeRole()) { \ case ::testing::internal::DeathTest::OVERSEE_TEST: \ diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h index 9eb98b1..e155483 100644 --- a/googletest/include/gtest/internal/gtest-param-util.h +++ b/googletest/include/gtest/internal/gtest-param-util.h @@ -154,7 +154,7 @@ class ParamIterator { private: friend class ParamGenerator; explicit ParamIterator(ParamIteratorInterface* impl) : impl_(impl) {} - scoped_ptr > impl_; + std::unique_ptr > impl_; }; // ParamGeneratorInterface is the binary interface to access generators @@ -354,9 +354,9 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface { // A cached value of *iterator_. We keep it here to allow access by // pointer in the wrapping iterator's operator->(). // value_ needs to be mutable to be accessed in Current(). - // Use of scoped_ptr helps manage cached value's lifetime, + // Use of std::unique_ptr helps manage cached value's lifetime, // which is bound by the lifespan of the iterator itself. - mutable scoped_ptr value_; + mutable std::unique_ptr value_; }; // class ValuesInIteratorRangeGenerator::Iterator // No implementation - assignment is unsupported. @@ -602,7 +602,7 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase { const std::string test_case_base_name; const std::string test_base_name; - const scoped_ptr > test_meta_factory; + const std::unique_ptr > test_meta_factory; }; using TestInfoContainer = ::std::vector >; // Records data received from INSTANTIATE_TEST_CASE_P macros: diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 5e302ae..b618289 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -212,8 +212,6 @@ // IteratorTraits - partial implementation of std::iterator_traits, which // is not available in libCstd when compiled with Sun C++. // -// Smart pointers: -// scoped_ptr - as in TR2. // // Regular expressions: // RE - a simple regular expression class using the POSIX @@ -253,9 +251,11 @@ #include // for isspace, etc #include // for ptrdiff_t -#include #include +#include #include +#include + #ifndef _WIN32_WCE # include # include @@ -1010,48 +1010,6 @@ typedef ::std::wstring wstring; // returns 'condition'. GTEST_API_ bool IsTrue(bool condition); -// Defines scoped_ptr. - -// This implementation of scoped_ptr is PARTIAL - it only contains -// enough stuff to satisfy Google Test's need. -template -class scoped_ptr { - public: - typedef T element_type; - - explicit scoped_ptr(T* p = nullptr) : ptr_(p) {} - ~scoped_ptr() { reset(); } - - T& operator*() const { return *ptr_; } - T* operator->() const { return ptr_; } - T* get() const { return ptr_; } - - T* release() { - T* const ptr = ptr_; - ptr_ = nullptr; - return ptr; - } - - void reset(T* p = nullptr) { - if (p != ptr_) { - if (IsTrue(sizeof(T) > 0)) { // Makes sure T is a complete type. - delete ptr_; - } - ptr_ = p; - } - } - - friend void swap(scoped_ptr& a, scoped_ptr& b) { - using std::swap; - swap(a.ptr_, b.ptr_); - } - - private: - T* ptr_; - - GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr); -}; - // Defines RE. #if GTEST_USES_PCRE @@ -1845,7 +1803,7 @@ class ThreadLocal : public ThreadLocalBase { GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory); }; - scoped_ptr default_factory_; + std::unique_ptr default_factory_; GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal); }; @@ -2056,7 +2014,7 @@ class GTEST_API_ ThreadLocal { // A key pthreads uses for looking up per-thread values. const pthread_key_t key_; - scoped_ptr default_factory_; + std::unique_ptr default_factory_; GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal); }; diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h index f05de04..91f923d 100644 --- a/googletest/src/gtest-internal-inl.h +++ b/googletest/src/gtest-internal-inl.h @@ -42,6 +42,7 @@ #include // For memmove. #include +#include #include #include @@ -913,8 +914,8 @@ class GTEST_API_ UnitTestImpl { #if GTEST_HAS_DEATH_TEST // The decomposed components of the gtest_internal_run_death_test flag, // parsed when RUN_ALL_TESTS is called. - internal::scoped_ptr internal_run_death_test_flag_; - internal::scoped_ptr death_test_factory_; + std::unique_ptr internal_run_death_test_flag_; + std::unique_ptr death_test_factory_; #endif // GTEST_HAS_DEATH_TEST // A per-thread stack of traces created by the SCOPED_TRACE() macro. @@ -1174,7 +1175,7 @@ class StreamingListener : public EmptyTestEventListener { std::string FormatBool(bool value) { return value ? "1" : "0"; } - const scoped_ptr socket_writer_; + const std::unique_ptr socket_writer_; GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamingListener); }; // class StreamingListener diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index 2cac34e..950c16b 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -410,14 +410,14 @@ class ThreadWithParamSupport : public ThreadWithParamBase { : runnable_(runnable), thread_can_start_(thread_can_start) { } - scoped_ptr runnable_; + std::unique_ptr runnable_; // Does not own. Notification* thread_can_start_; }; static DWORD WINAPI ThreadMain(void* ptr) { // Transfers ownership. - scoped_ptr param(static_cast(ptr)); + std::unique_ptr param(static_cast(ptr)); if (param->thread_can_start_ != nullptr) param->thread_can_start_->WaitForNotification(); param->runnable_->Run(); diff --git a/googletest/test/googletest-output-test_.cc b/googletest/test/googletest-output-test_.cc index a24dfce..e3cebf4 100644 --- a/googletest/test/googletest-output-test_.cc +++ b/googletest/test/googletest-output-test_.cc @@ -524,8 +524,7 @@ class DeathTestAndMultiThreadsTest : public testing::Test { private: SpawnThreadNotifications notifications_; - testing::internal::scoped_ptr > - thread_; + std::unique_ptr > thread_; }; #endif // GTEST_IS_THREADSAFE diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc index 2de35e0..e6a227b 100644 --- a/googletest/test/googletest-port-test.cc +++ b/googletest/test/googletest-port-test.cc @@ -37,6 +37,7 @@ #endif // GTEST_OS_MAC #include +#include #include // For std::pair and std::make_pair. #include @@ -218,14 +219,6 @@ TEST(IteratorTraitsTest, WorksForPointerToConst) { IteratorTraits::value_type>(); } -// Tests that the element_type typedef is available in scoped_ptr and refers -// to the parameter type. -TEST(ScopedPtrTest, DefinesElementType) { - StaticAssertTypeEq::element_type>(); -} - -// FIXME: Implement THE REST of scoped_ptr tests. - TEST(GtestCheckSyntaxTest, BehavesLikeASingleStatement) { if (AlwaysFalse()) GTEST_CHECK_(false) << "This should never be executed; " @@ -1095,7 +1088,7 @@ TEST(MutexTest, OnlyOneThreadCanLockAtATime) { typedef ThreadWithParam > ThreadType; const int kCycleCount = 20; const int kThreadCount = 7; - scoped_ptr counting_threads[kThreadCount]; + std::unique_ptr counting_threads[kThreadCount]; Notification threads_can_start; // Creates and runs kThreadCount threads that increment locked_counter // kCycleCount times each. diff --git a/googletest/test/googletest-shuffle-test_.cc b/googletest/test/googletest-shuffle-test_.cc index 1fe5f6a..e72f157 100644 --- a/googletest/test/googletest-shuffle-test_.cc +++ b/googletest/test/googletest-shuffle-test_.cc @@ -41,7 +41,6 @@ using ::testing::Test; using ::testing::TestEventListeners; using ::testing::TestInfo; using ::testing::UnitTest; -using ::testing::internal::scoped_ptr; // The test methods are empty, as the sole purpose of this program is // to print the test names before/after shuffling. diff --git a/googletest/test/gtest_stress_test.cc b/googletest/test/gtest_stress_test.cc index 3af1403..8434819 100644 --- a/googletest/test/gtest_stress_test.cc +++ b/googletest/test/gtest_stress_test.cc @@ -45,7 +45,6 @@ namespace { using internal::Notification; using internal::TestPropertyKeyIs; using internal::ThreadWithParam; -using internal::scoped_ptr; // In order to run tests in this file, for platforms where Google Test is // thread safe, implement ThreadWithParam. See the description of its API @@ -119,7 +118,7 @@ void CheckTestFailureCount(int expected_failures) { // concurrently. TEST(StressTest, CanUseScopedTraceAndAssertionsInManyThreads) { { - scoped_ptr > threads[kThreadCount]; + std::unique_ptr > threads[kThreadCount]; Notification threads_can_start; for (int i = 0; i != kThreadCount; i++) threads[i].reset(new ThreadWithParam(&ManyAsserts, -- cgit v0.12