diff options
Diffstat (limited to 'googlemock/include')
-rw-r--r-- | googlemock/include/gmock/gmock-actions.h | 12 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-cardinalities.h | 4 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-matchers.h | 28 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-nice-strict.h | 2 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-spec-builders.h | 77 | ||||
-rw-r--r-- | googlemock/include/gmock/internal/gmock-internal-utils.h | 7 |
6 files changed, 87 insertions, 43 deletions
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 1cffde2b..bd9ba73e 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -611,7 +611,7 @@ class DefaultValue { private: class ValueProducer { public: - virtual ~ValueProducer() {} + virtual ~ValueProducer() = default; virtual T Produce() = 0; }; @@ -699,8 +699,8 @@ class ActionInterface { typedef typename internal::Function<F>::Result Result; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; - ActionInterface() {} - virtual ~ActionInterface() {} + ActionInterface() = default; + virtual ~ActionInterface() = default; // Performs the action. This method is not const, as in general an // action can have side effects and be stateful. For example, a @@ -749,7 +749,7 @@ class Action<R(Args...)> { // Constructs a null Action. Needed for storing Action objects in // STL containers. - Action() {} + Action() = default; // Construct an Action from a specified callable. // This cannot take std::function directly, because then Action would not be @@ -1273,7 +1273,7 @@ class AssignAction { const T2 value_; }; -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE // Implements the SetErrnoAndReturn action to simulate return from // various system calls and libc functions. @@ -1926,7 +1926,7 @@ PolymorphicAction<internal::AssignAction<T1, T2>> Assign(T1* ptr, T2 val) { return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val)); } -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE // Creates an action that sets errno and returns the appropriate error. template <typename T> diff --git a/googlemock/include/gmock/gmock-cardinalities.h b/googlemock/include/gmock/gmock-cardinalities.h index b6ab648e..533e604f 100644 --- a/googlemock/include/gmock/gmock-cardinalities.h +++ b/googlemock/include/gmock/gmock-cardinalities.h @@ -65,7 +65,7 @@ namespace testing { // The implementation of a cardinality. class CardinalityInterface { public: - virtual ~CardinalityInterface() {} + virtual ~CardinalityInterface() = default; // Conservative estimate on the lower/upper bound of the number of // calls allowed. @@ -92,7 +92,7 @@ class GTEST_API_ Cardinality { public: // Constructs a null cardinality. Needed for storing Cardinality // objects in STL containers. - Cardinality() {} + Cardinality() = default; // Constructs a Cardinality from its implementation. explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {} diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index fc00c356..0f677137 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -257,6 +257,8 @@ #include <algorithm> #include <cmath> +#include <exception> +#include <functional> #include <initializer_list> #include <ios> #include <iterator> @@ -562,7 +564,7 @@ namespace internal { // If the explanation is not empty, prints it to the ostream. inline void PrintIfNotEmpty(const std::string& explanation, ::std::ostream* os) { - if (explanation != "" && os != nullptr) { + if (!explanation.empty() && os != nullptr) { *os << ", " << explanation; } } @@ -1199,27 +1201,27 @@ class PairMatchBase { }; }; -class Eq2Matcher : public PairMatchBase<Eq2Matcher, AnyEq> { +class Eq2Matcher : public PairMatchBase<Eq2Matcher, std::equal_to<>> { public: static const char* Desc() { return "an equal pair"; } }; -class Ne2Matcher : public PairMatchBase<Ne2Matcher, AnyNe> { +class Ne2Matcher : public PairMatchBase<Ne2Matcher, std::not_equal_to<>> { public: static const char* Desc() { return "an unequal pair"; } }; -class Lt2Matcher : public PairMatchBase<Lt2Matcher, AnyLt> { +class Lt2Matcher : public PairMatchBase<Lt2Matcher, std::less<>> { public: static const char* Desc() { return "a pair where the first < the second"; } }; -class Gt2Matcher : public PairMatchBase<Gt2Matcher, AnyGt> { +class Gt2Matcher : public PairMatchBase<Gt2Matcher, std::greater<>> { public: static const char* Desc() { return "a pair where the first > the second"; } }; -class Le2Matcher : public PairMatchBase<Le2Matcher, AnyLe> { +class Le2Matcher : public PairMatchBase<Le2Matcher, std::less_equal<>> { public: static const char* Desc() { return "a pair where the first <= the second"; } }; -class Ge2Matcher : public PairMatchBase<Ge2Matcher, AnyGe> { +class Ge2Matcher : public PairMatchBase<Ge2Matcher, std::greater_equal<>> { public: static const char* Desc() { return "a pair where the first >= the second"; } }; @@ -1473,6 +1475,7 @@ class SomeOfArrayMatcher { operator Matcher<U>() const { // NOLINT using RawU = typename std::decay<U>::type; std::vector<Matcher<RawU>> matchers; + matchers.reserve(matchers_.size()); for (const auto& matcher : matchers_) { matchers.push_back(MatcherCast<RawU>(matcher)); } @@ -2964,7 +2967,7 @@ class KeyMatcherImpl : public MatcherInterface<PairType> { const bool match = inner_matcher_.MatchAndExplain( pair_getters::First(key_value, Rank0()), &inner_listener); const std::string explanation = inner_listener.str(); - if (explanation != "") { + if (!explanation.empty()) { *listener << "whose first field is a value " << explanation; } return match; @@ -3111,12 +3114,12 @@ class PairMatcherImpl : public MatcherInterface<PairType> { const std::string& second_explanation, MatchResultListener* listener) const { *listener << "whose both fields match"; - if (first_explanation != "") { + if (!first_explanation.empty()) { *listener << ", where the first field is a value " << first_explanation; } - if (second_explanation != "") { + if (!second_explanation.empty()) { *listener << ", "; - if (first_explanation != "") { + if (!first_explanation.empty()) { *listener << "and "; } else { *listener << "where "; @@ -5542,7 +5545,8 @@ PolymorphicMatcher<internal::ExceptionMatcherImpl<Err>> ThrowsMessage( \ private: \ ::std::string FormatDescription(bool negation) const { \ - ::std::string gmock_description = (description); \ + ::std::string gmock_description; \ + gmock_description = (description); \ if (!gmock_description.empty()) { \ return gmock_description; \ } \ diff --git a/googlemock/include/gmock/gmock-nice-strict.h b/googlemock/include/gmock/gmock-nice-strict.h index 4f0eb35d..056d4714 100644 --- a/googlemock/include/gmock/gmock-nice-strict.h +++ b/googlemock/include/gmock/gmock-nice-strict.h @@ -98,7 +98,7 @@ constexpr bool HasStrictnessModifier() { // deregistration. This guarantees that MockClass's constructor and destructor // run with the same level of strictness as its instance methods. -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW && \ +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW) && \ (defined(_MSC_VER) || defined(__clang__)) // We need to mark these classes with this declspec to ensure that // the empty base class optimization is performed. diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index 4e498d8f..78ca15d0 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -204,6 +204,9 @@ class GTEST_API_ UntypedFunctionMockerBase { using UntypedExpectations = std::vector<std::shared_ptr<ExpectationBase>>; + struct UninterestingCallCleanupHandler; + struct FailureCleanupHandler; + // Returns an Expectation object that references and co-owns exp, // which must be an expectation on this mock function. Expectation GetHandleOf(ExpectationBase* exp); @@ -563,7 +566,7 @@ class ExpectationSet { typedef Expectation::Set::value_type value_type; // Constructs an empty set. - ExpectationSet() {} + ExpectationSet() = default; // This single-argument ctor must not be explicit, in order to support the // ExpectationSet es = EXPECT_CALL(...); @@ -1396,6 +1399,41 @@ class Cleanup final { std::function<void()> f_; }; +struct UntypedFunctionMockerBase::UninterestingCallCleanupHandler { + CallReaction reaction; + std::stringstream& ss; + + ~UninterestingCallCleanupHandler() { + ReportUninterestingCall(reaction, ss.str()); + } +}; + +struct UntypedFunctionMockerBase::FailureCleanupHandler { + std::stringstream& ss; + std::stringstream& why; + std::stringstream& loc; + const ExpectationBase* untyped_expectation; + bool found; + bool is_excessive; + + ~FailureCleanupHandler() { + ss << "\n" << why.str(); + + if (!found) { + // No expectation matches this call - reports a failure. + Expect(false, nullptr, -1, ss.str()); + } else if (is_excessive) { + // We had an upper-bound violation and the failure message is in ss. + Expect(false, untyped_expectation->file(), untyped_expectation->line(), + ss.str()); + } else { + // We had an expected call and the matching expectation is + // described in ss. + Log(kInfo, loc.str() + ss.str(), 2); + } + } +}; + template <typename F> class FunctionMocker; @@ -1408,7 +1446,7 @@ class FunctionMocker<R(Args...)> final : public UntypedFunctionMockerBase { using ArgumentTuple = std::tuple<Args...>; using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>; - FunctionMocker() {} + FunctionMocker() = default; // There is no generally useful and implementable semantics of // copying a mock object, so copying a mock is usually a user error. @@ -1794,8 +1832,15 @@ R FunctionMocker<R(Args...)>::InvokeWith(ArgumentTuple&& args) // // We use RAII to do the latter in case R is void or a non-moveable type. In // either case we can't assign it to a local variable. - const Cleanup report_uninteresting_call( - [&] { ReportUninterestingCall(reaction, ss.str()); }); + // + // Note that std::bind() is essential here. + // We *don't* use any local callback types (like lambdas). + // Doing so slows down compilation dramatically because the *constructor* of + // std::function<T> is re-instantiated with different template + // parameters each time. + const UninterestingCallCleanupHandler report_uninteresting_call = { + reaction, ss + }; return PerformActionAndPrintResult(nullptr, std::move(args), ss.str(), ss); } @@ -1839,22 +1884,14 @@ R FunctionMocker<R(Args...)>::InvokeWith(ArgumentTuple&& args) // // We use RAII to do the latter in case R is void or a non-moveable type. In // either case we can't assign it to a local variable. - const Cleanup handle_failures([&] { - ss << "\n" << why.str(); - - if (!found) { - // No expectation matches this call - reports a failure. - Expect(false, nullptr, -1, ss.str()); - } else if (is_excessive) { - // We had an upper-bound violation and the failure message is in ss. - Expect(false, untyped_expectation->file(), untyped_expectation->line(), - ss.str()); - } else { - // We had an expected call and the matching expectation is - // described in ss. - Log(kInfo, loc.str() + ss.str(), 2); - } - }); + // + // Note that we *don't* use any local callback types (like lambdas) here. + // Doing so slows down compilation dramatically because the *constructor* of + // std::function<T> is re-instantiated with different template + // parameters each time. + const FailureCleanupHandler handle_failures = { + ss, why, loc, untyped_expectation, found, is_excessive + }; return PerformActionAndPrintResult(untyped_action, std::move(args), ss.str(), ss); diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index afbdce03..ead6d7c8 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -224,7 +224,7 @@ class FailureReporterInterface { // The type of a failure (either non-fatal or fatal). enum FailureType { kNonfatal, kFatal }; - virtual ~FailureReporterInterface() {} + virtual ~FailureReporterInterface() = default; // Reports a failure that occurred at the given source file location. virtual void ReportFailure(FailureType type, const char* file, int line, @@ -311,7 +311,8 @@ GTEST_API_ WithoutMatchers GetWithoutMatchers(); // crashes). template <typename T> inline T Invalid() { - Assert(false, "", -1, "Internal error: attempt to return invalid value"); + Assert(/*condition=*/false, /*file=*/"", /*line=*/-1, + "Internal error: attempt to return invalid value"); #if defined(__GNUC__) || defined(__clang__) __builtin_unreachable(); #elif defined(_MSC_VER) @@ -464,8 +465,10 @@ struct Function<R(Args...)> { using MakeResultIgnoredValue = IgnoredValue(Args...); }; +#ifdef GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL template <typename R, typename... Args> constexpr size_t Function<R(Args...)>::ArgumentCount; +#endif // Workaround for MSVC error C2039: 'type': is not a member of 'std' // when std::tuple_element is used. |