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

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

Issue 298973005: Updating JNIAdditionalImport to allow more than one import. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests Created 6 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 | 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 native int nativeFindAll(String find); 141 native int nativeFindAll(String find);
142 private static native OnFrameAvailableListener nativeGetInnerClass(); 142 private static native OnFrameAvailableListener nativeGetInnerClass();
143 private native Bitmap nativeQueryBitmap( 143 private native Bitmap nativeQueryBitmap(
144 int nativeChromeBrowserProvider, 144 int nativeChromeBrowserProvider,
145 String[] projection, String selection, 145 String[] projection, String selection,
146 String[] selectionArgs, String sortOrder); 146 String[] selectionArgs, String sortOrder);
147 private native void nativeGotOrientation( 147 private native void nativeGotOrientation(
148 int nativeDataFetcherImplAndroid, 148 int nativeDataFetcherImplAndroid,
149 double alpha, double beta, double gamma); 149 double alpha, double beta, double gamma);
150 """ 150 """
151 jni_generator.JniParams.SetFullyQualifiedClass(
152 'org/chromium/example/jni_generator/SampleForTests')
qsr 2014/05/23 08:11:38 This is necessary because this test was wrong -> t
151 jni_generator.JniParams.ExtractImportsAndInnerClasses(test_data) 153 jni_generator.JniParams.ExtractImportsAndInnerClasses(test_data)
152 natives = jni_generator.ExtractNatives(test_data, 'int') 154 natives = jni_generator.ExtractNatives(test_data, 'int')
153 golden_natives = [ 155 golden_natives = [
154 NativeMethod(return_type='int', static=False, 156 NativeMethod(return_type='int', static=False,
155 name='Init', 157 name='Init',
156 params=[], 158 params=[],
157 java_class_name=None, 159 java_class_name=None,
158 type='function'), 160 type='function'),
159 NativeMethod(return_type='void', static=False, name='Destroy', 161 NativeMethod(return_type='void', static=False, name='Destroy',
160 params=[Param(datatype='int', 162 params=[Param(datatype='int',
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 jni_generator.JNIFromJavaSource( 1028 jni_generator.JNIFromJavaSource(
1027 test_data % {'IMPORT': import_clause}, 1029 test_data % {'IMPORT': import_clause},
1028 'org/chromium/android_webview/AwContentStatics', 1030 'org/chromium/android_webview/AwContentStatics',
1029 TestOptions()) 1031 TestOptions())
1030 # Ensure it raises without the import. 1032 # Ensure it raises without the import.
1031 self.assertRaises(SyntaxError, lambda: generate('')) 1033 self.assertRaises(SyntaxError, lambda: generate(''))
1032 1034
1033 # Ensure it's fine with the import. 1035 # Ensure it's fine with the import.
1034 generate('import java.lang.Runnable;') 1036 generate('import java.lang.Runnable;')
1035 1037
1036 def testJNIAdditionalImport(self): 1038 def testSingleJNIAdditionalImport(self):
1037 test_data = """ 1039 test_data = """
1038 package org.chromium.foo; 1040 package org.chromium.foo;
1039 1041
1040 @JNIAdditionalImport(Bar.class) 1042 @JNIAdditionalImport(Bar.class)
1041 class Foo { 1043 class Foo {
1042 1044
1043 @CalledByNative 1045 @CalledByNative
1044 private static void calledByNative(Bar.Callback callback) { 1046 private static void calledByNative(Bar.Callback callback) {
1045 } 1047 }
1046 1048
1047 private static native void nativeDoSomething(Bar.Callback callback); 1049 private static native void nativeDoSomething(Bar.Callback callback);
1048 } 1050 }
1049 """ 1051 """
1050 jni_from_java = jni_generator.JNIFromJavaSource(test_data, 1052 jni_from_java = jni_generator.JNIFromJavaSource(test_data,
1051 'org/chromium/foo/Foo', 1053 'org/chromium/foo/Foo',
1052 TestOptions()) 1054 TestOptions())
1053 self.assertGoldenTextEquals(jni_from_java.GetContent()) 1055 self.assertGoldenTextEquals(jni_from_java.GetContent())
1054 1056
1057 def testMultipleJNIAdditionalImport(self):
1058 test_data = """
1059 package org.chromium.foo;
1060
1061 @JNIAdditionalImport({Bar1.class, Bar2.class})
1062 class Foo {
1063
1064 @CalledByNative
1065 private static void calledByNative(Bar1.Callback callback1,
1066 Bar2.Callback callback2) {
1067 }
1068
1069 private static native void nativeDoSomething(Bar1.Callback callback1,
1070 Bar2.Callback callback2);
1071 }
1072 """
1073 jni_from_java = jni_generator.JNIFromJavaSource(test_data,
1074 'org/chromium/foo/Foo',
1075 TestOptions())
1076 self.assertGoldenTextEquals(jni_from_java.GetContent())
1077
1055 1078
1056 if __name__ == '__main__': 1079 if __name__ == '__main__':
1057 unittest.main() 1080 unittest.main()
OLDNEW
« no previous file with comments | « base/android/jni_generator/jni_generator.py ('k') | base/android/jni_generator/testJNIAdditionalImport.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698