context_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 "gtest/gtest.h"
18 
19 namespace grpc_core {
20 
21 struct TestContext {
22  bool done = false;
23 };
24 
25 template <>
26 struct ContextType<TestContext> {};
27 
28 TEST(Context, WithContext) {
29  EXPECT_EQ(GetContext<TestContext>(), nullptr);
31  EXPECT_EQ(GetContext<TestContext>(), nullptr);
32  EXPECT_EQ(test.done, false);
33  WithContext([]() { GetContext<TestContext>()->done = true; }, &test)();
34  EXPECT_EQ(test.done, true);
35 }
36 
37 } // namespace grpc_core
38 
39 int main(int argc, char** argv) {
40  ::testing::InitGoogleTest(&argc, argv);
41  return RUN_ALL_TESTS();
42 }
grpc_core
Definition: call_metric_recorder.h:31
test
Definition: spinlock_test.cc:36
grpc_core::TEST
TEST(AvlTest, NoOp)
Definition: avl_test.cc:21
test::done
int done
Definition: sync_test.cc:143
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
grpc_core::ContextType
Definition: core/lib/promise/context.h:32
grpc_core::TestContext
promise_detail::Context< T > TestContext
Definition: test_context.h:23
grpc_core::TestContext
Definition: activity_test.cc:248
main
int main(int argc, char **argv)
Definition: context_test.cc:39
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
grpc_core::WithContext
promise_detail::WithContext< T, F > WithContext(F f, T *context)
Definition: core/lib/promise/context.h:80
update_failure_list.test
test
Definition: bloaty/third_party/protobuf/conformance/update_failure_list.py:69
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
grpc_core::TestContext::done
bool * done
Definition: activity_test.cc:249
context.h


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