OLD | NEW |
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 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 public void mark(int); | 1168 public void mark(int); |
1169 public boolean markSupported(); | 1169 public boolean markSupported(); |
1170 public abstract int read() throws java.io.IOException; | 1170 public abstract int read() throws java.io.IOException; |
1171 public int read(byte[]) throws java.io.IOException; | 1171 public int read(byte[]) throws java.io.IOException; |
1172 public int read(byte[], int, int) throws java.io.IOException; | 1172 public int read(byte[], int, int) throws java.io.IOException; |
1173 public synchronized void reset() throws java.io.IOException; | 1173 public synchronized void reset() throws java.io.IOException; |
1174 public long skip(long) throws java.io.IOException; | 1174 public long skip(long) throws java.io.IOException; |
1175 } | 1175 } |
1176 """ | 1176 """ |
1177 jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), None) | 1177 jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), None) |
1178 self.assertEquals(9, len(jni_from_javap.called_by_natives)) | 1178 self.assertEquals(10, len(jni_from_javap.called_by_natives)) |
1179 golden_content = """\ | 1179 golden_content = """\ |
1180 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1180 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
1181 // Use of this source code is governed by a BSD-style license that can be | 1181 // Use of this source code is governed by a BSD-style license that can be |
1182 // found in the LICENSE file. | 1182 // found in the LICENSE file. |
1183 | 1183 |
1184 // This file is autogenerated by | 1184 // This file is autogenerated by |
1185 // base/android/jni_generator/jni_generator_tests.py | 1185 // base/android/jni_generator/jni_generator_tests.py |
1186 // For | 1186 // For |
1187 // java/io/InputStream | 1187 // java/io/InputStream |
1188 | 1188 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 /* Must call RegisterNativesImpl() */ | 1331 /* Must call RegisterNativesImpl() */ |
1332 DCHECK(g_InputStream_clazz); | 1332 DCHECK(g_InputStream_clazz); |
1333 DCHECK(g_InputStream_skip); | 1333 DCHECK(g_InputStream_skip); |
1334 jlong ret = | 1334 jlong ret = |
1335 env->CallLongMethod(obj, | 1335 env->CallLongMethod(obj, |
1336 g_InputStream_skip, p0); | 1336 g_InputStream_skip, p0); |
1337 base::android::CheckException(env); | 1337 base::android::CheckException(env); |
1338 return ret; | 1338 return ret; |
1339 } | 1339 } |
1340 | 1340 |
| 1341 static jmethodID g_InputStream_Constructor = 0; |
| 1342 static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env) { |
| 1343 /* Must call RegisterNativesImpl() */ |
| 1344 DCHECK(g_InputStream_clazz); |
| 1345 DCHECK(g_InputStream_Constructor); |
| 1346 jobject ret = |
| 1347 env->NewObject(g_InputStream_clazz, |
| 1348 g_InputStream_Constructor); |
| 1349 base::android::CheckException(env); |
| 1350 return ScopedJavaLocalRef<jobject>(env, ret); |
| 1351 } |
| 1352 |
1341 // Step 3: GetMethodIDs and RegisterNatives. | 1353 // Step 3: GetMethodIDs and RegisterNatives. |
1342 static void GetMethodIDsImpl(JNIEnv* env) { | 1354 static void GetMethodIDsImpl(JNIEnv* env) { |
1343 g_InputStream_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | 1355 g_InputStream_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
1344 base::android::GetUnscopedClass(env, kInputStreamClassPath))); | 1356 base::android::GetUnscopedClass(env, kInputStreamClassPath))); |
1345 g_InputStream_available = | 1357 g_InputStream_available = |
1346 base::android::GetMethodID( | 1358 base::android::GetMethodID( |
1347 env, g_InputStream_clazz, | 1359 env, g_InputStream_clazz, |
1348 "available", | 1360 "available", |
1349 | 1361 |
1350 "(" | 1362 "(" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 g_InputStream_skip = | 1434 g_InputStream_skip = |
1423 base::android::GetMethodID( | 1435 base::android::GetMethodID( |
1424 env, g_InputStream_clazz, | 1436 env, g_InputStream_clazz, |
1425 "skip", | 1437 "skip", |
1426 | 1438 |
1427 "(" | 1439 "(" |
1428 "J" | 1440 "J" |
1429 ")" | 1441 ")" |
1430 "J"); | 1442 "J"); |
1431 | 1443 |
| 1444 g_InputStream_Constructor = |
| 1445 base::android::GetMethodID( |
| 1446 env, g_InputStream_clazz, |
| 1447 "<init>", |
| 1448 |
| 1449 "(" |
| 1450 ")" |
| 1451 "V"); |
| 1452 |
1432 } | 1453 } |
1433 | 1454 |
1434 static bool RegisterNativesImpl(JNIEnv* env) { | 1455 static bool RegisterNativesImpl(JNIEnv* env) { |
1435 GetMethodIDsImpl(env); | 1456 GetMethodIDsImpl(env); |
1436 | 1457 |
1437 return true; | 1458 return true; |
1438 } | 1459 } |
1439 } // namespace JNI_InputStream | 1460 } // namespace JNI_InputStream |
1440 | 1461 |
1441 #endif // java_io_InputStream_JNI | 1462 #endif // java_io_InputStream_JNI |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1503 test_data, ('com/google/lookhowextremelylongiam/snarf/' | 1524 test_data, ('com/google/lookhowextremelylongiam/snarf/' |
1504 'icankeepthisupallday/ReallyLongClassNamesAreAllTheRage')) | 1525 'icankeepthisupallday/ReallyLongClassNamesAreAllTheRage')) |
1505 jni_lines = jni_from_java.GetContent().split('\n') | 1526 jni_lines = jni_from_java.GetContent().split('\n') |
1506 line = filter(lambda line: line.lstrip().startswith('#ifndef'), | 1527 line = filter(lambda line: line.lstrip().startswith('#ifndef'), |
1507 jni_lines)[0] | 1528 jni_lines)[0] |
1508 self.assertTrue(len(line) > 80, | 1529 self.assertTrue(len(line) > 80, |
1509 ('Expected #ifndef line to be > 80 chars: ', line)) | 1530 ('Expected #ifndef line to be > 80 chars: ', line)) |
1510 | 1531 |
1511 if __name__ == '__main__': | 1532 if __name__ == '__main__': |
1512 unittest.main() | 1533 unittest.main() |
OLD | NEW |