def testFromJavaP(self): contents = self._ReadGoldenFile(os.path.join(os.path.dirname(sys.argv[0]), 'testInputStream.javap')) jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), TestOptions()) self.assertEquals(10, len(jni_from_javap.called_by_natives)) self.assertGoldenTextEquals(jni_from_javap.GetContent())
def testFromJavaP(self): contents = """ public abstract class java.io.InputStream extends java.lang.Object implements java.io.Closeable{ public java.io.InputStream(); Signature: ()V public int available() throws java.io.IOException; Signature: ()I public void close() throws java.io.IOException; Signature: ()V public void mark(int); Signature: (I)V public boolean markSupported(); Signature: ()Z public abstract int read() throws java.io.IOException; Signature: ()I public int read(byte[]) throws java.io.IOException; Signature: ([B)I public int read(byte[], int, int) throws java.io.IOException; Signature: ([BII)I public synchronized void reset() throws java.io.IOException; Signature: ()V public long skip(long) throws java.io.IOException; Signature: (J)J } """ jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), TestOptions()) self.assertEquals(10, len(jni_from_javap.called_by_natives)) self.assertGoldenTextEquals(jni_from_javap.GetContent())
def testConstantsFromJavaP(self): for f in ['testMotionEvent.javap', 'testMotionEvent.javap7']: contents = self._ReadGoldenFile(os.path.join(os.path.dirname(sys.argv[0]), f)) jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), TestOptions()) self.assertEquals(86, len(jni_from_javap.called_by_natives)) self.assertGoldenTextEquals(jni_from_javap.GetContent())
def testFromJavaPGenerics(self): contents = """ public abstract class java.util.HashSet<T> extends java.util.AbstractSet<E> implements java.util.Set<E>, java.lang.Cloneable, java.io.Serializable { public void dummy(); Signature: ()V } """ jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), TestOptions()) self.assertEquals(1, len(jni_from_javap.called_by_natives)) self.assertGoldenTextEquals(jni_from_javap.GetContent())
def testSnippnetJavap6_7_8(self): content_javap6 = """ public class java.util.HashSet { public boolean add(java.lang.Object); Signature: (Ljava/lang/Object;)Z } """ content_javap7 = """ public class java.util.HashSet { public boolean add(E); Signature: (Ljava/lang/Object;)Z } """ content_javap8 = """ public class java.util.HashSet { public boolean add(E); descriptor: (Ljava/lang/Object;)Z } """ jni_from_javap6 = jni_generator.JNIFromJavaP(content_javap6.split('\n'), TestOptions()) jni_from_javap7 = jni_generator.JNIFromJavaP(content_javap7.split('\n'), TestOptions()) jni_from_javap8 = jni_generator.JNIFromJavaP(content_javap8.split('\n'), TestOptions()) self.assertTrue(jni_from_javap6.GetContent()) self.assertTrue(jni_from_javap7.GetContent()) self.assertTrue(jni_from_javap8.GetContent()) # Ensure the javap7 is correctly parsed and uses the Signature field rather # than the "E" parameter. self.assertTextEquals(jni_from_javap6.GetContent(), jni_from_javap7.GetContent()) # Ensure the javap8 is correctly parsed and uses the descriptor field. self.assertTextEquals(jni_from_javap7.GetContent(), jni_from_javap8.GetContent())
def testFromJavaP(self): contents = """ public abstract class java.io.InputStream extends java.lang.Object implements java.io.Closeable{ public java.io.InputStream(); public int available() throws java.io.IOException; public void close() throws java.io.IOException; public void mark(int); public boolean markSupported(); public abstract int read() throws java.io.IOException; public int read(byte[]) throws java.io.IOException; public int read(byte[], int, int) throws java.io.IOException; public synchronized void reset() throws java.io.IOException; public long skip(long) throws java.io.IOException; } """ jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), None) self.assertEquals(9, 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_tests.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 jmethodID 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); DCHECK(g_InputStream_available); jint ret = env->CallIntMethod(obj, g_InputStream_available); base::android::CheckException(env); return ret; } static jmethodID 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); DCHECK(g_InputStream_close); env->CallVoidMethod(obj, g_InputStream_close); base::android::CheckException(env); } static jmethodID 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); DCHECK(g_InputStream_mark); env->CallVoidMethod(obj, g_InputStream_mark, p0); base::android::CheckException(env); } static jmethodID 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); DCHECK(g_InputStream_markSupported); jboolean ret = env->CallBooleanMethod(obj, g_InputStream_markSupported); base::android::CheckException(env); return ret; } static jmethodID g_InputStream_read_pqI = 0; static jint Java_InputStream_read(JNIEnv* env, jobject obj) __attribute__ ((unused)); static jint Java_InputStream_read(JNIEnv* env, jobject obj) { /* Must call RegisterNativesImpl() */ DCHECK(g_InputStream_clazz); DCHECK(g_InputStream_read_pqI); jint ret = env->CallIntMethod(obj, g_InputStream_read_pqI); base::android::CheckException(env); return ret; } static jmethodID g_InputStream_read_paBqI = 0; static jint Java_InputStream_read(JNIEnv* env, jobject obj, jbyteArray p0) __attribute__ ((unused)); static jint Java_InputStream_read(JNIEnv* env, jobject obj, jbyteArray p0) { /* Must call RegisterNativesImpl() */ DCHECK(g_InputStream_clazz); DCHECK(g_InputStream_read_paBqI); jint ret = env->CallIntMethod(obj, g_InputStream_read_paBqI, p0); base::android::CheckException(env); return ret; } static jmethodID g_InputStream_read_paBIIqI = 0; static jint Java_InputStream_read(JNIEnv* env, jobject obj, jbyteArray p0, jint p1, jint p2) __attribute__ ((unused)); static jint Java_InputStream_read(JNIEnv* env, jobject obj, jbyteArray p0, jint p1, jint p2) { /* Must call RegisterNativesImpl() */ DCHECK(g_InputStream_clazz); DCHECK(g_InputStream_read_paBIIqI); jint ret = env->CallIntMethod(obj, g_InputStream_read_paBIIqI, p0, p1, p2); base::android::CheckException(env); return ret; } static jmethodID 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); DCHECK(g_InputStream_reset); env->CallVoidMethod(obj, g_InputStream_reset); base::android::CheckException(env); } static jmethodID 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); DCHECK(g_InputStream_skip); jlong ret = env->CallLongMethod(obj, g_InputStream_skip, p0); base::android::CheckException(env); return ret; } // Step 3: GetMethodIDs and RegisterNatives. static void GetMethodIDsImpl(JNIEnv* env) { g_InputStream_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( base::android::GetUnscopedClass(env, kInputStreamClassPath))); g_InputStream_available = base::android::GetMethodID( env, g_InputStream_clazz, "available", "(" ")" "I"); g_InputStream_close = base::android::GetMethodID( env, g_InputStream_clazz, "close", "(" ")" "V"); g_InputStream_mark = base::android::GetMethodID( env, g_InputStream_clazz, "mark", "(" "I" ")" "V"); g_InputStream_markSupported = base::android::GetMethodID( env, g_InputStream_clazz, "markSupported", "(" ")" "Z"); g_InputStream_read_pqI = base::android::GetMethodID( env, g_InputStream_clazz, "read", "(" ")" "I"); g_InputStream_read_paBqI = base::android::GetMethodID( env, g_InputStream_clazz, "read", "(" "[B" ")" "I"); g_InputStream_read_paBIIqI = base::android::GetMethodID( env, g_InputStream_clazz, "read", "(" "[B" "I" "I" ")" "I"); g_InputStream_reset = base::android::GetMethodID( env, g_InputStream_clazz, "reset", "(" ")" "V"); g_InputStream_skip = base::android::GetMethodID( env, g_InputStream_clazz, "skip", "(" "J" ")" "J"); } static bool RegisterNativesImpl(JNIEnv* env) { GetMethodIDsImpl(env); return true; } } // namespace JNI_InputStream #endif // java_io_InputStream_JNI """ self.assertTextEquals(golden_content, jni_from_javap.GetContent())