Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(652)

Side by Side Diff: base/android/jni_generator/jni_generator_tests.py

Issue 11038015: Android: lazy initialization for method id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tidy up + tests Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 selectionArgs, sortOrder).Release(); 308 selectionArgs, sortOrder).Release();
309 } 309 }
310 310
311 static void GotOrientation(JNIEnv* env, jobject obj, 311 static void GotOrientation(JNIEnv* env, jobject obj,
312 jint nativeDataFetcherImplAndroid, 312 jint nativeDataFetcherImplAndroid,
313 jdouble alpha, 313 jdouble alpha,
314 jdouble beta, 314 jdouble beta,
315 jdouble gamma) { 315 jdouble gamma) {
316 DCHECK(nativeDataFetcherImplAndroid) << "GotOrientation"; 316 DCHECK(nativeDataFetcherImplAndroid) << "GotOrientation";
317 DataFetcherImplAndroid* native = 317 DataFetcherImplAndroid* native =
318 reinterpret_cast<DataFetcherImplAndroid*>(nativeDataFetcherImplAndroid); 318 reinterpret_cast<DataFetcherImplAndroid*>(nativeDataFetcherImplAndroid);
319 return native->GotOrientation(env, obj, alpha, beta, gamma); 319 return native->GotOrientation(env, obj, alpha, beta, gamma);
320 } 320 }
321 321
322 // Step 3: GetMethodIDs and RegisterNatives. 322 // Step 3: RegisterNatives.
323 static void GetMethodIDsImpl(JNIEnv* env) { 323
324 static bool RegisterNativesImpl(JNIEnv* env) {
325
324 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( 326 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
325 base::android::GetUnscopedClass(env, kTestJniClassPath))); 327 base::android::GetUnscopedClass(env, kTestJniClassPath)));
326 }
327
328 static bool RegisterNativesImpl(JNIEnv* env) {
329 GetMethodIDsImpl(env);
330
331 static const JNINativeMethod kMethodsTestJni[] = { 328 static const JNINativeMethod kMethodsTestJni[] = {
332 { "nativeInit", 329 { "nativeInit",
333 "(" 330 "("
334 ")" 331 ")"
335 "I", reinterpret_cast<void*>(Init) }, 332 "I", reinterpret_cast<void*>(Init) },
336 { "nativeDestroy", 333 { "nativeDestroy",
337 "(" 334 "("
338 "I" 335 "I"
339 ")" 336 ")"
340 "V", reinterpret_cast<void*>(Destroy) }, 337 "V", reinterpret_cast<void*>(Destroy) },
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 const char kTestJniClassPath[] = "org/chromium/TestJni"; 471 const char kTestJniClassPath[] = "org/chromium/TestJni";
475 const char kMyInnerClassClassPath[] = "org/chromium/TestJni$MyInnerClass"; 472 const char kMyInnerClassClassPath[] = "org/chromium/TestJni$MyInnerClass";
476 // Leaking this jclass as we cannot use LazyInstance from some threads. 473 // Leaking this jclass as we cannot use LazyInstance from some threads.
477 jclass g_TestJni_clazz = NULL; 474 jclass g_TestJni_clazz = NULL;
478 } // namespace 475 } // namespace
479 476
480 static jint Init(JNIEnv* env, jobject obj); 477 static jint Init(JNIEnv* env, jobject obj);
481 478
482 // Step 2: method stubs. 479 // Step 2: method stubs.
483 480
484 // Step 3: GetMethodIDs and RegisterNatives. 481 // Step 3: RegisterNatives.
485 static void GetMethodIDsImpl(JNIEnv* env) { 482
483 static bool RegisterNativesImpl(JNIEnv* env) {
484
486 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( 485 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
487 base::android::GetUnscopedClass(env, kTestJniClassPath))); 486 base::android::GetUnscopedClass(env, kTestJniClassPath)));
488 }
489
490 static bool RegisterNativesImpl(JNIEnv* env) {
491 GetMethodIDsImpl(env);
492
493 static const JNINativeMethod kMethodsMyInnerClass[] = { 487 static const JNINativeMethod kMethodsMyInnerClass[] = {
494 { "nativeInit", 488 { "nativeInit",
495 "(" 489 "("
496 ")" 490 ")"
497 "I", reinterpret_cast<void*>(Init) }, 491 "I", reinterpret_cast<void*>(Init) },
498 }; 492 };
499 const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass); 493 const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass);
500 494
501 if (env->RegisterNatives(g_MyInnerClass_clazz, 495 if (env->RegisterNatives(g_MyInnerClass_clazz,
502 kMethodsMyInnerClass, 496 kMethodsMyInnerClass,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 // Leaking this jclass as we cannot use LazyInstance from some threads. 562 // Leaking this jclass as we cannot use LazyInstance from some threads.
569 jclass g_TestJni_clazz = NULL; 563 jclass g_TestJni_clazz = NULL;
570 } // namespace 564 } // namespace
571 565
572 static jint Init(JNIEnv* env, jobject obj); 566 static jint Init(JNIEnv* env, jobject obj);
573 567
574 static jint Init(JNIEnv* env, jobject obj); 568 static jint Init(JNIEnv* env, jobject obj);
575 569
576 // Step 2: method stubs. 570 // Step 2: method stubs.
577 571
578 // Step 3: GetMethodIDs and RegisterNatives. 572 // Step 3: RegisterNatives.
579 static void GetMethodIDsImpl(JNIEnv* env) { 573
574 static bool RegisterNativesImpl(JNIEnv* env) {
575
580 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( 576 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
581 base::android::GetUnscopedClass(env, kTestJniClassPath))); 577 base::android::GetUnscopedClass(env, kTestJniClassPath)));
582 }
583
584 static bool RegisterNativesImpl(JNIEnv* env) {
585 GetMethodIDsImpl(env);
586
587 static const JNINativeMethod kMethodsMyOtherInnerClass[] = { 578 static const JNINativeMethod kMethodsMyOtherInnerClass[] = {
588 { "nativeInit", 579 { "nativeInit",
589 "(" 580 "("
590 ")" 581 ")"
591 "I", reinterpret_cast<void*>(Init) }, 582 "I", reinterpret_cast<void*>(Init) },
592 }; 583 };
593 const int kMethodsMyOtherInnerClassSize = 584 const int kMethodsMyOtherInnerClassSize =
594 arraysize(kMethodsMyOtherInnerClass); 585 arraysize(kMethodsMyOtherInnerClass);
595 586
596 if (env->RegisterNatives(g_MyOtherInnerClass_clazz, 587 if (env->RegisterNatives(g_MyOtherInnerClass_clazz,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 // Leaking this jclass as we cannot use LazyInstance from some threads. 667 // Leaking this jclass as we cannot use LazyInstance from some threads.
677 jclass g_TestJni_clazz = NULL; 668 jclass g_TestJni_clazz = NULL;
678 } // namespace 669 } // namespace
679 670
680 static jint Init(JNIEnv* env, jobject obj); 671 static jint Init(JNIEnv* env, jobject obj);
681 672
682 static jint Init(JNIEnv* env, jobject obj); 673 static jint Init(JNIEnv* env, jobject obj);
683 674
684 // Step 2: method stubs. 675 // Step 2: method stubs.
685 676
686 // Step 3: GetMethodIDs and RegisterNatives. 677 // Step 3: RegisterNatives.
687 static void GetMethodIDsImpl(JNIEnv* env) { 678
679 static bool RegisterNativesImpl(JNIEnv* env) {
680
688 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( 681 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
689 base::android::GetUnscopedClass(env, kTestJniClassPath))); 682 base::android::GetUnscopedClass(env, kTestJniClassPath)));
690 }
691
692 static bool RegisterNativesImpl(JNIEnv* env) {
693 GetMethodIDsImpl(env);
694
695 static const JNINativeMethod kMethodsMyOtherInnerClass[] = { 683 static const JNINativeMethod kMethodsMyOtherInnerClass[] = {
696 { "nativeInit", 684 { "nativeInit",
697 "(" 685 "("
698 ")" 686 ")"
699 "I", reinterpret_cast<void*>(Init) }, 687 "I", reinterpret_cast<void*>(Init) },
700 }; 688 };
701 const int kMethodsMyOtherInnerClassSize = 689 const int kMethodsMyOtherInnerClassSize =
702 arraysize(kMethodsMyOtherInnerClass); 690 arraysize(kMethodsMyOtherInnerClass);
703 691
704 if (env->RegisterNatives(g_MyOtherInnerClass_clazz, 692 if (env->RegisterNatives(g_MyOtherInnerClass_clazz,
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 900
913 static jmethodID g_TestJni_showConfirmInfoBar = 0; 901 static jmethodID g_TestJni_showConfirmInfoBar = 0;
914 static ScopedJavaLocalRef<jobject> Java_TestJni_showConfirmInfoBar(JNIEnv* env, 902 static ScopedJavaLocalRef<jobject> Java_TestJni_showConfirmInfoBar(JNIEnv* env,
915 jobject obj, jint nativeInfoBar, 903 jobject obj, jint nativeInfoBar,
916 jstring buttonOk, 904 jstring buttonOk,
917 jstring buttonCancel, 905 jstring buttonCancel,
918 jstring title, 906 jstring title,
919 jobject icon) { 907 jobject icon) {
920 /* Must call RegisterNativesImpl() */ 908 /* Must call RegisterNativesImpl() */
921 DCHECK(g_TestJni_clazz); 909 DCHECK(g_TestJni_clazz);
922 DCHECK(g_TestJni_showConfirmInfoBar); 910
911 base::android::LazyMethodID::Get<
912 base::android::LazyMethodID::METHODTYPE_NORMAL,
913 base::android::LazyMethodID::EXCEPTIONCHECK_YES>(
914 env, g_TestJni_clazz,
915 "showConfirmInfoBar",
916
917 "("
918 "I"
919 "Ljava/lang/String;"
920 "Ljava/lang/String;"
921 "Ljava/lang/String;"
922 "Landroid/graphics/Bitmap;"
923 ")"
924 "Lcom/google/android/apps/chrome/infobar/InfoBarContainer$NativeInfoBar;",
925 &g_TestJni_showConfirmInfoBar);
926
923 jobject ret = 927 jobject ret =
924 env->CallObjectMethod(obj, 928 env->CallObjectMethod(obj,
925 g_TestJni_showConfirmInfoBar, nativeInfoBar, buttonOk, buttonCancel, 929 g_TestJni_showConfirmInfoBar, nativeInfoBar, buttonOk, buttonCancel,
926 title, icon); 930 title, icon);
927 base::android::CheckException(env); 931 base::android::CheckException(env);
928 return ScopedJavaLocalRef<jobject>(env, ret); 932 return ScopedJavaLocalRef<jobject>(env, ret);
929 } 933 }
930 934
931 static jmethodID g_TestJni_showAutoLoginInfoBar = 0; 935 static jmethodID g_TestJni_showAutoLoginInfoBar = 0;
932 static ScopedJavaLocalRef<jobject> Java_TestJni_showAutoLoginInfoBar(JNIEnv* 936 static ScopedJavaLocalRef<jobject> Java_TestJni_showAutoLoginInfoBar(JNIEnv*
933 env, jobject obj, jint nativeInfoBar, 937 env, jobject obj, jint nativeInfoBar,
934 jstring realm, 938 jstring realm,
935 jstring account, 939 jstring account,
936 jstring args) { 940 jstring args) {
937 /* Must call RegisterNativesImpl() */ 941 /* Must call RegisterNativesImpl() */
938 DCHECK(g_TestJni_clazz); 942 DCHECK(g_TestJni_clazz);
939 DCHECK(g_TestJni_showAutoLoginInfoBar); 943
944 base::android::LazyMethodID::Get<
945 base::android::LazyMethodID::METHODTYPE_NORMAL,
946 base::android::LazyMethodID::EXCEPTIONCHECK_YES>(
947 env, g_TestJni_clazz,
948 "showAutoLoginInfoBar",
949
950 "("
951 "I"
952 "Ljava/lang/String;"
953 "Ljava/lang/String;"
954 "Ljava/lang/String;"
955 ")"
956 "Lcom/google/android/apps/chrome/infobar/InfoBarContainer$NativeInfoBar;",
957 &g_TestJni_showAutoLoginInfoBar);
958
940 jobject ret = 959 jobject ret =
941 env->CallObjectMethod(obj, 960 env->CallObjectMethod(obj,
942 g_TestJni_showAutoLoginInfoBar, nativeInfoBar, realm, account, args); 961 g_TestJni_showAutoLoginInfoBar, nativeInfoBar, realm, account, args);
943 base::android::CheckException(env); 962 base::android::CheckException(env);
944 return ScopedJavaLocalRef<jobject>(env, ret); 963 return ScopedJavaLocalRef<jobject>(env, ret);
945 } 964 }
946 965
947 static jmethodID g_InfoBar_dismiss = 0; 966 static jmethodID g_InfoBar_dismiss = 0;
948 static void Java_InfoBar_dismiss(JNIEnv* env, jobject obj) { 967 static void Java_InfoBar_dismiss(JNIEnv* env, jobject obj) {
949 /* Must call RegisterNativesImpl() */ 968 /* Must call RegisterNativesImpl() */
950 DCHECK(g_InfoBar_clazz); 969 DCHECK(g_InfoBar_clazz);
951 DCHECK(g_InfoBar_dismiss); 970
971 base::android::LazyMethodID::Get<
972 base::android::LazyMethodID::METHODTYPE_NORMAL,
973 base::android::LazyMethodID::EXCEPTIONCHECK_YES>(
974 env, g_InfoBar_clazz,
975 "dismiss",
976
977 "("
978 ")"
979 "V",
980 &g_InfoBar_dismiss);
952 981
953 env->CallVoidMethod(obj, 982 env->CallVoidMethod(obj,
954 g_InfoBar_dismiss); 983 g_InfoBar_dismiss);
955 base::android::CheckException(env); 984 base::android::CheckException(env);
956 985
957 } 986 }
958 987
959 static jmethodID g_TestJni_shouldShowAutoLogin = 0; 988 static jmethodID g_TestJni_shouldShowAutoLogin = 0;
960 static jboolean Java_TestJni_shouldShowAutoLogin(JNIEnv* env, jobject 989 static jboolean Java_TestJni_shouldShowAutoLogin(JNIEnv* env, jobject
961 contentView, 990 contentView,
962 jstring realm, 991 jstring realm,
963 jstring account, 992 jstring account,
964 jstring args) { 993 jstring args) {
965 /* Must call RegisterNativesImpl() */ 994 /* Must call RegisterNativesImpl() */
966 DCHECK(g_TestJni_clazz); 995 DCHECK(g_TestJni_clazz);
967 DCHECK(g_TestJni_shouldShowAutoLogin); 996
997 base::android::LazyMethodID::Get<
998 base::android::LazyMethodID::METHODTYPE_STATIC,
999 base::android::LazyMethodID::EXCEPTIONCHECK_YES>(
1000 env, g_TestJni_clazz,
1001 "shouldShowAutoLogin",
1002
1003 "("
1004 "Lorg/chromium/content/browser/ContentViewCore;"
1005 "Ljava/lang/String;"
1006 "Ljava/lang/String;"
1007 "Ljava/lang/String;"
1008 ")"
1009 "Z",
1010 &g_TestJni_shouldShowAutoLogin);
1011
968 jboolean ret = 1012 jboolean ret =
969 env->CallStaticBooleanMethod(g_TestJni_clazz, 1013 env->CallStaticBooleanMethod(g_TestJni_clazz,
970 g_TestJni_shouldShowAutoLogin, contentView, realm, account, args); 1014 g_TestJni_shouldShowAutoLogin, contentView, realm, account, args);
971 base::android::CheckException(env); 1015 base::android::CheckException(env);
972 return ret; 1016 return ret;
973 } 1017 }
974 1018
975 static jmethodID g_TestJni_openUrl = 0; 1019 static jmethodID g_TestJni_openUrl = 0;
976 static ScopedJavaLocalRef<jobject> Java_TestJni_openUrl(JNIEnv* env, jstring 1020 static ScopedJavaLocalRef<jobject> Java_TestJni_openUrl(JNIEnv* env, jstring
977 url) { 1021 url) {
978 /* Must call RegisterNativesImpl() */ 1022 /* Must call RegisterNativesImpl() */
979 DCHECK(g_TestJni_clazz); 1023 DCHECK(g_TestJni_clazz);
980 DCHECK(g_TestJni_openUrl); 1024
1025 base::android::LazyMethodID::Get<
1026 base::android::LazyMethodID::METHODTYPE_STATIC,
1027 base::android::LazyMethodID::EXCEPTIONCHECK_YES>(
1028 env, g_TestJni_clazz,
1029 "openUrl",
1030
1031 "("
1032 "Ljava/lang/String;"
1033 ")"
1034 "Ljava/io/InputStream;",
1035 &g_TestJni_openUrl);
1036
981 jobject ret = 1037 jobject ret =
982 env->CallStaticObjectMethod(g_TestJni_clazz, 1038 env->CallStaticObjectMethod(g_TestJni_clazz,
983 g_TestJni_openUrl, url); 1039 g_TestJni_openUrl, url);
984 base::android::CheckException(env); 1040 base::android::CheckException(env);
985 return ScopedJavaLocalRef<jobject>(env, ret); 1041 return ScopedJavaLocalRef<jobject>(env, ret);
986 } 1042 }
987 1043
988 static jmethodID g_TestJni_activateHardwareAcceleration = 0; 1044 static jmethodID g_TestJni_activateHardwareAcceleration = 0;
989 static void Java_TestJni_activateHardwareAcceleration(JNIEnv* env, jobject obj, 1045 static void Java_TestJni_activateHardwareAcceleration(JNIEnv* env, jobject obj,
990 jboolean activated, 1046 jboolean activated,
991 jint iPid, 1047 jint iPid,
992 jint iType, 1048 jint iType,
993 jint iPrimaryID, 1049 jint iPrimaryID,
994 jint iSecondaryID) { 1050 jint iSecondaryID) {
995 /* Must call RegisterNativesImpl() */ 1051 /* Must call RegisterNativesImpl() */
996 DCHECK(g_TestJni_clazz); 1052 DCHECK(g_TestJni_clazz);
997 DCHECK(g_TestJni_activateHardwareAcceleration); 1053
1054 base::android::LazyMethodID::Get<
1055 base::android::LazyMethodID::METHODTYPE_NORMAL,
1056 base::android::LazyMethodID::EXCEPTIONCHECK_YES>(
1057 env, g_TestJni_clazz,
1058 "activateHardwareAcceleration",
1059
1060 "("
1061 "Z"
1062 "I"
1063 "I"
1064 "I"
1065 "I"
1066 ")"
1067 "V",
1068 &g_TestJni_activateHardwareAcceleration);
998 1069
999 env->CallVoidMethod(obj, 1070 env->CallVoidMethod(obj,
1000 g_TestJni_activateHardwareAcceleration, activated, iPid, iType, 1071 g_TestJni_activateHardwareAcceleration, activated, iPid, iType,
1001 iPrimaryID, iSecondaryID); 1072 iPrimaryID, iSecondaryID);
1002 base::android::CheckException(env); 1073 base::android::CheckException(env);
1003 1074
1004 } 1075 }
1005 1076
1006 static jmethodID g_TestJni_uncheckedCall = 0; 1077 static jmethodID g_TestJni_uncheckedCall = 0;
1007 static void Java_TestJni_uncheckedCall(JNIEnv* env, jobject obj, jint iParam) { 1078 static void Java_TestJni_uncheckedCall(JNIEnv* env, jobject obj, jint iParam) {
1008 /* Must call RegisterNativesImpl() */ 1079 /* Must call RegisterNativesImpl() */
1009 DCHECK(g_TestJni_clazz); 1080 DCHECK(g_TestJni_clazz);
1010 DCHECK(g_TestJni_uncheckedCall); 1081
1082 base::android::LazyMethodID::Get<
1083 base::android::LazyMethodID::METHODTYPE_NORMAL,
1084 base::android::LazyMethodID::EXCEPTIONCHECK_YES>(
1085 env, g_TestJni_clazz,
1086 "uncheckedCall",
1087
1088 "("
1089 "I"
1090 ")"
1091 "V",
1092 &g_TestJni_uncheckedCall);
1011 1093
1012 env->CallVoidMethod(obj, 1094 env->CallVoidMethod(obj,
1013 g_TestJni_uncheckedCall, iParam); 1095 g_TestJni_uncheckedCall, iParam);
1014 1096
1015 } 1097 }
1016 1098
1017 // Step 3: GetMethodIDs and RegisterNatives. 1099 // Step 3: RegisterNatives.
1018 static void GetMethodIDsImpl(JNIEnv* env) { 1100
1101 static bool RegisterNativesImpl(JNIEnv* env) {
1102
1019 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( 1103 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
1020 base::android::GetUnscopedClass(env, kTestJniClassPath))); 1104 base::android::GetUnscopedClass(env, kTestJniClassPath)));
1021 g_InfoBar_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( 1105 g_InfoBar_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
1022 base::android::GetUnscopedClass(env, kInfoBarClassPath))); 1106 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
1087 "("
1088 "Z"
1089 "I"
1090 "I"
1091 "I"
1092 "I"
1093 ")"
1094 "V");
1095
1096 g_TestJni_uncheckedCall =
1097 base::android::GetMethodID(
1098 env, g_TestJni_clazz,
1099 "uncheckedCall",
1100
1101 "("
1102 "I"
1103 ")"
1104 "V");
1105
1106 }
1107
1108 static bool RegisterNativesImpl(JNIEnv* env) {
1109 GetMethodIDsImpl(env);
1110
1111 return true; 1107 return true;
1112 } 1108 }
1113 1109
1114 #endif // org_chromium_TestJni_JNI 1110 #endif // org_chromium_TestJni_JNI
1115 """ 1111 """
1116 self.assertTextEquals(golden_content, h.GetContent()) 1112 self.assertTextEquals(golden_content, h.GetContent())
1117 1113
1118 def testCalledByNativeParseError(self): 1114 def testCalledByNativeParseError(self):
1119 try: 1115 try:
1120 jni_generator.ExtractCalledByNatives(""" 1116 jni_generator.ExtractCalledByNatives("""
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 namespace JNI_InputStream { 1212 namespace JNI_InputStream {
1217 1213
1218 // Step 2: method stubs. 1214 // Step 2: method stubs.
1219 1215
1220 static jmethodID g_InputStream_available = 0; 1216 static jmethodID g_InputStream_available = 0;
1221 static jint Java_InputStream_available(JNIEnv* env, jobject obj) __attribute__ 1217 static jint Java_InputStream_available(JNIEnv* env, jobject obj) __attribute__
1222 ((unused)); 1218 ((unused));
1223 static jint Java_InputStream_available(JNIEnv* env, jobject obj) { 1219 static jint Java_InputStream_available(JNIEnv* env, jobject obj) {
1224 /* Must call RegisterNativesImpl() */ 1220 /* Must call RegisterNativesImpl() */
1225 DCHECK(g_InputStream_clazz); 1221 DCHECK(g_InputStream_clazz);
1226 DCHECK(g_InputStream_available); 1222
1223 base::android::LazyMethodID::Get<
1224 base::android::LazyMethodID::METHODTYPE_NORMAL,
1225 base::android::LazyMethodID::EXCEPTIONCHECK_NO>(
1226 env, g_InputStream_clazz,
1227 "available",
1228
1229 "("
1230 ")"
1231 "I",
1232 &g_InputStream_available);
1233
1227 jint ret = 1234 jint ret =
1228 env->CallIntMethod(obj, 1235 env->CallIntMethod(obj,
1229 g_InputStream_available); 1236 g_InputStream_available);
1230 base::android::CheckException(env); 1237 base::android::CheckException(env);
1231 return ret; 1238 return ret;
1232 } 1239 }
1233 1240
1234 static jmethodID g_InputStream_close = 0; 1241 static jmethodID g_InputStream_close = 0;
1235 static void Java_InputStream_close(JNIEnv* env, jobject obj) __attribute__ 1242 static void Java_InputStream_close(JNIEnv* env, jobject obj) __attribute__
1236 ((unused)); 1243 ((unused));
1237 static void Java_InputStream_close(JNIEnv* env, jobject obj) { 1244 static void Java_InputStream_close(JNIEnv* env, jobject obj) {
1238 /* Must call RegisterNativesImpl() */ 1245 /* Must call RegisterNativesImpl() */
1239 DCHECK(g_InputStream_clazz); 1246 DCHECK(g_InputStream_clazz);
1240 DCHECK(g_InputStream_close); 1247
1248 base::android::LazyMethodID::Get<
1249 base::android::LazyMethodID::METHODTYPE_NORMAL,
1250 base::android::LazyMethodID::EXCEPTIONCHECK_NO>(
1251 env, g_InputStream_clazz,
1252 "close",
1253
1254 "("
1255 ")"
1256 "V",
1257 &g_InputStream_close);
1241 1258
1242 env->CallVoidMethod(obj, 1259 env->CallVoidMethod(obj,
1243 g_InputStream_close); 1260 g_InputStream_close);
1244 base::android::CheckException(env); 1261 base::android::CheckException(env);
1245 1262
1246 } 1263 }
1247 1264
1248 static jmethodID g_InputStream_mark = 0; 1265 static jmethodID g_InputStream_mark = 0;
1249 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) 1266 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0)
1250 __attribute__ ((unused)); 1267 __attribute__ ((unused));
1251 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) { 1268 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) {
1252 /* Must call RegisterNativesImpl() */ 1269 /* Must call RegisterNativesImpl() */
1253 DCHECK(g_InputStream_clazz); 1270 DCHECK(g_InputStream_clazz);
1254 DCHECK(g_InputStream_mark); 1271
1272 base::android::LazyMethodID::Get<
1273 base::android::LazyMethodID::METHODTYPE_NORMAL,
1274 base::android::LazyMethodID::EXCEPTIONCHECK_NO>(
1275 env, g_InputStream_clazz,
1276 "mark",
1277
1278 "("
1279 "I"
1280 ")"
1281 "V",
1282 &g_InputStream_mark);
1255 1283
1256 env->CallVoidMethod(obj, 1284 env->CallVoidMethod(obj,
1257 g_InputStream_mark, p0); 1285 g_InputStream_mark, p0);
1258 base::android::CheckException(env); 1286 base::android::CheckException(env);
1259 1287
1260 } 1288 }
1261 1289
1262 static jmethodID g_InputStream_markSupported = 0; 1290 static jmethodID g_InputStream_markSupported = 0;
1263 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) 1291 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj)
1264 __attribute__ ((unused)); 1292 __attribute__ ((unused));
1265 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) { 1293 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) {
1266 /* Must call RegisterNativesImpl() */ 1294 /* Must call RegisterNativesImpl() */
1267 DCHECK(g_InputStream_clazz); 1295 DCHECK(g_InputStream_clazz);
1268 DCHECK(g_InputStream_markSupported); 1296
1297 base::android::LazyMethodID::Get<
1298 base::android::LazyMethodID::METHODTYPE_NORMAL,
1299 base::android::LazyMethodID::EXCEPTIONCHECK_NO>(
1300 env, g_InputStream_clazz,
1301 "markSupported",
1302
1303 "("
1304 ")"
1305 "Z",
1306 &g_InputStream_markSupported);
1307
1269 jboolean ret = 1308 jboolean ret =
1270 env->CallBooleanMethod(obj, 1309 env->CallBooleanMethod(obj,
1271 g_InputStream_markSupported); 1310 g_InputStream_markSupported);
1272 base::android::CheckException(env); 1311 base::android::CheckException(env);
1273 return ret; 1312 return ret;
1274 } 1313 }
1275 1314
1276 static jmethodID g_InputStream_readI = 0; 1315 static jmethodID g_InputStream_readI = 0;
1277 static jint Java_InputStream_readI(JNIEnv* env, jobject obj) __attribute__ 1316 static jint Java_InputStream_readI(JNIEnv* env, jobject obj) __attribute__
1278 ((unused)); 1317 ((unused));
1279 static jint Java_InputStream_readI(JNIEnv* env, jobject obj) { 1318 static jint Java_InputStream_readI(JNIEnv* env, jobject obj) {
1280 /* Must call RegisterNativesImpl() */ 1319 /* Must call RegisterNativesImpl() */
1281 DCHECK(g_InputStream_clazz); 1320 DCHECK(g_InputStream_clazz);
1282 DCHECK(g_InputStream_readI); 1321
1322 base::android::LazyMethodID::Get<
1323 base::android::LazyMethodID::METHODTYPE_NORMAL,
1324 base::android::LazyMethodID::EXCEPTIONCHECK_NO>(
1325 env, g_InputStream_clazz,
1326 "read",
1327
1328 "("
1329 ")"
1330 "I",
1331 &g_InputStream_readI);
1332
1283 jint ret = 1333 jint ret =
1284 env->CallIntMethod(obj, 1334 env->CallIntMethod(obj,
1285 g_InputStream_readI); 1335 g_InputStream_readI);
1286 base::android::CheckException(env); 1336 base::android::CheckException(env);
1287 return ret; 1337 return ret;
1288 } 1338 }
1289 1339
1290 static jmethodID g_InputStream_readI_AB = 0; 1340 static jmethodID g_InputStream_readI_AB = 0;
1291 static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) 1341 static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0)
1292 __attribute__ ((unused)); 1342 __attribute__ ((unused));
1293 static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) { 1343 static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) {
1294 /* Must call RegisterNativesImpl() */ 1344 /* Must call RegisterNativesImpl() */
1295 DCHECK(g_InputStream_clazz); 1345 DCHECK(g_InputStream_clazz);
1296 DCHECK(g_InputStream_readI_AB); 1346
1347 base::android::LazyMethodID::Get<
1348 base::android::LazyMethodID::METHODTYPE_NORMAL,
1349 base::android::LazyMethodID::EXCEPTIONCHECK_NO>(
1350 env, g_InputStream_clazz,
1351 "read",
1352
1353 "("
1354 "[B"
1355 ")"
1356 "I",
1357 &g_InputStream_readI_AB);
1358
1297 jint ret = 1359 jint ret =
1298 env->CallIntMethod(obj, 1360 env->CallIntMethod(obj,
1299 g_InputStream_readI_AB, p0); 1361 g_InputStream_readI_AB, p0);
1300 base::android::CheckException(env); 1362 base::android::CheckException(env);
1301 return ret; 1363 return ret;
1302 } 1364 }
1303 1365
1304 static jmethodID g_InputStream_readI_AB_I_I = 0; 1366 static jmethodID g_InputStream_readI_AB_I_I = 0;
1305 static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray 1367 static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray
1306 p0, 1368 p0,
1307 jint p1, 1369 jint p1,
1308 jint p2) __attribute__ ((unused)); 1370 jint p2) __attribute__ ((unused));
1309 static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray 1371 static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray
1310 p0, 1372 p0,
1311 jint p1, 1373 jint p1,
1312 jint p2) { 1374 jint p2) {
1313 /* Must call RegisterNativesImpl() */ 1375 /* Must call RegisterNativesImpl() */
1314 DCHECK(g_InputStream_clazz); 1376 DCHECK(g_InputStream_clazz);
1315 DCHECK(g_InputStream_readI_AB_I_I); 1377
1378 base::android::LazyMethodID::Get<
1379 base::android::LazyMethodID::METHODTYPE_NORMAL,
1380 base::android::LazyMethodID::EXCEPTIONCHECK_NO>(
1381 env, g_InputStream_clazz,
1382 "read",
1383
1384 "("
1385 "[B"
1386 "I"
1387 "I"
1388 ")"
1389 "I",
1390 &g_InputStream_readI_AB_I_I);
1391
1316 jint ret = 1392 jint ret =
1317 env->CallIntMethod(obj, 1393 env->CallIntMethod(obj,
1318 g_InputStream_readI_AB_I_I, p0, p1, p2); 1394 g_InputStream_readI_AB_I_I, p0, p1, p2);
1319 base::android::CheckException(env); 1395 base::android::CheckException(env);
1320 return ret; 1396 return ret;
1321 } 1397 }
1322 1398
1323 static jmethodID g_InputStream_reset = 0; 1399 static jmethodID g_InputStream_reset = 0;
1324 static void Java_InputStream_reset(JNIEnv* env, jobject obj) __attribute__ 1400 static void Java_InputStream_reset(JNIEnv* env, jobject obj) __attribute__
1325 ((unused)); 1401 ((unused));
1326 static void Java_InputStream_reset(JNIEnv* env, jobject obj) { 1402 static void Java_InputStream_reset(JNIEnv* env, jobject obj) {
1327 /* Must call RegisterNativesImpl() */ 1403 /* Must call RegisterNativesImpl() */
1328 DCHECK(g_InputStream_clazz); 1404 DCHECK(g_InputStream_clazz);
1329 DCHECK(g_InputStream_reset); 1405
1406 base::android::LazyMethodID::Get<
1407 base::android::LazyMethodID::METHODTYPE_NORMAL,
1408 base::android::LazyMethodID::EXCEPTIONCHECK_NO>(
1409 env, g_InputStream_clazz,
1410 "reset",
1411
1412 "("
1413 ")"
1414 "V",
1415 &g_InputStream_reset);
1330 1416
1331 env->CallVoidMethod(obj, 1417 env->CallVoidMethod(obj,
1332 g_InputStream_reset); 1418 g_InputStream_reset);
1333 base::android::CheckException(env); 1419 base::android::CheckException(env);
1334 1420
1335 } 1421 }
1336 1422
1337 static jmethodID g_InputStream_skip = 0; 1423 static jmethodID g_InputStream_skip = 0;
1338 static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) 1424 static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0)
1339 __attribute__ ((unused)); 1425 __attribute__ ((unused));
1340 static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) { 1426 static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) {
1341 /* Must call RegisterNativesImpl() */ 1427 /* Must call RegisterNativesImpl() */
1342 DCHECK(g_InputStream_clazz); 1428 DCHECK(g_InputStream_clazz);
1343 DCHECK(g_InputStream_skip); 1429
1430 base::android::LazyMethodID::Get<
1431 base::android::LazyMethodID::METHODTYPE_NORMAL,
1432 base::android::LazyMethodID::EXCEPTIONCHECK_NO>(
1433 env, g_InputStream_clazz,
1434 "skip",
1435
1436 "("
1437 "J"
1438 ")"
1439 "J",
1440 &g_InputStream_skip);
1441
1344 jlong ret = 1442 jlong ret =
1345 env->CallLongMethod(obj, 1443 env->CallLongMethod(obj,
1346 g_InputStream_skip, p0); 1444 g_InputStream_skip, p0);
1347 base::android::CheckException(env); 1445 base::android::CheckException(env);
1348 return ret; 1446 return ret;
1349 } 1447 }
1350 1448
1351 static jmethodID g_InputStream_Constructor = 0; 1449 static jmethodID g_InputStream_Constructor = 0;
1450 static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env)
1451 __attribute__ ((unused));
1352 static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env) { 1452 static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env) {
1353 /* Must call RegisterNativesImpl() */ 1453 /* Must call RegisterNativesImpl() */
1354 DCHECK(g_InputStream_clazz); 1454 DCHECK(g_InputStream_clazz);
1355 DCHECK(g_InputStream_Constructor); 1455
1456 base::android::LazyMethodID::Get<
1457 base::android::LazyMethodID::METHODTYPE_NORMAL,
1458 base::android::LazyMethodID::EXCEPTIONCHECK_NO>(
1459 env, g_InputStream_clazz,
1460 "<init>",
1461
1462 "("
1463 ")"
1464 "V",
1465 &g_InputStream_Constructor);
1466
1356 jobject ret = 1467 jobject ret =
1357 env->NewObject(g_InputStream_clazz, 1468 env->NewObject(g_InputStream_clazz,
1358 g_InputStream_Constructor); 1469 g_InputStream_Constructor);
1359 base::android::CheckException(env); 1470 base::android::CheckException(env);
1360 return ScopedJavaLocalRef<jobject>(env, ret); 1471 return ScopedJavaLocalRef<jobject>(env, ret);
1361 } 1472 }
1362 1473
1363 // Step 3: GetMethodIDs and RegisterNatives. 1474 // Step 3: RegisterNatives.
1364 static void GetMethodIDsImpl(JNIEnv* env) { 1475
1476 static bool RegisterNativesImpl(JNIEnv* env) {
1477
1365 g_InputStream_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( 1478 g_InputStream_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
1366 base::android::GetUnscopedClass(env, kInputStreamClassPath))); 1479 base::android::GetUnscopedClass(env, kInputStreamClassPath)));
1367 g_InputStream_available =
1368 base::android::GetMethodID(
1369 env, g_InputStream_clazz,
1370 "available",
1371
1372 "("
1373 ")"
1374 "I");
1375
1376 g_InputStream_close =
1377 base::android::GetMethodID(
1378 env, g_InputStream_clazz,
1379 "close",
1380
1381 "("
1382 ")"
1383 "V");
1384
1385 g_InputStream_mark =
1386 base::android::GetMethodID(
1387 env, g_InputStream_clazz,
1388 "mark",
1389
1390 "("
1391 "I"
1392 ")"
1393 "V");
1394
1395 g_InputStream_markSupported =
1396 base::android::GetMethodID(
1397 env, g_InputStream_clazz,
1398 "markSupported",
1399
1400 "("
1401 ")"
1402 "Z");
1403
1404 g_InputStream_readI =
1405 base::android::GetMethodID(
1406 env, g_InputStream_clazz,
1407 "read",
1408
1409 "("
1410 ")"
1411 "I");
1412
1413 g_InputStream_readI_AB =
1414 base::android::GetMethodID(
1415 env, g_InputStream_clazz,
1416 "read",
1417
1418 "("
1419 "[B"
1420 ")"
1421 "I");
1422
1423 g_InputStream_readI_AB_I_I =
1424 base::android::GetMethodID(
1425 env, g_InputStream_clazz,
1426 "read",
1427
1428 "("
1429 "[B"
1430 "I"
1431 "I"
1432 ")"
1433 "I");
1434
1435 g_InputStream_reset =
1436 base::android::GetMethodID(
1437 env, g_InputStream_clazz,
1438 "reset",
1439
1440 "("
1441 ")"
1442 "V");
1443
1444 g_InputStream_skip =
1445 base::android::GetMethodID(
1446 env, g_InputStream_clazz,
1447 "skip",
1448
1449 "("
1450 "J"
1451 ")"
1452 "J");
1453
1454 g_InputStream_Constructor =
1455 base::android::GetMethodID(
1456 env, g_InputStream_clazz,
1457 "<init>",
1458
1459 "("
1460 ")"
1461 "V");
1462
1463 }
1464
1465 static bool RegisterNativesImpl(JNIEnv* env) {
1466 GetMethodIDsImpl(env);
1467
1468 return true; 1480 return true;
1469 } 1481 }
1470 } // namespace JNI_InputStream 1482 } // namespace JNI_InputStream
1471 1483
1472 #endif // java_io_InputStream_JNI 1484 #endif // java_io_InputStream_JNI
1473 """ 1485 """
1474 self.assertTextEquals(golden_content, jni_from_javap.GetContent()) 1486 self.assertTextEquals(golden_content, jni_from_javap.GetContent())
1475 1487
1476 def testREForNatives(self): 1488 def testREForNatives(self):
1477 # We should not match "native SyncSetupFlow" inside the comment. 1489 # We should not match "native SyncSetupFlow" inside the comment.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 test_data, ('com/google/lookhowextremelylongiam/snarf/' 1546 test_data, ('com/google/lookhowextremelylongiam/snarf/'
1535 'icankeepthisupallday/ReallyLongClassNamesAreAllTheRage')) 1547 'icankeepthisupallday/ReallyLongClassNamesAreAllTheRage'))
1536 jni_lines = jni_from_java.GetContent().split('\n') 1548 jni_lines = jni_from_java.GetContent().split('\n')
1537 line = filter(lambda line: line.lstrip().startswith('#ifndef'), 1549 line = filter(lambda line: line.lstrip().startswith('#ifndef'),
1538 jni_lines)[0] 1550 jni_lines)[0]
1539 self.assertTrue(len(line) > 80, 1551 self.assertTrue(len(line) > 80,
1540 ('Expected #ifndef line to be > 80 chars: ', line)) 1552 ('Expected #ifndef line to be > 80 chars: ', line))
1541 1553
1542 if __name__ == '__main__': 1554 if __name__ == '__main__':
1543 unittest.main() 1555 unittest.main()
OLDNEW
« base/android/jni_android_unittest.cc ('K') | « base/android/jni_generator/jni_generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698