diff options
author | vladlosev <vladlosev@8415998a-534a-0410-bf83-d39667b30386> | 2009-11-18 00:09:28 +0000 |
---|---|---|
committer | vladlosev <vladlosev@8415998a-534a-0410-bf83-d39667b30386> | 2009-11-18 00:09:28 +0000 |
commit | a070cbd91c2a8bfe7caed64e31387312a1c5df5a (patch) | |
tree | 048a0d8d6d709491210b43bd66bc2f987b88833b /test | |
parent | 2871bb4d34117aad6e3c30e9fa094c06bece51fc (diff) | |
download | googletest-a070cbd91c2a8bfe7caed64e31387312a1c5df5a.tar.gz googletest-a070cbd91c2a8bfe7caed64e31387312a1c5df5a.tar.bz2 googletest-a070cbd91c2a8bfe7caed64e31387312a1c5df5a.zip |
Enables gmock's implicit_cast to work with source types that
Diffstat (limited to 'test')
-rw-r--r-- | test/gmock-actions_test.cc | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/gmock-actions_test.cc b/test/gmock-actions_test.cc index d3d96c6d..e2b1d052 100644 --- a/test/gmock-actions_test.cc +++ b/test/gmock-actions_test.cc @@ -515,6 +515,53 @@ TEST(ReturnTest, IsCovariant) { EXPECT_EQ(&derived, ret.Perform(make_tuple())); } +// Tests that the type of the value passed into Return is converted into T +// when the action is cast to Action<T(...)> rather than when the action is +// performed. See comments on testing::internal::ReturnAction in +// gmock-actions.h for more information. +class FromType { + public: + FromType(bool* converted) : converted_(converted) {} + bool* converted() const { return converted_; } + + private: + bool* const converted_; +}; + +class ToType { + public: + ToType(const FromType& x) { *x.converted() = true; } +}; + +TEST(ReturnTest, ConvertsArgumentWhenConverted) { + bool converted = false; + FromType x(&converted); + Action<ToType()> action(Return(x)); + EXPECT_TRUE(converted) << "Return must convert its argument in its own " + << "conversion operator."; + converted = false; + action.Perform(tuple<>()); + EXPECT_FALSE(converted) << "Action must NOT convert its argument " + << "when performed." ; +} + +// We do not support non-const type conversions on Symbian. See +// definition of implicit_cast in gmock-port.h for more information. +#if !GTEST_OS_SYMBIAN +class DestinationType {}; + +class SourceType { + public: + // Note: a non-const typecast operator. + operator DestinationType() { return DestinationType(); } +}; + +TEST(ReturnTest, CanConvertArgumentUsingNonConstTypeCastOperator) { + SourceType s; + Action<DestinationType()> action(Return(s)); +} +#endif // !GTEST_OS_SYMBIAN + // Tests that ReturnNull() returns NULL in a pointer-returning function. TEST(ReturnNullTest, WorksInPointerReturningFunction) { const Action<int*()> a1 = ReturnNull(); |