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

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

Issue 2162923002: jni_generator: Always generate native exports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 22 matching lines...) Expand all
33 class TestOptions(object): 33 class TestOptions(object):
34 """The mock options object which is passed to the jni_generator.py script.""" 34 """The mock options object which is passed to the jni_generator.py script."""
35 35
36 def __init__(self): 36 def __init__(self):
37 self.namespace = None 37 self.namespace = None
38 self.script_name = SCRIPT_NAME 38 self.script_name = SCRIPT_NAME
39 self.includes = INCLUDES 39 self.includes = INCLUDES
40 self.ptr_type = 'long' 40 self.ptr_type = 'long'
41 self.cpp = 'cpp' 41 self.cpp = 'cpp'
42 self.javap = 'javap' 42 self.javap = 'javap'
43 self.native_exports = False 43 self.native_exports_optional = True
44 self.native_exports_optional = False
45 44
46 class TestGenerator(unittest.TestCase): 45 class TestGenerator(unittest.TestCase):
47 def assertObjEquals(self, first, second): 46 def assertObjEquals(self, first, second):
48 dict_first = first.__dict__ 47 dict_first = first.__dict__
49 dict_second = second.__dict__ 48 dict_second = second.__dict__
50 self.assertEquals(dict_first.keys(), dict_second.keys()) 49 self.assertEquals(dict_first.keys(), dict_second.keys())
51 for key, value in dict_first.iteritems(): 50 for key, value in dict_first.iteritems():
52 if (type(value) is list and len(value) and 51 if (type(value) is list and len(value) and
53 isinstance(type(value[0]), object)): 52 isinstance(type(value[0]), object)):
54 self.assertListEquals(value, second.__getattribute__(key)) 53 self.assertListEquals(value, second.__getattribute__(key))
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 java_class_name=None, 927 java_class_name=None,
929 type='method', 928 type='method',
930 p0_type='ChromeBrowserProvider', 929 p0_type='ChromeBrowserProvider',
931 ptr_type=test_options.ptr_type), 930 ptr_type=test_options.ptr_type),
932 ] 931 ]
933 self.assertListEquals(golden_natives, natives) 932 self.assertListEquals(golden_natives, natives)
934 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', 933 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni',
935 natives, [], [], test_options) 934 natives, [], [], test_options)
936 self.assertGoldenTextEquals(h.GetContent()) 935 self.assertGoldenTextEquals(h.GetContent())
937 936
938 def runNativeExportsOption(self, optional): 937 def testNativeExportsOnlyOption(self):
939 test_data = """ 938 test_data = """
940 package org.chromium.example.jni_generator; 939 package org.chromium.example.jni_generator;
941 940
942 /** The pointer to the native Test. */ 941 /** The pointer to the native Test. */
943 long nativeTest; 942 long nativeTest;
944 943
945 class Test { 944 class Test {
946 private static native int nativeStaticMethod(long nativeTest, int arg1); 945 private static native int nativeStaticMethod(long nativeTest, int arg1);
947 private native int nativeMethod(long nativeTest, int arg1); 946 private native int nativeMethod(long nativeTest, int arg1);
948 @CalledByNative 947 @CalledByNative
(...skipping 11 matching lines...) Expand all
960 @NativeCall("MyInnerClass") 959 @NativeCall("MyInnerClass")
961 private native int nativeInit(); 960 private native int nativeInit();
962 } 961 }
963 class MyOtherInnerClass { 962 class MyOtherInnerClass {
964 @NativeCall("MyOtherInnerClass") 963 @NativeCall("MyOtherInnerClass")
965 private native int nativeInit(); 964 private native int nativeInit();
966 } 965 }
967 } 966 }
968 """ 967 """
969 options = TestOptions() 968 options = TestOptions()
970 options.native_exports = True 969 options.native_exports_optional = False
971 options.native_exports_optional = optional
972 jni_from_java = jni_generator.JNIFromJavaSource( 970 jni_from_java = jni_generator.JNIFromJavaSource(
973 test_data, 'org/chromium/example/jni_generator/SampleForTests', options) 971 test_data, 'org/chromium/example/jni_generator/SampleForTests', options)
974 return jni_from_java.GetContent() 972 self.assertGoldenTextEquals(jni_from_java.GetContent())
975
976 def testNativeExportsOption(self):
977 content = self.runNativeExportsOption(False)
978 self.assertGoldenTextEquals(content)
979
980 def testNativeExportsOptionalOption(self):
981 content = self.runNativeExportsOption(True)
982 self.assertGoldenTextEquals(content)
983 973
984 def testOuterInnerRaises(self): 974 def testOuterInnerRaises(self):
985 test_data = """ 975 test_data = """
986 package org.chromium.media; 976 package org.chromium.media;
987 977
988 @CalledByNative 978 @CalledByNative
989 static int getCaptureFormatWidth(VideoCapture.CaptureFormat format) { 979 static int getCaptureFormatWidth(VideoCapture.CaptureFormat format) {
990 return format.getWidth(); 980 return format.getWidth();
991 } 981 }
992 """ 982 """
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 test_result = unittest.main(argv=argv[0:1], exit=False) 1045 test_result = unittest.main(argv=argv[0:1], exit=False)
1056 1046
1057 if test_result.result.wasSuccessful() and options.stamp: 1047 if test_result.result.wasSuccessful() and options.stamp:
1058 TouchStamp(options.stamp) 1048 TouchStamp(options.stamp)
1059 1049
1060 return not test_result.result.wasSuccessful() 1050 return not test_result.result.wasSuccessful()
1061 1051
1062 1052
1063 if __name__ == '__main__': 1053 if __name__ == '__main__':
1064 sys.exit(main(sys.argv)) 1054 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « base/android/jni_generator/jni_generator.py ('k') | base/android/jni_generator/testCalledByNatives.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698