2 * Copyright 2013 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);
49 void test() const volatile;
65 void test() const volatile;
68 #define LOG_VALUE(x) []() { \
69 LOG(INFO) << #x << ": " << boolalpha << (x); \
73 TEST(HasMemberFnTraits, DirectMembers) {
74 EXPECT_TRUE(LOG_VALUE((has_test<Foo, int()>::value)));
75 EXPECT_TRUE(LOG_VALUE((has_test<Foo, int() const>::value)));
76 EXPECT_FALSE(LOG_VALUE((has_test<Foo, double(int, long)>::value)));
77 EXPECT_TRUE(LOG_VALUE((has_test<Foo, string(const string&) const>::value)));
78 EXPECT_FALSE(LOG_VALUE((has_test<Foo, long(int) const>::value)));
79 EXPECT_FALSE(LOG_VALUE((has_test<Foo, string(string) const>::value)));
81 EXPECT_TRUE(LOG_VALUE((has_test<Bar, int()>::value)));
82 EXPECT_FALSE(LOG_VALUE((has_test<Bar, int() const>::value)));
83 EXPECT_TRUE(LOG_VALUE((has_test<Bar, double(int, long)>::value)));
84 EXPECT_FALSE(LOG_VALUE((has_test<Bar, string(const string&) const>::value)));
85 EXPECT_TRUE(LOG_VALUE((has_test<Bar, long(int) const>::value)));
86 EXPECT_FALSE(LOG_VALUE((has_test<Bar, string(string) const>::value)));
88 EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void()>::value)));
89 EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() const>::value)));
90 EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() volatile>::value)));
91 EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() const volatile>::value)));
92 EXPECT_TRUE(LOG_VALUE((has_test<Gaz, void() volatile const>::value)));
94 EXPECT_TRUE(LOG_VALUE((has_test<NoCV, void()>::value)));
95 EXPECT_FALSE(LOG_VALUE((has_test<NoCV, void() const>::value)));
96 EXPECT_FALSE(LOG_VALUE((has_test<NoCV, void() volatile>::value)));
97 EXPECT_FALSE(LOG_VALUE((has_test<NoCV, void() const volatile>::value)));
98 EXPECT_FALSE(LOG_VALUE((has_test<NoCV, void() volatile const>::value)));
100 EXPECT_FALSE(LOG_VALUE((has_test<Const, void()>::value)));
101 EXPECT_TRUE(LOG_VALUE((has_test<Const, void() const>::value)));
102 EXPECT_FALSE(LOG_VALUE((has_test<Const, void() volatile>::value)));
103 EXPECT_FALSE(LOG_VALUE((has_test<Const, void() const volatile>::value)));
104 EXPECT_FALSE(LOG_VALUE((has_test<Const, void() volatile const>::value)));
106 EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void()>::value)));
107 EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void() const>::value)));
108 EXPECT_TRUE(LOG_VALUE((has_test<Volatile, void() volatile>::value)));
109 EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void() const volatile>::value)));
110 EXPECT_FALSE(LOG_VALUE((has_test<Volatile, void() volatile const>::value)));
112 EXPECT_FALSE(LOG_VALUE((has_test<CV, void()>::value)));
113 EXPECT_FALSE(LOG_VALUE((has_test<CV, void() const>::value)));
114 EXPECT_FALSE(LOG_VALUE((has_test<CV, void() volatile>::value)));
115 EXPECT_TRUE(LOG_VALUE((has_test<CV, void() const volatile>::value)));
116 EXPECT_TRUE(LOG_VALUE((has_test<CV, void() volatile const>::value)));
119 int main(int argc, char *argv[]) {
120 testing::InitGoogleTest(&argc, argv);
121 return RUN_ALL_TESTS();