2013-12-18 Janus Weil <janus@gcc.gnu.org>
[official-gcc.git] / libjava / testsuite / libjava.jvmti / natgetmethodname.cc
blob3d759d58dd48c094c3be14d17c138e6e06a69ac2
1 #include <gcj/cni.h>
3 #include <jvm.h>
4 #include <jvmti.h>
5 #include <stdio.h>
7 #include <java/lang/Object.h>
9 #include "getmethodname.h"
11 static void
12 print_error (jvmtiEnv *env, const char *msg, jvmtiError err)
14 char *error_msg;
15 env->GetErrorName (err, &error_msg);
16 printf ("%s: %s\n", msg, error_msg);
17 env->Deallocate (reinterpret_cast<unsigned char *> (error_msg));
20 #define NUM_METHODS 8
21 static const char *function_names[] = { "clone",
22 "equals",
23 "finalize",
24 "getClass",
25 "hashCode",
26 "notify",
27 "notifyAll",
28 "toString" };
29 static int
30 function_index (const char *name)
32 for (int i = 0; i < NUM_METHODS; ++i)
34 if (strcmp (function_names[i], name) == 0)
35 return i;
38 return -1;
41 void
42 getmethodname::do_getmethodname_tests ()
44 jvmtiEnv *env;
45 JavaVM *vm = _Jv_GetJavaVM ();
46 vm->GetEnv (reinterpret_cast<void **> (&env), JVMTI_VERSION_1_0);
48 jvmtiError err;
49 err = env->GetMethodName (reinterpret_cast<jmethodID> (NULL),
50 reinterpret_cast<char **> (NULL),
51 reinterpret_cast<char **> (NULL),
52 reinterpret_cast<char **> (NULL));
53 print_error (env, "null jmethodID", err);
55 jint count;
56 jmethodID *methods;
57 err = env->GetClassMethods (&java::lang::Object::class$, &count, &methods);
58 print_error (env, "GetClassMethods", err);
60 char *names[NUM_METHODS], *solo_names[NUM_METHODS];
61 char *signatures[NUM_METHODS], *solo_signatures[NUM_METHODS];
62 char *generics[NUM_METHODS], *solo_generics[NUM_METHODS];
64 for (jint i = 0; i < count; ++i)
66 char *name, *n;
67 char *signature, *s;
68 char *generic, *g;
69 err = env->GetMethodName (methods[i], &name, &signature, &generic);
71 int idx = -1;
72 if (err != JVMTI_ERROR_NONE)
74 print_error (env, "GetMethodName - all fields", err);
75 continue;
78 idx = function_index (name);
79 if (idx == -1)
80 continue;
82 names[idx] = name;
83 signatures[idx] = signature;
84 generics[idx] = generic;
86 err = env->GetMethodName (methods[i], &n, NULL, NULL);
87 print_error (env, "GetMethodName - name", err);
88 solo_names[idx] = n;
90 err = env->GetMethodName (methods[i], NULL, &s, NULL);
91 print_error (env, "GetMethodName - signature", err);
92 solo_signatures[idx] = s;
94 err = env->GetMethodName (methods[i], NULL, NULL, &g);
95 print_error (env, "GetMethodName - generic", err);
96 solo_generics[idx] = g;
99 #define WRAP(X) ((X) == NULL ? "null" : (X))
100 #define MATCH(X,Y) (strcmp ((X),(Y)) == 0 ? "match" : "do not match")
101 for (int i = 0; i < NUM_METHODS; ++i)
103 printf ("name=%s, signature=%s, generic=%s\n",
104 WRAP (names[i]), WRAP (signatures[i]), WRAP (generics[i]));
105 printf ("names %s\n", MATCH (solo_names[i], names[i]));
106 printf ("signatures %s\n", MATCH (solo_signatures[i], signatures[i]));
107 printf ("generic %s\n", "not yet");
109 env->Deallocate (reinterpret_cast<unsigned char *> (names[i]));
110 env->Deallocate (reinterpret_cast<unsigned char *> (solo_names[i]));
111 env->Deallocate (reinterpret_cast<unsigned char *> (signatures[i]));
112 env->Deallocate (reinterpret_cast<unsigned char *> (solo_signatures[i]));
113 env->Deallocate (reinterpret_cast<unsigned char *> (generics[i]));
114 env->Deallocate (reinterpret_cast<unsigned char *> (solo_generics[i]));