diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 13833beb32c06257a9ba425d760d5c5eeb5525b2..027b1293fd477360d3dffc78da4ab1f2417ee3a6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -57,6 +57,7 @@ add_executable (unit_tests test_CRSGraph.cpp test_CRSMatrix.cpp test_DataVariant.cpp + test_Demangle.cpp test_DoWhileProcessor.cpp test_EmbeddedData.cpp test_ExecutionPolicy.cpp diff --git a/tests/test_Demangle.cpp b/tests/test_Demangle.cpp new file mode 100644 index 0000000000000000000000000000000000000000..057bf9db93e42dc3115e7d7619ef887109dfd21a --- /dev/null +++ b/tests/test_Demangle.cpp @@ -0,0 +1,42 @@ +#ifndef TEST_DEMANGLE_HPP +#define TEST_DEMANGLE_HPP + +#include <catch2/catch.hpp> + +#include <utils/Demangle.hpp> + +#include <cxxabi.h> + +// clazy:excludeall=non-pod-global-static + +TEST_CASE("Demangle", "[utils]") +{ + SECTION("demangle success") + { + const std::string mangled = typeid(std::string).name(); + + int status = -1; + char* cxa_demangled = abi::__cxa_demangle(mangled.data(), NULL, NULL, &status); + + REQUIRE(status == 0); + + std::string demangled{cxa_demangled}; + free(cxa_demangled); + + REQUIRE(demangled == demangle<std::string>()); + } + + SECTION("demangle failed") + { + const std::string mangled = "not_mangled"; + + int status = -1; + abi::__cxa_demangle(mangled.data(), NULL, NULL, &status); + + REQUIRE(status != 0); + + REQUIRE((std::string{"not_mangled"} == demangle("not_mangled"))); + } +} + +#endif // TEST_DEMANGLE_HPP