• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 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 #ifndef GRPC_TEST_CORE_PROMISE_POLL_MATCHER_H
16 #define GRPC_TEST_CORE_PROMISE_POLL_MATCHER_H
17 
18 #include "gmock/gmock.h"
19 
20 // Various gmock matchers for Poll
21 
22 namespace grpc_core {
23 
24 // Expect that a promise is still pending:
25 // EXPECT_THAT(some_promise(), IsPending());
26 MATCHER(IsPending, "") {
27   if (arg.ready()) {
28     *result_listener << "is ready";
29     return false;
30   }
31   return true;
32 }
33 
34 // Expect that a promise is ready:
35 // EXPECT_THAT(some_promise(), IsReady());
36 MATCHER(IsReady, "") {
37   if (arg.pending()) {
38     *result_listener << "is pending";
39     return false;
40   }
41   return true;
42 }
43 
44 // Expect that a promise is ready with a specific value:
45 // EXPECT_THAT(some_promise(), IsReady(value));
46 MATCHER_P(IsReady, value, "") {
47   if (arg.pending()) {
48     *result_listener << "is pending";
49     return false;
50   }
51   if (arg.value() != value) {
52     *result_listener << "is " << ::testing::PrintToString(arg.value());
53     return false;
54   }
55   return true;
56 }
57 
58 }  // namespace grpc_core
59 
60 #endif  // GRPC_TEST_CORE_PROMISE_POLL_MATCHER_H
61