From f57187842a752d6ea339c3daaf2c8a42ed5e7822 Mon Sep 17 00:00:00 2001 From: Sergiu Deitsch Date: Fri, 1 Nov 2024 15:03:36 +0100 Subject: [PATCH] rework unit tests --- CMakeLists.txt | 4 ---- src/demangle_unittest.cc | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 59bac783e..c3fc1a238 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/demangle_unittest.cc b/src/demangle_unittest.cc index a85166463..2dcbd34fe 100644 --- a/src/demangle_unittest.cc +++ b/src/demangle_unittest.cc @@ -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 @@ -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