Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: base/android/jni_generator/jni_generator_tests.py

Issue 147533004: Remove unneeded JNI registrations. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Fix exports in non-JNI shared libs. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 private static String testStaticMethodWithNoParam(); 989 private static String testStaticMethodWithNoParam();
990 } 990 }
991 """ 991 """
992 options = TestOptions() 992 options = TestOptions()
993 options.jni_init_native_name = 'nativeInitNativeClass' 993 options.jni_init_native_name = 'nativeInitNativeClass'
994 options.eager_called_by_natives = True 994 options.eager_called_by_natives = True
995 jni_from_java = jni_generator.JNIFromJavaSource( 995 jni_from_java = jni_generator.JNIFromJavaSource(
996 test_data, 'org/chromium/example/jni_generator/Test', options) 996 test_data, 'org/chromium/example/jni_generator/Test', options)
997 self.assertGoldenTextEquals(jni_from_java.GetContent()) 997 self.assertGoldenTextEquals(jni_from_java.GetContent())
998 998
999 def testNativeExportsOption(self):
1000 test_data = """
1001 package org.chromium.example.jni_generator;
1002
1003 /** The pointer to the native Test. */
1004 long nativeTest;
1005
1006 class Test {
1007 private static native boolean nativeInitNativeClass();
1008 private static native int nativeStaticMethod(long nativeTest, int arg1);
1009 private native int nativeMethod(long nativeTest, int arg1);
1010 @CalledByNative
1011 private void testMethodWithParam(int iParam);
1012 @CalledByNative
1013 private String testMethodWithParamAndReturn(int iParam);
1014 @CalledByNative
1015 private static int testStaticMethodWithParam(int iParam);
1016 @CalledByNative
1017 private static double testMethodWithNoParam();
1018 @CalledByNative
1019 private static String testStaticMethodWithNoParam();
1020
1021 class MyInnerClass {
1022 @NativeCall("MyInnerClass")
1023 private native int nativeInit();
1024 }
1025 class MyOtherInnerClass {
1026 @NativeCall("MyOtherInnerClass")
1027 private native int nativeInit();
1028 }
1029 }
1030 """
1031 options = TestOptions()
1032 options.jni_init_native_name = 'nativeInitNativeClass'
1033 options.native_exports = True
1034 jni_from_java = jni_generator.JNIFromJavaSource(
1035 test_data, 'org/chromium/example/jni_generator/SampleForTests', options)
1036 self.assertGoldenTextEquals(jni_from_java.GetContent())
1037
999 def testOuterInnerRaises(self): 1038 def testOuterInnerRaises(self):
1000 test_data = """ 1039 test_data = """
1001 package org.chromium.media; 1040 package org.chromium.media;
1002 1041
1003 @CalledByNative 1042 @CalledByNative
1004 static int getCaptureFormatWidth(VideoCapture.CaptureFormat format) { 1043 static int getCaptureFormatWidth(VideoCapture.CaptureFormat format) {
1005 return format.getWidth(); 1044 return format.getWidth();
1006 } 1045 }
1007 """ 1046 """
1008 def willRaise(): 1047 def willRaise():
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 } 1110 }
1072 """ 1111 """
1073 jni_from_java = jni_generator.JNIFromJavaSource(test_data, 1112 jni_from_java = jni_generator.JNIFromJavaSource(test_data,
1074 'org/chromium/foo/Foo', 1113 'org/chromium/foo/Foo',
1075 TestOptions()) 1114 TestOptions())
1076 self.assertGoldenTextEquals(jni_from_java.GetContent()) 1115 self.assertGoldenTextEquals(jni_from_java.GetContent())
1077 1116
1078 1117
1079 if __name__ == '__main__': 1118 if __name__ == '__main__':
1080 unittest.main() 1119 unittest.main()
OLDNEW
« no previous file with comments | « base/android/jni_generator/jni_generator.py ('k') | base/android/jni_generator/testNativeExportsOption.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698