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 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 return format.getWidth(); | 1078 return format.getWidth(); |
1079 } | 1079 } |
1080 """ | 1080 """ |
1081 def willRaise(): | 1081 def willRaise(): |
1082 jni_generator.JNIFromJavaSource( | 1082 jni_generator.JNIFromJavaSource( |
1083 test_data, | 1083 test_data, |
1084 'org/chromium/media/VideoCaptureFactory', | 1084 'org/chromium/media/VideoCaptureFactory', |
1085 TestOptions()) | 1085 TestOptions()) |
1086 self.assertRaises(SyntaxError, willRaise) | 1086 self.assertRaises(SyntaxError, willRaise) |
1087 | 1087 |
1088 def testImplicitImport(self): | |
1089 test_data = """ | |
1090 package org.chromium.android_webview; | |
1091 | |
1092 %(IMPORT)s | |
1093 | |
1094 @CalledByNative | |
1095 private static void clientCertificatesCleared(Runnable callback) { | |
1096 if (callbaback == null) return; | |
1097 callback.run(); | |
1098 } | |
1099 """ | |
1100 def generate(import_clause): | |
1101 jni_generator.JNIFromJavaSource( | |
1102 test_data % {'IMPORT': import_clause}, | |
1103 'org/chromium/android_webview/AwContentStatics', | |
1104 TestOptions()) | |
1105 # Ensure it raises without the import. | |
1106 self.assertRaises(SyntaxError, lambda: generate('')) | |
1107 | |
1108 # Ensure it's fine with the import. | |
1109 generate('import java.lang.Runnable;') | |
1110 | |
1111 def testSingleJNIAdditionalImport(self): | 1088 def testSingleJNIAdditionalImport(self): |
1112 test_data = """ | 1089 test_data = """ |
1113 package org.chromium.foo; | 1090 package org.chromium.foo; |
1114 | 1091 |
1115 @JNIAdditionalImport(Bar.class) | 1092 @JNIAdditionalImport(Bar.class) |
1116 class Foo { | 1093 class Foo { |
1117 | 1094 |
1118 @CalledByNative | 1095 @CalledByNative |
1119 private static void calledByNative(Bar.Callback callback) { | 1096 private static void calledByNative(Bar.Callback callback) { |
1120 } | 1097 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 test_result = unittest.main(argv=argv[0:1], exit=False) | 1143 test_result = unittest.main(argv=argv[0:1], exit=False) |
1167 | 1144 |
1168 if test_result.result.wasSuccessful() and options.stamp: | 1145 if test_result.result.wasSuccessful() and options.stamp: |
1169 TouchStamp(options.stamp) | 1146 TouchStamp(options.stamp) |
1170 | 1147 |
1171 return not test_result.result.wasSuccessful() | 1148 return not test_result.result.wasSuccessful() |
1172 | 1149 |
1173 | 1150 |
1174 if __name__ == '__main__': | 1151 if __name__ == '__main__': |
1175 sys.exit(main(sys.argv)) | 1152 sys.exit(main(sys.argv)) |
OLD | NEW |