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 24 matching lines...) Expand all Loading... | |
| 35 def __init__(self): | 35 def __init__(self): |
| 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 | 45 self.native_exports = False |
| 46 | 46 |
| 47 class TestGenerator(unittest.TestCase): | 47 class TestGenerator(unittest.TestCase): |
| 48 def assertObjEquals(self, first, second): | 48 def assertObjEquals(self, first, second): |
| 49 dict_first = first.__dict__ | 49 dict_first = first.__dict__ |
| 50 dict_second = second.__dict__ | 50 dict_second = second.__dict__ |
| 51 self.assertEquals(dict_first.keys(), dict_second.keys()) | 51 self.assertEquals(dict_first.keys(), dict_second.keys()) |
| 52 for key, value in dict_first.iteritems(): | 52 for key, value in dict_first.iteritems(): |
| 53 if (type(value) is list and len(value) and | 53 if (type(value) is list and len(value) and |
| 54 isinstance(type(value[0]), object)): | 54 isinstance(type(value[0]), object)): |
| 55 self.assertListEquals(value, second.__getattribute__(key)) | 55 self.assertListEquals(value, second.__getattribute__(key)) |
| (...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 987 private static String testStaticMethodWithNoParam(); | 987 private static String testStaticMethodWithNoParam(); |
| 988 } | 988 } |
| 989 """ | 989 """ |
| 990 options = TestOptions() | 990 options = TestOptions() |
| 991 options.jni_init_native_name = 'nativeInitNativeClass' | 991 options.jni_init_native_name = 'nativeInitNativeClass' |
| 992 options.eager_called_by_natives = True | 992 options.eager_called_by_natives = True |
| 993 jni_from_java = jni_generator.JNIFromJavaSource( | 993 jni_from_java = jni_generator.JNIFromJavaSource( |
| 994 test_data, 'org/chromium/example/jni_generator/Test', options) | 994 test_data, 'org/chromium/example/jni_generator/Test', options) |
| 995 self.assertGoldenTextEquals(jni_from_java.GetContent()) | 995 self.assertGoldenTextEquals(jni_from_java.GetContent()) |
| 996 | 996 |
| 997 def testNativeExportsOption(self): | |
| 998 test_data = """ | |
| 999 package org.chromium.example.jni_generator; | |
| 1000 | |
| 1001 /** The pointer to the native Test. */ | |
| 1002 long nativeTest; | |
| 1003 | |
| 1004 class Test { | |
| 1005 private static native boolean nativeInitNativeClass(); | |
|
bulach
2014/04/16 11:22:35
as above, the stub for this class is not being gen
ostap
2014/04/16 20:36:04
Done.
| |
| 1006 private static native int nativeStaticMethod(long nativeTest, int arg1); | |
| 1007 private native int nativeMethod(long nativeTest, int arg1); | |
| 1008 @CalledByNative | |
| 1009 private void testMethodWithParam(int iParam); | |
| 1010 @CalledByNative | |
| 1011 private String testMethodWithParamAndReturn(int iParam); | |
| 1012 @CalledByNative | |
| 1013 private static int testStaticMethodWithParam(int iParam); | |
| 1014 @CalledByNative | |
| 1015 private static double testMethodWithNoParam(); | |
| 1016 @CalledByNative | |
| 1017 private static String testStaticMethodWithNoParam(); | |
| 1018 } | |
| 1019 """ | |
| 1020 options = TestOptions() | |
| 1021 options.jni_init_native_name = 'nativeInitNativeClass' | |
| 1022 options.native_exports = True | |
| 1023 jni_from_java = jni_generator.JNIFromJavaSource( | |
| 1024 test_data, 'org/chromium/example/jni_generator/SampleForTests', options) | |
| 1025 self.assertGoldenTextEquals(jni_from_java.GetContent()) | |
| 1026 | |
| 997 def testOuterInnerRaises(self): | 1027 def testOuterInnerRaises(self): |
| 998 test_data = """ | 1028 test_data = """ |
| 999 package org.chromium.media; | 1029 package org.chromium.media; |
| 1000 | 1030 |
| 1001 @CalledByNative | 1031 @CalledByNative |
| 1002 static int getCaptureFormatWidth(VideoCapture.CaptureFormat format) { | 1032 static int getCaptureFormatWidth(VideoCapture.CaptureFormat format) { |
| 1003 return format.getWidth(); | 1033 return format.getWidth(); |
| 1004 } | 1034 } |
| 1005 """ | 1035 """ |
| 1006 def willRaise(): | 1036 def willRaise(): |
| 1007 jni_generator.JNIFromJavaSource( | 1037 jni_generator.JNIFromJavaSource( |
| 1008 test_data, | 1038 test_data, |
| 1009 'org/chromium/media/VideoCaptureFactory', | 1039 'org/chromium/media/VideoCaptureFactory', |
| 1010 TestOptions()) | 1040 TestOptions()) |
| 1011 self.assertRaises(SyntaxError, willRaise) | 1041 self.assertRaises(SyntaxError, willRaise) |
| 1012 | 1042 |
| 1013 | 1043 |
| 1014 if __name__ == '__main__': | 1044 if __name__ == '__main__': |
| 1015 unittest.main() | 1045 unittest.main() |
| OLD | NEW |