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

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

Issue 1959583003: jni_generator: remove obsolete/unused features. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Undo whitespace change to reduce diff to golden files Created 4 years, 7 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 19 matching lines...) Expand all
30 # files. 30 # files.
31 REBASELINE_ENV = 'REBASELINE' 31 REBASELINE_ENV = 'REBASELINE'
32 32
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.pure_native_methods = False
41 self.ptr_type = 'long' 40 self.ptr_type = 'long'
42 self.jni_init_native_name = None
43 self.eager_called_by_natives = False
44 self.cpp = 'cpp' 41 self.cpp = 'cpp'
45 self.javap = 'javap' 42 self.javap = 'javap'
46 self.native_exports = False 43 self.native_exports = False
47 self.native_exports_optional = False 44 self.native_exports_optional = False
48 45
49 class TestGenerator(unittest.TestCase): 46 class TestGenerator(unittest.TestCase):
50 def assertObjEquals(self, first, second): 47 def assertObjEquals(self, first, second):
51 dict_first = first.__dict__ 48 dict_first = first.__dict__
52 dict_second = second.__dict__ 49 dict_second = second.__dict__
53 self.assertEquals(dict_first.keys(), dict_second.keys()) 50 self.assertEquals(dict_first.keys(), dict_second.keys())
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 jni_from_java = jni_generator.JNIFromJavaSource( 843 jni_from_java = jni_generator.JNIFromJavaSource(
847 test_data, ('com/google/lookhowextremelylongiam/snarf/' 844 test_data, ('com/google/lookhowextremelylongiam/snarf/'
848 'icankeepthisupallday/ReallyLongClassNamesAreAllTheRage'), 845 'icankeepthisupallday/ReallyLongClassNamesAreAllTheRage'),
849 TestOptions()) 846 TestOptions())
850 jni_lines = jni_from_java.GetContent().split('\n') 847 jni_lines = jni_from_java.GetContent().split('\n')
851 line = filter(lambda line: line.lstrip().startswith('#ifndef'), 848 line = filter(lambda line: line.lstrip().startswith('#ifndef'),
852 jni_lines)[0] 849 jni_lines)[0]
853 self.assertTrue(len(line) > 80, 850 self.assertTrue(len(line) > 80,
854 ('Expected #ifndef line to be > 80 chars: ', line)) 851 ('Expected #ifndef line to be > 80 chars: ', line))
855 852
856 def testJarJarRemapping(self):
857 test_data = """
858 package org.chromium.example.jni_generator;
859
860 import org.chromium.example2.Test;
861
862 import org.chromium.example3.PrefixFoo;
863 import org.chromium.example3.Prefix;
864 import org.chromium.example3.Bar$Inner;
865
866 class Example {
867 private static native void nativeTest(Test t);
868 private static native void nativeTest2(PrefixFoo t);
869 private static native void nativeTest3(Prefix t);
870 private static native void nativeTest4(Bar$Inner t);
871 }
872 """
873 jni_generator.JniParams.SetJarJarMappings(
874 """rule org.chromium.example.** com.test.@1
875 rule org.chromium.example2.** org.test2.@1
876 rule org.chromium.example3.Prefix org.test3.Test
877 rule org.chromium.example3.Bar$** org.test3.TestBar$@1""")
878 jni_from_java = jni_generator.JNIFromJavaSource(
879 test_data, 'org/chromium/example/jni_generator/Example', TestOptions())
880 jni_generator.JniParams.SetJarJarMappings('')
881 self.assertGoldenTextEquals(jni_from_java.GetContent())
882
883 def testImports(self): 853 def testImports(self):
884 import_header = """ 854 import_header = """
885 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 855 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
886 // Use of this source code is governed by a BSD-style license that can be 856 // Use of this source code is governed by a BSD-style license that can be
887 // found in the LICENSE file. 857 // found in the LICENSE file.
888 858
889 package org.chromium.content.app; 859 package org.chromium.content.app;
890 860
891 import android.app.Service; 861 import android.app.Service;
892 import android.content.Context; 862 import android.content.Context;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 java_class_name=None, 928 java_class_name=None,
959 type='method', 929 type='method',
960 p0_type='ChromeBrowserProvider', 930 p0_type='ChromeBrowserProvider',
961 ptr_type=test_options.ptr_type), 931 ptr_type=test_options.ptr_type),
962 ] 932 ]
963 self.assertListEquals(golden_natives, natives) 933 self.assertListEquals(golden_natives, natives)
964 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', 934 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni',
965 natives, [], [], test_options) 935 natives, [], [], test_options)
966 self.assertGoldenTextEquals(h.GetContent()) 936 self.assertGoldenTextEquals(h.GetContent())
967 937
968 def testPureNativeMethodsOption(self):
969 test_data = """
970 package org.chromium.example.jni_generator;
971
972 /** The pointer to the native Test. */
973 long nativeTest;
974
975 class Test {
976 private static native long nativeMethod(long nativeTest, int arg1);
977 }
978 """
979 options = TestOptions()
980 options.pure_native_methods = True
981 jni_from_java = jni_generator.JNIFromJavaSource(
982 test_data, 'org/chromium/example/jni_generator/Test', options)
983 self.assertGoldenTextEquals(jni_from_java.GetContent())
984
985 def testJNIInitNativeNameOption(self):
986 test_data = """
987 package org.chromium.example.jni_generator;
988
989 /** The pointer to the native Test. */
990 long nativeTest;
991
992 class Test {
993 private static native boolean nativeInitNativeClass();
994 private static native int nativeMethod(long nativeTest, int arg1);
995 }
996 """
997 options = TestOptions()
998 options.jni_init_native_name = 'nativeInitNativeClass'
999 jni_from_java = jni_generator.JNIFromJavaSource(
1000 test_data, 'org/chromium/example/jni_generator/Test', options)
1001 self.assertGoldenTextEquals(jni_from_java.GetContent())
1002
1003 def testEagerCalledByNativesOption(self):
1004 test_data = """
1005 package org.chromium.example.jni_generator;
1006
1007 /** The pointer to the native Test. */
1008 long nativeTest;
1009
1010 class Test {
1011 private static native boolean nativeInitNativeClass();
1012 private static native int nativeMethod(long nativeTest, int arg1);
1013 @CalledByNative
1014 private void testMethodWithParam(int iParam);
1015 @CalledByNative
1016 private static int testStaticMethodWithParam(int iParam);
1017 @CalledByNative
1018 private static double testMethodWithNoParam();
1019 @CalledByNative
1020 private static String testStaticMethodWithNoParam();
1021 }
1022 """
1023 options = TestOptions()
1024 options.jni_init_native_name = 'nativeInitNativeClass'
1025 options.eager_called_by_natives = True
1026 jni_from_java = jni_generator.JNIFromJavaSource(
1027 test_data, 'org/chromium/example/jni_generator/Test', options)
1028 self.assertGoldenTextEquals(jni_from_java.GetContent())
1029
1030 def runNativeExportsOption(self, optional): 938 def runNativeExportsOption(self, optional):
1031 test_data = """ 939 test_data = """
1032 package org.chromium.example.jni_generator; 940 package org.chromium.example.jni_generator;
1033 941
1034 /** The pointer to the native Test. */ 942 /** The pointer to the native Test. */
1035 long nativeTest; 943 long nativeTest;
1036 944
1037 class Test { 945 class Test {
1038 private static native boolean nativeInitNativeClass();
1039 private static native int nativeStaticMethod(long nativeTest, int arg1); 946 private static native int nativeStaticMethod(long nativeTest, int arg1);
1040 private native int nativeMethod(long nativeTest, int arg1); 947 private native int nativeMethod(long nativeTest, int arg1);
1041 @CalledByNative 948 @CalledByNative
1042 private void testMethodWithParam(int iParam); 949 private void testMethodWithParam(int iParam);
1043 @CalledByNative 950 @CalledByNative
1044 private String testMethodWithParamAndReturn(int iParam); 951 private String testMethodWithParamAndReturn(int iParam);
1045 @CalledByNative 952 @CalledByNative
1046 private static int testStaticMethodWithParam(int iParam); 953 private static int testStaticMethodWithParam(int iParam);
1047 @CalledByNative 954 @CalledByNative
1048 private static double testMethodWithNoParam(); 955 private static double testMethodWithNoParam();
1049 @CalledByNative 956 @CalledByNative
1050 private static String testStaticMethodWithNoParam(); 957 private static String testStaticMethodWithNoParam();
1051 958
1052 class MyInnerClass { 959 class MyInnerClass {
1053 @NativeCall("MyInnerClass") 960 @NativeCall("MyInnerClass")
1054 private native int nativeInit(); 961 private native int nativeInit();
1055 } 962 }
1056 class MyOtherInnerClass { 963 class MyOtherInnerClass {
1057 @NativeCall("MyOtherInnerClass") 964 @NativeCall("MyOtherInnerClass")
1058 private native int nativeInit(); 965 private native int nativeInit();
1059 } 966 }
1060 } 967 }
1061 """ 968 """
1062 options = TestOptions() 969 options = TestOptions()
1063 options.jni_init_native_name = 'nativeInitNativeClass'
1064 options.native_exports = True 970 options.native_exports = True
1065 options.native_exports_optional = optional 971 options.native_exports_optional = optional
1066 jni_from_java = jni_generator.JNIFromJavaSource( 972 jni_from_java = jni_generator.JNIFromJavaSource(
1067 test_data, 'org/chromium/example/jni_generator/SampleForTests', options) 973 test_data, 'org/chromium/example/jni_generator/SampleForTests', options)
1068 return jni_from_java.GetContent() 974 return jni_from_java.GetContent()
1069 975
1070 def testNativeExportsOption(self): 976 def testNativeExportsOption(self):
1071 content = self.runNativeExportsOption(False) 977 content = self.runNativeExportsOption(False)
1072 self.assertGoldenTextEquals(content) 978 self.assertGoldenTextEquals(content)
1073 979
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 test_result = unittest.main(argv=argv[0:1], exit=False) 1055 test_result = unittest.main(argv=argv[0:1], exit=False)
1150 1056
1151 if test_result.result.wasSuccessful() and options.stamp: 1057 if test_result.result.wasSuccessful() and options.stamp:
1152 TouchStamp(options.stamp) 1058 TouchStamp(options.stamp)
1153 1059
1154 return not test_result.result.wasSuccessful() 1060 return not test_result.result.wasSuccessful()
1155 1061
1156 1062
1157 if __name__ == '__main__': 1063 if __name__ == '__main__':
1158 sys.exit(main(sys.argv)) 1064 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « base/android/jni_generator/jni_generator.py ('k') | base/android/jni_generator/testEagerCalledByNativesOption.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698