Index: base/android/jni_generator/jni_generator_tests.py |
diff --git a/base/android/jni_generator/jni_generator_tests.py b/base/android/jni_generator/jni_generator_tests.py |
index cb325011ffd39ca056c1383c3741cc3e914830f7..cac113e3b71aedfbcb62384416e8b2dded0188fb 100755 |
--- a/base/android/jni_generator/jni_generator_tests.py |
+++ b/base/android/jni_generator/jni_generator_tests.py |
@@ -12,6 +12,7 @@ file. |
""" |
import difflib |
+import inspect |
import os |
import sys |
import unittest |
@@ -64,7 +65,28 @@ class TestGenerator(unittest.TestCase): |
print '=' * 80 |
print generated_text |
print '=' * 80 |
- self.fail('Golden text mismatch') |
+ print 'Run with:' |
+ print 'REBASELINE=1', sys.argv[0] |
+ print 'to regenerate the data files.' |
+ self.fail('Golden text mismatch.') |
+ |
+ def _ReadGoldenFile(self, golden_file): |
+ if not os.path.exists(golden_file): |
+ return None |
+ with file(golden_file, 'r') as f: |
+ return f.read() |
+ |
+ def assertGoldenTextEquals(self, generated_text): |
+ script_dir = os.path.dirname(sys.argv[0]) |
+ caller = inspect.stack()[1][3] |
+ golden_file = os.path.join(script_dir, caller + '.golden') |
+ golden_text = self._ReadGoldenFile(golden_file) |
+ if os.environ.get('REBASELINE'): |
+ if golden_text != generated_text: |
+ with file(golden_file, 'w') as f: |
+ f.write(generated_text) |
+ return |
+ self.assertTextEquals(golden_text, generated_text) |
def testNatives(self): |
test_data = """" |
@@ -219,225 +241,7 @@ class TestGenerator(unittest.TestCase): |
self.assertListEquals(golden_natives, natives) |
h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', |
natives, [], TestOptions()) |
- golden_content = """\ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
-// Use of this source code is governed by a BSD-style license that can be |
-// found in the LICENSE file. |
- |
-// This file is autogenerated by |
-// base/android/jni_generator/jni_generator.py |
-// For |
-// org/chromium/TestJni |
- |
-#ifndef org_chromium_TestJni_JNI |
-#define org_chromium_TestJni_JNI |
- |
-#include <jni.h> |
- |
-#include "base/android/jni_android.h" |
-#include "base/android/scoped_java_ref.h" |
-#include "base/basictypes.h" |
-#include "base/logging.h" |
- |
-using base::android::ScopedJavaLocalRef; |
- |
-// Step 1: forward declarations. |
-namespace { |
-const char kTestJniClassPath[] = "org/chromium/TestJni"; |
-// Leaking this jclass as we cannot use LazyInstance from some threads. |
-jclass g_TestJni_clazz = NULL; |
-} // namespace |
- |
-static jint Init(JNIEnv* env, jobject obj); |
- |
-static jstring GetDomainAndRegistry(JNIEnv* env, jclass clazz, |
- jstring url); |
- |
-static void CreateHistoricalTabFromState(JNIEnv* env, jclass clazz, |
- jbyteArray state, |
- jint tab_index); |
- |
-static jbyteArray GetStateAsByteArray(JNIEnv* env, jobject obj, |
- jobject view); |
- |
-static jobjectArray GetAutofillProfileGUIDs(JNIEnv* env, jclass clazz); |
- |
-static void SetRecognitionResults(JNIEnv* env, jobject obj, |
- jint sessionId, |
- jobjectArray results); |
- |
-static jint FindAll(JNIEnv* env, jobject obj, |
- jstring find); |
- |
-static jobject GetInnerClass(JNIEnv* env, jclass clazz); |
- |
-// Step 2: method stubs. |
-static void Destroy(JNIEnv* env, jobject obj, |
- jint nativeChromeBrowserProvider) { |
- DCHECK(nativeChromeBrowserProvider) << "Destroy"; |
- ChromeBrowserProvider* native = |
- reinterpret_cast<ChromeBrowserProvider*>(nativeChromeBrowserProvider); |
- return native->Destroy(env, obj); |
-} |
- |
-static jlong AddBookmark(JNIEnv* env, jobject obj, |
- jint nativeChromeBrowserProvider, |
- jstring url, |
- jstring title, |
- jboolean isFolder, |
- jlong parentId) { |
- DCHECK(nativeChromeBrowserProvider) << "AddBookmark"; |
- ChromeBrowserProvider* native = |
- reinterpret_cast<ChromeBrowserProvider*>(nativeChromeBrowserProvider); |
- return native->AddBookmark(env, obj, url, title, isFolder, parentId); |
-} |
- |
-static jlong AddBookmarkFromAPI(JNIEnv* env, jobject obj, |
- jint nativeChromeBrowserProvider, |
- jstring url, |
- jobject created, |
- jobject isBookmark, |
- jobject date, |
- jbyteArray favicon, |
- jstring title, |
- jobject visits) { |
- DCHECK(nativeChromeBrowserProvider) << "AddBookmarkFromAPI"; |
- ChromeBrowserProvider* native = |
- reinterpret_cast<ChromeBrowserProvider*>(nativeChromeBrowserProvider); |
- return native->AddBookmarkFromAPI(env, obj, url, created, isBookmark, date, |
- favicon, title, visits); |
-} |
- |
-static jobject QueryBitmap(JNIEnv* env, jobject obj, |
- jint nativeChromeBrowserProvider, |
- jobjectArray projection, |
- jstring selection, |
- jobjectArray selectionArgs, |
- jstring sortOrder) { |
- DCHECK(nativeChromeBrowserProvider) << "QueryBitmap"; |
- ChromeBrowserProvider* native = |
- reinterpret_cast<ChromeBrowserProvider*>(nativeChromeBrowserProvider); |
- return native->QueryBitmap(env, obj, projection, selection, selectionArgs, |
- sortOrder).Release(); |
-} |
- |
-static void GotOrientation(JNIEnv* env, jobject obj, |
- jint nativeDataFetcherImplAndroid, |
- jdouble alpha, |
- jdouble beta, |
- jdouble gamma) { |
- DCHECK(nativeDataFetcherImplAndroid) << "GotOrientation"; |
- DataFetcherImplAndroid* native = |
- reinterpret_cast<DataFetcherImplAndroid*>(nativeDataFetcherImplAndroid); |
- return native->GotOrientation(env, obj, alpha, beta, gamma); |
-} |
- |
-// Step 3: RegisterNatives. |
- |
-static bool RegisterNativesImpl(JNIEnv* env) { |
- |
- g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
- base::android::GetClass(env, kTestJniClassPath).obj())); |
- static const JNINativeMethod kMethodsTestJni[] = { |
- { "nativeInit", |
-"(" |
-")" |
-"I", reinterpret_cast<void*>(Init) }, |
- { "nativeDestroy", |
-"(" |
-"I" |
-")" |
-"V", reinterpret_cast<void*>(Destroy) }, |
- { "nativeAddBookmark", |
-"(" |
-"I" |
-"Ljava/lang/String;" |
-"Ljava/lang/String;" |
-"Z" |
-"J" |
-")" |
-"J", reinterpret_cast<void*>(AddBookmark) }, |
- { "nativeGetDomainAndRegistry", |
-"(" |
-"Ljava/lang/String;" |
-")" |
-"Ljava/lang/String;", reinterpret_cast<void*>(GetDomainAndRegistry) }, |
- { "nativeCreateHistoricalTabFromState", |
-"(" |
-"[B" |
-"I" |
-")" |
-"V", reinterpret_cast<void*>(CreateHistoricalTabFromState) }, |
- { "nativeGetStateAsByteArray", |
-"(" |
-"Landroid/view/View;" |
-")" |
-"[B", reinterpret_cast<void*>(GetStateAsByteArray) }, |
- { "nativeGetAutofillProfileGUIDs", |
-"(" |
-")" |
-"[Ljava/lang/String;", reinterpret_cast<void*>(GetAutofillProfileGUIDs) }, |
- { "nativeSetRecognitionResults", |
-"(" |
-"I" |
-"[Ljava/lang/String;" |
-")" |
-"V", reinterpret_cast<void*>(SetRecognitionResults) }, |
- { "nativeAddBookmarkFromAPI", |
-"(" |
-"I" |
-"Ljava/lang/String;" |
-"Ljava/lang/Long;" |
-"Ljava/lang/Boolean;" |
-"Ljava/lang/Long;" |
-"[B" |
-"Ljava/lang/String;" |
-"Ljava/lang/Integer;" |
-")" |
-"J", reinterpret_cast<void*>(AddBookmarkFromAPI) }, |
- { "nativeFindAll", |
-"(" |
-"Ljava/lang/String;" |
-")" |
-"I", reinterpret_cast<void*>(FindAll) }, |
- { "nativeGetInnerClass", |
-"(" |
-")" |
-"Lorg/chromium/example/jni_generator/SampleForTests$OnFrameAvailableListener;", |
- reinterpret_cast<void*>(GetInnerClass) }, |
- { "nativeQueryBitmap", |
-"(" |
-"I" |
-"[Ljava/lang/String;" |
-"Ljava/lang/String;" |
-"[Ljava/lang/String;" |
-"Ljava/lang/String;" |
-")" |
-"Landroid/graphics/Bitmap;", reinterpret_cast<void*>(QueryBitmap) }, |
- { "nativeGotOrientation", |
-"(" |
-"I" |
-"D" |
-"D" |
-"D" |
-")" |
-"V", reinterpret_cast<void*>(GotOrientation) }, |
- }; |
- const int kMethodsTestJniSize = arraysize(kMethodsTestJni); |
- |
- if (env->RegisterNatives(g_TestJni_clazz, |
- kMethodsTestJni, |
- kMethodsTestJniSize) < 0) { |
- LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
- return false; |
- } |
- |
- return true; |
-} |
- |
-#endif // org_chromium_TestJni_JNI |
-""" |
- self.assertTextEquals(golden_content, h.GetContent()) |
+ self.assertGoldenTextEquals(h.GetContent()) |
def testInnerClassNatives(self): |
test_data = """ |
@@ -456,67 +260,7 @@ static bool RegisterNativesImpl(JNIEnv* env) { |
self.assertListEquals(golden_natives, natives) |
h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', |
natives, [], TestOptions()) |
- golden_content = """\ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
-// Use of this source code is governed by a BSD-style license that can be |
-// found in the LICENSE file. |
- |
-// This file is autogenerated by |
-// base/android/jni_generator/jni_generator.py |
-// For |
-// org/chromium/TestJni |
- |
-#ifndef org_chromium_TestJni_JNI |
-#define org_chromium_TestJni_JNI |
- |
-#include <jni.h> |
- |
-#include "base/android/jni_android.h" |
-#include "base/android/scoped_java_ref.h" |
-#include "base/basictypes.h" |
-#include "base/logging.h" |
- |
-using base::android::ScopedJavaLocalRef; |
- |
-// Step 1: forward declarations. |
-namespace { |
-const char kTestJniClassPath[] = "org/chromium/TestJni"; |
-const char kMyInnerClassClassPath[] = "org/chromium/TestJni$MyInnerClass"; |
-// Leaking this jclass as we cannot use LazyInstance from some threads. |
-jclass g_TestJni_clazz = NULL; |
-} // namespace |
- |
-static jint Init(JNIEnv* env, jobject obj); |
- |
-// Step 2: method stubs. |
- |
-// Step 3: RegisterNatives. |
- |
-static bool RegisterNativesImpl(JNIEnv* env) { |
- |
- g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
- base::android::GetClass(env, kTestJniClassPath).obj())); |
- static const JNINativeMethod kMethodsMyInnerClass[] = { |
- { "nativeInit", |
-"(" |
-")" |
-"I", reinterpret_cast<void*>(Init) }, |
- }; |
- const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass); |
- |
- if (env->RegisterNatives(g_MyInnerClass_clazz, |
- kMethodsMyInnerClass, |
- kMethodsMyInnerClassSize) < 0) { |
- LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
- return false; |
- } |
- |
- return true; |
-} |
- |
-#endif // org_chromium_TestJni_JNI |
-""" |
- self.assertTextEquals(golden_content, h.GetContent()) |
+ self.assertGoldenTextEquals(h.GetContent()) |
def testInnerClassNativesMultiple(self): |
test_data = """ |
@@ -543,87 +287,7 @@ static bool RegisterNativesImpl(JNIEnv* env) { |
self.assertListEquals(golden_natives, natives) |
h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', |
natives, [], TestOptions()) |
- golden_content = """\ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
-// Use of this source code is governed by a BSD-style license that can be |
-// found in the LICENSE file. |
- |
-// This file is autogenerated by |
-// base/android/jni_generator/jni_generator.py |
-// For |
-// org/chromium/TestJni |
- |
-#ifndef org_chromium_TestJni_JNI |
-#define org_chromium_TestJni_JNI |
- |
-#include <jni.h> |
- |
-#include "base/android/jni_android.h" |
-#include "base/android/scoped_java_ref.h" |
-#include "base/basictypes.h" |
-#include "base/logging.h" |
- |
-using base::android::ScopedJavaLocalRef; |
- |
-// Step 1: forward declarations. |
-namespace { |
-const char kMyOtherInnerClassClassPath[] = |
- "org/chromium/TestJni$MyOtherInnerClass"; |
-const char kTestJniClassPath[] = "org/chromium/TestJni"; |
-const char kMyInnerClassClassPath[] = "org/chromium/TestJni$MyInnerClass"; |
-// Leaking this jclass as we cannot use LazyInstance from some threads. |
-jclass g_TestJni_clazz = NULL; |
-} // namespace |
- |
-static jint Init(JNIEnv* env, jobject obj); |
- |
-static jint Init(JNIEnv* env, jobject obj); |
- |
-// Step 2: method stubs. |
- |
-// Step 3: RegisterNatives. |
- |
-static bool RegisterNativesImpl(JNIEnv* env) { |
- |
- g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
- base::android::GetClass(env, kTestJniClassPath).obj())); |
- static const JNINativeMethod kMethodsMyOtherInnerClass[] = { |
- { "nativeInit", |
-"(" |
-")" |
-"I", reinterpret_cast<void*>(Init) }, |
- }; |
- const int kMethodsMyOtherInnerClassSize = |
- arraysize(kMethodsMyOtherInnerClass); |
- |
- if (env->RegisterNatives(g_MyOtherInnerClass_clazz, |
- kMethodsMyOtherInnerClass, |
- kMethodsMyOtherInnerClassSize) < 0) { |
- LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
- return false; |
- } |
- |
- static const JNINativeMethod kMethodsMyInnerClass[] = { |
- { "nativeInit", |
-"(" |
-")" |
-"I", reinterpret_cast<void*>(Init) }, |
- }; |
- const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass); |
- |
- if (env->RegisterNatives(g_MyInnerClass_clazz, |
- kMethodsMyInnerClass, |
- kMethodsMyInnerClassSize) < 0) { |
- LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
- return false; |
- } |
- |
- return true; |
-} |
- |
-#endif // org_chromium_TestJni_JNI |
-""" |
- self.assertTextEquals(golden_content, h.GetContent()) |
+ self.assertGoldenTextEquals(h.GetContent()) |
def testInnerClassNativesBothInnerAndOuter(self): |
test_data = """ |
@@ -649,86 +313,7 @@ static bool RegisterNativesImpl(JNIEnv* env) { |
self.assertListEquals(golden_natives, natives) |
h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', |
natives, [], TestOptions()) |
- golden_content = """\ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
-// Use of this source code is governed by a BSD-style license that can be |
-// found in the LICENSE file. |
- |
-// This file is autogenerated by |
-// base/android/jni_generator/jni_generator.py |
-// For |
-// org/chromium/TestJni |
- |
-#ifndef org_chromium_TestJni_JNI |
-#define org_chromium_TestJni_JNI |
- |
-#include <jni.h> |
- |
-#include "base/android/jni_android.h" |
-#include "base/android/scoped_java_ref.h" |
-#include "base/basictypes.h" |
-#include "base/logging.h" |
- |
-using base::android::ScopedJavaLocalRef; |
- |
-// Step 1: forward declarations. |
-namespace { |
-const char kMyOtherInnerClassClassPath[] = |
- "org/chromium/TestJni$MyOtherInnerClass"; |
-const char kTestJniClassPath[] = "org/chromium/TestJni"; |
-// Leaking this jclass as we cannot use LazyInstance from some threads. |
-jclass g_TestJni_clazz = NULL; |
-} // namespace |
- |
-static jint Init(JNIEnv* env, jobject obj); |
- |
-static jint Init(JNIEnv* env, jobject obj); |
- |
-// Step 2: method stubs. |
- |
-// Step 3: RegisterNatives. |
- |
-static bool RegisterNativesImpl(JNIEnv* env) { |
- |
- g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
- base::android::GetClass(env, kTestJniClassPath).obj())); |
- static const JNINativeMethod kMethodsMyOtherInnerClass[] = { |
- { "nativeInit", |
-"(" |
-")" |
-"I", reinterpret_cast<void*>(Init) }, |
- }; |
- const int kMethodsMyOtherInnerClassSize = |
- arraysize(kMethodsMyOtherInnerClass); |
- |
- if (env->RegisterNatives(g_MyOtherInnerClass_clazz, |
- kMethodsMyOtherInnerClass, |
- kMethodsMyOtherInnerClassSize) < 0) { |
- LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
- return false; |
- } |
- |
- static const JNINativeMethod kMethodsTestJni[] = { |
- { "nativeInit", |
-"(" |
-")" |
-"I", reinterpret_cast<void*>(Init) }, |
- }; |
- const int kMethodsTestJniSize = arraysize(kMethodsTestJni); |
- |
- if (env->RegisterNatives(g_TestJni_clazz, |
- kMethodsTestJni, |
- kMethodsTestJniSize) < 0) { |
- LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
- return false; |
- } |
- |
- return true; |
-} |
- |
-#endif // org_chromium_TestJni_JNI |
-""" |
- self.assertTextEquals(golden_content, h.GetContent()) |
+ self.assertGoldenTextEquals(h.GetContent()) |
def testCalledByNatives(self): |
test_data = """" |
@@ -1038,495 +623,7 @@ static bool RegisterNativesImpl(JNIEnv* env) { |
h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', |
[], called_by_natives, |
TestOptions()) |
- golden_content = """\ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
-// Use of this source code is governed by a BSD-style license that can be |
-// found in the LICENSE file. |
- |
-// This file is autogenerated by |
-// base/android/jni_generator/jni_generator.py |
-// For |
-// org/chromium/TestJni |
- |
-#ifndef org_chromium_TestJni_JNI |
-#define org_chromium_TestJni_JNI |
- |
-#include <jni.h> |
- |
-#include "base/android/jni_android.h" |
-#include "base/android/scoped_java_ref.h" |
-#include "base/basictypes.h" |
-#include "base/logging.h" |
- |
-using base::android::ScopedJavaLocalRef; |
- |
-// Step 1: forward declarations. |
-namespace { |
-const char kTestJniClassPath[] = "org/chromium/TestJni"; |
-const char kInfoBarClassPath[] = "org/chromium/TestJni$InfoBar"; |
-// Leaking this jclass as we cannot use LazyInstance from some threads. |
-jclass g_TestJni_clazz = NULL; |
-// Leaking this jclass as we cannot use LazyInstance from some threads. |
-jclass g_InfoBar_clazz = NULL; |
-} // namespace |
- |
-// Step 2: method stubs. |
- |
-static base::subtle::AtomicWord g_TestJni_showConfirmInfoBar = 0; |
-static ScopedJavaLocalRef<jobject> Java_TestJni_showConfirmInfoBar(JNIEnv* env, |
- jobject obj, jint nativeInfoBar, |
- jstring buttonOk, |
- jstring buttonCancel, |
- jstring title, |
- jobject icon) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_TestJni_clazz, |
- "showConfirmInfoBar", |
- |
-"(" |
-"I" |
-"Ljava/lang/String;" |
-"Ljava/lang/String;" |
-"Ljava/lang/String;" |
-"Landroid/graphics/Bitmap;" |
-")" |
-"Lorg/chromium/Foo$InnerClass;", |
- &g_TestJni_showConfirmInfoBar); |
- |
- jobject ret = |
- env->CallObjectMethod(obj, |
- method_id, nativeInfoBar, buttonOk, buttonCancel, title, icon); |
- base::android::CheckException(env); |
- return ScopedJavaLocalRef<jobject>(env, ret); |
-} |
- |
-static base::subtle::AtomicWord g_TestJni_showAutoLoginInfoBar = 0; |
-static ScopedJavaLocalRef<jobject> Java_TestJni_showAutoLoginInfoBar(JNIEnv* |
- env, jobject obj, jint nativeInfoBar, |
- jstring realm, |
- jstring account, |
- jstring args) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_TestJni_clazz, |
- "showAutoLoginInfoBar", |
- |
-"(" |
-"I" |
-"Ljava/lang/String;" |
-"Ljava/lang/String;" |
-"Ljava/lang/String;" |
-")" |
-"Lorg/chromium/Foo$InnerClass;", |
- &g_TestJni_showAutoLoginInfoBar); |
- |
- jobject ret = |
- env->CallObjectMethod(obj, |
- method_id, nativeInfoBar, realm, account, args); |
- base::android::CheckException(env); |
- return ScopedJavaLocalRef<jobject>(env, ret); |
-} |
- |
-static base::subtle::AtomicWord g_InfoBar_dismiss = 0; |
-static void Java_InfoBar_dismiss(JNIEnv* env, jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_InfoBar_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_InfoBar_clazz, |
- "dismiss", |
- |
-"(" |
-")" |
-"V", |
- &g_InfoBar_dismiss); |
- |
- env->CallVoidMethod(obj, |
- method_id); |
- base::android::CheckException(env); |
- |
-} |
- |
-static base::subtle::AtomicWord g_TestJni_shouldShowAutoLogin = 0; |
-static jboolean Java_TestJni_shouldShowAutoLogin(JNIEnv* env, jobject view, |
- jstring realm, |
- jstring account, |
- jstring args) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_STATIC>( |
- env, g_TestJni_clazz, |
- "shouldShowAutoLogin", |
- |
-"(" |
-"Landroid/view/View;" |
-"Ljava/lang/String;" |
-"Ljava/lang/String;" |
-"Ljava/lang/String;" |
-")" |
-"Z", |
- &g_TestJni_shouldShowAutoLogin); |
- |
- jboolean ret = |
- env->CallStaticBooleanMethod(g_TestJni_clazz, |
- method_id, view, realm, account, args); |
- base::android::CheckException(env); |
- return ret; |
-} |
- |
-static base::subtle::AtomicWord g_TestJni_openUrl = 0; |
-static ScopedJavaLocalRef<jobject> Java_TestJni_openUrl(JNIEnv* env, jstring |
- url) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_STATIC>( |
- env, g_TestJni_clazz, |
- "openUrl", |
- |
-"(" |
-"Ljava/lang/String;" |
-")" |
-"Ljava/io/InputStream;", |
- &g_TestJni_openUrl); |
- |
- jobject ret = |
- env->CallStaticObjectMethod(g_TestJni_clazz, |
- method_id, url); |
- base::android::CheckException(env); |
- return ScopedJavaLocalRef<jobject>(env, ret); |
-} |
- |
-static base::subtle::AtomicWord g_TestJni_activateHardwareAcceleration = 0; |
-static void Java_TestJni_activateHardwareAcceleration(JNIEnv* env, jobject obj, |
- jboolean activated, |
- jint iPid, |
- jint iType, |
- jint iPrimaryID, |
- jint iSecondaryID) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_TestJni_clazz, |
- "activateHardwareAcceleration", |
- |
-"(" |
-"Z" |
-"I" |
-"I" |
-"I" |
-"I" |
-")" |
-"V", |
- &g_TestJni_activateHardwareAcceleration); |
- |
- env->CallVoidMethod(obj, |
- method_id, activated, iPid, iType, iPrimaryID, iSecondaryID); |
- base::android::CheckException(env); |
- |
-} |
- |
-static base::subtle::AtomicWord g_TestJni_uncheckedCall = 0; |
-static void Java_TestJni_uncheckedCall(JNIEnv* env, jobject obj, jint iParam) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_TestJni_clazz, |
- "uncheckedCall", |
- |
-"(" |
-"I" |
-")" |
-"V", |
- &g_TestJni_uncheckedCall); |
- |
- env->CallVoidMethod(obj, |
- method_id, iParam); |
- |
-} |
- |
-static base::subtle::AtomicWord g_TestJni_returnByteArray = 0; |
-static ScopedJavaLocalRef<jbyteArray> Java_TestJni_returnByteArray(JNIEnv* env, |
- jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_TestJni_clazz, |
- "returnByteArray", |
- |
-"(" |
-")" |
-"[B", |
- &g_TestJni_returnByteArray); |
- |
- jbyteArray ret = |
- static_cast<jbyteArray>(env->CallObjectMethod(obj, |
- method_id)); |
- base::android::CheckException(env); |
- return ScopedJavaLocalRef<jbyteArray>(env, ret); |
-} |
- |
-static base::subtle::AtomicWord g_TestJni_returnBooleanArray = 0; |
-static ScopedJavaLocalRef<jbooleanArray> Java_TestJni_returnBooleanArray(JNIEnv* |
- env, jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_TestJni_clazz, |
- "returnBooleanArray", |
- |
-"(" |
-")" |
-"[Z", |
- &g_TestJni_returnBooleanArray); |
- |
- jbooleanArray ret = |
- static_cast<jbooleanArray>(env->CallObjectMethod(obj, |
- method_id)); |
- base::android::CheckException(env); |
- return ScopedJavaLocalRef<jbooleanArray>(env, ret); |
-} |
- |
-static base::subtle::AtomicWord g_TestJni_returnCharArray = 0; |
-static ScopedJavaLocalRef<jcharArray> Java_TestJni_returnCharArray(JNIEnv* env, |
- jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_TestJni_clazz, |
- "returnCharArray", |
- |
-"(" |
-")" |
-"[C", |
- &g_TestJni_returnCharArray); |
- |
- jcharArray ret = |
- static_cast<jcharArray>(env->CallObjectMethod(obj, |
- method_id)); |
- base::android::CheckException(env); |
- return ScopedJavaLocalRef<jcharArray>(env, ret); |
-} |
- |
-static base::subtle::AtomicWord g_TestJni_returnShortArray = 0; |
-static ScopedJavaLocalRef<jshortArray> Java_TestJni_returnShortArray(JNIEnv* |
- env, jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_TestJni_clazz, |
- "returnShortArray", |
- |
-"(" |
-")" |
-"[S", |
- &g_TestJni_returnShortArray); |
- |
- jshortArray ret = |
- static_cast<jshortArray>(env->CallObjectMethod(obj, |
- method_id)); |
- base::android::CheckException(env); |
- return ScopedJavaLocalRef<jshortArray>(env, ret); |
-} |
- |
-static base::subtle::AtomicWord g_TestJni_returnIntArray = 0; |
-static ScopedJavaLocalRef<jintArray> Java_TestJni_returnIntArray(JNIEnv* env, |
- jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_TestJni_clazz, |
- "returnIntArray", |
- |
-"(" |
-")" |
-"[I", |
- &g_TestJni_returnIntArray); |
- |
- jintArray ret = |
- static_cast<jintArray>(env->CallObjectMethod(obj, |
- method_id)); |
- base::android::CheckException(env); |
- return ScopedJavaLocalRef<jintArray>(env, ret); |
-} |
- |
-static base::subtle::AtomicWord g_TestJni_returnLongArray = 0; |
-static ScopedJavaLocalRef<jlongArray> Java_TestJni_returnLongArray(JNIEnv* env, |
- jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_TestJni_clazz, |
- "returnLongArray", |
- |
-"(" |
-")" |
-"[J", |
- &g_TestJni_returnLongArray); |
- |
- jlongArray ret = |
- static_cast<jlongArray>(env->CallObjectMethod(obj, |
- method_id)); |
- base::android::CheckException(env); |
- return ScopedJavaLocalRef<jlongArray>(env, ret); |
-} |
- |
-static base::subtle::AtomicWord g_TestJni_returnDoubleArray = 0; |
-static ScopedJavaLocalRef<jdoubleArray> Java_TestJni_returnDoubleArray(JNIEnv* |
- env, jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_TestJni_clazz, |
- "returnDoubleArray", |
- |
-"(" |
-")" |
-"[D", |
- &g_TestJni_returnDoubleArray); |
- |
- jdoubleArray ret = |
- static_cast<jdoubleArray>(env->CallObjectMethod(obj, |
- method_id)); |
- base::android::CheckException(env); |
- return ScopedJavaLocalRef<jdoubleArray>(env, ret); |
-} |
- |
-static base::subtle::AtomicWord g_TestJni_returnObjectArray = 0; |
-static ScopedJavaLocalRef<jobjectArray> Java_TestJni_returnObjectArray(JNIEnv* |
- env, jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_TestJni_clazz, |
- "returnObjectArray", |
- |
-"(" |
-")" |
-"[Ljava/lang/Object;", |
- &g_TestJni_returnObjectArray); |
- |
- jobjectArray ret = |
- static_cast<jobjectArray>(env->CallObjectMethod(obj, |
- method_id)); |
- base::android::CheckException(env); |
- return ScopedJavaLocalRef<jobjectArray>(env, ret); |
-} |
- |
-static base::subtle::AtomicWord g_TestJni_returnArrayOfByteArray = 0; |
-static ScopedJavaLocalRef<jobjectArray> |
- Java_TestJni_returnArrayOfByteArray(JNIEnv* env, jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_TestJni_clazz, |
- "returnArrayOfByteArray", |
- |
-"(" |
-")" |
-"[[B", |
- &g_TestJni_returnArrayOfByteArray); |
- |
- jobjectArray ret = |
- static_cast<jobjectArray>(env->CallObjectMethod(obj, |
- method_id)); |
- base::android::CheckException(env); |
- return ScopedJavaLocalRef<jobjectArray>(env, ret); |
-} |
- |
-static base::subtle::AtomicWord g_TestJni_getCompressFormat = 0; |
-static ScopedJavaLocalRef<jobject> Java_TestJni_getCompressFormat(JNIEnv* env, |
- jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_TestJni_clazz, |
- "getCompressFormat", |
- |
-"(" |
-")" |
-"Landroid/graphics/Bitmap$CompressFormat;", |
- &g_TestJni_getCompressFormat); |
- |
- jobject ret = |
- env->CallObjectMethod(obj, |
- method_id); |
- base::android::CheckException(env); |
- return ScopedJavaLocalRef<jobject>(env, ret); |
-} |
- |
-static base::subtle::AtomicWord g_TestJni_getCompressFormatList = 0; |
-static ScopedJavaLocalRef<jobject> Java_TestJni_getCompressFormatList(JNIEnv* |
- env, jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_TestJni_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_TestJni_clazz, |
- "getCompressFormatList", |
- |
-"(" |
-")" |
-"Ljava/util/List;", |
- &g_TestJni_getCompressFormatList); |
- |
- jobject ret = |
- env->CallObjectMethod(obj, |
- method_id); |
- base::android::CheckException(env); |
- return ScopedJavaLocalRef<jobject>(env, ret); |
-} |
- |
-// Step 3: RegisterNatives. |
- |
-static bool RegisterNativesImpl(JNIEnv* env) { |
- |
- g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
- base::android::GetClass(env, kTestJniClassPath).obj())); |
- g_InfoBar_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
- base::android::GetClass(env, kInfoBarClassPath).obj())); |
- return true; |
-} |
- |
-#endif // org_chromium_TestJni_JNI |
-""" |
- self.assertTextEquals(golden_content, h.GetContent()) |
+ self.assertGoldenTextEquals(h.GetContent()) |
def testCalledByNativeParseError(self): |
try: |
@@ -1590,72 +687,7 @@ public abstract class java.util.HashSet<T> extends java.util.AbstractSet<E> |
jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), |
TestOptions()) |
self.assertEquals(1, len(jni_from_javap.called_by_natives)) |
- golden_content = """\ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
-// Use of this source code is governed by a BSD-style license that can be |
-// found in the LICENSE file. |
- |
-// This file is autogenerated by |
-// base/android/jni_generator/jni_generator.py |
-// For |
-// java/util/HashSet |
- |
-#ifndef java_util_HashSet_JNI |
-#define java_util_HashSet_JNI |
- |
-#include <jni.h> |
- |
-#include "base/android/jni_android.h" |
-#include "base/android/scoped_java_ref.h" |
-#include "base/basictypes.h" |
-#include "base/logging.h" |
- |
-using base::android::ScopedJavaLocalRef; |
- |
-// Step 1: forward declarations. |
-namespace { |
-const char kHashSetClassPath[] = "java/util/HashSet"; |
-// Leaking this jclass as we cannot use LazyInstance from some threads. |
-jclass g_HashSet_clazz = NULL; |
-} // namespace |
- |
-namespace JNI_HashSet { |
- |
-// Step 2: method stubs. |
- |
-static base::subtle::AtomicWord g_HashSet_dummy = 0; |
-static void Java_HashSet_dummy(JNIEnv* env, jobject obj) __attribute__ |
- ((unused)); |
-static void Java_HashSet_dummy(JNIEnv* env, jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_HashSet_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_HashSet_clazz, |
- "dummy", |
-"()V", |
- &g_HashSet_dummy); |
- |
- env->CallVoidMethod(obj, |
- method_id); |
- base::android::CheckException(env); |
- |
-} |
- |
-// Step 3: RegisterNatives. |
- |
-static bool RegisterNativesImpl(JNIEnv* env) { |
- |
- g_HashSet_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
- base::android::GetClass(env, kHashSetClassPath).obj())); |
- return true; |
-} |
-} // namespace JNI_HashSet |
- |
-#endif // java_util_HashSet_JNI |
-""" |
- self.assertTextEquals(golden_content, jni_from_javap.GetContent()) |
+ self.assertGoldenTextEquals(jni_from_javap.GetContent()) |
def testSnippnetJavap6_7(self): |
content_javap6 = """ |
@@ -1711,264 +743,7 @@ public long skip(long) throws java.io.IOException; |
jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), |
TestOptions()) |
self.assertEquals(10, len(jni_from_javap.called_by_natives)) |
- golden_content = """\ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
-// Use of this source code is governed by a BSD-style license that can be |
-// found in the LICENSE file. |
- |
-// This file is autogenerated by |
-// base/android/jni_generator/jni_generator.py |
-// For |
-// java/io/InputStream |
- |
-#ifndef java_io_InputStream_JNI |
-#define java_io_InputStream_JNI |
- |
-#include <jni.h> |
- |
-#include "base/android/jni_android.h" |
-#include "base/android/scoped_java_ref.h" |
-#include "base/basictypes.h" |
-#include "base/logging.h" |
- |
-using base::android::ScopedJavaLocalRef; |
- |
-// Step 1: forward declarations. |
-namespace { |
-const char kInputStreamClassPath[] = "java/io/InputStream"; |
-// Leaking this jclass as we cannot use LazyInstance from some threads. |
-jclass g_InputStream_clazz = NULL; |
-} // namespace |
- |
-namespace JNI_InputStream { |
- |
-// Step 2: method stubs. |
- |
-static base::subtle::AtomicWord g_InputStream_available = 0; |
-static jint Java_InputStream_available(JNIEnv* env, jobject obj) __attribute__ |
- ((unused)); |
-static jint Java_InputStream_available(JNIEnv* env, jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_InputStream_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_InputStream_clazz, |
- "available", |
-"()I", |
- &g_InputStream_available); |
- |
- jint ret = |
- env->CallIntMethod(obj, |
- method_id); |
- base::android::CheckException(env); |
- return ret; |
-} |
- |
-static base::subtle::AtomicWord g_InputStream_close = 0; |
-static void Java_InputStream_close(JNIEnv* env, jobject obj) __attribute__ |
- ((unused)); |
-static void Java_InputStream_close(JNIEnv* env, jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_InputStream_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_InputStream_clazz, |
- "close", |
-"()V", |
- &g_InputStream_close); |
- |
- env->CallVoidMethod(obj, |
- method_id); |
- base::android::CheckException(env); |
- |
-} |
- |
-static base::subtle::AtomicWord g_InputStream_mark = 0; |
-static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) |
- __attribute__ ((unused)); |
-static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_InputStream_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_InputStream_clazz, |
- "mark", |
-"(I)V", |
- &g_InputStream_mark); |
- |
- env->CallVoidMethod(obj, |
- method_id, p0); |
- base::android::CheckException(env); |
- |
-} |
- |
-static base::subtle::AtomicWord g_InputStream_markSupported = 0; |
-static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) |
- __attribute__ ((unused)); |
-static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_InputStream_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_InputStream_clazz, |
- "markSupported", |
-"()Z", |
- &g_InputStream_markSupported); |
- |
- jboolean ret = |
- env->CallBooleanMethod(obj, |
- method_id); |
- base::android::CheckException(env); |
- return ret; |
-} |
- |
-static base::subtle::AtomicWord g_InputStream_readI = 0; |
-static jint Java_InputStream_readI(JNIEnv* env, jobject obj) __attribute__ |
- ((unused)); |
-static jint Java_InputStream_readI(JNIEnv* env, jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_InputStream_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_InputStream_clazz, |
- "read", |
-"()I", |
- &g_InputStream_readI); |
- |
- jint ret = |
- env->CallIntMethod(obj, |
- method_id); |
- base::android::CheckException(env); |
- return ret; |
-} |
- |
-static base::subtle::AtomicWord g_InputStream_readI_AB = 0; |
-static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) |
- __attribute__ ((unused)); |
-static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_InputStream_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_InputStream_clazz, |
- "read", |
-"([B)I", |
- &g_InputStream_readI_AB); |
- |
- jint ret = |
- env->CallIntMethod(obj, |
- method_id, p0); |
- base::android::CheckException(env); |
- return ret; |
-} |
- |
-static base::subtle::AtomicWord g_InputStream_readI_AB_I_I = 0; |
-static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray |
- p0, |
- jint p1, |
- jint p2) __attribute__ ((unused)); |
-static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray |
- p0, |
- jint p1, |
- jint p2) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_InputStream_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_InputStream_clazz, |
- "read", |
-"([BII)I", |
- &g_InputStream_readI_AB_I_I); |
- |
- jint ret = |
- env->CallIntMethod(obj, |
- method_id, p0, p1, p2); |
- base::android::CheckException(env); |
- return ret; |
-} |
- |
-static base::subtle::AtomicWord g_InputStream_reset = 0; |
-static void Java_InputStream_reset(JNIEnv* env, jobject obj) __attribute__ |
- ((unused)); |
-static void Java_InputStream_reset(JNIEnv* env, jobject obj) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_InputStream_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_InputStream_clazz, |
- "reset", |
-"()V", |
- &g_InputStream_reset); |
- |
- env->CallVoidMethod(obj, |
- method_id); |
- base::android::CheckException(env); |
- |
-} |
- |
-static base::subtle::AtomicWord g_InputStream_skip = 0; |
-static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) |
- __attribute__ ((unused)); |
-static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_InputStream_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_InputStream_clazz, |
- "skip", |
-"(J)J", |
- &g_InputStream_skip); |
- |
- jlong ret = |
- env->CallLongMethod(obj, |
- method_id, p0); |
- base::android::CheckException(env); |
- return ret; |
-} |
- |
-static base::subtle::AtomicWord g_InputStream_Constructor = 0; |
-static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env) |
- __attribute__ ((unused)); |
-static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env) { |
- /* Must call RegisterNativesImpl() */ |
- DCHECK(g_InputStream_clazz); |
- jmethodID method_id = |
- base::android::MethodID::LazyGet< |
- base::android::MethodID::TYPE_INSTANCE>( |
- env, g_InputStream_clazz, |
- "<init>", |
-"()V", |
- &g_InputStream_Constructor); |
- |
- jobject ret = |
- env->NewObject(g_InputStream_clazz, |
- method_id); |
- base::android::CheckException(env); |
- return ScopedJavaLocalRef<jobject>(env, ret); |
-} |
- |
-// Step 3: RegisterNatives. |
- |
-static bool RegisterNativesImpl(JNIEnv* env) { |
- |
- g_InputStream_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
- base::android::GetClass(env, kInputStreamClassPath).obj())); |
- return true; |
-} |
-} // namespace JNI_InputStream |
- |
-#endif // java_io_InputStream_JNI |
-""" |
- self.assertTextEquals(golden_content, jni_from_javap.GetContent()) |
+ self.assertGoldenTextEquals(jni_from_javap.GetContent()) |
def testREForNatives(self): |
# We should not match "native SyncSetupFlow" inside the comment. |
@@ -2047,68 +822,7 @@ static bool RegisterNativesImpl(JNIEnv* env) { |
jni_from_java = jni_generator.JNIFromJavaSource( |
test_data, 'org/chromium/example/jni_generator/Example', TestOptions()) |
jni_generator.JniParams.SetJarJarMappings('') |
- golden_content = """\ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
-// Use of this source code is governed by a BSD-style license that can be |
-// found in the LICENSE file. |
- |
-// This file is autogenerated by |
-// base/android/jni_generator/jni_generator.py |
-// For |
-// org/chromium/example/jni_generator/Example |
- |
-#ifndef org_chromium_example_jni_generator_Example_JNI |
-#define org_chromium_example_jni_generator_Example_JNI |
- |
-#include <jni.h> |
- |
-#include "base/android/jni_android.h" |
-#include "base/android/scoped_java_ref.h" |
-#include "base/basictypes.h" |
-#include "base/logging.h" |
- |
-using base::android::ScopedJavaLocalRef; |
- |
-// Step 1: forward declarations. |
-namespace { |
-const char kExampleClassPath[] = "com/test/jni_generator/Example"; |
-// Leaking this jclass as we cannot use LazyInstance from some threads. |
-jclass g_Example_clazz = NULL; |
-} // namespace |
- |
-static void Test(JNIEnv* env, jclass clazz, |
- jobject t); |
- |
-// Step 2: method stubs. |
- |
-// Step 3: RegisterNatives. |
- |
-static bool RegisterNativesImpl(JNIEnv* env) { |
- |
- g_Example_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
- base::android::GetClass(env, kExampleClassPath).obj())); |
- static const JNINativeMethod kMethodsExample[] = { |
- { "nativeTest", |
-"(" |
-"Lorg/test2/org/chromium/example2/Test;" |
-")" |
-"V", reinterpret_cast<void*>(Test) }, |
- }; |
- const int kMethodsExampleSize = arraysize(kMethodsExample); |
- |
- if (env->RegisterNatives(g_Example_clazz, |
- kMethodsExample, |
- kMethodsExampleSize) < 0) { |
- LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
- return false; |
- } |
- |
- return true; |
-} |
- |
-#endif // org_chromium_example_jni_generator_Example_JNI |
-""" |
- self.assertTextEquals(golden_content, jni_from_java.GetContent()) |
+ self.assertGoldenTextEquals(jni_from_java.GetContent()) |
def testImports(self): |
import_header = """ |
@@ -2193,72 +907,7 @@ class Foo { |
self.assertListEquals(golden_natives, natives) |
h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', |
natives, [], test_options) |
- golden_content = """\ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
-// Use of this source code is governed by a BSD-style license that can be |
-// found in the LICENSE file. |
- |
-// This file is autogenerated by |
-// base/android/jni_generator/jni_generator.py |
-// For |
-// org/chromium/TestJni |
- |
-#ifndef org_chromium_TestJni_JNI |
-#define org_chromium_TestJni_JNI |
- |
-#include <jni.h> |
- |
-#include "base/android/jni_android.h" |
-#include "base/android/scoped_java_ref.h" |
-#include "base/basictypes.h" |
-#include "base/logging.h" |
- |
-using base::android::ScopedJavaLocalRef; |
- |
-// Step 1: forward declarations. |
-namespace { |
-const char kTestJniClassPath[] = "org/chromium/TestJni"; |
-// Leaking this jclass as we cannot use LazyInstance from some threads. |
-jclass g_TestJni_clazz = NULL; |
-} // namespace |
- |
-// Step 2: method stubs. |
-static void Destroy(JNIEnv* env, jobject obj, |
- jlong nativeChromeBrowserProvider) { |
- DCHECK(nativeChromeBrowserProvider) << "Destroy"; |
- ChromeBrowserProvider* native = |
- reinterpret_cast<ChromeBrowserProvider*>(nativeChromeBrowserProvider); |
- return native->Destroy(env, obj); |
-} |
- |
-// Step 3: RegisterNatives. |
- |
-static bool RegisterNativesImpl(JNIEnv* env) { |
- |
- g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
- base::android::GetClass(env, kTestJniClassPath).obj())); |
- static const JNINativeMethod kMethodsTestJni[] = { |
- { "nativeDestroy", |
-"(" |
-"J" |
-")" |
-"V", reinterpret_cast<void*>(Destroy) }, |
- }; |
- const int kMethodsTestJniSize = arraysize(kMethodsTestJni); |
- |
- if (env->RegisterNatives(g_TestJni_clazz, |
- kMethodsTestJni, |
- kMethodsTestJniSize) < 0) { |
- LOG(ERROR) << "RegisterNatives failed in " << __FILE__; |
- return false; |
- } |
- |
- return true; |
-} |
- |
-#endif // org_chromium_TestJni_JNI |
-""" |
- self.assertTextEquals(golden_content, h.GetContent()) |
+ self.assertGoldenTextEquals(h.GetContent()) |
if __name__ == '__main__': |