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 25 matching lines...) Expand all Loading... |
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 self.native_exports = False | 45 self.native_exports = False |
| 46 self.native_exports_optional = False |
46 | 47 |
47 class TestGenerator(unittest.TestCase): | 48 class TestGenerator(unittest.TestCase): |
48 def assertObjEquals(self, first, second): | 49 def assertObjEquals(self, first, second): |
49 dict_first = first.__dict__ | 50 dict_first = first.__dict__ |
50 dict_second = second.__dict__ | 51 dict_second = second.__dict__ |
51 self.assertEquals(dict_first.keys(), dict_second.keys()) | 52 self.assertEquals(dict_first.keys(), dict_second.keys()) |
52 for key, value in dict_first.iteritems(): | 53 for key, value in dict_first.iteritems(): |
53 if (type(value) is list and len(value) and | 54 if (type(value) is list and len(value) and |
54 isinstance(type(value[0]), object)): | 55 isinstance(type(value[0]), object)): |
55 self.assertListEquals(value, second.__getattribute__(key)) | 56 self.assertListEquals(value, second.__getattribute__(key)) |
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 private static String testStaticMethodWithNoParam(); | 1013 private static String testStaticMethodWithNoParam(); |
1013 } | 1014 } |
1014 """ | 1015 """ |
1015 options = TestOptions() | 1016 options = TestOptions() |
1016 options.jni_init_native_name = 'nativeInitNativeClass' | 1017 options.jni_init_native_name = 'nativeInitNativeClass' |
1017 options.eager_called_by_natives = True | 1018 options.eager_called_by_natives = True |
1018 jni_from_java = jni_generator.JNIFromJavaSource( | 1019 jni_from_java = jni_generator.JNIFromJavaSource( |
1019 test_data, 'org/chromium/example/jni_generator/Test', options) | 1020 test_data, 'org/chromium/example/jni_generator/Test', options) |
1020 self.assertGoldenTextEquals(jni_from_java.GetContent()) | 1021 self.assertGoldenTextEquals(jni_from_java.GetContent()) |
1021 | 1022 |
1022 def testNativeExportsOption(self): | 1023 def runNativeExportsOption(self, optional): |
1023 test_data = """ | 1024 test_data = """ |
1024 package org.chromium.example.jni_generator; | 1025 package org.chromium.example.jni_generator; |
1025 | 1026 |
1026 /** The pointer to the native Test. */ | 1027 /** The pointer to the native Test. */ |
1027 long nativeTest; | 1028 long nativeTest; |
1028 | 1029 |
1029 class Test { | 1030 class Test { |
1030 private static native boolean nativeInitNativeClass(); | 1031 private static native boolean nativeInitNativeClass(); |
1031 private static native int nativeStaticMethod(long nativeTest, int arg1); | 1032 private static native int nativeStaticMethod(long nativeTest, int arg1); |
1032 private native int nativeMethod(long nativeTest, int arg1); | 1033 private native int nativeMethod(long nativeTest, int arg1); |
(...skipping 14 matching lines...) Expand all Loading... |
1047 } | 1048 } |
1048 class MyOtherInnerClass { | 1049 class MyOtherInnerClass { |
1049 @NativeCall("MyOtherInnerClass") | 1050 @NativeCall("MyOtherInnerClass") |
1050 private native int nativeInit(); | 1051 private native int nativeInit(); |
1051 } | 1052 } |
1052 } | 1053 } |
1053 """ | 1054 """ |
1054 options = TestOptions() | 1055 options = TestOptions() |
1055 options.jni_init_native_name = 'nativeInitNativeClass' | 1056 options.jni_init_native_name = 'nativeInitNativeClass' |
1056 options.native_exports = True | 1057 options.native_exports = True |
| 1058 options.native_exports_optional = optional |
1057 jni_from_java = jni_generator.JNIFromJavaSource( | 1059 jni_from_java = jni_generator.JNIFromJavaSource( |
1058 test_data, 'org/chromium/example/jni_generator/SampleForTests', options) | 1060 test_data, 'org/chromium/example/jni_generator/SampleForTests', options) |
1059 self.assertGoldenTextEquals(jni_from_java.GetContent()) | 1061 return jni_from_java.GetContent() |
| 1062 |
| 1063 def testNativeExportsOption(self): |
| 1064 content = self.runNativeExportsOption(False) |
| 1065 self.assertGoldenTextEquals(content) |
| 1066 |
| 1067 def testNativeExportsOptionalOption(self): |
| 1068 content = self.runNativeExportsOption(True) |
| 1069 self.assertGoldenTextEquals(content) |
1060 | 1070 |
1061 def testOuterInnerRaises(self): | 1071 def testOuterInnerRaises(self): |
1062 test_data = """ | 1072 test_data = """ |
1063 package org.chromium.media; | 1073 package org.chromium.media; |
1064 | 1074 |
1065 @CalledByNative | 1075 @CalledByNative |
1066 static int getCaptureFormatWidth(VideoCapture.CaptureFormat format) { | 1076 static int getCaptureFormatWidth(VideoCapture.CaptureFormat format) { |
1067 return format.getWidth(); | 1077 return format.getWidth(); |
1068 } | 1078 } |
1069 """ | 1079 """ |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 } | 1143 } |
1134 """ | 1144 """ |
1135 jni_from_java = jni_generator.JNIFromJavaSource(test_data, | 1145 jni_from_java = jni_generator.JNIFromJavaSource(test_data, |
1136 'org/chromium/foo/Foo', | 1146 'org/chromium/foo/Foo', |
1137 TestOptions()) | 1147 TestOptions()) |
1138 self.assertGoldenTextEquals(jni_from_java.GetContent()) | 1148 self.assertGoldenTextEquals(jni_from_java.GetContent()) |
1139 | 1149 |
1140 | 1150 |
1141 if __name__ == '__main__': | 1151 if __name__ == '__main__': |
1142 unittest.main() | 1152 unittest.main() |
OLD | NEW |