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