xref: /aosp_15_r20/external/grpc-grpc/test/core/promise/poll_test.cc (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
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/poll.h"
16 
17 #include <memory>
18 
19 #include "gtest/gtest.h"
20 
21 namespace grpc_core {
22 
23 static_assert(sizeof(Poll<Empty>) == sizeof(bool),
24               "Poll<Empty> should be just a bool");
25 
TEST(PollTest,IsItPoll)26 TEST(PollTest, IsItPoll) {
27   EXPECT_EQ(PollTraits<Poll<int>>::is_poll(), true);
28   EXPECT_EQ(PollTraits<Poll<bool>>::is_poll(), true);
29   EXPECT_EQ(PollTraits<Poll<Empty>>::is_poll(), true);
30   EXPECT_EQ(PollTraits<Poll<std::unique_ptr<int>>>::is_poll(), true);
31   EXPECT_EQ(PollTraits<int>::is_poll(), false);
32   EXPECT_EQ(PollTraits<bool>::is_poll(), false);
33   EXPECT_EQ(PollTraits<Empty>::is_poll(), false);
34   EXPECT_EQ(PollTraits<std::unique_ptr<int>>::is_poll(), false);
35 }
36 
TEST(PollTest,Pending)37 TEST(PollTest, Pending) {
38   Poll<int> i = Pending();
39   EXPECT_TRUE(i.pending());
40   Poll<Empty> j = Pending();
41   EXPECT_TRUE(j.pending());
42 }
43 
TEST(PollTest,Ready)44 TEST(PollTest, Ready) {
45   Poll<int> i = 1;
46   EXPECT_TRUE(i.ready());
47   EXPECT_EQ(i.value(), 1);
48   Poll<Empty> j = Empty();
49   EXPECT_TRUE(j.ready());
50 }
51 
TEST(PollTest,CanMove)52 TEST(PollTest, CanMove) {
53   Poll<std::shared_ptr<int>> x = std::make_shared<int>(3);
54   Poll<std::shared_ptr<int>> y = std::make_shared<int>(4);
55   y = std::move(x);
56   Poll<std::shared_ptr<int>> z = std::move(y);
57   EXPECT_EQ(*z.value(), 3);
58 }
59 
TEST(PollTest,ImplicitConstructor)60 TEST(PollTest, ImplicitConstructor) {
61   Poll<std::shared_ptr<int>> x(std::make_unique<int>(3));
62   EXPECT_EQ(*x.value(), 3);
63 }
64 
65 }  // namespace grpc_core
66 
main(int argc,char ** argv)67 int main(int argc, char** argv) {
68   ::testing::InitGoogleTest(&argc, argv);
69   return RUN_ALL_TESTS();
70 }
71