1 #include "test.h"
2 #include <cxxabi.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5
6 #include <list>
7
test(const char * expected,int line)8 template <typename T> void test(const char* expected, int line) {
9 const char *mangled = typeid(T).name();
10 int status = 0;
11 using abi::__cxa_demangle;
12 char* demangled = __cxa_demangle(mangled, 0, 0, &status);
13 printf("mangled='%s' demangled='%s', status=%d\n", mangled, demangled,
14 status);
15 free(demangled);
16 TEST_LOC(status == 0, "should be able to demangle", __FILE__, line);
17 TEST_LOC(demangled != 0, "should be able to demangle", __FILE__, line);
18 if (!demangled) {
19 /* Don't dereference NULL in strcmp() */
20 return;
21 }
22 TEST_LOC(strcmp(expected, demangled) == 0, "should be able to demangle",
23 __FILE__, line);
24 TEST_LOC(strcmp(mangled, demangled) != 0, "should be able to demangle",
25 __FILE__, line);
26 }
27
28
29 namespace N {
30 template<typename T, int U>
31 class Templated {
~Templated()32 virtual ~Templated() {};
33 };
34 }
35
test_demangle(void)36 void test_demangle(void)
37 {
38 using namespace N;
39 test<int>("int", __LINE__);
40 test<char[4]>("char [4]", __LINE__);
41 test<char[]>("char []", __LINE__);
42 test<Templated<Templated<long, 7>, 8> >(
43 "N::Templated<N::Templated<long, 7>, 8>", __LINE__);
44 test<Templated<void(long), -1> >(
45 "N::Templated<void (long), -1>", __LINE__);
46 }
47