Chromium Code Reviews| 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 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| 1057 jni_from_java = jni_generator.JNIFromJavaSource( | 1058 jni_from_java = jni_generator.JNIFromJavaSource( |
| 1058 test_data, 'org/chromium/example/jni_generator/SampleForTests', options) | 1059 test_data, 'org/chromium/example/jni_generator/SampleForTests', options) |
| 1059 self.assertGoldenTextEquals(jni_from_java.GetContent()) | 1060 self.assertGoldenTextEquals(jni_from_java.GetContent()) |
| 1060 | 1061 |
| 1062 def testNativeExportsOptionalOption(self): | |
| 1063 test_data = """ | |
| 1064 package org.chromium.example.jni_generator; | |
| 1065 | |
| 1066 /** The pointer to the native Test. */ | |
| 1067 long nativeTest; | |
| 1068 | |
| 1069 class Test { | |
| 1070 private static native boolean nativeInitNativeClass(); | |
| 1071 private static native int nativeStaticMethod(long nativeTest, int arg1); | |
| 1072 private native int nativeMethod(long nativeTest, int arg1); | |
| 1073 @CalledByNative | |
| 1074 private void testMethodWithParam(int iParam); | |
| 1075 @CalledByNative | |
| 1076 private String testMethodWithParamAndReturn(int iParam); | |
| 1077 @CalledByNative | |
| 1078 private static int testStaticMethodWithParam(int iParam); | |
| 1079 @CalledByNative | |
| 1080 private static double testMethodWithNoParam(); | |
| 1081 @CalledByNative | |
| 1082 private static String testStaticMethodWithNoParam(); | |
| 1083 | |
| 1084 class MyInnerClass { | |
| 1085 @NativeCall("MyInnerClass") | |
| 1086 private native int nativeInit(); | |
| 1087 } | |
| 1088 class MyOtherInnerClass { | |
| 1089 @NativeCall("MyOtherInnerClass") | |
| 1090 private native int nativeInit(); | |
| 1091 } | |
| 1092 } | |
| 1093 """ | |
| 1094 options = TestOptions() | |
| 1095 options.jni_init_native_name = 'nativeInitNativeClass' | |
| 1096 options.native_exports = True | |
| 1097 options.native_exports_optional = True | |
| 1098 jni_from_java = jni_generator.JNIFromJavaSource( | |
| 1099 test_data, 'org/chromium/example/jni_generator/SampleForTests', options) | |
| 1100 self.assertGoldenTextEquals(jni_from_java.GetContent()) | |
|
rmcilroy
2015/02/20 17:19:35
Could we extract the common code from testNativeEx
Torne
2015/02/20 21:53:45
Done.
| |
| 1101 | |
| 1061 def testOuterInnerRaises(self): | 1102 def testOuterInnerRaises(self): |
| 1062 test_data = """ | 1103 test_data = """ |
| 1063 package org.chromium.media; | 1104 package org.chromium.media; |
| 1064 | 1105 |
| 1065 @CalledByNative | 1106 @CalledByNative |
| 1066 static int getCaptureFormatWidth(VideoCapture.CaptureFormat format) { | 1107 static int getCaptureFormatWidth(VideoCapture.CaptureFormat format) { |
| 1067 return format.getWidth(); | 1108 return format.getWidth(); |
| 1068 } | 1109 } |
| 1069 """ | 1110 """ |
| 1070 def willRaise(): | 1111 def willRaise(): |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1133 } | 1174 } |
| 1134 """ | 1175 """ |
| 1135 jni_from_java = jni_generator.JNIFromJavaSource(test_data, | 1176 jni_from_java = jni_generator.JNIFromJavaSource(test_data, |
| 1136 'org/chromium/foo/Foo', | 1177 'org/chromium/foo/Foo', |
| 1137 TestOptions()) | 1178 TestOptions()) |
| 1138 self.assertGoldenTextEquals(jni_from_java.GetContent()) | 1179 self.assertGoldenTextEquals(jni_from_java.GetContent()) |
| 1139 | 1180 |
| 1140 | 1181 |
| 1141 if __name__ == '__main__': | 1182 if __name__ == '__main__': |
| 1142 unittest.main() | 1183 unittest.main() |
| OLD | NEW |