endpoint_binder_pool_test.cc
Go to the documentation of this file.
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 #include <cassert>
18 #include <string>
19 #include <utility>
20 #include <vector>
21 
22 #include <gmock/gmock.h>
23 #include <gtest/gtest.h>
24 
25 #include "absl/memory/memory.h"
26 
30 
31 namespace grpc_binder {
32 
34  public:
35  MOCK_METHOD(void, Cb, (std::unique_ptr<grpc_binder::Binder>), ());
36 };
37 
38 TEST(EndpointBinderPoolTest, AddBeforeGet) {
40  auto b = absl::make_unique<grpc_binder::MockBinder>();
41  CallbackChecker cc;
42  pool.AddEndpointBinder("test", std::move(b));
43  // TODO(mingcl): Use pointer matcher to verify it is `b` being passed back
44  // here. It is only available in newer gtest version
45  EXPECT_CALL(cc, Cb(testing::_));
46  pool.GetEndpointBinder(
47  "test", std::bind(&CallbackChecker::Cb, &cc, std::placeholders::_1));
48 }
49 
50 TEST(EndpointBinderPoolTest, GetBeforeAdd) {
52  auto b = absl::make_unique<grpc_binder::MockBinder>();
53  CallbackChecker cc;
54  EXPECT_CALL(cc, Cb(testing::_)).Times(0);
55  pool.GetEndpointBinder(
56  "test", std::bind(&CallbackChecker::Cb, &cc, std::placeholders::_1));
57  EXPECT_CALL(cc, Cb(testing::_)).Times(1);
58  pool.AddEndpointBinder("test", std::move(b));
59 }
60 
61 TEST(EndpointBinderPoolTest, ExpectNotCalled) {
63  auto b = absl::make_unique<grpc_binder::MockBinder>();
64  CallbackChecker cc;
65  EXPECT_CALL(cc, Cb(testing::_)).Times(0);
66  pool.GetEndpointBinder(
67  "test", std::bind(&CallbackChecker::Cb, &cc, std::placeholders::_1));
68 }
69 
70 } // namespace grpc_binder
71 
72 int main(int argc, char** argv) {
73  ::testing::InitGoogleTest(&argc, argv);
75  return RUN_ALL_TESTS();
76 }
generate.env
env
Definition: generate.py:37
grpc_binder::CallbackChecker::MOCK_METHOD
MOCK_METHOD(void, Cb,(std::unique_ptr< grpc_binder::Binder >),())
grpc_binder
Definition: connection_id_generator.cc:45
mock_objects.h
grpc_binder::TEST
TEST(EndpointBinderPoolTest, AddBeforeGet)
Definition: endpoint_binder_pool_test.cc:38
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
endpoint_binder_pool.h
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
b
uint64_t b
Definition: abseil-cpp/absl/container/internal/layout_test.cc:53
EXPECT_CALL
#define EXPECT_CALL(obj, call)
test_config.h
testing::_
const internal::AnythingMatcher _
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8548
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
pool
InternalDescriptorPool * pool
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:807
grpc_binder::EndpointBinderPool
Definition: endpoint_binder_pool.h:36
grpc_binder::CallbackChecker
Definition: endpoint_binder_pool_test.cc:33
main
int main(int argc, char **argv)
Definition: endpoint_binder_pool_test.cc:72


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:19