From 525ced2d1d0a4864b401d3df840afc3ebc8e695a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com> Date: Mon, 2 Nov 2020 23:51:54 +0100 Subject: [PATCH] Add Demangle tests --- tests/CMakeLists.txt | 1 + tests/test_Demangle.cpp | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/test_Demangle.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 13833beb3..027b1293f 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 000000000..057bf9db9 --- /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 -- GitLab