single_set_ptr_test.cc
Go to the documentation of this file.
1 // Copyright 2022 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 <thread>
18 
19 #include <gtest/gtest.h>
20 
21 namespace grpc_core {
22 namespace testing {
23 
24 TEST(SingleSetPtrTest, NoOp) { SingleSetPtr<int>(); }
25 
26 TEST(SingleSetPtrTest, CanSet) {
28  EXPECT_FALSE(p.is_set());
30  p.Set(new int(42));
31  EXPECT_EQ(*p, 42);
32 }
33 
34 TEST(SingleSetPtrTest, CanReset) {
36  EXPECT_FALSE(p.is_set());
37  p.Set(new int(42));
38  EXPECT_TRUE(p.is_set());
39  p.Set(new int(43));
40  EXPECT_EQ(*p, 42);
41  p.Reset();
42  EXPECT_FALSE(p.is_set());
43 }
44 
45 TEST(SingleSetPtrTest, LotsOfSetters) {
47  std::vector<std::thread> threads;
48  threads.reserve(100);
49  for (int i = 0; i < 100; i++) {
50  threads.emplace_back([&p, i]() { p.Set(new int(i)); });
51  }
52  for (auto& t : threads) {
53  t.join();
54  }
55 }
56 
57 } // namespace testing
58 } // namespace grpc_core
59 
60 int main(int argc, char** argv) {
61  ::testing::InitGoogleTest(&argc, argv);
62  return RUN_ALL_TESTS();
63 }
EXPECT_FALSE
#define EXPECT_FALSE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1970
testing
Definition: aws_request_signer_test.cc:25
main
int main(int argc, char **argv)
Definition: single_set_ptr_test.cc:60
NoOp
Definition: bm_call_create.cc:477
grpc_core
Definition: call_metric_recorder.h:31
threads
static uv_thread_t * threads
Definition: threadpool.c:38
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
grpc_core::SingleSetPtr
Definition: single_set_ptr.h:28
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
single_set_ptr.h
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
GPR_ERROR
#define GPR_ERROR
Definition: include/grpc/impl/codegen/log.h:57
EXPECT_DEATH_IF_SUPPORTED
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest-death-test.h:335
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
grpc_core::testing::TEST
TEST(ServiceConfigParserTest, DoubleRegistration)
Definition: service_config_test.cc:448
EXPECT_TRUE
#define EXPECT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1967
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:13