blob: abb690c626a4518219fd48fd05965de004a4c258 [file] [log] [blame]
Pavel Labath97b215a2018-10-17 18:50:25 +00001//===------------------ ItaniumDemangleTest.cpp ---------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/Demangle/ItaniumDemangle.h"
11#include "llvm/Support/Allocator.h"
12#include "gmock/gmock.h"
13#include "gtest/gtest.h"
14#include <cstdlib>
15#include <vector>
16
17using namespace llvm;
18using namespace llvm::itanium_demangle;
19
20namespace {
21class TestAllocator {
22 BumpPtrAllocator Alloc;
23
24public:
25 void reset() { Alloc.Reset(); }
26
27 template <typename T, typename... Args> T *makeNode(Args &&... args) {
28 return new (Alloc.Allocate(sizeof(T), alignof(T)))
29 T(std::forward<Args>(args)...);
30 }
31
32 void *allocateNodeArray(size_t sz) {
33 return Alloc.Allocate(sizeof(Node *) * sz, alignof(Node *));
34 }
35};
36} // namespace
37
38TEST(ItaniumDemangle, MethodOverride) {
39 struct TestParser : AbstractManglingParser<TestParser, TestAllocator> {
40 std::vector<char> Types;
41
42 TestParser(const char *Str)
43 : AbstractManglingParser(Str, Str + strlen(Str)) {}
44
45 Node *parseType() {
46 Types.push_back(*First);
47 return AbstractManglingParser<TestParser, TestAllocator>::parseType();
48 }
49 };
50
51 TestParser Parser("_Z1fIiEjl");
52 ASSERT_NE(nullptr, Parser.parse());
53 EXPECT_THAT(Parser.Types, testing::ElementsAre('i', 'j', 'l'));
54}