Refactor tests to verify that a single folly target can be used successfully
[folly.git] / folly / test / DemangleTest.cpp
1 /*
2  * Copyright 2015 Facebook, Inc.
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 <folly/Demangle.h>
18
19 #include <gflags/gflags.h>
20 #include <gtest/gtest.h>
21
22 using folly::demangle;
23
24 namespace folly_test {
25 struct ThisIsAVeryLongStructureName {
26 };
27 }  // namespace folly_test
28
29 #if FOLLY_HAVE_CPLUS_DEMANGLE_V3_CALLBACK
30 TEST(Demangle, demangle) {
31   char expected[] = "folly_test::ThisIsAVeryLongStructureName";
32   EXPECT_STREQ(
33       expected,
34       demangle(typeid(folly_test::ThisIsAVeryLongStructureName)).c_str());
35
36   {
37     char buf[sizeof(expected)];
38     EXPECT_EQ(sizeof(expected) - 1,
39               demangle(typeid(folly_test::ThisIsAVeryLongStructureName),
40                        buf, sizeof(buf)));
41     EXPECT_STREQ(expected, buf);
42
43     EXPECT_EQ(sizeof(expected) - 1,
44               demangle(typeid(folly_test::ThisIsAVeryLongStructureName),
45                        buf, 11));
46     EXPECT_STREQ("folly_test", buf);
47   }
48 }
49 #endif
50
51 int main(int argc, char *argv[]) {
52   testing::InitGoogleTest(&argc, argv);
53   gflags::ParseCommandLineFlags(&argc, &argv, true);
54   return RUN_ALL_TESTS();
55 }