1 /*
2  * Copyright (c) Facebook, Inc. and its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <thrift/test/reflection/gen-cpp2/reflection_visitation.h>
18 
19 #include <folly/Overload.h>
20 #include <folly/portability/GTest.h>
21 
22 using namespace apache::thrift;
23 using namespace std;
24 
25 namespace test_cpp2 {
26 namespace cpp_reflection {
TEST(dep_C_struct,test_transitivity)27 TEST(dep_C_struct, test_transitivity) {
28   dep_C_struct s;
29   s.i_c_ref() = 10;
30   s.d_ref()->i_d_ref() = 20;
31   for_each_field(s, [](auto&&, auto&& ref) {
32     folly::overload(
33         [](int32_t i) { EXPECT_EQ(i, 10); },
34         [](dep_D_struct d) {
35           for_each_field(d, [](auto&&, auto&& ref) { EXPECT_EQ(*ref, 20); });
36         })(*ref);
37   });
38 }
TEST(union1,test_union)39 TEST(union1, test_union) {
40   union1 s;
41   s.us_ref() = "foo";
42   visit_union(s, [](auto&&, auto&& value) {
43     folly::overload(
44         [](string& s) { EXPECT_EQ(s, "foo"); },
45         [](auto&&) { EXPECT_TRUE(false); })(value);
46   });
47 }
48 } // namespace cpp_reflection
49 } // namespace test_cpp2
50