36 #include "gmock/gmock-actions.h" 41 #include "gmock/gmock.h" 42 #include "gmock/internal/gmock-port.h" 43 #include "gtest/gtest.h" 44 #include "gtest/gtest-spi.h" 75 using testing::tuple_element;
77 #if !GTEST_OS_WINDOWS_MOBILE 81 #if GTEST_HAS_PROTOBUF_ 82 using testing::internal::TestMessage;
83 #endif // GTEST_HAS_PROTOBUF_ 86 TEST(BuiltInDefaultValueTest, IsNullForPointerTypes) {
87 EXPECT_TRUE(BuiltInDefaultValue<int*>::Get() == NULL);
88 EXPECT_TRUE(BuiltInDefaultValue<const char*>::Get() == NULL);
89 EXPECT_TRUE(BuiltInDefaultValue<void*>::Get() == NULL);
93 TEST(BuiltInDefaultValueTest, ExistsForPointerTypes) {
95 EXPECT_TRUE(BuiltInDefaultValue<const char*>::Exists());
101 TEST(BuiltInDefaultValueTest, IsZeroForNumericTypes) {
102 EXPECT_EQ(0U, BuiltInDefaultValue<unsigned char>::Get());
103 EXPECT_EQ(0, BuiltInDefaultValue<signed char>::Get());
104 EXPECT_EQ(0, BuiltInDefaultValue<char>::Get());
105 #if GMOCK_HAS_SIGNED_WCHAR_T_ 106 EXPECT_EQ(0U, BuiltInDefaultValue<unsigned wchar_t>::Get());
107 EXPECT_EQ(0, BuiltInDefaultValue<signed wchar_t>::Get());
109 #if GMOCK_WCHAR_T_IS_NATIVE_ 110 EXPECT_EQ(0, BuiltInDefaultValue<wchar_t>::Get());
112 EXPECT_EQ(0U, BuiltInDefaultValue<unsigned short>::Get());
113 EXPECT_EQ(0, BuiltInDefaultValue<signed short>::Get());
114 EXPECT_EQ(0, BuiltInDefaultValue<short>::Get());
115 EXPECT_EQ(0U, BuiltInDefaultValue<unsigned int>::Get());
116 EXPECT_EQ(0, BuiltInDefaultValue<signed int>::Get());
117 EXPECT_EQ(0, BuiltInDefaultValue<int>::Get());
118 EXPECT_EQ(0U, BuiltInDefaultValue<unsigned long>::Get());
119 EXPECT_EQ(0, BuiltInDefaultValue<signed long>::Get());
120 EXPECT_EQ(0, BuiltInDefaultValue<long>::Get());
121 EXPECT_EQ(0U, BuiltInDefaultValue<UInt64>::Get());
122 EXPECT_EQ(0, BuiltInDefaultValue<Int64>::Get());
123 EXPECT_EQ(0, BuiltInDefaultValue<float>::Get());
124 EXPECT_EQ(0, BuiltInDefaultValue<double>::Get());
129 TEST(BuiltInDefaultValueTest, ExistsForNumericTypes) {
130 EXPECT_TRUE(BuiltInDefaultValue<unsigned char>::Exists());
131 EXPECT_TRUE(BuiltInDefaultValue<signed char>::Exists());
133 #if GMOCK_HAS_SIGNED_WCHAR_T_ 134 EXPECT_TRUE(BuiltInDefaultValue<unsigned wchar_t>::Exists());
135 EXPECT_TRUE(BuiltInDefaultValue<signed wchar_t>::Exists());
137 #if GMOCK_WCHAR_T_IS_NATIVE_ 138 EXPECT_TRUE(BuiltInDefaultValue<wchar_t>::Exists());
140 EXPECT_TRUE(BuiltInDefaultValue<unsigned short>::Exists());
141 EXPECT_TRUE(BuiltInDefaultValue<signed short>::Exists());
143 EXPECT_TRUE(BuiltInDefaultValue<unsigned int>::Exists());
144 EXPECT_TRUE(BuiltInDefaultValue<signed int>::Exists());
146 EXPECT_TRUE(BuiltInDefaultValue<unsigned long>::Exists());
147 EXPECT_TRUE(BuiltInDefaultValue<signed long>::Exists());
149 EXPECT_TRUE(BuiltInDefaultValue<UInt64>::Exists());
152 EXPECT_TRUE(BuiltInDefaultValue<double>::Exists());
156 TEST(BuiltInDefaultValueTest, IsFalseForBool) {
161 TEST(BuiltInDefaultValueTest, BoolExists) {
167 TEST(BuiltInDefaultValueTest, IsEmptyStringForString) {
168 #if GTEST_HAS_GLOBAL_STRING 169 EXPECT_EQ(
"", BuiltInDefaultValue< ::string>::Get());
170 #endif // GTEST_HAS_GLOBAL_STRING 172 EXPECT_EQ(
"", BuiltInDefaultValue< ::std::string>::Get());
177 TEST(BuiltInDefaultValueTest, ExistsForString) {
178 #if GTEST_HAS_GLOBAL_STRING 179 EXPECT_TRUE(BuiltInDefaultValue< ::string>::Exists());
180 #endif // GTEST_HAS_GLOBAL_STRING 182 EXPECT_TRUE(BuiltInDefaultValue< ::std::string>::Exists());
187 TEST(BuiltInDefaultValueTest, WorksForConstTypes) {
188 EXPECT_EQ(
"", BuiltInDefaultValue<const std::string>::Get());
189 EXPECT_EQ(0, BuiltInDefaultValue<const int>::Get());
190 EXPECT_TRUE(BuiltInDefaultValue<char* const>::Get() == NULL);
195 class MyDefaultConstructible {
197 MyDefaultConstructible() : value_(42) {}
199 int value()
const {
return value_; }
206 class MyNonDefaultConstructible {
209 explicit MyNonDefaultConstructible(
int a_value) : value_(a_value) {}
211 int value()
const {
return value_; }
217 #if GTEST_HAS_STD_TYPE_TRAITS_ 219 TEST(BuiltInDefaultValueTest, ExistsForDefaultConstructibleType) {
220 EXPECT_TRUE(BuiltInDefaultValue<MyDefaultConstructible>::Exists());
223 TEST(BuiltInDefaultValueTest, IsDefaultConstructedForDefaultConstructibleType) {
224 EXPECT_EQ(42, BuiltInDefaultValue<MyDefaultConstructible>::Get().
value());
227 #endif // GTEST_HAS_STD_TYPE_TRAITS_ 229 TEST(BuiltInDefaultValueTest, DoesNotExistForNonDefaultConstructibleType) {
230 EXPECT_FALSE(BuiltInDefaultValue<MyNonDefaultConstructible>::Exists());
234 TEST(BuiltInDefaultValueDeathTest, IsUndefinedForReferences) {
236 BuiltInDefaultValue<int&>::Get();
239 BuiltInDefaultValue<const char&>::Get();
243 TEST(BuiltInDefaultValueDeathTest, IsUndefinedForNonDefaultConstructibleType) {
245 BuiltInDefaultValue<MyNonDefaultConstructible>::Get();
250 TEST(DefaultValueTest, IsInitiallyUnset) {
252 EXPECT_FALSE(DefaultValue<MyDefaultConstructible>::IsSet());
253 EXPECT_FALSE(DefaultValue<const MyNonDefaultConstructible>::IsSet());
257 TEST(DefaultValueTest, CanBeSetAndUnset) {
259 EXPECT_FALSE(DefaultValue<const MyNonDefaultConstructible>::Exists());
261 DefaultValue<int>::Set(1);
262 DefaultValue<const MyNonDefaultConstructible>::Set(
263 MyNonDefaultConstructible(42));
266 EXPECT_EQ(42, DefaultValue<const MyNonDefaultConstructible>::Get().
value());
269 EXPECT_TRUE(DefaultValue<const MyNonDefaultConstructible>::Exists());
271 DefaultValue<int>::Clear();
272 DefaultValue<const MyNonDefaultConstructible>::Clear();
275 EXPECT_FALSE(DefaultValue<const MyNonDefaultConstructible>::IsSet());
278 EXPECT_FALSE(DefaultValue<const MyNonDefaultConstructible>::Exists());
284 TEST(DefaultValueDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) {
287 EXPECT_FALSE(DefaultValue<MyNonDefaultConstructible>::IsSet());
288 EXPECT_FALSE(DefaultValue<MyNonDefaultConstructible>::Exists());
293 DefaultValue<MyNonDefaultConstructible>::Get();
297 #if GTEST_HAS_STD_UNIQUE_PTR_ 298 TEST(DefaultValueTest, GetWorksForMoveOnlyIfSet) {
299 EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Exists());
300 EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Get() == NULL);
301 DefaultValue<std::unique_ptr<int>>::SetFactory([] {
302 return std::unique_ptr<int>(
new int(42));
304 EXPECT_TRUE(DefaultValue<std::unique_ptr<int>>::Exists());
305 std::unique_ptr<int>
i = DefaultValue<std::unique_ptr<int>>::Get();
308 #endif // GTEST_HAS_STD_UNIQUE_PTR_ 311 TEST(DefaultValueTest, GetWorksForVoid) {
312 return DefaultValue<void>::Get();
318 TEST(DefaultValueOfReferenceTest, IsInitiallyUnset) {
320 EXPECT_FALSE(DefaultValue<MyDefaultConstructible&>::IsSet());
321 EXPECT_FALSE(DefaultValue<MyNonDefaultConstructible&>::IsSet());
325 TEST(DefaultValueOfReferenceTest, IsInitiallyNotExisting) {
327 EXPECT_FALSE(DefaultValue<MyDefaultConstructible&>::Exists());
328 EXPECT_FALSE(DefaultValue<MyNonDefaultConstructible&>::Exists());
332 TEST(DefaultValueOfReferenceTest, CanBeSetAndUnset) {
334 DefaultValue<const int&>::Set(n);
335 MyNonDefaultConstructible
x(42);
336 DefaultValue<MyNonDefaultConstructible&>::Set(
x);
339 EXPECT_TRUE(DefaultValue<MyNonDefaultConstructible&>::Exists());
341 EXPECT_EQ(&n, &(DefaultValue<const int&>::Get()));
342 EXPECT_EQ(&
x, &(DefaultValue<MyNonDefaultConstructible&>::Get()));
344 DefaultValue<const int&>::Clear();
345 DefaultValue<MyNonDefaultConstructible&>::Clear();
348 EXPECT_FALSE(DefaultValue<MyNonDefaultConstructible&>::Exists());
351 EXPECT_FALSE(DefaultValue<MyNonDefaultConstructible&>::IsSet());
357 TEST(DefaultValueOfReferenceDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) {
359 EXPECT_FALSE(DefaultValue<MyNonDefaultConstructible&>::IsSet());
362 DefaultValue<int&>::Get();
365 DefaultValue<MyNonDefaultConstructible>::Get();
372 typedef int MyGlobalFunction(
bool,
int);
374 class MyActionImpl :
public ActionInterface<MyGlobalFunction> {
376 virtual int Perform(
const tuple<bool, int>& args) {
377 return get<0>(args) ? get<1>(args) : 0;
381 TEST(ActionInterfaceTest, CanBeImplementedByDefiningPerform) {
382 MyActionImpl my_action_impl;
383 (void)my_action_impl;
399 TEST(ActionTest, CanBeConstructedFromActionInterface) {
400 Action<MyGlobalFunction>
action(
new MyActionImpl);
404 TEST(ActionTest, DelegatesWorkToActionInterface) {
405 const Action<MyGlobalFunction>
action(
new MyActionImpl);
413 Action<MyGlobalFunction> a1(
new MyActionImpl);
414 Action<MyGlobalFunction> a2(a1);
438 class IsNotZero :
public ActionInterface<bool(int)> {
440 virtual bool Perform(
const tuple<int>& arg) {
441 return get<0>(arg) != 0;
445 #if !GTEST_OS_SYMBIAN 451 TEST(ActionTest, CanBeConvertedToOtherActionType) {
452 const Action<bool(int)> a1(
new IsNotZero);
453 const Action<int(char)> a2 = Action<int(char)>(a1);
457 #endif // !GTEST_OS_SYMBIAN 463 class ReturnSecondArgumentAction {
468 template <
typename Result,
typename ArgumentTuple>
469 Result Perform(
const ArgumentTuple& args) {
return get<1>(args); }
474 class ReturnZeroFromNullaryFunctionAction {
483 template <
typename Result>
484 Result Perform(
const tuple<>&)
const {
return 0; }
490 PolymorphicAction<ReturnSecondArgumentAction> ReturnSecondArgument() {
494 PolymorphicAction<ReturnZeroFromNullaryFunctionAction>
495 ReturnZeroFromNullaryFunction() {
501 TEST(MakePolymorphicActionTest, ConstructsActionFromImpl) {
502 Action<int(bool, int, double)> a1 = ReturnSecondArgument();
508 TEST(MakePolymorphicActionTest, WorksWhenPerformHasOneTemplateParameter) {
509 Action<int()> a1 = ReturnZeroFromNullaryFunction();
512 Action<void*()> a2 = ReturnZeroFromNullaryFunction();
518 TEST(ReturnTest, WorksForVoid) {
519 const Action<void(int)> ret =
Return();
524 TEST(ReturnTest, ReturnsGivenValue) {
525 Action<int()> ret =
Return(1);
533 TEST(ReturnTest, AcceptsStringLiteral) {
534 Action<const char*()> a1 =
Return(
"Hello");
537 Action<std::string()> a2 =
Return(
"world");
543 struct IntegerVectorWrapper {
544 std::vector<int> *
v;
545 IntegerVectorWrapper(std::vector<int>& _v) : v(&_v) {}
549 TEST(ReturnTest, SupportsWrapperReturnType) {
552 for (
int i = 0;
i < 5; ++
i) v.push_back(
i);
556 Action<IntegerVectorWrapper()>
a =
Return(v);
557 const std::vector<int>& result = *(a.Perform(
make_tuple()).v);
567 struct Derived :
public Base {
568 bool operator==(
const Derived&) {
return true; }
571 TEST(ReturnTest, IsCovariant) {
574 Action<Base*()> ret =
Return(&base);
587 explicit FromType(
bool* is_converted) : converted_(is_converted) {}
588 bool* converted()
const {
return converted_; }
591 bool*
const converted_;
599 ToType(
const FromType&
x) { *x.converted() =
true; }
602 TEST(ReturnTest, ConvertsArgumentWhenConverted) {
603 bool converted =
false;
604 FromType
x(&converted);
606 EXPECT_TRUE(converted) <<
"Return must convert its argument in its own " 607 <<
"conversion operator.";
609 action.Perform(tuple<>());
610 EXPECT_FALSE(converted) <<
"Action must NOT convert its argument " 611 <<
"when performed.";
614 class DestinationType {};
619 operator DestinationType() {
return DestinationType(); }
622 TEST(ReturnTest, CanConvertArgumentUsingNonConstTypeCastOperator) {
628 TEST(ReturnNullTest, WorksInPointerReturningFunction) {
632 const Action<const char*(bool)> a2 =
ReturnNull();
636 #if GTEST_HAS_STD_UNIQUE_PTR_ 639 TEST(ReturnNullTest, WorksInSmartPointerReturningFunction) {
640 const Action<std::unique_ptr<const int>()> a1 =
ReturnNull();
646 #endif // GTEST_HAS_STD_UNIQUE_PTR_ 649 TEST(ReturnRefTest, WorksForReference) {
651 const Action<const int&(bool)> ret =
ReturnRef(n);
657 TEST(ReturnRefTest, IsCovariant) {
668 TEST(ReturnRefOfCopyTest, WorksForReference) {
681 TEST(ReturnRefOfCopyTest, IsCovariant) {
699 #if GTEST_HAS_STD_UNIQUE_PTR_ 702 MOCK_METHOD0(MakeVectorUnique, std::vector<std::unique_ptr<int>>());
711 TEST(DoDefaultTest, ReturnsBuiltInDefaultValueByDefault) {
720 TEST(DoDefaultDeathTest, DiesForUnknowType) {
724 #if GTEST_HAS_EXCEPTIONS 736 void VoidFunc(
bool ) {}
738 TEST(DoDefaultDeathTest, DiesIfUsedInCompositeAction) {
755 TEST(DoDefaultTest, ReturnsUserSpecifiedPerTypeDefaultValueWhenThereIsOne) {
756 DefaultValue<int>::Set(1);
761 DefaultValue<int>::Clear();
765 TEST(DoDefaultTest, DoesWhatOnCallSpecifies) {
768 .WillByDefault(
Return(2));
775 TEST(DoDefaultTest, CannotBeUsedInOnCall) {
780 },
"DoDefault() cannot be used in ON_CALL()");
785 TEST(SetArgPointeeTest, SetsTheNthPointee) {
787 Action<MyFunction> a = SetArgPointee<1>(2);
795 a = SetArgPointee<2>(
'a');
803 #if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN) 806 TEST(SetArgPointeeTest, AcceptsStringLiteral) {
808 Action<MyFunction> a = SetArgPointee<0>(
"hi");
810 const char*
ptr = NULL;
815 a = SetArgPointee<1>(
"world");
822 TEST(SetArgPointeeTest, AcceptsWideStringLiteral) {
824 Action<MyFunction> a = SetArgPointee<0>(L
"world");
825 const wchar_t* ptr = NULL;
829 # if GTEST_HAS_STD_WSTRING 832 Action<MyStringFunction> a2 = SetArgPointee<0>(L
"world");
842 TEST(SetArgPointeeTest, AcceptsCharPointer) {
844 const char*
const hi =
"hi";
845 Action<MyFunction> a = SetArgPointee<1>(hi);
847 const char* ptr = NULL;
852 char world_array[] =
"world";
853 char*
const world = world_array;
854 a = SetArgPointee<2>(world);
861 TEST(SetArgPointeeTest, AcceptsWideCharPointer) {
862 typedef void MyFunction(
bool,
const wchar_t**);
863 const wchar_t*
const hi = L
"hi";
864 Action<MyFunction> a = SetArgPointee<1>(hi);
865 const wchar_t* ptr = NULL;
869 # if GTEST_HAS_STD_WSTRING 872 wchar_t world_array[] = L
"world";
873 wchar_t*
const world = world_array;
874 Action<MyStringFunction> a2 = SetArgPointee<1>(world);
881 #if GTEST_HAS_PROTOBUF_ 885 TEST(SetArgPointeeTest, SetsTheNthPointeeOfProtoBufferType) {
886 TestMessage*
const msg =
new TestMessage;
887 msg->set_member(
"yes");
888 TestMessage orig_msg;
889 orig_msg.CopyFrom(*msg);
891 Action<void(bool, TestMessage*)> a = SetArgPointee<1>(*msg);
907 TEST(SetArgPointeeTest, SetsTheNthPointeeOfProtoBufferBaseType) {
908 TestMessage*
const msg =
new TestMessage;
909 msg->set_member(
"yes");
910 TestMessage orig_msg;
911 orig_msg.CopyFrom(*msg);
913 Action<void(bool, ::ProtocolMessage*)> a = SetArgPointee<1>(*msg);
921 ::ProtocolMessage*
const dest_base = &
dest;
930 TEST(SetArgPointeeTest, SetsTheNthPointeeOfProto2BufferType) {
931 using testing::internal::FooMessage;
932 FooMessage*
const msg =
new FooMessage;
933 msg->set_int_field(2);
934 msg->set_string_field(
"hi");
936 orig_msg.CopyFrom(*msg);
938 Action<void(bool, FooMessage*)> a = SetArgPointee<1>(*msg);
946 dest.set_int_field(0);
955 TEST(SetArgPointeeTest, SetsTheNthPointeeOfProto2BufferBaseType) {
956 using testing::internal::FooMessage;
957 FooMessage*
const msg =
new FooMessage;
958 msg->set_int_field(2);
959 msg->set_string_field(
"hi");
961 orig_msg.CopyFrom(*msg);
963 Action<void(bool, ::proto2::Message*)> a = SetArgPointee<1>(*msg);
971 dest.set_int_field(0);
972 ::proto2::Message*
const dest_base = &
dest;
978 #endif // GTEST_HAS_PROTOBUF_ 982 TEST(SetArgumentPointeeTest, SetsTheNthPointee) {
984 Action<MyFunction> a = SetArgumentPointee<1>(2);
992 a = SetArgumentPointee<2>(
'a');
1000 #if GTEST_HAS_PROTOBUF_ 1004 TEST(SetArgumentPointeeTest, SetsTheNthPointeeOfProtoBufferType) {
1005 TestMessage*
const msg =
new TestMessage;
1006 msg->set_member(
"yes");
1007 TestMessage orig_msg;
1008 orig_msg.CopyFrom(*msg);
1010 Action<void(bool, TestMessage*)> a = SetArgumentPointee<1>(*msg);
1026 TEST(SetArgumentPointeeTest, SetsTheNthPointeeOfProtoBufferBaseType) {
1027 TestMessage*
const msg =
new TestMessage;
1028 msg->set_member(
"yes");
1029 TestMessage orig_msg;
1030 orig_msg.CopyFrom(*msg);
1032 Action<void(bool, ::ProtocolMessage*)> a = SetArgumentPointee<1>(*msg);
1040 ::ProtocolMessage*
const dest_base = &
dest;
1049 TEST(SetArgumentPointeeTest, SetsTheNthPointeeOfProto2BufferType) {
1050 using testing::internal::FooMessage;
1051 FooMessage*
const msg =
new FooMessage;
1052 msg->set_int_field(2);
1053 msg->set_string_field(
"hi");
1054 FooMessage orig_msg;
1055 orig_msg.CopyFrom(*msg);
1057 Action<void(bool, FooMessage*)> a = SetArgumentPointee<1>(*msg);
1065 dest.set_int_field(0);
1074 TEST(SetArgumentPointeeTest, SetsTheNthPointeeOfProto2BufferBaseType) {
1075 using testing::internal::FooMessage;
1076 FooMessage*
const msg =
new FooMessage;
1077 msg->set_int_field(2);
1078 msg->set_string_field(
"hi");
1079 FooMessage orig_msg;
1080 orig_msg.CopyFrom(*msg);
1082 Action<void(bool, ::proto2::Message*)> a = SetArgumentPointee<1>(*msg);
1090 dest.set_int_field(0);
1091 ::proto2::Message*
const dest_base = &
dest;
1097 #endif // GTEST_HAS_PROTOBUF_ 1102 class NullaryFunctor {
1104 int operator()() {
return 2; }
1110 class VoidNullaryFunctor {
1112 void operator()() { g_done =
true; }
1117 Foo() : value_(123) {}
1119 int Nullary()
const {
return value_; }
1143 TEST(InvokeWithoutArgsTest, Functor) {
1149 Action<int(int, double, char)> a2 =
1163 Action<int(bool, char)> a =
1169 TEST(IgnoreResultTest, PolymorphicAction) {
1181 TEST(IgnoreResultTest, MonomorphicAction) {
1190 MyNonDefaultConstructible ReturnMyNonDefaultConstructible(
double ) {
1192 return MyNonDefaultConstructible(42);
1195 TEST(IgnoreResultTest, ActionReturningClass) {
1197 Action<void(int)> a =
1203 TEST(AssignTest, Int) {
1205 Action<void(int)> a =
Assign(&x, 5);
1210 TEST(AssignTest, String) {
1212 Action<void(void)> a =
Assign(&x,
"Hello, world");
1217 TEST(AssignTest, CompatibleTypes) {
1219 Action<void(int)> a =
Assign(&x, 5);
1224 #if !GTEST_OS_WINDOWS_MOBILE 1228 virtual void SetUp() { errno = 0; }
1229 virtual void TearDown() { errno = 0; }
1232 TEST_F(SetErrnoAndReturnTest, Int) {
1238 TEST_F(SetErrnoAndReturnTest, Ptr) {
1245 TEST_F(SetErrnoAndReturnTest, CompatibleTypes) {
1251 #endif // !GTEST_OS_WINDOWS_MOBILE 1266 ref_wrapper =
ByRef(s2);
1273 ref_wrapper = ref_wrapper1;
1279 TEST(ByRefTest, ConstValue) {
1283 const int& const_ref =
ByRef(n);
1288 TEST(ByRefTest, NonConstValue) {
1292 int& ref =
ByRef(n);
1296 const int& const_ref =
ByRef(n);
1301 TEST(ByRefTest, ExplicitType) {
1303 const int& r1 = ByRef<const int>(n);
1310 Derived& r2 = ByRef<Derived>(d);
1313 const Derived& r3 = ByRef<const Derived>(d);
1316 Base& r4 = ByRef<Base>(d);
1319 const Base& r5 = ByRef<const Base>(d);
1330 TEST(ByRefTest, PrintsCorrectly) {
1332 ::std::stringstream expected, actual;
1335 EXPECT_EQ(expected.str(), actual.str());
1338 #if GTEST_HAS_STD_UNIQUE_PTR_ 1340 std::unique_ptr<int> UniquePtrSource() {
1341 return std::unique_ptr<int>(
new int(19));
1344 std::vector<std::unique_ptr<int>> VectorUniquePtrSource() {
1345 std::vector<std::unique_ptr<int>> out;
1346 out.emplace_back(
new int(7));
1350 TEST(MockMethodTest, CanReturnMoveOnlyValue_Return) {
1352 std::unique_ptr<int>
i(
new int(19));
1356 Derived* d =
new Derived;
1358 .WillOnce(
Return(
ByMove(std::unique_ptr<Derived>(d))));
1360 std::unique_ptr<int> result1 = mock.MakeUnique();
1363 std::vector<std::unique_ptr<int>> vresult = mock.MakeVectorUnique();
1368 std::unique_ptr<Base> result2 = mock.MakeUniqueBase();
1372 TEST(MockMethodTest, CanReturnMoveOnlyValue_DoAllReturn) {
1375 std::unique_ptr<int>
i(
new int(19));
1381 std::unique_ptr<int> result1 = mock.MakeUnique();
1385 TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) {
1389 DefaultValue<std::unique_ptr<int>>::SetFactory([] {
1390 return std::unique_ptr<int>(
new int(42));
1396 .WillRepeatedly(
Invoke(VectorUniquePtrSource));
1397 std::unique_ptr<int> result1 = mock.MakeUnique();
1399 std::unique_ptr<int> result2 = mock.MakeUnique();
1403 std::vector<std::unique_ptr<int>> vresult = mock.MakeVectorUnique();
1409 #endif // GTEST_HAS_STD_UNIQUE_PTR_
#define EXPECT_ANY_THROW(statement)
TypeWithSize< 8 >::Int Int64
bool operator==(const char *c, CStringRange::Sentinel)
A polymorphic function wrapper that is not copyable and does not require the wrapped function to be c...
#define TEST(test_case_name, test_name)
internal::NeMatcher< Rhs > Ne(Rhs x)
PolymorphicAction< internal::SetArgumentPointeeAction< N, T, internal::IsAProtocolMessage< T >::value > > SetArgumentPointee(const T &x)
#define EXPECT_EQ(val1, val2)
PolymorphicAction< Impl > MakePolymorphicAction(const Impl &impl)
constexpr detail::Map< Move > move
TypeWithSize< 8 >::UInt UInt64
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
internal::ReturnRefAction< R > ReturnRef(R &x)
internal::ByMoveWrapper< R > ByMove(R x)
#define GTEST_DISALLOW_ASSIGN_(type)
boost::variant< DeliverAppData, WriteToSocket, ReportHandshakeSuccess, ReportEarlyHandshakeSuccess, ReportEarlyWriteFailed, ReportError, MutateState, WaitForData, NewCachedPsk > Action
Action< F > MakeAction(ActionInterface< F > *impl)
#define EXPECT_STREQ(s1, s2)
PolymorphicAction< internal::SetArgumentPointeeAction< N, T, internal::IsAProtocolMessage< T >::value > > SetArgPointee(const T &x)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
ConvertibleToBool IsNotZero(int number)
void UniversalPrint(const T &value,::std::ostream *os)
AtomicCounter< T, DeterministicAtomic > Base
static const char *const value
PolymorphicAction< internal::ReturnNullAction > ReturnNull()
#define EXPECT_TRUE(condition)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
#define EXPECT_THAT(value, matcher)
internal::DoDefaultAction DoDefault()
#define ON_CALL(obj, call)
#define EXPECT_DOUBLE_EQ(val1, val2)
#define MOCK_METHOD1(m,...)
internal::ReferenceWrapper< T > ByRef(T &l_value)
#define EXPECT_NE(val1, val2)
StrictConjunction< std::is_copy_constructible< T >, std::is_copy_assignable< T >> IsCopyable
#define EXPECT_NONFATAL_FAILURE(statement, substr)
PolymorphicAction< internal::AssignAction< T1, T2 > > Assign(T1 *ptr, T2 val)
internal::DoBothAction< Action1, Action2 > DoAll(Action1 a1, Action2 a2)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
internal::IgnoreResultAction< A > IgnoreResult(const A &an_action)
PolymorphicAction< internal::SetErrnoAndReturnAction< T > > SetErrnoAndReturn(int errval, T result)
static void Print(const T &value,::std::ostream *os)
PUSHMI_INLINE_VAR constexpr detail::get_fn< T > get
internal::ElementsAreMatcher< ::testing::tuple<> > ElementsAre()
internal::ReturnRefOfCopyAction< R > ReturnRefOfCopy(const R &x)
internal::ReturnAction< R > Return(R value)
#define TEST_F(test_fixture, test_name)
#define MOCK_METHOD0(m,...)