call_checker.h
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 
15 #ifndef LOCAL_GOOGLE_HOME_CTILLER_GRPC_TEST_CORE_RESOURCE_QUOTA_CALL_CHECKER_H_
16 #define LOCAL_GOOGLE_HOME_CTILLER_GRPC_TEST_CORE_RESOURCE_QUOTA_CALL_CHECKER_H_
17 
18 #include <memory>
19 
20 #include <grpc/support/log.h>
21 
22 namespace grpc_core {
23 namespace testing {
24 
25 // Utility to help check a function is called.
26 // Usage:
27 // auto checker = CallChecker::Make();
28 // auto f = [checker]() {
29 // checker.Called();
30 // };
31 // Will crash if: f never called, or f called more than once.
32 class CallChecker {
33  public:
34  explicit CallChecker(bool optional) : optional_(optional) {}
37  }
38 
39  void Called() {
41  called_ = true;
42  }
43 
44  static std::shared_ptr<CallChecker> Make() {
45  return std::make_shared<CallChecker>(false);
46  }
47 
48  static std::shared_ptr<CallChecker> MakeOptional() {
49  return std::make_shared<CallChecker>(true);
50  }
51 
52  private:
53  bool called_ = false;
54  const bool optional_ = false;
55 };
56 
57 } // namespace testing
58 } // namespace grpc_core
59 
60 #endif // LOCAL_GOOGLE_HOME_CTILLER_GRPC_TEST_CORE_RESOURCE_QUOTA_CALL_CHECKER_H_
testing
Definition: aws_request_signer_test.cc:25
log.h
grpc_core::testing::CallChecker::CallChecker
CallChecker(bool optional)
Definition: call_checker.h:34
grpc_core
Definition: call_metric_recorder.h:31
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
grpc_core::testing::CallChecker::MakeOptional
static std::shared_ptr< CallChecker > MakeOptional()
Definition: call_checker.h:48
grpc_core::testing::CallChecker::~CallChecker
~CallChecker()
Definition: call_checker.h:35
grpc_core::testing::CallChecker::optional_
const bool optional_
Definition: call_checker.h:54
grpc_core::testing::CallChecker::called_
bool called_
Definition: call_checker.h:53
grpc_core::testing::CallChecker
Definition: call_checker.h:32
grpc_core::testing::CallChecker::Called
void Called()
Definition: call_checker.h:39
grpc_core::testing::CallChecker::Make
static std::shared_ptr< CallChecker > Make()
Definition: call_checker.h:44


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:42