Re-sync with internal repository
[hiphop-php.git] / third-party / thrift / src / thrift / test / reflection / visitation_transitivity_test.cpp
blobb9e9df5636fe8a319728d7d7336ebb4216f8f118
1 /*
2 * Copyright (c) Facebook, Inc. and its affiliates.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <thrift/test/reflection/gen-cpp2/reflection_visitation.h>
19 #include <folly/Overload.h>
20 #include <folly/portability/GTest.h>
22 using namespace apache::thrift;
23 using namespace std;
25 namespace test_cpp2 {
26 namespace cpp_reflection {
27 TEST(dep_C_struct, test_transitivity) {
28 dep_C_struct s;
29 s.i_c() = 10;
30 s.d()->i_d() = 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 });
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 });
48 } // namespace cpp_reflection
49 } // namespace test_cpp2