File indexing completed on 2024-11-15 09:01:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef ABSL_RANDOM_INTERNAL_MOCK_OVERLOAD_SET_H_
0017 #define ABSL_RANDOM_INTERNAL_MOCK_OVERLOAD_SET_H_
0018
0019 #include <type_traits>
0020
0021 #include "gmock/gmock.h"
0022 #include "absl/random/internal/mock_helpers.h"
0023 #include "absl/random/mocking_bit_gen.h"
0024
0025 namespace absl {
0026 ABSL_NAMESPACE_BEGIN
0027 namespace random_internal {
0028
0029 template <typename DistrT, typename Fn>
0030 struct MockSingleOverload;
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 template <typename DistrT, typename Ret, typename... Args>
0042 struct MockSingleOverload<DistrT, Ret(MockingBitGen&, Args...)> {
0043 static_assert(std::is_same<typename DistrT::result_type, Ret>::value,
0044 "Overload signature must have return type matching the "
0045 "distribution result_type.");
0046 using KeyT = Ret(DistrT, std::tuple<Args...>);
0047
0048 template <typename MockURBG>
0049 auto gmock_Call(MockURBG& gen, const ::testing::Matcher<Args>&... matchers)
0050 -> decltype(MockHelpers::MockFor<KeyT>(gen).gmock_Call(matchers...)) {
0051 static_assert(std::is_base_of<MockingBitGen, MockURBG>::value,
0052 "Mocking requires an absl::MockingBitGen");
0053 return MockHelpers::MockFor<KeyT>(gen).gmock_Call(matchers...);
0054 }
0055 };
0056
0057 template <typename DistrT, typename Ret, typename Arg, typename... Args>
0058 struct MockSingleOverload<DistrT, Ret(Arg, MockingBitGen&, Args...)> {
0059 static_assert(std::is_same<typename DistrT::result_type, Ret>::value,
0060 "Overload signature must have return type matching the "
0061 "distribution result_type.");
0062 using KeyT = Ret(DistrT, std::tuple<Arg, Args...>);
0063
0064 template <typename MockURBG>
0065 auto gmock_Call(const ::testing::Matcher<Arg>& matcher, MockURBG& gen,
0066 const ::testing::Matcher<Args>&... matchers)
0067 -> decltype(MockHelpers::MockFor<KeyT>(gen).gmock_Call(matcher,
0068 matchers...)) {
0069 static_assert(std::is_base_of<MockingBitGen, MockURBG>::value,
0070 "Mocking requires an absl::MockingBitGen");
0071 return MockHelpers::MockFor<KeyT>(gen).gmock_Call(matcher, matchers...);
0072 }
0073 };
0074
0075
0076
0077
0078
0079
0080
0081 template <typename DistrT, typename... Signatures>
0082 struct MockOverloadSet;
0083
0084 template <typename DistrT, typename Sig>
0085 struct MockOverloadSet<DistrT, Sig> : public MockSingleOverload<DistrT, Sig> {
0086 using MockSingleOverload<DistrT, Sig>::gmock_Call;
0087 };
0088
0089 template <typename DistrT, typename FirstSig, typename... Rest>
0090 struct MockOverloadSet<DistrT, FirstSig, Rest...>
0091 : public MockSingleOverload<DistrT, FirstSig>,
0092 public MockOverloadSet<DistrT, Rest...> {
0093 using MockSingleOverload<DistrT, FirstSig>::gmock_Call;
0094 using MockOverloadSet<DistrT, Rest...>::gmock_Call;
0095 };
0096
0097 }
0098 ABSL_NAMESPACE_END
0099 }
0100 #endif