summaryrefslogtreecommitdiffstats
path: root/googlemock
diff options
context:
space:
mode:
Diffstat (limited to 'googlemock')
-rw-r--r--googlemock/include/gmock/gmock-actions.h8
-rw-r--r--googlemock/include/gmock/gmock-cardinalities.h4
-rw-r--r--googlemock/include/gmock/gmock-matchers.h14
-rw-r--r--googlemock/include/gmock/gmock-spec-builders.h77
-rw-r--r--googlemock/include/gmock/internal/gmock-internal-utils.h4
-rw-r--r--googlemock/src/gmock-internal-utils.cc1
-rw-r--r--googlemock/src/gmock-spec-builders.cc9
-rw-r--r--googlemock/src/gmock.cc2
-rw-r--r--googlemock/test/gmock-actions_test.cc23
-rw-r--r--googlemock/test/gmock-cardinalities_test.cc4
-rw-r--r--googlemock/test/gmock-function-mocker_test.cc24
-rw-r--r--googlemock/test/gmock-internal-utils_test.cc1
-rw-r--r--googlemock/test/gmock-matchers-arithmetic_test.cc7
-rw-r--r--googlemock/test/gmock-matchers-comparisons_test.cc10
-rw-r--r--googlemock/test/gmock-matchers-containers_test.cc18
-rw-r--r--googlemock/test/gmock-matchers-misc_test.cc8
-rw-r--r--googlemock/test/gmock-more-actions_test.cc6
-rw-r--r--googlemock/test/gmock-nice-strict_test.cc8
-rw-r--r--googlemock/test/gmock-spec-builders_test.cc43
-rw-r--r--googlemock/test/gmock_ex_test.cc2
-rw-r--r--googlemock/test/gmock_leak_test_.cc4
-rw-r--r--googlemock/test/gmock_link_test.h4
-rw-r--r--googlemock/test/gmock_output_test_.cc11
-rw-r--r--googlemock/test/gmock_output_test_golden.txt22
-rw-r--r--googlemock/test/gmock_test.cc2
25 files changed, 206 insertions, 110 deletions
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h
index c0bb8a9..bd9ba73 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
diff --git a/googlemock/include/gmock/gmock-cardinalities.h b/googlemock/include/gmock/gmock-cardinalities.h
index b6ab648..533e604 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 a480576..0f67713 100644
--- a/googlemock/include/gmock/gmock-matchers.h
+++ b/googlemock/include/gmock/gmock-matchers.h
@@ -257,6 +257,7 @@
#include <algorithm>
#include <cmath>
+#include <exception>
#include <functional>
#include <initializer_list>
#include <ios>
@@ -563,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;
}
}
@@ -2966,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;
@@ -3113,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 ";
@@ -5544,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-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h
index 4e498d8..78ca15d 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 b5283ed..ead6d7c 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,
@@ -465,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 774cce3..5c2ce0d 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>
diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc
index 5a98faf..de89471 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>
@@ -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.
@@ -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
@@ -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 5025656..b5e714d 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/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc
index 7734830..da1675c 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());
@@ -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 cdd9956..ad49752 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 4db498d..f7b31ae 100644
--- a/googlemock/test/gmock-function-mocker_test.cc
+++ b/googlemock/test/gmock-function-mocker_test.cc
@@ -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;
@@ -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
@@ -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
@@ -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());
@@ -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 360d02a..6c769a8 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"
diff --git a/googlemock/test/gmock-matchers-arithmetic_test.cc b/googlemock/test/gmock-matchers-arithmetic_test.cc
index 2c5f4d0..f176962 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 0738aaf..b2ce99e 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 b40a26a..38fd9a5 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 0c7aa49..b8f6458 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',
diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc
index 866e1ab..9980f3b 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 08254e1..95f0969 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 d53196b..221de2d 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);
@@ -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));
@@ -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 44e5e35..e174122 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 fa64591..a6bb339 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 8d2abb1..db11c2d 100644
--- a/googlemock/test/gmock_link_test.h
+++ b/googlemock/test/gmock_link_test.h
@@ -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));
diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc
index ca5a646..03d8421 100644
--- a/googlemock/test/gmock_output_test_.cc
+++ b/googlemock/test/gmock_output_test_.cc
@@ -33,7 +33,6 @@
#include <stdio.h>
#include <string>
-#include <tuple>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
@@ -53,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));
@@ -255,16 +254,12 @@ TEST_F(GMockOutputTest, CatchesLeakedMocks) {
}
MATCHER_P2(IsPair, first, second, "") {
- return Value(std::get<0>(arg), first) && Value(std::get<1>(arg), second);
+ return Value(arg.first, first) && Value(arg.second, second);
}
TEST_F(GMockOutputTest, PrintsMatcher) {
const testing::Matcher<int> m1 = Ge(48);
- // Explicitly using std::tuple instead of std::pair due to differences between
- // MSVC and other compilers. std::pair is printed as
- // "struct std::pair<int,bool>" when using MSVC vs "std::pair<int,bool>" with
- // other compilers.
- EXPECT_THAT((std::tuple<int, bool>(42, true)), IsPair(m1, true));
+ EXPECT_THAT((std::pair<int, bool>(42, true)), IsPair(m1, true));
}
void TestCatchesLeakedMocksInAdHocTests() {
diff --git a/googlemock/test/gmock_output_test_golden.txt b/googlemock/test/gmock_output_test_golden.txt
index d6c0333..ca88af0 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
@@ -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
@@ -290,9 +307,10 @@ Stack trace:
[ OK ] GMockOutputTest.CatchesLeakedMocks
[ RUN ] GMockOutputTest.PrintsMatcher
FILE:#: Failure
-Value of: (std::tuple<int, bool>(42, true))
+Value of: (std::pair<int, bool>(42, true))
Expected: is pair (first: is >= 48, second: true)
- Actual: (42, true)
+ Actual: (42, true) (of type std::pair<int,bool>)
+
[ FAILED ] GMockOutputTest.PrintsMatcher
[ FAILED ] GMockOutputTest.UnexpectedCall
[ FAILED ] GMockOutputTest.UnexpectedCallToVoidFunction
diff --git a/googlemock/test/gmock_test.cc b/googlemock/test/gmock_test.cc
index 8f1bd5d..8cfff30 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.
}