Skip to content

Commit

Permalink
rework unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiud committed Nov 1, 2024
1 parent 5fd3750 commit f571878
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,6 @@ if (BUILD_TESTING)

add_test (NAME demangle COMMAND demangle_unittest)

if (HAVE___CXA_DEMANGLE)
# Demangle tests use a different (reduced) representation of symbols
set_tests_properties (demangle PROPERTIES DISABLED ON)
endif (HAVE___CXA_DEMANGLE)

if (HAVE_STACKTRACE)
add_executable (stacktrace_unittest
Expand Down
19 changes: 15 additions & 4 deletions src/demangle_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,10 @@ TEST(Demangle, CornerCases) {
EXPECT_STREQ(demangled, tmp);
EXPECT_TRUE(Demangle(mangled, tmp, size - 1));
EXPECT_STREQ(demangled, tmp);
EXPECT_FALSE(Demangle(mangled, tmp, size - 2)); // Not enough.
EXPECT_FALSE(Demangle(mangled, tmp, 1));
EXPECT_FALSE(Demangle(mangled, tmp, 0));
EXPECT_FALSE(Demangle(mangled, nullptr, 0)); // Should not cause SEGV.
}

// Demangle tests use a different (reduced) representation of symbols
# if !defined(HAVE___CXA_DEMANGLE)
// Test handling of functions suffixed with .clone.N, which is used by GCC
// 4.5.x, and .constprop.N and .isra.N, which are used by GCC 4.6.x. These
// suffixes are used to indicate functions which have been cloned during
Expand Down Expand Up @@ -141,6 +139,19 @@ TEST(Demangle, FromFile) {
EXPECT_EQ(demangled, DemangleIt(mangled.c_str()));
}
}
# endif // defined(HAVE___CXA_DEMANGLE)

TEST(Demangle, SmallBuffer) {
constexpr std::size_t size = 10;
char tmp[size];
const char* const mangled = "_Z6foobarv";
EXPECT_FALSE(Demangle(mangled, tmp, size - 2)); // Not enough.
EXPECT_FALSE(Demangle(mangled, tmp, 1));
EXPECT_FALSE(Demangle(mangled, tmp, 0));
EXPECT_FALSE(Demangle(mangled, nullptr, 0)); // Should not cause SEGV.
EXPECT_FALSE(Demangle("", tmp, sizeof(tmp)));
EXPECT_TRUE(Demangle("_Z3foo", nullptr, 0));
}

#endif

Expand Down

0 comments on commit f571878

Please sign in to comment.