| 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 const char kTestJniClassPath[] = "org/chromium/TestJni"; | 891 const char kTestJniClassPath[] = "org/chromium/TestJni"; |
| 904 const char kInfoBarClassPath[] = "org/chromium/TestJni$InfoBar"; | 892 const char kInfoBarClassPath[] = "org/chromium/TestJni$InfoBar"; |
| 905 // Leaking this jclass as we cannot use LazyInstance from some threads. | 893 // Leaking this jclass as we cannot use LazyInstance from some threads. |
| 906 jclass g_TestJni_clazz = NULL; | 894 jclass g_TestJni_clazz = NULL; |
| 907 // Leaking this jclass as we cannot use LazyInstance from some threads. | 895 // Leaking this jclass as we cannot use LazyInstance from some threads. |
| 908 jclass g_InfoBar_clazz = NULL; | 896 jclass g_InfoBar_clazz = NULL; |
| 909 } // namespace | 897 } // namespace |
| 910 | 898 |
| 911 // Step 2: method stubs. | 899 // Step 2: method stubs. |
| 912 | 900 |
| 913 static jmethodID g_TestJni_showConfirmInfoBar = 0; | 901 static base::subtle::AtomicWord 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 jmethodID method_id = |
| 911 base::android::MethodID::LazyGet< |
| 912 base::android::MethodID::METHODTYPE_NORMAL>( |
| 913 env, g_TestJni_clazz, |
| 914 "showConfirmInfoBar", |
| 915 |
| 916 "(" |
| 917 "I" |
| 918 "Ljava/lang/String;" |
| 919 "Ljava/lang/String;" |
| 920 "Ljava/lang/String;" |
| 921 "Landroid/graphics/Bitmap;" |
| 922 ")" |
| 923 "Lcom/google/android/apps/chrome/infobar/InfoBarContainer$NativeInfoBar;", |
| 924 &g_TestJni_showConfirmInfoBar); |
| 925 |
| 923 jobject ret = | 926 jobject ret = |
| 924 env->CallObjectMethod(obj, | 927 env->CallObjectMethod(obj, |
| 925 g_TestJni_showConfirmInfoBar, nativeInfoBar, buttonOk, buttonCancel, | 928 method_id, nativeInfoBar, buttonOk, buttonCancel, title, icon); |
| 926 title, icon); | |
| 927 base::android::CheckException(env); | 929 base::android::CheckException(env); |
| 928 return ScopedJavaLocalRef<jobject>(env, ret); | 930 return ScopedJavaLocalRef<jobject>(env, ret); |
| 929 } | 931 } |
| 930 | 932 |
| 931 static jmethodID g_TestJni_showAutoLoginInfoBar = 0; | 933 static base::subtle::AtomicWord g_TestJni_showAutoLoginInfoBar = 0; |
| 932 static ScopedJavaLocalRef<jobject> Java_TestJni_showAutoLoginInfoBar(JNIEnv* | 934 static ScopedJavaLocalRef<jobject> Java_TestJni_showAutoLoginInfoBar(JNIEnv* |
| 933 env, jobject obj, jint nativeInfoBar, | 935 env, jobject obj, jint nativeInfoBar, |
| 934 jstring realm, | 936 jstring realm, |
| 935 jstring account, | 937 jstring account, |
| 936 jstring args) { | 938 jstring args) { |
| 937 /* Must call RegisterNativesImpl() */ | 939 /* Must call RegisterNativesImpl() */ |
| 938 DCHECK(g_TestJni_clazz); | 940 DCHECK(g_TestJni_clazz); |
| 939 DCHECK(g_TestJni_showAutoLoginInfoBar); | 941 jmethodID method_id = |
| 942 base::android::MethodID::LazyGet< |
| 943 base::android::MethodID::METHODTYPE_NORMAL>( |
| 944 env, g_TestJni_clazz, |
| 945 "showAutoLoginInfoBar", |
| 946 |
| 947 "(" |
| 948 "I" |
| 949 "Ljava/lang/String;" |
| 950 "Ljava/lang/String;" |
| 951 "Ljava/lang/String;" |
| 952 ")" |
| 953 "Lcom/google/android/apps/chrome/infobar/InfoBarContainer$NativeInfoBar;", |
| 954 &g_TestJni_showAutoLoginInfoBar); |
| 955 |
| 940 jobject ret = | 956 jobject ret = |
| 941 env->CallObjectMethod(obj, | 957 env->CallObjectMethod(obj, |
| 942 g_TestJni_showAutoLoginInfoBar, nativeInfoBar, realm, account, args); | 958 method_id, nativeInfoBar, realm, account, args); |
| 943 base::android::CheckException(env); | 959 base::android::CheckException(env); |
| 944 return ScopedJavaLocalRef<jobject>(env, ret); | 960 return ScopedJavaLocalRef<jobject>(env, ret); |
| 945 } | 961 } |
| 946 | 962 |
| 947 static jmethodID g_InfoBar_dismiss = 0; | 963 static base::subtle::AtomicWord g_InfoBar_dismiss = 0; |
| 948 static void Java_InfoBar_dismiss(JNIEnv* env, jobject obj) { | 964 static void Java_InfoBar_dismiss(JNIEnv* env, jobject obj) { |
| 949 /* Must call RegisterNativesImpl() */ | 965 /* Must call RegisterNativesImpl() */ |
| 950 DCHECK(g_InfoBar_clazz); | 966 DCHECK(g_InfoBar_clazz); |
| 951 DCHECK(g_InfoBar_dismiss); | 967 jmethodID method_id = |
| 968 base::android::MethodID::LazyGet< |
| 969 base::android::MethodID::METHODTYPE_NORMAL>( |
| 970 env, g_InfoBar_clazz, |
| 971 "dismiss", |
| 972 |
| 973 "(" |
| 974 ")" |
| 975 "V", |
| 976 &g_InfoBar_dismiss); |
| 952 | 977 |
| 953 env->CallVoidMethod(obj, | 978 env->CallVoidMethod(obj, |
| 954 g_InfoBar_dismiss); | 979 method_id); |
| 955 base::android::CheckException(env); | 980 base::android::CheckException(env); |
| 956 | 981 |
| 957 } | 982 } |
| 958 | 983 |
| 959 static jmethodID g_TestJni_shouldShowAutoLogin = 0; | 984 static base::subtle::AtomicWord g_TestJni_shouldShowAutoLogin = 0; |
| 960 static jboolean Java_TestJni_shouldShowAutoLogin(JNIEnv* env, jobject | 985 static jboolean Java_TestJni_shouldShowAutoLogin(JNIEnv* env, jobject |
| 961 contentView, | 986 contentView, |
| 962 jstring realm, | 987 jstring realm, |
| 963 jstring account, | 988 jstring account, |
| 964 jstring args) { | 989 jstring args) { |
| 965 /* Must call RegisterNativesImpl() */ | 990 /* Must call RegisterNativesImpl() */ |
| 966 DCHECK(g_TestJni_clazz); | 991 DCHECK(g_TestJni_clazz); |
| 967 DCHECK(g_TestJni_shouldShowAutoLogin); | 992 jmethodID method_id = |
| 993 base::android::MethodID::LazyGet< |
| 994 base::android::MethodID::METHODTYPE_STATIC>( |
| 995 env, g_TestJni_clazz, |
| 996 "shouldShowAutoLogin", |
| 997 |
| 998 "(" |
| 999 "Lorg/chromium/content/browser/ContentViewCore;" |
| 1000 "Ljava/lang/String;" |
| 1001 "Ljava/lang/String;" |
| 1002 "Ljava/lang/String;" |
| 1003 ")" |
| 1004 "Z", |
| 1005 &g_TestJni_shouldShowAutoLogin); |
| 1006 |
| 968 jboolean ret = | 1007 jboolean ret = |
| 969 env->CallStaticBooleanMethod(g_TestJni_clazz, | 1008 env->CallStaticBooleanMethod(g_TestJni_clazz, |
| 970 g_TestJni_shouldShowAutoLogin, contentView, realm, account, args); | 1009 method_id, contentView, realm, account, args); |
| 971 base::android::CheckException(env); | 1010 base::android::CheckException(env); |
| 972 return ret; | 1011 return ret; |
| 973 } | 1012 } |
| 974 | 1013 |
| 975 static jmethodID g_TestJni_openUrl = 0; | 1014 static base::subtle::AtomicWord g_TestJni_openUrl = 0; |
| 976 static ScopedJavaLocalRef<jobject> Java_TestJni_openUrl(JNIEnv* env, jstring | 1015 static ScopedJavaLocalRef<jobject> Java_TestJni_openUrl(JNIEnv* env, jstring |
| 977 url) { | 1016 url) { |
| 978 /* Must call RegisterNativesImpl() */ | 1017 /* Must call RegisterNativesImpl() */ |
| 979 DCHECK(g_TestJni_clazz); | 1018 DCHECK(g_TestJni_clazz); |
| 980 DCHECK(g_TestJni_openUrl); | 1019 jmethodID method_id = |
| 1020 base::android::MethodID::LazyGet< |
| 1021 base::android::MethodID::METHODTYPE_STATIC>( |
| 1022 env, g_TestJni_clazz, |
| 1023 "openUrl", |
| 1024 |
| 1025 "(" |
| 1026 "Ljava/lang/String;" |
| 1027 ")" |
| 1028 "Ljava/io/InputStream;", |
| 1029 &g_TestJni_openUrl); |
| 1030 |
| 981 jobject ret = | 1031 jobject ret = |
| 982 env->CallStaticObjectMethod(g_TestJni_clazz, | 1032 env->CallStaticObjectMethod(g_TestJni_clazz, |
| 983 g_TestJni_openUrl, url); | 1033 method_id, url); |
| 984 base::android::CheckException(env); | 1034 base::android::CheckException(env); |
| 985 return ScopedJavaLocalRef<jobject>(env, ret); | 1035 return ScopedJavaLocalRef<jobject>(env, ret); |
| 986 } | 1036 } |
| 987 | 1037 |
| 988 static jmethodID g_TestJni_activateHardwareAcceleration = 0; | 1038 static base::subtle::AtomicWord g_TestJni_activateHardwareAcceleration = 0; |
| 989 static void Java_TestJni_activateHardwareAcceleration(JNIEnv* env, jobject obj, | 1039 static void Java_TestJni_activateHardwareAcceleration(JNIEnv* env, jobject obj, |
| 990 jboolean activated, | 1040 jboolean activated, |
| 991 jint iPid, | 1041 jint iPid, |
| 992 jint iType, | 1042 jint iType, |
| 993 jint iPrimaryID, | 1043 jint iPrimaryID, |
| 994 jint iSecondaryID) { | 1044 jint iSecondaryID) { |
| 995 /* Must call RegisterNativesImpl() */ | 1045 /* Must call RegisterNativesImpl() */ |
| 996 DCHECK(g_TestJni_clazz); | 1046 DCHECK(g_TestJni_clazz); |
| 997 DCHECK(g_TestJni_activateHardwareAcceleration); | 1047 jmethodID method_id = |
| 998 | 1048 base::android::MethodID::LazyGet< |
| 999 env->CallVoidMethod(obj, | 1049 base::android::MethodID::METHODTYPE_NORMAL>( |
| 1000 g_TestJni_activateHardwareAcceleration, activated, iPid, iType, | 1050 env, g_TestJni_clazz, |
| 1001 iPrimaryID, iSecondaryID); | 1051 "activateHardwareAcceleration", |
| 1002 base::android::CheckException(env); | |
| 1003 | |
| 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 | 1052 |
| 1087 "(" | 1053 "(" |
| 1088 "Z" | 1054 "Z" |
| 1089 "I" | 1055 "I" |
| 1090 "I" | 1056 "I" |
| 1091 "I" | 1057 "I" |
| 1092 "I" | 1058 "I" |
| 1093 ")" | 1059 ")" |
| 1094 "V"); | 1060 "V", |
| 1061 &g_TestJni_activateHardwareAcceleration); |
| 1095 | 1062 |
| 1096 g_TestJni_uncheckedCall = | 1063 env->CallVoidMethod(obj, |
| 1097 base::android::GetMethodID( | 1064 method_id, activated, iPid, iType, iPrimaryID, iSecondaryID); |
| 1098 env, g_TestJni_clazz, | 1065 base::android::CheckException(env); |
| 1099 "uncheckedCall", | 1066 |
| 1067 } |
| 1068 |
| 1069 static base::subtle::AtomicWord g_TestJni_uncheckedCall = 0; |
| 1070 static void Java_TestJni_uncheckedCall(JNIEnv* env, jobject obj, jint iParam) { |
| 1071 /* Must call RegisterNativesImpl() */ |
| 1072 DCHECK(g_TestJni_clazz); |
| 1073 jmethodID method_id = |
| 1074 base::android::MethodID::LazyGet< |
| 1075 base::android::MethodID::METHODTYPE_NORMAL>( |
| 1076 env, g_TestJni_clazz, |
| 1077 "uncheckedCall", |
| 1100 | 1078 |
| 1101 "(" | 1079 "(" |
| 1102 "I" | 1080 "I" |
| 1103 ")" | 1081 ")" |
| 1104 "V"); | 1082 "V", |
| 1083 &g_TestJni_uncheckedCall); |
| 1084 |
| 1085 env->CallVoidMethod(obj, |
| 1086 method_id, iParam); |
| 1105 | 1087 |
| 1106 } | 1088 } |
| 1107 | 1089 |
| 1090 // Step 3: RegisterNatives. |
| 1091 |
| 1108 static bool RegisterNativesImpl(JNIEnv* env) { | 1092 static bool RegisterNativesImpl(JNIEnv* env) { |
| 1109 GetMethodIDsImpl(env); | |
| 1110 | 1093 |
| 1094 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 1095 base::android::GetUnscopedClass(env, kTestJniClassPath))); |
| 1096 g_InfoBar_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 1097 base::android::GetUnscopedClass(env, kInfoBarClassPath))); |
| 1111 return true; | 1098 return true; |
| 1112 } | 1099 } |
| 1113 | 1100 |
| 1114 #endif // org_chromium_TestJni_JNI | 1101 #endif // org_chromium_TestJni_JNI |
| 1115 """ | 1102 """ |
| 1116 self.assertTextEquals(golden_content, h.GetContent()) | 1103 self.assertTextEquals(golden_content, h.GetContent()) |
| 1117 | 1104 |
| 1118 def testCalledByNativeParseError(self): | 1105 def testCalledByNativeParseError(self): |
| 1119 try: | 1106 try: |
| 1120 jni_generator.ExtractCalledByNatives(""" | 1107 jni_generator.ExtractCalledByNatives(""" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 namespace { | 1197 namespace { |
| 1211 const char kInputStreamClassPath[] = "java/io/InputStream"; | 1198 const char kInputStreamClassPath[] = "java/io/InputStream"; |
| 1212 // Leaking this jclass as we cannot use LazyInstance from some threads. | 1199 // Leaking this jclass as we cannot use LazyInstance from some threads. |
| 1213 jclass g_InputStream_clazz = NULL; | 1200 jclass g_InputStream_clazz = NULL; |
| 1214 } // namespace | 1201 } // namespace |
| 1215 | 1202 |
| 1216 namespace JNI_InputStream { | 1203 namespace JNI_InputStream { |
| 1217 | 1204 |
| 1218 // Step 2: method stubs. | 1205 // Step 2: method stubs. |
| 1219 | 1206 |
| 1220 static jmethodID g_InputStream_available = 0; | 1207 static base::subtle::AtomicWord g_InputStream_available = 0; |
| 1221 static jint Java_InputStream_available(JNIEnv* env, jobject obj) __attribute__ | 1208 static jint Java_InputStream_available(JNIEnv* env, jobject obj) __attribute__ |
| 1222 ((unused)); | 1209 ((unused)); |
| 1223 static jint Java_InputStream_available(JNIEnv* env, jobject obj) { | 1210 static jint Java_InputStream_available(JNIEnv* env, jobject obj) { |
| 1224 /* Must call RegisterNativesImpl() */ | 1211 /* Must call RegisterNativesImpl() */ |
| 1225 DCHECK(g_InputStream_clazz); | 1212 DCHECK(g_InputStream_clazz); |
| 1226 DCHECK(g_InputStream_available); | 1213 jmethodID method_id = |
| 1214 base::android::MethodID::LazyGet< |
| 1215 base::android::MethodID::METHODTYPE_NORMAL>( |
| 1216 env, g_InputStream_clazz, |
| 1217 "available", |
| 1218 |
| 1219 "(" |
| 1220 ")" |
| 1221 "I", |
| 1222 &g_InputStream_available); |
| 1223 |
| 1227 jint ret = | 1224 jint ret = |
| 1228 env->CallIntMethod(obj, | 1225 env->CallIntMethod(obj, |
| 1229 g_InputStream_available); | 1226 method_id); |
| 1230 base::android::CheckException(env); | 1227 base::android::CheckException(env); |
| 1231 return ret; | 1228 return ret; |
| 1232 } | 1229 } |
| 1233 | 1230 |
| 1234 static jmethodID g_InputStream_close = 0; | 1231 static base::subtle::AtomicWord g_InputStream_close = 0; |
| 1235 static void Java_InputStream_close(JNIEnv* env, jobject obj) __attribute__ | 1232 static void Java_InputStream_close(JNIEnv* env, jobject obj) __attribute__ |
| 1236 ((unused)); | 1233 ((unused)); |
| 1237 static void Java_InputStream_close(JNIEnv* env, jobject obj) { | 1234 static void Java_InputStream_close(JNIEnv* env, jobject obj) { |
| 1238 /* Must call RegisterNativesImpl() */ | 1235 /* Must call RegisterNativesImpl() */ |
| 1239 DCHECK(g_InputStream_clazz); | 1236 DCHECK(g_InputStream_clazz); |
| 1240 DCHECK(g_InputStream_close); | 1237 jmethodID method_id = |
| 1238 base::android::MethodID::LazyGet< |
| 1239 base::android::MethodID::METHODTYPE_NORMAL>( |
| 1240 env, g_InputStream_clazz, |
| 1241 "close", |
| 1242 |
| 1243 "(" |
| 1244 ")" |
| 1245 "V", |
| 1246 &g_InputStream_close); |
| 1241 | 1247 |
| 1242 env->CallVoidMethod(obj, | 1248 env->CallVoidMethod(obj, |
| 1243 g_InputStream_close); | 1249 method_id); |
| 1244 base::android::CheckException(env); | 1250 base::android::CheckException(env); |
| 1245 | 1251 |
| 1246 } | 1252 } |
| 1247 | 1253 |
| 1248 static jmethodID g_InputStream_mark = 0; | 1254 static base::subtle::AtomicWord g_InputStream_mark = 0; |
| 1249 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) | 1255 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) |
| 1250 __attribute__ ((unused)); | 1256 __attribute__ ((unused)); |
| 1251 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) { | 1257 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) { |
| 1252 /* Must call RegisterNativesImpl() */ | 1258 /* Must call RegisterNativesImpl() */ |
| 1253 DCHECK(g_InputStream_clazz); | 1259 DCHECK(g_InputStream_clazz); |
| 1254 DCHECK(g_InputStream_mark); | 1260 jmethodID method_id = |
| 1261 base::android::MethodID::LazyGet< |
| 1262 base::android::MethodID::METHODTYPE_NORMAL>( |
| 1263 env, g_InputStream_clazz, |
| 1264 "mark", |
| 1265 |
| 1266 "(" |
| 1267 "I" |
| 1268 ")" |
| 1269 "V", |
| 1270 &g_InputStream_mark); |
| 1255 | 1271 |
| 1256 env->CallVoidMethod(obj, | 1272 env->CallVoidMethod(obj, |
| 1257 g_InputStream_mark, p0); | 1273 method_id, p0); |
| 1258 base::android::CheckException(env); | 1274 base::android::CheckException(env); |
| 1259 | 1275 |
| 1260 } | 1276 } |
| 1261 | 1277 |
| 1262 static jmethodID g_InputStream_markSupported = 0; | 1278 static base::subtle::AtomicWord g_InputStream_markSupported = 0; |
| 1263 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) | 1279 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) |
| 1264 __attribute__ ((unused)); | 1280 __attribute__ ((unused)); |
| 1265 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) { | 1281 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) { |
| 1266 /* Must call RegisterNativesImpl() */ | 1282 /* Must call RegisterNativesImpl() */ |
| 1267 DCHECK(g_InputStream_clazz); | 1283 DCHECK(g_InputStream_clazz); |
| 1268 DCHECK(g_InputStream_markSupported); | 1284 jmethodID method_id = |
| 1285 base::android::MethodID::LazyGet< |
| 1286 base::android::MethodID::METHODTYPE_NORMAL>( |
| 1287 env, g_InputStream_clazz, |
| 1288 "markSupported", |
| 1289 |
| 1290 "(" |
| 1291 ")" |
| 1292 "Z", |
| 1293 &g_InputStream_markSupported); |
| 1294 |
| 1269 jboolean ret = | 1295 jboolean ret = |
| 1270 env->CallBooleanMethod(obj, | 1296 env->CallBooleanMethod(obj, |
| 1271 g_InputStream_markSupported); | 1297 method_id); |
| 1272 base::android::CheckException(env); | 1298 base::android::CheckException(env); |
| 1273 return ret; | 1299 return ret; |
| 1274 } | 1300 } |
| 1275 | 1301 |
| 1276 static jmethodID g_InputStream_readI = 0; | 1302 static base::subtle::AtomicWord g_InputStream_readI = 0; |
| 1277 static jint Java_InputStream_readI(JNIEnv* env, jobject obj) __attribute__ | 1303 static jint Java_InputStream_readI(JNIEnv* env, jobject obj) __attribute__ |
| 1278 ((unused)); | 1304 ((unused)); |
| 1279 static jint Java_InputStream_readI(JNIEnv* env, jobject obj) { | 1305 static jint Java_InputStream_readI(JNIEnv* env, jobject obj) { |
| 1280 /* Must call RegisterNativesImpl() */ | 1306 /* Must call RegisterNativesImpl() */ |
| 1281 DCHECK(g_InputStream_clazz); | 1307 DCHECK(g_InputStream_clazz); |
| 1282 DCHECK(g_InputStream_readI); | 1308 jmethodID method_id = |
| 1309 base::android::MethodID::LazyGet< |
| 1310 base::android::MethodID::METHODTYPE_NORMAL>( |
| 1311 env, g_InputStream_clazz, |
| 1312 "read", |
| 1313 |
| 1314 "(" |
| 1315 ")" |
| 1316 "I", |
| 1317 &g_InputStream_readI); |
| 1318 |
| 1283 jint ret = | 1319 jint ret = |
| 1284 env->CallIntMethod(obj, | 1320 env->CallIntMethod(obj, |
| 1285 g_InputStream_readI); | 1321 method_id); |
| 1286 base::android::CheckException(env); | 1322 base::android::CheckException(env); |
| 1287 return ret; | 1323 return ret; |
| 1288 } | 1324 } |
| 1289 | 1325 |
| 1290 static jmethodID g_InputStream_readI_AB = 0; | 1326 static base::subtle::AtomicWord g_InputStream_readI_AB = 0; |
| 1291 static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) | 1327 static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) |
| 1292 __attribute__ ((unused)); | 1328 __attribute__ ((unused)); |
| 1293 static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) { | 1329 static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) { |
| 1294 /* Must call RegisterNativesImpl() */ | 1330 /* Must call RegisterNativesImpl() */ |
| 1295 DCHECK(g_InputStream_clazz); | 1331 DCHECK(g_InputStream_clazz); |
| 1296 DCHECK(g_InputStream_readI_AB); | 1332 jmethodID method_id = |
| 1333 base::android::MethodID::LazyGet< |
| 1334 base::android::MethodID::METHODTYPE_NORMAL>( |
| 1335 env, g_InputStream_clazz, |
| 1336 "read", |
| 1337 |
| 1338 "(" |
| 1339 "[B" |
| 1340 ")" |
| 1341 "I", |
| 1342 &g_InputStream_readI_AB); |
| 1343 |
| 1297 jint ret = | 1344 jint ret = |
| 1298 env->CallIntMethod(obj, | 1345 env->CallIntMethod(obj, |
| 1299 g_InputStream_readI_AB, p0); | 1346 method_id, p0); |
| 1300 base::android::CheckException(env); | 1347 base::android::CheckException(env); |
| 1301 return ret; | 1348 return ret; |
| 1302 } | 1349 } |
| 1303 | 1350 |
| 1304 static jmethodID g_InputStream_readI_AB_I_I = 0; | 1351 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 | 1352 static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray |
| 1306 p0, | 1353 p0, |
| 1307 jint p1, | 1354 jint p1, |
| 1308 jint p2) __attribute__ ((unused)); | 1355 jint p2) __attribute__ ((unused)); |
| 1309 static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray | 1356 static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray |
| 1310 p0, | 1357 p0, |
| 1311 jint p1, | 1358 jint p1, |
| 1312 jint p2) { | 1359 jint p2) { |
| 1313 /* Must call RegisterNativesImpl() */ | 1360 /* Must call RegisterNativesImpl() */ |
| 1314 DCHECK(g_InputStream_clazz); | 1361 DCHECK(g_InputStream_clazz); |
| 1315 DCHECK(g_InputStream_readI_AB_I_I); | 1362 jmethodID method_id = |
| 1316 jint ret = | 1363 base::android::MethodID::LazyGet< |
| 1317 env->CallIntMethod(obj, | 1364 base::android::MethodID::METHODTYPE_NORMAL>( |
| 1318 g_InputStream_readI_AB_I_I, p0, p1, p2); | 1365 env, g_InputStream_clazz, |
| 1319 base::android::CheckException(env); | 1366 "read", |
| 1320 return ret; | |
| 1321 } | |
| 1322 | |
| 1323 static jmethodID g_InputStream_reset = 0; | |
| 1324 static void Java_InputStream_reset(JNIEnv* env, jobject obj) __attribute__ | |
| 1325 ((unused)); | |
| 1326 static void Java_InputStream_reset(JNIEnv* env, jobject obj) { | |
| 1327 /* Must call RegisterNativesImpl() */ | |
| 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 | 1367 |
| 1430 "(" | 1368 "(" |
| 1431 "[B" | 1369 "[B" |
| 1432 "I" | 1370 "I" |
| 1433 "I" | 1371 "I" |
| 1434 ")" | 1372 ")" |
| 1435 "I"); | 1373 "I", |
| 1374 &g_InputStream_readI_AB_I_I); |
| 1436 | 1375 |
| 1437 g_InputStream_reset = | 1376 jint ret = |
| 1438 base::android::GetMethodIDOrNull( | 1377 env->CallIntMethod(obj, |
| 1439 env, g_InputStream_clazz, | 1378 method_id, p0, p1, p2); |
| 1440 "reset", | 1379 base::android::CheckException(env); |
| 1380 return ret; |
| 1381 } |
| 1382 |
| 1383 static base::subtle::AtomicWord g_InputStream_reset = 0; |
| 1384 static void Java_InputStream_reset(JNIEnv* env, jobject obj) __attribute__ |
| 1385 ((unused)); |
| 1386 static void Java_InputStream_reset(JNIEnv* env, jobject obj) { |
| 1387 /* Must call RegisterNativesImpl() */ |
| 1388 DCHECK(g_InputStream_clazz); |
| 1389 jmethodID method_id = |
| 1390 base::android::MethodID::LazyGet< |
| 1391 base::android::MethodID::METHODTYPE_NORMAL>( |
| 1392 env, g_InputStream_clazz, |
| 1393 "reset", |
| 1441 | 1394 |
| 1442 "(" | 1395 "(" |
| 1443 ")" | 1396 ")" |
| 1444 "V"); | 1397 "V", |
| 1398 &g_InputStream_reset); |
| 1445 | 1399 |
| 1446 g_InputStream_skip = | 1400 env->CallVoidMethod(obj, |
| 1447 base::android::GetMethodIDOrNull( | 1401 method_id); |
| 1448 env, g_InputStream_clazz, | 1402 base::android::CheckException(env); |
| 1449 "skip", | 1403 |
| 1404 } |
| 1405 |
| 1406 static base::subtle::AtomicWord g_InputStream_skip = 0; |
| 1407 static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) |
| 1408 __attribute__ ((unused)); |
| 1409 static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) { |
| 1410 /* Must call RegisterNativesImpl() */ |
| 1411 DCHECK(g_InputStream_clazz); |
| 1412 jmethodID method_id = |
| 1413 base::android::MethodID::LazyGet< |
| 1414 base::android::MethodID::METHODTYPE_NORMAL>( |
| 1415 env, g_InputStream_clazz, |
| 1416 "skip", |
| 1450 | 1417 |
| 1451 "(" | 1418 "(" |
| 1452 "J" | 1419 "J" |
| 1453 ")" | 1420 ")" |
| 1454 "J"); | 1421 "J", |
| 1422 &g_InputStream_skip); |
| 1455 | 1423 |
| 1456 g_InputStream_Constructor = | 1424 jlong ret = |
| 1457 base::android::GetMethodIDOrNull( | 1425 env->CallLongMethod(obj, |
| 1458 env, g_InputStream_clazz, | 1426 method_id, p0); |
| 1459 "<init>", | 1427 base::android::CheckException(env); |
| 1428 return ret; |
| 1429 } |
| 1430 |
| 1431 static base::subtle::AtomicWord g_InputStream_Constructor = 0; |
| 1432 static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env) |
| 1433 __attribute__ ((unused)); |
| 1434 static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env) { |
| 1435 /* Must call RegisterNativesImpl() */ |
| 1436 DCHECK(g_InputStream_clazz); |
| 1437 jmethodID method_id = |
| 1438 base::android::MethodID::LazyGet< |
| 1439 base::android::MethodID::METHODTYPE_NORMAL>( |
| 1440 env, g_InputStream_clazz, |
| 1441 "<init>", |
| 1460 | 1442 |
| 1461 "(" | 1443 "(" |
| 1462 ")" | 1444 ")" |
| 1463 "V"); | 1445 "V", |
| 1446 &g_InputStream_Constructor); |
| 1464 | 1447 |
| 1448 jobject ret = |
| 1449 env->NewObject(g_InputStream_clazz, |
| 1450 method_id); |
| 1451 base::android::CheckException(env); |
| 1452 return ScopedJavaLocalRef<jobject>(env, ret); |
| 1465 } | 1453 } |
| 1466 | 1454 |
| 1455 // Step 3: RegisterNatives. |
| 1456 |
| 1467 static bool RegisterNativesImpl(JNIEnv* env) { | 1457 static bool RegisterNativesImpl(JNIEnv* env) { |
| 1468 GetMethodIDsImpl(env); | |
| 1469 | 1458 |
| 1459 g_InputStream_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
| 1460 base::android::GetUnscopedClass(env, kInputStreamClassPath))); |
| 1470 return true; | 1461 return true; |
| 1471 } | 1462 } |
| 1472 } // namespace JNI_InputStream | 1463 } // namespace JNI_InputStream |
| 1473 | 1464 |
| 1474 #endif // java_io_InputStream_JNI | 1465 #endif // java_io_InputStream_JNI |
| 1475 """ | 1466 """ |
| 1476 self.assertTextEquals(golden_content, jni_from_javap.GetContent()) | 1467 self.assertTextEquals(golden_content, jni_from_javap.GetContent()) |
| 1477 | 1468 |
| 1478 def testREForNatives(self): | 1469 def testREForNatives(self): |
| 1479 # We should not match "native SyncSetupFlow" inside the comment. | 1470 # 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/' | 1527 test_data, ('com/google/lookhowextremelylongiam/snarf/' |
| 1537 'icankeepthisupallday/ReallyLongClassNamesAreAllTheRage')) | 1528 'icankeepthisupallday/ReallyLongClassNamesAreAllTheRage')) |
| 1538 jni_lines = jni_from_java.GetContent().split('\n') | 1529 jni_lines = jni_from_java.GetContent().split('\n') |
| 1539 line = filter(lambda line: line.lstrip().startswith('#ifndef'), | 1530 line = filter(lambda line: line.lstrip().startswith('#ifndef'), |
| 1540 jni_lines)[0] | 1531 jni_lines)[0] |
| 1541 self.assertTrue(len(line) > 80, | 1532 self.assertTrue(len(line) > 80, |
| 1542 ('Expected #ifndef line to be > 80 chars: ', line)) | 1533 ('Expected #ifndef line to be > 80 chars: ', line)) |
| 1543 | 1534 |
| 1544 if __name__ == '__main__': | 1535 if __name__ == '__main__': |
| 1545 unittest.main() | 1536 unittest.main() |
| OLD | NEW |