aboutsummaryrefslogtreecommitdiffstats
path: root/googlemock/test
diff options
context:
space:
mode:
Diffstat (limited to 'googlemock/test')
-rw-r--r--googlemock/test/gmock-actions_test.cc89
-rw-r--r--googlemock/test/gmock-function-mocker_test.cc389
-rw-r--r--googlemock/test/gmock-generated-function-mockers_test.cc659
-rw-r--r--googlemock/test/gmock-generated-matchers_test.cc73
-rw-r--r--googlemock/test/gmock-internal-utils_test.cc19
-rw-r--r--googlemock/test/gmock-matchers_test.cc397
-rw-r--r--googlemock/test/gmock-pp_test.cc10
-rw-r--r--googlemock/test/gmock-spec-builders_test.cc2
-rw-r--r--googlemock/test/gmock_all_test.cc1
-rwxr-xr-xgooglemock/test/pump_test.py182
10 files changed, 880 insertions, 941 deletions
diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc
index f63c8c5a..d1229ac9 100644
--- a/googlemock/test/gmock-actions_test.cc
+++ b/googlemock/test/gmock-actions_test.cc
@@ -46,6 +46,7 @@
#include <iterator>
#include <memory>
#include <string>
+#include <type_traits>
#include "gmock/gmock.h"
#include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h"
@@ -73,13 +74,12 @@ using testing::Return;
using testing::ReturnNull;
using testing::ReturnRef;
using testing::ReturnRefOfCopy;
+using testing::ReturnRoundRobin;
using testing::SetArgPointee;
using testing::SetArgumentPointee;
using testing::Unused;
using testing::WithArgs;
using testing::internal::BuiltInDefaultValue;
-using testing::internal::Int64;
-using testing::internal::UInt64;
#if !GTEST_OS_WINDOWS_MOBILE
using testing::SetErrnoAndReturn;
@@ -121,8 +121,9 @@ TEST(BuiltInDefaultValueTest, IsZeroForNumericTypes) {
EXPECT_EQ(0U, BuiltInDefaultValue<unsigned long>::Get()); // NOLINT
EXPECT_EQ(0, BuiltInDefaultValue<signed long>::Get()); // NOLINT
EXPECT_EQ(0, BuiltInDefaultValue<long>::Get()); // NOLINT
- EXPECT_EQ(0U, BuiltInDefaultValue<UInt64>::Get());
- EXPECT_EQ(0, BuiltInDefaultValue<Int64>::Get());
+ EXPECT_EQ(0U, BuiltInDefaultValue<unsigned long long>::Get()); // NOLINT
+ EXPECT_EQ(0, BuiltInDefaultValue<signed long long>::Get()); // NOLINT
+ EXPECT_EQ(0, BuiltInDefaultValue<long long>::Get()); // NOLINT
EXPECT_EQ(0, BuiltInDefaultValue<float>::Get());
EXPECT_EQ(0, BuiltInDefaultValue<double>::Get());
}
@@ -145,8 +146,9 @@ TEST(BuiltInDefaultValueTest, ExistsForNumericTypes) {
EXPECT_TRUE(BuiltInDefaultValue<unsigned long>::Exists()); // NOLINT
EXPECT_TRUE(BuiltInDefaultValue<signed long>::Exists()); // NOLINT
EXPECT_TRUE(BuiltInDefaultValue<long>::Exists()); // NOLINT
- EXPECT_TRUE(BuiltInDefaultValue<UInt64>::Exists());
- EXPECT_TRUE(BuiltInDefaultValue<Int64>::Exists());
+ EXPECT_TRUE(BuiltInDefaultValue<unsigned long long>::Exists()); // NOLINT
+ EXPECT_TRUE(BuiltInDefaultValue<signed long long>::Exists()); // NOLINT
+ EXPECT_TRUE(BuiltInDefaultValue<long long>::Exists()); // NOLINT
EXPECT_TRUE(BuiltInDefaultValue<float>::Exists());
EXPECT_TRUE(BuiltInDefaultValue<double>::Exists());
}
@@ -646,6 +648,41 @@ TEST(ReturnRefTest, IsCovariant) {
EXPECT_EQ(&derived, &a.Perform(std::make_tuple()));
}
+template <typename T, typename = decltype(ReturnRef(std::declval<T&&>()))>
+bool CanCallReturnRef(T&&) { return true; }
+bool CanCallReturnRef(Unused) { return false; }
+
+// Tests that ReturnRef(v) is working with non-temporaries (T&)
+TEST(ReturnRefTest, WorksForNonTemporary) {
+ int scalar_value = 123;
+ EXPECT_TRUE(CanCallReturnRef(scalar_value));
+
+ std::string non_scalar_value("ABC");
+ EXPECT_TRUE(CanCallReturnRef(non_scalar_value));
+
+ const int const_scalar_value{321};
+ EXPECT_TRUE(CanCallReturnRef(const_scalar_value));
+
+ const std::string const_non_scalar_value("CBA");
+ EXPECT_TRUE(CanCallReturnRef(const_non_scalar_value));
+}
+
+// Tests that ReturnRef(v) is not working with temporaries (T&&)
+TEST(ReturnRefTest, DoesNotWorkForTemporary) {
+ auto scalar_value = []() -> int { return 123; };
+ EXPECT_FALSE(CanCallReturnRef(scalar_value()));
+
+ auto non_scalar_value = []() -> std::string { return "ABC"; };
+ EXPECT_FALSE(CanCallReturnRef(non_scalar_value()));
+
+ // cannot use here callable returning "const scalar type",
+ // because such const for scalar return type is ignored
+ EXPECT_FALSE(CanCallReturnRef(static_cast<const int>(321)));
+
+ auto const_non_scalar_value = []() -> const std::string { return "CBA"; };
+ EXPECT_FALSE(CanCallReturnRef(const_non_scalar_value()));
+}
+
// Tests that ReturnRefOfCopy(v) works for reference types.
TEST(ReturnRefOfCopyTest, WorksForReference) {
int n = 42;
@@ -670,6 +707,31 @@ TEST(ReturnRefOfCopyTest, IsCovariant) {
EXPECT_NE(&derived, &a.Perform(std::make_tuple()));
}
+// Tests that ReturnRoundRobin(v) works with initializer lists
+TEST(ReturnRoundRobinTest, WorksForInitList) {
+ Action<int()> ret = ReturnRoundRobin({1, 2, 3});
+
+ EXPECT_EQ(1, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(2, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(3, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(1, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(2, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(3, ret.Perform(std::make_tuple()));
+}
+
+// Tests that ReturnRoundRobin(v) works with vectors
+TEST(ReturnRoundRobinTest, WorksForVector) {
+ std::vector<double> v = {4.4, 5.5, 6.6};
+ Action<double()> ret = ReturnRoundRobin(v);
+
+ EXPECT_EQ(4.4, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(5.5, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(6.6, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(4.4, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(5.5, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(6.6, ret.Perform(std::make_tuple()));
+}
+
// Tests that DoDefault() does the default action for the mock method.
class MockClass {
@@ -1408,8 +1470,19 @@ TEST(FunctorActionTest, TypeConversion) {
EXPECT_EQ(1, s2.Perform(std::make_tuple("hello")));
// Also between the lambda and the action itself.
- const Action<bool(std::string)> x = [](Unused) { return 42; };
- EXPECT_TRUE(x.Perform(std::make_tuple("hello")));
+ const Action<bool(std::string)> x1 = [](Unused) { return 42; };
+ const Action<bool(std::string)> x2 = [] { return 42; };
+ EXPECT_TRUE(x1.Perform(std::make_tuple("hello")));
+ EXPECT_TRUE(x2.Perform(std::make_tuple("hello")));
+
+ // Ensure decay occurs where required.
+ std::function<int()> f = [] { return 7; };
+ Action<int(int)> d = f;
+ f = nullptr;
+ EXPECT_EQ(7, d.Perform(std::make_tuple(1)));
+
+ // Ensure creation of an empty action succeeds.
+ Action<void(int)>(nullptr);
}
TEST(FunctorActionTest, UnusedArguments) {
diff --git a/googlemock/test/gmock-function-mocker_test.cc b/googlemock/test/gmock-function-mocker_test.cc
index fbc5d5b2..019e3cb9 100644
--- a/googlemock/test/gmock-function-mocker_test.cc
+++ b/googlemock/test/gmock-function-mocker_test.cc
@@ -31,7 +31,7 @@
// Google Mock - a framework for writing C++ mock classes.
//
// This file tests the function mocker classes.
-#include "gmock/gmock-generated-function-mockers.h"
+#include "gmock/gmock-function-mocker.h"
#if GTEST_OS_WINDOWS
// MSDN says the header file to be included for STDMETHOD is BaseTyps.h but
@@ -42,6 +42,8 @@
#include <map>
#include <string>
+#include <type_traits>
+
#include "gmock/gmock.h"
#include "gtest/gtest.h"
@@ -101,6 +103,10 @@ class FooInterface {
virtual int TypeWithComma(const std::map<int, std::string>& a_map) = 0;
virtual int TypeWithTemplatedCopyCtor(const TemplatedCopyable<int>&) = 0;
+ virtual int (*ReturnsFunctionPointer1(int))(bool) = 0;
+ using fn_ptr = int (*)(bool);
+ virtual fn_ptr ReturnsFunctionPointer2(int) = 0;
+
#if GTEST_OS_WINDOWS
STDMETHOD_(int, CTNullary)() = 0;
STDMETHOD_(bool, CTUnary)(int x) = 0;
@@ -159,6 +165,9 @@ class MockFoo : public FooInterface {
MOCK_METHOD(int, TypeWithTemplatedCopyCtor,
(const TemplatedCopyable<int>&)); // NOLINT
+ MOCK_METHOD(int (*)(bool), ReturnsFunctionPointer1, (int), ());
+ MOCK_METHOD(fn_ptr, ReturnsFunctionPointer2, (int), ());
+
#if GTEST_OS_WINDOWS
MOCK_METHOD(int, CTNullary, (), (Calltype(STDMETHODCALLTYPE)));
MOCK_METHOD(bool, CTUnary, (int), (Calltype(STDMETHODCALLTYPE)));
@@ -174,182 +183,238 @@ class MockFoo : public FooInterface {
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
};
+
+class LegacyMockFoo : public FooInterface {
+ public:
+ LegacyMockFoo() {}
+
+ // Makes sure that a mock function parameter can be named.
+ MOCK_METHOD1(VoidReturning, void(int n)); // NOLINT
+
+ MOCK_METHOD0(Nullary, int()); // NOLINT
+
+ // Makes sure that a mock function parameter can be unnamed.
+ MOCK_METHOD1(Unary, bool(int)); // NOLINT
+ MOCK_METHOD2(Binary, long(short, int)); // NOLINT
+ MOCK_METHOD10(Decimal, int(bool, char, short, int, long, float, // NOLINT
+ double, unsigned, char*, const std::string& str));
+
+ MOCK_METHOD1(TakesNonConstReference, bool(int&)); // NOLINT
+ MOCK_METHOD1(TakesConstReference, std::string(const int&));
+ MOCK_METHOD1(TakesConst, bool(const int)); // NOLINT
+
+ // Tests that the function return type can contain unprotected comma.
+ MOCK_METHOD0(ReturnTypeWithComma, std::map<int, std::string>());
+ MOCK_CONST_METHOD1(ReturnTypeWithComma,
+ std::map<int, std::string>(int)); // NOLINT
+
+ MOCK_METHOD0(OverloadedOnArgumentNumber, int()); // NOLINT
+ MOCK_METHOD1(OverloadedOnArgumentNumber, int(int)); // NOLINT
+
+ MOCK_METHOD1(OverloadedOnArgumentType, int(int)); // NOLINT
+ MOCK_METHOD1(OverloadedOnArgumentType, char(char)); // NOLINT
+
+ MOCK_METHOD0(OverloadedOnConstness, int()); // NOLINT
+ MOCK_CONST_METHOD0(OverloadedOnConstness, char()); // NOLINT
+
+ MOCK_METHOD1(TypeWithHole, int(int (*)())); // NOLINT
+ MOCK_METHOD1(TypeWithComma,
+ int(const std::map<int, std::string>&)); // NOLINT
+ MOCK_METHOD1(TypeWithTemplatedCopyCtor,
+ int(const TemplatedCopyable<int>&)); // NOLINT
+
+ MOCK_METHOD1(ReturnsFunctionPointer1, int (*(int))(bool));
+ MOCK_METHOD1(ReturnsFunctionPointer2, fn_ptr(int));
+
+#if 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,
+ int(bool b, char c, short d, int e, // NOLINT
+ long f, float g, double h, // NOLINT
+ unsigned i, char* j, const std::string& k));
+ MOCK_CONST_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTConst,
+ char(int)); // NOLINT
+
+ // Tests that the function return type can contain unprotected comma.
+ MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTReturnTypeWithComma,
+ std::map<int, std::string>());
+#endif // GTEST_OS_WINDOWS
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockFoo);
+};
+
#ifdef _MSC_VER
# pragma warning(pop)
#endif
-class MockMethodFunctionMockerTest : public testing::Test {
+template <class T>
+class FunctionMockerTest : public testing::Test {
protected:
- MockMethodFunctionMockerTest() : foo_(&mock_foo_) {}
+ FunctionMockerTest() : foo_(&mock_foo_) {}
FooInterface* const foo_;
- MockFoo mock_foo_;
+ T mock_foo_;
};
+using FunctionMockerTestTypes = ::testing::Types<MockFoo, LegacyMockFoo>;
+TYPED_TEST_SUITE(FunctionMockerTest, FunctionMockerTestTypes);
// Tests mocking a void-returning function.
-TEST_F(MockMethodFunctionMockerTest, MocksVoidFunction) {
- EXPECT_CALL(mock_foo_, VoidReturning(Lt(100)));
- foo_->VoidReturning(0);
+TYPED_TEST(FunctionMockerTest, MocksVoidFunction) {
+ EXPECT_CALL(this->mock_foo_, VoidReturning(Lt(100)));
+ this->foo_->VoidReturning(0);
}
// Tests mocking a nullary function.
-TEST_F(MockMethodFunctionMockerTest, MocksNullaryFunction) {
- EXPECT_CALL(mock_foo_, Nullary())
+TYPED_TEST(FunctionMockerTest, MocksNullaryFunction) {
+ EXPECT_CALL(this->mock_foo_, Nullary())
.WillOnce(DoDefault())
.WillOnce(Return(1));
- EXPECT_EQ(0, foo_->Nullary());
- EXPECT_EQ(1, foo_->Nullary());
+ EXPECT_EQ(0, this->foo_->Nullary());
+ EXPECT_EQ(1, this->foo_->Nullary());
}
// Tests mocking a unary function.
-TEST_F(MockMethodFunctionMockerTest, MocksUnaryFunction) {
- EXPECT_CALL(mock_foo_, Unary(Eq(2)))
- .Times(2)
- .WillOnce(Return(true));
+TYPED_TEST(FunctionMockerTest, MocksUnaryFunction) {
+ EXPECT_CALL(this->mock_foo_, Unary(Eq(2))).Times(2).WillOnce(Return(true));
- EXPECT_TRUE(foo_->Unary(2));
- EXPECT_FALSE(foo_->Unary(2));
+ EXPECT_TRUE(this->foo_->Unary(2));
+ EXPECT_FALSE(this->foo_->Unary(2));
}
// Tests mocking a binary function.
-TEST_F(MockMethodFunctionMockerTest, MocksBinaryFunction) {
- EXPECT_CALL(mock_foo_, Binary(2, _))
- .WillOnce(Return(3));
+TYPED_TEST(FunctionMockerTest, MocksBinaryFunction) {
+ EXPECT_CALL(this->mock_foo_, Binary(2, _)).WillOnce(Return(3));
- EXPECT_EQ(3, foo_->Binary(2, 1));
+ EXPECT_EQ(3, this->foo_->Binary(2, 1));
}
// Tests mocking a decimal function.
-TEST_F(MockMethodFunctionMockerTest, MocksDecimalFunction) {
- EXPECT_CALL(mock_foo_, Decimal(true, 'a', 0, 0, 1L, A<float>(),
- Lt(100), 5U, NULL, "hi"))
+TYPED_TEST(FunctionMockerTest, MocksDecimalFunction) {
+ EXPECT_CALL(this->mock_foo_,
+ Decimal(true, 'a', 0, 0, 1L, A<float>(), Lt(100), 5U, NULL, "hi"))
.WillOnce(Return(5));
- EXPECT_EQ(5, foo_->Decimal(true, 'a', 0, 0, 1, 0, 0, 5, nullptr, "hi"));
+ EXPECT_EQ(5, this->foo_->Decimal(true, 'a', 0, 0, 1, 0, 0, 5, nullptr, "hi"));
}
// Tests mocking a function that takes a non-const reference.
-TEST_F(MockMethodFunctionMockerTest,
- MocksFunctionWithNonConstReferenceArgument) {
+TYPED_TEST(FunctionMockerTest, MocksFunctionWithNonConstReferenceArgument) {
int a = 0;
- EXPECT_CALL(mock_foo_, TakesNonConstReference(Ref(a)))
+ EXPECT_CALL(this->mock_foo_, TakesNonConstReference(Ref(a)))
.WillOnce(Return(true));
- EXPECT_TRUE(foo_->TakesNonConstReference(a));
+ EXPECT_TRUE(this->foo_->TakesNonConstReference(a));
}
// Tests mocking a function that takes a const reference.
-TEST_F(MockMethodFunctionMockerTest, MocksFunctionWithConstReferenceArgument) {
+TYPED_TEST(FunctionMockerTest, MocksFunctionWithConstReferenceArgument) {
int a = 0;
- EXPECT_CALL(mock_foo_, TakesConstReference(Ref(a)))
+ EXPECT_CALL(this->mock_foo_, TakesConstReference(Ref(a)))
.WillOnce(Return("Hello"));
- EXPECT_EQ("Hello", foo_->TakesConstReference(a));
+ EXPECT_EQ("Hello", this->foo_->TakesConstReference(a));
}
// Tests mocking a function that takes a const variable.
-TEST_F(MockMethodFunctionMockerTest, MocksFunctionWithConstArgument) {
- EXPECT_CALL(mock_foo_, TakesConst(Lt(10)))
- .WillOnce(DoDefault());
+TYPED_TEST(FunctionMockerTest, MocksFunctionWithConstArgument) {
+ EXPECT_CALL(this->mock_foo_, TakesConst(Lt(10))).WillOnce(DoDefault());
- EXPECT_FALSE(foo_->TakesConst(5));
+ EXPECT_FALSE(this->foo_->TakesConst(5));
}
// Tests mocking functions overloaded on the number of arguments.
-TEST_F(MockMethodFunctionMockerTest, MocksFunctionsOverloadedOnArgumentNumber) {
- EXPECT_CALL(mock_foo_, OverloadedOnArgumentNumber())
+TYPED_TEST(FunctionMockerTest, MocksFunctionsOverloadedOnArgumentNumber) {
+ EXPECT_CALL(this->mock_foo_, OverloadedOnArgumentNumber())
.WillOnce(Return(1));
- EXPECT_CALL(mock_foo_, OverloadedOnArgumentNumber(_))
+ EXPECT_CALL(this->mock_foo_, OverloadedOnArgumentNumber(_))
.WillOnce(Return(2));
- EXPECT_EQ(2, foo_->OverloadedOnArgumentNumber(1));
- EXPECT_EQ(1, foo_->OverloadedOnArgumentNumber());
+ EXPECT_EQ(2, this->foo_->OverloadedOnArgumentNumber(1));
+ EXPECT_EQ(1, this->foo_->OverloadedOnArgumentNumber());
}
// Tests mocking functions overloaded on the types of argument.
-TEST_F(MockMethodFunctionMockerTest, MocksFunctionsOverloadedOnArgumentType) {
- EXPECT_CALL(mock_foo_, OverloadedOnArgumentType(An<int>()))
+TYPED_TEST(FunctionMockerTest, MocksFunctionsOverloadedOnArgumentType) {
+ EXPECT_CALL(this->mock_foo_, OverloadedOnArgumentType(An<int>()))
.WillOnce(Return(1));
- EXPECT_CALL(mock_foo_, OverloadedOnArgumentType(TypedEq<char>('a')))
+ EXPECT_CALL(this->mock_foo_, OverloadedOnArgumentType(TypedEq<char>('a')))
.WillOnce(Return('b'));
- EXPECT_EQ(1, foo_->OverloadedOnArgumentType(0));
- EXPECT_EQ('b', foo_->OverloadedOnArgumentType('a'));
+ EXPECT_EQ(1, this->foo_->OverloadedOnArgumentType(0));
+ EXPECT_EQ('b', this->foo_->OverloadedOnArgumentType('a'));
}
// Tests mocking functions overloaded on the const-ness of this object.
-TEST_F(MockMethodFunctionMockerTest,
- MocksFunctionsOverloadedOnConstnessOfThis) {
- EXPECT_CALL(mock_foo_, OverloadedOnConstness());
- EXPECT_CALL(Const(mock_foo_), OverloadedOnConstness())
+TYPED_TEST(FunctionMockerTest, MocksFunctionsOverloadedOnConstnessOfThis) {
+ EXPECT_CALL(this->mock_foo_, OverloadedOnConstness());
+ EXPECT_CALL(Const(this->mock_foo_), OverloadedOnConstness())
.WillOnce(Return('a'));
- EXPECT_EQ(0, foo_->OverloadedOnConstness());
- EXPECT_EQ('a', Const(*foo_).OverloadedOnConstness());
+ EXPECT_EQ(0, this->foo_->OverloadedOnConstness());
+ EXPECT_EQ('a', Const(*this->foo_).OverloadedOnConstness());
}
-TEST_F(MockMethodFunctionMockerTest, MocksReturnTypeWithComma) {
+TYPED_TEST(FunctionMockerTest, MocksReturnTypeWithComma) {
const std::map<int, std::string> a_map;
- EXPECT_CALL(mock_foo_, ReturnTypeWithComma())
- .WillOnce(Return(a_map));
- EXPECT_CALL(mock_foo_, ReturnTypeWithComma(42))
- .WillOnce(Return(a_map));
+ EXPECT_CALL(this->mock_foo_, ReturnTypeWithComma()).WillOnce(Return(a_map));
+ EXPECT_CALL(this->mock_foo_, ReturnTypeWithComma(42)).WillOnce(Return(a_map));
- EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma());
- EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma(42));
+ EXPECT_EQ(a_map, this->mock_foo_.ReturnTypeWithComma());
+ EXPECT_EQ(a_map, this->mock_foo_.ReturnTypeWithComma(42));
}
-TEST_F(MockMethodFunctionMockerTest, MocksTypeWithTemplatedCopyCtor) {
- EXPECT_CALL(mock_foo_, TypeWithTemplatedCopyCtor(_)).WillOnce(Return(true));
- EXPECT_TRUE(foo_->TypeWithTemplatedCopyCtor(TemplatedCopyable<int>()));
+TYPED_TEST(FunctionMockerTest, MocksTypeWithTemplatedCopyCtor) {
+ EXPECT_CALL(this->mock_foo_, TypeWithTemplatedCopyCtor(_))
+ .WillOnce(Return(true));
+ EXPECT_TRUE(this->foo_->TypeWithTemplatedCopyCtor(TemplatedCopyable<int>()));
}
#if GTEST_OS_WINDOWS
// Tests mocking a nullary function with calltype.
-TEST_F(MockMethodFunctionMockerTest, MocksNullaryFunctionWithCallType) {
- EXPECT_CALL(mock_foo_, CTNullary())
+TYPED_TEST(FunctionMockerTest, MocksNullaryFunctionWithCallType) {
+ EXPECT_CALL(this->mock_foo_, CTNullary())
.WillOnce(Return(-1))
.WillOnce(Return(0));
- EXPECT_EQ(-1, foo_->CTNullary());
- EXPECT_EQ(0, foo_->CTNullary());
+ EXPECT_EQ(-1, this->foo_->CTNullary());
+ EXPECT_EQ(0, this->foo_->CTNullary());
}
// Tests mocking a unary function with calltype.
-TEST_F(MockMethodFunctionMockerTest, MocksUnaryFunctionWithCallType) {
- EXPECT_CALL(mock_foo_, CTUnary(Eq(2)))
+TYPED_TEST(FunctionMockerTest, MocksUnaryFunctionWithCallType) {
+ EXPECT_CALL(this->mock_foo_, CTUnary(Eq(2)))
.Times(2)
.WillOnce(Return(true))
.WillOnce(Return(false));
- EXPECT_TRUE(foo_->CTUnary(2));
- EXPECT_FALSE(foo_->CTUnary(2));
+ EXPECT_TRUE(this->foo_->CTUnary(2));
+ EXPECT_FALSE(this->foo_->CTUnary(2));
}
// Tests mocking a decimal function with calltype.
-TEST_F(MockMethodFunctionMockerTest, MocksDecimalFunctionWithCallType) {
- EXPECT_CALL(mock_foo_, CTDecimal(true, 'a', 0, 0, 1L, A<float>(),
- Lt(100), 5U, NULL, "hi"))
+TYPED_TEST(FunctionMockerTest, MocksDecimalFunctionWithCallType) {
+ EXPECT_CALL(this->mock_foo_, CTDecimal(true, 'a', 0, 0, 1L, A<float>(),
+ Lt(100), 5U, NULL, "hi"))
.WillOnce(Return(10));
- EXPECT_EQ(10, foo_->CTDecimal(true, 'a', 0, 0, 1, 0, 0, 5, NULL, "hi"));
+ EXPECT_EQ(10, this->foo_->CTDecimal(true, 'a', 0, 0, 1, 0, 0, 5, NULL, "hi"));
}
// Tests mocking functions overloaded on the const-ness of this object.
-TEST_F(MockMethodFunctionMockerTest, MocksFunctionsConstFunctionWithCallType) {
- EXPECT_CALL(Const(mock_foo_), CTConst(_))
- .WillOnce(Return('a'));
+TYPED_TEST(FunctionMockerTest, MocksFunctionsConstFunctionWithCallType) {
+ EXPECT_CALL(Const(this->mock_foo_), CTConst(_)).WillOnce(Return('a'));
- EXPECT_EQ('a', Const(*foo_).CTConst(0));
+ EXPECT_EQ('a', Const(*this->foo_).CTConst(0));
}
-TEST_F(MockMethodFunctionMockerTest, MocksReturnTypeWithCommaAndCallType) {
+TYPED_TEST(FunctionMockerTest, MocksReturnTypeWithCommaAndCallType) {
const std::map<int, std::string> a_map;
- EXPECT_CALL(mock_foo_, CTReturnTypeWithComma())
- .WillOnce(Return(a_map));
+ EXPECT_CALL(this->mock_foo_, CTReturnTypeWithComma()).WillOnce(Return(a_map));
- EXPECT_EQ(a_map, mock_foo_.CTReturnTypeWithComma());
+ EXPECT_EQ(a_map, this->mock_foo_.CTReturnTypeWithComma());
}
#endif // GTEST_OS_WINDOWS
@@ -364,20 +429,33 @@ class MockB {
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockB);
};
+class LegacyMockB {
+ public:
+ LegacyMockB() {}
+
+ MOCK_METHOD0(DoB, void());
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockB);
+};
+
+template <typename T>
+class ExpectCallTest : public ::testing::Test {};
+using ExpectCallTestTypes = ::testing::Types<MockB, LegacyMockB>;
+TYPED_TEST_SUITE(ExpectCallTest, ExpectCallTestTypes);
+
// Tests that functions with no EXPECT_CALL() rules can be called any
// number of times.
-TEST(MockMethodExpectCallTest, UnmentionedFunctionCanBeCalledAnyNumberOfTimes) {
- {
- MockB b;
- }
+TYPED_TEST(ExpectCallTest, UnmentionedFunctionCanBeCalledAnyNumberOfTimes) {
+ { TypeParam b; }
{
- MockB b;
+ TypeParam b;
b.DoB();
}
{
- MockB b;
+ TypeParam b;
b.DoB();
b.DoB();
}
@@ -416,9 +494,33 @@ class MockStack : public StackInterface<T> {
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockStack);
};
+template <typename T>
+class LegacyMockStack : public StackInterface<T> {
+ public:
+ LegacyMockStack() {}
+
+ MOCK_METHOD1_T(Push, void(const T& elem));
+ MOCK_METHOD0_T(Pop, void());
+ MOCK_CONST_METHOD0_T(GetSize, int()); // NOLINT
+ MOCK_CONST_METHOD0_T(GetTop, const T&());
+
+ // Tests that the function return type can contain unprotected comma.
+ MOCK_METHOD0_T(ReturnTypeWithComma, std::map<int, int>());
+ MOCK_CONST_METHOD1_T(ReturnTypeWithComma, std::map<int, int>(int)); // NOLINT
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockStack);
+};
+
+template <typename T>
+class TemplateMockTest : public ::testing::Test {};
+using TemplateMockTestTypes =
+ ::testing::Types<MockStack<int>, LegacyMockStack<int>>;
+TYPED_TEST_SUITE(TemplateMockTest, TemplateMockTestTypes);
+
// Tests that template mock works.
-TEST(MockMethodTemplateMockTest, Works) {
- MockStack<int> mock;
+TYPED_TEST(TemplateMockTest, Works) {
+ TypeParam mock;
EXPECT_CALL(mock, GetSize())
.WillOnce(Return(0))
@@ -439,8 +541,8 @@ TEST(MockMethodTemplateMockTest, Works) {
EXPECT_EQ(0, mock.GetSize());
}
-TEST(MockMethodTemplateMockTest, MethodWithCommaInReturnTypeWorks) {
- MockStack<int> mock;
+TYPED_TEST(TemplateMockTest, MethodWithCommaInReturnTypeWorks) {
+ TypeParam mock;
const std::map<int, int> a_map;
EXPECT_CALL(mock, ReturnTypeWithComma())
@@ -484,9 +586,31 @@ class MockStackWithCallType : public StackInterfaceWithCallType<T> {
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockStackWithCallType);
};
+template <typename T>
+class LegacyMockStackWithCallType : public StackInterfaceWithCallType<T> {
+ public:
+ LegacyMockStackWithCallType() {}
+
+ MOCK_METHOD1_T_WITH_CALLTYPE(STDMETHODCALLTYPE, Push, void(const T& elem));
+ MOCK_METHOD0_T_WITH_CALLTYPE(STDMETHODCALLTYPE, Pop, void());
+ MOCK_CONST_METHOD0_T_WITH_CALLTYPE(STDMETHODCALLTYPE, GetSize, int());
+ MOCK_CONST_METHOD0_T_WITH_CALLTYPE(STDMETHODCALLTYPE, GetTop, const T&());
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockStackWithCallType);
+};
+
+template <typename T>
+class TemplateMockTestWithCallType : public ::testing::Test {};
+using TemplateMockTestWithCallTypeTypes =
+ ::testing::Types<MockStackWithCallType<int>,
+ LegacyMockStackWithCallType<int>>;
+TYPED_TEST_SUITE(TemplateMockTestWithCallType,
+ TemplateMockTestWithCallTypeTypes);
+
// Tests that template mock with calltype works.
-TEST(MockMethodTemplateMockTestWithCallType, Works) {
- MockStackWithCallType<int> mock;
+TYPED_TEST(TemplateMockTestWithCallType, Works) {
+ TypeParam mock;
EXPECT_CALL(mock, GetSize())
.WillOnce(Return(0))
@@ -513,6 +637,11 @@ TEST(MockMethodTemplateMockTestWithCallType, Works) {
MOCK_METHOD(int, Overloaded, (int), (const)); \
MOCK_METHOD(bool, Overloaded, (bool f, int n))
+#define LEGACY_MY_MOCK_METHODS1_ \
+ MOCK_METHOD0(Overloaded, void()); \
+ MOCK_CONST_METHOD1(Overloaded, int(int n)); \
+ MOCK_METHOD2(Overloaded, bool(bool f, int n))
+
class MockOverloadedOnArgNumber {
public:
MockOverloadedOnArgNumber() {}
@@ -523,8 +652,25 @@ class MockOverloadedOnArgNumber {
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockOverloadedOnArgNumber);
};
-TEST(MockMethodOverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) {
- MockOverloadedOnArgNumber mock;
+class LegacyMockOverloadedOnArgNumber {
+ public:
+ LegacyMockOverloadedOnArgNumber() {}
+
+ LEGACY_MY_MOCK_METHODS1_;
+
+ private:
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockOverloadedOnArgNumber);
+};
+
+template <typename T>
+class OverloadedMockMethodTest : public ::testing::Test {};
+using OverloadedMockMethodTestTypes =
+ ::testing::Types<MockOverloadedOnArgNumber,
+ LegacyMockOverloadedOnArgNumber>;
+TYPED_TEST_SUITE(OverloadedMockMethodTest, OverloadedMockMethodTestTypes);
+
+TYPED_TEST(OverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) {
+ TypeParam mock;
EXPECT_CALL(mock, Overloaded());
EXPECT_CALL(mock, Overloaded(1)).WillOnce(Return(2));
EXPECT_CALL(mock, Overloaded(true, 1)).WillOnce(Return(true));
@@ -649,11 +795,62 @@ struct MockMethodSizes4 {
MOCK_METHOD(void, func, (int, int, int, int));
};
+struct LegacyMockMethodSizes0 {
+ MOCK_METHOD0(func, void());
+};
+struct LegacyMockMethodSizes1 {
+ MOCK_METHOD1(func, void(int));
+};
+struct LegacyMockMethodSizes2 {
+ MOCK_METHOD2(func, void(int, int));
+};
+struct LegacyMockMethodSizes3 {
+ MOCK_METHOD3(func, void(int, int, int));
+};
+struct LegacyMockMethodSizes4 {
+ MOCK_METHOD4(func, void(int, int, int, int));
+};
+
+
TEST(MockMethodMockFunctionTest, MockMethodSizeOverhead) {
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes1));
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes2));
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes3));
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes4));
+
+ EXPECT_EQ(sizeof(LegacyMockMethodSizes0), sizeof(LegacyMockMethodSizes1));
+ EXPECT_EQ(sizeof(LegacyMockMethodSizes0), sizeof(LegacyMockMethodSizes2));
+ EXPECT_EQ(sizeof(LegacyMockMethodSizes0), sizeof(LegacyMockMethodSizes3));
+ EXPECT_EQ(sizeof(LegacyMockMethodSizes0), sizeof(LegacyMockMethodSizes4));
+
+ EXPECT_EQ(sizeof(LegacyMockMethodSizes0), sizeof(MockMethodSizes0));
+}
+
+void hasTwoParams(int, int);
+void MaybeThrows();
+void DoesntThrow() noexcept;
+struct MockMethodNoexceptSpecifier {
+ MOCK_METHOD(void, func1, (), (noexcept));
+ MOCK_METHOD(void, func2, (), (noexcept(true)));
+ MOCK_METHOD(void, func3, (), (noexcept(false)));
+ MOCK_METHOD(void, func4, (), (noexcept(noexcept(MaybeThrows()))));
+ MOCK_METHOD(void, func5, (), (noexcept(noexcept(DoesntThrow()))));
+ MOCK_METHOD(void, func6, (), (noexcept(noexcept(DoesntThrow())), const));
+ MOCK_METHOD(void, func7, (), (const, noexcept(noexcept(DoesntThrow()))));
+ // Put commas in the noexcept expression
+ MOCK_METHOD(void, func8, (), (noexcept(noexcept(hasTwoParams(1, 2))), const));
+};
+
+TEST(MockMethodMockFunctionTest, NoexceptSpecifierPreserved) {
+ EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func1()));
+ EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func2()));
+ EXPECT_FALSE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func3()));
+ EXPECT_FALSE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func4()));
+ EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func5()));
+ EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func6()));
+ EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func7()));
+ EXPECT_EQ(noexcept(std::declval<MockMethodNoexceptSpecifier>().func8()),
+ noexcept(hasTwoParams(1, 2)));
}
} // namespace gmock_function_mocker_test
diff --git a/googlemock/test/gmock-generated-function-mockers_test.cc b/googlemock/test/gmock-generated-function-mockers_test.cc
deleted file mode 100644
index dff3a9f0..00000000
--- a/googlemock/test/gmock-generated-function-mockers_test.cc
+++ /dev/null
@@ -1,659 +0,0 @@
-// Copyright 2007, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-// Google Mock - a framework for writing C++ mock classes.
-//
-// This file tests the function mocker classes.
-
-#include "gmock/gmock-generated-function-mockers.h"
-
-#if 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.
-# include <objbase.h>
-#endif // GTEST_OS_WINDOWS
-
-#include <map>
-#include <string>
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-
-namespace testing {
-namespace gmock_generated_function_mockers_test {
-
-using testing::_;
-using testing::A;
-using testing::An;
-using testing::AnyNumber;
-using testing::Const;
-using testing::DoDefault;
-using testing::Eq;
-using testing::Lt;
-using testing::MockFunction;
-using testing::Ref;
-using testing::Return;
-using testing::ReturnRef;
-using testing::TypedEq;
-
-template<typename T>
-class TemplatedCopyable {
- public:
- TemplatedCopyable() {}
-
- template <typename U>
- TemplatedCopyable(const U& other) {} // NOLINT
-};
-
-class FooInterface {
- public:
- virtual ~FooInterface() {}
-
- virtual void VoidReturning(int x) = 0;
-
- virtual int Nullary() = 0;
- virtual bool Unary(int x) = 0;
- virtual long Binary(short x, int y) = 0; // NOLINT
- virtual int Decimal(bool b, char c, short d, int e, long f, // NOLINT
- float g, double h, unsigned i, char* j,
- const std::string& k) = 0;
-
- virtual bool TakesNonConstReference(int& n) = 0; // NOLINT
- virtual std::string TakesConstReference(const int& n) = 0;
- virtual bool TakesConst(const int x) = 0;
-
- virtual int OverloadedOnArgumentNumber() = 0;
- virtual int OverloadedOnArgumentNumber(int n) = 0;
-
- virtual int OverloadedOnArgumentType(int n) = 0;
- virtual char OverloadedOnArgumentType(char c) = 0;
-
- virtual int OverloadedOnConstness() = 0;
- virtual char OverloadedOnConstness() const = 0;
-
- virtual int TypeWithHole(int (*func)()) = 0;
- virtual int TypeWithComma(const std::map<int, std::string>& a_map) = 0;
- virtual int TypeWithTemplatedCopyCtor(
- const TemplatedCopyable<int>& a_vector) = 0;
-
-#if GTEST_OS_WINDOWS
- STDMETHOD_(int, CTNullary)() = 0;
- STDMETHOD_(bool, CTUnary)(int x) = 0;
- STDMETHOD_(int, CTDecimal)
- (bool b, char c, short d, int e, long f, // NOLINT
- float g, double h, unsigned i, char* j, const std::string& k) = 0;
- STDMETHOD_(char, CTConst)(int x) const = 0;
-#endif // GTEST_OS_WINDOWS
-};
-
-// Const qualifiers on arguments were once (incorrectly) considered
-// significant in determining whether two virtual functions had the same
-// signature. This was fixed in Visual Studio 2008. However, the compiler
-// still emits a warning that alerts about this change in behavior.
-#ifdef _MSC_VER
-# pragma warning(push)
-# pragma warning(disable : 4373)
-#endif
-class MockFoo : public FooInterface {
- public:
- MockFoo() {}
-
- // Makes sure that a mock function parameter can be named.
- MOCK_METHOD1(VoidReturning, void(int n)); // NOLINT
-
- MOCK_METHOD0(Nullary, int()); // NOLINT
-
- // Makes sure that a mock function parameter can be unnamed.
- MOCK_METHOD1(Unary, bool(int)); // NOLINT
- MOCK_METHOD2(Binary, long(short, int)); // NOLINT
- MOCK_METHOD10(Decimal, int(bool, char, short, int, long, float, // NOLINT
- double, unsigned, char*, const std::string& str));
-
- MOCK_METHOD1(TakesNonConstReference, bool(int&)); // NOLINT
- MOCK_METHOD1(TakesConstReference, std::string(const int&));
- MOCK_METHOD1(TakesConst, bool(const int)); // NOLINT
-
- // Tests that the function return type can contain unprotected comma.
- MOCK_METHOD0(ReturnTypeWithComma, std::map<int, std::string>());
- MOCK_CONST_METHOD1(ReturnTypeWithComma,
- std::map<int, std::string>(int)); // NOLINT
-
- MOCK_METHOD0(OverloadedOnArgumentNumber, int()); // NOLINT
- MOCK_METHOD1(OverloadedOnArgumentNumber, int(int)); // NOLINT
-
- MOCK_METHOD1(OverloadedOnArgumentType, int(int)); // NOLINT
- MOCK_METHOD1(OverloadedOnArgumentType, char(char)); // NOLINT
-
- MOCK_METHOD0(OverloadedOnConstness, int()); // NOLINT
- MOCK_CONST_METHOD0(OverloadedOnConstness, char()); // NOLINT
-
- MOCK_METHOD1(TypeWithHole, int(int (*)())); // NOLINT
- MOCK_METHOD1(TypeWithComma,
- int(const std::map<int, std::string>&)); // NOLINT
- MOCK_METHOD1(TypeWithTemplatedCopyCtor,
- int(const TemplatedCopyable<int>&)); // NOLINT
-
-#if GTEST_OS_WINDOWS
- MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTNullary, int());
- MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTUnary, bool(int));
- MOCK_METHOD10_WITH_CALLTYPE(STDMETHODCALLTYPE, CTDecimal,
- int(bool b, char c, short d, int e, long f,
- float g, double h, unsigned i, char* j,
- const std::string& k));
- MOCK_CONST_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTConst, char(int));
-
- // Tests that the function return type can contain unprotected comma.
- MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTReturnTypeWithComma,
- std::map<int, std::string>());
-#endif // GTEST_OS_WINDOWS
-
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
-};
-#ifdef _MSC_VER
-# pragma warning(pop)
-#endif
-
-class FunctionMockerTest : public testing::Test {
- protected:
- FunctionMockerTest() : foo_(&mock_foo_) {}
-
- FooInterface* const foo_;
- MockFoo mock_foo_;
-};
-
-// Tests mocking a void-returning function.
-TEST_F(FunctionMockerTest, MocksVoidFunction) {
- EXPECT_CALL(mock_foo_, VoidReturning(Lt(100)));
- foo_->VoidReturning(0);
-}
-
-// Tests mocking a nullary function.
-TEST_F(FunctionMockerTest, MocksNullaryFunction) {
- EXPECT_CALL(mock_foo_, Nullary())
- .WillOnce(DoDefault())
- .WillOnce(Return(1));
-
- EXPECT_EQ(0, foo_->Nullary());
- EXPECT_EQ(1, foo_->Nullary());
-}
-
-// Tests mocking a unary function.
-TEST_F(FunctionMockerTest, MocksUnaryFunction) {
- EXPECT_CALL(mock_foo_, Unary(Eq(2)))
- .Times(2)
- .WillOnce(Return(true));
-
- EXPECT_TRUE(foo_->Unary(2));
- EXPECT_FALSE(foo_->Unary(2));
-}
-
-// Tests mocking a binary function.
-TEST_F(FunctionMockerTest, MocksBinaryFunction) {
- EXPECT_CALL(mock_foo_, Binary(2, _))
- .WillOnce(Return(3));
-
- EXPECT_EQ(3, foo_->Binary(2, 1));
-}
-
-// Tests mocking a decimal function.
-TEST_F(FunctionMockerTest, MocksDecimalFunction) {
- EXPECT_CALL(mock_foo_, Decimal(true, 'a', 0, 0, 1L, A<float>(), Lt(100), 5U,
- nullptr, "hi"))
- .WillOnce(Return(5));
-
- EXPECT_EQ(5, foo_->Decimal(true, 'a', 0, 0, 1, 0, 0, 5, nullptr, "hi"));
-}
-
-// Tests mocking a function that takes a non-const reference.
-TEST_F(FunctionMockerTest, MocksFunctionWithNonConstReferenceArgument) {
- int a = 0;
- EXPECT_CALL(mock_foo_, TakesNonConstReference(Ref(a)))
- .WillOnce(Return(true));
-
- EXPECT_TRUE(foo_->TakesNonConstReference(a));
-}
-
-// Tests mocking a function that takes a const reference.
-TEST_F(FunctionMockerTest, MocksFunctionWithConstReferenceArgument) {
- int a = 0;
- EXPECT_CALL(mock_foo_, TakesConstReference(Ref(a)))
- .WillOnce(Return("Hello"));
-
- EXPECT_EQ("Hello", foo_->TakesConstReference(a));
-}
-
-// Tests mocking a function that takes a const variable.
-TEST_F(FunctionMockerTest, MocksFunctionWithConstArgument) {
- EXPECT_CALL(mock_foo_, TakesConst(Lt(10)))
- .WillOnce(DoDefault());
-
- EXPECT_FALSE(foo_->TakesConst(5));
-}
-
-// Tests mocking functions overloaded on the number of arguments.
-TEST_F(FunctionMockerTest, MocksFunctionsOverloadedOnArgumentNumber) {
- EXPECT_CALL(mock_foo_, OverloadedOnArgumentNumber())
- .WillOnce(Return(1));
- EXPECT_CALL(mock_foo_, OverloadedOnArgumentNumber(_))
- .WillOnce(Return(2));
-
- EXPECT_EQ(2, foo_->OverloadedOnArgumentNumber(1));
- EXPECT_EQ(1, foo_->OverloadedOnArgumentNumber());
-}
-
-// Tests mocking functions overloaded on the types of argument.
-TEST_F(FunctionMockerTest, MocksFunctionsOverloadedOnArgumentType) {
- EXPECT_CALL(mock_foo_, OverloadedOnArgumentType(An<int>()))
- .WillOnce(Return(1));
- EXPECT_CALL(mock_foo_, OverloadedOnArgumentType(TypedEq<char>('a')))
- .WillOnce(Return('b'));
-
- EXPECT_EQ(1, foo_->OverloadedOnArgumentType(0));
- EXPECT_EQ('b', foo_->OverloadedOnArgumentType('a'));
-}
-
-// Tests mocking functions overloaded on the const-ness of this object.
-TEST_F(FunctionMockerTest, MocksFunctionsOverloadedOnConstnessOfThis) {
- EXPECT_CALL(mock_foo_, OverloadedOnConstness());
- EXPECT_CALL(Const(mock_foo_), OverloadedOnConstness())
- .WillOnce(Return('a'));
-
- EXPECT_EQ(0, foo_->OverloadedOnConstness());
- EXPECT_EQ('a', Const(*foo_).OverloadedOnConstness());
-}
-
-TEST_F(FunctionMockerTest, MocksReturnTypeWithComma) {
- const std::map<int, std::string> a_map;
- EXPECT_CALL(mock_foo_, ReturnTypeWithComma())
- .WillOnce(Return(a_map));
- EXPECT_CALL(mock_foo_, ReturnTypeWithComma(42))
- .WillOnce(Return(a_map));
-
- EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma());
- EXPECT_EQ(a_map, mock_foo_.ReturnTypeWithComma(42));
-}
-
-TEST_F(FunctionMockerTest, MocksTypeWithTemplatedCopyCtor) {
- EXPECT_CALL(mock_foo_, TypeWithTemplatedCopyCtor(_)).WillOnce(Return(true));
- EXPECT_TRUE(foo_->TypeWithTemplatedCopyCtor(TemplatedCopyable<int>()));
-}
-
-#if GTEST_OS_WINDOWS
-// Tests mocking a nullary function with calltype.
-TEST_F(FunctionMockerTest, MocksNullaryFunctionWithCallType) {
- EXPECT_CALL(mock_foo_, CTNullary())
- .WillOnce(Return(-1))
- .WillOnce(Return(0));
-
- EXPECT_EQ(-1, foo_->CTNullary());
- EXPECT_EQ(0, foo_->CTNullary());
-}
-
-// Tests mocking a unary function with calltype.
-TEST_F(FunctionMockerTest, MocksUnaryFunctionWithCallType) {
- EXPECT_CALL(mock_foo_, CTUnary(Eq(2)))
- .Times(2)
- .WillOnce(Return(true))
- .WillOnce(Return(false));
-
- EXPECT_TRUE(foo_->CTUnary(2));
- EXPECT_FALSE(foo_->CTUnary(2));
-}
-
-// Tests mocking a decimal function with calltype.
-TEST_F(FunctionMockerTest, MocksDecimalFunctionWithCallType) {
- EXPECT_CALL(mock_foo_, CTDecimal(true, 'a', 0, 0, 1L, A<float>(), Lt(100), 5U,
- nullptr, "hi"))
- .WillOnce(Return(10));
-
- EXPECT_EQ(10, foo_->CTDecimal(true, 'a', 0, 0, 1, 0, 0, 5, nullptr, "hi"));
-}
-
-// Tests mocking functions overloaded on the const-ness of this object.
-TEST_F(FunctionMockerTest, MocksFunctionsConstFunctionWithCallType) {
- EXPECT_CALL(Const(mock_foo_), CTConst(_))
- .WillOnce(Return('a'));
-
- EXPECT_EQ('a', Const(*foo_).CTConst(0));
-}
-
-TEST_F(FunctionMockerTest, MocksReturnTypeWithCommaAndCallType) {
- const std::map<int, std::string> a_map;
- EXPECT_CALL(mock_foo_, CTReturnTypeWithComma())
- .WillOnce(Return(a_map));
-
- EXPECT_EQ(a_map, mock_foo_.CTReturnTypeWithComma());
-}
-
-#endif // GTEST_OS_WINDOWS
-
-class MockB {
- public:
- MockB() {}
-
- MOCK_METHOD0(DoB, void());
-
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(MockB);
-};
-
-// Tests that functions with no EXPECT_CALL() ruls can be called any
-// number of times.
-TEST(ExpectCallTest, UnmentionedFunctionCanBeCalledAnyNumberOfTimes) {
- {
- MockB b;
- }
-
- {
- MockB b;
- b.DoB();
- }
-
- {
- MockB b;
- b.DoB();
- b.DoB();
- }
-}
-
-// Tests mocking template interfaces.
-
-template <typename T>
-class StackInterface {
- public:
- virtual ~StackInterface() {}
-
- // Template parameter appears in function parameter.
- virtual void Push(const T& value) = 0;
- virtual void Pop() = 0;
- virtual int GetSize() const = 0;
- // Template parameter appears in function return type.
- virtual const T& GetTop() const = 0;
-};
-
-template <typename T>
-class MockStack : public StackInterface<T> {
- public:
- MockStack() {}
-
- MOCK_METHOD1_T(Push, void(const T& elem));
- MOCK_METHOD0_T(Pop, void());
- MOCK_CONST_METHOD0_T(GetSize, int()); // NOLINT
- MOCK_CONST_METHOD0_T(GetTop, const T&());
-
- // Tests that the function return type can contain unprotected comma.
- MOCK_METHOD0_T(ReturnTypeWithComma, std::map<int, int>());
- MOCK_CONST_METHOD1_T(ReturnTypeWithComma, std::map<int, int>(int)); // NOLINT
-
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(MockStack);
-};
-
-// Tests that template mock works.
-TEST(TemplateMockTest, Works) {
- MockStack<int> mock;
-
- EXPECT_CALL(mock, GetSize())
- .WillOnce(Return(0))
- .WillOnce(Return(1))
- .WillOnce(Return(0));
- EXPECT_CALL(mock, Push(_));
- int n = 5;
- EXPECT_CALL(mock, GetTop())
- .WillOnce(ReturnRef(n));
- EXPECT_CALL(mock, Pop())
- .Times(AnyNumber());
-
- EXPECT_EQ(0, mock.GetSize());
- mock.Push(5);
- EXPECT_EQ(1, mock.GetSize());
- EXPECT_EQ(5, mock.GetTop());
- mock.Pop();
- EXPECT_EQ(0, mock.GetSize());
-}
-
-TEST(TemplateMockTest, MethodWithCommaInReturnTypeWorks) {
- MockStack<int> mock;
-
- const std::map<int, int> a_map;
- EXPECT_CALL(mock, ReturnTypeWithComma())
- .WillOnce(Return(a_map));
- EXPECT_CALL(mock, ReturnTypeWithComma(1))
- .WillOnce(Return(a_map));
-
- EXPECT_EQ(a_map, mock.ReturnTypeWithComma());
- EXPECT_EQ(a_map, mock.ReturnTypeWithComma(1));
-}
-
-#if GTEST_OS_WINDOWS
-// Tests mocking template interfaces with calltype.
-
-template <typename T>
-class StackInterfaceWithCallType {
- public:
- virtual ~StackInterfaceWithCallType() {}
-
- // Template parameter appears in function parameter.
- STDMETHOD_(void, Push)(const T& value) = 0;
- STDMETHOD_(void, Pop)() = 0;
- STDMETHOD_(int, GetSize)() const = 0;
- // Template parameter appears in function return type.
- STDMETHOD_(const T&, GetTop)() const = 0;
-};
-
-template <typename T>
-class MockStackWithCallType : public StackInterfaceWithCallType<T> {
- public:
- MockStackWithCallType() {}
-
- MOCK_METHOD1_T_WITH_CALLTYPE(STDMETHODCALLTYPE, Push, void(const T& elem));
- MOCK_METHOD0_T_WITH_CALLTYPE(STDMETHODCALLTYPE, Pop, void());
- MOCK_CONST_METHOD0_T_WITH_CALLTYPE(STDMETHODCALLTYPE, GetSize, int());
- MOCK_CONST_METHOD0_T_WITH_CALLTYPE(STDMETHODCALLTYPE, GetTop, const T&());
-
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(MockStackWithCallType);
-};
-
-// Tests that template mock with calltype works.
-TEST(TemplateMockTestWithCallType, Works) {
- MockStackWithCallType<int> mock;
-
- EXPECT_CALL(mock, GetSize())
- .WillOnce(Return(0))
- .WillOnce(Return(1))
- .WillOnce(Return(0));
- EXPECT_CALL(mock, Push(_));
- int n = 5;
- EXPECT_CALL(mock, GetTop())
- .WillOnce(ReturnRef(n));
- EXPECT_CALL(mock, Pop())
- .Times(AnyNumber());
-
- EXPECT_EQ(0, mock.GetSize());
- mock.Push(5);
- EXPECT_EQ(1, mock.GetSize());
- EXPECT_EQ(5, mock.GetTop());
- mock.Pop();
- EXPECT_EQ(0, mock.GetSize());
-}
-#endif // GTEST_OS_WINDOWS
-
-#define MY_MOCK_METHODS1_ \
- MOCK_METHOD0(Overloaded, void()); \
- MOCK_CONST_METHOD1(Overloaded, int(int n)); \
- MOCK_METHOD2(Overloaded, bool(bool f, int n))
-
-class MockOverloadedOnArgNumber {
- public:
- MockOverloadedOnArgNumber() {}
-
- MY_MOCK_METHODS1_;
-
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(MockOverloadedOnArgNumber);
-};
-
-TEST(OverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) {
- MockOverloadedOnArgNumber mock;
- EXPECT_CALL(mock, Overloaded());
- EXPECT_CALL(mock, Overloaded(1)).WillOnce(Return(2));
- EXPECT_CALL(mock, Overloaded(true, 1)).WillOnce(Return(true));
-
- mock.Overloaded();
- EXPECT_EQ(2, mock.Overloaded(1));
- EXPECT_TRUE(mock.Overloaded(true, 1));
-}
-
-#define MY_MOCK_METHODS2_ \
- MOCK_CONST_METHOD1(Overloaded, int(int n)); \
- MOCK_METHOD1(Overloaded, int(int n))
-
-class MockOverloadedOnConstness {
- public:
- MockOverloadedOnConstness() {}
-
- MY_MOCK_METHODS2_;
-
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(MockOverloadedOnConstness);
-};
-
-TEST(OverloadedMockMethodTest, CanOverloadOnConstnessInMacroBody) {
- MockOverloadedOnConstness mock;
- const MockOverloadedOnConstness* const_mock = &mock;
- EXPECT_CALL(mock, Overloaded(1)).WillOnce(Return(2));
- EXPECT_CALL(*const_mock, Overloaded(1)).WillOnce(Return(3));
-
- EXPECT_EQ(2, mock.Overloaded(1));
- EXPECT_EQ(3, const_mock->Overloaded(1));
-}
-
-TEST(MockFunctionTest, WorksForVoidNullary) {
- MockFunction<void()> foo;
- EXPECT_CALL(foo, Call());
- foo.Call();
-}
-
-TEST(MockFunctionTest, WorksForNonVoidNullary) {
- MockFunction<int()> foo;
- EXPECT_CALL(foo, Call())
- .WillOnce(Return(1))
- .WillOnce(Return(2));
- EXPECT_EQ(1, foo.Call());
- EXPECT_EQ(2, foo.Call());
-}
-
-TEST(MockFunctionTest, WorksForVoidUnary) {
- MockFunction<void(int)> foo;
- EXPECT_CALL(foo, Call(1));
- foo.Call(1);
-}
-
-TEST(MockFunctionTest, WorksForNonVoidBinary) {
- MockFunction<int(bool, int)> foo;
- EXPECT_CALL(foo, Call(false, 42))
- .WillOnce(Return(1))
- .WillOnce(Return(2));
- EXPECT_CALL(foo, Call(true, Ge(100)))
- .WillOnce(Return(3));
- EXPECT_EQ(1, foo.Call(false, 42));
- EXPECT_EQ(2, foo.Call(false, 42));
- EXPECT_EQ(3, foo.Call(true, 120));
-}
-
-TEST(MockFunctionTest, WorksFor10Arguments) {
- MockFunction<int(bool a0, char a1, int a2, int a3, int a4,
- int a5, int a6, char a7, int a8, bool a9)> foo;
- EXPECT_CALL(foo, Call(_, 'a', _, _, _, _, _, _, _, _))
- .WillOnce(Return(1))
- .WillOnce(Return(2));
- EXPECT_EQ(1, foo.Call(false, 'a', 0, 0, 0, 0, 0, 'b', 0, true));
- EXPECT_EQ(2, foo.Call(true, 'a', 0, 0, 0, 0, 0, 'b', 1, false));
-}
-
-TEST(MockFunctionTest, AsStdFunction) {
- MockFunction<int(int)> foo;
- auto call = [](const std::function<int(int)> &f, int i) {
- return f(i);
- };
- EXPECT_CALL(foo, Call(1)).WillOnce(Return(-1));
- EXPECT_CALL(foo, Call(2)).WillOnce(Return(-2));
- EXPECT_EQ(-1, call(foo.AsStdFunction(), 1));
- EXPECT_EQ(-2, call(foo.AsStdFunction(), 2));
-}
-
-TEST(MockFunctionTest, AsStdFunctionReturnsReference) {
- MockFunction<int&()> foo;
- int value = 1;
- EXPECT_CALL(foo, Call()).WillOnce(ReturnRef(value));
- int& ref = foo.AsStdFunction()();
- EXPECT_EQ(1, ref);
- value = 2;
- EXPECT_EQ(2, ref);
-}
-
-TEST(MockFunctionTest, AsStdFunctionWithReferenceParameter) {
- MockFunction<int(int &)> foo;
- auto call = [](const std::function<int(int& )> &f, int &i) {
- return f(i);
- };
- int i = 42;
- EXPECT_CALL(foo, Call(i)).WillOnce(Return(-1));
- EXPECT_EQ(-1, call(foo.AsStdFunction(), i));
-}
-
-
-struct MockMethodSizes0 {
- MOCK_METHOD0(func, void());
-};
-struct MockMethodSizes1 {
- MOCK_METHOD1(func, void(int));
-};
-struct MockMethodSizes2 {
- MOCK_METHOD2(func, void(int, int));
-};
-struct MockMethodSizes3 {
- MOCK_METHOD3(func, void(int, int, int));
-};
-struct MockMethodSizes4 {
- MOCK_METHOD4(func, void(int, int, int, int));
-};
-
-TEST(MockFunctionTest, MockMethodSizeOverhead) {
- EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes1));
- EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes2));
- EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes3));
- EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes4));
-}
-
-} // namespace gmock_generated_function_mockers_test
-} // namespace testing
diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc
index 6c4b3000..26c41f68 100644
--- a/googlemock/test/gmock-generated-matchers_test.cc
+++ b/googlemock/test/gmock-generated-matchers_test.cc
@@ -39,8 +39,10 @@
# pragma warning(disable:4100)
#endif
-#include "gmock/gmock-generated-matchers.h"
+#include "gmock/gmock-matchers.h"
+#include <array>
+#include <iterator>
#include <list>
#include <map>
#include <memory>
@@ -51,8 +53,8 @@
#include <vector>
#include "gmock/gmock.h"
-#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
+#include "gtest/gtest.h"
namespace {
@@ -195,7 +197,7 @@ TEST(ElementsAreTest, ExplainsNonTrivialMatch) {
ElementsAre(GreaterThan(1), 0, GreaterThan(2));
const int a[] = { 10, 0, 100 };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> test_vector(std::begin(a), std::end(a));
EXPECT_EQ("whose element #0 matches, which is 9 more than 1,\n"
"and whose element #2 matches, which is 98 more than 2",
Explain(m, test_vector));
@@ -280,7 +282,7 @@ TEST(ElementsAreTest, MatchesThreeElementsMixedMatchers) {
TEST(ElementsAreTest, MatchesTenElementVector) {
const int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> test_vector(std::begin(a), std::end(a));
EXPECT_THAT(test_vector,
// The element list can contain values and/or matchers
@@ -317,13 +319,10 @@ TEST(ElementsAreTest, DoesNotMatchWrongOrder) {
}
TEST(ElementsAreTest, WorksForNestedContainer) {
- const char* strings[] = {
- "Hi",
- "world"
- };
+ constexpr std::array<const char*, 2> strings = {{"Hi", "world"}};
vector<list<char> > nested;
- for (size_t i = 0; i < GTEST_ARRAY_SIZE_(strings); i++) {
+ for (size_t i = 0; i < strings.size(); i++) {
nested.push_back(list<char>(strings[i], strings[i] + strlen(strings[i])));
}
@@ -335,7 +334,7 @@ TEST(ElementsAreTest, WorksForNestedContainer) {
TEST(ElementsAreTest, WorksWithByRefElementMatchers) {
int a[] = { 0, 1, 2 };
- vector<int> v(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> v(std::begin(a), std::end(a));
EXPECT_THAT(v, ElementsAre(Ref(v[0]), Ref(v[1]), Ref(v[2])));
EXPECT_THAT(v, Not(ElementsAre(Ref(v[0]), Ref(v[1]), Ref(a[2]))));
@@ -343,7 +342,7 @@ TEST(ElementsAreTest, WorksWithByRefElementMatchers) {
TEST(ElementsAreTest, WorksWithContainerPointerUsingPointee) {
int a[] = { 0, 1, 2 };
- vector<int> v(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> v(std::begin(a), std::end(a));
EXPECT_THAT(&v, Pointee(ElementsAre(0, 1, _)));
EXPECT_THAT(&v, Not(Pointee(ElementsAre(0, _, 3))));
@@ -393,13 +392,6 @@ TEST(ElementsAreTest, AcceptsStringLiteral) {
EXPECT_THAT(array, Not(ElementsAre("hi", "one", "too")));
}
-#ifndef _MSC_VER
-
-// The following test passes a value of type const char[] to a
-// function template that expects const T&. Some versions of MSVC
-// generates a compiler error C2665 for that. We believe it's a bug
-// in MSVC. Therefore this test is #if-ed out for MSVC.
-
// Declared here with the size unknown. Defined AFTER the following test.
extern const char kHi[];
@@ -416,8 +408,6 @@ TEST(ElementsAreTest, AcceptsArrayWithUnknownSize) {
const char kHi[] = "hi";
-#endif // _MSC_VER
-
TEST(ElementsAreTest, MakesCopyOfArguments) {
int x = 1;
int y = 2;
@@ -440,7 +430,7 @@ TEST(ElementsAreTest, MakesCopyOfArguments) {
TEST(ElementsAreArrayTest, CanBeCreatedWithValueArray) {
const int a[] = { 1, 2, 3 };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> test_vector(std::begin(a), std::end(a));
EXPECT_THAT(test_vector, ElementsAreArray(a));
test_vector[2] = 0;
@@ -448,20 +438,20 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithValueArray) {
}
TEST(ElementsAreArrayTest, CanBeCreatedWithArraySize) {
- const char* a[] = { "one", "two", "three" };
+ std::array<const char*, 3> a = {{"one", "two", "three"}};
- vector<std::string> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
- EXPECT_THAT(test_vector, ElementsAreArray(a, GTEST_ARRAY_SIZE_(a)));
+ vector<std::string> test_vector(std::begin(a), std::end(a));
+ EXPECT_THAT(test_vector, ElementsAreArray(a.data(), a.size()));
- const char** p = a;
+ const char** p = a.data();
test_vector[0] = "1";
- EXPECT_THAT(test_vector, Not(ElementsAreArray(p, GTEST_ARRAY_SIZE_(a))));
+ EXPECT_THAT(test_vector, Not(ElementsAreArray(p, a.size())));
}
TEST(ElementsAreArrayTest, CanBeCreatedWithoutArraySize) {
const char* a[] = { "one", "two", "three" };
- vector<std::string> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<std::string> test_vector(std::begin(a), std::end(a));
EXPECT_THAT(test_vector, ElementsAreArray(a));
test_vector[0] = "1";
@@ -484,8 +474,8 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherArray) {
TEST(ElementsAreArrayTest, CanBeCreatedWithVector) {
const int a[] = { 1, 2, 3 };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
- const vector<int> expected(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> test_vector(std::begin(a), std::end(a));
+ const vector<int> expected(std::begin(a), std::end(a));
EXPECT_THAT(test_vector, ElementsAreArray(expected));
test_vector.push_back(4);
EXPECT_THAT(test_vector, Not(ElementsAreArray(expected)));
@@ -530,9 +520,9 @@ TEST(ElementsAreArrayTest,
TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherVector) {
const int a[] = { 1, 2, 3 };
const Matcher<int> kMatchers[] = { Eq(1), Eq(2), Eq(3) };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
- const vector<Matcher<int> > expected(
- kMatchers, kMatchers + GTEST_ARRAY_SIZE_(kMatchers));
+ vector<int> test_vector(std::begin(a), std::end(a));
+ const vector<Matcher<int>> expected(std::begin(kMatchers),
+ std::end(kMatchers));
EXPECT_THAT(test_vector, ElementsAreArray(expected));
test_vector.push_back(4);
EXPECT_THAT(test_vector, Not(ElementsAreArray(expected)));
@@ -540,11 +530,11 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherVector) {
TEST(ElementsAreArrayTest, CanBeCreatedWithIteratorRange) {
const int a[] = { 1, 2, 3 };
- const vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
- const vector<int> expected(a, a + GTEST_ARRAY_SIZE_(a));
+ const vector<int> test_vector(std::begin(a), std::end(a));
+ const vector<int> expected(std::begin(a), std::end(a));
EXPECT_THAT(test_vector, ElementsAreArray(expected.begin(), expected.end()));
// Pointers are iterators, too.
- EXPECT_THAT(test_vector, ElementsAreArray(a, a + GTEST_ARRAY_SIZE_(a)));
+ EXPECT_THAT(test_vector, ElementsAreArray(std::begin(a), std::end(a)));
// The empty range of NULL pointers should also be okay.
int* const null_int = nullptr;
EXPECT_THAT(test_vector, Not(ElementsAreArray(null_int, null_int)));
@@ -564,8 +554,8 @@ TEST(ElementsAreArrayTest, WorksWithNativeArray) {
TEST(ElementsAreArrayTest, SourceLifeSpan) {
const int a[] = { 1, 2, 3 };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
- vector<int> expect(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> test_vector(std::begin(a), std::end(a));
+ vector<int> expect(std::begin(a), std::end(a));
ElementsAreArrayMatcher<int> matcher_maker =
ElementsAreArray(expect.begin(), expect.end());
EXPECT_THAT(test_vector, matcher_maker);
@@ -774,9 +764,16 @@ MATCHER_P2(ReferencesAnyOf, variable1, variable2, "") {
TEST(MatcherPnMacroTest, WorksWhenExplicitlyInstantiatedWithReferences) {
UncopyableFoo foo1('1'), foo2('2'), foo3('3');
- const Matcher<const UncopyableFoo&> m =
+ const Matcher<const UncopyableFoo&> const_m =
ReferencesAnyOf<const UncopyableFoo&, const UncopyableFoo&>(foo1, foo2);
+ EXPECT_TRUE(const_m.Matches(foo1));
+ EXPECT_TRUE(const_m.Matches(foo2));
+ EXPECT_FALSE(const_m.Matches(foo3));
+
+ const Matcher<UncopyableFoo&> m =
+ ReferencesAnyOf<UncopyableFoo&, UncopyableFoo&>(foo1, foo2);
+
EXPECT_TRUE(m.Matches(foo1));
EXPECT_TRUE(m.Matches(foo2));
EXPECT_FALSE(m.Matches(foo3));
diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc
index d000e692..8019f4a3 100644
--- a/googlemock/test/gmock-internal-utils_test.cc
+++ b/googlemock/test/gmock-internal-utils_test.cc
@@ -36,11 +36,11 @@
#include <stdlib.h>
+#include <cstdint>
#include <map>
#include <memory>
#include <sstream>
#include <string>
-#include <type_traits>
#include <vector>
#include "gmock/gmock.h"
@@ -173,9 +173,9 @@ TEST(KindOfTest, Integer) {
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned int)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long)); // NOLINT
+ EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long long)); // NOLINT
+ 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_(Int64)); // NOLINT
- EXPECT_EQ(kInteger, GMOCK_KIND_OF_(UInt64)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(size_t)); // NOLINT
#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN
// ssize_t is not defined on Windows and possibly some other OSes.
@@ -223,11 +223,12 @@ TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
EXPECT_TRUE((LosslessArithmeticConvertible<unsigned char, int>::value));
// Unsigned => larger unsigned is fine.
- EXPECT_TRUE(
- (LosslessArithmeticConvertible<unsigned short, UInt64>::value)); // NOLINT
+ EXPECT_TRUE((LosslessArithmeticConvertible<
+ unsigned short, uint64_t>::value)); // NOLINT
// Signed => unsigned is not fine.
- EXPECT_FALSE((LosslessArithmeticConvertible<short, UInt64>::value)); // NOLINT
+ EXPECT_FALSE((LosslessArithmeticConvertible<
+ short, uint64_t>::value)); // NOLINT
EXPECT_FALSE((LosslessArithmeticConvertible<
signed char, unsigned int>::value)); // NOLINT
@@ -243,12 +244,12 @@ TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
EXPECT_FALSE((LosslessArithmeticConvertible<
unsigned char, signed char>::value));
EXPECT_FALSE((LosslessArithmeticConvertible<int, unsigned int>::value));
- EXPECT_FALSE((LosslessArithmeticConvertible<UInt64, Int64>::value));
+ EXPECT_FALSE((LosslessArithmeticConvertible<uint64_t, int64_t>::value));
// Larger size => smaller size is not fine.
EXPECT_FALSE((LosslessArithmeticConvertible<long, char>::value)); // NOLINT
EXPECT_FALSE((LosslessArithmeticConvertible<int, signed char>::value));
- EXPECT_FALSE((LosslessArithmeticConvertible<Int64, unsigned int>::value));
+ EXPECT_FALSE((LosslessArithmeticConvertible<int64_t, unsigned int>::value));
}
TEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) {
@@ -267,7 +268,7 @@ TEST(LosslessArithmeticConvertibleTest, FloatingPointToBool) {
TEST(LosslessArithmeticConvertibleTest, FloatingPointToInteger) {
EXPECT_FALSE((LosslessArithmeticConvertible<float, long>::value)); // NOLINT
- EXPECT_FALSE((LosslessArithmeticConvertible<double, Int64>::value));
+ EXPECT_FALSE((LosslessArithmeticConvertible<double, int64_t>::value));
EXPECT_FALSE((LosslessArithmeticConvertible<long double, int>::value));
}
diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc
index 03735267..3619959f 100644
--- a/googlemock/test/gmock-matchers_test.cc
+++ b/googlemock/test/gmock-matchers_test.cc
@@ -41,10 +41,12 @@
#endif
#include "gmock/gmock-matchers.h"
-#include "gmock/gmock-more-matchers.h"
#include <string.h>
#include <time.h>
+
+#include <array>
+#include <cstdint>
#include <deque>
#include <forward_list>
#include <functional>
@@ -60,9 +62,11 @@
#include <type_traits>
#include <utility>
#include <vector>
+
+#include "gmock/gmock-more-matchers.h"
#include "gmock/gmock.h"
-#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
+#include "gtest/gtest.h"
namespace testing {
namespace gmock_matchers_test {
@@ -136,7 +140,7 @@ Matcher<int> GreaterThan(int n) {
std::string OfType(const std::string& type_name) {
#if GTEST_HAS_RTTI
- return " (of type " + type_name + ")";
+ return IsReadableTypeName(type_name) ? " (of type " + type_name + ")" : "";
#else
return "";
#endif
@@ -347,43 +351,43 @@ TEST(StringMatcherTest, CanBeImplicitlyConstructedFromString) {
EXPECT_FALSE(m2.Matches("hello"));
}
-#if GTEST_HAS_ABSL
+#if GTEST_INTERNAL_HAS_STRING_VIEW
// Tests that a C-string literal can be implicitly converted to a
-// Matcher<absl::string_view> or Matcher<const absl::string_view&>.
+// Matcher<StringView> or Matcher<const StringView&>.
TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) {
- Matcher<absl::string_view> m1 = "cats";
+ Matcher<internal::StringView> m1 = "cats";
EXPECT_TRUE(m1.Matches("cats"));
EXPECT_FALSE(m1.Matches("dogs"));
- Matcher<const absl::string_view&> m2 = "cats";
+ Matcher<const internal::StringView&> m2 = "cats";
EXPECT_TRUE(m2.Matches("cats"));
EXPECT_FALSE(m2.Matches("dogs"));
}
// Tests that a std::string object can be implicitly converted to a
-// Matcher<absl::string_view> or Matcher<const absl::string_view&>.
+// Matcher<StringView> or Matcher<const StringView&>.
TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromString) {
- Matcher<absl::string_view> m1 = std::string("cats");
+ Matcher<internal::StringView> m1 = std::string("cats");
EXPECT_TRUE(m1.Matches("cats"));
EXPECT_FALSE(m1.Matches("dogs"));
- Matcher<const absl::string_view&> m2 = std::string("cats");
+ Matcher<const internal::StringView&> m2 = std::string("cats");
EXPECT_TRUE(m2.Matches("cats"));
EXPECT_FALSE(m2.Matches("dogs"));
}
-// Tests that a absl::string_view object can be implicitly converted to a
-// Matcher<absl::string_view> or Matcher<const absl::string_view&>.
+// Tests that a StringView object can be implicitly converted to a
+// Matcher<StringView> or Matcher<const StringView&>.
TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromStringView) {
- Matcher<absl::string_view> m1 = absl::string_view("cats");
+ Matcher<internal::StringView> m1 = internal::StringView("cats");
EXPECT_TRUE(m1.Matches("cats"));
EXPECT_FALSE(m1.Matches("dogs"));
- Matcher<const absl::string_view&> m2 = absl::string_view("cats");
+ Matcher<const internal::StringView&> m2 = internal::StringView("cats");
EXPECT_TRUE(m2.Matches("cats"));
EXPECT_FALSE(m2.Matches("dogs"));
}
-#endif // GTEST_HAS_ABSL
+#endif // GTEST_INTERNAL_HAS_STRING_VIEW
// Tests that a std::reference_wrapper<std::string> object can be implicitly
// converted to a Matcher<std::string> or Matcher<const std::string&> via Eq().
@@ -761,10 +765,11 @@ TEST(SafeMatcherCastTest, FromConstReferenceToReference) {
// Tests that MatcherCast<const T&>(m) works when m is a Matcher<T>.
TEST(SafeMatcherCastTest, FromNonReferenceToConstReference) {
- Matcher<int> m1 = Eq(0);
- Matcher<const int&> m2 = SafeMatcherCast<const int&>(m1);
- EXPECT_TRUE(m2.Matches(0));
- EXPECT_FALSE(m2.Matches(1));
+ Matcher<std::unique_ptr<int>> m1 = IsNull();
+ Matcher<const std::unique_ptr<int>&> m2 =
+ SafeMatcherCast<const std::unique_ptr<int>&>(m1);
+ EXPECT_TRUE(m2.Matches(std::unique_ptr<int>()));
+ EXPECT_FALSE(m2.Matches(std::unique_ptr<int>(new int)));
}
// Tests that SafeMatcherCast<T&>(m) works when m is a Matcher<T>.
@@ -1231,17 +1236,17 @@ TEST(StrEqTest, MatchesEqualString) {
EXPECT_TRUE(m2.Matches("Hello"));
EXPECT_FALSE(m2.Matches("Hi"));
-#if GTEST_HAS_ABSL
- Matcher<const absl::string_view&> m3 = StrEq("Hello");
- EXPECT_TRUE(m3.Matches(absl::string_view("Hello")));
- EXPECT_FALSE(m3.Matches(absl::string_view("hello")));
- EXPECT_FALSE(m3.Matches(absl::string_view()));
+#if GTEST_INTERNAL_HAS_STRING_VIEW
+ Matcher<const internal::StringView&> m3 = StrEq("Hello");
+ EXPECT_TRUE(m3.Matches(internal::StringView("Hello")));
+ EXPECT_FALSE(m3.Matches(internal::StringView("hello")));
+ EXPECT_FALSE(m3.Matches(internal::StringView()));
- Matcher<const absl::string_view&> m_empty = StrEq("");
- EXPECT_TRUE(m_empty.Matches(absl::string_view("")));
- EXPECT_TRUE(m_empty.Matches(absl::string_view()));
- EXPECT_FALSE(m_empty.Matches(absl::string_view("hello")));
-#endif // GTEST_HAS_ABSL
+ Matcher<const internal::StringView&> m_empty = StrEq("");
+ EXPECT_TRUE(m_empty.Matches(internal::StringView("")));
+ EXPECT_TRUE(m_empty.Matches(internal::StringView()));
+ EXPECT_FALSE(m_empty.Matches(internal::StringView("hello")));
+#endif // GTEST_INTERNAL_HAS_STRING_VIEW
}
TEST(StrEqTest, CanDescribeSelf) {
@@ -1268,12 +1273,12 @@ TEST(StrNeTest, MatchesUnequalString) {
EXPECT_TRUE(m2.Matches("hello"));
EXPECT_FALSE(m2.Matches("Hello"));
-#if GTEST_HAS_ABSL
- Matcher<const absl::string_view> m3 = StrNe("Hello");
- EXPECT_TRUE(m3.Matches(absl::string_view("")));
- EXPECT_TRUE(m3.Matches(absl::string_view()));
- EXPECT_FALSE(m3.Matches(absl::string_view("Hello")));
-#endif // GTEST_HAS_ABSL
+#if GTEST_INTERNAL_HAS_STRING_VIEW
+ Matcher<const internal::StringView> m3 = StrNe("Hello");
+ EXPECT_TRUE(m3.Matches(internal::StringView("")));
+ EXPECT_TRUE(m3.Matches(internal::StringView()));
+ EXPECT_FALSE(m3.Matches(internal::StringView("Hello")));
+#endif // GTEST_INTERNAL_HAS_STRING_VIEW
}
TEST(StrNeTest, CanDescribeSelf) {
@@ -1292,13 +1297,13 @@ TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) {
EXPECT_TRUE(m2.Matches("hello"));
EXPECT_FALSE(m2.Matches("Hi"));
-#if GTEST_HAS_ABSL
- Matcher<const absl::string_view&> m3 = StrCaseEq(std::string("Hello"));
- EXPECT_TRUE(m3.Matches(absl::string_view("Hello")));
- EXPECT_TRUE(m3.Matches(absl::string_view("hello")));
- EXPECT_FALSE(m3.Matches(absl::string_view("Hi")));
- EXPECT_FALSE(m3.Matches(absl::string_view()));
-#endif // GTEST_HAS_ABSL
+#if GTEST_INTERNAL_HAS_STRING_VIEW
+ Matcher<const internal::StringView&> m3 = StrCaseEq(std::string("Hello"));
+ EXPECT_TRUE(m3.Matches(internal::StringView("Hello")));
+ EXPECT_TRUE(m3.Matches(internal::StringView("hello")));
+ EXPECT_FALSE(m3.Matches(internal::StringView("Hi")));
+ EXPECT_FALSE(m3.Matches(internal::StringView()));
+#endif // GTEST_INTERNAL_HAS_STRING_VIEW
}
TEST(StrCaseEqTest, MatchesEqualStringWith0IgnoringCase) {
@@ -1342,13 +1347,13 @@ TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) {
EXPECT_TRUE(m2.Matches(""));
EXPECT_FALSE(m2.Matches("Hello"));
-#if GTEST_HAS_ABSL
- Matcher<const absl::string_view> m3 = StrCaseNe("Hello");
- EXPECT_TRUE(m3.Matches(absl::string_view("Hi")));
- EXPECT_TRUE(m3.Matches(absl::string_view()));
- EXPECT_FALSE(m3.Matches(absl::string_view("Hello")));
- EXPECT_FALSE(m3.Matches(absl::string_view("hello")));
-#endif // GTEST_HAS_ABSL
+#if GTEST_INTERNAL_HAS_STRING_VIEW
+ Matcher<const internal::StringView> m3 = StrCaseNe("Hello");
+ EXPECT_TRUE(m3.Matches(internal::StringView("Hi")));
+ EXPECT_TRUE(m3.Matches(internal::StringView()));
+ EXPECT_FALSE(m3.Matches(internal::StringView("Hello")));
+ EXPECT_FALSE(m3.Matches(internal::StringView("hello")));
+#endif // GTEST_INTERNAL_HAS_STRING_VIEW
}
TEST(StrCaseNeTest, CanDescribeSelf) {
@@ -1389,25 +1394,25 @@ TEST(HasSubstrTest, WorksForCStrings) {
EXPECT_FALSE(m_empty.Matches(nullptr));
}
-#if GTEST_HAS_ABSL
-// Tests that HasSubstr() works for matching absl::string_view-typed values.
+#if GTEST_INTERNAL_HAS_STRING_VIEW
+// Tests that HasSubstr() works for matching StringView-typed values.
TEST(HasSubstrTest, WorksForStringViewClasses) {
- const Matcher<absl::string_view> m1 = HasSubstr("foo");
- EXPECT_TRUE(m1.Matches(absl::string_view("I love food.")));
- EXPECT_FALSE(m1.Matches(absl::string_view("tofo")));
- EXPECT_FALSE(m1.Matches(absl::string_view()));
+ const Matcher<internal::StringView> m1 = HasSubstr("foo");
+ EXPECT_TRUE(m1.Matches(internal::StringView("I love food.")));
+ EXPECT_FALSE(m1.Matches(internal::StringView("tofo")));
+ EXPECT_FALSE(m1.Matches(internal::StringView()));
- const Matcher<const absl::string_view&> m2 = HasSubstr("foo");
- EXPECT_TRUE(m2.Matches(absl::string_view("I love food.")));
- EXPECT_FALSE(m2.Matches(absl::string_view("tofo")));
- EXPECT_FALSE(m2.Matches(absl::string_view()));
+ const Matcher<const internal::StringView&> m2 = HasSubstr("foo");
+ EXPECT_TRUE(m2.Matches(internal::StringView("I love food.")));
+ EXPECT_FALSE(m2.Matches(internal::StringView("tofo")));
+ EXPECT_FALSE(m2.Matches(internal::StringView()));
- const Matcher<const absl::string_view&> m3 = HasSubstr("");
- EXPECT_TRUE(m3.Matches(absl::string_view("foo")));
- EXPECT_TRUE(m3.Matches(absl::string_view("")));
- EXPECT_TRUE(m3.Matches(absl::string_view()));
+ const Matcher<const internal::StringView&> m3 = HasSubstr("");
+ EXPECT_TRUE(m3.Matches(internal::StringView("foo")));
+ EXPECT_TRUE(m3.Matches(internal::StringView("")));
+ EXPECT_TRUE(m3.Matches(internal::StringView()));
}
-#endif // GTEST_HAS_ABSL
+#endif // GTEST_INTERNAL_HAS_STRING_VIEW
// Tests that HasSubstr(s) describes itself properly.
TEST(HasSubstrTest, CanDescribeSelf) {
@@ -1644,12 +1649,12 @@ TEST(StartsWithTest, MatchesStringWithGivenPrefix) {
EXPECT_FALSE(m2.Matches("H"));
EXPECT_FALSE(m2.Matches(" Hi"));
-#if GTEST_HAS_ABSL
- const Matcher<absl::string_view> m_empty = StartsWith("");
- EXPECT_TRUE(m_empty.Matches(absl::string_view()));
- EXPECT_TRUE(m_empty.Matches(absl::string_view("")));
- EXPECT_TRUE(m_empty.Matches(absl::string_view("not empty")));
-#endif // GTEST_HAS_ABSL
+#if GTEST_INTERNAL_HAS_STRING_VIEW
+ const Matcher<internal::StringView> m_empty = StartsWith("");
+ EXPECT_TRUE(m_empty.Matches(internal::StringView()));
+ EXPECT_TRUE(m_empty.Matches(internal::StringView("")));
+ EXPECT_TRUE(m_empty.Matches(internal::StringView("not empty")));
+#endif // GTEST_INTERNAL_HAS_STRING_VIEW
}
TEST(StartsWithTest, CanDescribeSelf) {
@@ -1672,13 +1677,13 @@ TEST(EndsWithTest, MatchesStringWithGivenSuffix) {
EXPECT_FALSE(m2.Matches("i"));
EXPECT_FALSE(m2.Matches("Hi "));
-#if GTEST_HAS_ABSL
- const Matcher<const absl::string_view&> m4 = EndsWith("");
+#if GTEST_INTERNAL_HAS_STRING_VIEW
+ const Matcher<const internal::StringView&> m4 = EndsWith("");
EXPECT_TRUE(m4.Matches("Hi"));
EXPECT_TRUE(m4.Matches(""));
- EXPECT_TRUE(m4.Matches(absl::string_view()));
- EXPECT_TRUE(m4.Matches(absl::string_view("")));
-#endif // GTEST_HAS_ABSL
+ EXPECT_TRUE(m4.Matches(internal::StringView()));
+ EXPECT_TRUE(m4.Matches(internal::StringView("")));
+#endif // GTEST_INTERNAL_HAS_STRING_VIEW
}
TEST(EndsWithTest, CanDescribeSelf) {
@@ -1699,16 +1704,16 @@ TEST(MatchesRegexTest, MatchesStringMatchingGivenRegex) {
EXPECT_FALSE(m2.Matches("az1"));
EXPECT_FALSE(m2.Matches("1az"));
-#if GTEST_HAS_ABSL
- const Matcher<const absl::string_view&> m3 = MatchesRegex("a.*z");
- EXPECT_TRUE(m3.Matches(absl::string_view("az")));
- EXPECT_TRUE(m3.Matches(absl::string_view("abcz")));
- EXPECT_FALSE(m3.Matches(absl::string_view("1az")));
- EXPECT_FALSE(m3.Matches(absl::string_view()));
- const Matcher<const absl::string_view&> m4 = MatchesRegex("");
- EXPECT_TRUE(m4.Matches(absl::string_view("")));
- EXPECT_TRUE(m4.Matches(absl::string_view()));
-#endif // GTEST_HAS_ABSL
+#if GTEST_INTERNAL_HAS_STRING_VIEW
+ const Matcher<const internal::StringView&> m3 = MatchesRegex("a.*z");
+ EXPECT_TRUE(m3.Matches(internal::StringView("az")));
+ EXPECT_TRUE(m3.Matches(internal::StringView("abcz")));
+ EXPECT_FALSE(m3.Matches(internal::StringView("1az")));
+ EXPECT_FALSE(m3.Matches(internal::StringView()));
+ const Matcher<const internal::StringView&> m4 = MatchesRegex("");
+ EXPECT_TRUE(m4.Matches(internal::StringView("")));
+ EXPECT_TRUE(m4.Matches(internal::StringView()));
+#endif // GTEST_INTERNAL_HAS_STRING_VIEW
}
TEST(MatchesRegexTest, CanDescribeSelf) {
@@ -1718,10 +1723,10 @@ TEST(MatchesRegexTest, CanDescribeSelf) {
Matcher<const char*> m2 = MatchesRegex(new RE("a.*"));
EXPECT_EQ("matches regular expression \"a.*\"", Describe(m2));
-#if GTEST_HAS_ABSL
- Matcher<const absl::string_view> m3 = MatchesRegex(new RE("0.*"));
+#if GTEST_INTERNAL_HAS_STRING_VIEW
+ Matcher<const internal::StringView> m3 = MatchesRegex(new RE("0.*"));
EXPECT_EQ("matches regular expression \"0.*\"", Describe(m3));
-#endif // GTEST_HAS_ABSL
+#endif // GTEST_INTERNAL_HAS_STRING_VIEW
}
// Tests ContainsRegex().
@@ -1737,16 +1742,17 @@ TEST(ContainsRegexTest, MatchesStringContainingGivenRegex) {
EXPECT_TRUE(m2.Matches("az1"));
EXPECT_FALSE(m2.Matches("1a"));
-#if GTEST_HAS_ABSL
- const Matcher<const absl::string_view&> m3 = ContainsRegex(new RE("a.*z"));
- EXPECT_TRUE(m3.Matches(absl::string_view("azbz")));
- EXPECT_TRUE(m3.Matches(absl::string_view("az1")));
- EXPECT_FALSE(m3.Matches(absl::string_view("1a")));
- EXPECT_FALSE(m3.Matches(absl::string_view()));
- const Matcher<const absl::string_view&> m4 = ContainsRegex("");
- EXPECT_TRUE(m4.Matches(absl::string_view("")));
- EXPECT_TRUE(m4.Matches(absl::string_view()));
-#endif // GTEST_HAS_ABSL
+#if GTEST_INTERNAL_HAS_STRING_VIEW
+ const Matcher<const internal::StringView&> m3 =
+ ContainsRegex(new RE("a.*z"));
+ EXPECT_TRUE(m3.Matches(internal::StringView("azbz")));
+ EXPECT_TRUE(m3.Matches(internal::StringView("az1")));
+ EXPECT_FALSE(m3.Matches(internal::StringView("1a")));
+ EXPECT_FALSE(m3.Matches(internal::StringView()));
+ const Matcher<const internal::StringView&> m4 = ContainsRegex("");
+ EXPECT_TRUE(m4.Matches(internal::StringView("")));
+ EXPECT_TRUE(m4.Matches(internal::StringView()));
+#endif // GTEST_INTERNAL_HAS_STRING_VIEW
}
TEST(ContainsRegexTest, CanDescribeSelf) {
@@ -1756,10 +1762,10 @@ TEST(ContainsRegexTest, CanDescribeSelf) {
Matcher<const char*> m2 = ContainsRegex(new RE("a.*"));
EXPECT_EQ("contains regular expression \"a.*\"", Describe(m2));
-#if GTEST_HAS_ABSL
- Matcher<const absl::string_view> m3 = ContainsRegex(new RE("0.*"));
+#if GTEST_INTERNAL_HAS_STRING_VIEW
+ Matcher<const internal::StringView> m3 = ContainsRegex(new RE("0.*"));
EXPECT_EQ("contains regular expression \"0.*\"", Describe(m3));
-#endif // GTEST_HAS_ABSL
+#endif // GTEST_INTERNAL_HAS_STRING_VIEW
}
// Tests for wide strings.
@@ -2054,6 +2060,114 @@ TEST(PairMatchBaseTest, WorksWithMoveOnly) {
EXPECT_TRUE(matcher.Matches(pointers));
}
+// Tests that IsNan() matches a NaN, with float.
+TEST(IsNan, FloatMatchesNan) {
+ float quiet_nan = std::numeric_limits<float>::quiet_NaN();
+ float other_nan = std::nanf("1");
+ float real_value = 1.0f;
+
+ Matcher<float> m = IsNan();
+ EXPECT_TRUE(m.Matches(quiet_nan));
+ EXPECT_TRUE(m.Matches(other_nan));
+ EXPECT_FALSE(m.Matches(real_value));
+
+ Matcher<float&> m_ref = IsNan();
+ EXPECT_TRUE(m_ref.Matches(quiet_nan));
+ EXPECT_TRUE(m_ref.Matches(other_nan));
+ EXPECT_FALSE(m_ref.Matches(real_value));
+
+ Matcher<const float&> m_cref = IsNan();
+ EXPECT_TRUE(m_cref.Matches(quiet_nan));
+ EXPECT_TRUE(m_cref.Matches(other_nan));
+ EXPECT_FALSE(m_cref.Matches(real_value));
+}
+
+// Tests that IsNan() matches a NaN, with double.
+TEST(IsNan, DoubleMatchesNan) {
+ double quiet_nan = std::numeric_limits<double>::quiet_NaN();
+ double other_nan = std::nan("1");
+ double real_value = 1.0;
+
+ Matcher<double> m = IsNan();
+ EXPECT_TRUE(m.Matches(quiet_nan));
+ EXPECT_TRUE(m.Matches(other_nan));
+ EXPECT_FALSE(m.Matches(real_value));
+
+ Matcher<double&> m_ref = IsNan();
+ EXPECT_TRUE(m_ref.Matches(quiet_nan));
+ EXPECT_TRUE(m_ref.Matches(other_nan));
+ EXPECT_FALSE(m_ref.Matches(real_value));
+
+ Matcher<const double&> m_cref = IsNan();
+ EXPECT_TRUE(m_cref.Matches(quiet_nan));
+ EXPECT_TRUE(m_cref.Matches(other_nan));
+ EXPECT_FALSE(m_cref.Matches(real_value));
+}
+
+// Tests that IsNan() matches a NaN, with long double.
+TEST(IsNan, LongDoubleMatchesNan) {
+ long double quiet_nan = std::numeric_limits<long double>::quiet_NaN();
+ long double other_nan = std::nan("1");
+ long double real_value = 1.0;
+
+ Matcher<long double> m = IsNan();
+ EXPECT_TRUE(m.Matches(quiet_nan));
+ EXPECT_TRUE(m.Matches(other_nan));
+ EXPECT_FALSE(m.Matches(real_value));
+
+ Matcher<long double&> m_ref = IsNan();
+ EXPECT_TRUE(m_ref.Matches(quiet_nan));
+ EXPECT_TRUE(m_ref.Matches(other_nan));
+ EXPECT_FALSE(m_ref.Matches(real_value));
+
+ Matcher<const long double&> m_cref = IsNan();
+ EXPECT_TRUE(m_cref.Matches(quiet_nan));
+ EXPECT_TRUE(m_cref.Matches(other_nan));
+ EXPECT_FALSE(m_cref.Matches(real_value));
+}
+
+// Tests that IsNan() works with Not.
+TEST(IsNan, NotMatchesNan) {
+ Matcher<float> mf = Not(IsNan());
+ EXPECT_FALSE(mf.Matches(std::numeric_limits<float>::quiet_NaN()));
+ EXPECT_FALSE(mf.Matches(std::nanf("1")));
+ EXPECT_TRUE(mf.Matches(1.0));
+
+ Matcher<double> md = Not(IsNan());
+ EXPECT_FALSE(md.Matches(std::numeric_limits<double>::quiet_NaN()));
+ EXPECT_FALSE(md.Matches(std::nan("1")));
+ EXPECT_TRUE(md.Matches(1.0));
+
+ Matcher<long double> mld = Not(IsNan());
+ EXPECT_FALSE(mld.Matches(std::numeric_limits<long double>::quiet_NaN()));
+ EXPECT_FALSE(mld.Matches(std::nanl("1")));
+ EXPECT_TRUE(mld.Matches(1.0));
+}
+
+// Tests that IsNan() can describe itself.
+TEST(IsNan, CanDescribeSelf) {
+ Matcher<float> mf = IsNan();
+ EXPECT_EQ("is NaN", Describe(mf));
+
+ Matcher<double> md = IsNan();
+ EXPECT_EQ("is NaN", Describe(md));
+
+ Matcher<long double> mld = IsNan();
+ EXPECT_EQ("is NaN", Describe(mld));
+}
+
+// Tests that IsNan() can describe itself with Not.
+TEST(IsNan, CanDescribeSelfWithNot) {
+ Matcher<float> mf = Not(IsNan());
+ EXPECT_EQ("isn't NaN", Describe(mf));
+
+ Matcher<double> md = Not(IsNan());
+ EXPECT_EQ("isn't NaN", Describe(md));
+
+ Matcher<long double> mld = Not(IsNan());
+ EXPECT_EQ("isn't NaN", Describe(mld));
+}
+
// Tests that FloatEq() matches a 2-tuple where
// FloatEq(first field) matches the second field.
TEST(FloatEq2Test, MatchesEqualArguments) {
@@ -2763,6 +2877,33 @@ TEST(ExplainMatchResultTest, WorksWithMonomorphicMatcher) {
EXPECT_EQ("", listener2.str());
}
+MATCHER(ConstructNoArg, "") { return true; }
+MATCHER_P(Construct1Arg, arg1, "") { return true; }
+MATCHER_P2(Construct2Args, arg1, arg2, "") { return true; }
+
+TEST(MatcherConstruct, ExplicitVsImplicit) {
+ {
+ // No arg constructor can be constructed with empty brace.
+ ConstructNoArgMatcher m = {};
+ (void)m;
+ // And with no args
+ ConstructNoArgMatcher m2;
+ (void)m2;
+ }
+ {
+ // The one arg constructor has an explicit constructor.
+ // This is to prevent the implicit conversion.
+ using M = Construct1ArgMatcherP<int>;
+ EXPECT_TRUE((std::is_constructible<M, int>::value));
+ EXPECT_FALSE((std::is_convertible<int, M>::value));
+ }
+ {
+ // Multiple arg matchers can be constructed with an implicit construction.
+ Construct2ArgsMatcherP2<int, double> m = {1, 2.2};
+ (void)m;
+ }
+}
+
MATCHER_P(Really, inner_matcher, "") {
return ExplainMatchResult(inner_matcher, arg, result_listener);
}
@@ -2876,18 +3017,13 @@ TEST(MatcherAssertionTest, WorksWhenMatcherIsNotSatisfied) {
static unsigned short n; // NOLINT
n = 5;
- // VC++ prior to version 8.0 SP1 has a bug where it will not see any
- // functions declared in the namespace scope from within nested classes.
- // EXPECT/ASSERT_(NON)FATAL_FAILURE macros use nested classes so that all
- // namespace-level functions invoked inside them need to be explicitly
- // resolved.
- EXPECT_FATAL_FAILURE(ASSERT_THAT(n, ::testing::Gt(10)),
+ EXPECT_FATAL_FAILURE(ASSERT_THAT(n, Gt(10)),
"Value of: n\n"
"Expected: is > 10\n"
" Actual: 5" + OfType("unsigned short"));
n = 0;
EXPECT_NONFATAL_FAILURE(
- EXPECT_THAT(n, ::testing::AllOf(::testing::Le(7), ::testing::Ge(5))),
+ EXPECT_THAT(n, AllOf(Le(7), Ge(5))),
"Value of: n\n"
"Expected: (is <= 7) and (is >= 5)\n"
" Actual: 0" + OfType("unsigned short"));
@@ -2901,11 +3037,11 @@ TEST(MatcherAssertionTest, WorksForByRefArguments) {
static int n;
n = 0;
EXPECT_THAT(n, AllOf(Le(7), Ref(n)));
- EXPECT_FATAL_FAILURE(ASSERT_THAT(n, ::testing::Not(::testing::Ref(n))),
+ EXPECT_FATAL_FAILURE(ASSERT_THAT(n, Not(Ref(n))),
"Value of: n\n"
"Expected: does not reference the variable @");
// Tests the "Actual" part.
- EXPECT_FATAL_FAILURE(ASSERT_THAT(n, ::testing::Not(::testing::Ref(n))),
+ EXPECT_FATAL_FAILURE(ASSERT_THAT(n, Not(Ref(n))),
"Actual: 0" + OfType("int") + ", which is located @");
}
@@ -5093,14 +5229,14 @@ TEST(WhenSortedTest, WorksForStreamlike) {
// Streamlike 'container' provides only minimal iterator support.
// Its iterators are tagged with input_iterator_tag.
const int a[5] = {2, 1, 4, 5, 3};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
EXPECT_THAT(s, WhenSorted(ElementsAre(1, 2, 3, 4, 5)));
EXPECT_THAT(s, Not(WhenSorted(ElementsAre(2, 1, 4, 5, 3))));
}
TEST(WhenSortedTest, WorksForVectorConstRefMatcherOnStreamlike) {
const int a[] = {2, 1, 4, 5, 3};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
Matcher<const std::vector<int>&> vector_match = ElementsAre(1, 2, 3, 4, 5);
EXPECT_THAT(s, WhenSorted(vector_match));
EXPECT_THAT(s, Not(WhenSorted(ElementsAre(2, 1, 4, 5, 3))));
@@ -5145,7 +5281,7 @@ TEST(IsSupersetOfTest, WorksForEmpty) {
TEST(IsSupersetOfTest, WorksForStreamlike) {
const int a[5] = {1, 2, 3, 4, 5};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
vector<int> expected;
expected.push_back(1);
@@ -5273,7 +5409,7 @@ TEST(IsSubsetOfTest, WorksForEmpty) {
TEST(IsSubsetOfTest, WorksForStreamlike) {
const int a[5] = {1, 2};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
vector<int> expected;
expected.push_back(1);
@@ -5367,14 +5503,14 @@ TEST(IsSubsetOfTest, WorksWithMoveOnly) {
TEST(ElemensAreStreamTest, WorksForStreamlike) {
const int a[5] = {1, 2, 3, 4, 5};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
EXPECT_THAT(s, ElementsAre(1, 2, 3, 4, 5));
EXPECT_THAT(s, Not(ElementsAre(2, 1, 4, 5, 3)));
}
TEST(ElemensAreArrayStreamTest, WorksForStreamlike) {
const int a[5] = {1, 2, 3, 4, 5};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
vector<int> expected;
expected.push_back(1);
@@ -5421,7 +5557,7 @@ TEST(ElementsAreTest, TakesStlContainer) {
TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) {
const int a[] = {0, 1, 2, 3, 4};
- std::vector<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ std::vector<int> s(std::begin(a), std::end(a));
do {
StringMatchResultListener listener;
EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAreArray(a),
@@ -5432,8 +5568,8 @@ TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) {
TEST(UnorderedElementsAreArrayTest, VectorBool) {
const bool a[] = {0, 1, 0, 1, 1};
const bool b[] = {1, 0, 1, 1, 0};
- std::vector<bool> expected(a, a + GTEST_ARRAY_SIZE_(a));
- std::vector<bool> actual(b, b + GTEST_ARRAY_SIZE_(b));
+ std::vector<bool> expected(std::begin(a), std::end(a));
+ std::vector<bool> actual(std::begin(b), std::end(b));
StringMatchResultListener listener;
EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAreArray(expected),
actual, &listener)) << listener.str();
@@ -5444,7 +5580,7 @@ TEST(UnorderedElementsAreArrayTest, WorksForStreamlike) {
// Its iterators are tagged with input_iterator_tag, and it has no
// size() or empty() methods.
const int a[5] = {2, 1, 4, 5, 3};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
::std::vector<int> expected;
expected.push_back(1);
@@ -5527,7 +5663,7 @@ TEST_F(UnorderedElementsAreTest, WorksWithUncopyable) {
TEST_F(UnorderedElementsAreTest, SucceedsWhenExpected) {
const int a[] = {1, 2, 3};
- std::vector<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ std::vector<int> s(std::begin(a), std::end(a));
do {
StringMatchResultListener listener;
EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAre(1, 2, 3),
@@ -5537,7 +5673,7 @@ TEST_F(UnorderedElementsAreTest, SucceedsWhenExpected) {
TEST_F(UnorderedElementsAreTest, FailsWhenAnElementMatchesNoMatcher) {
const int a[] = {1, 2, 3};
- std::vector<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ std::vector<int> s(std::begin(a), std::end(a));
std::vector<Matcher<int> > mv;
mv.push_back(1);
mv.push_back(2);
@@ -5553,7 +5689,7 @@ TEST_F(UnorderedElementsAreTest, WorksForStreamlike) {
// Its iterators are tagged with input_iterator_tag, and it has no
// size() or empty() methods.
const int a[5] = {2, 1, 4, 5, 3};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
EXPECT_THAT(s, UnorderedElementsAre(1, 2, 3, 4, 5));
EXPECT_THAT(s, Not(UnorderedElementsAre(2, 2, 3, 4, 5)));
@@ -5869,8 +6005,9 @@ TEST_F(BipartiteNonSquareTest, SimpleBacktracking) {
// :.......:
// 0 1 2
MatchMatrix g(4, 3);
- static const size_t kEdges[][2] = {{0, 2}, {1, 1}, {2, 1}, {3, 0}};
- for (size_t i = 0; i < GTEST_ARRAY_SIZE_(kEdges); ++i) {
+ constexpr std::array<std::array<size_t, 2>, 4> kEdges = {
+ {{{0, 2}}, {{1, 1}}, {{2, 1}}, {{3, 0}}}};
+ for (size_t i = 0; i < kEdges.size(); ++i) {
g.SetEdge(kEdges[i][0], kEdges[i][1], true);
}
EXPECT_THAT(FindBacktrackingMaxBPM(g),
@@ -5916,9 +6053,9 @@ TEST_P(BipartiteRandomTest, LargerNets) {
int iters = GetParam().second;
MatchMatrix graph(static_cast<size_t>(nodes), static_cast<size_t>(nodes));
- auto seed = static_cast<testing::internal::UInt32>(GTEST_FLAG(random_seed));
+ auto seed = static_cast<uint32_t>(GTEST_FLAG(random_seed));
if (seed == 0) {
- seed = static_cast<testing::internal::UInt32>(time(nullptr));
+ seed = static_cast<uint32_t>(time(nullptr));
}
for (; iters > 0; --iters, ++seed) {
@@ -6777,7 +6914,8 @@ TEST_F(PredicateFormatterFromMatcherTest, NoShortCircuitOnFailure) {
EXPECT_FALSE(result); // Implicit cast to bool.
std::string expect =
"Value of: dummy-name\nExpected: [DescribeTo]\n"
- " Actual: 1, [MatchAndExplain]";
+ " Actual: 1" +
+ OfType(internal::GetTypeName<Behavior>()) + ", [MatchAndExplain]";
EXPECT_EQ(expect, result.message());
}
@@ -6788,7 +6926,8 @@ TEST_F(PredicateFormatterFromMatcherTest, DetectsFlakyShortCircuit) {
"Value of: dummy-name\nExpected: [DescribeTo]\n"
" The matcher failed on the initial attempt; but passed when rerun to "
"generate the explanation.\n"
- " Actual: 2, [MatchAndExplain]";
+ " Actual: 2" +
+ OfType(internal::GetTypeName<Behavior>()) + ", [MatchAndExplain]";
EXPECT_EQ(expect, result.message());
}
diff --git a/googlemock/test/gmock-pp_test.cc b/googlemock/test/gmock-pp_test.cc
index 7387d398..5d1566e3 100644
--- a/googlemock/test/gmock-pp_test.cc
+++ b/googlemock/test/gmock-pp_test.cc
@@ -1,5 +1,10 @@
#include "gmock/internal/gmock-pp.h"
+// Used to test MSVC treating __VA_ARGS__ with a comma in it as one value
+#define GMOCK_TEST_REPLACE_comma_WITH_COMMA_I_comma ,
+#define GMOCK_TEST_REPLACE_comma_WITH_COMMA(x) \
+ GMOCK_PP_CAT(GMOCK_TEST_REPLACE_comma_WITH_COMMA_I_, x)
+
// Static assertions.
namespace testing {
namespace internal {
@@ -17,6 +22,11 @@ static_assert(GMOCK_PP_NARG(x, y, z, w) == 4, "");
static_assert(!GMOCK_PP_HAS_COMMA(), "");
static_assert(GMOCK_PP_HAS_COMMA(b, ), "");
static_assert(!GMOCK_PP_HAS_COMMA((, )), "");
+static_assert(GMOCK_PP_HAS_COMMA(GMOCK_TEST_REPLACE_comma_WITH_COMMA(comma)),
+ "");
+static_assert(
+ GMOCK_PP_HAS_COMMA(GMOCK_TEST_REPLACE_comma_WITH_COMMA(comma(unrelated))),
+ "");
static_assert(!GMOCK_PP_IS_EMPTY(, ), "");
static_assert(!GMOCK_PP_IS_EMPTY(a), "");
static_assert(!GMOCK_PP_IS_EMPTY(()), "");
diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc
index 7bf5a8ad..791a2476 100644
--- a/googlemock/test/gmock-spec-builders_test.cc
+++ b/googlemock/test/gmock-spec-builders_test.cc
@@ -69,8 +69,8 @@ using testing::AtMost;
using testing::Between;
using testing::Cardinality;
using testing::CardinalityInterface;
-using testing::ContainsRegex;
using testing::Const;
+using testing::ContainsRegex;
using testing::DoAll;
using testing::DoDefault;
using testing::Eq;
diff --git a/googlemock/test/gmock_all_test.cc b/googlemock/test/gmock_all_test.cc
index b2b2027d..c53d0965 100644
--- a/googlemock/test/gmock_all_test.cc
+++ b/googlemock/test/gmock_all_test.cc
@@ -38,7 +38,6 @@
#include "test/gmock-actions_test.cc"
#include "test/gmock-cardinalities_test.cc"
#include "test/gmock-generated-actions_test.cc"
-#include "test/gmock-generated-function-mockers_test.cc"
#include "test/gmock-generated-matchers_test.cc"
#include "test/gmock-internal-utils_test.cc"
#include "test/gmock-matchers_test.cc"
diff --git a/googlemock/test/pump_test.py b/googlemock/test/pump_test.py
new file mode 100755
index 00000000..eb5a1313
--- /dev/null
+++ b/googlemock/test/pump_test.py
@@ -0,0 +1,182 @@
+#!/usr/bin/env python
+#
+# Copyright 2010, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""Tests for the Pump meta-programming tool."""
+
+from google3.testing.pybase import googletest
+import google3.third_party.googletest.googlemock.scripts.pump
+
+pump = google3.third_party.googletest.googlemock.scripts.pump
+Convert = pump.ConvertFromPumpSource
+StripMetaComments = pump.StripMetaComments
+
+
+class PumpTest(googletest.TestCase):
+
+ def testConvertsEmptyToEmpty(self):
+ self.assertEquals('', Convert('').strip())
+
+ def testConvertsPlainCodeToSame(self):
+ self.assertEquals('#include <stdio.h>\n',
+ Convert('#include <stdio.h>\n'))
+
+ def testConvertsLongIWYUPragmaToSame(self):
+ long_line = '// IWYU pragma: private, include "' + (80*'a') + '.h"\n'
+ self.assertEquals(long_line, Convert(long_line))
+
+ def testConvertsIWYUPragmaWithLeadingSpaceToSame(self):
+ long_line = ' // IWYU pragma: private, include "' + (80*'a') + '.h"\n'
+ self.assertEquals(long_line, Convert(long_line))
+
+ def testConvertsIWYUPragmaWithSlashStarLeaderToSame(self):
+ long_line = '/* IWYU pragma: private, include "' + (80*'a') + '.h"\n'
+ self.assertEquals(long_line, Convert(long_line))
+
+ def testConvertsIWYUPragmaWithSlashStarAndSpacesToSame(self):
+ long_line = ' /* IWYU pragma: private, include "' + (80*'a') + '.h"\n'
+ self.assertEquals(long_line, Convert(long_line))
+
+ def testIgnoresMetaComment(self):
+ self.assertEquals('',
+ Convert('$$ This is a Pump meta comment.\n').strip())
+
+ def testSimpleVarDeclarationWorks(self):
+ self.assertEquals('3\n',
+ Convert('$var m = 3\n'
+ '$m\n'))
+
+ def testVarDeclarationCanReferenceEarlierVar(self):
+ self.assertEquals('43 != 3;\n',
+ Convert('$var a = 42\n'
+ '$var b = a + 1\n'
+ '$var c = (b - a)*3\n'
+ '$b != $c;\n'))
+
+ def testSimpleLoopWorks(self):
+ self.assertEquals('1, 2, 3, 4, 5\n',
+ Convert('$var n = 5\n'
+ '$range i 1..n\n'
+ '$for i, [[$i]]\n'))
+
+ def testSimpleLoopWithCommentWorks(self):
+ self.assertEquals('1, 2, 3, 4, 5\n',
+ Convert('$var n = 5 $$ This is comment 1.\n'
+ '$range i 1..n $$ This is comment 2.\n'
+ '$for i, [[$i]]\n'))
+
+ def testNonTrivialRangeExpressionsWork(self):
+ self.assertEquals('1, 2, 3, 4\n',
+ Convert('$var n = 5\n'
+ '$range i (n/n)..(n - 1)\n'
+ '$for i, [[$i]]\n'))
+
+ def testLoopWithoutSeparatorWorks(self):
+ self.assertEquals('a + 1 + 2 + 3;\n',
+ Convert('$range i 1..3\n'
+ 'a$for i [[ + $i]];\n'))
+
+ def testCanGenerateDollarSign(self):
+ self.assertEquals('$\n', Convert('$($)\n'))
+
+ def testCanIterpolateExpressions(self):
+ self.assertEquals('a[2] = 3;\n',
+ Convert('$var i = 1\n'
+ 'a[$(i + 1)] = $(i*4 - 1);\n'))
+
+ def testConditionalWithoutElseBranchWorks(self):
+ self.assertEquals('true\n',
+ Convert('$var n = 5\n'
+ '$if n > 0 [[true]]\n'))
+
+ def testConditionalWithElseBranchWorks(self):
+ self.assertEquals('true -- really false\n',
+ Convert('$var n = 5\n'
+ '$if n > 0 [[true]]\n'
+ '$else [[false]] -- \n'
+ '$if n > 10 [[really true]]\n'
+ '$else [[really false]]\n'))
+
+ def testConditionalWithCascadingElseBranchWorks(self):
+ self.assertEquals('a\n',
+ Convert('$var n = 5\n'
+ '$if n > 0 [[a]]\n'
+ '$elif n > 10 [[b]]\n'
+ '$else [[c]]\n'))
+ self.assertEquals('b\n',
+ Convert('$var n = 5\n'
+ '$if n > 10 [[a]]\n'
+ '$elif n > 0 [[b]]\n'
+ '$else [[c]]\n'))
+ self.assertEquals('c\n',
+ Convert('$var n = 5\n'
+ '$if n > 10 [[a]]\n'
+ '$elif n > 8 [[b]]\n'
+ '$else [[c]]\n'))
+
+ def testNestedLexicalBlocksWork(self):
+ self.assertEquals('a = 5;\n',
+ Convert('$var n = 5\n'
+ 'a = [[$if n > 0 [[$n]]]];\n'))
+
+
+class StripMetaCommentsTest(googletest.TestCase):
+
+ def testReturnsSameStringIfItContainsNoComment(self):
+ self.assertEquals('', StripMetaComments(''))
+ self.assertEquals(' blah ', StripMetaComments(' blah '))
+ self.assertEquals('A single $ is fine.',
+ StripMetaComments('A single $ is fine.'))
+ self.assertEquals('multiple\nlines',
+ StripMetaComments('multiple\nlines'))
+
+ def testStripsSimpleComment(self):
+ self.assertEquals('yes\n', StripMetaComments('yes $$ or no?\n'))
+
+ def testStripsSimpleCommentWithMissingNewline(self):
+ self.assertEquals('yes', StripMetaComments('yes $$ or no?'))
+
+ def testStripsPureCommentLinesEntirely(self):
+ self.assertEquals('yes\n',
+ StripMetaComments('$$ a pure comment line.\n'
+ 'yes $$ or no?\n'
+ ' $$ another comment line.\n'))
+
+ def testStripsCommentsFromMultiLineText(self):
+ self.assertEquals('multi-\n'
+ 'line\n'
+ 'text is fine.',
+ StripMetaComments('multi- $$ comment 1\n'
+ 'line\n'
+ 'text is fine. $$ comment 2'))
+
+
+if __name__ == '__main__':
+ googletest.main()