summaryrefslogtreecommitdiff
path: root/absl/random/internal/mock_overload_set.h
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2020-06-11 09:56:29 -0700
committerGravatar vslashg <gfalcon@google.com>2020-06-12 17:24:49 -0400
commit2c92bdc7c2f8e65198af61a0611d90a55312ee82 (patch)
tree8b0fe283dd1594d6bd8f4d039417047807985f97 /absl/random/internal/mock_overload_set.h
parente7ebf9803746b9a115d96164bdf5e915be8f223b (diff)
Export of internal Abseil changes
-- e21e960918678629abf89ad1b694b7d4a456b434 by Greg Falcon <gfalcon@google.com>: Roll back invoke() change due to large increases in compiler memory usage. PiperOrigin-RevId: 315919455 -- f95872e1e1d7afdefbac94f42ea228d42d80eb6e by Greg Falcon <gfalcon@google.com>: Rollback of invoke() changes due to compiler memory usage growth PiperOrigin-RevId: 315911585 -- 6c6c6ba6892016a2ce4703042800254fb9b15727 by Laramie Leavitt <lar@google.com>: Move some of the common mocking code into MockHelpers. Use MockHelpers to do mock signature detection and improve the dispatch mechansim. PiperOrigin-RevId: 315825988 -- 5e9380367d280c7fa6dbd4d0f48c31ade7f1d419 by Greg Falcon <gfalcon@google.com>: Rename the internal implementation details Invoke and InvokeT to `invoke` and `invoke_result_t`, since these are re-implementations of C++17 library entites of the same names. PiperOrigin-RevId: 315790467 GitOrigin-RevId: e21e960918678629abf89ad1b694b7d4a456b434 Change-Id: Ia75011f94cb033c1c9a4cb64cf14d283b91426ac
Diffstat (limited to 'absl/random/internal/mock_overload_set.h')
-rw-r--r--absl/random/internal/mock_overload_set.h27
1 files changed, 10 insertions, 17 deletions
diff --git a/absl/random/internal/mock_overload_set.h b/absl/random/internal/mock_overload_set.h
index 60561b51..dccc6cee 100644
--- a/absl/random/internal/mock_overload_set.h
+++ b/absl/random/internal/mock_overload_set.h
@@ -20,7 +20,7 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
-#include "absl/base/internal/fast_type_id.h"
+#include "absl/random/internal/mock_helpers.h"
#include "absl/random/mocking_bit_gen.h"
namespace absl {
@@ -37,22 +37,19 @@ struct MockSingleOverload;
// `mock_single_overload.gmock_Call(...)`. Because expectations are stored on
// the MockingBitGen (an argument passed inside `Call(...)`), this forwards to
// arguments to MockingBitGen::Register.
+//
+// The underlying KeyT must match the KeyT constructed by DistributionCaller.
template <typename DistrT, typename Ret, typename... Args>
struct MockSingleOverload<DistrT, Ret(MockingBitGen&, Args...)> {
static_assert(std::is_same<typename DistrT::result_type, Ret>::value,
"Overload signature must have return type matching the "
"distribution result_type.");
- using ArgTupleT = std::tuple<Args...>;
+ using KeyT = Ret(DistrT, std::tuple<Args...>);
auto gmock_Call(
absl::MockingBitGen& gen, // NOLINT(google-runtime-references)
const ::testing::Matcher<Args>&... matchers)
- -> decltype(gen.RegisterMock<Ret, ArgTupleT>(
- std::declval<::absl::base_internal::FastTypeIdType>())
- .gmock_Call(matchers...)) {
- return gen
- .RegisterMock<Ret, ArgTupleT>(
- ::absl::base_internal::FastTypeId<Ret(DistrT, ArgTupleT)>())
- .gmock_Call(matchers...);
+ -> decltype(MockHelpers::MockFor<KeyT>(gen).gmock_Call(matchers...)) {
+ return MockHelpers::MockFor<KeyT>(gen).gmock_Call(matchers...);
}
};
@@ -61,18 +58,14 @@ struct MockSingleOverload<DistrT, Ret(Arg, MockingBitGen&, Args...)> {
static_assert(std::is_same<typename DistrT::result_type, Ret>::value,
"Overload signature must have return type matching the "
"distribution result_type.");
- using ArgTupleT = std::tuple<Arg, Args...>;
+ using KeyT = Ret(DistrT, std::tuple<Arg, Args...>);
auto gmock_Call(
const ::testing::Matcher<Arg>& matcher,
absl::MockingBitGen& gen, // NOLINT(google-runtime-references)
const ::testing::Matcher<Args>&... matchers)
- -> decltype(gen.RegisterMock<Ret, ArgTupleT>(
- std::declval<::absl::base_internal::FastTypeIdType>())
- .gmock_Call(matcher, matchers...)) {
- return gen
- .RegisterMock<Ret, ArgTupleT>(
- ::absl::base_internal::FastTypeId<Ret(DistrT, ArgTupleT)>())
- .gmock_Call(matcher, matchers...);
+ -> decltype(MockHelpers::MockFor<KeyT>(gen).gmock_Call(matcher,
+ matchers...)) {
+ return MockHelpers::MockFor<KeyT>(gen).gmock_Call(matcher, matchers...);
}
};