2 * Copyright 2016 Facebook, Inc.
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.
18 * @author: Marcelo Juchem <marcelo@fb.com>
21 #include <folly/Traits.h>
23 #include <folly/portability/GTest.h>
25 #include <glog/logging.h>
30 using namespace folly;
32 FOLLY_CREATE_HAS_MEMBER_FN_TRAITS(has_test, test);
37 string test(const string&) const;
42 double test(int,long);
49 void test() /* nolint */ volatile;
50 void test() const /* nolint */ volatile;
62 void test() /* nolint */ volatile;
66 void test() const /* nolint */ volatile;
69 bool log_value(const char* what, bool result) {
70 LOG(INFO) << what << ": " << boolalpha << result;
74 #define LOG_VALUE(x) log_value(#x, x)
76 TEST(HasMemberFnTraits, DirectMembers) {
77 EXPECT_TRUE(LOG_VALUE((has_test<Foo, int()>::value)));
78 EXPECT_TRUE(LOG_VALUE((has_test<Foo, int() const>::value)));
79 EXPECT_FALSE(LOG_VALUE((has_test<Foo, double(int, long)>::value)));
80 EXPECT_TRUE(LOG_VALUE((has_test<Foo, string(const string&) const>::value)));
81 EXPECT_FALSE(LOG_VALUE((has_test<Foo, long(int) const>::value)));
82 EXPECT_FALSE(LOG_VALUE((has_test<Foo, string(string) const>::value)));
84 EXPECT_TRUE(LOG_VALUE((has_test<Bar, int()>::value)));
85 EXPECT_FALSE(LOG_VALUE((has_test<Bar, int() const>::value)));
86 EXPECT_TRUE(LOG_VALUE((has_test<Bar, double(int, long)>::value)));
87 EXPECT_FALSE(LOG_VALUE((has_test<Bar, string(const string&) const>::value)));
88 EXPECT_TRUE(LOG_VALUE((has_test<Bar, long(int) const>::value)));
89 EXPECT_FALSE(LOG_VALUE((has_test<Bar, string(string) const>::value)));
91 EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void()>::value)));
92 EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() const>::value)));
93 EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() /* nolint */ volatile>::value)));
94 EXPECT_TRUE(LOG_VALUE((
95 has_test<Gaz, void() const /* nolint */ volatile>::value)));
96 EXPECT_TRUE(LOG_VALUE((
97 has_test<Gaz, void() /* nolint */ volatile const>::value)));
99 EXPECT_TRUE(LOG_VALUE((has_test<NoCV, void()>::value)));
100 EXPECT_FALSE(LOG_VALUE((has_test<NoCV, void() const>::value)));
101 EXPECT_FALSE(LOG_VALUE((
102 has_test<NoCV, void() /* nolint */ volatile>::value)));
103 EXPECT_FALSE(LOG_VALUE((
104 has_test<NoCV, void() const /* nolint */ volatile>::value)));
105 EXPECT_FALSE(LOG_VALUE((
106 has_test<NoCV, void() /* nolint */ volatile const>::value)));
108 EXPECT_FALSE(LOG_VALUE((has_test<Const, void()>::value)));
109 EXPECT_TRUE(LOG_VALUE((has_test<Const, void() const>::value)));
110 EXPECT_FALSE(LOG_VALUE((
111 has_test<Const, void() /* nolint */ volatile>::value)));
112 EXPECT_FALSE(LOG_VALUE((
113 has_test<Const, void() const /* nolint */ volatile>::value)));
114 EXPECT_FALSE(LOG_VALUE((
115 has_test<Const, void() /* nolint */ volatile const>::value)));
117 EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void()>::value)));
118 EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void() const>::value)));
119 EXPECT_TRUE(LOG_VALUE((
120 has_test<Volatile, void() /* nolint */ volatile>::value)));
121 EXPECT_FALSE(LOG_VALUE((
122 has_test<Volatile, void() const /* nolint */ volatile>::value)));
123 EXPECT_FALSE(LOG_VALUE((
124 has_test<Volatile, void() /* nolint */ volatile const>::value)));
126 EXPECT_FALSE(LOG_VALUE((has_test<CV, void()>::value)));
127 EXPECT_FALSE(LOG_VALUE((has_test<CV, void() const>::value)));
128 EXPECT_FALSE(LOG_VALUE((
129 has_test<CV, void() /* nolint */ volatile>::value)));
130 EXPECT_TRUE(LOG_VALUE((
131 has_test<CV, void() const /* nolint */ volatile>::value)));
132 EXPECT_TRUE(LOG_VALUE((
133 has_test<CV, void() /* nolint */ volatile const>::value)));
136 int main(int argc, char *argv[]) {
137 testing::InitGoogleTest(&argc, argv);
138 return RUN_ALL_TESTS();