diff options
author | Gennadiy Civil <misterg@google.com> | 2018-04-10 20:10:34 (GMT) |
---|---|---|
committer | Gennadiy Civil <misterg@google.com> | 2018-04-10 20:10:34 (GMT) |
commit | 39c58da187c9cd54e54560601be4b7ceef320da4 (patch) | |
tree | f74c36bfff352cf49eb110b3f2f6ff57d18dc37f /googlemock/include | |
parent | e1071eb9497304a38e69737e90a88b4877b8b736 (diff) | |
parent | 8fbb4194709cc9fd3de3deb2b406461a173bab15 (diff) | |
download | googletest-39c58da187c9cd54e54560601be4b7ceef320da4.zip googletest-39c58da187c9cd54e54560601be4b7ceef320da4.tar.gz googletest-39c58da187c9cd54e54560601be4b7ceef320da4.tar.bz2 |
merge
Diffstat (limited to 'googlemock/include')
-rw-r--r-- | googlemock/include/gmock/gmock-actions.h | 90 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-more-matchers.h | 8 | ||||
-rw-r--r-- | googlemock/include/gmock/internal/gmock-internal-utils.h | 16 |
3 files changed, 18 insertions, 96 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 <typename G, - typename = typename ::std::enable_if< - ::std::is_constructible<::std::function<F>, G>::value>::type> - Action(G&& fun) : fun_(::std::forward<G>(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<F>* impl) : impl_(impl) {} + // Copy constructor. + Action(const Action& action) : impl_(action.impl_) {} + // This constructor allows us to turn an Action<Func> object into an // Action<F>, 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<Func>& 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 <typename F1, typename F2> friend class internal::ActionAdaptor; - template <typename G> - 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<F> fun_; -#endif internal::linked_ptr<ActionInterface<F> > impl_; }; @@ -556,9 +531,6 @@ struct ByMoveWrapper { // statement, and conversion of the result of Return to Action<T(U)> 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 <typename R> class ReturnAction { public: @@ -778,7 +750,7 @@ class DoDefaultAction { // This template type conversion operator allows DoDefault() to be // used in any function. template <typename F> - operator Action<F>() const { return Action<F>(); } // NOLINT + operator Action<F>() const { return Action<F>(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 <typename CallbackType> -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 <typename Result, typename ArgumentTuple> - Result Perform(const ArgumentTuple&) const { return callback_->Run(); } - - private: - const internal::linked_ptr<CallbackType> callback_; - - GTEST_DISALLOW_ASSIGN_(InvokeCallbackWithoutArgsAction); -}; - // Implements the IgnoreResult(action) action. template <typename A> class IgnoreResultAction { @@ -1103,13 +1053,7 @@ typedef internal::IgnoredValue Unused; template <typename To> template <typename From> Action<To>::Action(const Action<From>& from) - : -#if GTEST_LANG_CXX11 - fun_(from.fun_), -#endif - impl_(from.impl_ == NULL ? NULL - : new internal::ActionAdaptor<To, From>(from)) { -} + : impl_(new internal::ActionAdaptor<To, From>(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-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<bool>(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 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<std::tuple_size<Tuple>::value>()); } #endif - - -#ifdef _MSC_VER -# pragma warning(pop) -#endif - } // namespace internal } // namespace testing |