1 /*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /*
18 * These are all tests of JNI, but where the JNI calls themselves are
19 * represented as macro invocations. There are both C and C++ files which
20 * include this file. A #if at the top of this file (immediately below)
21 * detects which language is being used and defines macros accordingly.
22 *
23 * This file also defines a static method called runAllTests(), which
24 * does what it says.
25 */
26
27 #ifndef INCLUDED_FROM_WRAPPER
28 #error "This file should only be compiled by including it from a wrapper file."
29 #endif
30
31 #include "helper.h"
32 #include <inttypes.h>
33 #include <stdbool.h>
34 #include <stdlib.h>
35 #include <string.h>
36
37
38 /** reference to test class {@code InstanceFromNative} */
39 static jclass InstanceFromNative;
40
41 /** reference to test class {@code StaticFromNative} */
42 static jclass StaticFromNative;
43
44 /** reference to field {@code InstanceFromNative.theOne} */
45 static jfieldID InstanceFromNative_theOne;
46
47 /** reference to string {@code "biscuits"} */
48 static jstring biscuits;
49
50 /**
51 * how to call a method: (virtual, direct, static) x (standard, array of
52 * args, va_list) */
53 typedef enum {
54 VIRTUAL_PLAIN, VIRTUAL_ARRAY, VIRTUAL_VA,
55 DIRECT_PLAIN, DIRECT_ARRAY, DIRECT_VA,
56 STATIC_PLAIN, STATIC_ARRAY, STATIC_VA,
57 } callType;
58
59 /*
60 * CALL() calls the JNI function with the given name, using a JNIEnv
61 * pointer named "env", and passing along any other arguments given.
62 */
63 #ifdef __cplusplus
64 #define CALL(name, args...) env->name(args)
65 #else
66 /*
67 * Note: The space before the comma below is significant with respect to
68 * the processing of the ## operator.
69 */
70 #define CALL(name, args...) (*env)->name(env , ## args)
71 #endif
72
73
74 /**
75 * Simple assert-like macro which returns NULL if the two values are
76 * equal, or an error message if they aren't.
77 */
78 #define FAIL_IF_UNEQUAL(printfType, expected, actual) \
79 ((expected) == (actual)) ? NULL : \
80 failure("expected " printfType " but got " printfType, \
81 expected, actual);
82
83
84 /**
85 * Initializes the static variables. Returns NULL on success or an
86 * error string on failure.
87 */
initializeVariables(JNIEnv * env)88 static char *initializeVariables(JNIEnv *env) {
89 jclass clazz;
90 jfieldID field;
91
92 clazz = CALL(FindClass, "android/jni/cts/StaticFromNative");
93 if (clazz == NULL) {
94 return failure("could not find StaticFromNative");
95 }
96
97 StaticFromNative = (jclass) CALL(NewGlobalRef, clazz);
98
99 clazz = CALL(FindClass, "android/jni/cts/InstanceFromNative");
100 if (clazz == NULL) {
101 return failure("could not find InstanceFromNative");
102 }
103
104 InstanceFromNative = (jclass) CALL(NewGlobalRef, clazz);
105
106 field = CALL(GetStaticFieldID, InstanceFromNative, "theOne",
107 "Landroid/jni/cts/InstanceFromNative;");
108 if (field == NULL) {
109 return failure("could not find InstanceFromNative.theOne");
110 }
111
112 InstanceFromNative_theOne = field;
113
114 biscuits = CALL(NewStringUTF, "biscuits");
115 if (biscuits == NULL) {
116 return failure("could not construct string");
117 }
118
119 biscuits = (jstring) CALL(NewGlobalRef, biscuits);
120
121 return NULL;
122 }
123
124 /**
125 * Gets the standard instance of InstanceFromNative.
126 */
getStandardInstance(JNIEnv * env)127 static jobject getStandardInstance(JNIEnv *env) {
128 return CALL(GetStaticObjectField, InstanceFromNative,
129 InstanceFromNative_theOne);
130 }
131
132 /**
133 * Looks up a static method on StaticFromNative.
134 */
findStaticMethod(JNIEnv * env,char ** errorMsg,const char * name,const char * sig)135 static jmethodID findStaticMethod(JNIEnv *env, char **errorMsg,
136 const char *name, const char *sig) {
137 jmethodID result = CALL(GetStaticMethodID, StaticFromNative,
138 name, sig);
139
140 if (result == NULL) {
141 *errorMsg = failure("could not find static test method %s:%s",
142 name, sig);
143 }
144
145 return result;
146 }
147
148 /**
149 * Looks up an instance method on InstanceFromNative.
150 */
findInstanceMethod(JNIEnv * env,char ** errorMsg,const char * name,const char * sig)151 static jmethodID findInstanceMethod(JNIEnv *env, char **errorMsg,
152 const char *name, const char *sig) {
153 jmethodID result = CALL(GetMethodID, InstanceFromNative, name, sig);
154
155 if (result == NULL) {
156 *errorMsg = failure("could not find instance test method %s:%s",
157 name, sig);
158 }
159
160 return result;
161 }
162
163 /**
164 * Looks up either an instance method on InstanceFromNative or a
165 * static method on StaticFromNative, depending on the given
166 * call type.
167 */
findAppropriateMethod(JNIEnv * env,char ** errorMsg,callType ct,const char * name,const char * sig)168 static jmethodID findAppropriateMethod(JNIEnv *env, char **errorMsg,
169 callType ct, const char *name, const char *sig) {
170 if ((ct == STATIC_PLAIN) || (ct == STATIC_ARRAY) ||
171 (ct == STATIC_VA)) {
172 return findStaticMethod(env, errorMsg, name, sig);
173 } else {
174 return findInstanceMethod(env, errorMsg, name, sig);
175 }
176 }
177
178
179 /*
180 * The tests.
181 */
182
183 // TODO: Missing functions:
184 // AllocObject
185
help_CallBooleanMethod(JNIEnv * env,int ct,...)186 static char *help_CallBooleanMethod(JNIEnv *env, int ct, ...) {
187 va_list args;
188 va_start(args, ct);
189
190 char *msg;
191 jobject o = getStandardInstance(env);
192 jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
193 "returnBoolean", "()Z");
194
195 if (method == NULL) {
196 va_end(args);
197 return msg;
198 }
199
200 jboolean result;
201
202 switch (ct) {
203 case VIRTUAL_PLAIN: {
204 result = CALL(CallBooleanMethod, o, method);
205 break;
206 }
207 case VIRTUAL_ARRAY: {
208 result = CALL(CallBooleanMethodA, o, method, NULL);
209 break;
210 }
211 case VIRTUAL_VA: {
212 result = CALL(CallBooleanMethodV, o, method, args);
213 break;
214 }
215 case DIRECT_PLAIN: {
216 result = CALL(CallNonvirtualBooleanMethod, o, InstanceFromNative,
217 method);
218 break;
219 }
220 case DIRECT_ARRAY: {
221 result = CALL(CallNonvirtualBooleanMethodA, o, InstanceFromNative,
222 method, NULL);
223 break;
224 }
225 case DIRECT_VA: {
226 result = CALL(CallNonvirtualBooleanMethodV, o, InstanceFromNative,
227 method, args);
228 break;
229 }
230 case STATIC_PLAIN: {
231 result = CALL(CallStaticBooleanMethod, StaticFromNative, method);
232 break;
233 }
234 case STATIC_ARRAY: {
235 result = CALL(CallStaticBooleanMethodA, StaticFromNative, method,
236 NULL);
237 break;
238 }
239 case STATIC_VA: {
240 result = CALL(CallStaticBooleanMethodV, StaticFromNative, method,
241 args);
242 break;
243 }
244 default: {
245 va_end(args);
246 return failure("shouldn't happen");
247 }
248 }
249
250 va_end(args);
251
252 return FAIL_IF_UNEQUAL("%d", true, result);
253 }
254
TEST_DECLARATION(CallBooleanMethod)255 TEST_DECLARATION(CallBooleanMethod) {
256 return help_CallBooleanMethod(env, VIRTUAL_PLAIN);
257 }
258
TEST_DECLARATION(CallBooleanMethodA)259 TEST_DECLARATION(CallBooleanMethodA) {
260 return help_CallBooleanMethod(env, VIRTUAL_ARRAY);
261 }
262
TEST_DECLARATION(CallBooleanMethodV)263 TEST_DECLARATION(CallBooleanMethodV) {
264 return help_CallBooleanMethod(env, VIRTUAL_VA);
265 }
266
TEST_DECLARATION(CallNonvirtualBooleanMethod)267 TEST_DECLARATION(CallNonvirtualBooleanMethod) {
268 return help_CallBooleanMethod(env, DIRECT_PLAIN);
269 }
270
TEST_DECLARATION(CallNonvirtualBooleanMethodA)271 TEST_DECLARATION(CallNonvirtualBooleanMethodA) {
272 return help_CallBooleanMethod(env, DIRECT_ARRAY);
273 }
274
TEST_DECLARATION(CallNonvirtualBooleanMethodV)275 TEST_DECLARATION(CallNonvirtualBooleanMethodV) {
276 return help_CallBooleanMethod(env, DIRECT_VA);
277 }
278
TEST_DECLARATION(CallStaticBooleanMethod)279 TEST_DECLARATION(CallStaticBooleanMethod) {
280 return help_CallBooleanMethod(env, STATIC_PLAIN);
281 }
282
TEST_DECLARATION(CallStaticBooleanMethodA)283 TEST_DECLARATION(CallStaticBooleanMethodA) {
284 return help_CallBooleanMethod(env, STATIC_ARRAY);
285 }
286
TEST_DECLARATION(CallStaticBooleanMethodV)287 TEST_DECLARATION(CallStaticBooleanMethodV) {
288 return help_CallBooleanMethod(env, STATIC_VA);
289 }
290
help_CallByteMethod(JNIEnv * env,int ct,...)291 static char *help_CallByteMethod(JNIEnv *env, int ct, ...) {
292 va_list args;
293 va_start(args, ct);
294
295 char *msg;
296 jobject o = getStandardInstance(env);
297 jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
298 "returnByte", "()B");
299
300 if (method == NULL) {
301 va_end(args);
302 return msg;
303 }
304
305 jbyte result;
306
307 switch (ct) {
308 case VIRTUAL_PLAIN: {
309 result = CALL(CallByteMethod, o, method);
310 break;
311 }
312 case VIRTUAL_ARRAY: {
313 result = CALL(CallByteMethodA, o, method, NULL);
314 break;
315 }
316 case VIRTUAL_VA: {
317 result = CALL(CallByteMethodV, o, method, args);
318 break;
319 }
320 case DIRECT_PLAIN: {
321 result = CALL(CallNonvirtualByteMethod, o, InstanceFromNative,
322 method);
323 break;
324 }
325 case DIRECT_ARRAY: {
326 result = CALL(CallNonvirtualByteMethodA, o, InstanceFromNative,
327 method, NULL);
328 break;
329 }
330 case DIRECT_VA: {
331 result = CALL(CallNonvirtualByteMethodV, o, InstanceFromNative,
332 method, args);
333 break;
334 }
335 case STATIC_PLAIN: {
336 result = CALL(CallStaticByteMethod, StaticFromNative, method);
337 break;
338 }
339 case STATIC_ARRAY: {
340 result = CALL(CallStaticByteMethodA, StaticFromNative, method,
341 NULL);
342 break;
343 }
344 case STATIC_VA: {
345 result = CALL(CallStaticByteMethodV, StaticFromNative, method,
346 args);
347 break;
348 }
349 default: {
350 va_end(args);
351 return failure("shouldn't happen");
352 }
353 }
354
355 va_end(args);
356
357 return FAIL_IF_UNEQUAL("%d", 14, result);
358 }
359
TEST_DECLARATION(CallByteMethod)360 TEST_DECLARATION(CallByteMethod) {
361 return help_CallByteMethod(env, VIRTUAL_PLAIN);
362 }
363
TEST_DECLARATION(CallByteMethodA)364 TEST_DECLARATION(CallByteMethodA) {
365 return help_CallByteMethod(env, VIRTUAL_ARRAY);
366 }
367
TEST_DECLARATION(CallByteMethodV)368 TEST_DECLARATION(CallByteMethodV) {
369 return help_CallByteMethod(env, VIRTUAL_VA);
370 }
371
TEST_DECLARATION(CallNonvirtualByteMethod)372 TEST_DECLARATION(CallNonvirtualByteMethod) {
373 return help_CallByteMethod(env, DIRECT_PLAIN);
374 }
375
TEST_DECLARATION(CallNonvirtualByteMethodA)376 TEST_DECLARATION(CallNonvirtualByteMethodA) {
377 return help_CallByteMethod(env, DIRECT_ARRAY);
378 }
379
TEST_DECLARATION(CallNonvirtualByteMethodV)380 TEST_DECLARATION(CallNonvirtualByteMethodV) {
381 return help_CallByteMethod(env, DIRECT_VA);
382 }
383
TEST_DECLARATION(CallStaticByteMethod)384 TEST_DECLARATION(CallStaticByteMethod) {
385 return help_CallByteMethod(env, STATIC_PLAIN);
386 }
387
TEST_DECLARATION(CallStaticByteMethodA)388 TEST_DECLARATION(CallStaticByteMethodA) {
389 return help_CallByteMethod(env, STATIC_ARRAY);
390 }
391
TEST_DECLARATION(CallStaticByteMethodV)392 TEST_DECLARATION(CallStaticByteMethodV) {
393 return help_CallByteMethod(env, STATIC_VA);
394 }
395
help_CallShortMethod(JNIEnv * env,int ct,...)396 static char *help_CallShortMethod(JNIEnv *env, int ct, ...) {
397 va_list args;
398 va_start(args, ct);
399
400 char *msg;
401 jobject o = getStandardInstance(env);
402 jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
403 "returnShort", "()S");
404
405 if (method == NULL) {
406 va_end(args);
407 return msg;
408 }
409
410 jshort result;
411
412 switch (ct) {
413 case VIRTUAL_PLAIN: {
414 result = CALL(CallShortMethod, o, method);
415 break;
416 }
417 case VIRTUAL_ARRAY: {
418 result = CALL(CallShortMethodA, o, method, NULL);
419 break;
420 }
421 case VIRTUAL_VA: {
422 result = CALL(CallShortMethodV, o, method, args);
423 break;
424 }
425 case DIRECT_PLAIN: {
426 result = CALL(CallNonvirtualShortMethod, o, InstanceFromNative,
427 method);
428 break;
429 }
430 case DIRECT_ARRAY: {
431 result = CALL(CallNonvirtualShortMethodA, o, InstanceFromNative,
432 method, NULL);
433 break;
434 }
435 case DIRECT_VA: {
436 result = CALL(CallNonvirtualShortMethodV, o, InstanceFromNative,
437 method, args);
438 break;
439 }
440 case STATIC_PLAIN: {
441 result = CALL(CallStaticShortMethod, StaticFromNative, method);
442 break;
443 }
444 case STATIC_ARRAY: {
445 result = CALL(CallStaticShortMethodA, StaticFromNative, method,
446 NULL);
447 break;
448 }
449 case STATIC_VA: {
450 result = CALL(CallStaticShortMethodV, StaticFromNative, method,
451 args);
452 break;
453 }
454 default: {
455 va_end(args);
456 return failure("shouldn't happen");
457 }
458 }
459
460 va_end(args);
461
462 return FAIL_IF_UNEQUAL("%d", -608, result);
463 }
464
TEST_DECLARATION(CallShortMethod)465 TEST_DECLARATION(CallShortMethod) {
466 return help_CallShortMethod(env, VIRTUAL_PLAIN);
467 }
468
TEST_DECLARATION(CallShortMethodA)469 TEST_DECLARATION(CallShortMethodA) {
470 return help_CallShortMethod(env, VIRTUAL_ARRAY);
471 }
472
TEST_DECLARATION(CallShortMethodV)473 TEST_DECLARATION(CallShortMethodV) {
474 return help_CallShortMethod(env, VIRTUAL_VA);
475 }
476
TEST_DECLARATION(CallNonvirtualShortMethod)477 TEST_DECLARATION(CallNonvirtualShortMethod) {
478 return help_CallShortMethod(env, DIRECT_PLAIN);
479 }
480
TEST_DECLARATION(CallNonvirtualShortMethodA)481 TEST_DECLARATION(CallNonvirtualShortMethodA) {
482 return help_CallShortMethod(env, DIRECT_ARRAY);
483 }
484
TEST_DECLARATION(CallNonvirtualShortMethodV)485 TEST_DECLARATION(CallNonvirtualShortMethodV) {
486 return help_CallShortMethod(env, DIRECT_VA);
487 }
488
TEST_DECLARATION(CallStaticShortMethod)489 TEST_DECLARATION(CallStaticShortMethod) {
490 return help_CallShortMethod(env, STATIC_PLAIN);
491 }
492
TEST_DECLARATION(CallStaticShortMethodA)493 TEST_DECLARATION(CallStaticShortMethodA) {
494 return help_CallShortMethod(env, STATIC_ARRAY);
495 }
496
TEST_DECLARATION(CallStaticShortMethodV)497 TEST_DECLARATION(CallStaticShortMethodV) {
498 return help_CallShortMethod(env, STATIC_VA);
499 }
500
help_CallCharMethod(JNIEnv * env,int ct,...)501 static char *help_CallCharMethod(JNIEnv *env, int ct, ...) {
502 va_list args;
503 va_start(args, ct);
504
505 char *msg;
506 jobject o = getStandardInstance(env);
507 jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
508 "returnChar", "()C");
509
510 if (method == NULL) {
511 va_end(args);
512 return msg;
513 }
514
515 jchar result;
516
517 switch (ct) {
518 case VIRTUAL_PLAIN: {
519 result = CALL(CallCharMethod, o, method);
520 break;
521 }
522 case VIRTUAL_ARRAY: {
523 result = CALL(CallCharMethodA, o, method, NULL);
524 break;
525 }
526 case VIRTUAL_VA: {
527 result = CALL(CallCharMethodV, o, method, args);
528 break;
529 }
530 case DIRECT_PLAIN: {
531 result = CALL(CallNonvirtualCharMethod, o, InstanceFromNative,
532 method);
533 break;
534 }
535 case DIRECT_ARRAY: {
536 result = CALL(CallNonvirtualCharMethodA, o, InstanceFromNative,
537 method, NULL);
538 break;
539 }
540 case DIRECT_VA: {
541 result = CALL(CallNonvirtualCharMethodV, o, InstanceFromNative,
542 method, args);
543 break;
544 }
545 case STATIC_PLAIN: {
546 result = CALL(CallStaticCharMethod, StaticFromNative, method);
547 break;
548 }
549 case STATIC_ARRAY: {
550 result = CALL(CallStaticCharMethodA, StaticFromNative, method,
551 NULL);
552 break;
553 }
554 case STATIC_VA: {
555 result = CALL(CallStaticCharMethodV, StaticFromNative, method,
556 args);
557 break;
558 }
559 default: {
560 va_end(args);
561 return failure("shouldn't happen");
562 }
563 }
564
565 va_end(args);
566
567 return FAIL_IF_UNEQUAL("%d", 9000, result);
568 }
569
TEST_DECLARATION(CallCharMethod)570 TEST_DECLARATION(CallCharMethod) {
571 return help_CallCharMethod(env, VIRTUAL_PLAIN);
572 }
573
TEST_DECLARATION(CallCharMethodA)574 TEST_DECLARATION(CallCharMethodA) {
575 return help_CallCharMethod(env, VIRTUAL_ARRAY);
576 }
577
TEST_DECLARATION(CallCharMethodV)578 TEST_DECLARATION(CallCharMethodV) {
579 return help_CallCharMethod(env, VIRTUAL_VA);
580 }
581
TEST_DECLARATION(CallNonvirtualCharMethod)582 TEST_DECLARATION(CallNonvirtualCharMethod) {
583 return help_CallCharMethod(env, DIRECT_PLAIN);
584 }
585
TEST_DECLARATION(CallNonvirtualCharMethodA)586 TEST_DECLARATION(CallNonvirtualCharMethodA) {
587 return help_CallCharMethod(env, DIRECT_ARRAY);
588 }
589
TEST_DECLARATION(CallNonvirtualCharMethodV)590 TEST_DECLARATION(CallNonvirtualCharMethodV) {
591 return help_CallCharMethod(env, DIRECT_VA);
592 }
593
TEST_DECLARATION(CallStaticCharMethod)594 TEST_DECLARATION(CallStaticCharMethod) {
595 return help_CallCharMethod(env, STATIC_PLAIN);
596 }
597
TEST_DECLARATION(CallStaticCharMethodA)598 TEST_DECLARATION(CallStaticCharMethodA) {
599 return help_CallCharMethod(env, STATIC_ARRAY);
600 }
601
TEST_DECLARATION(CallStaticCharMethodV)602 TEST_DECLARATION(CallStaticCharMethodV) {
603 return help_CallCharMethod(env, STATIC_VA);
604 }
605
help_CallIntMethod(JNIEnv * env,int ct,...)606 static char *help_CallIntMethod(JNIEnv *env, int ct, ...) {
607 va_list args;
608 va_start(args, ct);
609
610 char *msg;
611 jobject o = getStandardInstance(env);
612 jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
613 "returnInt", "()I");
614
615 if (method == NULL) {
616 va_end(args);
617 return msg;
618 }
619
620 jint result;
621
622 switch (ct) {
623 case VIRTUAL_PLAIN: {
624 result = CALL(CallIntMethod, o, method);
625 break;
626 }
627 case VIRTUAL_ARRAY: {
628 result = CALL(CallIntMethodA, o, method, NULL);
629 break;
630 }
631 case VIRTUAL_VA: {
632 result = CALL(CallIntMethodV, o, method, args);
633 break;
634 }
635 case DIRECT_PLAIN: {
636 result = CALL(CallNonvirtualIntMethod, o, InstanceFromNative,
637 method);
638 break;
639 }
640 case DIRECT_ARRAY: {
641 result = CALL(CallNonvirtualIntMethodA, o, InstanceFromNative,
642 method, NULL);
643 break;
644 }
645 case DIRECT_VA: {
646 result = CALL(CallNonvirtualIntMethodV, o, InstanceFromNative,
647 method, args);
648 break;
649 }
650 case STATIC_PLAIN: {
651 result = CALL(CallStaticIntMethod, StaticFromNative, method);
652 break;
653 }
654 case STATIC_ARRAY: {
655 result = CALL(CallStaticIntMethodA, StaticFromNative, method,
656 NULL);
657 break;
658 }
659 case STATIC_VA: {
660 result = CALL(CallStaticIntMethodV, StaticFromNative, method,
661 args);
662 break;
663 }
664 default: {
665 va_end(args);
666 return failure("shouldn't happen");
667 }
668 }
669
670 va_end(args);
671
672 return FAIL_IF_UNEQUAL("%d", 4004004, result);
673 }
674
TEST_DECLARATION(CallIntMethod)675 TEST_DECLARATION(CallIntMethod) {
676 return help_CallIntMethod(env, VIRTUAL_PLAIN);
677 }
678
TEST_DECLARATION(CallIntMethodA)679 TEST_DECLARATION(CallIntMethodA) {
680 return help_CallIntMethod(env, VIRTUAL_ARRAY);
681 }
682
TEST_DECLARATION(CallIntMethodV)683 TEST_DECLARATION(CallIntMethodV) {
684 return help_CallIntMethod(env, VIRTUAL_VA);
685 }
686
TEST_DECLARATION(CallNonvirtualIntMethod)687 TEST_DECLARATION(CallNonvirtualIntMethod) {
688 return help_CallIntMethod(env, DIRECT_PLAIN);
689 }
690
TEST_DECLARATION(CallNonvirtualIntMethodA)691 TEST_DECLARATION(CallNonvirtualIntMethodA) {
692 return help_CallIntMethod(env, DIRECT_ARRAY);
693 }
694
TEST_DECLARATION(CallNonvirtualIntMethodV)695 TEST_DECLARATION(CallNonvirtualIntMethodV) {
696 return help_CallIntMethod(env, DIRECT_VA);
697 }
698
TEST_DECLARATION(CallStaticIntMethod)699 TEST_DECLARATION(CallStaticIntMethod) {
700 return help_CallIntMethod(env, STATIC_PLAIN);
701 }
702
TEST_DECLARATION(CallStaticIntMethodA)703 TEST_DECLARATION(CallStaticIntMethodA) {
704 return help_CallIntMethod(env, STATIC_ARRAY);
705 }
706
TEST_DECLARATION(CallStaticIntMethodV)707 TEST_DECLARATION(CallStaticIntMethodV) {
708 return help_CallIntMethod(env, STATIC_VA);
709 }
710
help_CallLongMethod(JNIEnv * env,int ct,...)711 static char *help_CallLongMethod(JNIEnv *env, int ct, ...) {
712 va_list args;
713 va_start(args, ct);
714
715 char *msg;
716 jobject o = getStandardInstance(env);
717 jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
718 "returnLong", "()J");
719
720 if (method == NULL) {
721 va_end(args);
722 return msg;
723 }
724
725 jlong result;
726
727 switch (ct) {
728 case VIRTUAL_PLAIN: {
729 result = CALL(CallLongMethod, o, method);
730 break;
731 }
732 case VIRTUAL_ARRAY: {
733 result = CALL(CallLongMethodA, o, method, NULL);
734 break;
735 }
736 case VIRTUAL_VA: {
737 result = CALL(CallLongMethodV, o, method, args);
738 break;
739 }
740 case DIRECT_PLAIN: {
741 result = CALL(CallNonvirtualLongMethod, o, InstanceFromNative,
742 method);
743 break;
744 }
745 case DIRECT_ARRAY: {
746 result = CALL(CallNonvirtualLongMethodA, o, InstanceFromNative,
747 method, NULL);
748 break;
749 }
750 case DIRECT_VA: {
751 result = CALL(CallNonvirtualLongMethodV, o, InstanceFromNative,
752 method, args);
753 break;
754 }
755 case STATIC_PLAIN: {
756 result = CALL(CallStaticLongMethod, StaticFromNative, method);
757 break;
758 }
759 case STATIC_ARRAY: {
760 result = CALL(CallStaticLongMethodA, StaticFromNative, method,
761 NULL);
762 break;
763 }
764 case STATIC_VA: {
765 result = CALL(CallStaticLongMethodV, StaticFromNative, method,
766 args);
767 break;
768 }
769 default: {
770 va_end(args);
771 return failure("shouldn't happen");
772 }
773 }
774
775 va_end(args);
776
777 return FAIL_IF_UNEQUAL("%" PRId64, -80080080087LL, result);
778 }
779
TEST_DECLARATION(CallLongMethod)780 TEST_DECLARATION(CallLongMethod) {
781 return help_CallLongMethod(env, VIRTUAL_PLAIN);
782 }
783
TEST_DECLARATION(CallLongMethodA)784 TEST_DECLARATION(CallLongMethodA) {
785 return help_CallLongMethod(env, VIRTUAL_ARRAY);
786 }
787
TEST_DECLARATION(CallLongMethodV)788 TEST_DECLARATION(CallLongMethodV) {
789 return help_CallLongMethod(env, VIRTUAL_VA);
790 }
791
TEST_DECLARATION(CallNonvirtualLongMethod)792 TEST_DECLARATION(CallNonvirtualLongMethod) {
793 return help_CallLongMethod(env, DIRECT_PLAIN);
794 }
795
TEST_DECLARATION(CallNonvirtualLongMethodA)796 TEST_DECLARATION(CallNonvirtualLongMethodA) {
797 return help_CallLongMethod(env, DIRECT_ARRAY);
798 }
799
TEST_DECLARATION(CallNonvirtualLongMethodV)800 TEST_DECLARATION(CallNonvirtualLongMethodV) {
801 return help_CallLongMethod(env, DIRECT_VA);
802 }
803
TEST_DECLARATION(CallStaticLongMethod)804 TEST_DECLARATION(CallStaticLongMethod) {
805 return help_CallLongMethod(env, STATIC_PLAIN);
806 }
807
TEST_DECLARATION(CallStaticLongMethodA)808 TEST_DECLARATION(CallStaticLongMethodA) {
809 return help_CallLongMethod(env, STATIC_ARRAY);
810 }
811
TEST_DECLARATION(CallStaticLongMethodV)812 TEST_DECLARATION(CallStaticLongMethodV) {
813 return help_CallLongMethod(env, STATIC_VA);
814 }
815
help_CallFloatMethod(JNIEnv * env,int ct,...)816 static char *help_CallFloatMethod(JNIEnv *env, int ct, ...) {
817 va_list args;
818 va_start(args, ct);
819
820 char *msg;
821 jobject o = getStandardInstance(env);
822 jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
823 "returnFloat", "()F");
824
825 if (method == NULL) {
826 va_end(args);
827 return msg;
828 }
829
830 jfloat result;
831
832 switch (ct) {
833 case VIRTUAL_PLAIN: {
834 result = CALL(CallFloatMethod, o, method);
835 break;
836 }
837 case VIRTUAL_ARRAY: {
838 result = CALL(CallFloatMethodA, o, method, NULL);
839 break;
840 }
841 case VIRTUAL_VA: {
842 result = CALL(CallFloatMethodV, o, method, args);
843 break;
844 }
845 case DIRECT_PLAIN: {
846 result = CALL(CallNonvirtualFloatMethod, o, InstanceFromNative,
847 method);
848 break;
849 }
850 case DIRECT_ARRAY: {
851 result = CALL(CallNonvirtualFloatMethodA, o, InstanceFromNative,
852 method, NULL);
853 break;
854 }
855 case DIRECT_VA: {
856 result = CALL(CallNonvirtualFloatMethodV, o, InstanceFromNative,
857 method, args);
858 break;
859 }
860 case STATIC_PLAIN: {
861 result = CALL(CallStaticFloatMethod, StaticFromNative, method);
862 break;
863 }
864 case STATIC_ARRAY: {
865 result = CALL(CallStaticFloatMethodA, StaticFromNative, method,
866 NULL);
867 break;
868 }
869 case STATIC_VA: {
870 result = CALL(CallStaticFloatMethodV, StaticFromNative, method,
871 args);
872 break;
873 }
874 default: {
875 va_end(args);
876 return failure("shouldn't happen");
877 }
878 }
879
880 va_end(args);
881
882 return FAIL_IF_UNEQUAL("%g", 2.5e22f, result);
883 }
884
TEST_DECLARATION(CallFloatMethod)885 TEST_DECLARATION(CallFloatMethod) {
886 return help_CallFloatMethod(env, VIRTUAL_PLAIN);
887 }
888
TEST_DECLARATION(CallFloatMethodA)889 TEST_DECLARATION(CallFloatMethodA) {
890 return help_CallFloatMethod(env, VIRTUAL_ARRAY);
891 }
892
TEST_DECLARATION(CallFloatMethodV)893 TEST_DECLARATION(CallFloatMethodV) {
894 return help_CallFloatMethod(env, VIRTUAL_VA);
895 }
896
TEST_DECLARATION(CallNonvirtualFloatMethod)897 TEST_DECLARATION(CallNonvirtualFloatMethod) {
898 return help_CallFloatMethod(env, DIRECT_PLAIN);
899 }
900
TEST_DECLARATION(CallNonvirtualFloatMethodA)901 TEST_DECLARATION(CallNonvirtualFloatMethodA) {
902 return help_CallFloatMethod(env, DIRECT_ARRAY);
903 }
904
TEST_DECLARATION(CallNonvirtualFloatMethodV)905 TEST_DECLARATION(CallNonvirtualFloatMethodV) {
906 return help_CallFloatMethod(env, DIRECT_VA);
907 }
908
TEST_DECLARATION(CallStaticFloatMethod)909 TEST_DECLARATION(CallStaticFloatMethod) {
910 return help_CallFloatMethod(env, STATIC_PLAIN);
911 }
912
TEST_DECLARATION(CallStaticFloatMethodA)913 TEST_DECLARATION(CallStaticFloatMethodA) {
914 return help_CallFloatMethod(env, STATIC_ARRAY);
915 }
916
TEST_DECLARATION(CallStaticFloatMethodV)917 TEST_DECLARATION(CallStaticFloatMethodV) {
918 return help_CallFloatMethod(env, STATIC_VA);
919 }
920
help_CallDoubleMethod(JNIEnv * env,int ct,...)921 static char *help_CallDoubleMethod(JNIEnv *env, int ct, ...) {
922 va_list args;
923 va_start(args, ct);
924
925 char *msg;
926 jobject o = getStandardInstance(env);
927 jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
928 "returnDouble", "()D");
929
930 if (method == NULL) {
931 va_end(args);
932 return msg;
933 }
934
935 jdouble result;
936
937 switch (ct) {
938 case VIRTUAL_PLAIN: {
939 result = CALL(CallDoubleMethod, o, method);
940 break;
941 }
942 case VIRTUAL_ARRAY: {
943 result = CALL(CallDoubleMethodA, o, method, NULL);
944 break;
945 }
946 case VIRTUAL_VA: {
947 result = CALL(CallDoubleMethodV, o, method, args);
948 break;
949 }
950 case DIRECT_PLAIN: {
951 result = CALL(CallNonvirtualDoubleMethod, o, InstanceFromNative,
952 method);
953 break;
954 }
955 case DIRECT_ARRAY: {
956 result = CALL(CallNonvirtualDoubleMethodA, o, InstanceFromNative,
957 method, NULL);
958 break;
959 }
960 case DIRECT_VA: {
961 result = CALL(CallNonvirtualDoubleMethodV, o, InstanceFromNative,
962 method, args);
963 break;
964 }
965 case STATIC_PLAIN: {
966 result = CALL(CallStaticDoubleMethod, StaticFromNative, method);
967 break;
968 }
969 case STATIC_ARRAY: {
970 result = CALL(CallStaticDoubleMethodA, StaticFromNative, method,
971 NULL);
972 break;
973 }
974 case STATIC_VA: {
975 result = CALL(CallStaticDoubleMethodV, StaticFromNative, method,
976 args);
977 break;
978 }
979 default: {
980 va_end(args);
981 return failure("shouldn't happen");
982 }
983 }
984
985 va_end(args);
986
987 return FAIL_IF_UNEQUAL("%g", 7.503e100, result);
988 }
989
TEST_DECLARATION(CallDoubleMethod)990 TEST_DECLARATION(CallDoubleMethod) {
991 return help_CallDoubleMethod(env, VIRTUAL_PLAIN);
992 }
993
TEST_DECLARATION(CallDoubleMethodA)994 TEST_DECLARATION(CallDoubleMethodA) {
995 return help_CallDoubleMethod(env, VIRTUAL_ARRAY);
996 }
997
TEST_DECLARATION(CallDoubleMethodV)998 TEST_DECLARATION(CallDoubleMethodV) {
999 return help_CallDoubleMethod(env, VIRTUAL_VA);
1000 }
1001
TEST_DECLARATION(CallNonvirtualDoubleMethod)1002 TEST_DECLARATION(CallNonvirtualDoubleMethod) {
1003 return help_CallDoubleMethod(env, DIRECT_PLAIN);
1004 }
1005
TEST_DECLARATION(CallNonvirtualDoubleMethodA)1006 TEST_DECLARATION(CallNonvirtualDoubleMethodA) {
1007 return help_CallDoubleMethod(env, DIRECT_ARRAY);
1008 }
1009
TEST_DECLARATION(CallNonvirtualDoubleMethodV)1010 TEST_DECLARATION(CallNonvirtualDoubleMethodV) {
1011 return help_CallDoubleMethod(env, DIRECT_VA);
1012 }
1013
TEST_DECLARATION(CallStaticDoubleMethod)1014 TEST_DECLARATION(CallStaticDoubleMethod) {
1015 return help_CallDoubleMethod(env, STATIC_PLAIN);
1016 }
1017
TEST_DECLARATION(CallStaticDoubleMethodA)1018 TEST_DECLARATION(CallStaticDoubleMethodA) {
1019 return help_CallDoubleMethod(env, STATIC_ARRAY);
1020 }
1021
TEST_DECLARATION(CallStaticDoubleMethodV)1022 TEST_DECLARATION(CallStaticDoubleMethodV) {
1023 return help_CallDoubleMethod(env, STATIC_VA);
1024 }
1025
help_CallVoidMethod(JNIEnv * env,int ct,...)1026 static char *help_CallVoidMethod(JNIEnv *env, int ct, ...) {
1027 va_list args;
1028 va_start(args, ct);
1029
1030 char *msg;
1031 jobject o = getStandardInstance(env);
1032 jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
1033 "nop", "()V");
1034
1035 if (method == NULL) {
1036 va_end(args);
1037 return msg;
1038 }
1039
1040 // For these, we simply consider "success" to be "didn't crash."
1041
1042 switch (ct) {
1043 case VIRTUAL_PLAIN: {
1044 CALL(CallVoidMethod, o, method);
1045 break;
1046 }
1047 case VIRTUAL_ARRAY: {
1048 CALL(CallVoidMethodA, o, method, NULL);
1049 break;
1050 }
1051 case VIRTUAL_VA: {
1052 CALL(CallVoidMethodV, o, method, args);
1053 break;
1054 }
1055 case DIRECT_PLAIN: {
1056 CALL(CallNonvirtualVoidMethod, o, InstanceFromNative,
1057 method);
1058 break;
1059 }
1060 case DIRECT_ARRAY: {
1061 CALL(CallNonvirtualVoidMethodA, o, InstanceFromNative,
1062 method, NULL);
1063 break;
1064 }
1065 case DIRECT_VA: {
1066 CALL(CallNonvirtualVoidMethodV, o, InstanceFromNative,
1067 method, args);
1068 break;
1069 }
1070 case STATIC_PLAIN: {
1071 CALL(CallStaticVoidMethod, StaticFromNative, method);
1072 break;
1073 }
1074 case STATIC_ARRAY: {
1075 CALL(CallStaticVoidMethodA, StaticFromNative, method,
1076 NULL);
1077 break;
1078 }
1079 case STATIC_VA: {
1080 CALL(CallStaticVoidMethodV, StaticFromNative, method,
1081 args);
1082 break;
1083 }
1084 default: {
1085 va_end(args);
1086 return failure("shouldn't happen");
1087 }
1088 }
1089
1090 va_end(args);
1091
1092 return NULL;
1093 }
1094
TEST_DECLARATION(CallVoidMethod)1095 TEST_DECLARATION(CallVoidMethod) {
1096 return help_CallVoidMethod(env, VIRTUAL_PLAIN);
1097 }
1098
TEST_DECLARATION(CallVoidMethodA)1099 TEST_DECLARATION(CallVoidMethodA) {
1100 return help_CallVoidMethod(env, VIRTUAL_ARRAY);
1101 }
1102
TEST_DECLARATION(CallVoidMethodV)1103 TEST_DECLARATION(CallVoidMethodV) {
1104 return help_CallVoidMethod(env, VIRTUAL_VA);
1105 }
1106
TEST_DECLARATION(CallNonvirtualVoidMethod)1107 TEST_DECLARATION(CallNonvirtualVoidMethod) {
1108 return help_CallVoidMethod(env, DIRECT_PLAIN);
1109 }
1110
TEST_DECLARATION(CallNonvirtualVoidMethodA)1111 TEST_DECLARATION(CallNonvirtualVoidMethodA) {
1112 return help_CallVoidMethod(env, DIRECT_ARRAY);
1113 }
1114
TEST_DECLARATION(CallNonvirtualVoidMethodV)1115 TEST_DECLARATION(CallNonvirtualVoidMethodV) {
1116 return help_CallVoidMethod(env, DIRECT_VA);
1117 }
1118
TEST_DECLARATION(CallStaticVoidMethod)1119 TEST_DECLARATION(CallStaticVoidMethod) {
1120 return help_CallVoidMethod(env, STATIC_PLAIN);
1121 }
1122
TEST_DECLARATION(CallStaticVoidMethodA)1123 TEST_DECLARATION(CallStaticVoidMethodA) {
1124 return help_CallVoidMethod(env, STATIC_ARRAY);
1125 }
1126
TEST_DECLARATION(CallStaticVoidMethodV)1127 TEST_DECLARATION(CallStaticVoidMethodV) {
1128 return help_CallVoidMethod(env, STATIC_VA);
1129 }
1130
help_CallObjectMethod(JNIEnv * env,int ct,...)1131 static char *help_CallObjectMethod(JNIEnv *env, int ct, ...) {
1132 va_list args;
1133 va_start(args, ct);
1134
1135 char *msg;
1136 jobject o = getStandardInstance(env);
1137 jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
1138 "returnString", "()Ljava/lang/String;");
1139
1140 if (method == NULL) {
1141 va_end(args);
1142 return msg;
1143 }
1144
1145 jstring result;
1146
1147 switch (ct) {
1148 case VIRTUAL_PLAIN: {
1149 result = (jstring) CALL(CallObjectMethod, o, method);
1150 break;
1151 }
1152 case VIRTUAL_ARRAY: {
1153 result = (jstring) CALL(CallObjectMethodA, o, method, NULL);
1154 break;
1155 }
1156 case VIRTUAL_VA: {
1157 result = (jstring) CALL(CallObjectMethodV, o, method, args);
1158 break;
1159 }
1160 case DIRECT_PLAIN: {
1161 result = (jstring)
1162 CALL(CallNonvirtualObjectMethod, o, InstanceFromNative,
1163 method);
1164 break;
1165 }
1166 case DIRECT_ARRAY: {
1167 result = (jstring)
1168 CALL(CallNonvirtualObjectMethodA, o, InstanceFromNative,
1169 method, NULL);
1170 break;
1171 }
1172 case DIRECT_VA: {
1173 result = (jstring)
1174 CALL(CallNonvirtualObjectMethodV, o, InstanceFromNative,
1175 method, args);
1176 break;
1177 }
1178 case STATIC_PLAIN: {
1179 result = (jstring)
1180 CALL(CallStaticObjectMethod, StaticFromNative, method);
1181 break;
1182 }
1183 case STATIC_ARRAY: {
1184 result = (jstring)
1185 CALL(CallStaticObjectMethodA, StaticFromNative, method, NULL);
1186 break;
1187 }
1188 case STATIC_VA: {
1189 result = (jstring)
1190 CALL(CallStaticObjectMethodV, StaticFromNative, method, args);
1191 break;
1192 }
1193 default: {
1194 va_end(args);
1195 return failure("shouldn't happen");
1196 }
1197 }
1198
1199 va_end(args);
1200
1201 if (result == NULL) {
1202 return failure("got null from call");
1203 }
1204
1205 const char *utf = CALL(GetStringUTFChars, result, NULL);
1206
1207 if (strcmp(utf, "muffins") == 0) {
1208 msg = NULL;
1209 } else {
1210 msg = failure("unexpected string: %s", utf);
1211 }
1212
1213 CALL(ReleaseStringUTFChars, result, utf);
1214
1215 return msg;
1216 }
1217
TEST_DECLARATION(CallObjectMethod)1218 TEST_DECLARATION(CallObjectMethod) {
1219 return help_CallObjectMethod(env, VIRTUAL_PLAIN);
1220 }
1221
TEST_DECLARATION(CallObjectMethodA)1222 TEST_DECLARATION(CallObjectMethodA) {
1223 return help_CallObjectMethod(env, VIRTUAL_ARRAY);
1224 }
1225
TEST_DECLARATION(CallObjectMethodV)1226 TEST_DECLARATION(CallObjectMethodV) {
1227 return help_CallObjectMethod(env, VIRTUAL_VA);
1228 }
1229
TEST_DECLARATION(CallNonvirtualObjectMethod)1230 TEST_DECLARATION(CallNonvirtualObjectMethod) {
1231 return help_CallObjectMethod(env, DIRECT_PLAIN);
1232 }
1233
TEST_DECLARATION(CallNonvirtualObjectMethodA)1234 TEST_DECLARATION(CallNonvirtualObjectMethodA) {
1235 return help_CallObjectMethod(env, DIRECT_ARRAY);
1236 }
1237
TEST_DECLARATION(CallNonvirtualObjectMethodV)1238 TEST_DECLARATION(CallNonvirtualObjectMethodV) {
1239 return help_CallObjectMethod(env, DIRECT_VA);
1240 }
1241
TEST_DECLARATION(CallStaticObjectMethod)1242 TEST_DECLARATION(CallStaticObjectMethod) {
1243 return help_CallObjectMethod(env, STATIC_PLAIN);
1244 }
1245
TEST_DECLARATION(CallStaticObjectMethodA)1246 TEST_DECLARATION(CallStaticObjectMethodA) {
1247 return help_CallObjectMethod(env, STATIC_ARRAY);
1248 }
1249
TEST_DECLARATION(CallStaticObjectMethodV)1250 TEST_DECLARATION(CallStaticObjectMethodV) {
1251 return help_CallObjectMethod(env, STATIC_VA);
1252 }
1253
help_TakeOneOfEach(JNIEnv * env,int ct,...)1254 static char *help_TakeOneOfEach(JNIEnv *env, int ct, ...) {
1255 va_list args;
1256 va_start(args, ct);
1257
1258 char *msg;
1259 jobject o = getStandardInstance(env);
1260 jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
1261 "takeOneOfEach", "(DFJICSBZLjava/lang/String;)Z");
1262
1263 if (method == NULL) {
1264 va_end(args);
1265 return msg;
1266 }
1267
1268 jvalue jargs[] = {
1269 {.d = 0.0}, {.f = 1.0f}, {.j = 2LL}, {.i = 3}, {.c = 4}, {.s = 5},
1270 {.b = 6}, {.z = true}, {.l = biscuits}
1271 };
1272
1273 jboolean result;
1274
1275 switch (ct) {
1276 case VIRTUAL_PLAIN: {
1277 result = CALL(CallBooleanMethod, o, method,
1278 0.0, 1.0f, 2LL, 3, (jchar) 4, (jshort) 5, (jbyte) 6,
1279 (jboolean) true, biscuits);
1280 break;
1281 }
1282 case VIRTUAL_ARRAY: {
1283 result = CALL(CallBooleanMethodA, o, method, jargs);
1284 break;
1285 }
1286 case VIRTUAL_VA: {
1287 result = CALL(CallBooleanMethodV, o, method, args);
1288 break;
1289 }
1290 case DIRECT_PLAIN: {
1291 result = CALL(CallNonvirtualBooleanMethod, o, InstanceFromNative,
1292 method,
1293 0.0, 1.0f, 2LL, 3, (jchar) 4, (jshort) 5, (jbyte) 6,
1294 (jboolean) true, biscuits);
1295 break;
1296 }
1297 case DIRECT_ARRAY: {
1298 result = CALL(CallNonvirtualBooleanMethodA, o, InstanceFromNative,
1299 method, jargs);
1300 break;
1301 }
1302 case DIRECT_VA: {
1303 result = CALL(CallNonvirtualBooleanMethodV, o, InstanceFromNative,
1304 method, args);
1305 break;
1306 }
1307 case STATIC_PLAIN: {
1308 result = CALL(CallStaticBooleanMethod, StaticFromNative, method,
1309 0.0, 1.0f, 2LL, 3, (jchar) 4, (jshort) 5, (jbyte) 6,
1310 (jboolean) true, biscuits);
1311 break;
1312 }
1313 case STATIC_ARRAY: {
1314 result = CALL(CallStaticBooleanMethodA, StaticFromNative, method,
1315 jargs);
1316 break;
1317 }
1318 case STATIC_VA: {
1319 result = CALL(CallStaticBooleanMethodV, StaticFromNative, method,
1320 args);
1321 break;
1322 }
1323 default: {
1324 va_end(args);
1325 return failure("shouldn't happen");
1326 }
1327 }
1328
1329 va_end(args);
1330
1331 return FAIL_IF_UNEQUAL("%d", true, result);
1332 }
1333
TEST_DECLARATION(TakeOneOfEach)1334 TEST_DECLARATION(TakeOneOfEach) {
1335 return help_TakeOneOfEach(env, VIRTUAL_PLAIN);
1336 }
1337
TEST_DECLARATION(TakeOneOfEachA)1338 TEST_DECLARATION(TakeOneOfEachA) {
1339 return help_TakeOneOfEach(env, VIRTUAL_ARRAY);
1340 }
1341
TEST_DECLARATION(TakeOneOfEachV)1342 TEST_DECLARATION(TakeOneOfEachV) {
1343 return help_TakeOneOfEach(env, VIRTUAL_VA,
1344 0.0, 1.0f, 2LL, 3, (jchar) 4, (jshort) 5, (jbyte) 6,
1345 (jboolean) true, biscuits);
1346 }
1347
TEST_DECLARATION(NonvirtualTakeOneOfEach)1348 TEST_DECLARATION(NonvirtualTakeOneOfEach) {
1349 return help_TakeOneOfEach(env, DIRECT_PLAIN);
1350 }
1351
TEST_DECLARATION(NonvirtualTakeOneOfEachA)1352 TEST_DECLARATION(NonvirtualTakeOneOfEachA) {
1353 return help_TakeOneOfEach(env, DIRECT_ARRAY);
1354 }
1355
TEST_DECLARATION(NonvirtualTakeOneOfEachV)1356 TEST_DECLARATION(NonvirtualTakeOneOfEachV) {
1357 return help_TakeOneOfEach(env, DIRECT_VA,
1358 0.0, 1.0f, 2LL, 3, (jchar) 4, (jshort) 5, (jbyte) 6,
1359 (jboolean) true, biscuits);
1360 }
1361
TEST_DECLARATION(StaticTakeOneOfEach)1362 TEST_DECLARATION(StaticTakeOneOfEach) {
1363 return help_TakeOneOfEach(env, STATIC_PLAIN);
1364 }
1365
TEST_DECLARATION(StaticTakeOneOfEachA)1366 TEST_DECLARATION(StaticTakeOneOfEachA) {
1367 return help_TakeOneOfEach(env, STATIC_ARRAY);
1368 }
1369
TEST_DECLARATION(StaticTakeOneOfEachV)1370 TEST_DECLARATION(StaticTakeOneOfEachV) {
1371 return help_TakeOneOfEach(env, STATIC_VA,
1372 0.0, 1.0f, 2LL, 3, (jchar) 4, (jshort) 5, (jbyte) 6,
1373 (jboolean) true, biscuits);
1374 }
1375
help_TakeCoolHandLuke(JNIEnv * env,int ct,...)1376 static char *help_TakeCoolHandLuke(JNIEnv *env, int ct, ...) {
1377 va_list args;
1378 va_start(args, ct);
1379
1380 char *msg;
1381 jobject o = getStandardInstance(env);
1382 jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
1383 "takeCoolHandLuke",
1384 "(IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII)Z");
1385
1386 if (method == NULL) {
1387 va_end(args);
1388 return msg;
1389 }
1390
1391 jvalue jargs[] = {
1392 {.i = 1}, {.i = 2}, {.i = 3}, {.i = 4},
1393 {.i = 5}, {.i = 6}, {.i = 7}, {.i = 8}, {.i = 9},
1394 {.i = 10}, {.i = 11}, {.i = 12}, {.i = 13}, {.i = 14},
1395 {.i = 15}, {.i = 16}, {.i = 17}, {.i = 18}, {.i = 19},
1396 {.i = 20}, {.i = 21}, {.i = 22}, {.i = 23}, {.i = 24},
1397 {.i = 25}, {.i = 26}, {.i = 27}, {.i = 28}, {.i = 29},
1398 {.i = 30}, {.i = 31}, {.i = 32}, {.i = 33}, {.i = 34},
1399 {.i = 35}, {.i = 36}, {.i = 37}, {.i = 38}, {.i = 39},
1400 {.i = 40}, {.i = 41}, {.i = 42}, {.i = 43}, {.i = 44},
1401 {.i = 45}, {.i = 46}, {.i = 47}, {.i = 48}, {.i = 49},
1402 {.i = 50}
1403 };
1404
1405 jboolean result;
1406
1407 switch (ct) {
1408 case VIRTUAL_PLAIN: {
1409 result = CALL(CallBooleanMethod, o, method,
1410 1, 2, 3, 4, 5, 6, 7, 8, 9,
1411 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
1412 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
1413 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
1414 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
1415 50);
1416 break;
1417 }
1418 case VIRTUAL_ARRAY: {
1419 result = CALL(CallBooleanMethodA, o, method, jargs);
1420 break;
1421 }
1422 case VIRTUAL_VA: {
1423 result = CALL(CallBooleanMethodV, o, method, args);
1424 break;
1425 }
1426 case DIRECT_PLAIN: {
1427 result = CALL(CallNonvirtualBooleanMethod, o, InstanceFromNative,
1428 method,
1429 1, 2, 3, 4, 5, 6, 7, 8, 9,
1430 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
1431 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
1432 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
1433 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
1434 50);
1435 break;
1436 }
1437 case DIRECT_ARRAY: {
1438 result = CALL(CallNonvirtualBooleanMethodA, o, InstanceFromNative,
1439 method, jargs);
1440 break;
1441 }
1442 case DIRECT_VA: {
1443 result = CALL(CallNonvirtualBooleanMethodV, o, InstanceFromNative,
1444 method, args);
1445 break;
1446 }
1447 case STATIC_PLAIN: {
1448 result = CALL(CallStaticBooleanMethod, StaticFromNative, method,
1449 1, 2, 3, 4, 5, 6, 7, 8, 9,
1450 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
1451 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
1452 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
1453 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
1454 50);
1455 break;
1456 }
1457 case STATIC_ARRAY: {
1458 result = CALL(CallStaticBooleanMethodA, StaticFromNative, method,
1459 jargs);
1460 break;
1461 }
1462 case STATIC_VA: {
1463 result = CALL(CallStaticBooleanMethodV, StaticFromNative, method,
1464 args);
1465 break;
1466 }
1467 default: {
1468 va_end(args);
1469 return failure("shouldn't happen");
1470 }
1471 }
1472
1473 va_end(args);
1474
1475 return FAIL_IF_UNEQUAL("%d", true, result);
1476 }
1477
TEST_DECLARATION(TakeCoolHandLuke)1478 TEST_DECLARATION(TakeCoolHandLuke) {
1479 return help_TakeCoolHandLuke(env, VIRTUAL_PLAIN);
1480 }
1481
TEST_DECLARATION(TakeCoolHandLukeA)1482 TEST_DECLARATION(TakeCoolHandLukeA) {
1483 return help_TakeCoolHandLuke(env, VIRTUAL_ARRAY);
1484 }
1485
TEST_DECLARATION(TakeCoolHandLukeV)1486 TEST_DECLARATION(TakeCoolHandLukeV) {
1487 return help_TakeCoolHandLuke(env, VIRTUAL_VA,
1488 1, 2, 3, 4, 5, 6, 7, 8, 9,
1489 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
1490 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
1491 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
1492 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
1493 50);
1494 }
1495
TEST_DECLARATION(NonvirtualTakeCoolHandLuke)1496 TEST_DECLARATION(NonvirtualTakeCoolHandLuke) {
1497 return help_TakeCoolHandLuke(env, DIRECT_PLAIN);
1498 }
1499
TEST_DECLARATION(NonvirtualTakeCoolHandLukeA)1500 TEST_DECLARATION(NonvirtualTakeCoolHandLukeA) {
1501 return help_TakeCoolHandLuke(env, DIRECT_ARRAY);
1502 }
1503
TEST_DECLARATION(NonvirtualTakeCoolHandLukeV)1504 TEST_DECLARATION(NonvirtualTakeCoolHandLukeV) {
1505 return help_TakeCoolHandLuke(env, DIRECT_VA,
1506 1, 2, 3, 4, 5, 6, 7, 8, 9,
1507 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
1508 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
1509 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
1510 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
1511 50);
1512 }
1513
TEST_DECLARATION(StaticTakeCoolHandLuke)1514 TEST_DECLARATION(StaticTakeCoolHandLuke) {
1515 return help_TakeCoolHandLuke(env, STATIC_PLAIN);
1516 }
1517
TEST_DECLARATION(StaticTakeCoolHandLukeA)1518 TEST_DECLARATION(StaticTakeCoolHandLukeA) {
1519 return help_TakeCoolHandLuke(env, STATIC_ARRAY);
1520 }
1521
TEST_DECLARATION(StaticTakeCoolHandLukeV)1522 TEST_DECLARATION(StaticTakeCoolHandLukeV) {
1523 return help_TakeCoolHandLuke(env, STATIC_VA,
1524 1, 2, 3, 4, 5, 6, 7, 8, 9,
1525 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
1526 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
1527 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
1528 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
1529 50);
1530 }
1531
TEST_DECLARATION(DefineClass)1532 TEST_DECLARATION(DefineClass) {
1533 // Android implementations should always return NULL.
1534 jclass clazz = CALL(DefineClass, "foo", NULL, NULL, 0);
1535
1536 if (clazz != NULL) {
1537 return failure("Expected NULL but got %p", clazz);
1538 }
1539
1540 return NULL;
1541 }
1542
1543 // TODO: Missing functions:
1544 // DeleteLocalRef
1545 // DeleteWeakGlobalRef
1546 // EnsureLocalCapacity
1547 // ExceptionCheck
1548 // ExceptionClear
1549 // ExceptionDescribe
1550 // ExceptionOccurred
1551 // FatalError (Note: impossible to test in this framework)
1552 // FindClass
1553 // FromReflectedField
1554 // FromReflectedMethod
1555 // GetArrayLength
1556 // GetBooleanArrayElements
1557 // GetBooleanArrayRegion
1558 // GetBooleanField
1559 // GetByteArrayElements
1560 // GetByteArrayRegion
1561 // GetByteField
1562 // GetCharArrayElements
1563 // GetCharArrayRegion
1564 // GetCharField
1565 // GetDirectBufferAddress
1566 // GetDirectBufferCapacity
1567 // GetDoubleArrayElements
1568 // GetDoubleArrayRegion
1569 // GetDoubleField
1570 // GetFieldID
1571 // GetFloatArrayElements
1572 // GetFloatArrayRegion
1573 // GetFloatField
1574 // GetIntArrayElements
1575 // GetIntArrayRegion
1576 // GetIntField
1577 // GetJavaVM
1578 // GetLongArrayElements
1579 // GetLongArrayRegion
1580 // GetLongField
1581 // GetMethodID
1582 // GetObjectArrayElement
1583 // GetObjectClass
1584 // GetObjectField
1585 // GetObjectRefType (since 1.6)
1586 // GetPrimitiveArrayCritical
1587 // GetShortArrayElements
1588 // GetShortArrayRegion
1589 // GetShortField
1590 // GetStaticBooleanField
1591 // GetStaticByteField
1592 // GetStaticCharField
1593 // GetStaticDoubleField
1594 // GetStaticFieldID
1595 // GetStaticFloatField
1596 // GetStaticIntField
1597 // GetStaticLongField
1598 // GetStaticMethodID
1599 // GetStaticObjectField
1600 // GetStaticShortField
1601 // GetStringChars
1602 // GetStringCritical
1603 // GetStringLength
1604 // GetStringRegion
1605 // GetStringUTFChars
1606 // GetStringUTFLength
1607 // GetStringUTFRegion
1608 // GetSuperclass
1609
TEST_DECLARATION(GetVersion)1610 TEST_DECLARATION(GetVersion) {
1611 // Android implementations should all be at version 1.6.
1612 jint version = CALL(GetVersion);
1613
1614 if (version != JNI_VERSION_1_6) {
1615 return failure("Expected JNI_VERSION_1_6 but got 0x%x", version);
1616 }
1617
1618 return NULL;
1619 }
1620
1621 // TODO: Missing functions:
1622 // IsAssignableFrom
1623 // IsInstanceOf
1624 // IsSameObject
1625 // MonitorEnter
1626 // MonitorExit
1627 // NewBooleanArray
1628 // NewByteArray
1629 // NewCharArray
1630 // NewDirectByteBuffer
1631 // NewDoubleArray
1632 // NewFloatArray
1633 // NewGlobalRef
1634 // NewIntArray
1635 // NewLocalRef
1636 // NewLongArray
1637 // NewObject
1638 // NewObjectA
1639 // NewObjectArray
1640 // NewObjectV
1641 // NewShortArray
1642 // NewString
1643 // NewStringUTF
1644 // NewWeakGlobalRef
1645 // PopLocalFrame
1646 // PushLocalFrame
1647 // RegisterNatives
1648 // ReleaseBooleanArrayElements
1649 // ReleaseByteArrayElements
1650 // ReleaseCharArrayElements
1651 // ReleaseDoubleArrayElements
1652 // ReleaseFloatArrayElements
1653 // ReleaseIntArrayElements
1654 // ReleaseLongArrayElements
1655 // ReleasePrimitiveArrayCritical
1656 // ReleaseShortArrayElements
1657 // ReleaseStringChars
1658 // ReleaseStringCritical
1659 // ReleaseStringUTFChars
1660 // SetBooleanArrayRegion
1661 // SetBooleanField
1662 // SetByteArrayRegion
1663 // SetByteField
1664 // SetCharArrayRegion
1665 // SetCharField
1666 // SetDoubleArrayRegion
1667 // SetDoubleField
1668 // SetFloatArrayRegion
1669 // SetFloatField
1670 // SetIntArrayRegion
1671 // SetIntField
1672 // SetLongArrayRegion
1673 // SetLongField
1674 // SetObjectArrayElement
1675 // SetObjectField
1676 // SetShortArrayRegion
1677 // SetShortField
1678 // SetStaticBooleanField
1679 // SetStaticByteField
1680 // SetStaticCharField
1681 // SetStaticDoubleField
1682 // SetStaticFloatField
1683 // SetStaticIntField
1684 // SetStaticLongField
1685 // SetStaticObjectField
1686 // SetStaticShortField
1687 // Throw
1688 // ThrowNew
1689 // ToReflectedField
1690 // ToReflectedMethod
1691 // UnregisterNatives
1692
1693
1694
1695 /**
1696 * Runs all the tests, returning NULL if they all succeeded, or
1697 * a string listing information about all the failures.
1698 */
runAllTests(JNIEnv * env)1699 static jstring runAllTests(JNIEnv *env) {
1700 char *result = initializeVariables(env);
1701
1702 if (CALL(ExceptionOccurred)) {
1703 CALL(ExceptionDescribe);
1704 CALL(ExceptionClear);
1705 }
1706
1707 if (result == NULL) {
1708 result = runJniTests(env,
1709 RUN_TEST(CallBooleanMethod),
1710 RUN_TEST(CallBooleanMethodA),
1711 RUN_TEST(CallBooleanMethodV),
1712 RUN_TEST(CallNonvirtualBooleanMethod),
1713 RUN_TEST(CallNonvirtualBooleanMethodA),
1714 RUN_TEST(CallNonvirtualBooleanMethodV),
1715 RUN_TEST(CallStaticBooleanMethod),
1716 RUN_TEST(CallStaticBooleanMethodA),
1717 RUN_TEST(CallStaticBooleanMethodV),
1718
1719 RUN_TEST(CallByteMethod),
1720 RUN_TEST(CallByteMethodA),
1721 RUN_TEST(CallByteMethodV),
1722 RUN_TEST(CallNonvirtualByteMethod),
1723 RUN_TEST(CallNonvirtualByteMethodA),
1724 RUN_TEST(CallNonvirtualByteMethodV),
1725 RUN_TEST(CallStaticByteMethod),
1726 RUN_TEST(CallStaticByteMethodA),
1727 RUN_TEST(CallStaticByteMethodV),
1728
1729 RUN_TEST(CallShortMethod),
1730 RUN_TEST(CallShortMethodA),
1731 RUN_TEST(CallShortMethodV),
1732 RUN_TEST(CallNonvirtualShortMethod),
1733 RUN_TEST(CallNonvirtualShortMethodA),
1734 RUN_TEST(CallNonvirtualShortMethodV),
1735 RUN_TEST(CallStaticShortMethod),
1736 RUN_TEST(CallStaticShortMethodA),
1737 RUN_TEST(CallStaticShortMethodV),
1738
1739 RUN_TEST(CallCharMethod),
1740 RUN_TEST(CallCharMethodA),
1741 RUN_TEST(CallCharMethodV),
1742 RUN_TEST(CallNonvirtualCharMethod),
1743 RUN_TEST(CallNonvirtualCharMethodA),
1744 RUN_TEST(CallNonvirtualCharMethodV),
1745 RUN_TEST(CallStaticCharMethod),
1746 RUN_TEST(CallStaticCharMethodA),
1747 RUN_TEST(CallStaticCharMethodV),
1748
1749 RUN_TEST(CallIntMethod),
1750 RUN_TEST(CallIntMethodA),
1751 RUN_TEST(CallIntMethodV),
1752 RUN_TEST(CallNonvirtualIntMethod),
1753 RUN_TEST(CallNonvirtualIntMethodA),
1754 RUN_TEST(CallNonvirtualIntMethodV),
1755 RUN_TEST(CallStaticIntMethod),
1756 RUN_TEST(CallStaticIntMethodA),
1757 RUN_TEST(CallStaticIntMethodV),
1758
1759 RUN_TEST(CallLongMethod),
1760 RUN_TEST(CallLongMethodA),
1761 RUN_TEST(CallLongMethodV),
1762 RUN_TEST(CallNonvirtualLongMethod),
1763 RUN_TEST(CallNonvirtualLongMethodA),
1764 RUN_TEST(CallNonvirtualLongMethodV),
1765 RUN_TEST(CallStaticLongMethod),
1766 RUN_TEST(CallStaticLongMethodA),
1767 RUN_TEST(CallStaticLongMethodV),
1768
1769 RUN_TEST(CallFloatMethod),
1770 RUN_TEST(CallFloatMethodA),
1771 RUN_TEST(CallFloatMethodV),
1772 RUN_TEST(CallNonvirtualFloatMethod),
1773 RUN_TEST(CallNonvirtualFloatMethodA),
1774 RUN_TEST(CallNonvirtualFloatMethodV),
1775 RUN_TEST(CallStaticFloatMethod),
1776 RUN_TEST(CallStaticFloatMethodA),
1777 RUN_TEST(CallStaticFloatMethodV),
1778
1779 RUN_TEST(CallDoubleMethod),
1780 RUN_TEST(CallDoubleMethodA),
1781 RUN_TEST(CallDoubleMethodV),
1782 RUN_TEST(CallNonvirtualDoubleMethod),
1783 RUN_TEST(CallNonvirtualDoubleMethodA),
1784 RUN_TEST(CallNonvirtualDoubleMethodV),
1785 RUN_TEST(CallStaticDoubleMethod),
1786 RUN_TEST(CallStaticDoubleMethodA),
1787 RUN_TEST(CallStaticDoubleMethodV),
1788
1789 RUN_TEST(CallVoidMethod),
1790 RUN_TEST(CallVoidMethodA),
1791 RUN_TEST(CallVoidMethodV),
1792 RUN_TEST(CallNonvirtualVoidMethod),
1793 RUN_TEST(CallNonvirtualVoidMethodA),
1794 RUN_TEST(CallNonvirtualVoidMethodV),
1795 RUN_TEST(CallStaticVoidMethod),
1796 RUN_TEST(CallStaticVoidMethodA),
1797 RUN_TEST(CallStaticVoidMethodV),
1798
1799 RUN_TEST(CallObjectMethod),
1800 RUN_TEST(CallObjectMethodA),
1801 RUN_TEST(CallObjectMethodV),
1802 RUN_TEST(CallNonvirtualObjectMethod),
1803 RUN_TEST(CallNonvirtualObjectMethodA),
1804 RUN_TEST(CallNonvirtualObjectMethodV),
1805 RUN_TEST(CallStaticObjectMethod),
1806 RUN_TEST(CallStaticObjectMethodA),
1807 RUN_TEST(CallStaticObjectMethodV),
1808
1809 RUN_TEST(TakeOneOfEach),
1810 RUN_TEST(TakeOneOfEachA),
1811 RUN_TEST(TakeOneOfEachV),
1812 RUN_TEST(NonvirtualTakeOneOfEach),
1813 RUN_TEST(NonvirtualTakeOneOfEachA),
1814 RUN_TEST(NonvirtualTakeOneOfEachV),
1815 RUN_TEST(StaticTakeOneOfEach),
1816 RUN_TEST(StaticTakeOneOfEachA),
1817 RUN_TEST(StaticTakeOneOfEachV),
1818
1819 RUN_TEST(TakeCoolHandLuke),
1820 RUN_TEST(TakeCoolHandLukeA),
1821 RUN_TEST(TakeCoolHandLukeV),
1822 RUN_TEST(NonvirtualTakeCoolHandLuke),
1823 RUN_TEST(NonvirtualTakeCoolHandLukeA),
1824 RUN_TEST(NonvirtualTakeCoolHandLukeV),
1825 RUN_TEST(StaticTakeCoolHandLuke),
1826 RUN_TEST(StaticTakeCoolHandLukeA),
1827 RUN_TEST(StaticTakeCoolHandLukeV),
1828
1829 RUN_TEST(DefineClass),
1830 RUN_TEST(GetVersion),
1831 NULL);
1832
1833 // TODO: Add more tests, above.
1834 }
1835
1836 if (result != NULL) {
1837 jstring s = CALL(NewStringUTF, result);
1838 free(result);
1839 return s;
1840 }
1841
1842 return NULL;
1843 }
1844