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 9e73bd9e62134293fc0e4f0ed8c4c7320ab4e480..7e8da0fc2d671a8d9a4d274d1ac023894aabf4bd 100755 |
--- a/base/android/jni_generator/jni_generator_tests.py |
+++ b/base/android/jni_generator/jni_generator_tests.py |
@@ -21,6 +21,9 @@ from jni_generator import CalledByNative, JniParams, NativeMethod, Param |
SCRIPT_NAME = 'base/android/jni_generator/jni_generator.py' |
+INCLUDES = ( |
+ 'base/android/jni_generator/jni_generator_helper.h' |
+) |
# Set this environment variable in order to regenerate the golden text |
# files. |
@@ -32,7 +35,11 @@ class TestOptions(object): |
def __init__(self): |
self.namespace = None |
self.script_name = SCRIPT_NAME |
+ self.includes = INCLUDES |
+ self.pure_native_methods = False |
self.ptr_type = 'int' |
+ self.jni_init_native_name = None |
+ self.eager_called_by_natives = False |
class TestGenerator(unittest.TestCase): |
@@ -799,12 +806,20 @@ public long skip(long) throws java.io.IOException; |
content = file(os.path.join(script_dir, |
'java/src/org/chromium/example/jni_generator/SampleForTests.java') |
).read() |
- golden_content = file(os.path.join(script_dir, |
- 'golden_sample_for_tests_jni.h')).read() |
+ golden_file = os.path.join(script_dir, 'golden_sample_for_tests_jni.h') |
+ golden_content = file(golden_file).read() |
jni_from_java = jni_generator.JNIFromJavaSource( |
content, 'org/chromium/example/jni_generator/SampleForTests', |
TestOptions()) |
- self.assertTextEquals(golden_content, jni_from_java.GetContent()) |
+ generated_text = jni_from_java.GetContent() |
+ try: |
+ self.assertTextEquals(golden_content, generated_text) |
rmcilroy
2013/12/13 14:14:51
maybe rather than a try/catch just do a
if not eq
bulach
2013/12/13 15:23:58
yeah, good point. had to change a bit to expose th
|
+ except Exception: |
+ if os.environ.get(REBASELINE_ENV): |
+ with file(golden_file, 'w') as f: |
+ f.write(generated_text) |
+ return |
+ raise |
def testNoWrappingPreprocessorLines(self): |
test_data = """ |
@@ -927,6 +942,67 @@ class Foo { |
natives, [], test_options) |
self.assertGoldenTextEquals(h.GetContent()) |
+ def testPureNativeMethodsOption(self): |
+ test_data = """ |
+ package org.chromium.example.jni_generator; |
+ |
+ /** The pointer to the native Test. */ |
+ int nativeTest; |
+ |
+ class Test { |
+ private static native int nativeMethod(int nativeTest, int arg1); |
+ } |
+ """ |
+ options = TestOptions() |
+ options.pure_native_methods = True |
+ jni_from_java = jni_generator.JNIFromJavaSource( |
+ test_data, 'org/chromium/example/jni_generator/Test', options) |
+ self.assertGoldenTextEquals(jni_from_java.GetContent()) |
+ |
+ def testJNIInitNativeNameOption(self): |
+ test_data = """ |
+ package org.chromium.example.jni_generator; |
+ |
+ /** The pointer to the native Test. */ |
+ int nativeTest; |
+ |
+ class Test { |
+ private static native boolean initNativeClass(); |
+ private static native int nativeMethod(int nativeTest, int arg1); |
+ } |
+ """ |
+ options = TestOptions() |
+ options.jni_init_native_name = 'initNativeClass' |
+ jni_from_java = jni_generator.JNIFromJavaSource( |
+ test_data, 'org/chromium/example/jni_generator/Test', options) |
+ self.assertGoldenTextEquals(jni_from_java.GetContent()) |
+ |
+ def testEagerCalledByNativesOption(self): |
+ test_data = """ |
+ package org.chromium.example.jni_generator; |
+ |
+ /** The pointer to the native Test. */ |
+ int nativeTest; |
+ |
+ class Test { |
+ private static native boolean initNativeClass(); |
+ private static native int nativeMethod(int nativeTest, int arg1); |
+ @CalledByNative |
+ private void testMethodWithParam(int iParam); |
+ @CalledByNative |
+ private static int testStaticMethodWithParam(int iParam); |
+ @CalledByNative |
+ private static double testMethodWithNoParam(); |
+ @CalledByNative |
+ private static String testStaticMethodWithNoParam(); |
+ } |
+ """ |
+ options = TestOptions() |
+ options.jni_init_native_name = 'initNativeClass' |
+ options.eager_called_by_natives = True |
+ jni_from_java = jni_generator.JNIFromJavaSource( |
+ test_data, 'org/chromium/example/jni_generator/Test', options) |
+ self.assertGoldenTextEquals(jni_from_java.GetContent()) |
if __name__ == '__main__': |
unittest.main() |