diff options
Diffstat (limited to 'googlemock')
28 files changed, 244 insertions, 141 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. diff --git a/googlemock/src/gmock-internal-utils.cc b/googlemock/src/gmock-internal-utils.cc index 31d55650..5c2ce0d5 100644 --- a/googlemock/src/gmock-internal-utils.cc +++ b/googlemock/src/gmock-internal-utils.cc @@ -41,6 +41,7 @@ #include <cctype> #include <cstdint> #include <cstring> +#include <iostream> #include <ostream> // NOLINT #include <string> #include <vector> @@ -87,7 +88,7 @@ GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name) { (!IsDigit(prev_char) && IsDigit(*p)); if (IsAlNum(*p)) { - if (starts_new_word && result != "") result += ' '; + if (starts_new_word && !result.empty()) result += ' '; result += ToLower(*p); } } diff --git a/googlemock/src/gmock-matchers.cc b/googlemock/src/gmock-matchers.cc index 5810b6aa..07bba4f0 100644 --- a/googlemock/src/gmock-matchers.cc +++ b/googlemock/src/gmock-matchers.cc @@ -53,7 +53,7 @@ GTEST_API_ std::string FormatMatcherDescription( bool negation, const char* matcher_name, const std::vector<const char*>& param_names, const Strings& param_values) { std::string result = ConvertIdentifierNameToWords(matcher_name); - if (param_values.size() >= 1) { + if (!param_values.empty()) { result += " " + JoinAsKeyValueTuple(param_names, param_values); } return negation ? "not (" + result + ")" : result; diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 7d7c55ad..de894716 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -40,6 +40,7 @@ #include <map> #include <memory> #include <set> +#include <sstream> #include <string> #include <unordered_map> #include <vector> @@ -48,10 +49,10 @@ #include "gtest/gtest.h" #include "gtest/internal/gtest-port.h" -#if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC +#if defined(GTEST_OS_CYGWIN) || defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC) #include <unistd.h> // NOLINT #endif -#if GTEST_OS_QURT +#ifdef GTEST_OS_QURT #include <qurt_event.h> #endif @@ -95,7 +96,7 @@ ExpectationBase::ExpectationBase(const char* a_file, int a_line, action_count_checked_(false) {} // Destructs an ExpectationBase object. -ExpectationBase::~ExpectationBase() {} +ExpectationBase::~ExpectationBase() = default; // Explicitly specifies the cardinality of this expectation. Used by // the subclasses to implement the .Times() clause. @@ -297,7 +298,7 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) { "See " "https://github.com/google/googletest/blob/main/docs/" "gmock_cook_book.md#" - "knowing-when-to-expect for details.\n", + "knowing-when-to-expect-useoncall for details.\n", stack_frames_to_skip); break; default: // FAIL @@ -308,7 +309,7 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) { UntypedFunctionMockerBase::UntypedFunctionMockerBase() : mock_obj_(nullptr), name_("") {} -UntypedFunctionMockerBase::~UntypedFunctionMockerBase() {} +UntypedFunctionMockerBase::~UntypedFunctionMockerBase() = default; // Sets the mock object this mock method belongs to, and registers // this information in the global mock registry. Will be called @@ -503,7 +504,7 @@ class MockObjectRegistry { std::cout << internal::FormatFileLocation(state.first_used_file, state.first_used_line); std::cout << " ERROR: this mock object"; - if (state.first_used_test != "") { + if (!state.first_used_test.empty()) { std::cout << " (used in test " << state.first_used_test_suite << "." << state.first_used_test << ")"; } @@ -526,7 +527,7 @@ class MockObjectRegistry { // RUN_ALL_TESTS() has already returned when this destructor is // called. Therefore we cannot use the normal Google Test // failure reporting mechanism. -#if GTEST_OS_QURT +#ifdef GTEST_OS_QURT qurt_exception_raise_fatal(); #else _exit(1); // We cannot call exit() as it is not reentrant and @@ -745,13 +746,13 @@ void Mock::ClearDefaultActionsLocked(void* mock_obj) // needed by VerifyAndClearExpectationsLocked(). } -Expectation::Expectation() {} +Expectation::Expectation() = default; Expectation::Expectation( const std::shared_ptr<internal::ExpectationBase>& an_expectation_base) : expectation_base_(an_expectation_base) {} -Expectation::~Expectation() {} +Expectation::~Expectation() = default; // Adds an expectation to a sequence. void Sequence::AddExpectation(const Expectation& expectation) const { diff --git a/googlemock/src/gmock.cc b/googlemock/src/gmock.cc index 5025656a..b5e714da 100644 --- a/googlemock/src/gmock.cc +++ b/googlemock/src/gmock.cc @@ -29,6 +29,8 @@ #include "gmock/gmock.h" +#include <string> + #include "gmock/internal/gmock-port.h" GMOCK_DEFINE_bool_(catch_leaked_mocks, true, diff --git a/googlemock/src/gmock_main.cc b/googlemock/src/gmock_main.cc index b411c5ec..fb37b53a 100644 --- a/googlemock/src/gmock_main.cc +++ b/googlemock/src/gmock_main.cc @@ -32,8 +32,8 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -#if GTEST_OS_ESP8266 || GTEST_OS_ESP32 -#if GTEST_OS_ESP8266 +#if defined(GTEST_OS_ESP8266) || defined(GTEST_OS_ESP32) +#ifdef GTEST_OS_ESP8266 extern "C" { #endif void setup() { @@ -43,7 +43,7 @@ void setup() { testing::InitGoogleMock(); } void loop() { RUN_ALL_TESTS(); } -#if GTEST_OS_ESP8266 +#ifdef GTEST_OS_ESP8266 } #endif @@ -55,7 +55,7 @@ void loop() { RUN_ALL_TESTS(); } // Windows. See the following link to track the current status of this bug: // https://web.archive.org/web/20170912203238/connect.microsoft.com/VisualStudio/feedback/details/394464/wmain-link-error-in-the-static-library // // NOLINT -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE #include <tchar.h> // NOLINT GTEST_API_ int _tmain(int argc, TCHAR** argv) { diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index f2d3042f..da1675c5 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -37,14 +37,18 @@ #include <functional> #include <iterator> #include <memory> +#include <sstream> #include <string> +#include <tuple> #include <type_traits> +#include <utility> #include <vector> #include "gmock/gmock.h" #include "gmock/internal/gmock-port.h" #include "gtest/gtest-spi.h" #include "gtest/gtest.h" +#include "gtest/internal/gtest-port.h" // Silence C4100 (unreferenced formal parameter) and C4503 (decorated name // length exceeded) for MSVC. @@ -218,7 +222,8 @@ TEST(TypeTraits, IsInvocableRV) { // In C++17 and above, where it's guaranteed that functions can return // non-moveable objects, everything should work fine for non-moveable rsult // types too. -#if defined(__cplusplus) && __cplusplus >= 201703L +#if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \ + GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L { struct NonMoveable { NonMoveable() = default; @@ -444,7 +449,7 @@ TEST(DefaultValueTest, GetWorksForMoveOnlyIfSet) { EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Exists()); EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Get() == nullptr); DefaultValue<std::unique_ptr<int>>::SetFactory( - [] { return std::unique_ptr<int>(new int(42)); }); + [] { return std::make_unique<int>(42); }); EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Exists()); std::unique_ptr<int> i = DefaultValue<std::unique_ptr<int>>::Get(); EXPECT_EQ(42, *i); @@ -982,7 +987,7 @@ TEST(ReturnRoundRobinTest, WorksForVector) { class MockClass { public: - MockClass() {} + MockClass() = default; MOCK_METHOD1(IntFunc, int(bool flag)); // NOLINT MOCK_METHOD0(Foo, MyNonDefaultConstructible()); @@ -1592,7 +1597,7 @@ TEST(WithArgsTest, RefQualifiedInnerAction) { EXPECT_EQ(19, mock.AsStdFunction()(0, 17)); } -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE class SetErrnoAndReturnTest : public testing::Test { protected: @@ -1751,9 +1756,7 @@ TEST(ReturnNewTest, ConstructorThatTakes10Arguments) { delete c; } -std::unique_ptr<int> UniquePtrSource() { - return std::unique_ptr<int>(new int(19)); -} +std::unique_ptr<int> UniquePtrSource() { return std::make_unique<int>(19); } std::vector<std::unique_ptr<int>> VectorUniquePtrSource() { std::vector<std::unique_ptr<int>> out; @@ -1802,7 +1805,7 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) { // Check default value DefaultValue<std::unique_ptr<int>>::SetFactory( - [] { return std::unique_ptr<int>(new int(42)); }); + [] { return std::make_unique<int>(42); }); EXPECT_EQ(42, *mock.MakeUnique()); EXPECT_CALL(mock, MakeUnique()).WillRepeatedly(Invoke(UniquePtrSource)); @@ -1822,7 +1825,7 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) { TEST(MockMethodTest, CanTakeMoveOnlyValue) { MockClass mock; - auto make = [](int i) { return std::unique_ptr<int>(new int(i)); }; + auto make = [](int i) { return std::make_unique<int>(i); }; EXPECT_CALL(mock, TakeUnique(_)).WillRepeatedly([](std::unique_ptr<int> i) { return *i; @@ -2053,9 +2056,7 @@ struct Double { } }; -std::unique_ptr<int> UniqueInt(int i) { - return std::unique_ptr<int>(new int(i)); -} +std::unique_ptr<int> UniqueInt(int i) { return std::make_unique<int>(i); } TEST(FunctorActionTest, ActionFromFunction) { Action<int(int, int&, int*)> a = &Add; diff --git a/googlemock/test/gmock-cardinalities_test.cc b/googlemock/test/gmock-cardinalities_test.cc index cdd99563..ad49752e 100644 --- a/googlemock/test/gmock-cardinalities_test.cc +++ b/googlemock/test/gmock-cardinalities_test.cc @@ -31,6 +31,8 @@ // // This file tests the built-in cardinalities. +#include <ostream> + #include "gmock/gmock.h" #include "gtest/gtest-spi.h" #include "gtest/gtest.h" @@ -50,7 +52,7 @@ using testing::MakeCardinality; class MockFoo { public: - MockFoo() {} + MockFoo() = default; MOCK_METHOD0(Bar, int()); // NOLINT private: diff --git a/googlemock/test/gmock-function-mocker_test.cc b/googlemock/test/gmock-function-mocker_test.cc index e211aff9..f7b31ae3 100644 --- a/googlemock/test/gmock-function-mocker_test.cc +++ b/googlemock/test/gmock-function-mocker_test.cc @@ -35,7 +35,7 @@ // Silence C4503 (decorated name length exceeded) for MSVC. GTEST_DISABLE_MSC_WARNINGS_PUSH_(4503) -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // MSDN says the header file to be included for STDMETHOD is BaseTyps.h but // we are getting compiler errors if we use basetyps.h, hence including // objbase.h for definition of STDMETHOD. @@ -70,7 +70,7 @@ using testing::TypedEq; template <typename T> class TemplatedCopyable { public: - TemplatedCopyable() {} + TemplatedCopyable() = default; template <typename U> TemplatedCopyable(const U& other) {} // NOLINT @@ -78,7 +78,7 @@ class TemplatedCopyable { class FooInterface { public: - virtual ~FooInterface() {} + virtual ~FooInterface() = default; virtual void VoidReturning(int x) = 0; @@ -120,7 +120,7 @@ class FooInterface { virtual int RefQualifiedOverloaded() & = 0; virtual int RefQualifiedOverloaded() && = 0; -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS STDMETHOD_(int, CTNullary)() = 0; STDMETHOD_(bool, CTUnary)(int x) = 0; STDMETHOD_(int, CTDecimal) @@ -137,7 +137,7 @@ class FooInterface { GTEST_DISABLE_MSC_WARNINGS_PUSH_(4373) class MockFoo : public FooInterface { public: - MockFoo() {} + MockFoo() = default; // Makes sure that a mock function parameter can be named. MOCK_METHOD(void, VoidReturning, (int n)); // NOLINT @@ -178,7 +178,7 @@ class MockFoo : public FooInterface { MOCK_METHOD(int (*)(bool), ReturnsFunctionPointer1, (int), ()); MOCK_METHOD(fn_ptr, ReturnsFunctionPointer2, (int), ()); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS MOCK_METHOD(int, CTNullary, (), (Calltype(STDMETHODCALLTYPE))); MOCK_METHOD(bool, CTUnary, (int), (Calltype(STDMETHODCALLTYPE))); MOCK_METHOD(int, CTDecimal, @@ -208,7 +208,7 @@ class MockFoo : public FooInterface { class LegacyMockFoo : public FooInterface { public: - LegacyMockFoo() {} + LegacyMockFoo() = default; // Makes sure that a mock function parameter can be named. MOCK_METHOD1(VoidReturning, void(int n)); // NOLINT @@ -248,7 +248,7 @@ class LegacyMockFoo : public FooInterface { MOCK_METHOD1(ReturnsFunctionPointer1, int (*(int))(bool)); MOCK_METHOD1(ReturnsFunctionPointer2, fn_ptr(int)); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTNullary, int()); MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTUnary, bool(int)); // NOLINT MOCK_METHOD10_WITH_CALLTYPE(STDMETHODCALLTYPE, CTDecimal, @@ -404,7 +404,7 @@ TYPED_TEST(FunctionMockerTest, MocksTypeWithTemplatedCopyCtor) { EXPECT_TRUE(this->foo_->TypeWithTemplatedCopyCtor(TemplatedCopyable<int>())); } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Tests mocking a nullary function with calltype. TYPED_TEST(FunctionMockerTest, MocksNullaryFunctionWithCallType) { EXPECT_CALL(this->mock_foo_, CTNullary()) @@ -487,7 +487,7 @@ TEST(FunctionMockerTest, RefQualified) { class MockB { public: - MockB() {} + MockB() = default; MOCK_METHOD(void, DoB, ()); @@ -498,7 +498,7 @@ class MockB { class LegacyMockB { public: - LegacyMockB() {} + LegacyMockB() = default; MOCK_METHOD0(DoB, void()); @@ -534,7 +534,7 @@ TYPED_TEST(ExpectCallTest, UnmentionedFunctionCanBeCalledAnyNumberOfTimes) { template <typename T> class StackInterface { public: - virtual ~StackInterface() {} + virtual ~StackInterface() = default; // Template parameter appears in function parameter. virtual void Push(const T& value) = 0; @@ -547,7 +547,7 @@ class StackInterface { template <typename T> class MockStack : public StackInterface<T> { public: - MockStack() {} + MockStack() = default; MOCK_METHOD(void, Push, (const T& elem), ()); MOCK_METHOD(void, Pop, (), (final)); @@ -566,7 +566,7 @@ class MockStack : public StackInterface<T> { template <typename T> class LegacyMockStack : public StackInterface<T> { public: - LegacyMockStack() {} + LegacyMockStack() = default; MOCK_METHOD1_T(Push, void(const T& elem)); MOCK_METHOD0_T(Pop, void()); @@ -620,7 +620,7 @@ TYPED_TEST(TemplateMockTest, MethodWithCommaInReturnTypeWorks) { EXPECT_EQ(a_map, mock.ReturnTypeWithComma(1)); } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Tests mocking template interfaces with calltype. template <typename T> @@ -711,7 +711,7 @@ TYPED_TEST(TemplateMockTestWithCallType, Works) { class MockOverloadedOnArgNumber { public: - MockOverloadedOnArgNumber() {} + MockOverloadedOnArgNumber() = default; MY_MOCK_METHODS1_; @@ -723,7 +723,7 @@ class MockOverloadedOnArgNumber { class LegacyMockOverloadedOnArgNumber { public: - LegacyMockOverloadedOnArgNumber() {} + LegacyMockOverloadedOnArgNumber() = default; LEGACY_MY_MOCK_METHODS1_; @@ -758,7 +758,7 @@ TYPED_TEST(OverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) { class MockOverloadedOnConstness { public: - MockOverloadedOnConstness() {} + MockOverloadedOnConstness() = default; MY_MOCK_METHODS2_; diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index 932bece5..6c769a88 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -40,6 +40,7 @@ #include <memory> #include <sstream> #include <string> +#include <tuple> #include <vector> #include "gmock/gmock.h" @@ -56,7 +57,7 @@ #include "src/gtest-internal-inl.h" #undef GTEST_IMPLEMENTATION_ -#if GTEST_OS_CYGWIN +#ifdef GTEST_OS_CYGWIN #include <sys/types.h> // For ssize_t. NOLINT #endif @@ -167,7 +168,7 @@ TEST(KindOfTest, Integer) { EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long long)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(wchar_t)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(size_t)); // NOLINT -#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN +#if defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC) || defined(GTEST_OS_CYGWIN) // ssize_t is not defined on Windows and possibly some other OSes. EXPECT_EQ(kInteger, GMOCK_KIND_OF_(ssize_t)); // NOLINT #endif diff --git a/googlemock/test/gmock-matchers-arithmetic_test.cc b/googlemock/test/gmock-matchers-arithmetic_test.cc index 2c5f4d0b..f1769628 100644 --- a/googlemock/test/gmock-matchers-arithmetic_test.cc +++ b/googlemock/test/gmock-matchers-arithmetic_test.cc @@ -31,7 +31,10 @@ // // This file tests some commonly used argument matchers. +#include <cmath> #include <limits> +#include <memory> +#include <string> #include "test/gmock-matchers_test.h" @@ -952,7 +955,7 @@ TEST(AllArgsTest, WorksForNonTuple) { class AllArgsHelper { public: - AllArgsHelper() {} + AllArgsHelper() = default; MOCK_METHOD2(Helper, int(char x, int y)); @@ -973,7 +976,7 @@ TEST(AllArgsTest, WorksInWithClause) { class OptionalMatchersHelper { public: - OptionalMatchersHelper() {} + OptionalMatchersHelper() = default; MOCK_METHOD0(NoArgs, int()); diff --git a/googlemock/test/gmock-matchers-comparisons_test.cc b/googlemock/test/gmock-matchers-comparisons_test.cc index 0738aafb..b2ce99e1 100644 --- a/googlemock/test/gmock-matchers-comparisons_test.cc +++ b/googlemock/test/gmock-matchers-comparisons_test.cc @@ -31,6 +31,10 @@ // // This file tests some commonly used argument matchers. +#include <functional> +#include <memory> +#include <string> +#include <tuple> #include <vector> #include "test/gmock-matchers_test.h" @@ -585,8 +589,8 @@ TEST(MatcherCastTest, ValueIsNotCopied) { class Base { public: - virtual ~Base() {} - Base() {} + virtual ~Base() = default; + Base() = default; private: Base(const Base&) = delete; @@ -1542,7 +1546,7 @@ TEST(PairTest, MatchesCorrectly) { TEST(PairTest, WorksWithMoveOnly) { pair<std::unique_ptr<int>, std::unique_ptr<int>> p; - p.second.reset(new int(7)); + p.second = std::make_unique<int>(7); EXPECT_THAT(p, Pair(Eq(nullptr), Ne(nullptr))); } diff --git a/googlemock/test/gmock-matchers-containers_test.cc b/googlemock/test/gmock-matchers-containers_test.cc index b40a26a4..38fd9a5d 100644 --- a/googlemock/test/gmock-matchers-containers_test.cc +++ b/googlemock/test/gmock-matchers-containers_test.cc @@ -31,6 +31,18 @@ // // This file tests some commonly used argument matchers. +#include <algorithm> +#include <array> +#include <deque> +#include <forward_list> +#include <iterator> +#include <list> +#include <memory> +#include <ostream> +#include <string> +#include <tuple> +#include <vector> + #include "gtest/gtest.h" // Silence warning C4244: 'initializing': conversion from 'int' to 'short', @@ -1824,8 +1836,8 @@ TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) { } TEST(UnorderedElementsAreArrayTest, VectorBool) { - const bool a[] = {0, 1, 0, 1, 1}; - const bool b[] = {1, 0, 1, 1, 0}; + const bool a[] = {false, true, false, true, true}; + const bool b[] = {true, false, true, true, false}; std::vector<bool> expected(std::begin(a), std::end(a)); std::vector<bool> actual(std::begin(b), std::end(b)); StringMatchResultListener listener; @@ -2776,7 +2788,7 @@ TEST(ElementsAreTest, WorksWithNativeArrayPassedByReference) { class NativeArrayPassedAsPointerAndSize { public: - NativeArrayPassedAsPointerAndSize() {} + NativeArrayPassedAsPointerAndSize() = default; MOCK_METHOD(void, Helper, (int* array, int size)); diff --git a/googlemock/test/gmock-matchers-misc_test.cc b/googlemock/test/gmock-matchers-misc_test.cc index c1e4f352..b8f64587 100644 --- a/googlemock/test/gmock-matchers-misc_test.cc +++ b/googlemock/test/gmock-matchers-misc_test.cc @@ -31,6 +31,14 @@ // // This file tests some commonly used argument matchers. +#include <array> +#include <memory> +#include <ostream> +#include <string> +#include <tuple> +#include <utility> +#include <vector> + #include "gtest/gtest.h" // Silence warning C4244: 'initializing': conversion from 'int' to 'short', @@ -200,7 +208,7 @@ TEST(IsTrueTest, IsTrueIsFalse) { EXPECT_THAT(nonnull_unique, Not(IsFalse())); } -#if GTEST_HAS_TYPED_TEST +#ifdef GTEST_HAS_TYPED_TEST // Tests ContainerEq with different container types, and // different element types. diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index 866e1aba..9980f3bc 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -33,10 +33,14 @@ #include "gmock/gmock-more-actions.h" +#include <algorithm> #include <functional> +#include <iterator> #include <memory> #include <sstream> #include <string> +#include <tuple> +#include <vector> #include "gmock/gmock.h" #include "gtest/gtest-spi.h" @@ -673,7 +677,7 @@ TEST(SetArrayArgumentTest, SetsTheNthArrayWithIteratorArgument) { Action<MyFunction> a = SetArrayArgument<1>(letters.begin(), letters.end()); std::string s; - a.Perform(std::make_tuple(true, back_inserter(s))); + a.Perform(std::make_tuple(true, std::back_inserter(s))); EXPECT_EQ(letters, s); } diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index 08254e1a..95f09690 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -40,7 +40,7 @@ // clash with ::testing::Mock. class Mock { public: - Mock() {} + Mock() = default; MOCK_METHOD0(DoThis, void()); @@ -78,7 +78,7 @@ class CallsMockMethodInDestructor { class Foo { public: - virtual ~Foo() {} + virtual ~Foo() = default; virtual void DoThis() = 0; virtual int DoThat(bool flag) = 0; @@ -86,7 +86,7 @@ class Foo { class MockFoo : public Foo { public: - MockFoo() {} + MockFoo() = default; void Delete() { delete this; } MOCK_METHOD0(DoThis, void()); @@ -109,7 +109,7 @@ class MockBar { (a10 ? 'T' : 'F'); } - virtual ~MockBar() {} + virtual ~MockBar() = default; const std::string& str() const { return str_; } diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index 487b6c3f..221de2d2 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -98,7 +98,7 @@ class NonDefaultConstructible { class MockA { public: - MockA() {} + MockA() = default; MOCK_METHOD1(DoA, void(int n)); MOCK_METHOD1(ReturnResult, Result(int n)); @@ -113,7 +113,7 @@ class MockA { class MockB { public: - MockB() {} + MockB() = default; MOCK_CONST_METHOD0(DoB, int()); // NOLINT MOCK_METHOD1(DoB, int(int n)); // NOLINT @@ -125,7 +125,7 @@ class MockB { class ReferenceHoldingMock { public: - ReferenceHoldingMock() {} + ReferenceHoldingMock() = default; MOCK_METHOD1(AcceptReference, void(std::shared_ptr<MockA>*)); @@ -143,12 +143,12 @@ class ReferenceHoldingMock { class CC { public: - virtual ~CC() {} + virtual ~CC() = default; virtual int Method() = 0; }; class MockCC : public CC { public: - MockCC() {} + MockCC() = default; MOCK_METHOD0(Method, int()); @@ -804,39 +804,40 @@ TEST(ExpectCallTest, InfersCardinality1WhenThereIsWillRepeatedly) { "to be called at least once"); } -#if defined(__cplusplus) && __cplusplus >= 201703L +#if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \ + GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L // It should be possible to return a non-moveable type from a mock action in // C++17 and above, where it's guaranteed that such a type can be initialized // from a prvalue returned from a function. TEST(ExpectCallTest, NonMoveableType) { // Define a non-moveable result type. - struct Result { - explicit Result(int x_in) : x(x_in) {} - Result(Result&&) = delete; + struct NonMoveableStruct { + explicit NonMoveableStruct(int x_in) : x(x_in) {} + NonMoveableStruct(NonMoveableStruct&&) = delete; int x; }; - static_assert(!std::is_move_constructible_v<Result>); - static_assert(!std::is_copy_constructible_v<Result>); + static_assert(!std::is_move_constructible_v<NonMoveableStruct>); + static_assert(!std::is_copy_constructible_v<NonMoveableStruct>); - static_assert(!std::is_move_assignable_v<Result>); - static_assert(!std::is_copy_assignable_v<Result>); + static_assert(!std::is_move_assignable_v<NonMoveableStruct>); + static_assert(!std::is_copy_assignable_v<NonMoveableStruct>); // We should be able to use a callable that returns that result as both a // OnceAction and an Action, whether the callable ignores arguments or not. - const auto return_17 = [] { return Result(17); }; + const auto return_17 = [] { return NonMoveableStruct(17); }; - static_cast<void>(OnceAction<Result()>{return_17}); - static_cast<void>(Action<Result()>{return_17}); + static_cast<void>(OnceAction<NonMoveableStruct()>{return_17}); + static_cast<void>(Action<NonMoveableStruct()>{return_17}); - static_cast<void>(OnceAction<Result(int)>{return_17}); - static_cast<void>(Action<Result(int)>{return_17}); + static_cast<void>(OnceAction<NonMoveableStruct(int)>{return_17}); + static_cast<void>(Action<NonMoveableStruct(int)>{return_17}); // It should be possible to return the result end to end through an // EXPECT_CALL statement, with both WillOnce and WillRepeatedly. - MockFunction<Result()> mock; + MockFunction<NonMoveableStruct()> mock; EXPECT_CALL(mock, Call) // .WillOnce(return_17) // .WillRepeatedly(return_17); @@ -1088,7 +1089,7 @@ TEST(UnexpectedCallTest, UnsatisfiedPrerequisites) { // Verifies that the failure message contains the two unsatisfied // pre-requisites but not the satisfied one. -#if GTEST_USES_POSIX_RE +#ifdef GTEST_USES_POSIX_RE EXPECT_THAT(r.message(), ContainsRegex( // POSIX RE doesn't understand the (?s) prefix, but has no @@ -1881,7 +1882,7 @@ struct Unprintable { class MockC { public: - MockC() {} + MockC() = default; MOCK_METHOD6(VoidMethod, void(bool cond, int n, std::string s, void* p, const Printable& x, Unprintable y)); @@ -2050,7 +2051,7 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture { "See " "https://github.com/google/googletest/blob/main/docs/" "gmock_cook_book.md#" - "knowing-when-to-expect for details."; + "knowing-when-to-expect-useoncall for details."; // A void-returning function. CaptureStdout(); @@ -2121,7 +2122,7 @@ void PrintTo(PrintMeNot /* dummy */, ::std::ostream* /* os */) { class LogTestHelper { public: - LogTestHelper() {} + LogTestHelper() = default; MOCK_METHOD1(Foo, PrintMeNot(PrintMeNot)); diff --git a/googlemock/test/gmock_ex_test.cc b/googlemock/test/gmock_ex_test.cc index 44e5e35f..e174122d 100644 --- a/googlemock/test/gmock_ex_test.cc +++ b/googlemock/test/gmock_ex_test.cc @@ -29,6 +29,8 @@ // Tests Google Mock's functionality that depends on exceptions. +#include <exception> + #include "gmock/gmock.h" #include "gtest/gtest.h" diff --git a/googlemock/test/gmock_leak_test_.cc b/googlemock/test/gmock_leak_test_.cc index fa645916..a6bb3392 100644 --- a/googlemock/test/gmock_leak_test_.cc +++ b/googlemock/test/gmock_leak_test_.cc @@ -40,13 +40,13 @@ using ::testing::Return; class FooInterface { public: - virtual ~FooInterface() {} + virtual ~FooInterface() = default; virtual void DoThis() = 0; }; class MockFoo : public FooInterface { public: - MockFoo() {} + MockFoo() = default; MOCK_METHOD0(DoThis, void()); diff --git a/googlemock/test/gmock_link_test.h b/googlemock/test/gmock_link_test.h index 95a8cb80..db11c2d2 100644 --- a/googlemock/test/gmock_link_test.h +++ b/googlemock/test/gmock_link_test.h @@ -116,7 +116,7 @@ #include "gmock/gmock.h" -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE #include <errno.h> #endif @@ -181,7 +181,7 @@ using testing::WithArg; using testing::WithArgs; using testing::WithoutArgs; -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE using testing::SetErrnoAndReturn; #endif @@ -194,7 +194,7 @@ using testing::MatchesRegex; class Interface { public: - virtual ~Interface() {} + virtual ~Interface() = default; virtual void VoidFromString(char* str) = 0; virtual char* StringFromString(char* str) = 0; virtual int IntFromString(char* str) = 0; @@ -208,7 +208,7 @@ class Interface { class Mock : public Interface { public: - Mock() {} + Mock() = default; MOCK_METHOD1(VoidFromString, void(char* str)); MOCK_METHOD1(StringFromString, char*(char* str)); @@ -306,7 +306,7 @@ TEST(LinkTest, TestSetArrayArgument) { mock.VoidFromString(&ch); } -#if !GTEST_OS_WINDOWS_MOBILE +#ifndef GTEST_OS_WINDOWS_MOBILE // Tests the linkage of the SetErrnoAndReturn action. TEST(LinkTest, TestSetErrnoAndReturn) { diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index af4eaa9e..03d84213 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -52,7 +52,7 @@ using testing::Value; class MockFoo { public: - MockFoo() {} + MockFoo() = default; MOCK_METHOD3(Bar, char(const std::string& s, int i, double x)); MOCK_METHOD2(Bar2, bool(int x, int y)); diff --git a/googlemock/test/gmock_output_test_golden.txt b/googlemock/test/gmock_output_test_golden.txt index 9a7adf6a..f1e0a32e 100644 --- a/googlemock/test/gmock_output_test_golden.txt +++ b/googlemock/test/gmock_output_test_golden.txt @@ -40,6 +40,7 @@ FILE:#: EXPECT_CALL(foo_, Bar2(0, _))... Actual: 1 Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.UnexpectedCall [ RUN ] GMockOutputTest.UnexpectedCallToVoidFunction unknown file: Failure @@ -53,6 +54,7 @@ FILE:#: EXPECT_CALL(foo_, Bar3(0, _))... Actual: 1 Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.UnexpectedCallToVoidFunction [ RUN ] GMockOutputTest.ExcessiveCall FILE:#: Failure @@ -61,6 +63,7 @@ Mock function called more times than expected - returning default value. Returns: false Expected: to be called once Actual: called twice - over-saturated and active + [ FAILED ] GMockOutputTest.ExcessiveCall [ RUN ] GMockOutputTest.ExcessiveCallToVoidFunction FILE:#: Failure @@ -68,6 +71,7 @@ Mock function called more times than expected - returning directly. Function call: Bar3(0, 1) Expected: to be called once Actual: called twice - over-saturated and active + [ FAILED ] GMockOutputTest.ExcessiveCallToVoidFunction [ RUN ] GMockOutputTest.UninterestingCall @@ -75,14 +79,14 @@ GMOCK WARNING: Uninteresting mock function call - returning default value. Function call: Bar2(0, 1) Returns: false -NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details. +NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect-useoncall for details. [ OK ] GMockOutputTest.UninterestingCall [ RUN ] GMockOutputTest.UninterestingCallToVoidFunction GMOCK WARNING: Uninteresting mock function call - returning directly. Function call: Bar3(0, 1) -NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details. +NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect-useoncall for details. [ OK ] GMockOutputTest.UninterestingCallToVoidFunction [ RUN ] GMockOutputTest.RetiredExpectation unknown file: Failure @@ -104,6 +108,7 @@ FILE:#: tried expectation #1: EXPECT_CALL(foo_, Bar2(0, 0))... Actual: 1 Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.RetiredExpectation [ RUN ] GMockOutputTest.UnsatisfiedPrerequisite unknown file: Failure @@ -125,6 +130,7 @@ FILE:#: pre-requisite #0 (end of pre-requisites) Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.UnsatisfiedPrerequisite [ RUN ] GMockOutputTest.UnsatisfiedPrerequisites unknown file: Failure @@ -147,6 +153,7 @@ FILE:#: pre-requisite #1 (end of pre-requisites) Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.UnsatisfiedPrerequisites [ RUN ] GMockOutputTest.UnsatisfiedWith FILE:#: Failure @@ -154,16 +161,19 @@ Actual function call count doesn't match EXPECT_CALL(foo_, Bar2(_, _))... Expected args: are a pair where the first >= the second Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.UnsatisfiedWith [ RUN ] GMockOutputTest.UnsatisfiedExpectation FILE:#: Failure Actual function call count doesn't match EXPECT_CALL(foo_, Bar2(0, _))... Expected: to be called twice Actual: called once - unsatisfied and active + FILE:#: Failure Actual function call count doesn't match EXPECT_CALL(foo_, Bar(_, _, _))... Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.UnsatisfiedExpectation [ RUN ] GMockOutputTest.MismatchArguments unknown file: Failure @@ -180,6 +190,7 @@ FILE:#: EXPECT_CALL(foo_, Bar(Ref(s), _, Ge(0)))... Actual: -0.1 Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.MismatchArguments [ RUN ] GMockOutputTest.MismatchWith unknown file: Failure @@ -194,6 +205,7 @@ FILE:#: EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))... Actual: don't match Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.MismatchWith [ RUN ] GMockOutputTest.MismatchArgumentsAndWith unknown file: Failure @@ -210,6 +222,7 @@ FILE:#: EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))... Actual: don't match Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.MismatchArgumentsAndWith [ RUN ] GMockOutputTest.UnexpectedCallWithDefaultAction unknown file: Failure @@ -227,6 +240,7 @@ FILE:#: EXPECT_CALL(foo_, Bar2(2, 2))... Actual: 0 Expected: to be called once Actual: never called - unsatisfied and active + unknown file: Failure Unexpected mock function call - taking default action specified at: @@ -242,6 +256,7 @@ FILE:#: EXPECT_CALL(foo_, Bar2(2, 2))... Actual: 0 Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.UnexpectedCallWithDefaultAction [ RUN ] GMockOutputTest.ExcessiveCallWithDefaultAction FILE:#: Failure @@ -251,6 +266,7 @@ FILE:#: Returns: true Expected: to be called once Actual: called twice - over-saturated and active + FILE:#: Failure Mock function called more times than expected - taking default action specified at: FILE:#: @@ -258,6 +274,7 @@ FILE:#: Returns: false Expected: to be called once Actual: called twice - over-saturated and active + [ FAILED ] GMockOutputTest.ExcessiveCallWithDefaultAction [ RUN ] GMockOutputTest.UninterestingCallWithDefaultAction @@ -266,14 +283,14 @@ Uninteresting mock function call - taking default action specified at: FILE:#: Function call: Bar2(2, 2) Returns: true -NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details. +NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect-useoncall for details. GMOCK WARNING: Uninteresting mock function call - taking default action specified at: FILE:#: Function call: Bar2(1, 1) Returns: false -NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect for details. +NOTE: You can safely ignore the above warning unless this call should not happen. Do not suppress it by blindly adding an EXPECT_CALL() if you don't mean to enforce the call. See https://github.com/google/googletest/blob/main/docs/gmock_cook_book.md#knowing-when-to-expect-useoncall for details. [ OK ] GMockOutputTest.UninterestingCallWithDefaultAction [ RUN ] GMockOutputTest.ExplicitActionsRunOutWithDefaultAction diff --git a/googlemock/test/gmock_test.cc b/googlemock/test/gmock_test.cc index 8f1bd5d0..8cfff306 100644 --- a/googlemock/test/gmock_test.cc +++ b/googlemock/test/gmock_test.cc @@ -174,6 +174,6 @@ TEST(WideInitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) { // Makes sure Google Mock flags can be accessed in code. TEST(FlagTest, IsAccessibleInCode) { bool dummy = - GMOCK_FLAG_GET(catch_leaked_mocks) && GMOCK_FLAG_GET(verbose) == ""; + GMOCK_FLAG_GET(catch_leaked_mocks) && GMOCK_FLAG_GET(verbose).empty(); (void)dummy; // Avoids the "unused local variable" warning. } |