gmock_link_test.h (googletest-release-1.11.0) | : | gmock_link_test.h (googletest-release-1.12.0) | ||
---|---|---|---|---|
skipping to change at line 120 | skipping to change at line 120 | |||
// NON-ANONYMOUS namespace in this file. The test fixture class LinkTest | // NON-ANONYMOUS namespace in this file. The test fixture class LinkTest | |||
// is defined as LinkTest1 in gmock_link_test.cc and as LinkTest2 in | // is defined as LinkTest1 in gmock_link_test.cc and as LinkTest2 in | |||
// gmock_link2_test.cc to avoid producing linker errors. | // gmock_link2_test.cc to avoid producing linker errors. | |||
#ifndef GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_ | #ifndef GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_ | |||
#define GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_ | #define GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_ | |||
#include "gmock/gmock.h" | #include "gmock/gmock.h" | |||
#if !GTEST_OS_WINDOWS_MOBILE | #if !GTEST_OS_WINDOWS_MOBILE | |||
# include <errno.h> | #include <errno.h> | |||
#endif | #endif | |||
#include <iostream> | #include <iostream> | |||
#include <vector> | #include <vector> | |||
#include "gtest/gtest.h" | #include "gtest/gtest.h" | |||
#include "gtest/internal/gtest-port.h" | #include "gtest/internal/gtest-port.h" | |||
using testing::_; | using testing::_; | |||
using testing::A; | using testing::A; | |||
skipping to change at line 202 | skipping to change at line 202 | |||
using testing::ContainsRegex; | using testing::ContainsRegex; | |||
using testing::MatchesRegex; | using testing::MatchesRegex; | |||
class Interface { | class Interface { | |||
public: | public: | |||
virtual ~Interface() {} | virtual ~Interface() {} | |||
virtual void VoidFromString(char* str) = 0; | virtual void VoidFromString(char* str) = 0; | |||
virtual char* StringFromString(char* str) = 0; | virtual char* StringFromString(char* str) = 0; | |||
virtual int IntFromString(char* str) = 0; | virtual int IntFromString(char* str) = 0; | |||
virtual int& IntRefFromString(char* str) = 0; | virtual int& IntRefFromString(char* str) = 0; | |||
virtual void VoidFromFunc(void(*func)(char* str)) = 0; | virtual void VoidFromFunc(void (*func)(char* str)) = 0; | |||
virtual void VoidFromIntRef(int& n) = 0; // NOLINT | virtual void VoidFromIntRef(int& n) = 0; // NOLINT | |||
virtual void VoidFromFloat(float n) = 0; | virtual void VoidFromFloat(float n) = 0; | |||
virtual void VoidFromDouble(double n) = 0; | virtual void VoidFromDouble(double n) = 0; | |||
virtual void VoidFromVector(const std::vector<int>& v) = 0; | virtual void VoidFromVector(const std::vector<int>& v) = 0; | |||
}; | }; | |||
class Mock: public Interface { | class Mock : public Interface { | |||
public: | public: | |||
Mock() {} | Mock() {} | |||
MOCK_METHOD1(VoidFromString, void(char* str)); | MOCK_METHOD1(VoidFromString, void(char* str)); | |||
MOCK_METHOD1(StringFromString, char*(char* str)); | MOCK_METHOD1(StringFromString, char*(char* str)); | |||
MOCK_METHOD1(IntFromString, int(char* str)); | MOCK_METHOD1(IntFromString, int(char* str)); | |||
MOCK_METHOD1(IntRefFromString, int&(char* str)); | MOCK_METHOD1(IntRefFromString, int&(char* str)); | |||
MOCK_METHOD1(VoidFromFunc, void(void(*func)(char* str))); | MOCK_METHOD1(VoidFromFunc, void(void (*func)(char* str))); | |||
MOCK_METHOD1(VoidFromIntRef, void(int& n)); // NOLINT | MOCK_METHOD1(VoidFromIntRef, void(int& n)); // NOLINT | |||
MOCK_METHOD1(VoidFromFloat, void(float n)); | MOCK_METHOD1(VoidFromFloat, void(float n)); | |||
MOCK_METHOD1(VoidFromDouble, void(double n)); | MOCK_METHOD1(VoidFromDouble, void(double n)); | |||
MOCK_METHOD1(VoidFromVector, void(const std::vector<int>& v)); | MOCK_METHOD1(VoidFromVector, void(const std::vector<int>& v)); | |||
private: | private: | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(Mock); | Mock(const Mock&) = delete; | |||
Mock& operator=(const Mock&) = delete; | ||||
}; | }; | |||
class InvokeHelper { | class InvokeHelper { | |||
public: | public: | |||
static void StaticVoidFromVoid() {} | static void StaticVoidFromVoid() {} | |||
void VoidFromVoid() {} | void VoidFromVoid() {} | |||
static void StaticVoidFromString(char* /* str */) {} | static void StaticVoidFromString(char* /* str */) {} | |||
void VoidFromString(char* /* str */) {} | void VoidFromString(char* /* str */) {} | |||
static int StaticIntFromString(char* /* str */) { return 1; } | static int StaticIntFromString(char* /* str */) { return 1; } | |||
static bool StaticBoolFromString(const char* /* str */) { return true; } | static bool StaticBoolFromString(const char* /* str */) { return true; } | |||
skipping to change at line 303 | skipping to change at line 304 | |||
EXPECT_CALL(mock, VoidFromString(_)).WillOnce(SetArgPointee<0>('y')); | EXPECT_CALL(mock, VoidFromString(_)).WillOnce(SetArgPointee<0>('y')); | |||
mock.VoidFromString(&ch); | mock.VoidFromString(&ch); | |||
} | } | |||
// Tests the linkage of the SetArrayArgument action. | // Tests the linkage of the SetArrayArgument action. | |||
TEST(LinkTest, TestSetArrayArgument) { | TEST(LinkTest, TestSetArrayArgument) { | |||
Mock mock; | Mock mock; | |||
char ch = 'x'; | char ch = 'x'; | |||
char ch2 = 'y'; | char ch2 = 'y'; | |||
EXPECT_CALL(mock, VoidFromString(_)).WillOnce(SetArrayArgument<0>(&ch2, | EXPECT_CALL(mock, VoidFromString(_)) | |||
&ch2 + 1)); | .WillOnce(SetArrayArgument<0>(&ch2, &ch2 + 1)); | |||
mock.VoidFromString(&ch); | mock.VoidFromString(&ch); | |||
} | } | |||
#if !GTEST_OS_WINDOWS_MOBILE | #if !GTEST_OS_WINDOWS_MOBILE | |||
// Tests the linkage of the SetErrnoAndReturn action. | // Tests the linkage of the SetErrnoAndReturn action. | |||
TEST(LinkTest, TestSetErrnoAndReturn) { | TEST(LinkTest, TestSetErrnoAndReturn) { | |||
Mock mock; | Mock mock; | |||
int saved_errno = errno; | int saved_errno = errno; | |||
skipping to change at line 341 | skipping to change at line 342 | |||
mock.VoidFromString(nullptr); | mock.VoidFromString(nullptr); | |||
} | } | |||
// Tests the linkage of the InvokeWithoutArgs action. | // Tests the linkage of the InvokeWithoutArgs action. | |||
TEST(LinkTest, TestInvokeWithoutArgs) { | TEST(LinkTest, TestInvokeWithoutArgs) { | |||
Mock mock; | Mock mock; | |||
InvokeHelper test_invoke_helper; | InvokeHelper test_invoke_helper; | |||
EXPECT_CALL(mock, VoidFromString(_)) | EXPECT_CALL(mock, VoidFromString(_)) | |||
.WillOnce(InvokeWithoutArgs(&InvokeHelper::StaticVoidFromVoid)) | .WillOnce(InvokeWithoutArgs(&InvokeHelper::StaticVoidFromVoid)) | |||
.WillOnce(InvokeWithoutArgs(&test_invoke_helper, | .WillOnce( | |||
&InvokeHelper::VoidFromVoid)); | InvokeWithoutArgs(&test_invoke_helper, &InvokeHelper::VoidFromVoid)); | |||
mock.VoidFromString(nullptr); | mock.VoidFromString(nullptr); | |||
mock.VoidFromString(nullptr); | mock.VoidFromString(nullptr); | |||
} | } | |||
// Tests the linkage of the InvokeArgument action. | // Tests the linkage of the InvokeArgument action. | |||
TEST(LinkTest, TestInvokeArgument) { | TEST(LinkTest, TestInvokeArgument) { | |||
Mock mock; | Mock mock; | |||
char ch = 'x'; | char ch = 'x'; | |||
EXPECT_CALL(mock, VoidFromFunc(_)).WillOnce(InvokeArgument<0>(&ch)); | EXPECT_CALL(mock, VoidFromFunc(_)).WillOnce(InvokeArgument<0>(&ch)); | |||
skipping to change at line 426 | skipping to change at line 427 | |||
EXPECT_THROW(mock.VoidFromString(nullptr), int); | EXPECT_THROW(mock.VoidFromString(nullptr), int); | |||
} | } | |||
#endif // GTEST_HAS_EXCEPTIONS | #endif // GTEST_HAS_EXCEPTIONS | |||
// The ACTION*() macros trigger warning C4100 (unreferenced formal | // The ACTION*() macros trigger warning C4100 (unreferenced formal | |||
// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in | // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in | |||
// the macro definition, as the warnings are generated when the macro | // the macro definition, as the warnings are generated when the macro | |||
// is expanded and macro expansion cannot contain #pragma. Therefore | // is expanded and macro expansion cannot contain #pragma. Therefore | |||
// we suppress them here. | // we suppress them here. | |||
#ifdef _MSC_VER | #ifdef _MSC_VER | |||
# pragma warning(push) | #pragma warning(push) | |||
# pragma warning(disable:4100) | #pragma warning(disable : 4100) | |||
#endif | #endif | |||
// Tests the linkage of actions created using ACTION macro. | // Tests the linkage of actions created using ACTION macro. | |||
namespace { | namespace { | |||
ACTION(Return1) { return 1; } | ACTION(Return1) { return 1; } | |||
} | } // namespace | |||
TEST(LinkTest, TestActionMacro) { | TEST(LinkTest, TestActionMacro) { | |||
Mock mock; | Mock mock; | |||
EXPECT_CALL(mock, IntFromString(_)).WillOnce(Return1()); | EXPECT_CALL(mock, IntFromString(_)).WillOnce(Return1()); | |||
mock.IntFromString(nullptr); | mock.IntFromString(nullptr); | |||
} | } | |||
// Tests the linkage of actions created using ACTION_P macro. | // Tests the linkage of actions created using ACTION_P macro. | |||
namespace { | namespace { | |||
ACTION_P(ReturnArgument, ret_value) { return ret_value; } | ACTION_P(ReturnArgument, ret_value) { return ret_value; } | |||
} | } // namespace | |||
TEST(LinkTest, TestActionPMacro) { | TEST(LinkTest, TestActionPMacro) { | |||
Mock mock; | Mock mock; | |||
EXPECT_CALL(mock, IntFromString(_)).WillOnce(ReturnArgument(42)); | EXPECT_CALL(mock, IntFromString(_)).WillOnce(ReturnArgument(42)); | |||
mock.IntFromString(nullptr); | mock.IntFromString(nullptr); | |||
} | } | |||
// Tests the linkage of actions created using ACTION_P2 macro. | // Tests the linkage of actions created using ACTION_P2 macro. | |||
namespace { | namespace { | |||
ACTION_P2(ReturnEqualsEitherOf, first, second) { | ACTION_P2(ReturnEqualsEitherOf, first, second) { | |||
return arg0 == first || arg0 == second; | return arg0 == first || arg0 == second; | |||
} | } | |||
} | } // namespace | |||
#ifdef _MSC_VER | #ifdef _MSC_VER | |||
# pragma warning(pop) | #pragma warning(pop) | |||
#endif | #endif | |||
TEST(LinkTest, TestActionP2Macro) { | TEST(LinkTest, TestActionP2Macro) { | |||
Mock mock; | Mock mock; | |||
char ch = 'x'; | char ch = 'x'; | |||
EXPECT_CALL(mock, IntFromString(_)) | EXPECT_CALL(mock, IntFromString(_)) | |||
.WillOnce(ReturnEqualsEitherOf("one", "two")); | .WillOnce(ReturnEqualsEitherOf("one", "two")); | |||
mock.IntFromString(&ch); | mock.IntFromString(&ch); | |||
} | } | |||
skipping to change at line 494 | skipping to change at line 495 | |||
ON_CALL(mock, VoidFromString(A<char*>())).WillByDefault(Return()); | ON_CALL(mock, VoidFromString(A<char*>())).WillByDefault(Return()); | |||
} | } | |||
// Tests the linkage of the Eq and the "bare value" matcher. | // Tests the linkage of the Eq and the "bare value" matcher. | |||
TEST(LinkTest, TestMatchersEq) { | TEST(LinkTest, TestMatchersEq) { | |||
Mock mock; | Mock mock; | |||
const char* p = "x"; | const char* p = "x"; | |||
ON_CALL(mock, VoidFromString(Eq(p))).WillByDefault(Return()); | ON_CALL(mock, VoidFromString(Eq(p))).WillByDefault(Return()); | |||
ON_CALL(mock, VoidFromString(const_cast<char*>("y"))) | ON_CALL(mock, VoidFromString(const_cast<char*>("y"))).WillByDefault(Return()); | |||
.WillByDefault(Return()); | ||||
} | } | |||
// Tests the linkage of the Lt, Gt, Le, Ge, and Ne matchers. | // Tests the linkage of the Lt, Gt, Le, Ge, and Ne matchers. | |||
TEST(LinkTest, TestMatchersRelations) { | TEST(LinkTest, TestMatchersRelations) { | |||
Mock mock; | Mock mock; | |||
ON_CALL(mock, VoidFromFloat(Lt(1.0f))).WillByDefault(Return()); | ON_CALL(mock, VoidFromFloat(Lt(1.0f))).WillByDefault(Return()); | |||
ON_CALL(mock, VoidFromFloat(Gt(1.0f))).WillByDefault(Return()); | ON_CALL(mock, VoidFromFloat(Gt(1.0f))).WillByDefault(Return()); | |||
ON_CALL(mock, VoidFromFloat(Le(1.0f))).WillByDefault(Return()); | ON_CALL(mock, VoidFromFloat(Le(1.0f))).WillByDefault(Return()); | |||
ON_CALL(mock, VoidFromFloat(Ge(1.0f))).WillByDefault(Return()); | ON_CALL(mock, VoidFromFloat(Ge(1.0f))).WillByDefault(Return()); | |||
skipping to change at line 594 | skipping to change at line 594 | |||
// Tests the linkage of the ElementsAre matcher. | // Tests the linkage of the ElementsAre matcher. | |||
TEST(LinkTest, TestMatcherElementsAre) { | TEST(LinkTest, TestMatcherElementsAre) { | |||
Mock mock; | Mock mock; | |||
ON_CALL(mock, VoidFromVector(ElementsAre('a', _))).WillByDefault(Return()); | ON_CALL(mock, VoidFromVector(ElementsAre('a', _))).WillByDefault(Return()); | |||
} | } | |||
// Tests the linkage of the ElementsAreArray matcher. | // Tests the linkage of the ElementsAreArray matcher. | |||
TEST(LinkTest, TestMatcherElementsAreArray) { | TEST(LinkTest, TestMatcherElementsAreArray) { | |||
Mock mock; | Mock mock; | |||
char arr[] = { 'a', 'b' }; | char arr[] = {'a', 'b'}; | |||
ON_CALL(mock, VoidFromVector(ElementsAreArray(arr))).WillByDefault(Return()); | ON_CALL(mock, VoidFromVector(ElementsAreArray(arr))).WillByDefault(Return()); | |||
} | } | |||
// Tests the linkage of the IsSubsetOf matcher. | // Tests the linkage of the IsSubsetOf matcher. | |||
TEST(LinkTest, TestMatcherIsSubsetOf) { | TEST(LinkTest, TestMatcherIsSubsetOf) { | |||
Mock mock; | Mock mock; | |||
char arr[] = {'a', 'b'}; | char arr[] = {'a', 'b'}; | |||
ON_CALL(mock, VoidFromVector(IsSubsetOf(arr))).WillByDefault(Return()); | ON_CALL(mock, VoidFromVector(IsSubsetOf(arr))).WillByDefault(Return()); | |||
End of changes. 14 change blocks. | ||||
18 lines changed or deleted | 18 lines changed or added |