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

Unified Diff: base/android/jni_generator/jni_generator_tests.py

Issue 49913003: Android: adds ptr_type to jni_generator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/android/jni_generator/jni_generator.py ('k') | build/jni_generator.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 bf78d9c8d5a303d6b17a7ac6e7de881fa97f3e2e..cb325011ffd39ca056c1383c3741cc3e914830f7 100755
--- a/base/android/jni_generator/jni_generator_tests.py
+++ b/base/android/jni_generator/jni_generator_tests.py
@@ -28,6 +28,7 @@ class TestOptions(object):
def __init__(self):
self.namespace = None
self.script_name = SCRIPT_NAME
+ self.ptr_type = 'int'
class TestGenerator(unittest.TestCase):
@@ -95,7 +96,7 @@ class TestGenerator(unittest.TestCase):
double alpha, double beta, double gamma);
"""
jni_generator.JniParams.ExtractImportsAndInnerClasses(test_data)
- natives = jni_generator.ExtractNatives(test_data)
+ natives = jni_generator.ExtractNatives(test_data, 'int')
golden_natives = [
NativeMethod(return_type='int', static=False,
name='Init',
@@ -445,7 +446,7 @@ static bool RegisterNativesImpl(JNIEnv* env) {
private native int nativeInit();
}
"""
- natives = jni_generator.ExtractNatives(test_data)
+ natives = jni_generator.ExtractNatives(test_data, 'int')
golden_natives = [
NativeMethod(return_type='int', static=False,
name='Init', params=[],
@@ -528,7 +529,7 @@ static bool RegisterNativesImpl(JNIEnv* env) {
private native int nativeInit();
}
"""
- natives = jni_generator.ExtractNatives(test_data)
+ natives = jni_generator.ExtractNatives(test_data, 'int')
golden_natives = [
NativeMethod(return_type='int', static=False,
name='Init', params=[],
@@ -634,7 +635,7 @@ static bool RegisterNativesImpl(JNIEnv* env) {
}
}
"""
- natives = jni_generator.ExtractNatives(test_data)
+ natives = jni_generator.ExtractNatives(test_data, 'int')
golden_natives = [
NativeMethod(return_type='int', static=False,
name='Init', params=[],
@@ -2172,6 +2173,93 @@ class Foo {
self.assertTextEquals(
'[Ljava/nio/ByteBuffer;', JniParams.JavaToJni('java/nio/ByteBuffer[]'))
+ def testNativesLong(self):
+ test_options = TestOptions()
+ test_options.ptr_type = 'long'
+ test_data = """"
+ private native void nativeDestroy(long nativeChromeBrowserProvider);
+ """
+ jni_generator.JniParams.ExtractImportsAndInnerClasses(test_data)
+ natives = jni_generator.ExtractNatives(test_data, test_options.ptr_type)
+ golden_natives = [
+ NativeMethod(return_type='void', static=False, name='Destroy',
+ params=[Param(datatype='long',
+ name='nativeChromeBrowserProvider')],
+ java_class_name=None,
+ type='method',
+ p0_type='ChromeBrowserProvider',
+ ptr_type=test_options.ptr_type),
+ ]
+ 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())
+
if __name__ == '__main__':
unittest.main()
« no previous file with comments | « base/android/jni_generator/jni_generator.py ('k') | build/jni_generator.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698