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 22 matching lines...) Expand all Loading... | |
33 """The mock options object which is passed to the jni_generator.py script.""" | 33 """The mock options object which is passed to the jni_generator.py script.""" |
34 | 34 |
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' | |
44 self.javap = 'javap' | |
43 | 45 |
44 | 46 |
45 class TestGenerator(unittest.TestCase): | 47 class TestGenerator(unittest.TestCase): |
46 def assertObjEquals(self, first, second): | 48 def assertObjEquals(self, first, second): |
47 dict_first = first.__dict__ | 49 dict_first = first.__dict__ |
48 dict_second = second.__dict__ | 50 dict_second = second.__dict__ |
49 self.assertEquals(dict_first.keys(), dict_second.keys()) | 51 self.assertEquals(dict_first.keys(), dict_second.keys()) |
50 for key, value in dict_first.iteritems(): | 52 for key, value in dict_first.iteritems(): |
51 if (type(value) is list and len(value) and | 53 if (type(value) is list and len(value) and |
52 isinstance(type(value[0]), object)): | 54 isinstance(type(value[0]), object)): |
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
962 self.assertGoldenTextEquals(jni_from_java.GetContent()) | 964 self.assertGoldenTextEquals(jni_from_java.GetContent()) |
963 | 965 |
964 def testJNIInitNativeNameOption(self): | 966 def testJNIInitNativeNameOption(self): |
965 test_data = """ | 967 test_data = """ |
966 package org.chromium.example.jni_generator; | 968 package org.chromium.example.jni_generator; |
967 | 969 |
968 /** The pointer to the native Test. */ | 970 /** The pointer to the native Test. */ |
969 long nativeTest; | 971 long nativeTest; |
970 | 972 |
971 class Test { | 973 class Test { |
972 private static native boolean initNativeClass(); | 974 private static native boolean nativeInitNativeClass(); |
rmcilroy
2014/01/14 10:13:52
nit - nativeInitClass (for all)?
bulach
2014/01/16 11:03:49
the first "native" is stripped from the C++ counte
| |
973 private static native int nativeMethod(long nativeTest, int arg1); | 975 private static native int nativeMethod(long nativeTest, int arg1); |
974 } | 976 } |
975 """ | 977 """ |
976 options = TestOptions() | 978 options = TestOptions() |
977 options.jni_init_native_name = 'initNativeClass' | 979 options.jni_init_native_name = 'nativeInitNativeClass' |
978 jni_from_java = jni_generator.JNIFromJavaSource( | 980 jni_from_java = jni_generator.JNIFromJavaSource( |
979 test_data, 'org/chromium/example/jni_generator/Test', options) | 981 test_data, 'org/chromium/example/jni_generator/Test', options) |
980 self.assertGoldenTextEquals(jni_from_java.GetContent()) | 982 self.assertGoldenTextEquals(jni_from_java.GetContent()) |
981 | 983 |
982 def testEagerCalledByNativesOption(self): | 984 def testEagerCalledByNativesOption(self): |
983 test_data = """ | 985 test_data = """ |
984 package org.chromium.example.jni_generator; | 986 package org.chromium.example.jni_generator; |
985 | 987 |
986 /** The pointer to the native Test. */ | 988 /** The pointer to the native Test. */ |
987 long nativeTest; | 989 long nativeTest; |
988 | 990 |
989 class Test { | 991 class Test { |
990 private static native boolean initNativeClass(); | 992 private static native boolean nativeInitNativeClass(); |
991 private static native int nativeMethod(long nativeTest, int arg1); | 993 private static native int nativeMethod(long nativeTest, int arg1); |
992 @CalledByNative | 994 @CalledByNative |
993 private void testMethodWithParam(int iParam); | 995 private void testMethodWithParam(int iParam); |
994 @CalledByNative | 996 @CalledByNative |
995 private static int testStaticMethodWithParam(int iParam); | 997 private static int testStaticMethodWithParam(int iParam); |
996 @CalledByNative | 998 @CalledByNative |
997 private static double testMethodWithNoParam(); | 999 private static double testMethodWithNoParam(); |
998 @CalledByNative | 1000 @CalledByNative |
999 private static String testStaticMethodWithNoParam(); | 1001 private static String testStaticMethodWithNoParam(); |
1000 } | 1002 } |
1001 """ | 1003 """ |
1002 options = TestOptions() | 1004 options = TestOptions() |
1003 options.jni_init_native_name = 'initNativeClass' | 1005 options.jni_init_native_name = 'nativeInitNativeClass' |
1004 options.eager_called_by_natives = True | 1006 options.eager_called_by_natives = True |
1005 jni_from_java = jni_generator.JNIFromJavaSource( | 1007 jni_from_java = jni_generator.JNIFromJavaSource( |
1006 test_data, 'org/chromium/example/jni_generator/Test', options) | 1008 test_data, 'org/chromium/example/jni_generator/Test', options) |
1007 self.assertGoldenTextEquals(jni_from_java.GetContent()) | 1009 self.assertGoldenTextEquals(jni_from_java.GetContent()) |
1008 | 1010 |
1009 if __name__ == '__main__': | 1011 if __name__ == '__main__': |
1010 unittest.main() | 1012 unittest.main() |
OLD | NEW |