Debian Codegraph @

test/core/promise/promise_factory_test.cc

raw
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
15 #include "src/core/lib/promise/detail/promise_factory.h"
16
17 #include <functional>
18
19 #include "absl/functional/bind_front.h"
20 #include "gtest/gtest.h"
21
22 #include "src/core/lib/promise/poll.h"
23 #include "src/core/lib/promise/promise.h"
24
25 namespace grpc_core {
26 namespace promise_detail {
27 namespace testing {
28
29 template <typename Arg, typename F>
30 auto MakeOnceFactory(F f) {
31 return OncePromiseFactory<Arg, F>(std::move(f));
32 }
33 template <typename Arg, typename F>
34 auto MakeRepeatedFactory(F f) {
35 return RepeatedPromiseFactory<Arg, F>(std::move(f));
36 }
37
38 TEST(AdaptorTest, FactoryFromPromise) {
39 EXPECT_EQ(
40 MakeOnceFactory<void>([]() { return Poll<int>(Poll<int>(42)); }).Make()(),
41 Poll<int>(42));
42 EXPECT_EQ(MakeRepeatedFactory<void>([]() {
43 return Poll<int>(Poll<int>(42));
44 }).Make()(),
45 Poll<int>(42));
46 EXPECT_EQ(MakeOnceFactory<void>(Promise<int>([]() {
47 return Poll<int>(Poll<int>(42));
48 })).Make()(),
49 Poll<int>(42));
50 EXPECT_EQ(MakeRepeatedFactory<void>(Promise<int>([]() {
51 return Poll<int>(Poll<int>(42));
52 })).Make()(),
53 Poll<int>(42));
54 }
55
56 TEST(AdaptorTest, FactoryFromBindFrontPromise) {
57 EXPECT_EQ(MakeOnceFactory<void>(
58 absl::bind_front([](int i) { return Poll<int>(i); }, 42))
59 .Make()(),
60 Poll<int>(42));
61 }
62
63 } // namespace testing
64 } // namespace promise_detail
65
66 } // namespace grpc_core
67
68 int main(int argc, char** argv) {
69 ::testing::InitGoogleTest(&argc, argv);
70 return RUN_ALL_TESTS();
71 }