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