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(); | |
| 1006 private static native int nativeMethod(long nativeTest, int arg1); | |
| 
 
bulach
2014/04/14 13:16:02
nit: how about adding a non-static method too?
 
ostap
2014/04/15 23:30:20
Done.
 
 | |
| 1007 @CalledByNative | |
| 1008 private void testMethodWithParam(int iParam); | |
| 1009 @CalledByNative | |
| 1010 private static int testStaticMethodWithParam(int iParam); | |
| 1011 @CalledByNative | |
| 1012 private static double testMethodWithNoParam(); | |
| 1013 @CalledByNative | |
| 1014 private static String testStaticMethodWithNoParam(); | |
| 1015 } | |
| 1016 """ | |
| 1017 options = TestOptions() | |
| 1018 options.jni_init_native_name = 'nativeInitNativeClass' | |
| 1019 options.native_exports = True | |
| 1020 jni_from_java = jni_generator.JNIFromJavaSource( | |
| 1021 test_data, 'org/chromium/example/jni_generator/Test', options) | |
| 1022 self.assertGoldenTextEquals(jni_from_java.GetContent()) | |
| 1023 | |
| 997 def testOuterInnerRaises(self): | 1024 def testOuterInnerRaises(self): | 
| 998 test_data = """ | 1025 test_data = """ | 
| 999 package org.chromium.media; | 1026 package org.chromium.media; | 
| 1000 | 1027 | 
| 1001 @CalledByNative | 1028 @CalledByNative | 
| 1002 static int getCaptureFormatWidth(VideoCapture.CaptureFormat format) { | 1029 static int getCaptureFormatWidth(VideoCapture.CaptureFormat format) { | 
| 1003 return format.getWidth(); | 1030 return format.getWidth(); | 
| 1004 } | 1031 } | 
| 1005 """ | 1032 """ | 
| 1006 def willRaise(): | 1033 def willRaise(): | 
| 1007 jni_generator.JNIFromJavaSource( | 1034 jni_generator.JNIFromJavaSource( | 
| 1008 test_data, | 1035 test_data, | 
| 1009 'org/chromium/media/VideoCaptureFactory', | 1036 'org/chromium/media/VideoCaptureFactory', | 
| 1010 TestOptions()) | 1037 TestOptions()) | 
| 1011 self.assertRaises(SyntaxError, willRaise) | 1038 self.assertRaises(SyntaxError, willRaise) | 
| 1012 | 1039 | 
| 1013 | 1040 | 
| 1014 if __name__ == '__main__': | 1041 if __name__ == '__main__': | 
| 1015 unittest.main() | 1042 unittest.main() | 
| OLD | NEW |