abseil-cpp/absl/random/internal/mock_overload_set.h
Go to the documentation of this file.
1 //
2 // Copyright 2019 The Abseil Authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // https://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef ABSL_RANDOM_INTERNAL_MOCK_OVERLOAD_SET_H_
17 #define ABSL_RANDOM_INTERNAL_MOCK_OVERLOAD_SET_H_
18 
19 #include <type_traits>
20 
21 #include "gmock/gmock.h"
22 #include "absl/random/internal/mock_helpers.h"
23 #include "absl/random/mocking_bit_gen.h"
24 
25 namespace absl {
27 namespace random_internal {
28 
29 template <typename DistrT, typename Fn>
31 
32 // MockSingleOverload
33 //
34 // MockSingleOverload hooks in to gMock's `ON_CALL` and `EXPECT_CALL` macros.
35 // EXPECT_CALL(mock_single_overload, Call(...))` will expand to a call to
36 // `mock_single_overload.gmock_Call(...)`. Because expectations are stored on
37 // the MockingBitGen (an argument passed inside `Call(...)`), this forwards to
38 // arguments to MockingBitGen::Register.
39 //
40 // The underlying KeyT must match the KeyT constructed by DistributionCaller.
41 template <typename DistrT, typename Ret, typename... Args>
42 struct MockSingleOverload<DistrT, Ret(MockingBitGen&, Args...)> {
44  "Overload signature must have return type matching the "
45  "distribution result_type.");
46  using KeyT = Ret(DistrT, std::tuple<Args...>);
47 
48  template <typename MockURBG>
49  auto gmock_Call(MockURBG& gen, const ::testing::Matcher<Args>&... matchers)
50  -> decltype(MockHelpers::MockFor<KeyT>(gen).gmock_Call(matchers...)) {
52  "Mocking requires an absl::MockingBitGen");
53  return MockHelpers::MockFor<KeyT>(gen).gmock_Call(matchers...);
54  }
55 };
56 
57 template <typename DistrT, typename Ret, typename Arg, typename... Args>
58 struct MockSingleOverload<DistrT, Ret(Arg, MockingBitGen&, Args...)> {
60  "Overload signature must have return type matching the "
61  "distribution result_type.");
62  using KeyT = Ret(DistrT, std::tuple<Arg, Args...>);
63 
64  template <typename MockURBG>
65  auto gmock_Call(const ::testing::Matcher<Arg>& matcher, MockURBG& gen,
66  const ::testing::Matcher<Args>&... matchers)
67  -> decltype(MockHelpers::MockFor<KeyT>(gen).gmock_Call(matcher,
68  matchers...)) {
70  "Mocking requires an absl::MockingBitGen");
71  return MockHelpers::MockFor<KeyT>(gen).gmock_Call(matcher, matchers...);
72  }
73 };
74 
75 // MockOverloadSet
76 //
77 // MockOverloadSet takes a distribution and a collection of signatures and
78 // performs overload resolution amongst all the overloads. This makes
79 // `EXPECT_CALL(mock_overload_set, Call(...))` expand and do overload resolution
80 // correctly.
81 template <typename DistrT, typename... Signatures>
83 
84 template <typename DistrT, typename Sig>
85 struct MockOverloadSet<DistrT, Sig> : public MockSingleOverload<DistrT, Sig> {
87 };
88 
89 template <typename DistrT, typename FirstSig, typename... Rest>
90 struct MockOverloadSet<DistrT, FirstSig, Rest...>
91  : public MockSingleOverload<DistrT, FirstSig>,
92  public MockOverloadSet<DistrT, Rest...> {
94  using MockOverloadSet<DistrT, Rest...>::gmock_Call;
95 };
96 
97 } // namespace random_internal
99 } // namespace absl
100 #endif // ABSL_RANDOM_INTERNAL_MOCK_OVERLOAD_SET_H_
absl::MockingBitGen
Definition: abseil-cpp/absl/random/mocking_bit_gen.h:104
matchers
XdsRouteConfigResource::Route::Matchers matchers
Definition: xds_server_config_fetcher.cc:317
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
Arg
Arg(64) -> Arg(128) ->Arg(256) ->Arg(512) ->Arg(1024) ->Arg(1536) ->Arg(2048) ->Arg(3072) ->Arg(4096) ->Arg(5120) ->Arg(6144) ->Arg(7168)
absl::random_internal::MockSingleOverload
Definition: abseil-cpp/absl/random/internal/mock_overload_set.h:30
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
hpack_encoder_fixtures::Args
Args({0, 16384})
absl::random_internal::MockSingleOverload< DistrT, Ret(MockingBitGen &, Args...)>::KeyT
Ret(DistrT, std::tuple< Args... >) KeyT
Definition: abseil-cpp/absl/random/internal/mock_overload_set.h:46
absl::random_internal::MockSingleOverload< DistrT, Ret(MockingBitGen &, Args...)>::gmock_Call
auto gmock_Call(MockURBG &gen, const ::testing::Matcher< Args > &... matchers) -> decltype(MockHelpers::MockFor< KeyT >(gen).gmock_Call(matchers...))
Definition: abseil-cpp/absl/random/internal/mock_overload_set.h:49
gen
OPENSSL_EXPORT GENERAL_NAME * gen
Definition: x509v3.h:495
value
const char * value
Definition: hpack_parser_table.cc:165
absl::random_internal::MockOverloadSet
Definition: abseil-cpp/absl/random/internal/mock_overload_set.h:82
absl::random_internal::MockSingleOverload< DistrT, Ret(Arg, MockingBitGen &, Args...)>::KeyT
Ret(DistrT, std::tuple< Arg, Args... >) KeyT
Definition: abseil-cpp/absl/random/internal/mock_overload_set.h:62
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
absl::random_internal::MockSingleOverload< DistrT, Ret(Arg, MockingBitGen &, Args...)>::gmock_Call
auto gmock_Call(const ::testing::Matcher< Arg > &matcher, MockURBG &gen, const ::testing::Matcher< Args > &... matchers) -> decltype(MockHelpers::MockFor< KeyT >(gen).gmock_Call(matcher, matchers...))
Definition: abseil-cpp/absl/random/internal/mock_overload_set.h:65


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:30