blob: f56a9be3cc246a1433e4652b378703a72cca8c4e [file] [log] [blame]
Christopher Ferris9323b722017-03-03 17:43:14 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdlib.h>
18
19#include <gtest/gtest.h>
20
21#include <demangle.h>
22
23#include "Demangler.h"
24
Christopher Ferris15d2e422017-05-31 14:40:15 -070025TEST(DemangleTest, IllegalArgumentModifiers) {
26 Demangler demangler;
27
28 ASSERT_EQ("_Zpp4FUNKK", demangler.Parse("_Zpp4FUNKK"));
29 ASSERT_EQ("_Zpp4FUNVV", demangler.Parse("_Zpp4FUNVV"));
30}
31
32TEST(DemangleTest, VoidArgument) {
Christopher Ferris9323b722017-03-03 17:43:14 -080033 Demangler demangler;
34
35 ASSERT_EQ("func()", demangler.Parse("_ZN4funcEv"));
36 ASSERT_EQ("func(void&)", demangler.Parse("_ZN4funcERv"));
37 ASSERT_EQ("func(void, void)", demangler.Parse("_ZN4funcEvv"));
38 ASSERT_EQ("func(void*)", demangler.Parse("_ZN4funcEPv"));
39 ASSERT_EQ("func(void const)", demangler.Parse("_ZN4funcEKv"));
40 ASSERT_EQ("func(void volatile)", demangler.Parse("_ZN4funcEVv"));
41}
42
43TEST(DemangleTest, ArgumentModifiers) {
44 Demangler demangler;
45
46 ASSERT_EQ("func(char)", demangler.Parse("_ZN4funcEc"));
47 ASSERT_EQ("func(char*)", demangler.Parse("_ZN4funcEPc"));
48 ASSERT_EQ("func(char**)", demangler.Parse("_ZN4funcEPPc"));
49 ASSERT_EQ("func(char***)", demangler.Parse("_ZN4funcEPPPc"));
50 ASSERT_EQ("func(char&)", demangler.Parse("_ZN4funcERc"));
51 ASSERT_EQ("func(char*&)", demangler.Parse("_ZN4funcERPc"));
52 ASSERT_EQ("func(char&)", demangler.Parse("_ZN4funcERRc"));
53 ASSERT_EQ("func(char*&*)", demangler.Parse("_ZN4funcEPRPc"));
54 ASSERT_EQ("func(char**&)", demangler.Parse("_ZN4funcERRPPc"));
55 ASSERT_EQ("func(char const)", demangler.Parse("_ZN4funcEKc"));
56 ASSERT_EQ("func(char volatile)", demangler.Parse("_ZN4funcEVc"));
57 ASSERT_EQ("func(char volatile const)", demangler.Parse("_ZN4funcEKVc"));
58 ASSERT_EQ("func(char const volatile)", demangler.Parse("_ZN4funcEVKc"));
59 ASSERT_EQ("func(char const* volatile&)", demangler.Parse("_ZN4funcERVPKc"));
60 ASSERT_EQ("func(void, char, short)", demangler.Parse("_ZN4funcEvcs"));
61 ASSERT_EQ("func(void*, char&, short&*)", demangler.Parse("_ZN4funcEPvRcPRs"));
62}
63
64TEST(DemangleTest, FunctionModifiers) {
65 Demangler demangler;
66
67 ASSERT_EQ("func() const", demangler.Parse("_ZNK4funcEv"));
68 ASSERT_EQ("func() volatile", demangler.Parse("_ZNV4funcEv"));
69 ASSERT_EQ("func() volatile const", demangler.Parse("_ZNKV4funcEv"));
70 ASSERT_EQ("func() const volatile", demangler.Parse("_ZNVK4funcEv"));
71}
72
73TEST(DemangleTest, MultiplePartsInName) {
74 Demangler demangler;
75
76 ASSERT_EQ("one::two()", demangler.Parse("_ZN3one3twoEv"));
77 ASSERT_EQ("one::two::three()", demangler.Parse("_ZN3one3two5threeEv"));
78 ASSERT_EQ("one::two::three::four()", demangler.Parse("_ZN3one3two5three4fourEv"));
79 ASSERT_EQ("one::two::three::four::five()", demangler.Parse("_ZN3one3two5three4four4fiveEv"));
80 ASSERT_EQ("one(two::three::four::five)", demangler.Parse("_ZN3oneEN3two5three4four4fiveE"));
81}
82
83TEST(DemangleTest, AnonymousNamespace) {
84 Demangler demangler;
85
86 ASSERT_EQ("(anonymous namespace)::two()", demangler.Parse("_ZN12_GLOBAL__N_13twoEv"));
87 ASSERT_EQ("one::two((anonymous namespace))", demangler.Parse("_ZN3one3twoE12_GLOBAL__N_1"));
88}
89
90TEST(DemangleTest, DestructorValues) {
91 Demangler demangler;
92
93 ASSERT_EQ("one::two::~two()", demangler.Parse("_ZN3one3twoD0Ev"));
94 ASSERT_EQ("one::two::~two()", demangler.Parse("_ZN3one3twoD1Ev"));
95 ASSERT_EQ("one::two::~two()", demangler.Parse("_ZN3one3twoD2Ev"));
96 ASSERT_EQ("one::two::~two()", demangler.Parse("_ZN3one3twoD5Ev"));
97 ASSERT_EQ("one::two::three::~three()", demangler.Parse("_ZN3one3two5threeD0Ev"));
98
99 ASSERT_EQ("_ZN3one3twoD3Ev", demangler.Parse("_ZN3one3twoD3Ev"));
100 ASSERT_EQ("_ZN3one3twoD4Ev", demangler.Parse("_ZN3one3twoD4Ev"));
101 ASSERT_EQ("_ZN3one3twoD6Ev", demangler.Parse("_ZN3one3twoD6Ev"));
102 ASSERT_EQ("_ZN3one3twoD7Ev", demangler.Parse("_ZN3one3twoD7Ev"));
103 ASSERT_EQ("_ZN3one3twoD8Ev", demangler.Parse("_ZN3one3twoD8Ev"));
104 ASSERT_EQ("_ZN3one3twoD9Ev", demangler.Parse("_ZN3one3twoD9Ev"));
105
106 ASSERT_EQ("one::two<three::four>::~two()", demangler.Parse("_ZN3one3twoIN5three4fourEED2Ev"));
107}
108
109TEST(DemangleTest, ConstructorValues) {
110 Demangler demangler;
111
112 ASSERT_EQ("one::two::two()", demangler.Parse("_ZN3one3twoC1Ev"));
113 ASSERT_EQ("one::two::two()", demangler.Parse("_ZN3one3twoC2Ev"));
114 ASSERT_EQ("one::two::two()", demangler.Parse("_ZN3one3twoC3Ev"));
115 ASSERT_EQ("one::two::two()", demangler.Parse("_ZN3one3twoC5Ev"));
116 ASSERT_EQ("one::two::three::three()", demangler.Parse("_ZN3one3two5threeC1Ev"));
117
118 ASSERT_EQ("_ZN3one3twoC0Ev", demangler.Parse("_ZN3one3twoC0Ev"));
119 ASSERT_EQ("_ZN3one3twoC4Ev", demangler.Parse("_ZN3one3twoC4Ev"));
120 ASSERT_EQ("_ZN3one3twoC6Ev", demangler.Parse("_ZN3one3twoC6Ev"));
121 ASSERT_EQ("_ZN3one3twoC7Ev", demangler.Parse("_ZN3one3twoC7Ev"));
122 ASSERT_EQ("_ZN3one3twoC8Ev", demangler.Parse("_ZN3one3twoC8Ev"));
123 ASSERT_EQ("_ZN3one3twoC9Ev", demangler.Parse("_ZN3one3twoC9Ev"));
124
125 ASSERT_EQ("one::two<three::four>::two()", demangler.Parse("_ZN3one3twoIN5three4fourEEC1Ev"));
126}
127
128TEST(DemangleTest, OperatorValues) {
129 Demangler demangler;
130
131 ASSERT_EQ("operator&&()", demangler.Parse("_Zaav"));
132 ASSERT_EQ("operator&()", demangler.Parse("_Zadv"));
133 ASSERT_EQ("operator&()", demangler.Parse("_Zanv"));
134 ASSERT_EQ("operator&=()", demangler.Parse("_ZaNv"));
135 ASSERT_EQ("operator=()", demangler.Parse("_ZaSv"));
136 ASSERT_EQ("operator()()", demangler.Parse("_Zclv"));
137 ASSERT_EQ("operator,()", demangler.Parse("_Zcmv"));
138 ASSERT_EQ("operator~()", demangler.Parse("_Zcov"));
139 ASSERT_EQ("operator delete[]()", demangler.Parse("_Zdav"));
140 ASSERT_EQ("operator*()", demangler.Parse("_Zdev"));
141 ASSERT_EQ("operator delete()", demangler.Parse("_Zdlv"));
142 ASSERT_EQ("operator/()", demangler.Parse("_Zdvv"));
143 ASSERT_EQ("operator/=()", demangler.Parse("_ZdVv"));
144 ASSERT_EQ("operator^()", demangler.Parse("_Zeov"));
145 ASSERT_EQ("operator^=()", demangler.Parse("_ZeOv"));
146 ASSERT_EQ("operator==()", demangler.Parse("_Zeqv"));
147 ASSERT_EQ("operator>=()", demangler.Parse("_Zgev"));
148 ASSERT_EQ("operator>()", demangler.Parse("_Zgtv"));
149 ASSERT_EQ("operator[]()", demangler.Parse("_Zixv"));
150 ASSERT_EQ("operator<=()", demangler.Parse("_Zlev"));
151 ASSERT_EQ("operator<<()", demangler.Parse("_Zlsv"));
152 ASSERT_EQ("operator<<=()", demangler.Parse("_ZlSv"));
153 ASSERT_EQ("operator<()", demangler.Parse("_Zltv"));
154 ASSERT_EQ("operator-()", demangler.Parse("_Zmiv"));
155 ASSERT_EQ("operator-=()", demangler.Parse("_ZmIv"));
156 ASSERT_EQ("operator*()", demangler.Parse("_Zmlv"));
157 ASSERT_EQ("operator*=()", demangler.Parse("_ZmLv"));
158 ASSERT_EQ("operator--()", demangler.Parse("_Zmmv"));
159 ASSERT_EQ("operator new[]()", demangler.Parse("_Znav"));
160 ASSERT_EQ("operator!=()", demangler.Parse("_Znev"));
161 ASSERT_EQ("operator-()", demangler.Parse("_Zngv"));
162 ASSERT_EQ("operator!()", demangler.Parse("_Zntv"));
163 ASSERT_EQ("operator new()", demangler.Parse("_Znwv"));
164 ASSERT_EQ("operator||()", demangler.Parse("_Zoov"));
165 ASSERT_EQ("operator|()", demangler.Parse("_Zorv"));
166 ASSERT_EQ("operator|=()", demangler.Parse("_ZoRv"));
167 ASSERT_EQ("operator->*()", demangler.Parse("_Zpmv"));
168 ASSERT_EQ("operator+()", demangler.Parse("_Zplv"));
169 ASSERT_EQ("operator+=()", demangler.Parse("_ZpLv"));
170 ASSERT_EQ("operator++()", demangler.Parse("_Zppv"));
171 ASSERT_EQ("operator+()", demangler.Parse("_Zpsv"));
172 ASSERT_EQ("operator->()", demangler.Parse("_Zptv"));
173 ASSERT_EQ("operator?()", demangler.Parse("_Zquv"));
174 ASSERT_EQ("operator%()", demangler.Parse("_Zrmv"));
175 ASSERT_EQ("operator%=()", demangler.Parse("_ZrMv"));
176 ASSERT_EQ("operator>>()", demangler.Parse("_Zrsv"));
177 ASSERT_EQ("operator>>=()", demangler.Parse("_ZrSv"));
178
179 // Spot check using an operator as part of function name.
180 ASSERT_EQ("operator&&()", demangler.Parse("_ZNaaEv"));
181 ASSERT_EQ("operator++()", demangler.Parse("_ZNppEv"));
182 ASSERT_EQ("one::operator++()", demangler.Parse("_ZN3oneppEv"));
183
184 // Spot check using an operator in an argument name.
185 ASSERT_EQ("operator+(operator|=)", demangler.Parse("_ZNpsENoRE"));
186 ASSERT_EQ("operator==()", demangler.Parse("_Zeqv"));
187 ASSERT_EQ("one(arg1::operator|=, arg2::operator==)",
188 demangler.Parse("_ZN3oneEN4arg1oREN4arg2eqE"));
189}
190
191TEST(DemangleTest, FunctionStartsWithNumber) {
192 Demangler demangler;
193
194 ASSERT_EQ("value(char, int)", demangler.Parse("_Z5valueci"));
195 ASSERT_EQ("abcdefjklmn(signed char)", demangler.Parse("_Z11abcdefjklmna"));
196 ASSERT_EQ("value(one, signed char)", demangler.Parse("_Z5value3onea"));
197}
198
Christopher Ferris4504bba2017-06-01 17:37:09 -0700199TEST(DemangleTest, FunctionStartsWithLPlusNumber) {
200 Demangler demangler;
201
202 ASSERT_EQ("value(char, int)", demangler.Parse("_ZL5valueci"));
203 ASSERT_EQ("abcdefjklmn(signed char)", demangler.Parse("_ZL11abcdefjklmna"));
204 ASSERT_EQ("value(one, signed char)", demangler.Parse("_ZL5value3onea"));
205}
206
Christopher Ferris9323b722017-03-03 17:43:14 -0800207TEST(DemangleTest, StdTypes) {
208 Demangler demangler;
209
210 ASSERT_EQ("std::one", demangler.Parse("_ZNSt3oneE"));
211 ASSERT_EQ("std::one(std::two)", demangler.Parse("_ZNSt3oneESt3two"));
212 ASSERT_EQ("std::std::one(std::two)", demangler.Parse("_ZNStSt3oneESt3two"));
213 ASSERT_EQ("std()", demangler.Parse("_ZNStEv"));
214 ASSERT_EQ("one::std::std::two::~two(one::std::std::two)",
215 demangler.Parse("_ZN3oneStSt3twoD0ES0_"));
216
217 ASSERT_EQ("std::allocator", demangler.Parse("_ZNSaE"));
218 ASSERT_EQ("std::basic_string", demangler.Parse("_ZNSbE"));
219 ASSERT_EQ("_ZNScE", demangler.Parse("_ZNScE"));
220 ASSERT_EQ("std::iostream", demangler.Parse("_ZNSdE"));
221 ASSERT_EQ("_ZNSeE", demangler.Parse("_ZNSeE"));
222 ASSERT_EQ("_ZNSfE", demangler.Parse("_ZNSfE"));
223 ASSERT_EQ("_ZNSgE", demangler.Parse("_ZNSgE"));
224 ASSERT_EQ("_ZNShE", demangler.Parse("_ZNShE"));
225 ASSERT_EQ("std::istream", demangler.Parse("_ZNSiE"));
226 ASSERT_EQ("_ZNSjE", demangler.Parse("_ZNSjE"));
227 ASSERT_EQ("_ZNSkE", demangler.Parse("_ZNSkE"));
228 ASSERT_EQ("_ZNSlE", demangler.Parse("_ZNSlE"));
229 ASSERT_EQ("_ZNSmE", demangler.Parse("_ZNSmE"));
230 ASSERT_EQ("_ZNSnE", demangler.Parse("_ZNSnE"));
231 ASSERT_EQ("std::ostream", demangler.Parse("_ZNSoE"));
232 ASSERT_EQ("_ZNSpE", demangler.Parse("_ZNSpE"));
233 ASSERT_EQ("_ZNSqE", demangler.Parse("_ZNSqE"));
234 ASSERT_EQ("_ZNSrE", demangler.Parse("_ZNSrE"));
235 ASSERT_EQ("std::string", demangler.Parse("_ZNSsE"));
236 ASSERT_EQ("_ZNSuE", demangler.Parse("_ZNSuE"));
237 ASSERT_EQ("_ZNSvE", demangler.Parse("_ZNSvE"));
238 ASSERT_EQ("_ZNSwE", demangler.Parse("_ZNSwE"));
239 ASSERT_EQ("_ZNSxE", demangler.Parse("_ZNSxE"));
240 ASSERT_EQ("_ZNSyE", demangler.Parse("_ZNSyE"));
241 ASSERT_EQ("_ZNSzE", demangler.Parse("_ZNSzE"));
242}
243
244TEST(DemangleTest, SingleLetterArguments) {
245 Demangler demangler;
246
247 ASSERT_EQ("func(signed char)", demangler.Parse("_ZN4funcEa"));
248 ASSERT_EQ("func(bool)", demangler.Parse("_ZN4funcEb"));
249 ASSERT_EQ("func(char)", demangler.Parse("_ZN4funcEc"));
250 ASSERT_EQ("func(double)", demangler.Parse("_ZN4funcEd"));
251 ASSERT_EQ("func(long double)", demangler.Parse("_ZN4funcEe"));
252 ASSERT_EQ("func(float)", demangler.Parse("_ZN4funcEf"));
253 ASSERT_EQ("func(__float128)", demangler.Parse("_ZN4funcEg"));
254 ASSERT_EQ("func(unsigned char)", demangler.Parse("_ZN4funcEh"));
255 ASSERT_EQ("func(int)", demangler.Parse("_ZN4funcEi"));
256 ASSERT_EQ("func(unsigned int)", demangler.Parse("_ZN4funcEj"));
257 ASSERT_EQ("_ZN4funcEk", demangler.Parse("_ZN4funcEk"));
258 ASSERT_EQ("func(long)", demangler.Parse("_ZN4funcEl"));
259 ASSERT_EQ("func(unsigned long)", demangler.Parse("_ZN4funcEm"));
260 ASSERT_EQ("func(__int128)", demangler.Parse("_ZN4funcEn"));
261 ASSERT_EQ("func(unsigned __int128)", demangler.Parse("_ZN4funcEo"));
262 ASSERT_EQ("_ZN4funcEp", demangler.Parse("_ZN4funcEp"));
263 ASSERT_EQ("_ZN4funcEq", demangler.Parse("_ZN4funcEq"));
264 ASSERT_EQ("_ZN4funcEr", demangler.Parse("_ZN4funcEr"));
265 ASSERT_EQ("func(short)", demangler.Parse("_ZN4funcEs"));
266 ASSERT_EQ("func(unsigned short)", demangler.Parse("_ZN4funcEt"));
267 ASSERT_EQ("_ZN4funcEu", demangler.Parse("_ZN4funcEu"));
268 ASSERT_EQ("func()", demangler.Parse("_ZN4funcEv"));
269 ASSERT_EQ("func(wchar_t)", demangler.Parse("_ZN4funcEw"));
270 ASSERT_EQ("func(long long)", demangler.Parse("_ZN4funcEx"));
271 ASSERT_EQ("func(unsigned long long)", demangler.Parse("_ZN4funcEy"));
272 ASSERT_EQ("func(...)", demangler.Parse("_ZN4funcEz"));
273}
274
275TEST(DemangleTest, DArguments) {
276 Demangler demangler;
277
278 ASSERT_EQ("func(auto)", demangler.Parse("_ZN4funcEDa"));
279 ASSERT_EQ("_ZN4funcEDb", demangler.Parse("_ZN4funcEDb"));
280 ASSERT_EQ("_ZN4funcEDc", demangler.Parse("_ZN4funcEDc"));
281 ASSERT_EQ("func(decimal64)", demangler.Parse("_ZN4funcEDd"));
282 ASSERT_EQ("func(decimal128)", demangler.Parse("_ZN4funcEDe"));
283 ASSERT_EQ("func(decimal32)", demangler.Parse("_ZN4funcEDf"));
284 ASSERT_EQ("_ZN4funcEDg", demangler.Parse("_ZN4funcEDg"));
285 ASSERT_EQ("func(half)", demangler.Parse("_ZN4funcEDh"));
286 ASSERT_EQ("func(char32_t)", demangler.Parse("_ZN4funcEDi"));
287 ASSERT_EQ("_ZN4funcEDj", demangler.Parse("_ZN4funcEDj"));
288 ASSERT_EQ("_ZN4funcEDk", demangler.Parse("_ZN4funcEDk"));
289 ASSERT_EQ("_ZN4funcEDl", demangler.Parse("_ZN4funcEDl"));
290 ASSERT_EQ("_ZN4funcEDm", demangler.Parse("_ZN4funcEDm"));
291 ASSERT_EQ("func(decltype(nullptr))", demangler.Parse("_ZN4funcEDn"));
292 ASSERT_EQ("_ZN4funcEDo", demangler.Parse("_ZN4funcEDo"));
293 ASSERT_EQ("_ZN4funcEDp", demangler.Parse("_ZN4funcEDp"));
294 ASSERT_EQ("_ZN4funcEDq", demangler.Parse("_ZN4funcEDq"));
295 ASSERT_EQ("_ZN4funcEDr", demangler.Parse("_ZN4funcEDr"));
296 ASSERT_EQ("func(char16_t)", demangler.Parse("_ZN4funcEDs"));
297 ASSERT_EQ("_ZN4funcEDt", demangler.Parse("_ZN4funcEDt"));
298 ASSERT_EQ("_ZN4funcEDu", demangler.Parse("_ZN4funcEDu"));
299 ASSERT_EQ("_ZN4funcEDv", demangler.Parse("_ZN4funcEDv"));
300 ASSERT_EQ("_ZN4funcEDw", demangler.Parse("_ZN4funcEDw"));
301 ASSERT_EQ("_ZN4funcEDx", demangler.Parse("_ZN4funcEDx"));
302 ASSERT_EQ("_ZN4funcEDy", demangler.Parse("_ZN4funcEDy"));
303 ASSERT_EQ("_ZN4funcEDz", demangler.Parse("_ZN4funcEDz"));
304}
305
306TEST(DemangleTest, FunctionArguments) {
307 Demangler demangler;
308
309 ASSERT_EQ("func(char ())", demangler.Parse("_ZN4funcEFcvE"));
310 ASSERT_EQ("func(char (*)())", demangler.Parse("_ZN4funcEPFcvE"));
311 ASSERT_EQ("func(char (&)())", demangler.Parse("_ZN4funcERFcvE"));
312 ASSERT_EQ("func(char (&)())", demangler.Parse("_ZN4funcERFcvE"));
313 ASSERT_EQ("func(char (*&)())", demangler.Parse("_ZN4funcERPFcvE"));
314 ASSERT_EQ("func(char (*)(int) const)", demangler.Parse("_ZN4funcEPKFciE"));
315 ASSERT_EQ("func(char (&)() const)", demangler.Parse("_ZN4funcERKFcvE"));
316 ASSERT_EQ("func(char (&)() volatile)", demangler.Parse("_ZN4funcERVFcvE"));
317 ASSERT_EQ("func(char (&)() volatile const)", demangler.Parse("_ZN4funcERKVFcvE"));
318 ASSERT_EQ("func(char (&)() const volatile)", demangler.Parse("_ZN4funcERVKFcvE"));
319 ASSERT_EQ("func(char (&)(int, signed char) const)", demangler.Parse("_ZN4funcERKFciaE"));
320 ASSERT_EQ("fake(char (&* volatile const)(void, void, signed char), signed char)",
321 demangler.Parse("_ZN4fakeEKVPRFcvvaEa"));
322}
323
324TEST(DemangleTest, TemplateFunction) {
325 Demangler demangler;
326
327 ASSERT_EQ("one<char>", demangler.Parse("_ZN3oneIcEE"));
328 ASSERT_EQ("one<void>", demangler.Parse("_ZN3oneIvEE"));
329 ASSERT_EQ("one<void*>", demangler.Parse("_ZN3oneIPvEE"));
330 ASSERT_EQ("one<void const>", demangler.Parse("_ZN3oneIKvEE"));
331 ASSERT_EQ("one<char, int, bool>", demangler.Parse("_ZN3oneIcibEE"));
332 ASSERT_EQ("one::two<three>", demangler.Parse("_ZN3one3twoIN5threeEEE"));
333 ASSERT_EQ("one<char, int, two::three>", demangler.Parse("_ZN3oneIciN3two5threeEEE"));
334 // Template within templates.
335 ASSERT_EQ("one::two<three<char, int>>", demangler.Parse("_ZN3one3twoIN5threeIciEEEE"));
336 ASSERT_EQ("one::two<three<char, four<int>>>", demangler.Parse("_ZN3one3twoIN5threeIcN4fourIiEEEEEE"));
337}
338
339TEST(DemangleTest, TemplateArguments) {
340 Demangler demangler;
341
342 ASSERT_EQ("one(two<char>)", demangler.Parse("_ZN3oneE3twoIcE"));
343 ASSERT_EQ("one(two<char, void>)", demangler.Parse("_ZN3oneE3twoIcvE"));
344 ASSERT_EQ("one(two<char, void, three<four, int>>)",
345 demangler.Parse("_ZN3oneE3twoIcv5threeI4fouriEE"));
346}
347
348TEST(DemangleTest, SubstitutionUnderscore) {
349 Demangler demangler;
350
351 ASSERT_EQ("a::a", demangler.Parse("_ZN1aS_E"));
352 ASSERT_EQ("one::one", demangler.Parse("_ZN3oneS_E"));
353 ASSERT_EQ("one::two::one", demangler.Parse("_ZN3one3twoS_E"));
354 ASSERT_EQ("one::two::three::one", demangler.Parse("_ZN3one3two5threeS_E"));
355 ASSERT_EQ("one::two(one)", demangler.Parse("_ZN3one3twoES_"));
356 ASSERT_EQ("one::two(three::one)", demangler.Parse("_ZN3one3twoEN5threeS_E"));
357
358 // Special case that St is part of the saved value used in the substitution.
359 ASSERT_EQ("std::one::std::one", demangler.Parse("_ZNSt3oneS_E"));
360
361 // Multiple substitutions in the string.
362 ASSERT_EQ("one::one(one, one)", demangler.Parse("_ZN3oneS_ES_S_"));
363 ASSERT_EQ("std::one::two::std::one(std::one)", demangler.Parse("_ZNSt3one3twoS_ES_"));
364}
365
366TEST(DemangleTest, SubstitutionByNumber) {
367 Demangler demangler;
368
369 // Basic substitution.
370 ASSERT_EQ("a::b::c(a::b)", demangler.Parse("_ZN1a1b1cES0_"));
371 ASSERT_EQ("_ZN1a1b1cES1_", demangler.Parse("_ZN1a1b1cES1_"));
372 ASSERT_EQ("a::b::c::d(a::b::c)", demangler.Parse("_ZN1a1b1c1dES1_"));
373 ASSERT_EQ("a::b::c::d::e::f::g::h::i::j::k::l::m::n::o::p::q(a::b::c::d::e::f::g::h::i::j::k::l)",
374 demangler.Parse("_ZN1a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1qESA_"));
375 ASSERT_EQ("a::b::c::d::e::f::g::h::i::j::k::l::m::n::o::p::q(a::b::c::d::e::f::g::h::i::j::k::l::m)",
376 demangler.Parse("_ZN1a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1qESB_"));
377
378 // Verify argument modifiers are included in substitution list.
379 ASSERT_EQ("one::two(char&* volatile const, char&)", demangler.Parse("_ZN3one3twoEKVPRcS0_"));
380 ASSERT_EQ("one::two(char&* volatile const, char&*)", demangler.Parse("_ZN3one3twoEKVPRcS1_"));
381 ASSERT_EQ("one::two(char&* volatile const, char&* volatile const)",
382 demangler.Parse("_ZN3one3twoEKVPRcS2_"));
383 ASSERT_EQ("one::two(int&* volatile* const, int&)", demangler.Parse("_ZN3one3twoEKPVPRiS0_"));
384 ASSERT_EQ("one::two(int&* volatile const, int&*)", demangler.Parse("_ZN3one3twoEKVPRiS1_"));
385 ASSERT_EQ("one::two(int&* volatile const, int&* volatile const)",
386 demangler.Parse("_ZN3one3twoEKVPRiS2_"));
387
388 // Verify Constructor/Destructor does properly save from function name.
389 ASSERT_EQ("_ZN1a1bES0_", demangler.Parse("_ZN1a1bES0_"));
390 ASSERT_EQ("a::b::b(a::b)", demangler.Parse("_ZN1a1bC1ES0_"));
391 ASSERT_EQ("a::b::~b(a::b)", demangler.Parse("_ZN1a1bD0ES0_"));
392
393 // Make sure substitution values are not saved.
394 ASSERT_EQ("a::b::b(a::b, char*, char*)", demangler.Parse("_ZN1a1bC1ES0_PcS1_"));
395}
396
397TEST(DemangleTest, ComplexSubstitution) {
398 Demangler demangler;
399
400 ASSERT_EQ("one::two<one::three>::two()", demangler.Parse("_ZN3one3twoINS_5threeEEC1Ev"));
401 ASSERT_EQ("one::two::two(one::two const&, bool, one::three*)",
402 demangler.Parse("_ZN3one3twoC2ERKS0_bPNS_5threeE"));
403 ASSERT_EQ("one::two::three::four<one::five>::~four(one::two*)",
404 demangler.Parse("_ZN3one3two5three4fourINS_4fiveEED2EPS0_"));
405 ASSERT_EQ("one::two::three::four<one::five>::~four(one::two::three*)",
406 demangler.Parse("_ZN3one3two5three4fourINS_4fiveEED2EPS1_"));
407 ASSERT_EQ("one::two::three::four<one::five>::~four(one::two::three::four*)",
408 demangler.Parse("_ZN3one3two5three4fourINS_4fiveEED2EPS2_"));
409 ASSERT_EQ("one::two::three::four<one::five>::~four(one::five*)",
410 demangler.Parse("_ZN3one3two5three4fourINS_4fiveEED2EPS3_"));
411}
412
413TEST(DemangleTest, StringTooLong) {
414 Demangler demangler;
415
416 ASSERT_EQ("_ZN3one3twoC2ERKS0_bPNS_5threeE",
417 demangler.Parse("_ZN3one3twoC2ERKS0_bPNS_5threeE", 10));
418 ASSERT_EQ("_ZN3one3twoC2ERKS0_bPNS_5threeE",
419 demangler.Parse("_ZN3one3twoC2ERKS0_bPNS_5threeE", 30));
420 ASSERT_EQ("one::two::two(one::two const&, bool, one::three*)",
421 demangler.Parse("_ZN3one3twoC2ERKS0_bPNS_5threeE", 31));
422
423 // Check the length check only occurs after the two letter value
424 // has been processed.
425 ASSERT_EQ("one::two(auto)", demangler.Parse("_ZN3one3twoEDa", 15));
426 ASSERT_EQ("one::two(auto)", demangler.Parse("_ZN3one3twoEDa", 14));
427 ASSERT_EQ("one::two(auto)", demangler.Parse("_ZN3one3twoEDa", 13));
428 ASSERT_EQ("_ZN3one3twoEDa", demangler.Parse("_ZN3one3twoEDa", 12));
429}
430
431TEST(DemangleTest, demangle) {
432 std::string str;
433
434 str = demangle("_ZN1a1b1cES0_");
435 ASSERT_EQ("a::b::c(a::b)", str);
436
437 str = demangle("_");
438 ASSERT_EQ("_", str);
439
440 str = demangle("_Z");
441 ASSERT_EQ("_Z", str);
442
443 str = demangle("_Za");
444 ASSERT_EQ("_Za", str);
445
446 str = demangle("_Zaa");
447 ASSERT_EQ("operator&&", str);
448
449 str = demangle("Xa");
450 ASSERT_EQ("Xa", str);
451}