Googletest export
Remove linked_ptr and use std::shared_ptr instead PiperOrigin-RevId: 218571466
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
@@ -346,9 +347,7 @@ class ActionInterface {
|
||||
// An Action<F> is a copyable and IMMUTABLE (except by assignment)
|
||||
// object that represents an action to be taken when a mock function
|
||||
// of type F is called. The implementation of Action<T> is just a
|
||||
// linked_ptr to const ActionInterface<T>, so copying is fairly cheap.
|
||||
// Don't inherit from Action!
|
||||
//
|
||||
// std::shared_ptr to const ActionInterface<T>. Don't inherit from Action!
|
||||
// You can view an object implementing ActionInterface<F> as a
|
||||
// concrete action (including its current state), and an Action<F>
|
||||
// object as a handle to it.
|
||||
@@ -425,7 +424,7 @@ class Action {
|
||||
#if GTEST_LANG_CXX11
|
||||
::std::function<F> fun_;
|
||||
#endif
|
||||
internal::linked_ptr<ActionInterface<F> > impl_;
|
||||
std::shared_ptr<ActionInterface<F>> impl_;
|
||||
};
|
||||
|
||||
// The PolymorphicAction class template makes it easy to implement a
|
||||
@@ -519,7 +518,7 @@ class ActionAdaptor : public ActionInterface<F1> {
|
||||
}
|
||||
|
||||
private:
|
||||
const internal::linked_ptr<ActionInterface<F2> > impl_;
|
||||
const std::shared_ptr<ActionInterface<F2>> impl_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(ActionAdaptor);
|
||||
};
|
||||
@@ -601,7 +600,7 @@ class ReturnAction {
|
||||
// Result to call. ImplicitCast_ forces the compiler to convert R to
|
||||
// Result without considering explicit constructors, thus resolving the
|
||||
// ambiguity. value_ is then initialized using its copy constructor.
|
||||
explicit Impl(const linked_ptr<R>& value)
|
||||
explicit Impl(const std::shared_ptr<R>& value)
|
||||
: value_before_cast_(*value),
|
||||
value_(ImplicitCast_<Result>(value_before_cast_)) {}
|
||||
|
||||
@@ -626,7 +625,7 @@ class ReturnAction {
|
||||
typedef typename Function<F>::Result Result;
|
||||
typedef typename Function<F>::ArgumentTuple ArgumentTuple;
|
||||
|
||||
explicit Impl(const linked_ptr<R>& wrapper)
|
||||
explicit Impl(const std::shared_ptr<R>& wrapper)
|
||||
: performed_(false), wrapper_(wrapper) {}
|
||||
|
||||
virtual Result Perform(const ArgumentTuple&) {
|
||||
@@ -638,12 +637,12 @@ class ReturnAction {
|
||||
|
||||
private:
|
||||
bool performed_;
|
||||
const linked_ptr<R> wrapper_;
|
||||
const std::shared_ptr<R> wrapper_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(Impl);
|
||||
};
|
||||
|
||||
const linked_ptr<R> value_;
|
||||
const std::shared_ptr<R> value_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(ReturnAction);
|
||||
};
|
||||
@@ -866,7 +865,7 @@ class SetArgumentPointeeAction<N, Proto, true> {
|
||||
}
|
||||
|
||||
private:
|
||||
const internal::linked_ptr<Proto> proto_;
|
||||
const std::shared_ptr<Proto> proto_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
|
||||
};
|
||||
@@ -931,7 +930,7 @@ class InvokeCallbackWithoutArgsAction {
|
||||
Result Perform(const ArgumentTuple&) const { return callback_->Run(); }
|
||||
|
||||
private:
|
||||
const internal::linked_ptr<CallbackType> callback_;
|
||||
const std::shared_ptr<CallbackType> callback_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(InvokeCallbackWithoutArgsAction);
|
||||
};
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
|
||||
|
||||
#include <limits.h>
|
||||
#include <memory>
|
||||
#include <ostream> // NOLINT
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
#include "gtest/gtest.h"
|
||||
@@ -81,9 +82,8 @@ class CardinalityInterface {
|
||||
|
||||
// A Cardinality is a copyable and IMMUTABLE (except by assignment)
|
||||
// object that specifies how many times a mock function is expected to
|
||||
// be called. The implementation of Cardinality is just a linked_ptr
|
||||
// to const CardinalityInterface, so copying is fairly cheap.
|
||||
// Don't inherit from Cardinality!
|
||||
// be called. The implementation of Cardinality is just a std::shared_ptr
|
||||
// to const CardinalityInterface. Don't inherit from Cardinality!
|
||||
class GTEST_API_ Cardinality {
|
||||
public:
|
||||
// Constructs a null cardinality. Needed for storing Cardinality
|
||||
@@ -123,7 +123,7 @@ class GTEST_API_ Cardinality {
|
||||
::std::ostream* os);
|
||||
|
||||
private:
|
||||
internal::linked_ptr<const CardinalityInterface> impl_;
|
||||
std::shared_ptr<const CardinalityInterface> impl_;
|
||||
};
|
||||
|
||||
// Creates a cardinality that allows at least n calls.
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "gmock/gmock-actions.h"
|
||||
@@ -348,7 +349,7 @@ class InvokeCallbackAction {
|
||||
callback_.get(), args);
|
||||
}
|
||||
private:
|
||||
const linked_ptr<CallbackType> callback_;
|
||||
const std::shared_ptr<CallbackType> callback_;
|
||||
};
|
||||
|
||||
// An INTERNAL macro for extracting the type of a tuple field. It's
|
||||
|
||||
@@ -43,6 +43,7 @@ $$}} This meta comment fixes auto-indentation in editors.
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "gmock/gmock-actions.h"
|
||||
@@ -118,7 +119,7 @@ class InvokeCallbackAction {
|
||||
callback_.get(), args);
|
||||
}
|
||||
private:
|
||||
const linked_ptr<CallbackType> callback_;
|
||||
const std::shared_ptr<CallbackType> callback_;
|
||||
};
|
||||
|
||||
// An INTERNAL macro for extracting the type of a tuple field. It's
|
||||
|
||||
@@ -43,14 +43,15 @@
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <ostream> // NOLINT
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/internal/gmock-internal-utils.h"
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#if GTEST_HAS_STD_INITIALIZER_LIST_
|
||||
# include <initializer_list> // NOLINT -- must be after gtest.h
|
||||
@@ -338,29 +339,15 @@ class MatcherBase {
|
||||
virtual ~MatcherBase() {}
|
||||
|
||||
private:
|
||||
// shared_ptr (util/gtl/shared_ptr.h) and linked_ptr have similar
|
||||
// interfaces. The former dynamically allocates a chunk of memory
|
||||
// to hold the reference count, while the latter tracks all
|
||||
// references using a circular linked list without allocating
|
||||
// memory. It has been observed that linked_ptr performs better in
|
||||
// typical scenarios. However, shared_ptr can out-perform
|
||||
// linked_ptr when there are many more uses of the copy constructor
|
||||
// than the default constructor.
|
||||
//
|
||||
// If performance becomes a problem, we should see if using
|
||||
// shared_ptr helps.
|
||||
::testing::internal::linked_ptr<
|
||||
const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> >
|
||||
impl_;
|
||||
std::shared_ptr<const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>> impl_;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// A Matcher<T> is a copyable and IMMUTABLE (except by assignment)
|
||||
// object that can check whether a value of type T matches. The
|
||||
// implementation of Matcher<T> is just a linked_ptr to const
|
||||
// MatcherInterface<T>, so copying is fairly cheap. Don't inherit
|
||||
// from Matcher!
|
||||
// implementation of Matcher<T> is just a std::shared_ptr to const
|
||||
// MatcherInterface<T>. Don't inherit from Matcher!
|
||||
template <typename T>
|
||||
class Matcher : public internal::MatcherBase<T> {
|
||||
public:
|
||||
@@ -1586,7 +1573,7 @@ class MatchesRegexMatcher {
|
||||
}
|
||||
|
||||
private:
|
||||
const internal::linked_ptr<const RE> regex_;
|
||||
const std::shared_ptr<const RE> regex_;
|
||||
const bool full_match_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(MatchesRegexMatcher);
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@@ -219,8 +220,7 @@ class GTEST_API_ UntypedFunctionMockerBase {
|
||||
protected:
|
||||
typedef std::vector<const void*> UntypedOnCallSpecs;
|
||||
|
||||
typedef std::vector<internal::linked_ptr<ExpectationBase> >
|
||||
UntypedExpectations;
|
||||
using UntypedExpectations = std::vector<std::shared_ptr<ExpectationBase>>;
|
||||
|
||||
// Returns an Expectation object that references and co-owns exp,
|
||||
// which must be an expectation on this mock function.
|
||||
@@ -498,12 +498,7 @@ class GTEST_API_ Mock {
|
||||
// - Constness is shallow: a const Expectation object itself cannot
|
||||
// be modified, but the mutable methods of the ExpectationBase
|
||||
// object it references can be called via expectation_base().
|
||||
// - The constructors and destructor are defined out-of-line because
|
||||
// the Symbian WINSCW compiler wants to otherwise instantiate them
|
||||
// when it sees this class definition, at which point it doesn't have
|
||||
// ExpectationBase available yet, leading to incorrect destruction
|
||||
// in the linked_ptr (or compilation errors if using a checking
|
||||
// linked_ptr).
|
||||
|
||||
class GTEST_API_ Expectation {
|
||||
public:
|
||||
// Constructs a null object that doesn't reference any expectation.
|
||||
@@ -555,16 +550,15 @@ class GTEST_API_ Expectation {
|
||||
typedef ::std::set<Expectation, Less> Set;
|
||||
|
||||
Expectation(
|
||||
const internal::linked_ptr<internal::ExpectationBase>& expectation_base);
|
||||
const std::shared_ptr<internal::ExpectationBase>& expectation_base);
|
||||
|
||||
// Returns the expectation this object references.
|
||||
const internal::linked_ptr<internal::ExpectationBase>&
|
||||
expectation_base() const {
|
||||
const std::shared_ptr<internal::ExpectationBase>& expectation_base() const {
|
||||
return expectation_base_;
|
||||
}
|
||||
|
||||
// A linked_ptr that co-owns the expectation this handle references.
|
||||
internal::linked_ptr<internal::ExpectationBase> expectation_base_;
|
||||
// A shared_ptr that co-owns the expectation this handle references.
|
||||
std::shared_ptr<internal::ExpectationBase> expectation_base_;
|
||||
};
|
||||
|
||||
// A set of expectation handles. Useful in the .After() clause of
|
||||
@@ -646,11 +640,8 @@ class GTEST_API_ Sequence {
|
||||
void AddExpectation(const Expectation& expectation) const;
|
||||
|
||||
private:
|
||||
// The last expectation in this sequence. We use a linked_ptr here
|
||||
// because Sequence objects are copyable and we want the copies to
|
||||
// be aliases. The linked_ptr allows the copies to co-own and share
|
||||
// the same Expectation object.
|
||||
internal::linked_ptr<Expectation> last_expectation_;
|
||||
// The last expectation in this sequence.
|
||||
std::shared_ptr<Expectation> last_expectation_;
|
||||
}; // class Sequence
|
||||
|
||||
// An object of this type causes all EXPECT_CALL() statements
|
||||
@@ -873,7 +864,7 @@ class GTEST_API_ ExpectationBase {
|
||||
Cardinality cardinality_; // The cardinality of the expectation.
|
||||
// The immediate pre-requisites (i.e. expectations that must be
|
||||
// satisfied before this expectation can be matched) of this
|
||||
// expectation. We use linked_ptr in the set because we want an
|
||||
// expectation. We use std::shared_ptr in the set because we want an
|
||||
// Expectation object to be co-owned by its FunctionMocker and its
|
||||
// successors. This allows multiple mock objects to be deleted at
|
||||
// different times.
|
||||
@@ -1631,7 +1622,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
||||
Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
|
||||
TypedExpectation<F>* const expectation =
|
||||
new TypedExpectation<F>(this, file, line, source_text, m);
|
||||
const linked_ptr<ExpectationBase> untyped_expectation(expectation);
|
||||
const std::shared_ptr<ExpectationBase> untyped_expectation(expectation);
|
||||
// See the definition of untyped_expectations_ for why access to
|
||||
// it is unprotected here.
|
||||
untyped_expectations_.push_back(untyped_expectation);
|
||||
|
||||
@@ -92,15 +92,6 @@ inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) {
|
||||
template <typename Element>
|
||||
inline Element* GetRawPointer(Element* p) { return p; }
|
||||
|
||||
// This comparator allows linked_ptr to be stored in sets.
|
||||
template <typename T>
|
||||
struct LinkedPtrLessThan {
|
||||
bool operator()(const ::testing::internal::linked_ptr<T>& lhs,
|
||||
const ::testing::internal::linked_ptr<T>& rhs) const {
|
||||
return lhs.get() < rhs.get();
|
||||
}
|
||||
};
|
||||
|
||||
// Symbian compilation can be done with wchar_t being either a native
|
||||
// type or a typedef. Using Google Mock with OpenC without wchar_t
|
||||
// should require the definition of _STLP_NO_WCHAR_T.
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
// here, as Google Mock depends on Google Test. Only add a utility
|
||||
// here if it's truly specific to Google Mock.
|
||||
|
||||
#include "gtest/internal/gtest-linked_ptr.h"
|
||||
#include "gtest/internal/gtest-port.h"
|
||||
#include "gmock/internal/custom/gmock-port.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user