Unverified Commit 4b6a7a49 authored by Henry Schreiner's avatar Henry Schreiner Committed by GitHub
Browse files

Merge branch 'master' into cleanup-cmake

parents b22e8dec 82febb8e
...@@ -68,8 +68,8 @@ class FunctionMocker<R()> : public ...@@ -68,8 +68,8 @@ class FunctionMocker<R()> : public
typedef R F(); typedef R F();
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With() { MockSpec<F> With() {
return this->current_spec(); return MockSpec<F>(this, ::testing::make_tuple());
} }
R Invoke() { R Invoke() {
...@@ -88,9 +88,8 @@ class FunctionMocker<R(A1)> : public ...@@ -88,9 +88,8 @@ class FunctionMocker<R(A1)> : public
typedef R F(A1); typedef R F(A1);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1) { MockSpec<F> With(const Matcher<A1>& m1) {
this->current_spec().SetMatchers(::testing::make_tuple(m1)); return MockSpec<F>(this, ::testing::make_tuple(m1));
return this->current_spec();
} }
R Invoke(A1 a1) { R Invoke(A1 a1) {
...@@ -98,7 +97,7 @@ class FunctionMocker<R(A1)> : public ...@@ -98,7 +97,7 @@ class FunctionMocker<R(A1)> : public
// by the C++ standard [14.6.4] here, as the base class type is // by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be // dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith). // looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1)); return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1)));
} }
}; };
...@@ -109,9 +108,8 @@ class FunctionMocker<R(A1, A2)> : public ...@@ -109,9 +108,8 @@ class FunctionMocker<R(A1, A2)> : public
typedef R F(A1, A2); typedef R F(A1, A2);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2) { MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2) {
this->current_spec().SetMatchers(::testing::make_tuple(m1, m2)); return MockSpec<F>(this, ::testing::make_tuple(m1, m2));
return this->current_spec();
} }
R Invoke(A1 a1, A2 a2) { R Invoke(A1 a1, A2 a2) {
...@@ -119,7 +117,8 @@ class FunctionMocker<R(A1, A2)> : public ...@@ -119,7 +117,8 @@ class FunctionMocker<R(A1, A2)> : public
// by the C++ standard [14.6.4] here, as the base class type is // by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be // dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith). // looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2)); return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1),
internal::forward<A2>(a2)));
} }
}; };
...@@ -130,10 +129,9 @@ class FunctionMocker<R(A1, A2, A3)> : public ...@@ -130,10 +129,9 @@ class FunctionMocker<R(A1, A2, A3)> : public
typedef R F(A1, A2, A3); typedef R F(A1, A2, A3);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2,
const Matcher<A3>& m3) { const Matcher<A3>& m3) {
this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3)); return MockSpec<F>(this, ::testing::make_tuple(m1, m2, m3));
return this->current_spec();
} }
R Invoke(A1 a1, A2 a2, A3 a3) { R Invoke(A1 a1, A2 a2, A3 a3) {
...@@ -141,7 +139,8 @@ class FunctionMocker<R(A1, A2, A3)> : public ...@@ -141,7 +139,8 @@ class FunctionMocker<R(A1, A2, A3)> : public
// by the C++ standard [14.6.4] here, as the base class type is // by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be // dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith). // looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2, a3)); return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1),
internal::forward<A2>(a2), internal::forward<A3>(a3)));
} }
}; };
...@@ -152,10 +151,9 @@ class FunctionMocker<R(A1, A2, A3, A4)> : public ...@@ -152,10 +151,9 @@ class FunctionMocker<R(A1, A2, A3, A4)> : public
typedef R F(A1, A2, A3, A4); typedef R F(A1, A2, A3, A4);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2,
const Matcher<A3>& m3, const Matcher<A4>& m4) { const Matcher<A3>& m3, const Matcher<A4>& m4) {
this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4)); return MockSpec<F>(this, ::testing::make_tuple(m1, m2, m3, m4));
return this->current_spec();
} }
R Invoke(A1 a1, A2 a2, A3 a3, A4 a4) { R Invoke(A1 a1, A2 a2, A3 a3, A4 a4) {
...@@ -163,7 +161,9 @@ class FunctionMocker<R(A1, A2, A3, A4)> : public ...@@ -163,7 +161,9 @@ class FunctionMocker<R(A1, A2, A3, A4)> : public
// by the C++ standard [14.6.4] here, as the base class type is // by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be // dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith). // looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4)); return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1),
internal::forward<A2>(a2), internal::forward<A3>(a3),
internal::forward<A4>(a4)));
} }
}; };
...@@ -175,10 +175,9 @@ class FunctionMocker<R(A1, A2, A3, A4, A5)> : public ...@@ -175,10 +175,9 @@ class FunctionMocker<R(A1, A2, A3, A4, A5)> : public
typedef R F(A1, A2, A3, A4, A5); typedef R F(A1, A2, A3, A4, A5);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2,
const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5) { const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5) {
this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5)); return MockSpec<F>(this, ::testing::make_tuple(m1, m2, m3, m4, m5));
return this->current_spec();
} }
R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
...@@ -186,7 +185,9 @@ class FunctionMocker<R(A1, A2, A3, A4, A5)> : public ...@@ -186,7 +185,9 @@ class FunctionMocker<R(A1, A2, A3, A4, A5)> : public
// by the C++ standard [14.6.4] here, as the base class type is // by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be // dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith). // looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5)); return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1),
internal::forward<A2>(a2), internal::forward<A3>(a3),
internal::forward<A4>(a4), internal::forward<A5>(a5)));
} }
}; };
...@@ -198,12 +199,10 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6)> : public ...@@ -198,12 +199,10 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6)> : public
typedef R F(A1, A2, A3, A4, A5, A6); typedef R F(A1, A2, A3, A4, A5, A6);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2,
const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
const Matcher<A6>& m6) { const Matcher<A6>& m6) {
this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5, return MockSpec<F>(this, ::testing::make_tuple(m1, m2, m3, m4, m5, m6));
m6));
return this->current_spec();
} }
R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
...@@ -211,7 +210,10 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6)> : public ...@@ -211,7 +210,10 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6)> : public
// by the C++ standard [14.6.4] here, as the base class type is // by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be // dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith). // looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6)); return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1),
internal::forward<A2>(a2), internal::forward<A3>(a3),
internal::forward<A4>(a4), internal::forward<A5>(a5),
internal::forward<A6>(a6)));
} }
}; };
...@@ -223,12 +225,10 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7)> : public ...@@ -223,12 +225,10 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7)> : public
typedef R F(A1, A2, A3, A4, A5, A6, A7); typedef R F(A1, A2, A3, A4, A5, A6, A7);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2,
const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
const Matcher<A6>& m6, const Matcher<A7>& m7) { const Matcher<A6>& m6, const Matcher<A7>& m7) {
this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5, return MockSpec<F>(this, ::testing::make_tuple(m1, m2, m3, m4, m5, m6, m7));
m6, m7));
return this->current_spec();
} }
R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
...@@ -236,7 +236,10 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7)> : public ...@@ -236,7 +236,10 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7)> : public
// by the C++ standard [14.6.4] here, as the base class type is // by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be // dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith). // looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7)); return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1),
internal::forward<A2>(a2), internal::forward<A3>(a3),
internal::forward<A4>(a4), internal::forward<A5>(a5),
internal::forward<A6>(a6), internal::forward<A7>(a7)));
} }
}; };
...@@ -248,12 +251,11 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8)> : public ...@@ -248,12 +251,11 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8)> : public
typedef R F(A1, A2, A3, A4, A5, A6, A7, A8); typedef R F(A1, A2, A3, A4, A5, A6, A7, A8);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2,
const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8) { const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8) {
this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5, return MockSpec<F>(this, ::testing::make_tuple(m1, m2, m3, m4, m5, m6, m7,
m6, m7, m8)); m8));
return this->current_spec();
} }
R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) { R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) {
...@@ -261,7 +263,11 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8)> : public ...@@ -261,7 +263,11 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8)> : public
// by the C++ standard [14.6.4] here, as the base class type is // by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be // dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith). // looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8)); return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1),
internal::forward<A2>(a2), internal::forward<A3>(a3),
internal::forward<A4>(a4), internal::forward<A5>(a5),
internal::forward<A6>(a6), internal::forward<A7>(a7),
internal::forward<A8>(a8)));
} }
}; };
...@@ -273,13 +279,12 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> : public ...@@ -273,13 +279,12 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> : public
typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9); typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2,
const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8, const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8,
const Matcher<A9>& m9) { const Matcher<A9>& m9) {
this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5, return MockSpec<F>(this, ::testing::make_tuple(m1, m2, m3, m4, m5, m6, m7,
m6, m7, m8, m9)); m8, m9));
return this->current_spec();
} }
R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) { R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) {
...@@ -287,7 +292,11 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> : public ...@@ -287,7 +292,11 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> : public
// by the C++ standard [14.6.4] here, as the base class type is // by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be // dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith). // looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9)); return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1),
internal::forward<A2>(a2), internal::forward<A3>(a3),
internal::forward<A4>(a4), internal::forward<A5>(a5),
internal::forward<A6>(a6), internal::forward<A7>(a7),
internal::forward<A8>(a8), internal::forward<A9>(a9)));
} }
}; };
...@@ -300,13 +309,12 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public ...@@ -300,13 +309,12 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public
typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, MockSpec<F> With(const Matcher<A1>& m1, const Matcher<A2>& m2,
const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8, const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8,
const Matcher<A9>& m9, const Matcher<A10>& m10) { const Matcher<A9>& m9, const Matcher<A10>& m10) {
this->current_spec().SetMatchers(::testing::make_tuple(m1, m2, m3, m4, m5, return MockSpec<F>(this, ::testing::make_tuple(m1, m2, m3, m4, m5, m6, m7,
m6, m7, m8, m9, m10)); m8, m9, m10));
return this->current_spec();
} }
R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
...@@ -315,8 +323,12 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public ...@@ -315,8 +323,12 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public
// by the C++ standard [14.6.4] here, as the base class type is // by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be // dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith). // looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9, return this->InvokeWith(ArgumentTuple(internal::forward<A1>(a1),
a10)); internal::forward<A2>(a2), internal::forward<A3>(a3),
internal::forward<A4>(a4), internal::forward<A5>(a5),
internal::forward<A6>(a6), internal::forward<A7>(a7),
internal::forward<A8>(a8), internal::forward<A9>(a9),
internal::forward<A10>(a10)));
} }
}; };
...@@ -363,7 +375,7 @@ using internal::FunctionMocker; ...@@ -363,7 +375,7 @@ using internal::FunctionMocker;
GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(0, constness, Method).Invoke(); \ return GMOCK_MOCKER_(0, constness, Method).Invoke(); \
} \ } \
::testing::MockSpec<__VA_ARGS__>& \ ::testing::MockSpec<__VA_ARGS__> \
gmock_##Method() constness { \ gmock_##Method() constness { \
GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \ GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(0, constness, Method).With(); \ return GMOCK_MOCKER_(0, constness, Method).With(); \
...@@ -380,9 +392,11 @@ using internal::FunctionMocker; ...@@ -380,9 +392,11 @@ using internal::FunctionMocker;
== 1), \ == 1), \
this_method_does_not_take_1_argument); \ this_method_does_not_take_1_argument); \
GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(1, constness, Method).Invoke(gmock_a1); \ return GMOCK_MOCKER_(1, constness, \
Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \
__VA_ARGS__)>(gmock_a1)); \
} \ } \
::testing::MockSpec<__VA_ARGS__>& \ ::testing::MockSpec<__VA_ARGS__> \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \ GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \ return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \
...@@ -393,16 +407,19 @@ using internal::FunctionMocker; ...@@ -393,16 +407,19 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2) constness { \ __VA_ARGS__) gmock_a2) constness { \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
== 2), \ == 2), \
this_method_does_not_take_2_arguments); \ this_method_does_not_take_2_arguments); \
GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(2, constness, Method).Invoke(gmock_a1, gmock_a2); \ return GMOCK_MOCKER_(2, constness, \
Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \
__VA_ARGS__)>(gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2)); \
} \ } \
::testing::MockSpec<__VA_ARGS__>& \ ::testing::MockSpec<__VA_ARGS__> \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \
GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \ GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \
...@@ -414,18 +431,21 @@ using internal::FunctionMocker; ...@@ -414,18 +431,21 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, \
GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3) constness { \ __VA_ARGS__) gmock_a3) constness { \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
== 3), \ == 3), \
this_method_does_not_take_3_arguments); \ this_method_does_not_take_3_arguments); \
GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(3, constness, Method).Invoke(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(3, constness, \
gmock_a3); \ Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \
__VA_ARGS__)>(gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3)); \
} \ } \
::testing::MockSpec<__VA_ARGS__>& \ ::testing::MockSpec<__VA_ARGS__> \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \
...@@ -439,19 +459,22 @@ using internal::FunctionMocker; ...@@ -439,19 +459,22 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
== 4), \ == 4), \
this_method_does_not_take_4_arguments); \ this_method_does_not_take_4_arguments); \
GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(4, constness, Method).Invoke(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(4, constness, \
gmock_a3, gmock_a4); \ Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \
__VA_ARGS__)>(gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4)); \
} \ } \
::testing::MockSpec<__VA_ARGS__>& \ ::testing::MockSpec<__VA_ARGS__> \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
...@@ -466,20 +489,24 @@ using internal::FunctionMocker; ...@@ -466,20 +489,24 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ __VA_ARGS__) gmock_a5) constness { \
GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5) constness { \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
== 5), \ == 5), \
this_method_does_not_take_5_arguments); \ this_method_does_not_take_5_arguments); \
GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(5, constness, Method).Invoke(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(5, constness, \
gmock_a3, gmock_a4, gmock_a5); \ Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \
__VA_ARGS__)>(gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5)); \
} \ } \
::testing::MockSpec<__VA_ARGS__>& \ ::testing::MockSpec<__VA_ARGS__> \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
...@@ -495,21 +522,26 @@ using internal::FunctionMocker; ...@@ -495,21 +522,26 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, \
GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ __VA_ARGS__) gmock_a6) constness { \
GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6) constness { \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
== 6), \ == 6), \
this_method_does_not_take_6_arguments); \ this_method_does_not_take_6_arguments); \
GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(6, constness, Method).Invoke(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(6, constness, \
gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \
__VA_ARGS__)>(gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \
::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6)); \
} \ } \
::testing::MockSpec<__VA_ARGS__>& \ ::testing::MockSpec<__VA_ARGS__> \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
...@@ -526,22 +558,27 @@ using internal::FunctionMocker; ...@@ -526,22 +558,27 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
== 7), \ == 7), \
this_method_does_not_take_7_arguments); \ this_method_does_not_take_7_arguments); \
GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(7, constness, Method).Invoke(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(7, constness, \
gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \
__VA_ARGS__)>(gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \
::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6), \
::testing::internal::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(gmock_a7)); \
} \ } \
::testing::MockSpec<__VA_ARGS__>& \ ::testing::MockSpec<__VA_ARGS__> \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
...@@ -559,23 +596,29 @@ using internal::FunctionMocker; ...@@ -559,23 +596,29 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \
GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ __VA_ARGS__) gmock_a8) constness { \
GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8) constness { \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
== 8), \ == 8), \
this_method_does_not_take_8_arguments); \ this_method_does_not_take_8_arguments); \
GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(8, constness, Method).Invoke(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(8, constness, \
gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \
__VA_ARGS__)>(gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \
::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6), \
::testing::internal::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(gmock_a7), \
::testing::internal::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(gmock_a8)); \
} \ } \
::testing::MockSpec<__VA_ARGS__>& \ ::testing::MockSpec<__VA_ARGS__> \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
...@@ -594,25 +637,31 @@ using internal::FunctionMocker; ...@@ -594,25 +637,31 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \
GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ __VA_ARGS__) gmock_a8, GMOCK_ARG_(tn, 9, \
GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ __VA_ARGS__) gmock_a9) constness { \
GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \
GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9) constness { \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
== 9), \ == 9), \
this_method_does_not_take_9_arguments); \ this_method_does_not_take_9_arguments); \
GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(9, constness, Method).Invoke(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(9, constness, \
gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \ Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \
gmock_a9); \ __VA_ARGS__)>(gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \
::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6), \
::testing::internal::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(gmock_a7), \
::testing::internal::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(gmock_a8), \
::testing::internal::forward<GMOCK_ARG_(tn, 9, __VA_ARGS__)>(gmock_a9)); \
} \ } \
::testing::MockSpec<__VA_ARGS__>& \ ::testing::MockSpec<__VA_ARGS__> \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
...@@ -633,26 +682,32 @@ using internal::FunctionMocker; ...@@ -633,26 +682,32 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \
GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \ __VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \
GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \ __VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \ GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \
GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ __VA_ARGS__) gmock_a8, GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \
GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \ GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \
GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \
GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \
GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \
== 10), \ == 10), \
this_method_does_not_take_10_arguments); \ this_method_does_not_take_10_arguments); \
GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(10, constness, Method).Invoke(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(10, constness, \
gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \ Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \
gmock_a10); \ __VA_ARGS__)>(gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \
::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \
::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \
::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6), \
::testing::internal::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(gmock_a7), \
::testing::internal::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(gmock_a8), \
::testing::internal::forward<GMOCK_ARG_(tn, 9, __VA_ARGS__)>(gmock_a9), \
::testing::internal::forward<GMOCK_ARG_(tn, 10, __VA_ARGS__)>(gmock_a10)); \
} \ } \
::testing::MockSpec<__VA_ARGS__>& \ ::testing::MockSpec<__VA_ARGS__> \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
...@@ -880,7 +935,7 @@ class MockFunction<R()> { ...@@ -880,7 +935,7 @@ class MockFunction<R()> {
MOCK_METHOD0_T(Call, R()); MOCK_METHOD0_T(Call, R());
#if GTEST_HAS_STD_FUNCTION_ #if GTEST_HAS_STD_FUNCTION_
std::function<R()> AsStdFunction() { ::std::function<R()> AsStdFunction() {
return [this]() -> R { return [this]() -> R {
return this->Call(); return this->Call();
}; };
...@@ -899,9 +954,9 @@ class MockFunction<R(A0)> { ...@@ -899,9 +954,9 @@ class MockFunction<R(A0)> {
MOCK_METHOD1_T(Call, R(A0)); MOCK_METHOD1_T(Call, R(A0));
#if GTEST_HAS_STD_FUNCTION_ #if GTEST_HAS_STD_FUNCTION_
std::function<R(A0)> AsStdFunction() { ::std::function<R(A0)> AsStdFunction() {
return [this](A0 a0) -> R { return [this](A0 a0) -> R {
return this->Call(a0); return this->Call(::std::move(a0));
}; };
} }
#endif // GTEST_HAS_STD_FUNCTION_ #endif // GTEST_HAS_STD_FUNCTION_
...@@ -918,9 +973,9 @@ class MockFunction<R(A0, A1)> { ...@@ -918,9 +973,9 @@ class MockFunction<R(A0, A1)> {
MOCK_METHOD2_T(Call, R(A0, A1)); MOCK_METHOD2_T(Call, R(A0, A1));
#if GTEST_HAS_STD_FUNCTION_ #if GTEST_HAS_STD_FUNCTION_
std::function<R(A0, A1)> AsStdFunction() { ::std::function<R(A0, A1)> AsStdFunction() {
return [this](A0 a0, A1 a1) -> R { return [this](A0 a0, A1 a1) -> R {
return this->Call(a0, a1); return this->Call(::std::move(a0), ::std::move(a1));
}; };
} }
#endif // GTEST_HAS_STD_FUNCTION_ #endif // GTEST_HAS_STD_FUNCTION_
...@@ -937,9 +992,9 @@ class MockFunction<R(A0, A1, A2)> { ...@@ -937,9 +992,9 @@ class MockFunction<R(A0, A1, A2)> {
MOCK_METHOD3_T(Call, R(A0, A1, A2)); MOCK_METHOD3_T(Call, R(A0, A1, A2));
#if GTEST_HAS_STD_FUNCTION_ #if GTEST_HAS_STD_FUNCTION_
std::function<R(A0, A1, A2)> AsStdFunction() { ::std::function<R(A0, A1, A2)> AsStdFunction() {
return [this](A0 a0, A1 a1, A2 a2) -> R { return [this](A0 a0, A1 a1, A2 a2) -> R {
return this->Call(a0, a1, a2); return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2));
}; };
} }
#endif // GTEST_HAS_STD_FUNCTION_ #endif // GTEST_HAS_STD_FUNCTION_
...@@ -956,9 +1011,10 @@ class MockFunction<R(A0, A1, A2, A3)> { ...@@ -956,9 +1011,10 @@ class MockFunction<R(A0, A1, A2, A3)> {
MOCK_METHOD4_T(Call, R(A0, A1, A2, A3)); MOCK_METHOD4_T(Call, R(A0, A1, A2, A3));
#if GTEST_HAS_STD_FUNCTION_ #if GTEST_HAS_STD_FUNCTION_
std::function<R(A0, A1, A2, A3)> AsStdFunction() { ::std::function<R(A0, A1, A2, A3)> AsStdFunction() {
return [this](A0 a0, A1 a1, A2 a2, A3 a3) -> R { return [this](A0 a0, A1 a1, A2 a2, A3 a3) -> R {
return this->Call(a0, a1, a2, a3); return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2),
::std::move(a3));
}; };
} }
#endif // GTEST_HAS_STD_FUNCTION_ #endif // GTEST_HAS_STD_FUNCTION_
...@@ -976,9 +1032,10 @@ class MockFunction<R(A0, A1, A2, A3, A4)> { ...@@ -976,9 +1032,10 @@ class MockFunction<R(A0, A1, A2, A3, A4)> {
MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4)); MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4));
#if GTEST_HAS_STD_FUNCTION_ #if GTEST_HAS_STD_FUNCTION_
std::function<R(A0, A1, A2, A3, A4)> AsStdFunction() { ::std::function<R(A0, A1, A2, A3, A4)> AsStdFunction() {
return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) -> R { return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) -> R {
return this->Call(a0, a1, a2, a3, a4); return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2),
::std::move(a3), ::std::move(a4));
}; };
} }
#endif // GTEST_HAS_STD_FUNCTION_ #endif // GTEST_HAS_STD_FUNCTION_
...@@ -996,9 +1053,10 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5)> { ...@@ -996,9 +1053,10 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5)> {
MOCK_METHOD6_T(Call, R(A0, A1, A2, A3, A4, A5)); MOCK_METHOD6_T(Call, R(A0, A1, A2, A3, A4, A5));
#if GTEST_HAS_STD_FUNCTION_ #if GTEST_HAS_STD_FUNCTION_
std::function<R(A0, A1, A2, A3, A4, A5)> AsStdFunction() { ::std::function<R(A0, A1, A2, A3, A4, A5)> AsStdFunction() {
return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) -> R { return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) -> R {
return this->Call(a0, a1, a2, a3, a4, a5); return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2),
::std::move(a3), ::std::move(a4), ::std::move(a5));
}; };
} }
#endif // GTEST_HAS_STD_FUNCTION_ #endif // GTEST_HAS_STD_FUNCTION_
...@@ -1016,9 +1074,10 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5, A6)> { ...@@ -1016,9 +1074,10 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5, A6)> {
MOCK_METHOD7_T(Call, R(A0, A1, A2, A3, A4, A5, A6)); MOCK_METHOD7_T(Call, R(A0, A1, A2, A3, A4, A5, A6));
#if GTEST_HAS_STD_FUNCTION_ #if GTEST_HAS_STD_FUNCTION_
std::function<R(A0, A1, A2, A3, A4, A5, A6)> AsStdFunction() { ::std::function<R(A0, A1, A2, A3, A4, A5, A6)> AsStdFunction() {
return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) -> R { return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) -> R {
return this->Call(a0, a1, a2, a3, a4, a5, a6); return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2),
::std::move(a3), ::std::move(a4), ::std::move(a5), ::std::move(a6));
}; };
} }
#endif // GTEST_HAS_STD_FUNCTION_ #endif // GTEST_HAS_STD_FUNCTION_
...@@ -1036,9 +1095,11 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7)> { ...@@ -1036,9 +1095,11 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7)> {
MOCK_METHOD8_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7)); MOCK_METHOD8_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7));
#if GTEST_HAS_STD_FUNCTION_ #if GTEST_HAS_STD_FUNCTION_
std::function<R(A0, A1, A2, A3, A4, A5, A6, A7)> AsStdFunction() { ::std::function<R(A0, A1, A2, A3, A4, A5, A6, A7)> AsStdFunction() {
return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) -> R { return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) -> R {
return this->Call(a0, a1, a2, a3, a4, a5, a6, a7); return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2),
::std::move(a3), ::std::move(a4), ::std::move(a5), ::std::move(a6),
::std::move(a7));
}; };
} }
#endif // GTEST_HAS_STD_FUNCTION_ #endif // GTEST_HAS_STD_FUNCTION_
...@@ -1056,10 +1117,12 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> { ...@@ -1056,10 +1117,12 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> {
MOCK_METHOD9_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8)); MOCK_METHOD9_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8));
#if GTEST_HAS_STD_FUNCTION_ #if GTEST_HAS_STD_FUNCTION_
std::function<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> AsStdFunction() { ::std::function<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> AsStdFunction() {
return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7,
A8 a8) -> R { A8 a8) -> R {
return this->Call(a0, a1, a2, a3, a4, a5, a6, a7, a8); return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2),
::std::move(a3), ::std::move(a4), ::std::move(a5), ::std::move(a6),
::std::move(a7), ::std::move(a8));
}; };
} }
#endif // GTEST_HAS_STD_FUNCTION_ #endif // GTEST_HAS_STD_FUNCTION_
...@@ -1078,10 +1141,12 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> { ...@@ -1078,10 +1141,12 @@ class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
MOCK_METHOD10_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)); MOCK_METHOD10_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9));
#if GTEST_HAS_STD_FUNCTION_ #if GTEST_HAS_STD_FUNCTION_
std::function<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> AsStdFunction() { ::std::function<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> AsStdFunction() {
return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, return [this](A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7,
A8 a8, A9 a9) -> R { A8 a8, A9 a9) -> R {
return this->Call(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); return this->Call(::std::move(a0), ::std::move(a1), ::std::move(a2),
::std::move(a3), ::std::move(a4), ::std::move(a5), ::std::move(a6),
::std::move(a7), ::std::move(a8), ::std::move(a9));
}; };
} }
#endif // GTEST_HAS_STD_FUNCTION_ #endif // GTEST_HAS_STD_FUNCTION_
......
$$ -*- mode: c++; -*- $$ -*- mode: c++; -*-
$$ This is a Pump source file. Please use Pump to convert it to $$ This is a Pump source file. Please use Pump to convert
$$ gmock-generated-function-mockers.h. $$ it to gmock-generated-function-mockers.h.
$$ $$
$var n = 10 $$ The maximum arity we support. $var n = 10 $$ The maximum arity we support.
// Copyright 2007, Google Inc. // Copyright 2007, Google Inc.
......
...@@ -51,10 +51,9 @@ ...@@ -51,10 +51,9 @@
// NiceMock<MockFoo>. // NiceMock<MockFoo>.
// //
// NiceMock, NaggyMock, and StrictMock "inherit" the constructors of // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
// their respective base class, with up-to 10 arguments. Therefore // their respective base class. Therefore you can write
// you can write NiceMock<MockFoo>(5, "a") to construct a nice mock // NiceMock<MockFoo>(5, "a") to construct a nice mock where MockFoo
// where MockFoo has a constructor that accepts (int, const char*), // has a constructor that accepts (int, const char*), for example.
// for example.
// //
// A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>, // A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
// and StrictMock<MockFoo> only works for mock methods defined using // and StrictMock<MockFoo> only works for mock methods defined using
...@@ -63,10 +62,6 @@ ...@@ -63,10 +62,6 @@
// or "strict" modifier may not affect it, depending on the compiler. // or "strict" modifier may not affect it, depending on the compiler.
// In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
// supported. // supported.
//
// Another known limitation is that the constructors of the base mock
// cannot have arguments passed by non-const reference, which are
// banned by the Google C++ style guide anyway.
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
...@@ -76,294 +71,329 @@ ...@@ -76,294 +71,329 @@
namespace testing { namespace testing {
namespace internal {
// NiceMockBase serves as a mix-in to establish the "uninteresting call"
// behavior for NiceMock on construction. It accomplishes this via CRTP to get
// access to the derived MockClass.
template <class MockClass>
class NiceMockBase {
protected:
NiceMockBase();
~NiceMockBase();
};
} // namespace internal
template <class MockClass> template <class MockClass>
class NiceMock : public MockClass { class NiceMock : public MockClass, public internal::NiceMockBase<MockClass> {
public: public:
// We don't factor out the constructor body to a common method, as NiceMock() : MockClass() {}
// we have to avoid a possible clash with members of MockClass.
NiceMock() { #if GTEST_LANG_CXX11
::testing::Mock::AllowUninterestingCalls( // Ideally, we would inherit base class's constructors through a using
internal::ImplicitCast_<MockClass*>(this)); // declaration, which would preserve their visibility. However, many existing
} // tests rely on the fact that current implementation reexports protected
// constructors as public. These tests would need to be cleaned up first.
// C++ doesn't (yet) allow inheritance of constructors, so we have
// to define it for each arity. // Single argument constructor is special-cased so that it can be
// made explicit.
template <typename A>
explicit NiceMock(A&& arg) : MockClass(std::forward<A>(arg)) {}
template <typename A1, typename A2, typename... An>
NiceMock(A1&& arg1, A2&& arg2, An&&... args)
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
std::forward<An>(args)...) {}
#else
// C++98 doesn't have variadic templates, so we have to define one
// for each arity.
template <typename A1> template <typename A1>
explicit NiceMock(const A1& a1) : MockClass(a1) { explicit NiceMock(const A1& a1) : MockClass(a1) {}
::testing::Mock::AllowUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2> template <typename A1, typename A2>
NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {}
::testing::Mock::AllowUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3> template <typename A1, typename A2, typename A3>
NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {}
::testing::Mock::AllowUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4> template <typename A1, typename A2, typename A3, typename A4>
NiceMock(const A1& a1, const A2& a2, const A3& a3, NiceMock(const A1& a1, const A2& a2, const A3& a3,
const A4& a4) : MockClass(a1, a2, a3, a4) { const A4& a4) : MockClass(a1, a2, a3, a4) {}
::testing::Mock::AllowUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5> template <typename A1, typename A2, typename A3, typename A4, typename A5>
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5) : MockClass(a1, a2, a3, a4, a5) { const A5& a5) : MockClass(a1, a2, a3, a4, a5) {}
::testing::Mock::AllowUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5, template <typename A1, typename A2, typename A3, typename A4, typename A5,
typename A6> typename A6>
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {}
::testing::Mock::AllowUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5, template <typename A1, typename A2, typename A3, typename A4, typename A5,
typename A6, typename A7> typename A6, typename A7>
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
a6, a7) { a6, a7) {}
::testing::Mock::AllowUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5, template <typename A1, typename A2, typename A3, typename A4, typename A5,
typename A6, typename A7, typename A8> typename A6, typename A7, typename A8>
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
a2, a3, a4, a5, a6, a7, a8) { a2, a3, a4, a5, a6, a7, a8) {}
::testing::Mock::AllowUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5, template <typename A1, typename A2, typename A3, typename A4, typename A5,
typename A6, typename A7, typename A8, typename A9> typename A6, typename A7, typename A8, typename A9>
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A5& a5, const A6& a6, const A7& a7, const A8& a8,
const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {}
::testing::Mock::AllowUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5, template <typename A1, typename A2, typename A3, typename A4, typename A5,
typename A6, typename A7, typename A8, typename A9, typename A10> typename A6, typename A7, typename A8, typename A9, typename A10>
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {}
::testing::Mock::AllowUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
virtual ~NiceMock() { #endif // GTEST_LANG_CXX11
::testing::Mock::UnregisterCallReaction(
internal::ImplicitCast_<MockClass*>(this));
}
private: private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock); GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
}; };
namespace internal {
template <typename MockClass>
NiceMockBase<MockClass>::NiceMockBase() {
::testing::Mock::AllowUninterestingCalls(
internal::ImplicitCast_<MockClass*>(
static_cast<NiceMock<MockClass> *>(this)));
}
template <typename MockClass>
NiceMockBase<MockClass>::~NiceMockBase() {
::testing::Mock::UnregisterCallReaction(
internal::ImplicitCast_<MockClass*>(
static_cast<NiceMock<MockClass>*>(this)));
}
} // namespace internal
namespace internal {
// NaggyMockBase serves as a mix-in to establish the "uninteresting call"
// behavior for NaggyMock on construction. It accomplishes this via CRTP to get
// access to the derived MockClass.
template <class MockClass>
class NaggyMockBase {
protected:
NaggyMockBase();
~NaggyMockBase();
};
} // namespace internal
template <class MockClass> template <class MockClass>
class NaggyMock : public MockClass { class NaggyMock : public MockClass, public internal::NaggyMockBase<MockClass> {
public: public:
// We don't factor out the constructor body to a common method, as NaggyMock() : MockClass() {}
// we have to avoid a possible clash with members of MockClass.
NaggyMock() { #if GTEST_LANG_CXX11
::testing::Mock::WarnUninterestingCalls( // Ideally, we would inherit base class's constructors through a using
internal::ImplicitCast_<MockClass*>(this)); // declaration, which would preserve their visibility. However, many existing
} // tests rely on the fact that current implementation reexports protected
// constructors as public. These tests would need to be cleaned up first.
// C++ doesn't (yet) allow inheritance of constructors, so we have
// to define it for each arity. // Single argument constructor is special-cased so that it can be
// made explicit.
template <typename A>
explicit NaggyMock(A&& arg) : MockClass(std::forward<A>(arg)) {}
template <typename A1, typename A2, typename... An>
NaggyMock(A1&& arg1, A2&& arg2, An&&... args)
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
std::forward<An>(args)...) {}
#else
// C++98 doesn't have variadic templates, so we have to define one
// for each arity.
template <typename A1> template <typename A1>
explicit NaggyMock(const A1& a1) : MockClass(a1) { explicit NaggyMock(const A1& a1) : MockClass(a1) {}
::testing::Mock::WarnUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2> template <typename A1, typename A2>
NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {}
::testing::Mock::WarnUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3> template <typename A1, typename A2, typename A3>
NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {}
::testing::Mock::WarnUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4> template <typename A1, typename A2, typename A3, typename A4>
NaggyMock(const A1& a1, const A2& a2, const A3& a3, NaggyMock(const A1& a1, const A2& a2, const A3& a3,
const A4& a4) : MockClass(a1, a2, a3, a4) { const A4& a4) : MockClass(a1, a2, a3, a4) {}
::testing::Mock::WarnUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5> template <typename A1, typename A2, typename A3, typename A4, typename A5>
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5) : MockClass(a1, a2, a3, a4, a5) { const A5& a5) : MockClass(a1, a2, a3, a4, a5) {}
::testing::Mock::WarnUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5, template <typename A1, typename A2, typename A3, typename A4, typename A5,
typename A6> typename A6>
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {}
::testing::Mock::WarnUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5, template <typename A1, typename A2, typename A3, typename A4, typename A5,
typename A6, typename A7> typename A6, typename A7>
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
a6, a7) { a6, a7) {}
::testing::Mock::WarnUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5, template <typename A1, typename A2, typename A3, typename A4, typename A5,
typename A6, typename A7, typename A8> typename A6, typename A7, typename A8>
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
a2, a3, a4, a5, a6, a7, a8) { a2, a3, a4, a5, a6, a7, a8) {}
::testing::Mock::WarnUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5, template <typename A1, typename A2, typename A3, typename A4, typename A5,
typename A6, typename A7, typename A8, typename A9> typename A6, typename A7, typename A8, typename A9>
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A5& a5, const A6& a6, const A7& a7, const A8& a8,
const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {}
::testing::Mock::WarnUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5, template <typename A1, typename A2, typename A3, typename A4, typename A5,
typename A6, typename A7, typename A8, typename A9, typename A10> typename A6, typename A7, typename A8, typename A9, typename A10>
NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {}
::testing::Mock::WarnUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
virtual ~NaggyMock() { #endif // GTEST_LANG_CXX11
::testing::Mock::UnregisterCallReaction(
internal::ImplicitCast_<MockClass*>(this));
}
private: private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock); GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
}; };
namespace internal {
template <typename MockClass>
NaggyMockBase<MockClass>::NaggyMockBase() {
::testing::Mock::WarnUninterestingCalls(
internal::ImplicitCast_<MockClass*>(
static_cast<NaggyMock<MockClass> *>(this)));
}
template <typename MockClass>
NaggyMockBase<MockClass>::~NaggyMockBase() {
::testing::Mock::UnregisterCallReaction(
internal::ImplicitCast_<MockClass*>(
static_cast<NaggyMock<MockClass>*>(this)));
}
} // namespace internal
namespace internal {
// StrictMockBase serves as a mix-in to establish the "uninteresting call"
// behavior for StrictMock on construction. It accomplishes this via CRTP to get
// access to the derived MockClass.
template <class MockClass>
class StrictMockBase {
protected:
StrictMockBase();
~StrictMockBase();
};
} // namespace internal
template <class MockClass> template <class MockClass>
class StrictMock : public MockClass { class StrictMock : public MockClass,
public internal::StrictMockBase<MockClass> {
public: public:
// We don't factor out the constructor body to a common method, as StrictMock() : MockClass() {}
// we have to avoid a possible clash with members of MockClass.
StrictMock() { #if GTEST_LANG_CXX11
::testing::Mock::FailUninterestingCalls( // Ideally, we would inherit base class's constructors through a using
internal::ImplicitCast_<MockClass*>(this)); // declaration, which would preserve their visibility. However, many existing
} // tests rely on the fact that current implementation reexports protected
// constructors as public. These tests would need to be cleaned up first.
// C++ doesn't (yet) allow inheritance of constructors, so we have
// to define it for each arity. // Single argument constructor is special-cased so that it can be
// made explicit.
template <typename A>
explicit StrictMock(A&& arg) : MockClass(std::forward<A>(arg)) {}
template <typename A1, typename A2, typename... An>
StrictMock(A1&& arg1, A2&& arg2, An&&... args)
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
std::forward<An>(args)...) {}
#else
// C++98 doesn't have variadic templates, so we have to define one
// for each arity.
template <typename A1> template <typename A1>
explicit StrictMock(const A1& a1) : MockClass(a1) { explicit StrictMock(const A1& a1) : MockClass(a1) {}
::testing::Mock::FailUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2> template <typename A1, typename A2>
StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {}
::testing::Mock::FailUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3> template <typename A1, typename A2, typename A3>
StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2,
::testing::Mock::FailUninterestingCalls( a3) {}
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4> template <typename A1, typename A2, typename A3, typename A4>
StrictMock(const A1& a1, const A2& a2, const A3& a3, StrictMock(const A1& a1, const A2& a2, const A3& a3,
const A4& a4) : MockClass(a1, a2, a3, a4) { const A4& a4) : MockClass(a1, a2, a3, a4) {}
::testing::Mock::FailUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5> template <typename A1, typename A2, typename A3, typename A4, typename A5>
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5) : MockClass(a1, a2, a3, a4, a5) { const A5& a5) : MockClass(a1, a2, a3, a4, a5) {}
::testing::Mock::FailUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5, template <typename A1, typename A2, typename A3, typename A4, typename A5,
typename A6> typename A6>
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {}
::testing::Mock::FailUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5, template <typename A1, typename A2, typename A3, typename A4, typename A5,
typename A6, typename A7> typename A6, typename A7>
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
a6, a7) { a6, a7) {}
::testing::Mock::FailUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5, template <typename A1, typename A2, typename A3, typename A4, typename A5,
typename A6, typename A7, typename A8> typename A6, typename A7, typename A8>
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
a2, a3, a4, a5, a6, a7, a8) { a2, a3, a4, a5, a6, a7, a8) {}
::testing::Mock::FailUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5, template <typename A1, typename A2, typename A3, typename A4, typename A5,
typename A6, typename A7, typename A8, typename A9> typename A6, typename A7, typename A8, typename A9>
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A5& a5, const A6& a6, const A7& a7, const A8& a8,
const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {}
::testing::Mock::FailUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
template <typename A1, typename A2, typename A3, typename A4, typename A5, template <typename A1, typename A2, typename A3, typename A4, typename A5,
typename A6, typename A7, typename A8, typename A9, typename A10> typename A6, typename A7, typename A8, typename A9, typename A10>
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {}
::testing::Mock::FailUninterestingCalls(
internal::ImplicitCast_<MockClass*>(this));
}
virtual ~StrictMock() { #endif // GTEST_LANG_CXX11
::testing::Mock::UnregisterCallReaction(
internal::ImplicitCast_<MockClass*>(this));
}
private: private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock); GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
}; };
namespace internal {
template <typename MockClass>
StrictMockBase<MockClass>::StrictMockBase() {
::testing::Mock::FailUninterestingCalls(
internal::ImplicitCast_<MockClass*>(
static_cast<StrictMock<MockClass> *>(this)));
}
template <typename MockClass>
StrictMockBase<MockClass>::~StrictMockBase() {
::testing::Mock::UnregisterCallReaction(
internal::ImplicitCast_<MockClass*>(
static_cast<StrictMock<MockClass>*>(this)));
}
} // namespace internal
// The following specializations catch some (relatively more common) // The following specializations catch some (relatively more common)
// user errors of nesting nice and strict mocks. They do NOT catch // user errors of nesting nice and strict mocks. They do NOT catch
// all possible errors. // all possible errors.
......
...@@ -43,6 +43,15 @@ ...@@ -43,6 +43,15 @@
namespace testing { namespace testing {
// Silence C4100 (unreferenced formal
// parameter) for MSVC
#ifdef _MSC_VER
# pragma warning(disable:4100)
#if (_MSC_VER == 1900)
# pragma warning(disable:4800)
#endif
#endif
// Defines a matcher that matches an empty container. The container must // Defines a matcher that matches an empty container. The container must
// support both size() and empty(), which all STL-like containers provide. // support both size() and empty(), which all STL-like containers provide.
MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") { MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") {
......
...@@ -103,6 +103,11 @@ class ExpectationTester; ...@@ -103,6 +103,11 @@ class ExpectationTester;
// Base class for function mockers. // Base class for function mockers.
template <typename F> class FunctionMockerBase; template <typename F> class FunctionMockerBase;
// Uninteresting call behavior mixins.
template <typename M> class NiceMockBase;
template <typename M> class NaggyMockBase;
template <typename M> class StrictMockBase;
// Protects the mock object registry (in class Mock), all function // Protects the mock object registry (in class Mock), all function
// mockers, and all expectations. // mockers, and all expectations.
// //
...@@ -147,14 +152,13 @@ class GTEST_API_ UntypedFunctionMockerBase { ...@@ -147,14 +152,13 @@ class GTEST_API_ UntypedFunctionMockerBase {
// action fails. // action fails.
// L = * // L = *
virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
const void* untyped_args, const std::string& call_description) const = 0; void* untyped_args, const std::string& call_description) const = 0;
// Performs the given action with the given arguments and returns // Performs the given action with the given arguments and returns
// the action's result. // the action's result.
// L = * // L = *
virtual UntypedActionResultHolderBase* UntypedPerformAction( virtual UntypedActionResultHolderBase* UntypedPerformAction(
const void* untyped_action, const void* untyped_action, void* untyped_args) const = 0;
const void* untyped_args) const = 0;
// Writes a message that the call is uninteresting (i.e. neither // Writes a message that the call is uninteresting (i.e. neither
// explicitly expected nor explicitly unexpected) to the given // explicitly expected nor explicitly unexpected) to the given
...@@ -209,9 +213,8 @@ class GTEST_API_ UntypedFunctionMockerBase { ...@@ -209,9 +213,8 @@ class GTEST_API_ UntypedFunctionMockerBase {
// arguments. This function can be safely called from multiple // arguments. This function can be safely called from multiple
// threads concurrently. The caller is responsible for deleting the // threads concurrently. The caller is responsible for deleting the
// result. // result.
UntypedActionResultHolderBase* UntypedInvokeWith( UntypedActionResultHolderBase* UntypedInvokeWith(void* untyped_args)
const void* untyped_args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
protected: protected:
typedef std::vector<const void*> UntypedOnCallSpecs; typedef std::vector<const void*> UntypedOnCallSpecs;
...@@ -236,6 +239,14 @@ class GTEST_API_ UntypedFunctionMockerBase { ...@@ -236,6 +239,14 @@ class GTEST_API_ UntypedFunctionMockerBase {
UntypedOnCallSpecs untyped_on_call_specs_; UntypedOnCallSpecs untyped_on_call_specs_;
// All expectations for this function mocker. // All expectations for this function mocker.
//
// It's undefined behavior to interleave expectations (EXPECT_CALLs
// or ON_CALLs) and mock function calls. Also, the order of
// expectations is important. Therefore it's a logic race condition
// to read/write untyped_expectations_ concurrently. In order for
// tools like tsan to catch concurrent read/write accesses to
// untyped_expectations, we deliberately leave accesses to it
// unprotected.
UntypedExpectations untyped_expectations_; UntypedExpectations untyped_expectations_;
}; // class UntypedFunctionMockerBase }; // class UntypedFunctionMockerBase
...@@ -397,13 +408,13 @@ class GTEST_API_ Mock { ...@@ -397,13 +408,13 @@ class GTEST_API_ Mock {
friend class internal::FunctionMockerBase; friend class internal::FunctionMockerBase;
template <typename M> template <typename M>
friend class NiceMock; friend class internal::NiceMockBase;
template <typename M> template <typename M>
friend class NaggyMock; friend class internal::NaggyMockBase;
template <typename M> template <typename M>
friend class StrictMock; friend class internal::StrictMockBase;
// Tells Google Mock to allow uninteresting calls on the given mock // Tells Google Mock to allow uninteresting calls on the given mock
// object. // object.
...@@ -1252,8 +1263,9 @@ class MockSpec { ...@@ -1252,8 +1263,9 @@ class MockSpec {
// Constructs a MockSpec object, given the function mocker object // Constructs a MockSpec object, given the function mocker object
// that the spec is associated with. // that the spec is associated with.
explicit MockSpec(internal::FunctionMockerBase<F>* function_mocker) MockSpec(internal::FunctionMockerBase<F>* function_mocker,
: function_mocker_(function_mocker) {} const ArgumentMatcherTuple& matchers)
: function_mocker_(function_mocker), matchers_(matchers) {}
// Adds a new default action spec to the function mocker and returns // Adds a new default action spec to the function mocker and returns
// the newly created spec. // the newly created spec.
...@@ -1279,10 +1291,6 @@ class MockSpec { ...@@ -1279,10 +1291,6 @@ class MockSpec {
template <typename Function> template <typename Function>
friend class internal::FunctionMocker; friend class internal::FunctionMocker;
void SetMatchers(const ArgumentMatcherTuple& matchers) {
matchers_ = matchers;
}
// The function mocker that owns this spec. // The function mocker that owns this spec.
internal::FunctionMockerBase<F>* const function_mocker_; internal::FunctionMockerBase<F>* const function_mocker_;
// The argument matchers specified in the spec. // The argument matchers specified in the spec.
...@@ -1390,19 +1398,20 @@ class ActionResultHolder : public UntypedActionResultHolderBase { ...@@ -1390,19 +1398,20 @@ class ActionResultHolder : public UntypedActionResultHolderBase {
template <typename F> template <typename F>
static ActionResultHolder* PerformDefaultAction( static ActionResultHolder* PerformDefaultAction(
const FunctionMockerBase<F>* func_mocker, const FunctionMockerBase<F>* func_mocker,
const typename Function<F>::ArgumentTuple& args, typename RvalueRef<typename Function<F>::ArgumentTuple>::type args,
const std::string& call_description) { const std::string& call_description) {
return new ActionResultHolder(Wrapper( return new ActionResultHolder(Wrapper(func_mocker->PerformDefaultAction(
func_mocker->PerformDefaultAction(args, call_description))); internal::move(args), call_description)));
} }
// Performs the given action and returns the result in a new-ed // Performs the given action and returns the result in a new-ed
// ActionResultHolder. // ActionResultHolder.
template <typename F> template <typename F>
static ActionResultHolder* static ActionResultHolder* PerformAction(
PerformAction(const Action<F>& action, const Action<F>& action,
const typename Function<F>::ArgumentTuple& args) { typename RvalueRef<typename Function<F>::ArgumentTuple>::type args) {
return new ActionResultHolder(Wrapper(action.Perform(args))); return new ActionResultHolder(
Wrapper(action.Perform(internal::move(args))));
} }
private: private:
...@@ -1430,9 +1439,9 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase { ...@@ -1430,9 +1439,9 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase {
template <typename F> template <typename F>
static ActionResultHolder* PerformDefaultAction( static ActionResultHolder* PerformDefaultAction(
const FunctionMockerBase<F>* func_mocker, const FunctionMockerBase<F>* func_mocker,
const typename Function<F>::ArgumentTuple& args, typename RvalueRef<typename Function<F>::ArgumentTuple>::type args,
const std::string& call_description) { const std::string& call_description) {
func_mocker->PerformDefaultAction(args, call_description); func_mocker->PerformDefaultAction(internal::move(args), call_description);
return new ActionResultHolder; return new ActionResultHolder;
} }
...@@ -1441,8 +1450,8 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase { ...@@ -1441,8 +1450,8 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase {
template <typename F> template <typename F>
static ActionResultHolder* PerformAction( static ActionResultHolder* PerformAction(
const Action<F>& action, const Action<F>& action,
const typename Function<F>::ArgumentTuple& args) { typename RvalueRef<typename Function<F>::ArgumentTuple>::type args) {
action.Perform(args); action.Perform(internal::move(args));
return new ActionResultHolder; return new ActionResultHolder;
} }
...@@ -1461,7 +1470,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1461,7 +1470,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
typedef typename Function<F>::ArgumentTuple ArgumentTuple; typedef typename Function<F>::ArgumentTuple ArgumentTuple;
typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
FunctionMockerBase() : current_spec_(this) {} FunctionMockerBase() {}
// The destructor verifies that all expectations on this mock // The destructor verifies that all expectations on this mock
// function have been satisfied. If not, it will report Google Test // function have been satisfied. If not, it will report Google Test
...@@ -1497,12 +1506,13 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1497,12 +1506,13 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
// mutable state of this object, and thus can be called concurrently // mutable state of this object, and thus can be called concurrently
// without locking. // without locking.
// L = * // L = *
Result PerformDefaultAction(const ArgumentTuple& args, Result PerformDefaultAction(
const std::string& call_description) const { typename RvalueRef<typename Function<F>::ArgumentTuple>::type args,
const std::string& call_description) const {
const OnCallSpec<F>* const spec = const OnCallSpec<F>* const spec =
this->FindOnCallSpec(args); this->FindOnCallSpec(args);
if (spec != NULL) { if (spec != NULL) {
return spec->GetAction().Perform(args); return spec->GetAction().Perform(internal::move(args));
} }
const std::string message = const std::string message =
call_description + call_description +
...@@ -1524,11 +1534,11 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1524,11 +1534,11 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
// action fails. The caller is responsible for deleting the result. // action fails. The caller is responsible for deleting the result.
// L = * // L = *
virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
const void* untyped_args, // must point to an ArgumentTuple void* untyped_args, // must point to an ArgumentTuple
const std::string& call_description) const { const std::string& call_description) const {
const ArgumentTuple& args = ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args);
*static_cast<const ArgumentTuple*>(untyped_args); return ResultHolder::PerformDefaultAction(this, internal::move(*args),
return ResultHolder::PerformDefaultAction(this, args, call_description); call_description);
} }
// Performs the given action with the given arguments and returns // Performs the given action with the given arguments and returns
...@@ -1536,13 +1546,12 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1536,13 +1546,12 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
// result. // result.
// L = * // L = *
virtual UntypedActionResultHolderBase* UntypedPerformAction( virtual UntypedActionResultHolderBase* UntypedPerformAction(
const void* untyped_action, const void* untyped_args) const { const void* untyped_action, void* untyped_args) const {
// Make a copy of the action before performing it, in case the // Make a copy of the action before performing it, in case the
// action deletes the mock object (and thus deletes itself). // action deletes the mock object (and thus deletes itself).
const Action<F> action = *static_cast<const Action<F>*>(untyped_action); const Action<F> action = *static_cast<const Action<F>*>(untyped_action);
const ArgumentTuple& args = ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args);
*static_cast<const ArgumentTuple*>(untyped_args); return ResultHolder::PerformAction(action, internal::move(*args));
return ResultHolder::PerformAction(action, args);
} }
// Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked(): // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked():
...@@ -1582,10 +1591,14 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1582,10 +1591,14 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
// Returns the result of invoking this mock function with the given // Returns the result of invoking this mock function with the given
// arguments. This function can be safely called from multiple // arguments. This function can be safely called from multiple
// threads concurrently. // threads concurrently.
Result InvokeWith(const ArgumentTuple& args) Result InvokeWith(
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { typename RvalueRef<typename Function<F>::ArgumentTuple>::type args)
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
// const_cast is required since in C++98 we still pass ArgumentTuple around
// by const& instead of rvalue reference.
void* untyped_args = const_cast<void*>(static_cast<const void*>(&args));
scoped_ptr<ResultHolder> holder( scoped_ptr<ResultHolder> holder(
DownCast_<ResultHolder*>(this->UntypedInvokeWith(&args))); DownCast_<ResultHolder*>(this->UntypedInvokeWith(untyped_args)));
return holder->Unwrap(); return holder->Unwrap();
} }
...@@ -1609,6 +1622,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1609,6 +1622,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
TypedExpectation<F>* const expectation = TypedExpectation<F>* const expectation =
new TypedExpectation<F>(this, file, line, source_text, m); new TypedExpectation<F>(this, file, line, source_text, m);
const linked_ptr<ExpectationBase> untyped_expectation(expectation); const linked_ptr<ExpectationBase> untyped_expectation(expectation);
// See the definition of untyped_expectations_ for why access to
// it is unprotected here.
untyped_expectations_.push_back(untyped_expectation); untyped_expectations_.push_back(untyped_expectation);
// Adds this expectation into the implicit sequence if there is one. // Adds this expectation into the implicit sequence if there is one.
...@@ -1620,10 +1635,6 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1620,10 +1635,6 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
return *expectation; return *expectation;
} }
// The current spec (either default action spec or expectation spec)
// being described on this function mocker.
MockSpec<F>& current_spec() { return current_spec_; }
private: private:
template <typename Func> friend class TypedExpectation; template <typename Func> friend class TypedExpectation;
...@@ -1716,6 +1727,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1716,6 +1727,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
const ArgumentTuple& args) const const ArgumentTuple& args) const
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
g_gmock_mutex.AssertHeld(); g_gmock_mutex.AssertHeld();
// See the definition of untyped_expectations_ for why access to
// it is unprotected here.
for (typename UntypedExpectations::const_reverse_iterator it = for (typename UntypedExpectations::const_reverse_iterator it =
untyped_expectations_.rbegin(); untyped_expectations_.rbegin();
it != untyped_expectations_.rend(); ++it) { it != untyped_expectations_.rend(); ++it) {
...@@ -1766,10 +1779,6 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1766,10 +1779,6 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
} }
} }
// The current spec (either default action spec or expectation spec)
// being described on this function mocker.
MockSpec<F> current_spec_;
// There is no generally useful and implementable semantics of // There is no generally useful and implementable semantics of
// copying a mock object, so copying a mock is usually a user error. // copying a mock object, so copying a mock is usually a user error.
// Thus we disallow copying function mockers. If the user really // Thus we disallow copying function mockers. If the user really
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <map> #include <map>
#include <set> #include <set>
#include <string> #include <string>
#include <vector>
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
...@@ -99,12 +100,19 @@ void ExpectationBase::RetireAllPreRequisites() ...@@ -99,12 +100,19 @@ void ExpectationBase::RetireAllPreRequisites()
return; return;
} }
for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin(); ::std::vector<ExpectationBase*> expectations(1, this);
it != immediate_prerequisites_.end(); ++it) { while (!expectations.empty()) {
ExpectationBase* const prerequisite = it->expectation_base().get(); ExpectationBase* exp = expectations.back();
if (!prerequisite->is_retired()) { expectations.pop_back();
prerequisite->RetireAllPreRequisites();
prerequisite->Retire(); for (ExpectationSet::const_iterator it =
exp->immediate_prerequisites_.begin();
it != exp->immediate_prerequisites_.end(); ++it) {
ExpectationBase* next = it->expectation_base().get();
if (!next->is_retired()) {
next->Retire();
expectations.push_back(next);
}
} }
} }
} }
...@@ -114,11 +122,18 @@ void ExpectationBase::RetireAllPreRequisites() ...@@ -114,11 +122,18 @@ void ExpectationBase::RetireAllPreRequisites()
bool ExpectationBase::AllPrerequisitesAreSatisfied() const bool ExpectationBase::AllPrerequisitesAreSatisfied() const
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
g_gmock_mutex.AssertHeld(); g_gmock_mutex.AssertHeld();
for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin(); ::std::vector<const ExpectationBase*> expectations(1, this);
it != immediate_prerequisites_.end(); ++it) { while (!expectations.empty()) {
if (!(it->expectation_base()->IsSatisfied()) || const ExpectationBase* exp = expectations.back();
!(it->expectation_base()->AllPrerequisitesAreSatisfied())) expectations.pop_back();
return false;
for (ExpectationSet::const_iterator it =
exp->immediate_prerequisites_.begin();
it != exp->immediate_prerequisites_.end(); ++it) {
const ExpectationBase* next = it->expectation_base().get();
if (!next->IsSatisfied()) return false;
expectations.push_back(next);
}
} }
return true; return true;
} }
...@@ -127,19 +142,28 @@ bool ExpectationBase::AllPrerequisitesAreSatisfied() const ...@@ -127,19 +142,28 @@ bool ExpectationBase::AllPrerequisitesAreSatisfied() const
void ExpectationBase::FindUnsatisfiedPrerequisites(ExpectationSet* result) const void ExpectationBase::FindUnsatisfiedPrerequisites(ExpectationSet* result) const
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
g_gmock_mutex.AssertHeld(); g_gmock_mutex.AssertHeld();
for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin(); ::std::vector<const ExpectationBase*> expectations(1, this);
it != immediate_prerequisites_.end(); ++it) { while (!expectations.empty()) {
if (it->expectation_base()->IsSatisfied()) { const ExpectationBase* exp = expectations.back();
// If *it is satisfied and has a call count of 0, some of its expectations.pop_back();
// pre-requisites may not be satisfied yet.
if (it->expectation_base()->call_count_ == 0) { for (ExpectationSet::const_iterator it =
it->expectation_base()->FindUnsatisfiedPrerequisites(result); exp->immediate_prerequisites_.begin();
it != exp->immediate_prerequisites_.end(); ++it) {
const ExpectationBase* next = it->expectation_base().get();
if (next->IsSatisfied()) {
// If *it is satisfied and has a call count of 0, some of its
// pre-requisites may not be satisfied yet.
if (next->call_count_ == 0) {
expectations.push_back(next);
}
} else {
// Now that we know next is unsatisfied, we are not so interested
// in whether its pre-requisites are satisfied. Therefore we
// don't iterate into it here.
*result += *it;
} }
} else {
// Now that we know *it is unsatisfied, we are not so interested
// in whether its pre-requisites are satisfied. Therefore we
// don't recursively call FindUnsatisfiedPrerequisites() here.
*result += *it;
} }
} }
} }
...@@ -254,11 +278,13 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) { ...@@ -254,11 +278,13 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) {
case kWarn: case kWarn:
Log(kWarning, Log(kWarning,
msg + msg +
"\nNOTE: You can safely ignore the above warning unless this " "\nNOTE: You can safely ignore the above warning unless this "
"call should not happen. Do not suppress it by blindly adding " "call should not happen. Do not suppress it by blindly adding "
"an EXPECT_CALL() if you don't mean to enforce the call. " "an EXPECT_CALL() if you don't mean to enforce the call. "
"See https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#" "See "
"knowing-when-to-expect for details.\n", "https://github.com/google/googletest/blob/master/googlemock/"
"docs/CookBook.md#"
"knowing-when-to-expect for details.\n",
stack_frames_to_skip); stack_frames_to_skip);
break; break;
default: // FAIL default: // FAIL
...@@ -334,9 +360,10 @@ const char* UntypedFunctionMockerBase::Name() const ...@@ -334,9 +360,10 @@ const char* UntypedFunctionMockerBase::Name() const
// Calculates the result of invoking this mock function with the given // Calculates the result of invoking this mock function with the given
// arguments, prints it, and returns it. The caller is responsible // arguments, prints it, and returns it. The caller is responsible
// for deleting the result. // for deleting the result.
UntypedActionResultHolderBase* UntypedActionResultHolderBase* UntypedFunctionMockerBase::UntypedInvokeWith(
UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args) void* const untyped_args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { // See the definition of untyped_expectations_ for why access to it
// is unprotected here.
if (untyped_expectations_.size() == 0) { if (untyped_expectations_.size() == 0) {
// No expectation is set on this mock method - we have an // No expectation is set on this mock method - we have an
// uninteresting call. // uninteresting call.
...@@ -355,16 +382,19 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args) ...@@ -355,16 +382,19 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
// If the user allows this uninteresting call, we print it // If the user allows this uninteresting call, we print it
// only when they want informational messages. // only when they want informational messages.
reaction == kAllow ? LogIsVisible(kInfo) : reaction == kAllow ? LogIsVisible(kInfo) :
// If the user wants this to be a warning, we print it only // If the user wants this to be a warning, we print
// when they want to see warnings. // it only when they want to see warnings.
reaction == kWarn ? LogIsVisible(kWarning) : reaction == kWarn
// Otherwise, the user wants this to be an error, and we ? LogIsVisible(kWarning)
// should always print detailed information in the error. :
true; // Otherwise, the user wants this to be an error, and we
// should always print detailed information in the error.
true;
if (!need_to_report_uninteresting_call) { if (!need_to_report_uninteresting_call) {
// Perform the action without printing the call information. // Perform the action without printing the call information.
return this->UntypedPerformDefaultAction(untyped_args, "Function call: " + std::string(Name())); return this->UntypedPerformDefaultAction(
untyped_args, "Function call: " + std::string(Name()));
} }
// Warns about the uninteresting call. // Warns about the uninteresting call.
...@@ -446,6 +476,8 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args) ...@@ -446,6 +476,8 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
// Returns an Expectation object that references and co-owns exp, // Returns an Expectation object that references and co-owns exp,
// which must be an expectation on this mock function. // which must be an expectation on this mock function.
Expectation UntypedFunctionMockerBase::GetHandleOf(ExpectationBase* exp) { Expectation UntypedFunctionMockerBase::GetHandleOf(ExpectationBase* exp) {
// See the definition of untyped_expectations_ for why access to it
// is unprotected here.
for (UntypedExpectations::const_iterator it = for (UntypedExpectations::const_iterator it =
untyped_expectations_.begin(); untyped_expectations_.begin();
it != untyped_expectations_.end(); ++it) { it != untyped_expectations_.end(); ++it) {
...@@ -508,7 +540,7 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked() ...@@ -508,7 +540,7 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()
return expectations_met; return expectations_met;
} }
static CallReaction intToCallReaction(int mock_behavior) { CallReaction intToCallReaction(int mock_behavior) {
if (mock_behavior >= kAllow && mock_behavior <= kFail) { if (mock_behavior >= kAllow && mock_behavior <= kFail) {
return static_cast<internal::CallReaction>(mock_behavior); return static_cast<internal::CallReaction>(mock_behavior);
} }
...@@ -582,9 +614,15 @@ class MockObjectRegistry { ...@@ -582,9 +614,15 @@ class MockObjectRegistry {
leaked_count++; leaked_count++;
} }
if (leaked_count > 0) { if (leaked_count > 0) {
std::cout << "\nERROR: " << leaked_count std::cout << "\nERROR: " << leaked_count << " leaked mock "
<< " leaked mock " << (leaked_count == 1 ? "object" : "objects") << (leaked_count == 1 ? "object" : "objects")
<< " found at program exit.\n"; << " found at program exit. Expectations on a mock object is "
"verified when the object is destructed. Leaking a mock "
"means that its expectations aren't verified, which is "
"usually a test bug. If you really intend to leak a mock, "
"you can suppress this error using "
"testing::Mock::AllowLeak(mock_object), or you may use a "
"fake or stub instead of a mock.\n";
std::cout.flush(); std::cout.flush();
::std::cerr.flush(); ::std::cerr.flush();
// RUN_ALL_TESTS() has already returned when this destructor is // RUN_ALL_TESTS() has already returned when this destructor is
......
...@@ -704,6 +704,7 @@ class MockClass { ...@@ -704,6 +704,7 @@ class MockClass {
MOCK_METHOD0(MakeUnique, std::unique_ptr<int>()); MOCK_METHOD0(MakeUnique, std::unique_ptr<int>());
MOCK_METHOD0(MakeUniqueBase, std::unique_ptr<Base>()); MOCK_METHOD0(MakeUniqueBase, std::unique_ptr<Base>());
MOCK_METHOD0(MakeVectorUnique, std::vector<std::unique_ptr<int>>()); MOCK_METHOD0(MakeVectorUnique, std::vector<std::unique_ptr<int>>());
MOCK_METHOD1(TakeUnique, int(std::unique_ptr<int>));
#endif #endif
private: private:
......
...@@ -698,11 +698,69 @@ TEST(MatcherCastTest, FromSameType) { ...@@ -698,11 +698,69 @@ TEST(MatcherCastTest, FromSameType) {
EXPECT_FALSE(m2.Matches(1)); EXPECT_FALSE(m2.Matches(1));
} }
// Tests that MatcherCast<T>(m) works when m is a value of the same type as the
// value type of the Matcher.
TEST(MatcherCastTest, FromAValue) {
Matcher<int> m = MatcherCast<int>(42);
EXPECT_TRUE(m.Matches(42));
EXPECT_FALSE(m.Matches(239));
}
// Tests that MatcherCast<T>(m) works when m is a value of the type implicitly
// convertible to the value type of the Matcher.
TEST(MatcherCastTest, FromAnImplicitlyConvertibleValue) {
const int kExpected = 'c';
Matcher<int> m = MatcherCast<int>('c');
EXPECT_TRUE(m.Matches(kExpected));
EXPECT_FALSE(m.Matches(kExpected + 1));
}
struct NonImplicitlyConstructibleTypeWithOperatorEq {
friend bool operator==(
const NonImplicitlyConstructibleTypeWithOperatorEq& /* ignored */,
int rhs) {
return 42 == rhs;
}
friend bool operator==(
int lhs,
const NonImplicitlyConstructibleTypeWithOperatorEq& /* ignored */) {
return lhs == 42;
}
};
// Tests that MatcherCast<T>(m) works when m is a neither a matcher nor
// implicitly convertible to the value type of the Matcher, but the value type
// of the matcher has operator==() overload accepting m.
TEST(MatcherCastTest, NonImplicitlyConstructibleTypeWithOperatorEq) {
Matcher<NonImplicitlyConstructibleTypeWithOperatorEq> m1 =
MatcherCast<NonImplicitlyConstructibleTypeWithOperatorEq>(42);
EXPECT_TRUE(m1.Matches(NonImplicitlyConstructibleTypeWithOperatorEq()));
Matcher<NonImplicitlyConstructibleTypeWithOperatorEq> m2 =
MatcherCast<NonImplicitlyConstructibleTypeWithOperatorEq>(239);
EXPECT_FALSE(m2.Matches(NonImplicitlyConstructibleTypeWithOperatorEq()));
// When updating the following lines please also change the comment to
// namespace convertible_from_any.
Matcher<int> m3 =
MatcherCast<int>(NonImplicitlyConstructibleTypeWithOperatorEq());
EXPECT_TRUE(m3.Matches(42));
EXPECT_FALSE(m3.Matches(239));
}
// The below ConvertibleFromAny struct is implicitly constructible from anything
// and when in the same namespace can interact with other tests. In particular,
// if it is in the same namespace as other tests and one removes
// NonImplicitlyConstructibleTypeWithOperatorEq::operator==(int lhs, ...);
// then the corresponding test still compiles (and it should not!) by implicitly
// converting NonImplicitlyConstructibleTypeWithOperatorEq to ConvertibleFromAny
// in m3.Matcher().
namespace convertible_from_any {
// Implicitly convertible from any type. // Implicitly convertible from any type.
struct ConvertibleFromAny { struct ConvertibleFromAny {
ConvertibleFromAny(int a_value) : value(a_value) {} ConvertibleFromAny(int a_value) : value(a_value) {}
template <typename T> template <typename T>
explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) { explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) {
ADD_FAILURE() << "Conversion constructor called"; ADD_FAILURE() << "Conversion constructor called";
} }
int value; int value;
...@@ -728,6 +786,7 @@ TEST(MatcherCastTest, FromConvertibleFromAny) { ...@@ -728,6 +786,7 @@ TEST(MatcherCastTest, FromConvertibleFromAny) {
EXPECT_TRUE(m.Matches(ConvertibleFromAny(1))); EXPECT_TRUE(m.Matches(ConvertibleFromAny(1)));
EXPECT_FALSE(m.Matches(ConvertibleFromAny(2))); EXPECT_FALSE(m.Matches(ConvertibleFromAny(2)));
} }
} // namespace convertible_from_any
struct IntReferenceWrapper { struct IntReferenceWrapper {
IntReferenceWrapper(const int& a_value) : value(&a_value) {} IntReferenceWrapper(const int& a_value) : value(&a_value) {}
...@@ -833,6 +892,7 @@ TEST(SafeMatcherCastTest, FromSameType) { ...@@ -833,6 +892,7 @@ TEST(SafeMatcherCastTest, FromSameType) {
EXPECT_FALSE(m2.Matches(1)); EXPECT_FALSE(m2.Matches(1));
} }
namespace convertible_from_any {
TEST(SafeMatcherCastTest, ConversionConstructorIsUsed) { TEST(SafeMatcherCastTest, ConversionConstructorIsUsed) {
Matcher<ConvertibleFromAny> m = SafeMatcherCast<ConvertibleFromAny>(1); Matcher<ConvertibleFromAny> m = SafeMatcherCast<ConvertibleFromAny>(1);
EXPECT_TRUE(m.Matches(ConvertibleFromAny(1))); EXPECT_TRUE(m.Matches(ConvertibleFromAny(1)));
...@@ -845,6 +905,7 @@ TEST(SafeMatcherCastTest, FromConvertibleFromAny) { ...@@ -845,6 +905,7 @@ TEST(SafeMatcherCastTest, FromConvertibleFromAny) {
EXPECT_TRUE(m.Matches(ConvertibleFromAny(1))); EXPECT_TRUE(m.Matches(ConvertibleFromAny(1)));
EXPECT_FALSE(m.Matches(ConvertibleFromAny(2))); EXPECT_FALSE(m.Matches(ConvertibleFromAny(2)));
} }
} // namespace convertible_from_any
TEST(SafeMatcherCastTest, ValueIsNotCopied) { TEST(SafeMatcherCastTest, ValueIsNotCopied) {
int n = 42; int n = 42;
...@@ -856,7 +917,7 @@ TEST(SafeMatcherCastTest, ValueIsNotCopied) { ...@@ -856,7 +917,7 @@ TEST(SafeMatcherCastTest, ValueIsNotCopied) {
TEST(ExpectThat, TakesLiterals) { TEST(ExpectThat, TakesLiterals) {
EXPECT_THAT(1, 1); EXPECT_THAT(1, 1);
EXPECT_THAT(1.0, 1.0); EXPECT_THAT(1.0, 1.0);
EXPECT_THAT(string(), ""); EXPECT_THAT(std::string(), "");
} }
TEST(ExpectThat, TakesFunctions) { TEST(ExpectThat, TakesFunctions) {
...@@ -956,15 +1017,11 @@ class Unprintable { ...@@ -956,15 +1017,11 @@ class Unprintable {
public: public:
Unprintable() : c_('a') {} Unprintable() : c_('a') {}
bool operator==(const Unprintable& /* rhs */) const { return true; }
private: private:
char c_; char c_;
}; };
inline bool operator==(const Unprintable& /* lhs */,
const Unprintable& /* rhs */) {
return true;
}
TEST(EqTest, CanDescribeSelf) { TEST(EqTest, CanDescribeSelf) {
Matcher<Unprintable> m = Eq(Unprintable()); Matcher<Unprintable> m = Eq(Unprintable());
EXPECT_EQ("is equal to 1-byte object <61>", Describe(m)); EXPECT_EQ("is equal to 1-byte object <61>", Describe(m));
...@@ -1135,14 +1192,14 @@ TEST(IsNullTest, ReferenceToConstLinkedPtr) { ...@@ -1135,14 +1192,14 @@ TEST(IsNullTest, ReferenceToConstLinkedPtr) {
EXPECT_FALSE(m.Matches(non_null_p)); EXPECT_FALSE(m.Matches(non_null_p));
} }
#if GTEST_HAS_STD_FUNCTION_ #if GTEST_LANG_CXX11
TEST(IsNullTest, StdFunction) { TEST(IsNullTest, StdFunction) {
const Matcher<std::function<void()>> m = IsNull(); const Matcher<std::function<void()>> m = IsNull();
EXPECT_TRUE(m.Matches(std::function<void()>())); EXPECT_TRUE(m.Matches(std::function<void()>()));
EXPECT_FALSE(m.Matches([]{})); EXPECT_FALSE(m.Matches([]{}));
} }
#endif // GTEST_HAS_STD_FUNCTION_ #endif // GTEST_LANG_CXX11
// Tests that IsNull() describes itself properly. // Tests that IsNull() describes itself properly.
TEST(IsNullTest, CanDescribeSelf) { TEST(IsNullTest, CanDescribeSelf) {
...@@ -1183,14 +1240,14 @@ TEST(NotNullTest, ReferenceToConstLinkedPtr) { ...@@ -1183,14 +1240,14 @@ TEST(NotNullTest, ReferenceToConstLinkedPtr) {
EXPECT_TRUE(m.Matches(non_null_p)); EXPECT_TRUE(m.Matches(non_null_p));
} }
#if GTEST_HAS_STD_FUNCTION_ #if GTEST_LANG_CXX11
TEST(NotNullTest, StdFunction) { TEST(NotNullTest, StdFunction) {
const Matcher<std::function<void()>> m = NotNull(); const Matcher<std::function<void()>> m = NotNull();
EXPECT_TRUE(m.Matches([]{})); EXPECT_TRUE(m.Matches([]{}));
EXPECT_FALSE(m.Matches(std::function<void()>())); EXPECT_FALSE(m.Matches(std::function<void()>()));
} }
#endif // GTEST_HAS_STD_FUNCTION_ #endif // GTEST_LANG_CXX11
// Tests that NotNull() describes itself properly. // Tests that NotNull() describes itself properly.
TEST(NotNullTest, CanDescribeSelf) { TEST(NotNullTest, CanDescribeSelf) {
...@@ -2249,6 +2306,150 @@ TEST(Ne2Test, CanDescribeSelf) { ...@@ -2249,6 +2306,150 @@ TEST(Ne2Test, CanDescribeSelf) {
EXPECT_EQ("are an unequal pair", Describe(m)); EXPECT_EQ("are an unequal pair", Describe(m));
} }
// Tests that FloatEq() matches a 2-tuple where
// FloatEq(first field) matches the second field.
TEST(FloatEq2Test, MatchesEqualArguments) {
typedef ::testing::tuple<float, float> Tpl;
Matcher<const Tpl&> m = FloatEq();
EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f)));
EXPECT_TRUE(m.Matches(Tpl(0.3f, 0.1f + 0.1f + 0.1f)));
EXPECT_FALSE(m.Matches(Tpl(1.1f, 1.0f)));
}
// Tests that FloatEq() describes itself properly.
TEST(FloatEq2Test, CanDescribeSelf) {
Matcher<const ::testing::tuple<float, float>&> m = FloatEq();
EXPECT_EQ("are an almost-equal pair", Describe(m));
}
// Tests that NanSensitiveFloatEq() matches a 2-tuple where
// NanSensitiveFloatEq(first field) matches the second field.
TEST(NanSensitiveFloatEqTest, MatchesEqualArgumentsWithNaN) {
typedef ::testing::tuple<float, float> Tpl;
Matcher<const Tpl&> m = NanSensitiveFloatEq();
EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f)));
EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits<float>::quiet_NaN(),
std::numeric_limits<float>::quiet_NaN())));
EXPECT_FALSE(m.Matches(Tpl(1.1f, 1.0f)));
EXPECT_FALSE(m.Matches(Tpl(1.0f, std::numeric_limits<float>::quiet_NaN())));
EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits<float>::quiet_NaN(), 1.0f)));
}
// Tests that NanSensitiveFloatEq() describes itself properly.
TEST(NanSensitiveFloatEqTest, CanDescribeSelfWithNaNs) {
Matcher<const ::testing::tuple<float, float>&> m = NanSensitiveFloatEq();
EXPECT_EQ("are an almost-equal pair", Describe(m));
}
// Tests that DoubleEq() matches a 2-tuple where
// DoubleEq(first field) matches the second field.
TEST(DoubleEq2Test, MatchesEqualArguments) {
typedef ::testing::tuple<double, double> Tpl;
Matcher<const Tpl&> m = DoubleEq();
EXPECT_TRUE(m.Matches(Tpl(1.0, 1.0)));
EXPECT_TRUE(m.Matches(Tpl(0.3, 0.1 + 0.1 + 0.1)));
EXPECT_FALSE(m.Matches(Tpl(1.1, 1.0)));
}
// Tests that DoubleEq() describes itself properly.
TEST(DoubleEq2Test, CanDescribeSelf) {
Matcher<const ::testing::tuple<double, double>&> m = DoubleEq();
EXPECT_EQ("are an almost-equal pair", Describe(m));
}
// Tests that NanSensitiveDoubleEq() matches a 2-tuple where
// NanSensitiveDoubleEq(first field) matches the second field.
TEST(NanSensitiveDoubleEqTest, MatchesEqualArgumentsWithNaN) {
typedef ::testing::tuple<double, double> Tpl;
Matcher<const Tpl&> m = NanSensitiveDoubleEq();
EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f)));
EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits<double>::quiet_NaN(),
std::numeric_limits<double>::quiet_NaN())));
EXPECT_FALSE(m.Matches(Tpl(1.1f, 1.0f)));
EXPECT_FALSE(m.Matches(Tpl(1.0f, std::numeric_limits<double>::quiet_NaN())));
EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits<double>::quiet_NaN(), 1.0f)));
}
// Tests that DoubleEq() describes itself properly.
TEST(NanSensitiveDoubleEqTest, CanDescribeSelfWithNaNs) {
Matcher<const ::testing::tuple<double, double>&> m = NanSensitiveDoubleEq();
EXPECT_EQ("are an almost-equal pair", Describe(m));
}
// Tests that FloatEq() matches a 2-tuple where
// FloatNear(first field, max_abs_error) matches the second field.
TEST(FloatNear2Test, MatchesEqualArguments) {
typedef ::testing::tuple<float, float> Tpl;
Matcher<const Tpl&> m = FloatNear(0.5f);
EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f)));
EXPECT_TRUE(m.Matches(Tpl(1.3f, 1.0f)));
EXPECT_FALSE(m.Matches(Tpl(1.8f, 1.0f)));
}
// Tests that FloatNear() describes itself properly.
TEST(FloatNear2Test, CanDescribeSelf) {
Matcher<const ::testing::tuple<float, float>&> m = FloatNear(0.5f);
EXPECT_EQ("are an almost-equal pair", Describe(m));
}
// Tests that NanSensitiveFloatNear() matches a 2-tuple where
// NanSensitiveFloatNear(first field) matches the second field.
TEST(NanSensitiveFloatNearTest, MatchesNearbyArgumentsWithNaN) {
typedef ::testing::tuple<float, float> Tpl;
Matcher<const Tpl&> m = NanSensitiveFloatNear(0.5f);
EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f)));
EXPECT_TRUE(m.Matches(Tpl(1.1f, 1.0f)));
EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits<float>::quiet_NaN(),
std::numeric_limits<float>::quiet_NaN())));
EXPECT_FALSE(m.Matches(Tpl(1.6f, 1.0f)));
EXPECT_FALSE(m.Matches(Tpl(1.0f, std::numeric_limits<float>::quiet_NaN())));
EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits<float>::quiet_NaN(), 1.0f)));
}
// Tests that NanSensitiveFloatNear() describes itself properly.
TEST(NanSensitiveFloatNearTest, CanDescribeSelfWithNaNs) {
Matcher<const ::testing::tuple<float, float>&> m =
NanSensitiveFloatNear(0.5f);
EXPECT_EQ("are an almost-equal pair", Describe(m));
}
// Tests that FloatEq() matches a 2-tuple where
// DoubleNear(first field, max_abs_error) matches the second field.
TEST(DoubleNear2Test, MatchesEqualArguments) {
typedef ::testing::tuple<double, double> Tpl;
Matcher<const Tpl&> m = DoubleNear(0.5);
EXPECT_TRUE(m.Matches(Tpl(1.0, 1.0)));
EXPECT_TRUE(m.Matches(Tpl(1.3, 1.0)));
EXPECT_FALSE(m.Matches(Tpl(1.8, 1.0)));
}
// Tests that DoubleNear() describes itself properly.
TEST(DoubleNear2Test, CanDescribeSelf) {
Matcher<const ::testing::tuple<double, double>&> m = DoubleNear(0.5);
EXPECT_EQ("are an almost-equal pair", Describe(m));
}
// Tests that NanSensitiveDoubleNear() matches a 2-tuple where
// NanSensitiveDoubleNear(first field) matches the second field.
TEST(NanSensitiveDoubleNearTest, MatchesNearbyArgumentsWithNaN) {
typedef ::testing::tuple<double, double> Tpl;
Matcher<const Tpl&> m = NanSensitiveDoubleNear(0.5f);
EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f)));
EXPECT_TRUE(m.Matches(Tpl(1.1f, 1.0f)));
EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits<double>::quiet_NaN(),
std::numeric_limits<double>::quiet_NaN())));
EXPECT_FALSE(m.Matches(Tpl(1.6f, 1.0f)));
EXPECT_FALSE(m.Matches(Tpl(1.0f, std::numeric_limits<double>::quiet_NaN())));
EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits<double>::quiet_NaN(), 1.0f)));
}
// Tests that NanSensitiveDoubleNear() describes itself properly.
TEST(NanSensitiveDoubleNearTest, CanDescribeSelfWithNaNs) {
Matcher<const ::testing::tuple<double, double>&> m =
NanSensitiveDoubleNear(0.5f);
EXPECT_EQ("are an almost-equal pair", Describe(m));
}
// Tests that Not(m) matches any value that doesn't match m. // Tests that Not(m) matches any value that doesn't match m.
TEST(NotTest, NegatesMatcher) { TEST(NotTest, NegatesMatcher) {
Matcher<int> m; Matcher<int> m;
...@@ -2814,6 +3015,22 @@ TEST(ExplainMatchResultTest, WorksInsideMATCHER) { ...@@ -2814,6 +3015,22 @@ TEST(ExplainMatchResultTest, WorksInsideMATCHER) {
EXPECT_THAT(0, Really(Eq(0))); EXPECT_THAT(0, Really(Eq(0)));
} }
TEST(DescribeMatcherTest, WorksWithValue) {
EXPECT_EQ("is equal to 42", DescribeMatcher<int>(42));
EXPECT_EQ("isn't equal to 42", DescribeMatcher<int>(42, true));
}
TEST(DescribeMatcherTest, WorksWithMonomorphicMatcher) {
const Matcher<int> monomorphic = Le(0);
EXPECT_EQ("is <= 0", DescribeMatcher<int>(monomorphic));
EXPECT_EQ("isn't <= 0", DescribeMatcher<int>(monomorphic, true));
}
TEST(DescribeMatcherTest, WorksWithPolymorphicMatcher) {
EXPECT_EQ("is even", DescribeMatcher<int>(PolymorphicIsEven()));
EXPECT_EQ("is odd", DescribeMatcher<int>(PolymorphicIsEven(), true));
}
TEST(AllArgsTest, WorksForTuple) { TEST(AllArgsTest, WorksForTuple) {
EXPECT_THAT(make_tuple(1, 2L), AllArgs(Lt())); EXPECT_THAT(make_tuple(1, 2L), AllArgs(Lt()));
EXPECT_THAT(make_tuple(2L, 1), Not(AllArgs(Lt()))); EXPECT_THAT(make_tuple(2L, 1), Not(AllArgs(Lt())));
...@@ -2943,18 +3160,22 @@ class FloatingPointTest : public testing::Test { ...@@ -2943,18 +3160,22 @@ class FloatingPointTest : public testing::Test {
zero_bits_(Floating(0).bits()), zero_bits_(Floating(0).bits()),
one_bits_(Floating(1).bits()), one_bits_(Floating(1).bits()),
infinity_bits_(Floating(Floating::Infinity()).bits()), infinity_bits_(Floating(Floating::Infinity()).bits()),
close_to_positive_zero_(AsBits(zero_bits_ + max_ulps_/2)), close_to_positive_zero_(
close_to_negative_zero_(AsBits(zero_bits_ + max_ulps_ - max_ulps_/2)), Floating::ReinterpretBits(zero_bits_ + max_ulps_/2)),
further_from_negative_zero_(-AsBits( close_to_negative_zero_(
-Floating::ReinterpretBits(zero_bits_ + max_ulps_ - max_ulps_/2)),
further_from_negative_zero_(-Floating::ReinterpretBits(
zero_bits_ + max_ulps_ + 1 - max_ulps_/2)), zero_bits_ + max_ulps_ + 1 - max_ulps_/2)),
close_to_one_(AsBits(one_bits_ + max_ulps_)), close_to_one_(Floating::ReinterpretBits(one_bits_ + max_ulps_)),
further_from_one_(AsBits(one_bits_ + max_ulps_ + 1)), further_from_one_(Floating::ReinterpretBits(one_bits_ + max_ulps_ + 1)),
infinity_(Floating::Infinity()), infinity_(Floating::Infinity()),
close_to_infinity_(AsBits(infinity_bits_ - max_ulps_)), close_to_infinity_(
further_from_infinity_(AsBits(infinity_bits_ - max_ulps_ - 1)), Floating::ReinterpretBits(infinity_bits_ - max_ulps_)),
further_from_infinity_(
Floating::ReinterpretBits(infinity_bits_ - max_ulps_ - 1)),
max_(Floating::Max()), max_(Floating::Max()),
nan1_(AsBits(Floating::kExponentBitMask | 1)), nan1_(Floating::ReinterpretBits(Floating::kExponentBitMask | 1)),
nan2_(AsBits(Floating::kExponentBitMask | 200)) { nan2_(Floating::ReinterpretBits(Floating::kExponentBitMask | 200)) {
} }
void TestSize() { void TestSize() {
...@@ -3009,7 +3230,7 @@ class FloatingPointTest : public testing::Test { ...@@ -3009,7 +3230,7 @@ class FloatingPointTest : public testing::Test {
// Pre-calculated numbers to be used by the tests. // Pre-calculated numbers to be used by the tests.
const size_t max_ulps_; const Bits max_ulps_;
const Bits zero_bits_; // The bits that represent 0.0. const Bits zero_bits_; // The bits that represent 0.0.
const Bits one_bits_; // The bits that represent 1.0. const Bits one_bits_; // The bits that represent 1.0.
...@@ -3035,12 +3256,6 @@ class FloatingPointTest : public testing::Test { ...@@ -3035,12 +3256,6 @@ class FloatingPointTest : public testing::Test {
// Some NaNs. // Some NaNs.
const RawType nan1_; const RawType nan1_;
const RawType nan2_; const RawType nan2_;
private:
template <typename T>
static RawType AsBits(T value) {
return Floating::ReinterpretBits(static_cast<Bits>(value));
}
}; };
// Tests floating-point matchers with fixed epsilons. // Tests floating-point matchers with fixed epsilons.
...@@ -3417,8 +3632,6 @@ MATCHER_P(FieldIIs, inner_matcher, "") { ...@@ -3417,8 +3632,6 @@ MATCHER_P(FieldIIs, inner_matcher, "") {
return ExplainMatchResult(inner_matcher, arg.i, result_listener); return ExplainMatchResult(inner_matcher, arg.i, result_listener);
} }
#if GTEST_HAS_RTTI
TEST(WhenDynamicCastToTest, SameType) { TEST(WhenDynamicCastToTest, SameType) {
Derived derived; Derived derived;
derived.i = 4; derived.i = 4;
...@@ -3476,8 +3689,12 @@ TEST(WhenDynamicCastToTest, AmbiguousCast) { ...@@ -3476,8 +3689,12 @@ TEST(WhenDynamicCastToTest, AmbiguousCast) {
TEST(WhenDynamicCastToTest, Describe) { TEST(WhenDynamicCastToTest, Describe) {
Matcher<Base*> matcher = WhenDynamicCastTo<Derived*>(Pointee(_)); Matcher<Base*> matcher = WhenDynamicCastTo<Derived*>(Pointee(_));
const string prefix = #if GTEST_HAS_RTTI
const std::string prefix =
"when dynamic_cast to " + internal::GetTypeName<Derived*>() + ", "; "when dynamic_cast to " + internal::GetTypeName<Derived*>() + ", ";
#else // GTEST_HAS_RTTI
const std::string prefix = "when dynamic_cast, ";
#endif // GTEST_HAS_RTTI
EXPECT_EQ(prefix + "points to a value that is anything", Describe(matcher)); EXPECT_EQ(prefix + "points to a value that is anything", Describe(matcher));
EXPECT_EQ(prefix + "does not point to a value that is anything", EXPECT_EQ(prefix + "does not point to a value that is anything",
DescribeNegation(matcher)); DescribeNegation(matcher));
...@@ -3511,8 +3728,6 @@ TEST(WhenDynamicCastToTest, BadReference) { ...@@ -3511,8 +3728,6 @@ TEST(WhenDynamicCastToTest, BadReference) {
EXPECT_THAT(as_base_ref, Not(WhenDynamicCastTo<const OtherDerived&>(_))); EXPECT_THAT(as_base_ref, Not(WhenDynamicCastTo<const OtherDerived&>(_)));
} }
#endif // GTEST_HAS_RTTI
// Minimal const-propagating pointer. // Minimal const-propagating pointer.
template <typename T> template <typename T>
class ConstPropagatingPtr { class ConstPropagatingPtr {
...@@ -3632,11 +3847,14 @@ struct DerivedStruct : public AStruct { ...@@ -3632,11 +3847,14 @@ struct DerivedStruct : public AStruct {
// Tests that Field(&Foo::field, ...) works when field is non-const. // Tests that Field(&Foo::field, ...) works when field is non-const.
TEST(FieldTest, WorksForNonConstField) { TEST(FieldTest, WorksForNonConstField) {
Matcher<AStruct> m = Field(&AStruct::x, Ge(0)); Matcher<AStruct> m = Field(&AStruct::x, Ge(0));
Matcher<AStruct> m_with_name = Field("x", &AStruct::x, Ge(0));
AStruct a; AStruct a;
EXPECT_TRUE(m.Matches(a)); EXPECT_TRUE(m.Matches(a));
EXPECT_TRUE(m_with_name.Matches(a));
a.x = -1; a.x = -1;
EXPECT_FALSE(m.Matches(a)); EXPECT_FALSE(m.Matches(a));
EXPECT_FALSE(m_with_name.Matches(a));
} }
// Tests that Field(&Foo::field, ...) works when field is const. // Tests that Field(&Foo::field, ...) works when field is const.
...@@ -3644,9 +3862,13 @@ TEST(FieldTest, WorksForConstField) { ...@@ -3644,9 +3862,13 @@ TEST(FieldTest, WorksForConstField) {
AStruct a; AStruct a;
Matcher<AStruct> m = Field(&AStruct::y, Ge(0.0)); Matcher<AStruct> m = Field(&AStruct::y, Ge(0.0));
Matcher<AStruct> m_with_name = Field("y", &AStruct::y, Ge(0.0));
EXPECT_TRUE(m.Matches(a)); EXPECT_TRUE(m.Matches(a));
EXPECT_TRUE(m_with_name.Matches(a));
m = Field(&AStruct::y, Le(0.0)); m = Field(&AStruct::y, Le(0.0));
m_with_name = Field("y", &AStruct::y, Le(0.0));
EXPECT_FALSE(m.Matches(a)); EXPECT_FALSE(m.Matches(a));
EXPECT_FALSE(m_with_name.Matches(a));
} }
// Tests that Field(&Foo::field, ...) works when field is not copyable. // Tests that Field(&Foo::field, ...) works when field is not copyable.
...@@ -3720,6 +3942,14 @@ TEST(FieldTest, CanDescribeSelf) { ...@@ -3720,6 +3942,14 @@ TEST(FieldTest, CanDescribeSelf) {
EXPECT_EQ("is an object whose given field isn't >= 0", DescribeNegation(m)); EXPECT_EQ("is an object whose given field isn't >= 0", DescribeNegation(m));
} }
TEST(FieldTest, CanDescribeSelfWithFieldName) {
Matcher<const AStruct&> m = Field("field_name", &AStruct::x, Ge(0));
EXPECT_EQ("is an object whose field `field_name` is >= 0", Describe(m));
EXPECT_EQ("is an object whose field `field_name` isn't >= 0",
DescribeNegation(m));
}
// Tests that Field() can explain the match result. // Tests that Field() can explain the match result.
TEST(FieldTest, CanExplainMatchResult) { TEST(FieldTest, CanExplainMatchResult) {
Matcher<const AStruct&> m = Field(&AStruct::x, Ge(0)); Matcher<const AStruct&> m = Field(&AStruct::x, Ge(0));
...@@ -3734,6 +3964,19 @@ TEST(FieldTest, CanExplainMatchResult) { ...@@ -3734,6 +3964,19 @@ TEST(FieldTest, CanExplainMatchResult) {
Explain(m, a)); Explain(m, a));
} }
TEST(FieldTest, CanExplainMatchResultWithFieldName) {
Matcher<const AStruct&> m = Field("field_name", &AStruct::x, Ge(0));
AStruct a;
a.x = 1;
EXPECT_EQ("whose field `field_name` is 1" + OfType("int"), Explain(m, a));
m = Field("field_name", &AStruct::x, GreaterThan(0));
EXPECT_EQ("whose field `field_name` is 1" + OfType("int") +
", which is 1 more than 0",
Explain(m, a));
}
// Tests that Field() works when the argument is a pointer to const. // Tests that Field() works when the argument is a pointer to const.
TEST(FieldForPointerTest, WorksForPointerToConst) { TEST(FieldForPointerTest, WorksForPointerToConst) {
Matcher<const AStruct*> m = Field(&AStruct::x, Ge(0)); Matcher<const AStruct*> m = Field(&AStruct::x, Ge(0));
...@@ -3791,6 +4034,14 @@ TEST(FieldForPointerTest, CanDescribeSelf) { ...@@ -3791,6 +4034,14 @@ TEST(FieldForPointerTest, CanDescribeSelf) {
EXPECT_EQ("is an object whose given field isn't >= 0", DescribeNegation(m)); EXPECT_EQ("is an object whose given field isn't >= 0", DescribeNegation(m));
} }
TEST(FieldForPointerTest, CanDescribeSelfWithFieldName) {
Matcher<const AStruct*> m = Field("field_name", &AStruct::x, Ge(0));
EXPECT_EQ("is an object whose field `field_name` is >= 0", Describe(m));
EXPECT_EQ("is an object whose field `field_name` isn't >= 0",
DescribeNegation(m));
}
// Tests that Field() can explain the result of matching a pointer. // Tests that Field() can explain the result of matching a pointer.
TEST(FieldForPointerTest, CanExplainMatchResult) { TEST(FieldForPointerTest, CanExplainMatchResult) {
Matcher<const AStruct*> m = Field(&AStruct::x, Ge(0)); Matcher<const AStruct*> m = Field(&AStruct::x, Ge(0));
...@@ -3806,6 +4057,22 @@ TEST(FieldForPointerTest, CanExplainMatchResult) { ...@@ -3806,6 +4057,22 @@ TEST(FieldForPointerTest, CanExplainMatchResult) {
", which is 1 more than 0", Explain(m, &a)); ", which is 1 more than 0", Explain(m, &a));
} }
TEST(FieldForPointerTest, CanExplainMatchResultWithFieldName) {
Matcher<const AStruct*> m = Field("field_name", &AStruct::x, Ge(0));
AStruct a;
a.x = 1;
EXPECT_EQ("", Explain(m, static_cast<const AStruct*>(NULL)));
EXPECT_EQ(
"which points to an object whose field `field_name` is 1" + OfType("int"),
Explain(m, &a));
m = Field("field_name", &AStruct::x, GreaterThan(0));
EXPECT_EQ("which points to an object whose field `field_name` is 1" +
OfType("int") + ", which is 1 more than 0",
Explain(m, &a));
}
// A user-defined class for testing Property(). // A user-defined class for testing Property().
class AClass { class AClass {
public: public:
...@@ -3849,26 +4116,33 @@ class DerivedClass : public AClass { ...@@ -3849,26 +4116,33 @@ class DerivedClass : public AClass {
// returns a non-reference. // returns a non-reference.
TEST(PropertyTest, WorksForNonReferenceProperty) { TEST(PropertyTest, WorksForNonReferenceProperty) {
Matcher<const AClass&> m = Property(&AClass::n, Ge(0)); Matcher<const AClass&> m = Property(&AClass::n, Ge(0));
Matcher<const AClass&> m_with_name = Property("n", &AClass::n, Ge(0));
AClass a; AClass a;
a.set_n(1); a.set_n(1);
EXPECT_TRUE(m.Matches(a)); EXPECT_TRUE(m.Matches(a));
EXPECT_TRUE(m_with_name.Matches(a));
a.set_n(-1); a.set_n(-1);
EXPECT_FALSE(m.Matches(a)); EXPECT_FALSE(m.Matches(a));
EXPECT_FALSE(m_with_name.Matches(a));
} }
// Tests that Property(&Foo::property, ...) works when property() // Tests that Property(&Foo::property, ...) works when property()
// returns a reference to const. // returns a reference to const.
TEST(PropertyTest, WorksForReferenceToConstProperty) { TEST(PropertyTest, WorksForReferenceToConstProperty) {
Matcher<const AClass&> m = Property(&AClass::s, StartsWith("hi")); Matcher<const AClass&> m = Property(&AClass::s, StartsWith("hi"));
Matcher<const AClass&> m_with_name =
Property("s", &AClass::s, StartsWith("hi"));
AClass a; AClass a;
a.set_s("hill"); a.set_s("hill");
EXPECT_TRUE(m.Matches(a)); EXPECT_TRUE(m.Matches(a));
EXPECT_TRUE(m_with_name.Matches(a));
a.set_s("hole"); a.set_s("hole");
EXPECT_FALSE(m.Matches(a)); EXPECT_FALSE(m.Matches(a));
EXPECT_FALSE(m_with_name.Matches(a));
} }
#if GTEST_LANG_CXX11 #if GTEST_LANG_CXX11
...@@ -3934,10 +4208,15 @@ TEST(PropertyTest, WorksForCompatibleMatcherType) { ...@@ -3934,10 +4208,15 @@ TEST(PropertyTest, WorksForCompatibleMatcherType) {
Matcher<const AClass&> m = Property(&AClass::n, Matcher<const AClass&> m = Property(&AClass::n,
Matcher<signed char>(Ge(0))); Matcher<signed char>(Ge(0)));
Matcher<const AClass&> m_with_name =
Property("n", &AClass::n, Matcher<signed char>(Ge(0)));
AClass a; AClass a;
EXPECT_TRUE(m.Matches(a)); EXPECT_TRUE(m.Matches(a));
EXPECT_TRUE(m_with_name.Matches(a));
a.set_n(-1); a.set_n(-1);
EXPECT_FALSE(m.Matches(a)); EXPECT_FALSE(m.Matches(a));
EXPECT_FALSE(m_with_name.Matches(a));
} }
// Tests that Property() can describe itself. // Tests that Property() can describe itself.
...@@ -3949,6 +4228,14 @@ TEST(PropertyTest, CanDescribeSelf) { ...@@ -3949,6 +4228,14 @@ TEST(PropertyTest, CanDescribeSelf) {
DescribeNegation(m)); DescribeNegation(m));
} }
TEST(PropertyTest, CanDescribeSelfWithPropertyName) {
Matcher<const AClass&> m = Property("fancy_name", &AClass::n, Ge(0));
EXPECT_EQ("is an object whose property `fancy_name` is >= 0", Describe(m));
EXPECT_EQ("is an object whose property `fancy_name` isn't >= 0",
DescribeNegation(m));
}
// Tests that Property() can explain the match result. // Tests that Property() can explain the match result.
TEST(PropertyTest, CanExplainMatchResult) { TEST(PropertyTest, CanExplainMatchResult) {
Matcher<const AClass&> m = Property(&AClass::n, Ge(0)); Matcher<const AClass&> m = Property(&AClass::n, Ge(0));
...@@ -3963,6 +4250,19 @@ TEST(PropertyTest, CanExplainMatchResult) { ...@@ -3963,6 +4250,19 @@ TEST(PropertyTest, CanExplainMatchResult) {
Explain(m, a)); Explain(m, a));
} }
TEST(PropertyTest, CanExplainMatchResultWithPropertyName) {
Matcher<const AClass&> m = Property("fancy_name", &AClass::n, Ge(0));
AClass a;
a.set_n(1);
EXPECT_EQ("whose property `fancy_name` is 1" + OfType("int"), Explain(m, a));
m = Property("fancy_name", &AClass::n, GreaterThan(0));
EXPECT_EQ("whose property `fancy_name` is 1" + OfType("int") +
", which is 1 more than 0",
Explain(m, a));
}
// Tests that Property() works when the argument is a pointer to const. // Tests that Property() works when the argument is a pointer to const.
TEST(PropertyForPointerTest, WorksForPointerToConst) { TEST(PropertyForPointerTest, WorksForPointerToConst) {
Matcher<const AClass*> m = Property(&AClass::n, Ge(0)); Matcher<const AClass*> m = Property(&AClass::n, Ge(0));
...@@ -4030,6 +4330,14 @@ TEST(PropertyForPointerTest, CanDescribeSelf) { ...@@ -4030,6 +4330,14 @@ TEST(PropertyForPointerTest, CanDescribeSelf) {
DescribeNegation(m)); DescribeNegation(m));
} }
TEST(PropertyForPointerTest, CanDescribeSelfWithPropertyDescription) {
Matcher<const AClass*> m = Property("fancy_name", &AClass::n, Ge(0));
EXPECT_EQ("is an object whose property `fancy_name` is >= 0", Describe(m));
EXPECT_EQ("is an object whose property `fancy_name` isn't >= 0",
DescribeNegation(m));
}
// Tests that Property() can explain the result of matching a pointer. // Tests that Property() can explain the result of matching a pointer.
TEST(PropertyForPointerTest, CanExplainMatchResult) { TEST(PropertyForPointerTest, CanExplainMatchResult) {
Matcher<const AClass*> m = Property(&AClass::n, Ge(0)); Matcher<const AClass*> m = Property(&AClass::n, Ge(0));
...@@ -4047,6 +4355,22 @@ TEST(PropertyForPointerTest, CanExplainMatchResult) { ...@@ -4047,6 +4355,22 @@ TEST(PropertyForPointerTest, CanExplainMatchResult) {
Explain(m, &a)); Explain(m, &a));
} }
TEST(PropertyForPointerTest, CanExplainMatchResultWithPropertyName) {
Matcher<const AClass*> m = Property("fancy_name", &AClass::n, Ge(0));
AClass a;
a.set_n(1);
EXPECT_EQ("", Explain(m, static_cast<const AClass*>(NULL)));
EXPECT_EQ("which points to an object whose property `fancy_name` is 1" +
OfType("int"),
Explain(m, &a));
m = Property("fancy_name", &AClass::n, GreaterThan(0));
EXPECT_EQ("which points to an object whose property `fancy_name` is 1" +
OfType("int") + ", which is 1 more than 0",
Explain(m, &a));
}
// Tests ResultOf. // Tests ResultOf.
// Tests that ResultOf(f, ...) compiles and works as expected when f is a // Tests that ResultOf(f, ...) compiles and works as expected when f is a
...@@ -4162,11 +4486,8 @@ TEST(ResultOfTest, WorksForFunctionReferences) { ...@@ -4162,11 +4486,8 @@ TEST(ResultOfTest, WorksForFunctionReferences) {
// Tests that ResultOf(f, ...) compiles and works as expected when f is a // Tests that ResultOf(f, ...) compiles and works as expected when f is a
// function object. // function object.
struct Functor { struct Functor : public ::std::unary_function<int, std::string> {
typedef std::string result_type; result_type operator()(argument_type input) const {
typedef int argument_type;
std::string operator()(int input) const {
return IntToStringFunction(input); return IntToStringFunction(input);
} }
}; };
...@@ -4360,6 +4681,44 @@ TEST(IsEmptyTest, ExplainsResult) { ...@@ -4360,6 +4681,44 @@ TEST(IsEmptyTest, ExplainsResult) {
EXPECT_EQ("whose size is 1", Explain(m, container)); EXPECT_EQ("whose size is 1", Explain(m, container));
} }
TEST(IsTrueTest, IsTrueIsFalse) {
EXPECT_THAT(true, IsTrue());
EXPECT_THAT(false, IsFalse());
EXPECT_THAT(true, Not(IsFalse()));
EXPECT_THAT(false, Not(IsTrue()));
EXPECT_THAT(0, Not(IsTrue()));
EXPECT_THAT(0, IsFalse());
EXPECT_THAT(NULL, Not(IsTrue()));
EXPECT_THAT(NULL, IsFalse());
EXPECT_THAT(-1, IsTrue());
EXPECT_THAT(-1, Not(IsFalse()));
EXPECT_THAT(1, IsTrue());
EXPECT_THAT(1, Not(IsFalse()));
EXPECT_THAT(2, IsTrue());
EXPECT_THAT(2, Not(IsFalse()));
int a = 42;
EXPECT_THAT(a, IsTrue());
EXPECT_THAT(a, Not(IsFalse()));
EXPECT_THAT(&a, IsTrue());
EXPECT_THAT(&a, Not(IsFalse()));
EXPECT_THAT(false, Not(IsTrue()));
EXPECT_THAT(true, Not(IsFalse()));
#if GTEST_LANG_CXX11
EXPECT_THAT(std::true_type(), IsTrue());
EXPECT_THAT(std::true_type(), Not(IsFalse()));
EXPECT_THAT(std::false_type(), IsFalse());
EXPECT_THAT(std::false_type(), Not(IsTrue()));
EXPECT_THAT(nullptr, Not(IsTrue()));
EXPECT_THAT(nullptr, IsFalse());
std::unique_ptr<int> null_unique;
std::unique_ptr<int> nonnull_unique(new int(0));
EXPECT_THAT(null_unique, Not(IsTrue()));
EXPECT_THAT(null_unique, IsFalse());
EXPECT_THAT(nonnull_unique, IsTrue());
EXPECT_THAT(nonnull_unique, Not(IsFalse()));
#endif // GTEST_LANG_CXX11
}
TEST(SizeIsTest, ImplementsSizeIs) { TEST(SizeIsTest, ImplementsSizeIs) {
vector<int> container; vector<int> container;
EXPECT_THAT(container, SizeIs(0)); EXPECT_THAT(container, SizeIs(0));
...@@ -4914,6 +5273,250 @@ TEST(WhenSortedTest, WorksForVectorConstRefMatcherOnStreamlike) { ...@@ -4914,6 +5273,250 @@ TEST(WhenSortedTest, WorksForVectorConstRefMatcherOnStreamlike) {
EXPECT_THAT(s, Not(WhenSorted(ElementsAre(2, 1, 4, 5, 3)))); EXPECT_THAT(s, Not(WhenSorted(ElementsAre(2, 1, 4, 5, 3))));
} }
TEST(IsSupersetOfTest, WorksForNativeArray) {
const int subset[] = {1, 4};
const int superset[] = {1, 2, 4};
const int disjoint[] = {1, 0, 3};
EXPECT_THAT(subset, IsSupersetOf(subset));
EXPECT_THAT(subset, Not(IsSupersetOf(superset)));
EXPECT_THAT(superset, IsSupersetOf(subset));
EXPECT_THAT(subset, Not(IsSupersetOf(disjoint)));
EXPECT_THAT(disjoint, Not(IsSupersetOf(subset)));
}
TEST(IsSupersetOfTest, WorksWithDuplicates) {
const int not_enough[] = {1, 2};
const int enough[] = {1, 1, 2};
const int expected[] = {1, 1};
EXPECT_THAT(not_enough, Not(IsSupersetOf(expected)));
EXPECT_THAT(enough, IsSupersetOf(expected));
}
TEST(IsSupersetOfTest, WorksForEmpty) {
vector<int> numbers;
vector<int> expected;
EXPECT_THAT(numbers, IsSupersetOf(expected));
expected.push_back(1);
EXPECT_THAT(numbers, Not(IsSupersetOf(expected)));
expected.clear();
numbers.push_back(1);
numbers.push_back(2);
EXPECT_THAT(numbers, IsSupersetOf(expected));
expected.push_back(1);
EXPECT_THAT(numbers, IsSupersetOf(expected));
expected.push_back(2);
EXPECT_THAT(numbers, IsSupersetOf(expected));
expected.push_back(3);
EXPECT_THAT(numbers, Not(IsSupersetOf(expected)));
}
TEST(IsSupersetOfTest, WorksForStreamlike) {
const int a[5] = {1, 2, 3, 4, 5};
Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
vector<int> expected;
expected.push_back(1);
expected.push_back(2);
expected.push_back(5);
EXPECT_THAT(s, IsSupersetOf(expected));
expected.push_back(0);
EXPECT_THAT(s, Not(IsSupersetOf(expected)));
}
TEST(IsSupersetOfTest, TakesStlContainer) {
const int actual[] = {3, 1, 2};
::std::list<int> expected;
expected.push_back(1);
expected.push_back(3);
EXPECT_THAT(actual, IsSupersetOf(expected));
expected.push_back(4);
EXPECT_THAT(actual, Not(IsSupersetOf(expected)));
}
TEST(IsSupersetOfTest, Describe) {
typedef std::vector<int> IntVec;
IntVec expected;
expected.push_back(111);
expected.push_back(222);
expected.push_back(333);
EXPECT_THAT(
Describe<IntVec>(IsSupersetOf(expected)),
Eq("a surjection from elements to requirements exists such that:\n"
" - an element is equal to 111\n"
" - an element is equal to 222\n"
" - an element is equal to 333"));
}
TEST(IsSupersetOfTest, DescribeNegation) {
typedef std::vector<int> IntVec;
IntVec expected;
expected.push_back(111);
expected.push_back(222);
expected.push_back(333);
EXPECT_THAT(
DescribeNegation<IntVec>(IsSupersetOf(expected)),
Eq("no surjection from elements to requirements exists such that:\n"
" - an element is equal to 111\n"
" - an element is equal to 222\n"
" - an element is equal to 333"));
}
TEST(IsSupersetOfTest, MatchAndExplain) {
std::vector<int> v;
v.push_back(2);
v.push_back(3);
std::vector<int> expected;
expected.push_back(1);
expected.push_back(2);
StringMatchResultListener listener;
ASSERT_FALSE(ExplainMatchResult(IsSupersetOf(expected), v, &listener))
<< listener.str();
EXPECT_THAT(listener.str(),
Eq("where the following matchers don't match any elements:\n"
"matcher #0: is equal to 1"));
v.push_back(1);
listener.Clear();
ASSERT_TRUE(ExplainMatchResult(IsSupersetOf(expected), v, &listener))
<< listener.str();
EXPECT_THAT(listener.str(), Eq("where:\n"
" - element #0 is matched by matcher #1,\n"
" - element #2 is matched by matcher #0"));
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
TEST(IsSupersetOfTest, WorksForRhsInitializerList) {
const int numbers[] = {1, 3, 6, 2, 4, 5};
EXPECT_THAT(numbers, IsSupersetOf({1, 2}));
EXPECT_THAT(numbers, Not(IsSupersetOf({3, 0})));
}
#endif
TEST(IsSubsetOfTest, WorksForNativeArray) {
const int subset[] = {1, 4};
const int superset[] = {1, 2, 4};
const int disjoint[] = {1, 0, 3};
EXPECT_THAT(subset, IsSubsetOf(subset));
EXPECT_THAT(subset, IsSubsetOf(superset));
EXPECT_THAT(superset, Not(IsSubsetOf(subset)));
EXPECT_THAT(subset, Not(IsSubsetOf(disjoint)));
EXPECT_THAT(disjoint, Not(IsSubsetOf(subset)));
}
TEST(IsSubsetOfTest, WorksWithDuplicates) {
const int not_enough[] = {1, 2};
const int enough[] = {1, 1, 2};
const int actual[] = {1, 1};
EXPECT_THAT(actual, Not(IsSubsetOf(not_enough)));
EXPECT_THAT(actual, IsSubsetOf(enough));
}
TEST(IsSubsetOfTest, WorksForEmpty) {
vector<int> numbers;
vector<int> expected;
EXPECT_THAT(numbers, IsSubsetOf(expected));
expected.push_back(1);
EXPECT_THAT(numbers, IsSubsetOf(expected));
expected.clear();
numbers.push_back(1);
numbers.push_back(2);
EXPECT_THAT(numbers, Not(IsSubsetOf(expected)));
expected.push_back(1);
EXPECT_THAT(numbers, Not(IsSubsetOf(expected)));
expected.push_back(2);
EXPECT_THAT(numbers, IsSubsetOf(expected));
expected.push_back(3);
EXPECT_THAT(numbers, IsSubsetOf(expected));
}
TEST(IsSubsetOfTest, WorksForStreamlike) {
const int a[5] = {1, 2};
Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
vector<int> expected;
expected.push_back(1);
EXPECT_THAT(s, Not(IsSubsetOf(expected)));
expected.push_back(2);
expected.push_back(5);
EXPECT_THAT(s, IsSubsetOf(expected));
}
TEST(IsSubsetOfTest, TakesStlContainer) {
const int actual[] = {3, 1, 2};
::std::list<int> expected;
expected.push_back(1);
expected.push_back(3);
EXPECT_THAT(actual, Not(IsSubsetOf(expected)));
expected.push_back(2);
expected.push_back(4);
EXPECT_THAT(actual, IsSubsetOf(expected));
}
TEST(IsSubsetOfTest, Describe) {
typedef std::vector<int> IntVec;
IntVec expected;
expected.push_back(111);
expected.push_back(222);
expected.push_back(333);
EXPECT_THAT(
Describe<IntVec>(IsSubsetOf(expected)),
Eq("an injection from elements to requirements exists such that:\n"
" - an element is equal to 111\n"
" - an element is equal to 222\n"
" - an element is equal to 333"));
}
TEST(IsSubsetOfTest, DescribeNegation) {
typedef std::vector<int> IntVec;
IntVec expected;
expected.push_back(111);
expected.push_back(222);
expected.push_back(333);
EXPECT_THAT(
DescribeNegation<IntVec>(IsSubsetOf(expected)),
Eq("no injection from elements to requirements exists such that:\n"
" - an element is equal to 111\n"
" - an element is equal to 222\n"
" - an element is equal to 333"));
}
TEST(IsSubsetOfTest, MatchAndExplain) {
std::vector<int> v;
v.push_back(2);
v.push_back(3);
std::vector<int> expected;
expected.push_back(1);
expected.push_back(2);
StringMatchResultListener listener;
ASSERT_FALSE(ExplainMatchResult(IsSubsetOf(expected), v, &listener))
<< listener.str();
EXPECT_THAT(listener.str(),
Eq("where the following elements don't match any matchers:\n"
"element #1: 3"));
expected.push_back(3);
listener.Clear();
ASSERT_TRUE(ExplainMatchResult(IsSubsetOf(expected), v, &listener))
<< listener.str();
EXPECT_THAT(listener.str(), Eq("where:\n"
" - element #0 is matched by matcher #1,\n"
" - element #1 is matched by matcher #2"));
}
#if GTEST_HAS_STD_INITIALIZER_LIST_
TEST(IsSubsetOfTest, WorksForRhsInitializerList) {
const int numbers[] = {1, 2, 3};
EXPECT_THAT(numbers, IsSubsetOf({1, 2, 3, 4}));
EXPECT_THAT(numbers, Not(IsSubsetOf({1, 2})));
}
#endif
// Tests using ElementsAre() and ElementsAreArray() with stream-like // Tests using ElementsAre() and ElementsAreArray() with stream-like
// "containers". // "containers".
...@@ -5721,6 +6324,16 @@ TEST(PointwiseTest, WorksForRhsNativeArray) { ...@@ -5721,6 +6324,16 @@ TEST(PointwiseTest, WorksForRhsNativeArray) {
EXPECT_THAT(lhs, Not(Pointwise(Lt(), rhs))); EXPECT_THAT(lhs, Not(Pointwise(Lt(), rhs)));
} }
// Test is effective only with sanitizers.
TEST(PointwiseTest, WorksForVectorOfBool) {
vector<bool> rhs(3, false);
rhs[1] = true;
vector<bool> lhs = rhs;
EXPECT_THAT(lhs, Pointwise(Eq(), rhs));
rhs[0] = true;
EXPECT_THAT(lhs, Not(Pointwise(Eq(), rhs)));
}
#if GTEST_HAS_STD_INITIALIZER_LIST_ #if GTEST_HAS_STD_INITIALIZER_LIST_
TEST(PointwiseTest, WorksForRhsInitializerList) { TEST(PointwiseTest, WorksForRhsInitializerList) {
...@@ -5886,6 +6499,51 @@ TEST(UnorderedPointwiseTest, AllowsMonomorphicInnerMatcher) { ...@@ -5886,6 +6499,51 @@ TEST(UnorderedPointwiseTest, AllowsMonomorphicInnerMatcher) {
EXPECT_THAT(lhs, UnorderedPointwise(m2, rhs)); EXPECT_THAT(lhs, UnorderedPointwise(m2, rhs));
} }
// Sample optional type implementation with minimal requirements for use with
// Optional matcher.
class SampleOptionalInt {
public:
typedef int value_type;
explicit SampleOptionalInt(int value) : value_(value), has_value_(true) {}
SampleOptionalInt() : value_(0), has_value_(false) {}
operator bool() const {
return has_value_;
}
const int& operator*() const {
return value_;
}
private:
int value_;
bool has_value_;
};
TEST(OptionalTest, DescribesSelf) {
const Matcher<SampleOptionalInt> m = Optional(Eq(1));
EXPECT_EQ("value is equal to 1", Describe(m));
}
TEST(OptionalTest, ExplainsSelf) {
const Matcher<SampleOptionalInt> m = Optional(Eq(1));
EXPECT_EQ("whose value 1 matches", Explain(m, SampleOptionalInt(1)));
EXPECT_EQ("whose value 2 doesn't match", Explain(m, SampleOptionalInt(2)));
}
TEST(OptionalTest, MatchesNonEmptyOptional) {
const Matcher<SampleOptionalInt> m1 = Optional(1);
const Matcher<SampleOptionalInt> m2 = Optional(Eq(2));
const Matcher<SampleOptionalInt> m3 = Optional(Lt(3));
SampleOptionalInt opt(1);
EXPECT_TRUE(m1.Matches(opt));
EXPECT_FALSE(m2.Matches(opt));
EXPECT_TRUE(m3.Matches(opt));
}
TEST(OptionalTest, DoesNotMatchNullopt) {
const Matcher<SampleOptionalInt> m = Optional(1);
SampleOptionalInt empty;
EXPECT_FALSE(m.Matches(empty));
}
class SampleVariantIntString { class SampleVariantIntString {
public: public:
SampleVariantIntString(int i) : i_(i), has_int_(true) {} SampleVariantIntString(int i) : i_(i), has_int_(true) {}
...@@ -5950,5 +6608,89 @@ TEST(VariantTest, InnerDoesNotMatch) { ...@@ -5950,5 +6608,89 @@ TEST(VariantTest, InnerDoesNotMatch) {
EXPECT_FALSE(m.Matches(SampleVariantIntString("2"))); EXPECT_FALSE(m.Matches(SampleVariantIntString("2")));
} }
class SampleAnyType {
public:
explicit SampleAnyType(int i) : index_(0), i_(i) {}
explicit SampleAnyType(const std::string& s) : index_(1), s_(s) {}
template <typename T>
friend const T* any_cast(const SampleAnyType* any) {
return any->get_impl(static_cast<T*>(NULL));
}
private:
int index_;
int i_;
std::string s_;
const int* get_impl(int*) const { return index_ == 0 ? &i_ : NULL; }
const std::string* get_impl(std::string*) const {
return index_ == 1 ? &s_ : NULL;
}
};
TEST(AnyWithTest, FullMatch) {
Matcher<SampleAnyType> m = AnyWith<int>(Eq(1));
EXPECT_TRUE(m.Matches(SampleAnyType(1)));
}
TEST(AnyWithTest, TestBadCastType) {
Matcher<SampleAnyType> m = AnyWith<std::string>(Eq("fail"));
EXPECT_FALSE(m.Matches(SampleAnyType(1)));
}
#if GTEST_LANG_CXX11
TEST(AnyWithTest, TestUseInContainers) {
std::vector<SampleAnyType> a;
a.emplace_back(1);
a.emplace_back(2);
a.emplace_back(3);
EXPECT_THAT(
a, ElementsAreArray({AnyWith<int>(1), AnyWith<int>(2), AnyWith<int>(3)}));
std::vector<SampleAnyType> b;
b.emplace_back("hello");
b.emplace_back("merhaba");
b.emplace_back("salut");
EXPECT_THAT(b, ElementsAreArray({AnyWith<std::string>("hello"),
AnyWith<std::string>("merhaba"),
AnyWith<std::string>("salut")}));
}
#endif // GTEST_LANG_CXX11
TEST(AnyWithTest, TestCompare) {
EXPECT_THAT(SampleAnyType(1), AnyWith<int>(Gt(0)));
}
TEST(AnyWithTest, DescribesSelf) {
const Matcher<const SampleAnyType&> m = AnyWith<int>(Eq(1));
EXPECT_THAT(Describe(m), ContainsRegex("is an 'any' type with value of type "
"'.*' and the value is equal to 1"));
}
TEST(AnyWithTest, ExplainsSelf) {
const Matcher<const SampleAnyType&> m = AnyWith<int>(Eq(1));
EXPECT_THAT(Explain(m, SampleAnyType(1)), ContainsRegex("whose value 1"));
EXPECT_THAT(Explain(m, SampleAnyType("A")),
HasSubstr("whose value is not of type '"));
EXPECT_THAT(Explain(m, SampleAnyType(2)), "whose value 2 doesn't match");
}
#if GTEST_LANG_CXX11
TEST(PointeeTest, WorksOnMoveOnlyType) {
std::unique_ptr<int> p(new int(3));
EXPECT_THAT(p, Pointee(Eq(3)));
EXPECT_THAT(p, Not(Pointee(Eq(2))));
}
TEST(NotTest, WorksOnMoveOnlyType) {
std::unique_ptr<int> p(new int(3));
EXPECT_THAT(p, Pointee(Eq(3)));
EXPECT_THAT(p, Not(Pointee(Eq(2))));
}
#endif // GTEST_LANG_CXX11
} // namespace gmock_matchers_test } // namespace gmock_matchers_test
} // namespace testing } // namespace testing
...@@ -748,7 +748,6 @@ TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) { ...@@ -748,7 +748,6 @@ TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) {
testing::GMOCK_FLAG(default_mock_behavior) = original_behavior; testing::GMOCK_FLAG(default_mock_behavior) = original_behavior;
} }
#endif // GTEST_HAS_STREAM_REDIRECTION #endif // GTEST_HAS_STREAM_REDIRECTION
// Tests the semantics of ON_CALL(). // Tests the semantics of ON_CALL().
...@@ -2691,7 +2690,6 @@ int gmock_main(int argc, char **argv) { ...@@ -2691,7 +2690,6 @@ int gmock_main(int argc, char **argv) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
#endif // GMOCK_RENAME_MAIN #endif // GMOCK_RENAME_MAIN
testing::InitGoogleMock(&argc, argv); testing::InitGoogleMock(&argc, argv);
// Ensures that the tests pass no matter what value of // Ensures that the tests pass no matter what value of
// --gmock_catch_leaked_mocks and --gmock_verbose the user specifies. // --gmock_catch_leaked_mocks and --gmock_verbose the user specifies.
testing::GMOCK_FLAG(catch_leaked_mocks) = true; testing::GMOCK_FLAG(catch_leaked_mocks) = true;
......
...@@ -273,6 +273,11 @@ MATCHER_P2(IsPair, first, second, "") { ...@@ -273,6 +273,11 @@ MATCHER_P2(IsPair, first, second, "") {
return Value(arg.first, first) && Value(arg.second, second); return Value(arg.first, first) && Value(arg.second, second);
} }
TEST_F(GMockOutputTest, PrintsMatcher) {
const testing::Matcher<int> m1 = Ge(48);
EXPECT_THAT((std::pair<int, bool>(42, true)), IsPair(m1, true));
}
void TestCatchesLeakedMocksInAdHocTests() { void TestCatchesLeakedMocksInAdHocTests() {
MockFoo* foo = new MockFoo; MockFoo* foo = new MockFoo;
......
...@@ -288,6 +288,12 @@ Stack trace: ...@@ -288,6 +288,12 @@ Stack trace:
[ OK ] GMockOutputTest.ExplicitActionsRunOutWithDefaultAction [ OK ] GMockOutputTest.ExplicitActionsRunOutWithDefaultAction
[ RUN ] GMockOutputTest.CatchesLeakedMocks [ RUN ] GMockOutputTest.CatchesLeakedMocks
[ OK ] GMockOutputTest.CatchesLeakedMocks [ OK ] GMockOutputTest.CatchesLeakedMocks
[ RUN ] GMockOutputTest.PrintsMatcher
FILE:#: Failure
Value of: (std::pair<int, bool>(42, true))
Expected: is pair (is >= 48, true)
Actual: (42, true) (of type std::pair<int, bool>)
[ FAILED ] GMockOutputTest.PrintsMatcher
[ FAILED ] GMockOutputTest.UnexpectedCall [ FAILED ] GMockOutputTest.UnexpectedCall
[ FAILED ] GMockOutputTest.UnexpectedCallToVoidFunction [ FAILED ] GMockOutputTest.UnexpectedCallToVoidFunction
[ FAILED ] GMockOutputTest.ExcessiveCall [ FAILED ] GMockOutputTest.ExcessiveCall
...@@ -302,9 +308,10 @@ Stack trace: ...@@ -302,9 +308,10 @@ Stack trace:
[ FAILED ] GMockOutputTest.MismatchArgumentsAndWith [ FAILED ] GMockOutputTest.MismatchArgumentsAndWith
[ FAILED ] GMockOutputTest.UnexpectedCallWithDefaultAction [ FAILED ] GMockOutputTest.UnexpectedCallWithDefaultAction
[ FAILED ] GMockOutputTest.ExcessiveCallWithDefaultAction [ FAILED ] GMockOutputTest.ExcessiveCallWithDefaultAction
[ FAILED ] GMockOutputTest.PrintsMatcher
FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#. FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#.
FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#. FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#.
FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#. FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#.
ERROR: 3 leaked mock objects found at program exit. ERROR: 3 leaked mock objects found at program exit. Expectations on a mock object is verified when the object is destructed. Leaking a mock means that its expectations aren't verified, which is usually a test bug. If you really intend to leak a mock, you can suppress this error using testing::Mock::AllowLeak(mock_object), or you may use a fake or stub instead of a mock.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment