OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Tests for jni_generator.py. | 6 """Tests for jni_generator.py. |
7 | 7 |
8 This test suite contains various tests for the JNI generator. | 8 This test suite contains various tests for the JNI generator. |
9 It exercises the low-level parser all the way up to the | 9 It exercises the low-level parser all the way up to the |
10 code generator and ensures the output matches a golden | 10 code generator and ensures the output matches a golden |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 // base/android/jni_generator/jni_generator_tests.py | 215 // base/android/jni_generator/jni_generator_tests.py |
216 // For | 216 // For |
217 // org/chromium/TestJni | 217 // org/chromium/TestJni |
218 | 218 |
219 #ifndef org_chromium_TestJni_JNI | 219 #ifndef org_chromium_TestJni_JNI |
220 #define org_chromium_TestJni_JNI | 220 #define org_chromium_TestJni_JNI |
221 | 221 |
222 #include <jni.h> | 222 #include <jni.h> |
223 | 223 |
224 #include "base/android/jni_android.h" | 224 #include "base/android/jni_android.h" |
| 225 #include "base/android/jni_method_id.h" |
225 #include "base/android/scoped_java_ref.h" | 226 #include "base/android/scoped_java_ref.h" |
226 #include "base/basictypes.h" | 227 #include "base/basictypes.h" |
227 #include "base/logging.h" | 228 #include "base/logging.h" |
228 | 229 |
229 using base::android::ScopedJavaLocalRef; | 230 using base::android::ScopedJavaLocalRef; |
230 | 231 |
231 // Step 1: forward declarations. | 232 // Step 1: forward declarations. |
232 namespace { | 233 namespace { |
233 const char kTestJniClassPath[] = "org/chromium/TestJni"; | 234 const char kTestJniClassPath[] = "org/chromium/TestJni"; |
234 // Leaking this jclass as we cannot use LazyInstance from some threads. | 235 // Leaking this jclass as we cannot use LazyInstance from some threads. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 selectionArgs, sortOrder).Release(); | 309 selectionArgs, sortOrder).Release(); |
309 } | 310 } |
310 | 311 |
311 static void GotOrientation(JNIEnv* env, jobject obj, | 312 static void GotOrientation(JNIEnv* env, jobject obj, |
312 jint nativeDataFetcherImplAndroid, | 313 jint nativeDataFetcherImplAndroid, |
313 jdouble alpha, | 314 jdouble alpha, |
314 jdouble beta, | 315 jdouble beta, |
315 jdouble gamma) { | 316 jdouble gamma) { |
316 DCHECK(nativeDataFetcherImplAndroid) << "GotOrientation"; | 317 DCHECK(nativeDataFetcherImplAndroid) << "GotOrientation"; |
317 DataFetcherImplAndroid* native = | 318 DataFetcherImplAndroid* native = |
318 reinterpret_cast<DataFetcherImplAndroid*>(nativeDataFetcherImplAndroid); | 319 reinterpret_cast<DataFetcherImplAndroid*>(nativeDataFetcherImplAndroid); |
319 return native->GotOrientation(env, obj, alpha, beta, gamma); | 320 return native->GotOrientation(env, obj, alpha, beta, gamma); |
320 } | 321 } |
321 | 322 |
322 // Step 3: GetMethodIDs and RegisterNatives. | 323 // Step 3: RegisterNatives. |
323 static void GetMethodIDsImpl(JNIEnv* env) { | 324 |
| 325 static bool RegisterNativesImpl(JNIEnv* env) { |
| 326 |
324 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | 327 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
325 base::android::GetUnscopedClass(env, kTestJniClassPath))); | 328 base::android::GetUnscopedClass(env, kTestJniClassPath))); |
326 } | |
327 | |
328 static bool RegisterNativesImpl(JNIEnv* env) { | |
329 GetMethodIDsImpl(env); | |
330 | |
331 static const JNINativeMethod kMethodsTestJni[] = { | 329 static const JNINativeMethod kMethodsTestJni[] = { |
332 { "nativeInit", | 330 { "nativeInit", |
333 "(" | 331 "(" |
334 ")" | 332 ")" |
335 "I", reinterpret_cast<void*>(Init) }, | 333 "I", reinterpret_cast<void*>(Init) }, |
336 { "nativeDestroy", | 334 { "nativeDestroy", |
337 "(" | 335 "(" |
338 "I" | 336 "I" |
339 ")" | 337 ")" |
340 "V", reinterpret_cast<void*>(Destroy) }, | 338 "V", reinterpret_cast<void*>(Destroy) }, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 // base/android/jni_generator/jni_generator_tests.py | 454 // base/android/jni_generator/jni_generator_tests.py |
457 // For | 455 // For |
458 // org/chromium/TestJni | 456 // org/chromium/TestJni |
459 | 457 |
460 #ifndef org_chromium_TestJni_JNI | 458 #ifndef org_chromium_TestJni_JNI |
461 #define org_chromium_TestJni_JNI | 459 #define org_chromium_TestJni_JNI |
462 | 460 |
463 #include <jni.h> | 461 #include <jni.h> |
464 | 462 |
465 #include "base/android/jni_android.h" | 463 #include "base/android/jni_android.h" |
| 464 #include "base/android/jni_method_id.h" |
466 #include "base/android/scoped_java_ref.h" | 465 #include "base/android/scoped_java_ref.h" |
467 #include "base/basictypes.h" | 466 #include "base/basictypes.h" |
468 #include "base/logging.h" | 467 #include "base/logging.h" |
469 | 468 |
470 using base::android::ScopedJavaLocalRef; | 469 using base::android::ScopedJavaLocalRef; |
471 | 470 |
472 // Step 1: forward declarations. | 471 // Step 1: forward declarations. |
473 namespace { | 472 namespace { |
474 const char kTestJniClassPath[] = "org/chromium/TestJni"; | 473 const char kTestJniClassPath[] = "org/chromium/TestJni"; |
475 const char kMyInnerClassClassPath[] = "org/chromium/TestJni$MyInnerClass"; | 474 const char kMyInnerClassClassPath[] = "org/chromium/TestJni$MyInnerClass"; |
476 // Leaking this jclass as we cannot use LazyInstance from some threads. | 475 // Leaking this jclass as we cannot use LazyInstance from some threads. |
477 jclass g_TestJni_clazz = NULL; | 476 jclass g_TestJni_clazz = NULL; |
478 } // namespace | 477 } // namespace |
479 | 478 |
480 static jint Init(JNIEnv* env, jobject obj); | 479 static jint Init(JNIEnv* env, jobject obj); |
481 | 480 |
482 // Step 2: method stubs. | 481 // Step 2: method stubs. |
483 | 482 |
484 // Step 3: GetMethodIDs and RegisterNatives. | 483 // Step 3: RegisterNatives. |
485 static void GetMethodIDsImpl(JNIEnv* env) { | 484 |
| 485 static bool RegisterNativesImpl(JNIEnv* env) { |
| 486 |
486 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | 487 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
487 base::android::GetUnscopedClass(env, kTestJniClassPath))); | 488 base::android::GetUnscopedClass(env, kTestJniClassPath))); |
488 } | |
489 | |
490 static bool RegisterNativesImpl(JNIEnv* env) { | |
491 GetMethodIDsImpl(env); | |
492 | |
493 static const JNINativeMethod kMethodsMyInnerClass[] = { | 489 static const JNINativeMethod kMethodsMyInnerClass[] = { |
494 { "nativeInit", | 490 { "nativeInit", |
495 "(" | 491 "(" |
496 ")" | 492 ")" |
497 "I", reinterpret_cast<void*>(Init) }, | 493 "I", reinterpret_cast<void*>(Init) }, |
498 }; | 494 }; |
499 const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass); | 495 const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass); |
500 | 496 |
501 if (env->RegisterNatives(g_MyInnerClass_clazz, | 497 if (env->RegisterNatives(g_MyInnerClass_clazz, |
502 kMethodsMyInnerClass, | 498 kMethodsMyInnerClass, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 // base/android/jni_generator/jni_generator_tests.py | 542 // base/android/jni_generator/jni_generator_tests.py |
547 // For | 543 // For |
548 // org/chromium/TestJni | 544 // org/chromium/TestJni |
549 | 545 |
550 #ifndef org_chromium_TestJni_JNI | 546 #ifndef org_chromium_TestJni_JNI |
551 #define org_chromium_TestJni_JNI | 547 #define org_chromium_TestJni_JNI |
552 | 548 |
553 #include <jni.h> | 549 #include <jni.h> |
554 | 550 |
555 #include "base/android/jni_android.h" | 551 #include "base/android/jni_android.h" |
| 552 #include "base/android/jni_method_id.h" |
556 #include "base/android/scoped_java_ref.h" | 553 #include "base/android/scoped_java_ref.h" |
557 #include "base/basictypes.h" | 554 #include "base/basictypes.h" |
558 #include "base/logging.h" | 555 #include "base/logging.h" |
559 | 556 |
560 using base::android::ScopedJavaLocalRef; | 557 using base::android::ScopedJavaLocalRef; |
561 | 558 |
562 // Step 1: forward declarations. | 559 // Step 1: forward declarations. |
563 namespace { | 560 namespace { |
564 const char kMyOtherInnerClassClassPath[] = | 561 const char kMyOtherInnerClassClassPath[] = |
565 "org/chromium/TestJni$MyOtherInnerClass"; | 562 "org/chromium/TestJni$MyOtherInnerClass"; |
566 const char kTestJniClassPath[] = "org/chromium/TestJni"; | 563 const char kTestJniClassPath[] = "org/chromium/TestJni"; |
567 const char kMyInnerClassClassPath[] = "org/chromium/TestJni$MyInnerClass"; | 564 const char kMyInnerClassClassPath[] = "org/chromium/TestJni$MyInnerClass"; |
568 // Leaking this jclass as we cannot use LazyInstance from some threads. | 565 // Leaking this jclass as we cannot use LazyInstance from some threads. |
569 jclass g_TestJni_clazz = NULL; | 566 jclass g_TestJni_clazz = NULL; |
570 } // namespace | 567 } // namespace |
571 | 568 |
572 static jint Init(JNIEnv* env, jobject obj); | 569 static jint Init(JNIEnv* env, jobject obj); |
573 | 570 |
574 static jint Init(JNIEnv* env, jobject obj); | 571 static jint Init(JNIEnv* env, jobject obj); |
575 | 572 |
576 // Step 2: method stubs. | 573 // Step 2: method stubs. |
577 | 574 |
578 // Step 3: GetMethodIDs and RegisterNatives. | 575 // Step 3: RegisterNatives. |
579 static void GetMethodIDsImpl(JNIEnv* env) { | 576 |
| 577 static bool RegisterNativesImpl(JNIEnv* env) { |
| 578 |
580 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | 579 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
581 base::android::GetUnscopedClass(env, kTestJniClassPath))); | 580 base::android::GetUnscopedClass(env, kTestJniClassPath))); |
582 } | |
583 | |
584 static bool RegisterNativesImpl(JNIEnv* env) { | |
585 GetMethodIDsImpl(env); | |
586 | |
587 static const JNINativeMethod kMethodsMyOtherInnerClass[] = { | 581 static const JNINativeMethod kMethodsMyOtherInnerClass[] = { |
588 { "nativeInit", | 582 { "nativeInit", |
589 "(" | 583 "(" |
590 ")" | 584 ")" |
591 "I", reinterpret_cast<void*>(Init) }, | 585 "I", reinterpret_cast<void*>(Init) }, |
592 }; | 586 }; |
593 const int kMethodsMyOtherInnerClassSize = | 587 const int kMethodsMyOtherInnerClassSize = |
594 arraysize(kMethodsMyOtherInnerClass); | 588 arraysize(kMethodsMyOtherInnerClass); |
595 | 589 |
596 if (env->RegisterNatives(g_MyOtherInnerClass_clazz, | 590 if (env->RegisterNatives(g_MyOtherInnerClass_clazz, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 // base/android/jni_generator/jni_generator_tests.py | 649 // base/android/jni_generator/jni_generator_tests.py |
656 // For | 650 // For |
657 // org/chromium/TestJni | 651 // org/chromium/TestJni |
658 | 652 |
659 #ifndef org_chromium_TestJni_JNI | 653 #ifndef org_chromium_TestJni_JNI |
660 #define org_chromium_TestJni_JNI | 654 #define org_chromium_TestJni_JNI |
661 | 655 |
662 #include <jni.h> | 656 #include <jni.h> |
663 | 657 |
664 #include "base/android/jni_android.h" | 658 #include "base/android/jni_android.h" |
| 659 #include "base/android/jni_method_id.h" |
665 #include "base/android/scoped_java_ref.h" | 660 #include "base/android/scoped_java_ref.h" |
666 #include "base/basictypes.h" | 661 #include "base/basictypes.h" |
667 #include "base/logging.h" | 662 #include "base/logging.h" |
668 | 663 |
669 using base::android::ScopedJavaLocalRef; | 664 using base::android::ScopedJavaLocalRef; |
670 | 665 |
671 // Step 1: forward declarations. | 666 // Step 1: forward declarations. |
672 namespace { | 667 namespace { |
673 const char kMyOtherInnerClassClassPath[] = | 668 const char kMyOtherInnerClassClassPath[] = |
674 "org/chromium/TestJni$MyOtherInnerClass"; | 669 "org/chromium/TestJni$MyOtherInnerClass"; |
675 const char kTestJniClassPath[] = "org/chromium/TestJni"; | 670 const char kTestJniClassPath[] = "org/chromium/TestJni"; |
676 // Leaking this jclass as we cannot use LazyInstance from some threads. | 671 // Leaking this jclass as we cannot use LazyInstance from some threads. |
677 jclass g_TestJni_clazz = NULL; | 672 jclass g_TestJni_clazz = NULL; |
678 } // namespace | 673 } // namespace |
679 | 674 |
680 static jint Init(JNIEnv* env, jobject obj); | 675 static jint Init(JNIEnv* env, jobject obj); |
681 | 676 |
682 static jint Init(JNIEnv* env, jobject obj); | 677 static jint Init(JNIEnv* env, jobject obj); |
683 | 678 |
684 // Step 2: method stubs. | 679 // Step 2: method stubs. |
685 | 680 |
686 // Step 3: GetMethodIDs and RegisterNatives. | 681 // Step 3: RegisterNatives. |
687 static void GetMethodIDsImpl(JNIEnv* env) { | 682 |
| 683 static bool RegisterNativesImpl(JNIEnv* env) { |
| 684 |
688 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | 685 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
689 base::android::GetUnscopedClass(env, kTestJniClassPath))); | 686 base::android::GetUnscopedClass(env, kTestJniClassPath))); |
690 } | |
691 | |
692 static bool RegisterNativesImpl(JNIEnv* env) { | |
693 GetMethodIDsImpl(env); | |
694 | |
695 static const JNINativeMethod kMethodsMyOtherInnerClass[] = { | 687 static const JNINativeMethod kMethodsMyOtherInnerClass[] = { |
696 { "nativeInit", | 688 { "nativeInit", |
697 "(" | 689 "(" |
698 ")" | 690 ")" |
699 "I", reinterpret_cast<void*>(Init) }, | 691 "I", reinterpret_cast<void*>(Init) }, |
700 }; | 692 }; |
701 const int kMethodsMyOtherInnerClassSize = | 693 const int kMethodsMyOtherInnerClassSize = |
702 arraysize(kMethodsMyOtherInnerClass); | 694 arraysize(kMethodsMyOtherInnerClass); |
703 | 695 |
704 if (env->RegisterNatives(g_MyOtherInnerClass_clazz, | 696 if (env->RegisterNatives(g_MyOtherInnerClass_clazz, |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 // base/android/jni_generator/jni_generator_tests.py | 877 // base/android/jni_generator/jni_generator_tests.py |
886 // For | 878 // For |
887 // org/chromium/TestJni | 879 // org/chromium/TestJni |
888 | 880 |
889 #ifndef org_chromium_TestJni_JNI | 881 #ifndef org_chromium_TestJni_JNI |
890 #define org_chromium_TestJni_JNI | 882 #define org_chromium_TestJni_JNI |
891 | 883 |
892 #include <jni.h> | 884 #include <jni.h> |
893 | 885 |
894 #include "base/android/jni_android.h" | 886 #include "base/android/jni_android.h" |
| 887 #include "base/android/jni_method_id.h" |
895 #include "base/android/scoped_java_ref.h" | 888 #include "base/android/scoped_java_ref.h" |
896 #include "base/basictypes.h" | 889 #include "base/basictypes.h" |
897 #include "base/logging.h" | 890 #include "base/logging.h" |
898 | 891 |
899 using base::android::ScopedJavaLocalRef; | 892 using base::android::ScopedJavaLocalRef; |
900 | 893 |
901 // Step 1: forward declarations. | 894 // Step 1: forward declarations. |
902 namespace { | 895 namespace { |
903 const char kTestJniClassPath[] = "org/chromium/TestJni"; | 896 const char kTestJniClassPath[] = "org/chromium/TestJni"; |
904 const char kInfoBarClassPath[] = "org/chromium/TestJni$InfoBar"; | 897 const char kInfoBarClassPath[] = "org/chromium/TestJni$InfoBar"; |
905 // Leaking this jclass as we cannot use LazyInstance from some threads. | 898 // Leaking this jclass as we cannot use LazyInstance from some threads. |
906 jclass g_TestJni_clazz = NULL; | 899 jclass g_TestJni_clazz = NULL; |
907 // Leaking this jclass as we cannot use LazyInstance from some threads. | 900 // Leaking this jclass as we cannot use LazyInstance from some threads. |
908 jclass g_InfoBar_clazz = NULL; | 901 jclass g_InfoBar_clazz = NULL; |
909 } // namespace | 902 } // namespace |
910 | 903 |
911 // Step 2: method stubs. | 904 // Step 2: method stubs. |
912 | 905 |
913 static jmethodID g_TestJni_showConfirmInfoBar = 0; | 906 static base::subtle::AtomicWord g_TestJni_showConfirmInfoBar = 0; |
914 static ScopedJavaLocalRef<jobject> Java_TestJni_showConfirmInfoBar(JNIEnv* env, | 907 static ScopedJavaLocalRef<jobject> Java_TestJni_showConfirmInfoBar(JNIEnv* env, |
915 jobject obj, jint nativeInfoBar, | 908 jobject obj, jint nativeInfoBar, |
916 jstring buttonOk, | 909 jstring buttonOk, |
917 jstring buttonCancel, | 910 jstring buttonCancel, |
918 jstring title, | 911 jstring title, |
919 jobject icon) { | 912 jobject icon) { |
920 /* Must call RegisterNativesImpl() */ | 913 /* Must call RegisterNativesImpl() */ |
921 DCHECK(g_TestJni_clazz); | 914 DCHECK(g_TestJni_clazz); |
922 DCHECK(g_TestJni_showConfirmInfoBar); | 915 jmethodID id = |
| 916 |
| 917 base::android::MethodID::LazyGet< |
| 918 base::android::MethodID::METHODTYPE_NORMAL, |
| 919 base::android::MethodID::EXCEPTIONCHECK_YES>( |
| 920 env, g_TestJni_clazz, |
| 921 "showConfirmInfoBar", |
| 922 |
| 923 "(" |
| 924 "I" |
| 925 "Ljava/lang/String;" |
| 926 "Ljava/lang/String;" |
| 927 "Ljava/lang/String;" |
| 928 "Landroid/graphics/Bitmap;" |
| 929 ")" |
| 930 "Lcom/google/android/apps/chrome/infobar/InfoBarContainer$NativeInfoBar;", |
| 931 &g_TestJni_showConfirmInfoBar); |
| 932 |
923 jobject ret = | 933 jobject ret = |
924 env->CallObjectMethod(obj, | 934 env->CallObjectMethod(obj, |
925 g_TestJni_showConfirmInfoBar, nativeInfoBar, buttonOk, buttonCancel, | 935 id, nativeInfoBar, buttonOk, buttonCancel, title, icon); |
926 title, icon); | |
927 base::android::CheckException(env); | 936 base::android::CheckException(env); |
928 return ScopedJavaLocalRef<jobject>(env, ret); | 937 return ScopedJavaLocalRef<jobject>(env, ret); |
929 } | 938 } |
930 | 939 |
931 static jmethodID g_TestJni_showAutoLoginInfoBar = 0; | 940 static base::subtle::AtomicWord g_TestJni_showAutoLoginInfoBar = 0; |
932 static ScopedJavaLocalRef<jobject> Java_TestJni_showAutoLoginInfoBar(JNIEnv* | 941 static ScopedJavaLocalRef<jobject> Java_TestJni_showAutoLoginInfoBar(JNIEnv* |
933 env, jobject obj, jint nativeInfoBar, | 942 env, jobject obj, jint nativeInfoBar, |
934 jstring realm, | 943 jstring realm, |
935 jstring account, | 944 jstring account, |
936 jstring args) { | 945 jstring args) { |
937 /* Must call RegisterNativesImpl() */ | 946 /* Must call RegisterNativesImpl() */ |
938 DCHECK(g_TestJni_clazz); | 947 DCHECK(g_TestJni_clazz); |
939 DCHECK(g_TestJni_showAutoLoginInfoBar); | 948 jmethodID id = |
| 949 |
| 950 base::android::MethodID::LazyGet< |
| 951 base::android::MethodID::METHODTYPE_NORMAL, |
| 952 base::android::MethodID::EXCEPTIONCHECK_YES>( |
| 953 env, g_TestJni_clazz, |
| 954 "showAutoLoginInfoBar", |
| 955 |
| 956 "(" |
| 957 "I" |
| 958 "Ljava/lang/String;" |
| 959 "Ljava/lang/String;" |
| 960 "Ljava/lang/String;" |
| 961 ")" |
| 962 "Lcom/google/android/apps/chrome/infobar/InfoBarContainer$NativeInfoBar;", |
| 963 &g_TestJni_showAutoLoginInfoBar); |
| 964 |
940 jobject ret = | 965 jobject ret = |
941 env->CallObjectMethod(obj, | 966 env->CallObjectMethod(obj, |
942 g_TestJni_showAutoLoginInfoBar, nativeInfoBar, realm, account, args); | 967 id, nativeInfoBar, realm, account, args); |
943 base::android::CheckException(env); | 968 base::android::CheckException(env); |
944 return ScopedJavaLocalRef<jobject>(env, ret); | 969 return ScopedJavaLocalRef<jobject>(env, ret); |
945 } | 970 } |
946 | 971 |
947 static jmethodID g_InfoBar_dismiss = 0; | 972 static base::subtle::AtomicWord g_InfoBar_dismiss = 0; |
948 static void Java_InfoBar_dismiss(JNIEnv* env, jobject obj) { | 973 static void Java_InfoBar_dismiss(JNIEnv* env, jobject obj) { |
949 /* Must call RegisterNativesImpl() */ | 974 /* Must call RegisterNativesImpl() */ |
950 DCHECK(g_InfoBar_clazz); | 975 DCHECK(g_InfoBar_clazz); |
951 DCHECK(g_InfoBar_dismiss); | 976 jmethodID id = |
| 977 |
| 978 base::android::MethodID::LazyGet< |
| 979 base::android::MethodID::METHODTYPE_NORMAL, |
| 980 base::android::MethodID::EXCEPTIONCHECK_YES>( |
| 981 env, g_InfoBar_clazz, |
| 982 "dismiss", |
| 983 |
| 984 "(" |
| 985 ")" |
| 986 "V", |
| 987 &g_InfoBar_dismiss); |
952 | 988 |
953 env->CallVoidMethod(obj, | 989 env->CallVoidMethod(obj, |
954 g_InfoBar_dismiss); | 990 id); |
955 base::android::CheckException(env); | 991 base::android::CheckException(env); |
956 | 992 |
957 } | 993 } |
958 | 994 |
959 static jmethodID g_TestJni_shouldShowAutoLogin = 0; | 995 static base::subtle::AtomicWord g_TestJni_shouldShowAutoLogin = 0; |
960 static jboolean Java_TestJni_shouldShowAutoLogin(JNIEnv* env, jobject | 996 static jboolean Java_TestJni_shouldShowAutoLogin(JNIEnv* env, jobject |
961 contentView, | 997 contentView, |
962 jstring realm, | 998 jstring realm, |
963 jstring account, | 999 jstring account, |
964 jstring args) { | 1000 jstring args) { |
965 /* Must call RegisterNativesImpl() */ | 1001 /* Must call RegisterNativesImpl() */ |
966 DCHECK(g_TestJni_clazz); | 1002 DCHECK(g_TestJni_clazz); |
967 DCHECK(g_TestJni_shouldShowAutoLogin); | 1003 jmethodID id = |
| 1004 |
| 1005 base::android::MethodID::LazyGet< |
| 1006 base::android::MethodID::METHODTYPE_STATIC, |
| 1007 base::android::MethodID::EXCEPTIONCHECK_YES>( |
| 1008 env, g_TestJni_clazz, |
| 1009 "shouldShowAutoLogin", |
| 1010 |
| 1011 "(" |
| 1012 "Lorg/chromium/content/browser/ContentViewCore;" |
| 1013 "Ljava/lang/String;" |
| 1014 "Ljava/lang/String;" |
| 1015 "Ljava/lang/String;" |
| 1016 ")" |
| 1017 "Z", |
| 1018 &g_TestJni_shouldShowAutoLogin); |
| 1019 |
968 jboolean ret = | 1020 jboolean ret = |
969 env->CallStaticBooleanMethod(g_TestJni_clazz, | 1021 env->CallStaticBooleanMethod(g_TestJni_clazz, |
970 g_TestJni_shouldShowAutoLogin, contentView, realm, account, args); | 1022 id, contentView, realm, account, args); |
971 base::android::CheckException(env); | 1023 base::android::CheckException(env); |
972 return ret; | 1024 return ret; |
973 } | 1025 } |
974 | 1026 |
975 static jmethodID g_TestJni_openUrl = 0; | 1027 static base::subtle::AtomicWord g_TestJni_openUrl = 0; |
976 static ScopedJavaLocalRef<jobject> Java_TestJni_openUrl(JNIEnv* env, jstring | 1028 static ScopedJavaLocalRef<jobject> Java_TestJni_openUrl(JNIEnv* env, jstring |
977 url) { | 1029 url) { |
978 /* Must call RegisterNativesImpl() */ | 1030 /* Must call RegisterNativesImpl() */ |
979 DCHECK(g_TestJni_clazz); | 1031 DCHECK(g_TestJni_clazz); |
980 DCHECK(g_TestJni_openUrl); | 1032 jmethodID id = |
| 1033 |
| 1034 base::android::MethodID::LazyGet< |
| 1035 base::android::MethodID::METHODTYPE_STATIC, |
| 1036 base::android::MethodID::EXCEPTIONCHECK_YES>( |
| 1037 env, g_TestJni_clazz, |
| 1038 "openUrl", |
| 1039 |
| 1040 "(" |
| 1041 "Ljava/lang/String;" |
| 1042 ")" |
| 1043 "Ljava/io/InputStream;", |
| 1044 &g_TestJni_openUrl); |
| 1045 |
981 jobject ret = | 1046 jobject ret = |
982 env->CallStaticObjectMethod(g_TestJni_clazz, | 1047 env->CallStaticObjectMethod(g_TestJni_clazz, |
983 g_TestJni_openUrl, url); | 1048 id, url); |
984 base::android::CheckException(env); | 1049 base::android::CheckException(env); |
985 return ScopedJavaLocalRef<jobject>(env, ret); | 1050 return ScopedJavaLocalRef<jobject>(env, ret); |
986 } | 1051 } |
987 | 1052 |
988 static jmethodID g_TestJni_activateHardwareAcceleration = 0; | 1053 static base::subtle::AtomicWord g_TestJni_activateHardwareAcceleration = 0; |
989 static void Java_TestJni_activateHardwareAcceleration(JNIEnv* env, jobject obj, | 1054 static void Java_TestJni_activateHardwareAcceleration(JNIEnv* env, jobject obj, |
990 jboolean activated, | 1055 jboolean activated, |
991 jint iPid, | 1056 jint iPid, |
992 jint iType, | 1057 jint iType, |
993 jint iPrimaryID, | 1058 jint iPrimaryID, |
994 jint iSecondaryID) { | 1059 jint iSecondaryID) { |
995 /* Must call RegisterNativesImpl() */ | 1060 /* Must call RegisterNativesImpl() */ |
996 DCHECK(g_TestJni_clazz); | 1061 DCHECK(g_TestJni_clazz); |
997 DCHECK(g_TestJni_activateHardwareAcceleration); | 1062 jmethodID id = |
998 | 1063 |
999 env->CallVoidMethod(obj, | 1064 base::android::MethodID::LazyGet< |
1000 g_TestJni_activateHardwareAcceleration, activated, iPid, iType, | 1065 base::android::MethodID::METHODTYPE_NORMAL, |
1001 iPrimaryID, iSecondaryID); | 1066 base::android::MethodID::EXCEPTIONCHECK_YES>( |
1002 base::android::CheckException(env); | 1067 env, g_TestJni_clazz, |
1003 | 1068 "activateHardwareAcceleration", |
1004 } | |
1005 | |
1006 static jmethodID g_TestJni_uncheckedCall = 0; | |
1007 static void Java_TestJni_uncheckedCall(JNIEnv* env, jobject obj, jint iParam) { | |
1008 /* Must call RegisterNativesImpl() */ | |
1009 DCHECK(g_TestJni_clazz); | |
1010 DCHECK(g_TestJni_uncheckedCall); | |
1011 | |
1012 env->CallVoidMethod(obj, | |
1013 g_TestJni_uncheckedCall, iParam); | |
1014 | |
1015 } | |
1016 | |
1017 // Step 3: GetMethodIDs and RegisterNatives. | |
1018 static void GetMethodIDsImpl(JNIEnv* env) { | |
1019 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
1020 base::android::GetUnscopedClass(env, kTestJniClassPath))); | |
1021 g_InfoBar_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
1022 base::android::GetUnscopedClass(env, kInfoBarClassPath))); | |
1023 g_TestJni_showConfirmInfoBar = | |
1024 base::android::GetMethodID( | |
1025 env, g_TestJni_clazz, | |
1026 "showConfirmInfoBar", | |
1027 | |
1028 "(" | |
1029 "I" | |
1030 "Ljava/lang/String;" | |
1031 "Ljava/lang/String;" | |
1032 "Ljava/lang/String;" | |
1033 "Landroid/graphics/Bitmap;" | |
1034 ")" | |
1035 "Lcom/google/android/apps/chrome/infobar/InfoBarContainer$NativeInfoBar;"); | |
1036 | |
1037 g_TestJni_showAutoLoginInfoBar = | |
1038 base::android::GetMethodID( | |
1039 env, g_TestJni_clazz, | |
1040 "showAutoLoginInfoBar", | |
1041 | |
1042 "(" | |
1043 "I" | |
1044 "Ljava/lang/String;" | |
1045 "Ljava/lang/String;" | |
1046 "Ljava/lang/String;" | |
1047 ")" | |
1048 "Lcom/google/android/apps/chrome/infobar/InfoBarContainer$NativeInfoBar;"); | |
1049 | |
1050 g_InfoBar_dismiss = | |
1051 base::android::GetMethodID( | |
1052 env, g_InfoBar_clazz, | |
1053 "dismiss", | |
1054 | |
1055 "(" | |
1056 ")" | |
1057 "V"); | |
1058 | |
1059 g_TestJni_shouldShowAutoLogin = | |
1060 base::android::GetStaticMethodID( | |
1061 env, g_TestJni_clazz, | |
1062 "shouldShowAutoLogin", | |
1063 | |
1064 "(" | |
1065 "Lorg/chromium/content/browser/ContentViewCore;" | |
1066 "Ljava/lang/String;" | |
1067 "Ljava/lang/String;" | |
1068 "Ljava/lang/String;" | |
1069 ")" | |
1070 "Z"); | |
1071 | |
1072 g_TestJni_openUrl = | |
1073 base::android::GetStaticMethodID( | |
1074 env, g_TestJni_clazz, | |
1075 "openUrl", | |
1076 | |
1077 "(" | |
1078 "Ljava/lang/String;" | |
1079 ")" | |
1080 "Ljava/io/InputStream;"); | |
1081 | |
1082 g_TestJni_activateHardwareAcceleration = | |
1083 base::android::GetMethodID( | |
1084 env, g_TestJni_clazz, | |
1085 "activateHardwareAcceleration", | |
1086 | 1069 |
1087 "(" | 1070 "(" |
1088 "Z" | 1071 "Z" |
1089 "I" | 1072 "I" |
1090 "I" | 1073 "I" |
1091 "I" | 1074 "I" |
1092 "I" | 1075 "I" |
1093 ")" | 1076 ")" |
1094 "V"); | 1077 "V", |
| 1078 &g_TestJni_activateHardwareAcceleration); |
1095 | 1079 |
1096 g_TestJni_uncheckedCall = | 1080 env->CallVoidMethod(obj, |
1097 base::android::GetMethodID( | 1081 id, activated, iPid, iType, iPrimaryID, iSecondaryID); |
1098 env, g_TestJni_clazz, | 1082 base::android::CheckException(env); |
1099 "uncheckedCall", | 1083 |
| 1084 } |
| 1085 |
| 1086 static base::subtle::AtomicWord g_TestJni_uncheckedCall = 0; |
| 1087 static void Java_TestJni_uncheckedCall(JNIEnv* env, jobject obj, jint iParam) { |
| 1088 /* Must call RegisterNativesImpl() */ |
| 1089 DCHECK(g_TestJni_clazz); |
| 1090 jmethodID id = |
| 1091 |
| 1092 base::android::MethodID::LazyGet< |
| 1093 base::android::MethodID::METHODTYPE_NORMAL, |
| 1094 base::android::MethodID::EXCEPTIONCHECK_YES>( |
| 1095 env, g_TestJni_clazz, |
| 1096 "uncheckedCall", |
1100 | 1097 |
1101 "(" | 1098 "(" |
1102 "I" | 1099 "I" |
1103 ")" | 1100 ")" |
1104 "V"); | 1101 "V", |
| 1102 &g_TestJni_uncheckedCall); |
| 1103 |
| 1104 env->CallVoidMethod(obj, |
| 1105 id, iParam); |
1105 | 1106 |
1106 } | 1107 } |
1107 | 1108 |
| 1109 // Step 3: RegisterNatives. |
| 1110 |
1108 static bool RegisterNativesImpl(JNIEnv* env) { | 1111 static bool RegisterNativesImpl(JNIEnv* env) { |
1109 GetMethodIDsImpl(env); | |
1110 | 1112 |
| 1113 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 1114 base::android::GetUnscopedClass(env, kTestJniClassPath))); |
| 1115 g_InfoBar_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 1116 base::android::GetUnscopedClass(env, kInfoBarClassPath))); |
1111 return true; | 1117 return true; |
1112 } | 1118 } |
1113 | 1119 |
1114 #endif // org_chromium_TestJni_JNI | 1120 #endif // org_chromium_TestJni_JNI |
1115 """ | 1121 """ |
1116 self.assertTextEquals(golden_content, h.GetContent()) | 1122 self.assertTextEquals(golden_content, h.GetContent()) |
1117 | 1123 |
1118 def testCalledByNativeParseError(self): | 1124 def testCalledByNativeParseError(self): |
1119 try: | 1125 try: |
1120 jni_generator.ExtractCalledByNatives(""" | 1126 jni_generator.ExtractCalledByNatives(""" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1193 // base/android/jni_generator/jni_generator_tests.py | 1199 // base/android/jni_generator/jni_generator_tests.py |
1194 // For | 1200 // For |
1195 // java/io/InputStream | 1201 // java/io/InputStream |
1196 | 1202 |
1197 #ifndef java_io_InputStream_JNI | 1203 #ifndef java_io_InputStream_JNI |
1198 #define java_io_InputStream_JNI | 1204 #define java_io_InputStream_JNI |
1199 | 1205 |
1200 #include <jni.h> | 1206 #include <jni.h> |
1201 | 1207 |
1202 #include "base/android/jni_android.h" | 1208 #include "base/android/jni_android.h" |
| 1209 #include "base/android/jni_method_id.h" |
1203 #include "base/android/scoped_java_ref.h" | 1210 #include "base/android/scoped_java_ref.h" |
1204 #include "base/basictypes.h" | 1211 #include "base/basictypes.h" |
1205 #include "base/logging.h" | 1212 #include "base/logging.h" |
1206 | 1213 |
1207 using base::android::ScopedJavaLocalRef; | 1214 using base::android::ScopedJavaLocalRef; |
1208 | 1215 |
1209 // Step 1: forward declarations. | 1216 // Step 1: forward declarations. |
1210 namespace { | 1217 namespace { |
1211 const char kInputStreamClassPath[] = "java/io/InputStream"; | 1218 const char kInputStreamClassPath[] = "java/io/InputStream"; |
1212 // Leaking this jclass as we cannot use LazyInstance from some threads. | 1219 // Leaking this jclass as we cannot use LazyInstance from some threads. |
1213 jclass g_InputStream_clazz = NULL; | 1220 jclass g_InputStream_clazz = NULL; |
1214 } // namespace | 1221 } // namespace |
1215 | 1222 |
1216 namespace JNI_InputStream { | 1223 namespace JNI_InputStream { |
1217 | 1224 |
1218 // Step 2: method stubs. | 1225 // Step 2: method stubs. |
1219 | 1226 |
1220 static jmethodID g_InputStream_available = 0; | 1227 static base::subtle::AtomicWord g_InputStream_available = 0; |
1221 static jint Java_InputStream_available(JNIEnv* env, jobject obj) __attribute__ | 1228 static jint Java_InputStream_available(JNIEnv* env, jobject obj) __attribute__ |
1222 ((unused)); | 1229 ((unused)); |
1223 static jint Java_InputStream_available(JNIEnv* env, jobject obj) { | 1230 static jint Java_InputStream_available(JNIEnv* env, jobject obj) { |
1224 /* Must call RegisterNativesImpl() */ | 1231 /* Must call RegisterNativesImpl() */ |
1225 DCHECK(g_InputStream_clazz); | 1232 DCHECK(g_InputStream_clazz); |
1226 DCHECK(g_InputStream_available); | 1233 jmethodID id = |
| 1234 |
| 1235 base::android::MethodID::LazyGet< |
| 1236 base::android::MethodID::METHODTYPE_NORMAL, |
| 1237 base::android::MethodID::EXCEPTIONCHECK_NO>( |
| 1238 env, g_InputStream_clazz, |
| 1239 "available", |
| 1240 |
| 1241 "(" |
| 1242 ")" |
| 1243 "I", |
| 1244 &g_InputStream_available); |
| 1245 |
1227 jint ret = | 1246 jint ret = |
1228 env->CallIntMethod(obj, | 1247 env->CallIntMethod(obj, |
1229 g_InputStream_available); | 1248 id); |
1230 base::android::CheckException(env); | 1249 base::android::CheckException(env); |
1231 return ret; | 1250 return ret; |
1232 } | 1251 } |
1233 | 1252 |
1234 static jmethodID g_InputStream_close = 0; | 1253 static base::subtle::AtomicWord g_InputStream_close = 0; |
1235 static void Java_InputStream_close(JNIEnv* env, jobject obj) __attribute__ | 1254 static void Java_InputStream_close(JNIEnv* env, jobject obj) __attribute__ |
1236 ((unused)); | 1255 ((unused)); |
1237 static void Java_InputStream_close(JNIEnv* env, jobject obj) { | 1256 static void Java_InputStream_close(JNIEnv* env, jobject obj) { |
1238 /* Must call RegisterNativesImpl() */ | 1257 /* Must call RegisterNativesImpl() */ |
1239 DCHECK(g_InputStream_clazz); | 1258 DCHECK(g_InputStream_clazz); |
1240 DCHECK(g_InputStream_close); | 1259 jmethodID id = |
| 1260 |
| 1261 base::android::MethodID::LazyGet< |
| 1262 base::android::MethodID::METHODTYPE_NORMAL, |
| 1263 base::android::MethodID::EXCEPTIONCHECK_NO>( |
| 1264 env, g_InputStream_clazz, |
| 1265 "close", |
| 1266 |
| 1267 "(" |
| 1268 ")" |
| 1269 "V", |
| 1270 &g_InputStream_close); |
1241 | 1271 |
1242 env->CallVoidMethod(obj, | 1272 env->CallVoidMethod(obj, |
1243 g_InputStream_close); | 1273 id); |
1244 base::android::CheckException(env); | 1274 base::android::CheckException(env); |
1245 | 1275 |
1246 } | 1276 } |
1247 | 1277 |
1248 static jmethodID g_InputStream_mark = 0; | 1278 static base::subtle::AtomicWord g_InputStream_mark = 0; |
1249 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) | 1279 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) |
1250 __attribute__ ((unused)); | 1280 __attribute__ ((unused)); |
1251 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) { | 1281 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) { |
1252 /* Must call RegisterNativesImpl() */ | 1282 /* Must call RegisterNativesImpl() */ |
1253 DCHECK(g_InputStream_clazz); | 1283 DCHECK(g_InputStream_clazz); |
1254 DCHECK(g_InputStream_mark); | 1284 jmethodID id = |
| 1285 |
| 1286 base::android::MethodID::LazyGet< |
| 1287 base::android::MethodID::METHODTYPE_NORMAL, |
| 1288 base::android::MethodID::EXCEPTIONCHECK_NO>( |
| 1289 env, g_InputStream_clazz, |
| 1290 "mark", |
| 1291 |
| 1292 "(" |
| 1293 "I" |
| 1294 ")" |
| 1295 "V", |
| 1296 &g_InputStream_mark); |
1255 | 1297 |
1256 env->CallVoidMethod(obj, | 1298 env->CallVoidMethod(obj, |
1257 g_InputStream_mark, p0); | 1299 id, p0); |
1258 base::android::CheckException(env); | 1300 base::android::CheckException(env); |
1259 | 1301 |
1260 } | 1302 } |
1261 | 1303 |
1262 static jmethodID g_InputStream_markSupported = 0; | 1304 static base::subtle::AtomicWord g_InputStream_markSupported = 0; |
1263 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) | 1305 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) |
1264 __attribute__ ((unused)); | 1306 __attribute__ ((unused)); |
1265 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) { | 1307 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) { |
1266 /* Must call RegisterNativesImpl() */ | 1308 /* Must call RegisterNativesImpl() */ |
1267 DCHECK(g_InputStream_clazz); | 1309 DCHECK(g_InputStream_clazz); |
1268 DCHECK(g_InputStream_markSupported); | 1310 jmethodID id = |
| 1311 |
| 1312 base::android::MethodID::LazyGet< |
| 1313 base::android::MethodID::METHODTYPE_NORMAL, |
| 1314 base::android::MethodID::EXCEPTIONCHECK_NO>( |
| 1315 env, g_InputStream_clazz, |
| 1316 "markSupported", |
| 1317 |
| 1318 "(" |
| 1319 ")" |
| 1320 "Z", |
| 1321 &g_InputStream_markSupported); |
| 1322 |
1269 jboolean ret = | 1323 jboolean ret = |
1270 env->CallBooleanMethod(obj, | 1324 env->CallBooleanMethod(obj, |
1271 g_InputStream_markSupported); | 1325 id); |
1272 base::android::CheckException(env); | 1326 base::android::CheckException(env); |
1273 return ret; | 1327 return ret; |
1274 } | 1328 } |
1275 | 1329 |
1276 static jmethodID g_InputStream_readI = 0; | 1330 static base::subtle::AtomicWord g_InputStream_readI = 0; |
1277 static jint Java_InputStream_readI(JNIEnv* env, jobject obj) __attribute__ | 1331 static jint Java_InputStream_readI(JNIEnv* env, jobject obj) __attribute__ |
1278 ((unused)); | 1332 ((unused)); |
1279 static jint Java_InputStream_readI(JNIEnv* env, jobject obj) { | 1333 static jint Java_InputStream_readI(JNIEnv* env, jobject obj) { |
1280 /* Must call RegisterNativesImpl() */ | 1334 /* Must call RegisterNativesImpl() */ |
1281 DCHECK(g_InputStream_clazz); | 1335 DCHECK(g_InputStream_clazz); |
1282 DCHECK(g_InputStream_readI); | 1336 jmethodID id = |
| 1337 |
| 1338 base::android::MethodID::LazyGet< |
| 1339 base::android::MethodID::METHODTYPE_NORMAL, |
| 1340 base::android::MethodID::EXCEPTIONCHECK_NO>( |
| 1341 env, g_InputStream_clazz, |
| 1342 "read", |
| 1343 |
| 1344 "(" |
| 1345 ")" |
| 1346 "I", |
| 1347 &g_InputStream_readI); |
| 1348 |
1283 jint ret = | 1349 jint ret = |
1284 env->CallIntMethod(obj, | 1350 env->CallIntMethod(obj, |
1285 g_InputStream_readI); | 1351 id); |
1286 base::android::CheckException(env); | 1352 base::android::CheckException(env); |
1287 return ret; | 1353 return ret; |
1288 } | 1354 } |
1289 | 1355 |
1290 static jmethodID g_InputStream_readI_AB = 0; | 1356 static base::subtle::AtomicWord g_InputStream_readI_AB = 0; |
1291 static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) | 1357 static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) |
1292 __attribute__ ((unused)); | 1358 __attribute__ ((unused)); |
1293 static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) { | 1359 static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) { |
1294 /* Must call RegisterNativesImpl() */ | 1360 /* Must call RegisterNativesImpl() */ |
1295 DCHECK(g_InputStream_clazz); | 1361 DCHECK(g_InputStream_clazz); |
1296 DCHECK(g_InputStream_readI_AB); | 1362 jmethodID id = |
| 1363 |
| 1364 base::android::MethodID::LazyGet< |
| 1365 base::android::MethodID::METHODTYPE_NORMAL, |
| 1366 base::android::MethodID::EXCEPTIONCHECK_NO>( |
| 1367 env, g_InputStream_clazz, |
| 1368 "read", |
| 1369 |
| 1370 "(" |
| 1371 "[B" |
| 1372 ")" |
| 1373 "I", |
| 1374 &g_InputStream_readI_AB); |
| 1375 |
1297 jint ret = | 1376 jint ret = |
1298 env->CallIntMethod(obj, | 1377 env->CallIntMethod(obj, |
1299 g_InputStream_readI_AB, p0); | 1378 id, p0); |
1300 base::android::CheckException(env); | 1379 base::android::CheckException(env); |
1301 return ret; | 1380 return ret; |
1302 } | 1381 } |
1303 | 1382 |
1304 static jmethodID g_InputStream_readI_AB_I_I = 0; | 1383 static base::subtle::AtomicWord g_InputStream_readI_AB_I_I = 0; |
1305 static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray | 1384 static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray |
1306 p0, | 1385 p0, |
1307 jint p1, | 1386 jint p1, |
1308 jint p2) __attribute__ ((unused)); | 1387 jint p2) __attribute__ ((unused)); |
1309 static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray | 1388 static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray |
1310 p0, | 1389 p0, |
1311 jint p1, | 1390 jint p1, |
1312 jint p2) { | 1391 jint p2) { |
1313 /* Must call RegisterNativesImpl() */ | 1392 /* Must call RegisterNativesImpl() */ |
1314 DCHECK(g_InputStream_clazz); | 1393 DCHECK(g_InputStream_clazz); |
1315 DCHECK(g_InputStream_readI_AB_I_I); | 1394 jmethodID id = |
1316 jint ret = | |
1317 env->CallIntMethod(obj, | |
1318 g_InputStream_readI_AB_I_I, p0, p1, p2); | |
1319 base::android::CheckException(env); | |
1320 return ret; | |
1321 } | |
1322 | 1395 |
1323 static jmethodID g_InputStream_reset = 0; | 1396 base::android::MethodID::LazyGet< |
1324 static void Java_InputStream_reset(JNIEnv* env, jobject obj) __attribute__ | 1397 base::android::MethodID::METHODTYPE_NORMAL, |
1325 ((unused)); | 1398 base::android::MethodID::EXCEPTIONCHECK_NO>( |
1326 static void Java_InputStream_reset(JNIEnv* env, jobject obj) { | 1399 env, g_InputStream_clazz, |
1327 /* Must call RegisterNativesImpl() */ | 1400 "read", |
1328 DCHECK(g_InputStream_clazz); | |
1329 DCHECK(g_InputStream_reset); | |
1330 | |
1331 env->CallVoidMethod(obj, | |
1332 g_InputStream_reset); | |
1333 base::android::CheckException(env); | |
1334 | |
1335 } | |
1336 | |
1337 static jmethodID g_InputStream_skip = 0; | |
1338 static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) | |
1339 __attribute__ ((unused)); | |
1340 static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) { | |
1341 /* Must call RegisterNativesImpl() */ | |
1342 DCHECK(g_InputStream_clazz); | |
1343 DCHECK(g_InputStream_skip); | |
1344 jlong ret = | |
1345 env->CallLongMethod(obj, | |
1346 g_InputStream_skip, p0); | |
1347 base::android::CheckException(env); | |
1348 return ret; | |
1349 } | |
1350 | |
1351 static jmethodID g_InputStream_Constructor = 0; | |
1352 static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env) | |
1353 __attribute__ ((unused)); | |
1354 static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env) { | |
1355 /* Must call RegisterNativesImpl() */ | |
1356 DCHECK(g_InputStream_clazz); | |
1357 DCHECK(g_InputStream_Constructor); | |
1358 jobject ret = | |
1359 env->NewObject(g_InputStream_clazz, | |
1360 g_InputStream_Constructor); | |
1361 base::android::CheckException(env); | |
1362 return ScopedJavaLocalRef<jobject>(env, ret); | |
1363 } | |
1364 | |
1365 // Step 3: GetMethodIDs and RegisterNatives. | |
1366 static void GetMethodIDsImpl(JNIEnv* env) { | |
1367 g_InputStream_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
1368 base::android::GetUnscopedClass(env, kInputStreamClassPath))); | |
1369 g_InputStream_available = | |
1370 base::android::GetMethodIDOrNull( | |
1371 env, g_InputStream_clazz, | |
1372 "available", | |
1373 | |
1374 "(" | |
1375 ")" | |
1376 "I"); | |
1377 | |
1378 g_InputStream_close = | |
1379 base::android::GetMethodIDOrNull( | |
1380 env, g_InputStream_clazz, | |
1381 "close", | |
1382 | |
1383 "(" | |
1384 ")" | |
1385 "V"); | |
1386 | |
1387 g_InputStream_mark = | |
1388 base::android::GetMethodIDOrNull( | |
1389 env, g_InputStream_clazz, | |
1390 "mark", | |
1391 | |
1392 "(" | |
1393 "I" | |
1394 ")" | |
1395 "V"); | |
1396 | |
1397 g_InputStream_markSupported = | |
1398 base::android::GetMethodIDOrNull( | |
1399 env, g_InputStream_clazz, | |
1400 "markSupported", | |
1401 | |
1402 "(" | |
1403 ")" | |
1404 "Z"); | |
1405 | |
1406 g_InputStream_readI = | |
1407 base::android::GetMethodIDOrNull( | |
1408 env, g_InputStream_clazz, | |
1409 "read", | |
1410 | |
1411 "(" | |
1412 ")" | |
1413 "I"); | |
1414 | |
1415 g_InputStream_readI_AB = | |
1416 base::android::GetMethodIDOrNull( | |
1417 env, g_InputStream_clazz, | |
1418 "read", | |
1419 | |
1420 "(" | |
1421 "[B" | |
1422 ")" | |
1423 "I"); | |
1424 | |
1425 g_InputStream_readI_AB_I_I = | |
1426 base::android::GetMethodIDOrNull( | |
1427 env, g_InputStream_clazz, | |
1428 "read", | |
1429 | 1401 |
1430 "(" | 1402 "(" |
1431 "[B" | 1403 "[B" |
1432 "I" | 1404 "I" |
1433 "I" | 1405 "I" |
1434 ")" | 1406 ")" |
1435 "I"); | 1407 "I", |
| 1408 &g_InputStream_readI_AB_I_I); |
1436 | 1409 |
1437 g_InputStream_reset = | 1410 jint ret = |
1438 base::android::GetMethodIDOrNull( | 1411 env->CallIntMethod(obj, |
1439 env, g_InputStream_clazz, | 1412 id, p0, p1, p2); |
1440 "reset", | 1413 base::android::CheckException(env); |
| 1414 return ret; |
| 1415 } |
| 1416 |
| 1417 static base::subtle::AtomicWord g_InputStream_reset = 0; |
| 1418 static void Java_InputStream_reset(JNIEnv* env, jobject obj) __attribute__ |
| 1419 ((unused)); |
| 1420 static void Java_InputStream_reset(JNIEnv* env, jobject obj) { |
| 1421 /* Must call RegisterNativesImpl() */ |
| 1422 DCHECK(g_InputStream_clazz); |
| 1423 jmethodID id = |
| 1424 |
| 1425 base::android::MethodID::LazyGet< |
| 1426 base::android::MethodID::METHODTYPE_NORMAL, |
| 1427 base::android::MethodID::EXCEPTIONCHECK_NO>( |
| 1428 env, g_InputStream_clazz, |
| 1429 "reset", |
1441 | 1430 |
1442 "(" | 1431 "(" |
1443 ")" | 1432 ")" |
1444 "V"); | 1433 "V", |
| 1434 &g_InputStream_reset); |
1445 | 1435 |
1446 g_InputStream_skip = | 1436 env->CallVoidMethod(obj, |
1447 base::android::GetMethodIDOrNull( | 1437 id); |
1448 env, g_InputStream_clazz, | 1438 base::android::CheckException(env); |
1449 "skip", | 1439 |
| 1440 } |
| 1441 |
| 1442 static base::subtle::AtomicWord g_InputStream_skip = 0; |
| 1443 static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) |
| 1444 __attribute__ ((unused)); |
| 1445 static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) { |
| 1446 /* Must call RegisterNativesImpl() */ |
| 1447 DCHECK(g_InputStream_clazz); |
| 1448 jmethodID id = |
| 1449 |
| 1450 base::android::MethodID::LazyGet< |
| 1451 base::android::MethodID::METHODTYPE_NORMAL, |
| 1452 base::android::MethodID::EXCEPTIONCHECK_NO>( |
| 1453 env, g_InputStream_clazz, |
| 1454 "skip", |
1450 | 1455 |
1451 "(" | 1456 "(" |
1452 "J" | 1457 "J" |
1453 ")" | 1458 ")" |
1454 "J"); | 1459 "J", |
| 1460 &g_InputStream_skip); |
1455 | 1461 |
1456 g_InputStream_Constructor = | 1462 jlong ret = |
1457 base::android::GetMethodIDOrNull( | 1463 env->CallLongMethod(obj, |
1458 env, g_InputStream_clazz, | 1464 id, p0); |
1459 "<init>", | 1465 base::android::CheckException(env); |
| 1466 return ret; |
| 1467 } |
| 1468 |
| 1469 static base::subtle::AtomicWord g_InputStream_Constructor = 0; |
| 1470 static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env) |
| 1471 __attribute__ ((unused)); |
| 1472 static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env) { |
| 1473 /* Must call RegisterNativesImpl() */ |
| 1474 DCHECK(g_InputStream_clazz); |
| 1475 jmethodID id = |
| 1476 |
| 1477 base::android::MethodID::LazyGet< |
| 1478 base::android::MethodID::METHODTYPE_NORMAL, |
| 1479 base::android::MethodID::EXCEPTIONCHECK_NO>( |
| 1480 env, g_InputStream_clazz, |
| 1481 "<init>", |
1460 | 1482 |
1461 "(" | 1483 "(" |
1462 ")" | 1484 ")" |
1463 "V"); | 1485 "V", |
| 1486 &g_InputStream_Constructor); |
1464 | 1487 |
| 1488 jobject ret = |
| 1489 env->NewObject(g_InputStream_clazz, |
| 1490 id); |
| 1491 base::android::CheckException(env); |
| 1492 return ScopedJavaLocalRef<jobject>(env, ret); |
1465 } | 1493 } |
1466 | 1494 |
| 1495 // Step 3: RegisterNatives. |
| 1496 |
1467 static bool RegisterNativesImpl(JNIEnv* env) { | 1497 static bool RegisterNativesImpl(JNIEnv* env) { |
1468 GetMethodIDsImpl(env); | |
1469 | 1498 |
| 1499 g_InputStream_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 1500 base::android::GetUnscopedClass(env, kInputStreamClassPath))); |
1470 return true; | 1501 return true; |
1471 } | 1502 } |
1472 } // namespace JNI_InputStream | 1503 } // namespace JNI_InputStream |
1473 | 1504 |
1474 #endif // java_io_InputStream_JNI | 1505 #endif // java_io_InputStream_JNI |
1475 """ | 1506 """ |
1476 self.assertTextEquals(golden_content, jni_from_javap.GetContent()) | 1507 self.assertTextEquals(golden_content, jni_from_javap.GetContent()) |
1477 | 1508 |
1478 def testREForNatives(self): | 1509 def testREForNatives(self): |
1479 # We should not match "native SyncSetupFlow" inside the comment. | 1510 # We should not match "native SyncSetupFlow" inside the comment. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1536 test_data, ('com/google/lookhowextremelylongiam/snarf/' | 1567 test_data, ('com/google/lookhowextremelylongiam/snarf/' |
1537 'icankeepthisupallday/ReallyLongClassNamesAreAllTheRage')) | 1568 'icankeepthisupallday/ReallyLongClassNamesAreAllTheRage')) |
1538 jni_lines = jni_from_java.GetContent().split('\n') | 1569 jni_lines = jni_from_java.GetContent().split('\n') |
1539 line = filter(lambda line: line.lstrip().startswith('#ifndef'), | 1570 line = filter(lambda line: line.lstrip().startswith('#ifndef'), |
1540 jni_lines)[0] | 1571 jni_lines)[0] |
1541 self.assertTrue(len(line) > 80, | 1572 self.assertTrue(len(line) > 80, |
1542 ('Expected #ifndef line to be > 80 chars: ', line)) | 1573 ('Expected #ifndef line to be > 80 chars: ', line)) |
1543 | 1574 |
1544 if __name__ == '__main__': | 1575 if __name__ == '__main__': |
1545 unittest.main() | 1576 unittest.main() |
OLD | NEW |