| 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 24 matching lines...) Expand all Loading... |
| 35 def __init__(self): | 35 def __init__(self): |
| 36 self.namespace = None | 36 self.namespace = None |
| 37 self.script_name = SCRIPT_NAME | 37 self.script_name = SCRIPT_NAME |
| 38 self.includes = INCLUDES | 38 self.includes = INCLUDES |
| 39 self.pure_native_methods = False | 39 self.pure_native_methods = False |
| 40 self.ptr_type = 'long' | 40 self.ptr_type = 'long' |
| 41 self.jni_init_native_name = None | 41 self.jni_init_native_name = None |
| 42 self.eager_called_by_natives = False | 42 self.eager_called_by_natives = False |
| 43 self.cpp = 'cpp' | 43 self.cpp = 'cpp' |
| 44 self.javap = 'javap' | 44 self.javap = 'javap' |
| 45 | 45 self.native_exports = False |
| 46 | 46 |
| 47 class TestGenerator(unittest.TestCase): | 47 class TestGenerator(unittest.TestCase): |
| 48 def assertObjEquals(self, first, second): | 48 def assertObjEquals(self, first, second): |
| 49 dict_first = first.__dict__ | 49 dict_first = first.__dict__ |
| 50 dict_second = second.__dict__ | 50 dict_second = second.__dict__ |
| 51 self.assertEquals(dict_first.keys(), dict_second.keys()) | 51 self.assertEquals(dict_first.keys(), dict_second.keys()) |
| 52 for key, value in dict_first.iteritems(): | 52 for key, value in dict_first.iteritems(): |
| 53 if (type(value) is list and len(value) and | 53 if (type(value) is list and len(value) and |
| 54 isinstance(type(value[0]), object)): | 54 isinstance(type(value[0]), object)): |
| 55 self.assertListEquals(value, second.__getattribute__(key)) | 55 self.assertListEquals(value, second.__getattribute__(key)) |
| (...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 private static String testStaticMethodWithNoParam(); | 998 private static String testStaticMethodWithNoParam(); |
| 999 } | 999 } |
| 1000 """ | 1000 """ |
| 1001 options = TestOptions() | 1001 options = TestOptions() |
| 1002 options.jni_init_native_name = 'nativeInitNativeClass' | 1002 options.jni_init_native_name = 'nativeInitNativeClass' |
| 1003 options.eager_called_by_natives = True | 1003 options.eager_called_by_natives = True |
| 1004 jni_from_java = jni_generator.JNIFromJavaSource( | 1004 jni_from_java = jni_generator.JNIFromJavaSource( |
| 1005 test_data, 'org/chromium/example/jni_generator/Test', options) | 1005 test_data, 'org/chromium/example/jni_generator/Test', options) |
| 1006 self.assertGoldenTextEquals(jni_from_java.GetContent()) | 1006 self.assertGoldenTextEquals(jni_from_java.GetContent()) |
| 1007 | 1007 |
| 1008 def testNativeExportsOption(self): |
| 1009 test_data = """ |
| 1010 package org.chromium.example.jni_generator; |
| 1011 |
| 1012 /** The pointer to the native Test. */ |
| 1013 long nativeTest; |
| 1014 |
| 1015 class Test { |
| 1016 private static native boolean nativeInitNativeClass(); |
| 1017 private static native int nativeStaticMethod(long nativeTest, int arg1); |
| 1018 private native int nativeMethod(long nativeTest, int arg1); |
| 1019 @CalledByNative |
| 1020 private void testMethodWithParam(int iParam); |
| 1021 @CalledByNative |
| 1022 private String testMethodWithParamAndReturn(int iParam); |
| 1023 @CalledByNative |
| 1024 private static int testStaticMethodWithParam(int iParam); |
| 1025 @CalledByNative |
| 1026 private static double testMethodWithNoParam(); |
| 1027 @CalledByNative |
| 1028 private static String testStaticMethodWithNoParam(); |
| 1029 |
| 1030 class MyInnerClass { |
| 1031 @NativeCall("MyInnerClass") |
| 1032 private native int nativeInit(); |
| 1033 } |
| 1034 class MyOtherInnerClass { |
| 1035 @NativeCall("MyOtherInnerClass") |
| 1036 private native int nativeInit(); |
| 1037 } |
| 1038 } |
| 1039 """ |
| 1040 options = TestOptions() |
| 1041 options.jni_init_native_name = 'nativeInitNativeClass' |
| 1042 options.native_exports = True |
| 1043 jni_from_java = jni_generator.JNIFromJavaSource( |
| 1044 test_data, 'org/chromium/example/jni_generator/SampleForTests', options) |
| 1045 self.assertGoldenTextEquals(jni_from_java.GetContent()) |
| 1046 |
| 1008 def testOuterInnerRaises(self): | 1047 def testOuterInnerRaises(self): |
| 1009 test_data = """ | 1048 test_data = """ |
| 1010 package org.chromium.media; | 1049 package org.chromium.media; |
| 1011 | 1050 |
| 1012 @CalledByNative | 1051 @CalledByNative |
| 1013 static int getCaptureFormatWidth(VideoCapture.CaptureFormat format) { | 1052 static int getCaptureFormatWidth(VideoCapture.CaptureFormat format) { |
| 1014 return format.getWidth(); | 1053 return format.getWidth(); |
| 1015 } | 1054 } |
| 1016 """ | 1055 """ |
| 1017 def willRaise(): | 1056 def willRaise(): |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 } | 1119 } |
| 1081 """ | 1120 """ |
| 1082 jni_from_java = jni_generator.JNIFromJavaSource(test_data, | 1121 jni_from_java = jni_generator.JNIFromJavaSource(test_data, |
| 1083 'org/chromium/foo/Foo', | 1122 'org/chromium/foo/Foo', |
| 1084 TestOptions()) | 1123 TestOptions()) |
| 1085 self.assertGoldenTextEquals(jni_from_java.GetContent()) | 1124 self.assertGoldenTextEquals(jni_from_java.GetContent()) |
| 1086 | 1125 |
| 1087 | 1126 |
| 1088 if __name__ == '__main__': | 1127 if __name__ == '__main__': |
| 1089 unittest.main() | 1128 unittest.main() |
| OLD | NEW |