* src/native/jni.h: Removed.
[cacao.git] / tests / regression / native / testarguments.c
1 /* tests/regression/native/testarguments.c - tests argument passing
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <stdio.h>
29 #include <stdlib.h>
30
31 #include "native/jni.hpp"
32
33
34 JNIEXPORT jobject JNICALL Java_testarguments_adr(JNIEnv *env, jclass clazz, jint i)
35 {
36   intptr_t p;
37
38   p = 0x11111111 * ((intptr_t) i);
39
40 #if defined(ENABLE_HANDLES)
41   return (*env)->NewLocalRef(env, &p);
42 #else
43   return (jobject) p;
44 #endif
45 }
46
47
48 JNIEXPORT void JNICALL Java_testarguments_np(JNIEnv *env, jclass clazz, jobject o)
49 {
50 #if defined(ENABLE_HANDLES)
51     intptr_t p = *((intptr_t *) o);
52 #else
53     intptr_t p = (intptr_t) o;
54 #endif
55
56 #if SIZEOF_VOID_P == 8
57     printf(" 0x%lx", (long) p);
58 #else
59     printf(" 0x%x", (int) p);
60 #endif
61
62     fflush(stdout);
63 }
64
65
66 JNIEXPORT void JNICALL Java_testarguments_nisub(JNIEnv *env, jclass clazz, jint a, jint b, jint c, jint d, jint e, jint f, jint g, jint h, jint i, jint j, jint k, jint l, jint m, jint n, jint o)
67 {
68     jmethodID mid;
69
70     printf("java-native: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
71     fflush(stdout);
72
73     mid = (*env)->GetStaticMethodID(env, clazz, "jisub", "(IIIIIIIIIIIIIII)V");
74
75     if (mid == 0) {
76         printf("native: couldn't find jisub\n");
77         return;
78     }
79
80     (*env)->CallStaticVoidMethod(env, clazz, mid, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
81 }
82
83
84 JNIEXPORT void JNICALL Java_testarguments_nlsub(JNIEnv *env, jclass clazz, jlong a, jlong b, jlong c, jlong d, jlong e, jlong f, jlong g, jlong h, jlong i, jlong j, jlong k, jlong l, jlong m, jlong n, jlong o)
85 {
86     jmethodID mid;
87
88     printf("java-native: 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx\n", a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
89     fflush(stdout);
90
91     mid = (*env)->GetStaticMethodID(env, clazz, "jlsub", "(JJJJJJJJJJJJJJJ)V");
92
93     if (mid == 0) {
94         printf("native: couldn't find jlsub\n");
95         return;
96     }
97
98     (*env)->CallStaticVoidMethod(env, clazz, mid, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
99 }
100
101
102 JNIEXPORT void JNICALL Java_testarguments_nfsub(JNIEnv *env, jclass clazz, jfloat a, jfloat b, jfloat c, jfloat d, jfloat e, jfloat f, jfloat g, jfloat h, jfloat i, jfloat j, jfloat k, jfloat l, jfloat m, jfloat n, jfloat o)
103 {
104     jmethodID mid;
105     union {
106       jint i;
107       jfloat f;
108     } x;
109
110     printf("java-native:");
111
112     x.f = a; printf(" 0x%x", x.i);
113     x.f = b; printf(" 0x%x", x.i);
114     x.f = c; printf(" 0x%x", x.i);
115     x.f = d; printf(" 0x%x", x.i);
116     x.f = e; printf(" 0x%x", x.i);
117     x.f = f; printf(" 0x%x", x.i);
118     x.f = g; printf(" 0x%x", x.i);
119     x.f = h; printf(" 0x%x", x.i);
120     x.f = i; printf(" 0x%x", x.i);
121     x.f = j; printf(" 0x%x", x.i);
122     x.f = k; printf(" 0x%x", x.i);
123     x.f = l; printf(" 0x%x", x.i);
124     x.f = m; printf(" 0x%x", x.i);
125     x.f = n; printf(" 0x%x", x.i);
126     x.f = o; printf(" 0x%x", x.i);
127
128     printf("\n");
129     fflush(stdout);
130
131     mid = (*env)->GetStaticMethodID(env, clazz, "jfsub", "(FFFFFFFFFFFFFFF)V");
132
133     if (mid == 0) {
134         printf("native: couldn't find jfsub\n");
135         return;
136     }
137
138     (*env)->CallStaticVoidMethod(env, clazz, mid, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
139 }
140
141
142 JNIEXPORT void JNICALL Java_testarguments_ndsub(JNIEnv *env, jclass clazz, jdouble a, jdouble b, jdouble c, jdouble d, jdouble e, jdouble f, jdouble g, jdouble h, jdouble i, jdouble j, jdouble k, jdouble l, jdouble m, jdouble n, jdouble o)
143 {
144     jmethodID mid;
145     union {
146       jlong l;
147       jdouble d;
148     } x;
149
150     printf("java-native:");
151
152     x.d = a; printf(" 0x%llx", x.l);
153     x.d = b; printf(" 0x%llx", x.l);
154     x.d = c; printf(" 0x%llx", x.l);
155     x.d = d; printf(" 0x%llx", x.l);
156     x.d = e; printf(" 0x%llx", x.l);
157     x.d = f; printf(" 0x%llx", x.l);
158     x.d = g; printf(" 0x%llx", x.l);
159     x.d = h; printf(" 0x%llx", x.l);
160     x.d = i; printf(" 0x%llx", x.l);
161     x.d = j; printf(" 0x%llx", x.l);
162     x.d = k; printf(" 0x%llx", x.l);
163     x.d = l; printf(" 0x%llx", x.l);
164     x.d = m; printf(" 0x%llx", x.l);
165     x.d = n; printf(" 0x%llx", x.l);
166     x.d = o; printf(" 0x%llx", x.l);
167
168     printf("\n");
169     fflush(stdout);
170
171     mid = (*env)->GetStaticMethodID(env, clazz, "jdsub", "(DDDDDDDDDDDDDDD)V");
172
173     if (mid == 0) {
174         printf("native: couldn't find jdsub\n");
175         return;
176     }
177
178     (*env)->CallStaticVoidMethod(env, clazz, mid, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
179 }
180
181
182 JNIEXPORT void JNICALL Java_testarguments_nasub(JNIEnv *env, jclass clazz, jobject a, jobject b, jobject c, jobject d, jobject e, jobject f, jobject g, jobject h, jobject i, jobject j, jobject k, jobject l, jobject m, jobject n, jobject o)
183 {
184     jmethodID mid;
185
186 #if defined(ENABLE_HANDLES)
187
188 # if SIZEOF_VOID_P == 8
189     printf("java-native: 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n", *((long*) a), *((long*) b), *((long*) c), *((long*) d), *((long*) e), *((long*) f), *((long*) g), *((long*) h), *((long*) i), *((long*) j), *((long*) k), *((long*) l), *((long*) m), *((long*) n), *((long*) o));
190 # else
191     printf("java-native: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", *((int*) a), *((int*) b), *((int*) c), *((int*) d), *((int*) e), *((int*) f), *((int*) g), *((int*) h), *((int*) i), *((int*) j), *((int*) k), *((int*) l), *((int*) m), *((int*) n), *((int*) o));
192 # endif
193
194 #else
195
196 # if SIZEOF_VOID_P == 8
197     printf("java-native: 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n", (long) a, (long) b, (long) c, (long) d, (long) e, (long) f, (long) g, (long) h, (long) i, (long) j, (long) k, (long) l, (long) m, (long) n, (long) o);
198 # else
199     printf("java-native: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", (int) a, (int) b, (int) c, (int) d, (int) e, (int) f, (int) g, (int) h, (int) i, (int) j, (int) k, (int) l, (int) m, (int) n, (int) o);
200 # endif
201
202 #endif
203
204     fflush(stdout);
205
206     mid = (*env)->GetStaticMethodID(env, clazz, "jasub", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V");
207
208     if (mid == 0) {
209         printf("native: couldn't find jasub\n");
210         return;
211     }
212
213     (*env)->CallStaticVoidMethod(env, clazz, mid, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
214 }
215
216
217 JNIEXPORT void JNICALL Java_testarguments_nmsub(JNIEnv *env, jclass clazz, jint a, jlong b, jfloat c, jdouble d, jint e, jlong f, jfloat g, jdouble h, jint i, jlong j, jfloat k, jdouble l, jint m, jlong n, jfloat o)
218 {
219     jmethodID mid;
220     union {
221       jint i;
222       jlong l;
223       jfloat f;
224       jdouble d;
225     } x;
226
227     printf("java-native:");
228
229     printf(" 0x%x", a);
230     printf(" 0x%llx", b);
231     x.f = c; printf(" 0x%x", x.i);
232     x.d = d; printf(" 0x%llx", x.l);
233     printf(" 0x%x", e);
234     printf(" 0x%llx", f);
235     x.f = g; printf(" 0x%x", x.i);
236     x.d = h; printf(" 0x%llx", x.l);
237     printf(" 0x%x", i);
238     printf(" 0x%llx", j);
239     x.f = k; printf(" 0x%x", x.i);
240     x.d = l; printf(" 0x%llx", x.l);
241     printf(" 0x%x", m);
242     printf(" 0x%llx", n);
243     x.f = o; printf(" 0x%x", x.i);
244
245     printf("\n");
246     fflush(stdout);
247
248     mid = (*env)->GetStaticMethodID(env, clazz, "jmsub", "(IJFDIJFDIJFDIJF)V");
249
250     if (mid == 0) {
251         printf("native: couldn't find jmsub\n");
252         return;
253     }
254
255     (*env)->CallStaticVoidMethod(env, clazz, mid, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
256 }