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 <gtest/gtest.h>
24 #include <glog/logging.h>
29 using namespace folly;
31 FOLLY_CREATE_HAS_MEMBER_FN_TRAITS(has_test, test);
36 string test(const string&) const;
41 double test(int,long);
48 void test() /* nolint */ volatile;
49 void test() const /* nolint */ volatile;
61 void test() /* nolint */ volatile;
65 void test() const /* nolint */ volatile;
68 bool log_value(const char* what, bool result) {
69 LOG(INFO) << what << ": " << boolalpha << result;
73 #define LOG_VALUE(x) log_value(#x, x)
75 TEST(HasMemberFnTraits, DirectMembers) {
76 EXPECT_TRUE(LOG_VALUE((has_test<Foo, int()>::value)));
77 EXPECT_TRUE(LOG_VALUE((has_test<Foo, int() const>::value)));
78 EXPECT_FALSE(LOG_VALUE((has_test<Foo, double(int, long)>::value)));
79 EXPECT_TRUE(LOG_VALUE((has_test<Foo, string(const string&) const>::value)));
80 EXPECT_FALSE(LOG_VALUE((has_test<Foo, long(int) const>::value)));
81 EXPECT_FALSE(LOG_VALUE((has_test<Foo, string(string) const>::value)));
83 EXPECT_TRUE(LOG_VALUE((has_test<Bar, int()>::value)));
84 EXPECT_FALSE(LOG_VALUE((has_test<Bar, int() const>::value)));
85 EXPECT_TRUE(LOG_VALUE((has_test<Bar, double(int, long)>::value)));
86 EXPECT_FALSE(LOG_VALUE((has_test<Bar, string(const string&) const>::value)));
87 EXPECT_TRUE(LOG_VALUE((has_test<Bar, long(int) const>::value)));
88 EXPECT_FALSE(LOG_VALUE((has_test<Bar, string(string) const>::value)));
90 EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void()>::value)));
91 EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() const>::value)));
92 EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() /* nolint */ volatile>::value)));
93 EXPECT_TRUE(LOG_VALUE((
94 has_test<Gaz, void() const /* nolint */ volatile>::value)));
95 EXPECT_TRUE(LOG_VALUE((
96 has_test<Gaz, void() /* nolint */ volatile const>::value)));
98 EXPECT_TRUE(LOG_VALUE((has_test<NoCV, void()>::value)));
99 EXPECT_FALSE(LOG_VALUE((has_test<NoCV, void() const>::value)));
100 EXPECT_FALSE(LOG_VALUE((
101 has_test<NoCV, void() /* nolint */ volatile>::value)));
102 EXPECT_FALSE(LOG_VALUE((
103 has_test<NoCV, void() const /* nolint */ volatile>::value)));
104 EXPECT_FALSE(LOG_VALUE((
105 has_test<NoCV, void() /* nolint */ volatile const>::value)));
107 EXPECT_FALSE(LOG_VALUE((has_test<Const, void()>::value)));
108 EXPECT_TRUE(LOG_VALUE((has_test<Const, void() const>::value)));
109 EXPECT_FALSE(LOG_VALUE((
110 has_test<Const, void() /* nolint */ volatile>::value)));
111 EXPECT_FALSE(LOG_VALUE((
112 has_test<Const, void() const /* nolint */ volatile>::value)));
113 EXPECT_FALSE(LOG_VALUE((
114 has_test<Const, void() /* nolint */ volatile const>::value)));
116 EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void()>::value)));
117 EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void() const>::value)));
118 EXPECT_TRUE(LOG_VALUE((
119 has_test<Volatile, void() /* nolint */ volatile>::value)));
120 EXPECT_FALSE(LOG_VALUE((
121 has_test<Volatile, void() const /* nolint */ volatile>::value)));
122 EXPECT_FALSE(LOG_VALUE((
123 has_test<Volatile, void() /* nolint */ volatile const>::value)));
125 EXPECT_FALSE(LOG_VALUE((has_test<CV, void()>::value)));
126 EXPECT_FALSE(LOG_VALUE((has_test<CV, void() const>::value)));
127 EXPECT_FALSE(LOG_VALUE((
128 has_test<CV, void() /* nolint */ volatile>::value)));
129 EXPECT_TRUE(LOG_VALUE((
130 has_test<CV, void() const /* nolint */ volatile>::value)));
131 EXPECT_TRUE(LOG_VALUE((
132 has_test<CV, void() /* nolint */ volatile const>::value)));
135 int main(int argc, char *argv[]) {
136 testing::InitGoogleTest(&argc, argv);
137 return RUN_ALL_TESTS();