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 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 jni_generator.JNIFromJavaSource( | 1026 jni_generator.JNIFromJavaSource( |
1027 test_data % {'IMPORT': import_clause}, | 1027 test_data % {'IMPORT': import_clause}, |
1028 'org/chromium/android_webview/AwContentStatics', | 1028 'org/chromium/android_webview/AwContentStatics', |
1029 TestOptions()) | 1029 TestOptions()) |
1030 # Ensure it raises without the import. | 1030 # Ensure it raises without the import. |
1031 self.assertRaises(SyntaxError, lambda: generate('')) | 1031 self.assertRaises(SyntaxError, lambda: generate('')) |
1032 | 1032 |
1033 # Ensure it's fine with the import. | 1033 # Ensure it's fine with the import. |
1034 generate('import java.lang.Runnable;') | 1034 generate('import java.lang.Runnable;') |
1035 | 1035 |
| 1036 def testJNIAdditionalImport(self): |
| 1037 test_data = """ |
| 1038 package org.chromium.foo; |
| 1039 |
| 1040 @JNIAdditionalImport(Bar.class) |
| 1041 class Foo { |
| 1042 |
| 1043 @CalledByNative |
| 1044 private static void calledByNative(Bar.Callback callback) { |
| 1045 } |
| 1046 |
| 1047 private static native void nativeDoSomething(Bar.Callback callback); |
| 1048 } |
| 1049 """ |
| 1050 jni_from_java = jni_generator.JNIFromJavaSource(test_data, |
| 1051 'org/chromium/foo/Foo', |
| 1052 TestOptions()) |
| 1053 self.assertGoldenTextEquals(jni_from_java.GetContent()) |
| 1054 |
1036 | 1055 |
1037 if __name__ == '__main__': | 1056 if __name__ == '__main__': |
1038 unittest.main() | 1057 unittest.main() |
OLD | NEW |