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