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