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

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

Issue 132013003: Android: moves jni_generator samples to use long for JNI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: With fixes Created 6 years, 11 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 | Annotate | Revision Log
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 REBASELINE_ENV = 'REBASELINE' 30 REBASELINE_ENV = 'REBASELINE'
31 31
32 class TestOptions(object): 32 class TestOptions(object):
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 = 'int' 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 43
44 44
45 class TestGenerator(unittest.TestCase): 45 class TestGenerator(unittest.TestCase):
46 def assertObjEquals(self, first, second): 46 def assertObjEquals(self, first, second):
47 dict_first = first.__dict__ 47 dict_first = first.__dict__
48 dict_second = second.__dict__ 48 dict_second = second.__dict__
49 self.assertEquals(dict_first.keys(), dict_second.keys()) 49 self.assertEquals(dict_first.keys(), dict_second.keys())
50 for key, value in dict_first.iteritems(): 50 for key, value in dict_first.iteritems():
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 self.assertListEquals(golden_natives, natives) 942 self.assertListEquals(golden_natives, natives)
943 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', 943 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni',
944 natives, [], test_options) 944 natives, [], test_options)
945 self.assertGoldenTextEquals(h.GetContent()) 945 self.assertGoldenTextEquals(h.GetContent())
946 946
947 def testPureNativeMethodsOption(self): 947 def testPureNativeMethodsOption(self):
948 test_data = """ 948 test_data = """
949 package org.chromium.example.jni_generator; 949 package org.chromium.example.jni_generator;
950 950
951 /** The pointer to the native Test. */ 951 /** The pointer to the native Test. */
952 int nativeTest; 952 long nativeTest;
953 953
954 class Test { 954 class Test {
955 private static native int nativeMethod(int nativeTest, int arg1); 955 private static native long nativeMethod(long nativeTest, int arg1);
956 } 956 }
957 """ 957 """
958 options = TestOptions() 958 options = TestOptions()
959 options.pure_native_methods = True 959 options.pure_native_methods = True
960 jni_from_java = jni_generator.JNIFromJavaSource( 960 jni_from_java = jni_generator.JNIFromJavaSource(
961 test_data, 'org/chromium/example/jni_generator/Test', options) 961 test_data, 'org/chromium/example/jni_generator/Test', options)
962 self.assertGoldenTextEquals(jni_from_java.GetContent()) 962 self.assertGoldenTextEquals(jni_from_java.GetContent())
963 963
964 def testJNIInitNativeNameOption(self): 964 def testJNIInitNativeNameOption(self):
965 test_data = """ 965 test_data = """
966 package org.chromium.example.jni_generator; 966 package org.chromium.example.jni_generator;
967 967
968 /** The pointer to the native Test. */ 968 /** The pointer to the native Test. */
969 int nativeTest; 969 long nativeTest;
970 970
971 class Test { 971 class Test {
972 private static native boolean initNativeClass(); 972 private static native boolean initNativeClass();
973 private static native int nativeMethod(int nativeTest, int arg1); 973 private static native int nativeMethod(long nativeTest, int arg1);
974 } 974 }
975 """ 975 """
976 options = TestOptions() 976 options = TestOptions()
977 options.jni_init_native_name = 'initNativeClass' 977 options.jni_init_native_name = 'initNativeClass'
978 jni_from_java = jni_generator.JNIFromJavaSource( 978 jni_from_java = jni_generator.JNIFromJavaSource(
979 test_data, 'org/chromium/example/jni_generator/Test', options) 979 test_data, 'org/chromium/example/jni_generator/Test', options)
980 self.assertGoldenTextEquals(jni_from_java.GetContent()) 980 self.assertGoldenTextEquals(jni_from_java.GetContent())
981 981
982 def testEagerCalledByNativesOption(self): 982 def testEagerCalledByNativesOption(self):
983 test_data = """ 983 test_data = """
984 package org.chromium.example.jni_generator; 984 package org.chromium.example.jni_generator;
985 985
986 /** The pointer to the native Test. */ 986 /** The pointer to the native Test. */
987 int nativeTest; 987 long nativeTest;
988 988
989 class Test { 989 class Test {
990 private static native boolean initNativeClass(); 990 private static native boolean initNativeClass();
991 private static native int nativeMethod(int nativeTest, int arg1); 991 private static native int nativeMethod(long nativeTest, int arg1);
992 @CalledByNative 992 @CalledByNative
993 private void testMethodWithParam(int iParam); 993 private void testMethodWithParam(int iParam);
994 @CalledByNative 994 @CalledByNative
995 private static int testStaticMethodWithParam(int iParam); 995 private static int testStaticMethodWithParam(int iParam);
996 @CalledByNative 996 @CalledByNative
997 private static double testMethodWithNoParam(); 997 private static double testMethodWithNoParam();
998 @CalledByNative 998 @CalledByNative
999 private static String testStaticMethodWithNoParam(); 999 private static String testStaticMethodWithNoParam();
1000 } 1000 }
1001 """ 1001 """
1002 options = TestOptions() 1002 options = TestOptions()
1003 options.jni_init_native_name = 'initNativeClass' 1003 options.jni_init_native_name = 'initNativeClass'
1004 options.eager_called_by_natives = True 1004 options.eager_called_by_natives = True
1005 jni_from_java = jni_generator.JNIFromJavaSource( 1005 jni_from_java = jni_generator.JNIFromJavaSource(
1006 test_data, 'org/chromium/example/jni_generator/Test', options) 1006 test_data, 'org/chromium/example/jni_generator/Test', options)
1007 self.assertGoldenTextEquals(jni_from_java.GetContent()) 1007 self.assertGoldenTextEquals(jni_from_java.GetContent())
1008 1008
1009 if __name__ == '__main__': 1009 if __name__ == '__main__':
1010 unittest.main() 1010 unittest.main()
OLDNEW
« no previous file with comments | « base/android/jni_generator/jni_generator.gyp ('k') | base/android/jni_generator/sample_for_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698