Warning, file /include/absl/random/internal/mock_overload_set.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 <tuple>
0020 #include <type_traits>
0021
0022 #include "gmock/gmock.h"
0023 #include "absl/base/config.h"
0024 #include "absl/random/internal/mock_helpers.h"
0025 #include "absl/random/mocking_bit_gen.h"
0026
0027 namespace absl {
0028 ABSL_NAMESPACE_BEGIN
0029 namespace random_internal {
0030
0031 template <typename DistrT, typename ValidatorT, typename Fn>
0032 struct MockSingleOverload;
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 template <typename DistrT, typename ValidatorT, typename Ret, typename... Args>
0044 struct MockSingleOverload<DistrT, ValidatorT, Ret(MockingBitGen&, Args...)> {
0045 static_assert(std::is_same<typename DistrT::result_type, Ret>::value,
0046 "Overload signature must have return type matching the "
0047 "distribution result_type.");
0048 using KeyT = Ret(DistrT, std::tuple<Args...>);
0049
0050 template <typename MockURBG>
0051 auto gmock_Call(MockURBG& gen, const ::testing::Matcher<Args>&... matchers)
0052 -> decltype(MockHelpers::MockFor<KeyT>(gen, ValidatorT())
0053 .gmock_Call(matchers...)) {
0054 static_assert(
0055 std::is_base_of<MockingBitGenImpl<true>, MockURBG>::value ||
0056 std::is_base_of<MockingBitGenImpl<false>, MockURBG>::value,
0057 "Mocking requires an absl::MockingBitGen");
0058 return MockHelpers::MockFor<KeyT>(gen, ValidatorT())
0059 .gmock_Call(matchers...);
0060 }
0061 };
0062
0063 template <typename DistrT, typename ValidatorT, typename Ret, typename Arg,
0064 typename... Args>
0065 struct MockSingleOverload<DistrT, ValidatorT,
0066 Ret(Arg, MockingBitGen&, Args...)> {
0067 static_assert(std::is_same<typename DistrT::result_type, Ret>::value,
0068 "Overload signature must have return type matching the "
0069 "distribution result_type.");
0070 using KeyT = Ret(DistrT, std::tuple<Arg, Args...>);
0071
0072 template <typename MockURBG>
0073 auto gmock_Call(const ::testing::Matcher<Arg>& matcher, MockURBG& gen,
0074 const ::testing::Matcher<Args>&... matchers)
0075 -> decltype(MockHelpers::MockFor<KeyT>(gen, ValidatorT())
0076 .gmock_Call(matcher, matchers...)) {
0077 static_assert(
0078 std::is_base_of<MockingBitGenImpl<true>, MockURBG>::value ||
0079 std::is_base_of<MockingBitGenImpl<false>, MockURBG>::value,
0080 "Mocking requires an absl::MockingBitGen");
0081 return MockHelpers::MockFor<KeyT>(gen, ValidatorT())
0082 .gmock_Call(matcher, matchers...);
0083 }
0084 };
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095 template <typename DistrT, typename ValidatorT, typename... Fns>
0096 struct MockOverloadSetWithValidator;
0097
0098 template <typename DistrT, typename ValidatorT, typename Sig>
0099 struct MockOverloadSetWithValidator<DistrT, ValidatorT, Sig>
0100 : public MockSingleOverload<DistrT, ValidatorT, Sig> {
0101 using MockSingleOverload<DistrT, ValidatorT, Sig>::gmock_Call;
0102 };
0103
0104 template <typename DistrT, typename ValidatorT, typename FirstSig,
0105 typename... Rest>
0106 struct MockOverloadSetWithValidator<DistrT, ValidatorT, FirstSig, Rest...>
0107 : public MockSingleOverload<DistrT, ValidatorT, FirstSig>,
0108 public MockOverloadSetWithValidator<DistrT, ValidatorT, Rest...> {
0109 using MockSingleOverload<DistrT, ValidatorT, FirstSig>::gmock_Call;
0110 using MockOverloadSetWithValidator<DistrT, ValidatorT, Rest...>::gmock_Call;
0111 };
0112
0113
0114
0115
0116
0117
0118
0119 template <typename DistrT, typename... Signatures>
0120 using MockOverloadSet =
0121 MockOverloadSetWithValidator<DistrT, NoOpValidator, Signatures...>;
0122
0123 }
0124 ABSL_NAMESPACE_END
0125 }
0126 #endif