test/core/gprpp/match_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 namespace testing {
21 
22 TEST(MatchTest, Test) {
24  absl::variant<int, double>(1.9), [](int) -> int { abort(); },
25  [](double x) -> int {
26  EXPECT_EQ(x, 1.9);
27  return 42;
28  }),
29  42);
32  [](int x) -> int {
33  EXPECT_EQ(x, 3);
34  return 42;
35  },
36  [](double) -> int { abort(); }),
37  42);
38 }
39 
40 TEST(MatchTest, TestVoidReturn) {
41  bool triggered = false;
42  Match(
43  absl::variant<int, double>(1.9), [](int) { abort(); },
44  [&triggered](double x) {
45  EXPECT_EQ(x, 1.9);
46  triggered = true;
47  });
48  EXPECT_TRUE(triggered);
49 }
50 
51 TEST(MatchTest, TestMutable) {
54  &v, [](int*) { abort(); }, [](double* x) { *x = 0.0; });
56 }
57 
58 TEST(MatchTest, TestMutableWithReturn) {
61  &v, [](int*) -> int { abort(); },
62  [](double* x) -> int {
63  *x = 0.0;
64  return 1;
65  }),
66  1);
68 }
69 
70 } // namespace testing
71 } // namespace grpc_core
72 
73 int main(int argc, char** argv) {
74  ::testing::InitGoogleTest(&argc, argv);
75  return RUN_ALL_TESTS();
76 }
testing
Definition: aws_request_signer_test.cc:25
main
int main(int argc, char **argv)
Definition: test/core/gprpp/match_test.cc:73
grpc_core
Definition: call_metric_recorder.h:31
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
setup.v
v
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
x
int x
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
grpc_core::Match
auto Match(const absl::variant< T0, Ts... > &value, Fs... fs) -> decltype(std::declval< OverloadType< Fs... >>()(std::declval< T0 >()))
Definition: src/core/lib/gprpp/match.h:51
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
absl::variant
Definition: abseil-cpp/absl/types/internal/variant.h:46
match.h
grpc_core::MatchMutable
auto MatchMutable(absl::variant< T0, Ts... > *value, Fs... fs) -> decltype(std::declval< OverloadType< Fs... >>()(std::declval< T0 * >()))
Definition: src/core/lib/gprpp/match.h:66
Test
Definition: hpack_parser_test.cc:43


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:22