0001
0002 #include <string.h>
0003 #include <stdlib.h>
0004 #include <stdio.h>
0005 #include "tests.h"
0006 #include "session.h"
0007 #include "debug.h"
0008 #include "demangle-java.h"
0009
0010 static int test__demangle_java(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
0011 {
0012 int ret = TEST_OK;
0013 char *buf = NULL;
0014 size_t i;
0015
0016 struct {
0017 const char *mangled, *demangled;
0018 } test_cases[] = {
0019 { "Ljava/lang/StringLatin1;equals([B[B)Z",
0020 "boolean java.lang.StringLatin1.equals(byte[], byte[])" },
0021 { "Ljava/util/zip/ZipUtils;CENSIZ([BI)J",
0022 "long java.util.zip.ZipUtils.CENSIZ(byte[], int)" },
0023 { "Ljava/util/regex/Pattern$BmpCharProperty;match(Ljava/util/regex/Matcher;ILjava/lang/CharSequence;)Z",
0024 "boolean java.util.regex.Pattern$BmpCharProperty.match(java.util.regex.Matcher, int, java.lang.CharSequence)" },
0025 { "Ljava/lang/AbstractStringBuilder;appendChars(Ljava/lang/String;II)V",
0026 "void java.lang.AbstractStringBuilder.appendChars(java.lang.String, int, int)" },
0027 { "Ljava/lang/Object;<init>()V",
0028 "void java.lang.Object<init>()" },
0029 };
0030
0031 for (i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) {
0032 buf = java_demangle_sym(test_cases[i].mangled, 0);
0033 if (strcmp(buf, test_cases[i].demangled)) {
0034 pr_debug("FAILED: %s: %s != %s\n", test_cases[i].mangled,
0035 buf, test_cases[i].demangled);
0036 ret = TEST_FAIL;
0037 }
0038 free(buf);
0039 }
0040
0041 return ret;
0042 }
0043
0044 DEFINE_SUITE("Demangle Java", demangle_java);