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.
17 #include <folly/Demangle.h>
19 #include <gtest/gtest.h>
21 using folly::demangle;
23 namespace folly_test {
24 struct ThisIsAVeryLongStructureName {
26 } // namespace folly_test
28 #if FOLLY_HAVE_CPLUS_DEMANGLE_V3_CALLBACK
29 TEST(Demangle, demangle) {
30 char expected[] = "folly_test::ThisIsAVeryLongStructureName";
33 demangle(typeid(folly_test::ThisIsAVeryLongStructureName)).c_str());
36 char buf[sizeof(expected)];
37 EXPECT_EQ(sizeof(expected) - 1,
38 demangle(typeid(folly_test::ThisIsAVeryLongStructureName),
40 EXPECT_STREQ(expected, buf);
42 EXPECT_EQ(sizeof(expected) - 1,
43 demangle(typeid(folly_test::ThisIsAVeryLongStructureName),
45 EXPECT_STREQ("folly_test", buf);
50 TEST(Demangle, strlcpy) {
53 EXPECT_EQ(3, folly::strlcpy(buf, "abc", 6));
54 EXPECT_EQ('\0', buf[3]);
55 EXPECT_EQ("abc", std::string(buf));
57 EXPECT_EQ(7, folly::strlcpy(buf, "abcdefg", 3));
58 EXPECT_EQ('\0', buf[2]);
59 EXPECT_EQ("ab", std::string(buf));
61 const char* big_string = "abcdefghijklmnop";
63 EXPECT_EQ(strlen(big_string), folly::strlcpy(buf, big_string, sizeof(buf)));
64 EXPECT_EQ('\0', buf[5]);
65 EXPECT_EQ("abcde", std::string(buf));
68 EXPECT_EQ(strlen(big_string), folly::strlcpy(buf, big_string, 0));
69 EXPECT_EQ('z', buf[0]); // unchanged, size = 0