• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @file java_test.cpp
3  *
4  * A simple test for java demangling. Run it through:
5  * $ java_test
6  *
7  * @remark Copyright 2007 OProfile authors
8  * @remark Read the file COPYING
9  *
10  * @author Philippe Elie
11  */
12 
13 #include "demangle_java_symbol.h"
14 
15 #include "op_regex.h"
16 
17 #include <iostream>
18 #include <fstream>
19 
20 #include <cstdlib>
21 
22 using namespace std;
23 
24 namespace {
25 
check_result(string const & input,string const & output,string const & result)26 void check_result(string const & input, string const & output,
27 			 string const & result)
28 {
29 	if (result != output) {
30 		cerr << "for:\n\"" << input << "\"\n"
31 		     << "expect:\n\"" << output << "\"\n"
32 		     << "found:\n\"" << result << "\"\n";
33 		exit(EXIT_FAILURE);
34 	}
35 }
36 
37 struct input_output {
38 	char const * mangled;
39 	char const * expect;
40 };
41 
42 input_output mangle_tests[] = {
43 	{ "Ltest$test_1;f2(I)V", "void test$test_1.f2(int)" },
44 	{ "Ltest;f4()V", "void test.f4()" },
45 	{ "Ltest;f2(II)V", "void test.f2(int, int)" },
46 	{ "Ltest$HelloThread;run()V~1", "void test$HelloThread.run()~1" },
47 	{ "Lsun/security/provider/SHA;implCompress([BI)V", "void sun.security.provider.SHA.implCompress(byte[], int)" },
48 	{ "Ljava/lang/String;equals(Ljava/lang/Object;)Z", "boolean java.lang.String.equals(java.lang.Object)" },
49 	{ "Lorg/eclipse/swt/graphics/ImageData;blit(I[BIIIIIIIIIII[BIII[BIIIIIIIIIIZZ)V", "void org.eclipse.swt.graphics.ImageData.blit(int, byte[], int, int, int, int, int, int, int, int, int, int, int, byte[], int, int, int, byte[], int, int, int, int, int, int, int, int, int, int, boolean, boolean)" },
50 	{ 0, 0 }
51 };
52 
53 } // anonymous namespace
54 
main(void)55 int main(void)
56 {
57 	input_output const * cur;
58 	for (cur = mangle_tests; cur->mangled; ++cur) {
59 		string result = demangle_java_symbol(cur->mangled);
60 		check_result(cur->mangled, cur->expect, result);
61 	}
62 
63 	return 0;
64 }
65 
66