1 //===------------------ DLangDemangleTest.cpp -----------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Demangle/Demangle.h"
10 #include "gmock/gmock.h"
11 #include "gtest/gtest.h"
14 #include <string_view>
17 struct DLangDemangleTestFixture
18 : public testing::TestWithParam
<std::pair
<std::string_view
, const char *>> {
21 void SetUp() override
{ Demangled
= llvm::dlangDemangle(GetParam().first
); }
23 void TearDown() override
{ std::free(Demangled
); }
26 TEST_P(DLangDemangleTestFixture
, DLangDemangleTest
) {
27 EXPECT_STREQ(Demangled
, GetParam().second
);
30 INSTANTIATE_TEST_SUITE_P(
31 DLangDemangleTest
, DLangDemangleTestFixture
,
33 std::make_pair("_Dmain", "D main"), std::make_pair("_Z", nullptr),
34 std::make_pair("_DDD", nullptr), std::make_pair("_D88", nullptr),
35 std::make_pair("_D8demangleZ", "demangle"),
36 std::make_pair("_D8demangle4testZ", "demangle.test"),
37 std::make_pair("_D8demangle4test5test2Z", "demangle.test.test2"),
38 std::make_pair("_D8demangle4test0Z", "demangle.test"),
39 std::make_pair("_D8demangle4test03fooZ", "demangle.test.foo"),
40 std::make_pair("_D8demangle4test6__initZ",
41 "initializer for demangle.test"),
42 std::make_pair("_D8demangle4test6__vtblZ", "vtable for demangle.test"),
43 std::make_pair("_D8demangle4test7__ClassZ",
44 "ClassInfo for demangle.test"),
45 std::make_pair("_D8demangle4test11__InterfaceZ",
46 "Interface for demangle.test"),
47 std::make_pair("_D8demangle4test12__ModuleInfoZ",
48 "ModuleInfo for demangle.test"),
49 std::make_pair("_D8demangle4__S14testZ", "demangle.test"),
50 std::make_pair("_D8demangle4__Sd4testZ", "demangle.__Sd.test"),
51 std::make_pair("_D8demangle3fooi", "demangle.foo"),
52 std::make_pair("_D8demangle3foo",
53 nullptr), // symbol without a type sequence.
54 std::make_pair("_D8demangle3fooinvalidtypeseq",
55 nullptr), // invalid type sequence.
57 "_D8demangle3ABCQe1ai",
58 "demangle.ABC.ABC.a"), // symbol back reference: `Qe` is a back
59 // reference for position 5, counting from e
60 // char, so decoding it points to `3`. Since
61 // `3` is a number, 3 chars get read and it
63 std::make_pair("_D8demangle3ABCQa1ai",
64 nullptr), // invalid symbol back reference (recursive).
65 std::make_pair("_D8demangleQDXXXXXXXXXXXXx",
66 nullptr), // overflow back reference position.
68 "_D8demangle4ABCi1aQd",
69 "demangle.ABCi.a"), // type back reference: `Qd` is a back reference
70 // for position 4, counting from `d` char, so
71 // decoding it points to `i`.
72 std::make_pair("_D8demangle3fooQXXXx",
73 nullptr), // invalid type back reference position.
74 std::make_pair("_D8demangle5recurQa",
75 nullptr))); // invalid type back reference (recursive).