promise_factory_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 <functional>
18 
19 #include "absl/functional/bind_front.h"
20 #include "absl/types/variant.h"
21 #include "gtest/gtest.h"
22 
25 
26 namespace grpc_core {
27 namespace promise_detail {
28 namespace testing {
29 
30 template <typename Arg, typename F>
33 }
34 
35 TEST(AdaptorTest, FactoryFromPromise) {
36  EXPECT_EQ(
37  MakeFactory<void>([]() { return Poll<int>(Poll<int>(42)); }).Once()(),
38  Poll<int>(42));
39  EXPECT_EQ(
40  MakeFactory<void>([]() { return Poll<int>(Poll<int>(42)); }).Repeated()(),
41  Poll<int>(42));
42  EXPECT_EQ(MakeFactory<void>(Promise<int>([]() {
43  return Poll<int>(Poll<int>(42));
44  })).Once()(),
45  Poll<int>(42));
46  EXPECT_EQ(MakeFactory<void>(Promise<int>([]() {
47  return Poll<int>(Poll<int>(42));
48  })).Repeated()(),
49  Poll<int>(42));
50 }
51 
52 TEST(AdaptorTest, FactoryFromBindFrontPromise) {
53  EXPECT_EQ(MakeFactory<void>(
54  absl::bind_front([](int i) { return Poll<int>(i); }, 42))
55  .Once()(),
56  Poll<int>(42));
57 }
58 
59 } // namespace testing
60 } // namespace promise_detail
61 
62 } // namespace grpc_core
63 
64 int main(int argc, char** argv) {
65  ::testing::InitGoogleTest(&argc, argv);
66  return RUN_ALL_TESTS();
67 }
testing
Definition: aws_request_signer_test.cc:25
absl::bind_front
constexpr ABSL_NAMESPACE_BEGIN functional_internal::bind_front_t< F, BoundArgs... > bind_front(F &&func, BoundArgs &&... args)
Definition: abseil-cpp/absl/functional/bind_front.h:182
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::promise_detail::testing::MakeFactory
PromiseFactory< Arg, F > MakeFactory(F f)
Definition: promise_factory_test.cc:31
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
promise_factory.h
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
promise.h
main
int main(int argc, char **argv)
Definition: promise_factory_test.cc:64
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
grpc_core::promise_detail::PromiseFactory
Definition: promise_factory.h:149
grpc_core::promise_detail::testing::TEST
TEST(AdaptorTest, FactoryFromPromise)
Definition: promise_factory_test.cc:35
poll.h
grpc_core::Promise
std::function< Poll< T >()> Promise
Definition: promise/promise.h:37
absl::variant
Definition: abseil-cpp/absl/types/internal/variant.h:46
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


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