4d48aa093b3d0f32b16f1ade47003248ddfb7314
[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    $Id: testarguments.c 8123 2007-06-20 23:50:55Z michi $
26
27 */
28
29
30 #include "config.h"
31
32 #include <stdio.h>
33
34 #include "native/jni.h"
35
36
37 JNIEXPORT jobject JNICALL Java_testarguments_adr(JNIEnv *env, jclass clazz, jint i)
38 {
39   switch (i) {
40   case 1:
41     return (jobject) 0x11111111;
42   case 2:
43     return (jobject) 0x22222222;
44   case 3:
45     return (jobject) 0x33333333;
46   case 4:
47     return (jobject) 0x44444444;
48   case 5:
49     return (jobject) 0x55555555;
50   case 6:
51     return (jobject) 0x66666666;
52   case 7:
53     return (jobject) 0x77777777;
54   case 8:
55     return (jobject) 0x88888888;
56   case 9:
57     return (jobject) 0x99999999;
58   case 10:
59     return (jobject) 0xaaaaaaaa;
60   case 11:
61     return (jobject) 0xbbbbbbbb;
62   case 12:
63     return (jobject) 0xcccccccc;
64   case 13:
65     return (jobject) 0xdddddddd;
66   case 14:
67     return (jobject) 0xeeeeeeee;
68   case 15:
69     return (jobject) 0xffffffff;
70   }
71 }
72
73
74 JNIEXPORT void JNICALL Java_testarguments_np(JNIEnv *env, jclass clazz, jobject o)
75 {
76 #if SIZEOF_VOID_P == 8
77     printf(" 0x%lx", (long) o);
78 #else
79     printf(" 0x%x", (int) o);
80 #endif
81
82     fflush(stdout);
83 }
84
85
86 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)
87 {
88     jmethodID mid;
89
90     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);
91     fflush(stdout);
92
93     mid = (*env)->GetStaticMethodID(env, clazz, "jisub", "(IIIIIIIIIIIIIII)V");
94
95     if (mid == 0) {
96         printf("native: couldn't find jisub\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_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)
105 {
106     jmethodID mid;
107
108     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);
109     fflush(stdout);
110
111     mid = (*env)->GetStaticMethodID(env, clazz, "jlsub", "(JJJJJJJJJJJJJJJ)V");
112
113     if (mid == 0) {
114         printf("native: couldn't find jlsub\n");
115         return;
116     }
117
118     (*env)->CallStaticVoidMethod(env, clazz, mid, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
119 }
120
121
122 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)
123 {
124     jmethodID mid;
125     union {
126       jint i;
127       jfloat f;
128     } x;
129
130     printf("java-native:");
131
132     x.f = a; printf(" 0x%x", x.i);
133     x.f = b; printf(" 0x%x", x.i);
134     x.f = c; printf(" 0x%x", x.i);
135     x.f = d; printf(" 0x%x", x.i);
136     x.f = e; printf(" 0x%x", x.i);
137     x.f = f; printf(" 0x%x", x.i);
138     x.f = g; printf(" 0x%x", x.i);
139     x.f = h; printf(" 0x%x", x.i);
140     x.f = i; printf(" 0x%x", x.i);
141     x.f = j; printf(" 0x%x", x.i);
142     x.f = k; printf(" 0x%x", x.i);
143     x.f = l; printf(" 0x%x", x.i);
144     x.f = m; printf(" 0x%x", x.i);
145     x.f = n; printf(" 0x%x", x.i);
146     x.f = o; printf(" 0x%x", x.i);
147
148     printf("\n");
149     fflush(stdout);
150
151     mid = (*env)->GetStaticMethodID(env, clazz, "jfsub", "(FFFFFFFFFFFFFFF)V");
152
153     if (mid == 0) {
154         printf("native: couldn't find jfsub\n");
155         return;
156     }
157
158     (*env)->CallStaticVoidMethod(env, clazz, mid, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
159 }
160
161
162 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)
163 {
164     jmethodID mid;
165     union {
166       jlong l;
167       jdouble d;
168     } x;
169
170     printf("java-native:");
171
172     x.d = a; printf(" 0x%llx", x.l);
173     x.d = b; printf(" 0x%llx", x.l);
174     x.d = c; printf(" 0x%llx", x.l);
175     x.d = d; printf(" 0x%llx", x.l);
176     x.d = e; printf(" 0x%llx", x.l);
177     x.d = f; printf(" 0x%llx", x.l);
178     x.d = g; printf(" 0x%llx", x.l);
179     x.d = h; printf(" 0x%llx", x.l);
180     x.d = i; printf(" 0x%llx", x.l);
181     x.d = j; printf(" 0x%llx", x.l);
182     x.d = k; printf(" 0x%llx", x.l);
183     x.d = l; printf(" 0x%llx", x.l);
184     x.d = m; printf(" 0x%llx", x.l);
185     x.d = n; printf(" 0x%llx", x.l);
186     x.d = o; printf(" 0x%llx", x.l);
187
188     printf("\n");
189     fflush(stdout);
190
191     mid = (*env)->GetStaticMethodID(env, clazz, "jdsub", "(DDDDDDDDDDDDDDD)V");
192
193     if (mid == 0) {
194         printf("native: couldn't find jdsub\n");
195         return;
196     }
197
198     (*env)->CallStaticVoidMethod(env, clazz, mid, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
199 }
200
201
202 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)
203 {
204     jmethodID mid;
205
206 #if SIZEOF_VOID_P == 8
207     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);
208 #else
209     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);
210 #endif
211
212     fflush(stdout);
213
214     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");
215
216     if (mid == 0) {
217         printf("native: couldn't find jasub\n");
218         return;
219     }
220
221     (*env)->CallStaticVoidMethod(env, clazz, mid, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
222 }
223
224
225 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)
226 {
227     jmethodID mid;
228     union {
229       jint i;
230       jlong l;
231       jfloat f;
232       jdouble d;
233     } x;
234
235     printf("java-native:");
236
237     printf(" 0x%x", a);
238     printf(" 0x%llx", b);
239     x.f = c; printf(" 0x%x", x.i);
240     x.d = d; printf(" 0x%llx", x.l);
241     printf(" 0x%x", e);
242     printf(" 0x%llx", f);
243     x.f = g; printf(" 0x%x", x.i);
244     x.d = h; printf(" 0x%llx", x.l);
245     printf(" 0x%x", i);
246     printf(" 0x%llx", j);
247     x.f = k; printf(" 0x%x", x.i);
248     x.d = l; printf(" 0x%llx", x.l);
249     printf(" 0x%x", m);
250     printf(" 0x%llx", n);
251     x.f = o; printf(" 0x%x", x.i);
252
253     printf("\n");
254     fflush(stdout);
255
256     mid = (*env)->GetStaticMethodID(env, clazz, "jmsub", "(IJFDIJFDIJFDIJF)V");
257
258     if (mid == 0) {
259         printf("native: couldn't find jmsub\n");
260         return;
261     }
262
263     (*env)->CallStaticVoidMethod(env, clazz, mid, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
264 }