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 |
11 file. | 11 file. |
12 """ | 12 """ |
13 | 13 |
14 import difflib | 14 import difflib |
| 15 import inspect |
15 import os | 16 import os |
16 import sys | 17 import sys |
17 import unittest | 18 import unittest |
18 import jni_generator | 19 import jni_generator |
19 from jni_generator import CalledByNative, JniParams, NativeMethod, Param | 20 from jni_generator import CalledByNative, JniParams, NativeMethod, Param |
20 | 21 |
21 | 22 |
22 SCRIPT_NAME = 'base/android/jni_generator/jni_generator.py' | 23 SCRIPT_NAME = 'base/android/jni_generator/jni_generator.py' |
23 | 24 |
24 | 25 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 stripped_golden = [l.strip() for l in golden_text.split('\n')] | 58 stripped_golden = [l.strip() for l in golden_text.split('\n')] |
58 stripped_generated = [l.strip() for l in generated_text.split('\n')] | 59 stripped_generated = [l.strip() for l in generated_text.split('\n')] |
59 if stripped_golden != stripped_generated: | 60 if stripped_golden != stripped_generated: |
60 print self.id() | 61 print self.id() |
61 for line in difflib.context_diff(stripped_golden, stripped_generated): | 62 for line in difflib.context_diff(stripped_golden, stripped_generated): |
62 print line | 63 print line |
63 print '\n\nGenerated' | 64 print '\n\nGenerated' |
64 print '=' * 80 | 65 print '=' * 80 |
65 print generated_text | 66 print generated_text |
66 print '=' * 80 | 67 print '=' * 80 |
67 self.fail('Golden text mismatch') | 68 print 'Run with:' |
| 69 print 'REBASELINE=1', sys.argv[0] |
| 70 print 'to regenerate the data files.' |
| 71 self.fail('Golden text mismatch.') |
| 72 |
| 73 def _ReadGoldenFile(self, golden_file): |
| 74 if not os.path.exists(golden_file): |
| 75 return None |
| 76 with file(golden_file, 'r') as f: |
| 77 return f.read() |
| 78 |
| 79 def assertGoldenTextEquals(self, generated_text): |
| 80 script_dir = os.path.dirname(sys.argv[0]) |
| 81 caller = inspect.stack()[1][3] |
| 82 golden_file = os.path.join(script_dir, caller + '.golden') |
| 83 golden_text = self._ReadGoldenFile(golden_file) |
| 84 if os.environ.get('REBASELINE'): |
| 85 if golden_text != generated_text: |
| 86 with file(golden_file, 'w') as f: |
| 87 f.write(generated_text) |
| 88 return |
| 89 self.assertTextEquals(golden_text, generated_text) |
68 | 90 |
69 def testNatives(self): | 91 def testNatives(self): |
70 test_data = """" | 92 test_data = """" |
71 interface OnFrameAvailableListener {} | 93 interface OnFrameAvailableListener {} |
72 private native int nativeInit(); | 94 private native int nativeInit(); |
73 private native void nativeDestroy(int nativeChromeBrowserProvider); | 95 private native void nativeDestroy(int nativeChromeBrowserProvider); |
74 private native long nativeAddBookmark( | 96 private native long nativeAddBookmark( |
75 int nativeChromeBrowserProvider, | 97 int nativeChromeBrowserProvider, |
76 String url, String title, boolean isFolder, long parentId); | 98 String url, String title, boolean isFolder, long parentId); |
77 private static native String nativeGetDomainAndRegistry(String url); | 99 private static native String nativeGetDomainAndRegistry(String url); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 Param(datatype='double', | 234 Param(datatype='double', |
213 name='gamma'), | 235 name='gamma'), |
214 ], | 236 ], |
215 java_class_name=None, | 237 java_class_name=None, |
216 type='method', | 238 type='method', |
217 p0_type='content::DataFetcherImplAndroid'), | 239 p0_type='content::DataFetcherImplAndroid'), |
218 ] | 240 ] |
219 self.assertListEquals(golden_natives, natives) | 241 self.assertListEquals(golden_natives, natives) |
220 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', | 242 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', |
221 natives, [], TestOptions()) | 243 natives, [], TestOptions()) |
222 golden_content = """\ | 244 self.assertGoldenTextEquals(h.GetContent()) |
223 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
224 // Use of this source code is governed by a BSD-style license that can be | |
225 // found in the LICENSE file. | |
226 | |
227 // This file is autogenerated by | |
228 // base/android/jni_generator/jni_generator.py | |
229 // For | |
230 // org/chromium/TestJni | |
231 | |
232 #ifndef org_chromium_TestJni_JNI | |
233 #define org_chromium_TestJni_JNI | |
234 | |
235 #include <jni.h> | |
236 | |
237 #include "base/android/jni_android.h" | |
238 #include "base/android/scoped_java_ref.h" | |
239 #include "base/basictypes.h" | |
240 #include "base/logging.h" | |
241 | |
242 using base::android::ScopedJavaLocalRef; | |
243 | |
244 // Step 1: forward declarations. | |
245 namespace { | |
246 const char kTestJniClassPath[] = "org/chromium/TestJni"; | |
247 // Leaking this jclass as we cannot use LazyInstance from some threads. | |
248 jclass g_TestJni_clazz = NULL; | |
249 } // namespace | |
250 | |
251 static jint Init(JNIEnv* env, jobject obj); | |
252 | |
253 static jstring GetDomainAndRegistry(JNIEnv* env, jclass clazz, | |
254 jstring url); | |
255 | |
256 static void CreateHistoricalTabFromState(JNIEnv* env, jclass clazz, | |
257 jbyteArray state, | |
258 jint tab_index); | |
259 | |
260 static jbyteArray GetStateAsByteArray(JNIEnv* env, jobject obj, | |
261 jobject view); | |
262 | |
263 static jobjectArray GetAutofillProfileGUIDs(JNIEnv* env, jclass clazz); | |
264 | |
265 static void SetRecognitionResults(JNIEnv* env, jobject obj, | |
266 jint sessionId, | |
267 jobjectArray results); | |
268 | |
269 static jint FindAll(JNIEnv* env, jobject obj, | |
270 jstring find); | |
271 | |
272 static jobject GetInnerClass(JNIEnv* env, jclass clazz); | |
273 | |
274 // Step 2: method stubs. | |
275 static void Destroy(JNIEnv* env, jobject obj, | |
276 jint nativeChromeBrowserProvider) { | |
277 DCHECK(nativeChromeBrowserProvider) << "Destroy"; | |
278 ChromeBrowserProvider* native = | |
279 reinterpret_cast<ChromeBrowserProvider*>(nativeChromeBrowserProvider); | |
280 return native->Destroy(env, obj); | |
281 } | |
282 | |
283 static jlong AddBookmark(JNIEnv* env, jobject obj, | |
284 jint nativeChromeBrowserProvider, | |
285 jstring url, | |
286 jstring title, | |
287 jboolean isFolder, | |
288 jlong parentId) { | |
289 DCHECK(nativeChromeBrowserProvider) << "AddBookmark"; | |
290 ChromeBrowserProvider* native = | |
291 reinterpret_cast<ChromeBrowserProvider*>(nativeChromeBrowserProvider); | |
292 return native->AddBookmark(env, obj, url, title, isFolder, parentId); | |
293 } | |
294 | |
295 static jlong AddBookmarkFromAPI(JNIEnv* env, jobject obj, | |
296 jint nativeChromeBrowserProvider, | |
297 jstring url, | |
298 jobject created, | |
299 jobject isBookmark, | |
300 jobject date, | |
301 jbyteArray favicon, | |
302 jstring title, | |
303 jobject visits) { | |
304 DCHECK(nativeChromeBrowserProvider) << "AddBookmarkFromAPI"; | |
305 ChromeBrowserProvider* native = | |
306 reinterpret_cast<ChromeBrowserProvider*>(nativeChromeBrowserProvider); | |
307 return native->AddBookmarkFromAPI(env, obj, url, created, isBookmark, date, | |
308 favicon, title, visits); | |
309 } | |
310 | |
311 static jobject QueryBitmap(JNIEnv* env, jobject obj, | |
312 jint nativeChromeBrowserProvider, | |
313 jobjectArray projection, | |
314 jstring selection, | |
315 jobjectArray selectionArgs, | |
316 jstring sortOrder) { | |
317 DCHECK(nativeChromeBrowserProvider) << "QueryBitmap"; | |
318 ChromeBrowserProvider* native = | |
319 reinterpret_cast<ChromeBrowserProvider*>(nativeChromeBrowserProvider); | |
320 return native->QueryBitmap(env, obj, projection, selection, selectionArgs, | |
321 sortOrder).Release(); | |
322 } | |
323 | |
324 static void GotOrientation(JNIEnv* env, jobject obj, | |
325 jint nativeDataFetcherImplAndroid, | |
326 jdouble alpha, | |
327 jdouble beta, | |
328 jdouble gamma) { | |
329 DCHECK(nativeDataFetcherImplAndroid) << "GotOrientation"; | |
330 DataFetcherImplAndroid* native = | |
331 reinterpret_cast<DataFetcherImplAndroid*>(nativeDataFetcherImplAndroid); | |
332 return native->GotOrientation(env, obj, alpha, beta, gamma); | |
333 } | |
334 | |
335 // Step 3: RegisterNatives. | |
336 | |
337 static bool RegisterNativesImpl(JNIEnv* env) { | |
338 | |
339 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
340 base::android::GetClass(env, kTestJniClassPath).obj())); | |
341 static const JNINativeMethod kMethodsTestJni[] = { | |
342 { "nativeInit", | |
343 "(" | |
344 ")" | |
345 "I", reinterpret_cast<void*>(Init) }, | |
346 { "nativeDestroy", | |
347 "(" | |
348 "I" | |
349 ")" | |
350 "V", reinterpret_cast<void*>(Destroy) }, | |
351 { "nativeAddBookmark", | |
352 "(" | |
353 "I" | |
354 "Ljava/lang/String;" | |
355 "Ljava/lang/String;" | |
356 "Z" | |
357 "J" | |
358 ")" | |
359 "J", reinterpret_cast<void*>(AddBookmark) }, | |
360 { "nativeGetDomainAndRegistry", | |
361 "(" | |
362 "Ljava/lang/String;" | |
363 ")" | |
364 "Ljava/lang/String;", reinterpret_cast<void*>(GetDomainAndRegistry) }, | |
365 { "nativeCreateHistoricalTabFromState", | |
366 "(" | |
367 "[B" | |
368 "I" | |
369 ")" | |
370 "V", reinterpret_cast<void*>(CreateHistoricalTabFromState) }, | |
371 { "nativeGetStateAsByteArray", | |
372 "(" | |
373 "Landroid/view/View;" | |
374 ")" | |
375 "[B", reinterpret_cast<void*>(GetStateAsByteArray) }, | |
376 { "nativeGetAutofillProfileGUIDs", | |
377 "(" | |
378 ")" | |
379 "[Ljava/lang/String;", reinterpret_cast<void*>(GetAutofillProfileGUIDs) }, | |
380 { "nativeSetRecognitionResults", | |
381 "(" | |
382 "I" | |
383 "[Ljava/lang/String;" | |
384 ")" | |
385 "V", reinterpret_cast<void*>(SetRecognitionResults) }, | |
386 { "nativeAddBookmarkFromAPI", | |
387 "(" | |
388 "I" | |
389 "Ljava/lang/String;" | |
390 "Ljava/lang/Long;" | |
391 "Ljava/lang/Boolean;" | |
392 "Ljava/lang/Long;" | |
393 "[B" | |
394 "Ljava/lang/String;" | |
395 "Ljava/lang/Integer;" | |
396 ")" | |
397 "J", reinterpret_cast<void*>(AddBookmarkFromAPI) }, | |
398 { "nativeFindAll", | |
399 "(" | |
400 "Ljava/lang/String;" | |
401 ")" | |
402 "I", reinterpret_cast<void*>(FindAll) }, | |
403 { "nativeGetInnerClass", | |
404 "(" | |
405 ")" | |
406 "Lorg/chromium/example/jni_generator/SampleForTests$OnFrameAvailableListener;", | |
407 reinterpret_cast<void*>(GetInnerClass) }, | |
408 { "nativeQueryBitmap", | |
409 "(" | |
410 "I" | |
411 "[Ljava/lang/String;" | |
412 "Ljava/lang/String;" | |
413 "[Ljava/lang/String;" | |
414 "Ljava/lang/String;" | |
415 ")" | |
416 "Landroid/graphics/Bitmap;", reinterpret_cast<void*>(QueryBitmap) }, | |
417 { "nativeGotOrientation", | |
418 "(" | |
419 "I" | |
420 "D" | |
421 "D" | |
422 "D" | |
423 ")" | |
424 "V", reinterpret_cast<void*>(GotOrientation) }, | |
425 }; | |
426 const int kMethodsTestJniSize = arraysize(kMethodsTestJni); | |
427 | |
428 if (env->RegisterNatives(g_TestJni_clazz, | |
429 kMethodsTestJni, | |
430 kMethodsTestJniSize) < 0) { | |
431 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | |
432 return false; | |
433 } | |
434 | |
435 return true; | |
436 } | |
437 | |
438 #endif // org_chromium_TestJni_JNI | |
439 """ | |
440 self.assertTextEquals(golden_content, h.GetContent()) | |
441 | 245 |
442 def testInnerClassNatives(self): | 246 def testInnerClassNatives(self): |
443 test_data = """ | 247 test_data = """ |
444 class MyInnerClass { | 248 class MyInnerClass { |
445 @NativeCall("MyInnerClass") | 249 @NativeCall("MyInnerClass") |
446 private native int nativeInit(); | 250 private native int nativeInit(); |
447 } | 251 } |
448 """ | 252 """ |
449 natives = jni_generator.ExtractNatives(test_data, 'int') | 253 natives = jni_generator.ExtractNatives(test_data, 'int') |
450 golden_natives = [ | 254 golden_natives = [ |
451 NativeMethod(return_type='int', static=False, | 255 NativeMethod(return_type='int', static=False, |
452 name='Init', params=[], | 256 name='Init', params=[], |
453 java_class_name='MyInnerClass', | 257 java_class_name='MyInnerClass', |
454 type='function') | 258 type='function') |
455 ] | 259 ] |
456 self.assertListEquals(golden_natives, natives) | 260 self.assertListEquals(golden_natives, natives) |
457 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', | 261 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', |
458 natives, [], TestOptions()) | 262 natives, [], TestOptions()) |
459 golden_content = """\ | 263 self.assertGoldenTextEquals(h.GetContent()) |
460 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
461 // Use of this source code is governed by a BSD-style license that can be | |
462 // found in the LICENSE file. | |
463 | |
464 // This file is autogenerated by | |
465 // base/android/jni_generator/jni_generator.py | |
466 // For | |
467 // org/chromium/TestJni | |
468 | |
469 #ifndef org_chromium_TestJni_JNI | |
470 #define org_chromium_TestJni_JNI | |
471 | |
472 #include <jni.h> | |
473 | |
474 #include "base/android/jni_android.h" | |
475 #include "base/android/scoped_java_ref.h" | |
476 #include "base/basictypes.h" | |
477 #include "base/logging.h" | |
478 | |
479 using base::android::ScopedJavaLocalRef; | |
480 | |
481 // Step 1: forward declarations. | |
482 namespace { | |
483 const char kTestJniClassPath[] = "org/chromium/TestJni"; | |
484 const char kMyInnerClassClassPath[] = "org/chromium/TestJni$MyInnerClass"; | |
485 // Leaking this jclass as we cannot use LazyInstance from some threads. | |
486 jclass g_TestJni_clazz = NULL; | |
487 } // namespace | |
488 | |
489 static jint Init(JNIEnv* env, jobject obj); | |
490 | |
491 // Step 2: method stubs. | |
492 | |
493 // Step 3: RegisterNatives. | |
494 | |
495 static bool RegisterNativesImpl(JNIEnv* env) { | |
496 | |
497 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
498 base::android::GetClass(env, kTestJniClassPath).obj())); | |
499 static const JNINativeMethod kMethodsMyInnerClass[] = { | |
500 { "nativeInit", | |
501 "(" | |
502 ")" | |
503 "I", reinterpret_cast<void*>(Init) }, | |
504 }; | |
505 const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass); | |
506 | |
507 if (env->RegisterNatives(g_MyInnerClass_clazz, | |
508 kMethodsMyInnerClass, | |
509 kMethodsMyInnerClassSize) < 0) { | |
510 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | |
511 return false; | |
512 } | |
513 | |
514 return true; | |
515 } | |
516 | |
517 #endif // org_chromium_TestJni_JNI | |
518 """ | |
519 self.assertTextEquals(golden_content, h.GetContent()) | |
520 | 264 |
521 def testInnerClassNativesMultiple(self): | 265 def testInnerClassNativesMultiple(self): |
522 test_data = """ | 266 test_data = """ |
523 class MyInnerClass { | 267 class MyInnerClass { |
524 @NativeCall("MyInnerClass") | 268 @NativeCall("MyInnerClass") |
525 private native int nativeInit(); | 269 private native int nativeInit(); |
526 } | 270 } |
527 class MyOtherInnerClass { | 271 class MyOtherInnerClass { |
528 @NativeCall("MyOtherInnerClass") | 272 @NativeCall("MyOtherInnerClass") |
529 private native int nativeInit(); | 273 private native int nativeInit(); |
530 } | 274 } |
531 """ | 275 """ |
532 natives = jni_generator.ExtractNatives(test_data, 'int') | 276 natives = jni_generator.ExtractNatives(test_data, 'int') |
533 golden_natives = [ | 277 golden_natives = [ |
534 NativeMethod(return_type='int', static=False, | 278 NativeMethod(return_type='int', static=False, |
535 name='Init', params=[], | 279 name='Init', params=[], |
536 java_class_name='MyInnerClass', | 280 java_class_name='MyInnerClass', |
537 type='function'), | 281 type='function'), |
538 NativeMethod(return_type='int', static=False, | 282 NativeMethod(return_type='int', static=False, |
539 name='Init', params=[], | 283 name='Init', params=[], |
540 java_class_name='MyOtherInnerClass', | 284 java_class_name='MyOtherInnerClass', |
541 type='function') | 285 type='function') |
542 ] | 286 ] |
543 self.assertListEquals(golden_natives, natives) | 287 self.assertListEquals(golden_natives, natives) |
544 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', | 288 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', |
545 natives, [], TestOptions()) | 289 natives, [], TestOptions()) |
546 golden_content = """\ | 290 self.assertGoldenTextEquals(h.GetContent()) |
547 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
548 // Use of this source code is governed by a BSD-style license that can be | |
549 // found in the LICENSE file. | |
550 | |
551 // This file is autogenerated by | |
552 // base/android/jni_generator/jni_generator.py | |
553 // For | |
554 // org/chromium/TestJni | |
555 | |
556 #ifndef org_chromium_TestJni_JNI | |
557 #define org_chromium_TestJni_JNI | |
558 | |
559 #include <jni.h> | |
560 | |
561 #include "base/android/jni_android.h" | |
562 #include "base/android/scoped_java_ref.h" | |
563 #include "base/basictypes.h" | |
564 #include "base/logging.h" | |
565 | |
566 using base::android::ScopedJavaLocalRef; | |
567 | |
568 // Step 1: forward declarations. | |
569 namespace { | |
570 const char kMyOtherInnerClassClassPath[] = | |
571 "org/chromium/TestJni$MyOtherInnerClass"; | |
572 const char kTestJniClassPath[] = "org/chromium/TestJni"; | |
573 const char kMyInnerClassClassPath[] = "org/chromium/TestJni$MyInnerClass"; | |
574 // Leaking this jclass as we cannot use LazyInstance from some threads. | |
575 jclass g_TestJni_clazz = NULL; | |
576 } // namespace | |
577 | |
578 static jint Init(JNIEnv* env, jobject obj); | |
579 | |
580 static jint Init(JNIEnv* env, jobject obj); | |
581 | |
582 // Step 2: method stubs. | |
583 | |
584 // Step 3: RegisterNatives. | |
585 | |
586 static bool RegisterNativesImpl(JNIEnv* env) { | |
587 | |
588 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
589 base::android::GetClass(env, kTestJniClassPath).obj())); | |
590 static const JNINativeMethod kMethodsMyOtherInnerClass[] = { | |
591 { "nativeInit", | |
592 "(" | |
593 ")" | |
594 "I", reinterpret_cast<void*>(Init) }, | |
595 }; | |
596 const int kMethodsMyOtherInnerClassSize = | |
597 arraysize(kMethodsMyOtherInnerClass); | |
598 | |
599 if (env->RegisterNatives(g_MyOtherInnerClass_clazz, | |
600 kMethodsMyOtherInnerClass, | |
601 kMethodsMyOtherInnerClassSize) < 0) { | |
602 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | |
603 return false; | |
604 } | |
605 | |
606 static const JNINativeMethod kMethodsMyInnerClass[] = { | |
607 { "nativeInit", | |
608 "(" | |
609 ")" | |
610 "I", reinterpret_cast<void*>(Init) }, | |
611 }; | |
612 const int kMethodsMyInnerClassSize = arraysize(kMethodsMyInnerClass); | |
613 | |
614 if (env->RegisterNatives(g_MyInnerClass_clazz, | |
615 kMethodsMyInnerClass, | |
616 kMethodsMyInnerClassSize) < 0) { | |
617 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | |
618 return false; | |
619 } | |
620 | |
621 return true; | |
622 } | |
623 | |
624 #endif // org_chromium_TestJni_JNI | |
625 """ | |
626 self.assertTextEquals(golden_content, h.GetContent()) | |
627 | 291 |
628 def testInnerClassNativesBothInnerAndOuter(self): | 292 def testInnerClassNativesBothInnerAndOuter(self): |
629 test_data = """ | 293 test_data = """ |
630 class MyOuterClass { | 294 class MyOuterClass { |
631 private native int nativeInit(); | 295 private native int nativeInit(); |
632 class MyOtherInnerClass { | 296 class MyOtherInnerClass { |
633 @NativeCall("MyOtherInnerClass") | 297 @NativeCall("MyOtherInnerClass") |
634 private native int nativeInit(); | 298 private native int nativeInit(); |
635 } | 299 } |
636 } | 300 } |
637 """ | 301 """ |
638 natives = jni_generator.ExtractNatives(test_data, 'int') | 302 natives = jni_generator.ExtractNatives(test_data, 'int') |
639 golden_natives = [ | 303 golden_natives = [ |
640 NativeMethod(return_type='int', static=False, | 304 NativeMethod(return_type='int', static=False, |
641 name='Init', params=[], | 305 name='Init', params=[], |
642 java_class_name=None, | 306 java_class_name=None, |
643 type='function'), | 307 type='function'), |
644 NativeMethod(return_type='int', static=False, | 308 NativeMethod(return_type='int', static=False, |
645 name='Init', params=[], | 309 name='Init', params=[], |
646 java_class_name='MyOtherInnerClass', | 310 java_class_name='MyOtherInnerClass', |
647 type='function') | 311 type='function') |
648 ] | 312 ] |
649 self.assertListEquals(golden_natives, natives) | 313 self.assertListEquals(golden_natives, natives) |
650 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', | 314 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', |
651 natives, [], TestOptions()) | 315 natives, [], TestOptions()) |
652 golden_content = """\ | 316 self.assertGoldenTextEquals(h.GetContent()) |
653 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
654 // Use of this source code is governed by a BSD-style license that can be | |
655 // found in the LICENSE file. | |
656 | |
657 // This file is autogenerated by | |
658 // base/android/jni_generator/jni_generator.py | |
659 // For | |
660 // org/chromium/TestJni | |
661 | |
662 #ifndef org_chromium_TestJni_JNI | |
663 #define org_chromium_TestJni_JNI | |
664 | |
665 #include <jni.h> | |
666 | |
667 #include "base/android/jni_android.h" | |
668 #include "base/android/scoped_java_ref.h" | |
669 #include "base/basictypes.h" | |
670 #include "base/logging.h" | |
671 | |
672 using base::android::ScopedJavaLocalRef; | |
673 | |
674 // Step 1: forward declarations. | |
675 namespace { | |
676 const char kMyOtherInnerClassClassPath[] = | |
677 "org/chromium/TestJni$MyOtherInnerClass"; | |
678 const char kTestJniClassPath[] = "org/chromium/TestJni"; | |
679 // Leaking this jclass as we cannot use LazyInstance from some threads. | |
680 jclass g_TestJni_clazz = NULL; | |
681 } // namespace | |
682 | |
683 static jint Init(JNIEnv* env, jobject obj); | |
684 | |
685 static jint Init(JNIEnv* env, jobject obj); | |
686 | |
687 // Step 2: method stubs. | |
688 | |
689 // Step 3: RegisterNatives. | |
690 | |
691 static bool RegisterNativesImpl(JNIEnv* env) { | |
692 | |
693 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
694 base::android::GetClass(env, kTestJniClassPath).obj())); | |
695 static const JNINativeMethod kMethodsMyOtherInnerClass[] = { | |
696 { "nativeInit", | |
697 "(" | |
698 ")" | |
699 "I", reinterpret_cast<void*>(Init) }, | |
700 }; | |
701 const int kMethodsMyOtherInnerClassSize = | |
702 arraysize(kMethodsMyOtherInnerClass); | |
703 | |
704 if (env->RegisterNatives(g_MyOtherInnerClass_clazz, | |
705 kMethodsMyOtherInnerClass, | |
706 kMethodsMyOtherInnerClassSize) < 0) { | |
707 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | |
708 return false; | |
709 } | |
710 | |
711 static const JNINativeMethod kMethodsTestJni[] = { | |
712 { "nativeInit", | |
713 "(" | |
714 ")" | |
715 "I", reinterpret_cast<void*>(Init) }, | |
716 }; | |
717 const int kMethodsTestJniSize = arraysize(kMethodsTestJni); | |
718 | |
719 if (env->RegisterNatives(g_TestJni_clazz, | |
720 kMethodsTestJni, | |
721 kMethodsTestJniSize) < 0) { | |
722 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | |
723 return false; | |
724 } | |
725 | |
726 return true; | |
727 } | |
728 | |
729 #endif // org_chromium_TestJni_JNI | |
730 """ | |
731 self.assertTextEquals(golden_content, h.GetContent()) | |
732 | 317 |
733 def testCalledByNatives(self): | 318 def testCalledByNatives(self): |
734 test_data = """" | 319 test_data = """" |
735 import android.graphics.Bitmap; | 320 import android.graphics.Bitmap; |
736 import android.view.View; | 321 import android.view.View; |
737 import java.io.InputStream; | 322 import java.io.InputStream; |
738 import java.util.List; | 323 import java.util.List; |
739 | 324 |
740 class InnerClass {} | 325 class InnerClass {} |
741 | 326 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 java_class_name='', | 616 java_class_name='', |
1032 params=[], | 617 params=[], |
1033 env_call=('Void', ''), | 618 env_call=('Void', ''), |
1034 unchecked=False, | 619 unchecked=False, |
1035 ), | 620 ), |
1036 ] | 621 ] |
1037 self.assertListEquals(golden_called_by_natives, called_by_natives) | 622 self.assertListEquals(golden_called_by_natives, called_by_natives) |
1038 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', | 623 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', |
1039 [], called_by_natives, | 624 [], called_by_natives, |
1040 TestOptions()) | 625 TestOptions()) |
1041 golden_content = """\ | 626 self.assertGoldenTextEquals(h.GetContent()) |
1042 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
1043 // Use of this source code is governed by a BSD-style license that can be | |
1044 // found in the LICENSE file. | |
1045 | |
1046 // This file is autogenerated by | |
1047 // base/android/jni_generator/jni_generator.py | |
1048 // For | |
1049 // org/chromium/TestJni | |
1050 | |
1051 #ifndef org_chromium_TestJni_JNI | |
1052 #define org_chromium_TestJni_JNI | |
1053 | |
1054 #include <jni.h> | |
1055 | |
1056 #include "base/android/jni_android.h" | |
1057 #include "base/android/scoped_java_ref.h" | |
1058 #include "base/basictypes.h" | |
1059 #include "base/logging.h" | |
1060 | |
1061 using base::android::ScopedJavaLocalRef; | |
1062 | |
1063 // Step 1: forward declarations. | |
1064 namespace { | |
1065 const char kTestJniClassPath[] = "org/chromium/TestJni"; | |
1066 const char kInfoBarClassPath[] = "org/chromium/TestJni$InfoBar"; | |
1067 // Leaking this jclass as we cannot use LazyInstance from some threads. | |
1068 jclass g_TestJni_clazz = NULL; | |
1069 // Leaking this jclass as we cannot use LazyInstance from some threads. | |
1070 jclass g_InfoBar_clazz = NULL; | |
1071 } // namespace | |
1072 | |
1073 // Step 2: method stubs. | |
1074 | |
1075 static base::subtle::AtomicWord g_TestJni_showConfirmInfoBar = 0; | |
1076 static ScopedJavaLocalRef<jobject> Java_TestJni_showConfirmInfoBar(JNIEnv* env, | |
1077 jobject obj, jint nativeInfoBar, | |
1078 jstring buttonOk, | |
1079 jstring buttonCancel, | |
1080 jstring title, | |
1081 jobject icon) { | |
1082 /* Must call RegisterNativesImpl() */ | |
1083 DCHECK(g_TestJni_clazz); | |
1084 jmethodID method_id = | |
1085 base::android::MethodID::LazyGet< | |
1086 base::android::MethodID::TYPE_INSTANCE>( | |
1087 env, g_TestJni_clazz, | |
1088 "showConfirmInfoBar", | |
1089 | |
1090 "(" | |
1091 "I" | |
1092 "Ljava/lang/String;" | |
1093 "Ljava/lang/String;" | |
1094 "Ljava/lang/String;" | |
1095 "Landroid/graphics/Bitmap;" | |
1096 ")" | |
1097 "Lorg/chromium/Foo$InnerClass;", | |
1098 &g_TestJni_showConfirmInfoBar); | |
1099 | |
1100 jobject ret = | |
1101 env->CallObjectMethod(obj, | |
1102 method_id, nativeInfoBar, buttonOk, buttonCancel, title, icon); | |
1103 base::android::CheckException(env); | |
1104 return ScopedJavaLocalRef<jobject>(env, ret); | |
1105 } | |
1106 | |
1107 static base::subtle::AtomicWord g_TestJni_showAutoLoginInfoBar = 0; | |
1108 static ScopedJavaLocalRef<jobject> Java_TestJni_showAutoLoginInfoBar(JNIEnv* | |
1109 env, jobject obj, jint nativeInfoBar, | |
1110 jstring realm, | |
1111 jstring account, | |
1112 jstring args) { | |
1113 /* Must call RegisterNativesImpl() */ | |
1114 DCHECK(g_TestJni_clazz); | |
1115 jmethodID method_id = | |
1116 base::android::MethodID::LazyGet< | |
1117 base::android::MethodID::TYPE_INSTANCE>( | |
1118 env, g_TestJni_clazz, | |
1119 "showAutoLoginInfoBar", | |
1120 | |
1121 "(" | |
1122 "I" | |
1123 "Ljava/lang/String;" | |
1124 "Ljava/lang/String;" | |
1125 "Ljava/lang/String;" | |
1126 ")" | |
1127 "Lorg/chromium/Foo$InnerClass;", | |
1128 &g_TestJni_showAutoLoginInfoBar); | |
1129 | |
1130 jobject ret = | |
1131 env->CallObjectMethod(obj, | |
1132 method_id, nativeInfoBar, realm, account, args); | |
1133 base::android::CheckException(env); | |
1134 return ScopedJavaLocalRef<jobject>(env, ret); | |
1135 } | |
1136 | |
1137 static base::subtle::AtomicWord g_InfoBar_dismiss = 0; | |
1138 static void Java_InfoBar_dismiss(JNIEnv* env, jobject obj) { | |
1139 /* Must call RegisterNativesImpl() */ | |
1140 DCHECK(g_InfoBar_clazz); | |
1141 jmethodID method_id = | |
1142 base::android::MethodID::LazyGet< | |
1143 base::android::MethodID::TYPE_INSTANCE>( | |
1144 env, g_InfoBar_clazz, | |
1145 "dismiss", | |
1146 | |
1147 "(" | |
1148 ")" | |
1149 "V", | |
1150 &g_InfoBar_dismiss); | |
1151 | |
1152 env->CallVoidMethod(obj, | |
1153 method_id); | |
1154 base::android::CheckException(env); | |
1155 | |
1156 } | |
1157 | |
1158 static base::subtle::AtomicWord g_TestJni_shouldShowAutoLogin = 0; | |
1159 static jboolean Java_TestJni_shouldShowAutoLogin(JNIEnv* env, jobject view, | |
1160 jstring realm, | |
1161 jstring account, | |
1162 jstring args) { | |
1163 /* Must call RegisterNativesImpl() */ | |
1164 DCHECK(g_TestJni_clazz); | |
1165 jmethodID method_id = | |
1166 base::android::MethodID::LazyGet< | |
1167 base::android::MethodID::TYPE_STATIC>( | |
1168 env, g_TestJni_clazz, | |
1169 "shouldShowAutoLogin", | |
1170 | |
1171 "(" | |
1172 "Landroid/view/View;" | |
1173 "Ljava/lang/String;" | |
1174 "Ljava/lang/String;" | |
1175 "Ljava/lang/String;" | |
1176 ")" | |
1177 "Z", | |
1178 &g_TestJni_shouldShowAutoLogin); | |
1179 | |
1180 jboolean ret = | |
1181 env->CallStaticBooleanMethod(g_TestJni_clazz, | |
1182 method_id, view, realm, account, args); | |
1183 base::android::CheckException(env); | |
1184 return ret; | |
1185 } | |
1186 | |
1187 static base::subtle::AtomicWord g_TestJni_openUrl = 0; | |
1188 static ScopedJavaLocalRef<jobject> Java_TestJni_openUrl(JNIEnv* env, jstring | |
1189 url) { | |
1190 /* Must call RegisterNativesImpl() */ | |
1191 DCHECK(g_TestJni_clazz); | |
1192 jmethodID method_id = | |
1193 base::android::MethodID::LazyGet< | |
1194 base::android::MethodID::TYPE_STATIC>( | |
1195 env, g_TestJni_clazz, | |
1196 "openUrl", | |
1197 | |
1198 "(" | |
1199 "Ljava/lang/String;" | |
1200 ")" | |
1201 "Ljava/io/InputStream;", | |
1202 &g_TestJni_openUrl); | |
1203 | |
1204 jobject ret = | |
1205 env->CallStaticObjectMethod(g_TestJni_clazz, | |
1206 method_id, url); | |
1207 base::android::CheckException(env); | |
1208 return ScopedJavaLocalRef<jobject>(env, ret); | |
1209 } | |
1210 | |
1211 static base::subtle::AtomicWord g_TestJni_activateHardwareAcceleration = 0; | |
1212 static void Java_TestJni_activateHardwareAcceleration(JNIEnv* env, jobject obj, | |
1213 jboolean activated, | |
1214 jint iPid, | |
1215 jint iType, | |
1216 jint iPrimaryID, | |
1217 jint iSecondaryID) { | |
1218 /* Must call RegisterNativesImpl() */ | |
1219 DCHECK(g_TestJni_clazz); | |
1220 jmethodID method_id = | |
1221 base::android::MethodID::LazyGet< | |
1222 base::android::MethodID::TYPE_INSTANCE>( | |
1223 env, g_TestJni_clazz, | |
1224 "activateHardwareAcceleration", | |
1225 | |
1226 "(" | |
1227 "Z" | |
1228 "I" | |
1229 "I" | |
1230 "I" | |
1231 "I" | |
1232 ")" | |
1233 "V", | |
1234 &g_TestJni_activateHardwareAcceleration); | |
1235 | |
1236 env->CallVoidMethod(obj, | |
1237 method_id, activated, iPid, iType, iPrimaryID, iSecondaryID); | |
1238 base::android::CheckException(env); | |
1239 | |
1240 } | |
1241 | |
1242 static base::subtle::AtomicWord g_TestJni_uncheckedCall = 0; | |
1243 static void Java_TestJni_uncheckedCall(JNIEnv* env, jobject obj, jint iParam) { | |
1244 /* Must call RegisterNativesImpl() */ | |
1245 DCHECK(g_TestJni_clazz); | |
1246 jmethodID method_id = | |
1247 base::android::MethodID::LazyGet< | |
1248 base::android::MethodID::TYPE_INSTANCE>( | |
1249 env, g_TestJni_clazz, | |
1250 "uncheckedCall", | |
1251 | |
1252 "(" | |
1253 "I" | |
1254 ")" | |
1255 "V", | |
1256 &g_TestJni_uncheckedCall); | |
1257 | |
1258 env->CallVoidMethod(obj, | |
1259 method_id, iParam); | |
1260 | |
1261 } | |
1262 | |
1263 static base::subtle::AtomicWord g_TestJni_returnByteArray = 0; | |
1264 static ScopedJavaLocalRef<jbyteArray> Java_TestJni_returnByteArray(JNIEnv* env, | |
1265 jobject obj) { | |
1266 /* Must call RegisterNativesImpl() */ | |
1267 DCHECK(g_TestJni_clazz); | |
1268 jmethodID method_id = | |
1269 base::android::MethodID::LazyGet< | |
1270 base::android::MethodID::TYPE_INSTANCE>( | |
1271 env, g_TestJni_clazz, | |
1272 "returnByteArray", | |
1273 | |
1274 "(" | |
1275 ")" | |
1276 "[B", | |
1277 &g_TestJni_returnByteArray); | |
1278 | |
1279 jbyteArray ret = | |
1280 static_cast<jbyteArray>(env->CallObjectMethod(obj, | |
1281 method_id)); | |
1282 base::android::CheckException(env); | |
1283 return ScopedJavaLocalRef<jbyteArray>(env, ret); | |
1284 } | |
1285 | |
1286 static base::subtle::AtomicWord g_TestJni_returnBooleanArray = 0; | |
1287 static ScopedJavaLocalRef<jbooleanArray> Java_TestJni_returnBooleanArray(JNIEnv* | |
1288 env, jobject obj) { | |
1289 /* Must call RegisterNativesImpl() */ | |
1290 DCHECK(g_TestJni_clazz); | |
1291 jmethodID method_id = | |
1292 base::android::MethodID::LazyGet< | |
1293 base::android::MethodID::TYPE_INSTANCE>( | |
1294 env, g_TestJni_clazz, | |
1295 "returnBooleanArray", | |
1296 | |
1297 "(" | |
1298 ")" | |
1299 "[Z", | |
1300 &g_TestJni_returnBooleanArray); | |
1301 | |
1302 jbooleanArray ret = | |
1303 static_cast<jbooleanArray>(env->CallObjectMethod(obj, | |
1304 method_id)); | |
1305 base::android::CheckException(env); | |
1306 return ScopedJavaLocalRef<jbooleanArray>(env, ret); | |
1307 } | |
1308 | |
1309 static base::subtle::AtomicWord g_TestJni_returnCharArray = 0; | |
1310 static ScopedJavaLocalRef<jcharArray> Java_TestJni_returnCharArray(JNIEnv* env, | |
1311 jobject obj) { | |
1312 /* Must call RegisterNativesImpl() */ | |
1313 DCHECK(g_TestJni_clazz); | |
1314 jmethodID method_id = | |
1315 base::android::MethodID::LazyGet< | |
1316 base::android::MethodID::TYPE_INSTANCE>( | |
1317 env, g_TestJni_clazz, | |
1318 "returnCharArray", | |
1319 | |
1320 "(" | |
1321 ")" | |
1322 "[C", | |
1323 &g_TestJni_returnCharArray); | |
1324 | |
1325 jcharArray ret = | |
1326 static_cast<jcharArray>(env->CallObjectMethod(obj, | |
1327 method_id)); | |
1328 base::android::CheckException(env); | |
1329 return ScopedJavaLocalRef<jcharArray>(env, ret); | |
1330 } | |
1331 | |
1332 static base::subtle::AtomicWord g_TestJni_returnShortArray = 0; | |
1333 static ScopedJavaLocalRef<jshortArray> Java_TestJni_returnShortArray(JNIEnv* | |
1334 env, jobject obj) { | |
1335 /* Must call RegisterNativesImpl() */ | |
1336 DCHECK(g_TestJni_clazz); | |
1337 jmethodID method_id = | |
1338 base::android::MethodID::LazyGet< | |
1339 base::android::MethodID::TYPE_INSTANCE>( | |
1340 env, g_TestJni_clazz, | |
1341 "returnShortArray", | |
1342 | |
1343 "(" | |
1344 ")" | |
1345 "[S", | |
1346 &g_TestJni_returnShortArray); | |
1347 | |
1348 jshortArray ret = | |
1349 static_cast<jshortArray>(env->CallObjectMethod(obj, | |
1350 method_id)); | |
1351 base::android::CheckException(env); | |
1352 return ScopedJavaLocalRef<jshortArray>(env, ret); | |
1353 } | |
1354 | |
1355 static base::subtle::AtomicWord g_TestJni_returnIntArray = 0; | |
1356 static ScopedJavaLocalRef<jintArray> Java_TestJni_returnIntArray(JNIEnv* env, | |
1357 jobject obj) { | |
1358 /* Must call RegisterNativesImpl() */ | |
1359 DCHECK(g_TestJni_clazz); | |
1360 jmethodID method_id = | |
1361 base::android::MethodID::LazyGet< | |
1362 base::android::MethodID::TYPE_INSTANCE>( | |
1363 env, g_TestJni_clazz, | |
1364 "returnIntArray", | |
1365 | |
1366 "(" | |
1367 ")" | |
1368 "[I", | |
1369 &g_TestJni_returnIntArray); | |
1370 | |
1371 jintArray ret = | |
1372 static_cast<jintArray>(env->CallObjectMethod(obj, | |
1373 method_id)); | |
1374 base::android::CheckException(env); | |
1375 return ScopedJavaLocalRef<jintArray>(env, ret); | |
1376 } | |
1377 | |
1378 static base::subtle::AtomicWord g_TestJni_returnLongArray = 0; | |
1379 static ScopedJavaLocalRef<jlongArray> Java_TestJni_returnLongArray(JNIEnv* env, | |
1380 jobject obj) { | |
1381 /* Must call RegisterNativesImpl() */ | |
1382 DCHECK(g_TestJni_clazz); | |
1383 jmethodID method_id = | |
1384 base::android::MethodID::LazyGet< | |
1385 base::android::MethodID::TYPE_INSTANCE>( | |
1386 env, g_TestJni_clazz, | |
1387 "returnLongArray", | |
1388 | |
1389 "(" | |
1390 ")" | |
1391 "[J", | |
1392 &g_TestJni_returnLongArray); | |
1393 | |
1394 jlongArray ret = | |
1395 static_cast<jlongArray>(env->CallObjectMethod(obj, | |
1396 method_id)); | |
1397 base::android::CheckException(env); | |
1398 return ScopedJavaLocalRef<jlongArray>(env, ret); | |
1399 } | |
1400 | |
1401 static base::subtle::AtomicWord g_TestJni_returnDoubleArray = 0; | |
1402 static ScopedJavaLocalRef<jdoubleArray> Java_TestJni_returnDoubleArray(JNIEnv* | |
1403 env, jobject obj) { | |
1404 /* Must call RegisterNativesImpl() */ | |
1405 DCHECK(g_TestJni_clazz); | |
1406 jmethodID method_id = | |
1407 base::android::MethodID::LazyGet< | |
1408 base::android::MethodID::TYPE_INSTANCE>( | |
1409 env, g_TestJni_clazz, | |
1410 "returnDoubleArray", | |
1411 | |
1412 "(" | |
1413 ")" | |
1414 "[D", | |
1415 &g_TestJni_returnDoubleArray); | |
1416 | |
1417 jdoubleArray ret = | |
1418 static_cast<jdoubleArray>(env->CallObjectMethod(obj, | |
1419 method_id)); | |
1420 base::android::CheckException(env); | |
1421 return ScopedJavaLocalRef<jdoubleArray>(env, ret); | |
1422 } | |
1423 | |
1424 static base::subtle::AtomicWord g_TestJni_returnObjectArray = 0; | |
1425 static ScopedJavaLocalRef<jobjectArray> Java_TestJni_returnObjectArray(JNIEnv* | |
1426 env, jobject obj) { | |
1427 /* Must call RegisterNativesImpl() */ | |
1428 DCHECK(g_TestJni_clazz); | |
1429 jmethodID method_id = | |
1430 base::android::MethodID::LazyGet< | |
1431 base::android::MethodID::TYPE_INSTANCE>( | |
1432 env, g_TestJni_clazz, | |
1433 "returnObjectArray", | |
1434 | |
1435 "(" | |
1436 ")" | |
1437 "[Ljava/lang/Object;", | |
1438 &g_TestJni_returnObjectArray); | |
1439 | |
1440 jobjectArray ret = | |
1441 static_cast<jobjectArray>(env->CallObjectMethod(obj, | |
1442 method_id)); | |
1443 base::android::CheckException(env); | |
1444 return ScopedJavaLocalRef<jobjectArray>(env, ret); | |
1445 } | |
1446 | |
1447 static base::subtle::AtomicWord g_TestJni_returnArrayOfByteArray = 0; | |
1448 static ScopedJavaLocalRef<jobjectArray> | |
1449 Java_TestJni_returnArrayOfByteArray(JNIEnv* env, jobject obj) { | |
1450 /* Must call RegisterNativesImpl() */ | |
1451 DCHECK(g_TestJni_clazz); | |
1452 jmethodID method_id = | |
1453 base::android::MethodID::LazyGet< | |
1454 base::android::MethodID::TYPE_INSTANCE>( | |
1455 env, g_TestJni_clazz, | |
1456 "returnArrayOfByteArray", | |
1457 | |
1458 "(" | |
1459 ")" | |
1460 "[[B", | |
1461 &g_TestJni_returnArrayOfByteArray); | |
1462 | |
1463 jobjectArray ret = | |
1464 static_cast<jobjectArray>(env->CallObjectMethod(obj, | |
1465 method_id)); | |
1466 base::android::CheckException(env); | |
1467 return ScopedJavaLocalRef<jobjectArray>(env, ret); | |
1468 } | |
1469 | |
1470 static base::subtle::AtomicWord g_TestJni_getCompressFormat = 0; | |
1471 static ScopedJavaLocalRef<jobject> Java_TestJni_getCompressFormat(JNIEnv* env, | |
1472 jobject obj) { | |
1473 /* Must call RegisterNativesImpl() */ | |
1474 DCHECK(g_TestJni_clazz); | |
1475 jmethodID method_id = | |
1476 base::android::MethodID::LazyGet< | |
1477 base::android::MethodID::TYPE_INSTANCE>( | |
1478 env, g_TestJni_clazz, | |
1479 "getCompressFormat", | |
1480 | |
1481 "(" | |
1482 ")" | |
1483 "Landroid/graphics/Bitmap$CompressFormat;", | |
1484 &g_TestJni_getCompressFormat); | |
1485 | |
1486 jobject ret = | |
1487 env->CallObjectMethod(obj, | |
1488 method_id); | |
1489 base::android::CheckException(env); | |
1490 return ScopedJavaLocalRef<jobject>(env, ret); | |
1491 } | |
1492 | |
1493 static base::subtle::AtomicWord g_TestJni_getCompressFormatList = 0; | |
1494 static ScopedJavaLocalRef<jobject> Java_TestJni_getCompressFormatList(JNIEnv* | |
1495 env, jobject obj) { | |
1496 /* Must call RegisterNativesImpl() */ | |
1497 DCHECK(g_TestJni_clazz); | |
1498 jmethodID method_id = | |
1499 base::android::MethodID::LazyGet< | |
1500 base::android::MethodID::TYPE_INSTANCE>( | |
1501 env, g_TestJni_clazz, | |
1502 "getCompressFormatList", | |
1503 | |
1504 "(" | |
1505 ")" | |
1506 "Ljava/util/List;", | |
1507 &g_TestJni_getCompressFormatList); | |
1508 | |
1509 jobject ret = | |
1510 env->CallObjectMethod(obj, | |
1511 method_id); | |
1512 base::android::CheckException(env); | |
1513 return ScopedJavaLocalRef<jobject>(env, ret); | |
1514 } | |
1515 | |
1516 // Step 3: RegisterNatives. | |
1517 | |
1518 static bool RegisterNativesImpl(JNIEnv* env) { | |
1519 | |
1520 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
1521 base::android::GetClass(env, kTestJniClassPath).obj())); | |
1522 g_InfoBar_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
1523 base::android::GetClass(env, kInfoBarClassPath).obj())); | |
1524 return true; | |
1525 } | |
1526 | |
1527 #endif // org_chromium_TestJni_JNI | |
1528 """ | |
1529 self.assertTextEquals(golden_content, h.GetContent()) | |
1530 | 627 |
1531 def testCalledByNativeParseError(self): | 628 def testCalledByNativeParseError(self): |
1532 try: | 629 try: |
1533 jni_generator.ExtractCalledByNatives(""" | 630 jni_generator.ExtractCalledByNatives(""" |
1534 @CalledByNative | 631 @CalledByNative |
1535 public static int foo(); // This one is fine | 632 public static int foo(); // This one is fine |
1536 | 633 |
1537 @CalledByNative | 634 @CalledByNative |
1538 scooby doo | 635 scooby doo |
1539 """) | 636 """) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1583 contents = """ | 680 contents = """ |
1584 public abstract class java.util.HashSet<T> extends java.util.AbstractSet<E> | 681 public abstract class java.util.HashSet<T> extends java.util.AbstractSet<E> |
1585 implements java.util.Set<E>, java.lang.Cloneable, java.io.Serializable { | 682 implements java.util.Set<E>, java.lang.Cloneable, java.io.Serializable { |
1586 public void dummy(); | 683 public void dummy(); |
1587 Signature: ()V | 684 Signature: ()V |
1588 } | 685 } |
1589 """ | 686 """ |
1590 jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), | 687 jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), |
1591 TestOptions()) | 688 TestOptions()) |
1592 self.assertEquals(1, len(jni_from_javap.called_by_natives)) | 689 self.assertEquals(1, len(jni_from_javap.called_by_natives)) |
1593 golden_content = """\ | 690 self.assertGoldenTextEquals(jni_from_javap.GetContent()) |
1594 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
1595 // Use of this source code is governed by a BSD-style license that can be | |
1596 // found in the LICENSE file. | |
1597 | |
1598 // This file is autogenerated by | |
1599 // base/android/jni_generator/jni_generator.py | |
1600 // For | |
1601 // java/util/HashSet | |
1602 | |
1603 #ifndef java_util_HashSet_JNI | |
1604 #define java_util_HashSet_JNI | |
1605 | |
1606 #include <jni.h> | |
1607 | |
1608 #include "base/android/jni_android.h" | |
1609 #include "base/android/scoped_java_ref.h" | |
1610 #include "base/basictypes.h" | |
1611 #include "base/logging.h" | |
1612 | |
1613 using base::android::ScopedJavaLocalRef; | |
1614 | |
1615 // Step 1: forward declarations. | |
1616 namespace { | |
1617 const char kHashSetClassPath[] = "java/util/HashSet"; | |
1618 // Leaking this jclass as we cannot use LazyInstance from some threads. | |
1619 jclass g_HashSet_clazz = NULL; | |
1620 } // namespace | |
1621 | |
1622 namespace JNI_HashSet { | |
1623 | |
1624 // Step 2: method stubs. | |
1625 | |
1626 static base::subtle::AtomicWord g_HashSet_dummy = 0; | |
1627 static void Java_HashSet_dummy(JNIEnv* env, jobject obj) __attribute__ | |
1628 ((unused)); | |
1629 static void Java_HashSet_dummy(JNIEnv* env, jobject obj) { | |
1630 /* Must call RegisterNativesImpl() */ | |
1631 DCHECK(g_HashSet_clazz); | |
1632 jmethodID method_id = | |
1633 base::android::MethodID::LazyGet< | |
1634 base::android::MethodID::TYPE_INSTANCE>( | |
1635 env, g_HashSet_clazz, | |
1636 "dummy", | |
1637 "()V", | |
1638 &g_HashSet_dummy); | |
1639 | |
1640 env->CallVoidMethod(obj, | |
1641 method_id); | |
1642 base::android::CheckException(env); | |
1643 | |
1644 } | |
1645 | |
1646 // Step 3: RegisterNatives. | |
1647 | |
1648 static bool RegisterNativesImpl(JNIEnv* env) { | |
1649 | |
1650 g_HashSet_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
1651 base::android::GetClass(env, kHashSetClassPath).obj())); | |
1652 return true; | |
1653 } | |
1654 } // namespace JNI_HashSet | |
1655 | |
1656 #endif // java_util_HashSet_JNI | |
1657 """ | |
1658 self.assertTextEquals(golden_content, jni_from_javap.GetContent()) | |
1659 | 691 |
1660 def testSnippnetJavap6_7(self): | 692 def testSnippnetJavap6_7(self): |
1661 content_javap6 = """ | 693 content_javap6 = """ |
1662 public class java.util.HashSet { | 694 public class java.util.HashSet { |
1663 public boolean add(java.lang.Object); | 695 public boolean add(java.lang.Object); |
1664 Signature: (Ljava/lang/Object;)Z | 696 Signature: (Ljava/lang/Object;)Z |
1665 } | 697 } |
1666 """ | 698 """ |
1667 | 699 |
1668 content_javap7 = """ | 700 content_javap7 = """ |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1704 Signature: ([BII)I | 736 Signature: ([BII)I |
1705 public synchronized void reset() throws java.io.IOException; | 737 public synchronized void reset() throws java.io.IOException; |
1706 Signature: ()V | 738 Signature: ()V |
1707 public long skip(long) throws java.io.IOException; | 739 public long skip(long) throws java.io.IOException; |
1708 Signature: (J)J | 740 Signature: (J)J |
1709 } | 741 } |
1710 """ | 742 """ |
1711 jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), | 743 jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), |
1712 TestOptions()) | 744 TestOptions()) |
1713 self.assertEquals(10, len(jni_from_javap.called_by_natives)) | 745 self.assertEquals(10, len(jni_from_javap.called_by_natives)) |
1714 golden_content = """\ | 746 self.assertGoldenTextEquals(jni_from_javap.GetContent()) |
1715 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
1716 // Use of this source code is governed by a BSD-style license that can be | |
1717 // found in the LICENSE file. | |
1718 | |
1719 // This file is autogenerated by | |
1720 // base/android/jni_generator/jni_generator.py | |
1721 // For | |
1722 // java/io/InputStream | |
1723 | |
1724 #ifndef java_io_InputStream_JNI | |
1725 #define java_io_InputStream_JNI | |
1726 | |
1727 #include <jni.h> | |
1728 | |
1729 #include "base/android/jni_android.h" | |
1730 #include "base/android/scoped_java_ref.h" | |
1731 #include "base/basictypes.h" | |
1732 #include "base/logging.h" | |
1733 | |
1734 using base::android::ScopedJavaLocalRef; | |
1735 | |
1736 // Step 1: forward declarations. | |
1737 namespace { | |
1738 const char kInputStreamClassPath[] = "java/io/InputStream"; | |
1739 // Leaking this jclass as we cannot use LazyInstance from some threads. | |
1740 jclass g_InputStream_clazz = NULL; | |
1741 } // namespace | |
1742 | |
1743 namespace JNI_InputStream { | |
1744 | |
1745 // Step 2: method stubs. | |
1746 | |
1747 static base::subtle::AtomicWord g_InputStream_available = 0; | |
1748 static jint Java_InputStream_available(JNIEnv* env, jobject obj) __attribute__ | |
1749 ((unused)); | |
1750 static jint Java_InputStream_available(JNIEnv* env, jobject obj) { | |
1751 /* Must call RegisterNativesImpl() */ | |
1752 DCHECK(g_InputStream_clazz); | |
1753 jmethodID method_id = | |
1754 base::android::MethodID::LazyGet< | |
1755 base::android::MethodID::TYPE_INSTANCE>( | |
1756 env, g_InputStream_clazz, | |
1757 "available", | |
1758 "()I", | |
1759 &g_InputStream_available); | |
1760 | |
1761 jint ret = | |
1762 env->CallIntMethod(obj, | |
1763 method_id); | |
1764 base::android::CheckException(env); | |
1765 return ret; | |
1766 } | |
1767 | |
1768 static base::subtle::AtomicWord g_InputStream_close = 0; | |
1769 static void Java_InputStream_close(JNIEnv* env, jobject obj) __attribute__ | |
1770 ((unused)); | |
1771 static void Java_InputStream_close(JNIEnv* env, jobject obj) { | |
1772 /* Must call RegisterNativesImpl() */ | |
1773 DCHECK(g_InputStream_clazz); | |
1774 jmethodID method_id = | |
1775 base::android::MethodID::LazyGet< | |
1776 base::android::MethodID::TYPE_INSTANCE>( | |
1777 env, g_InputStream_clazz, | |
1778 "close", | |
1779 "()V", | |
1780 &g_InputStream_close); | |
1781 | |
1782 env->CallVoidMethod(obj, | |
1783 method_id); | |
1784 base::android::CheckException(env); | |
1785 | |
1786 } | |
1787 | |
1788 static base::subtle::AtomicWord g_InputStream_mark = 0; | |
1789 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) | |
1790 __attribute__ ((unused)); | |
1791 static void Java_InputStream_mark(JNIEnv* env, jobject obj, jint p0) { | |
1792 /* Must call RegisterNativesImpl() */ | |
1793 DCHECK(g_InputStream_clazz); | |
1794 jmethodID method_id = | |
1795 base::android::MethodID::LazyGet< | |
1796 base::android::MethodID::TYPE_INSTANCE>( | |
1797 env, g_InputStream_clazz, | |
1798 "mark", | |
1799 "(I)V", | |
1800 &g_InputStream_mark); | |
1801 | |
1802 env->CallVoidMethod(obj, | |
1803 method_id, p0); | |
1804 base::android::CheckException(env); | |
1805 | |
1806 } | |
1807 | |
1808 static base::subtle::AtomicWord g_InputStream_markSupported = 0; | |
1809 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) | |
1810 __attribute__ ((unused)); | |
1811 static jboolean Java_InputStream_markSupported(JNIEnv* env, jobject obj) { | |
1812 /* Must call RegisterNativesImpl() */ | |
1813 DCHECK(g_InputStream_clazz); | |
1814 jmethodID method_id = | |
1815 base::android::MethodID::LazyGet< | |
1816 base::android::MethodID::TYPE_INSTANCE>( | |
1817 env, g_InputStream_clazz, | |
1818 "markSupported", | |
1819 "()Z", | |
1820 &g_InputStream_markSupported); | |
1821 | |
1822 jboolean ret = | |
1823 env->CallBooleanMethod(obj, | |
1824 method_id); | |
1825 base::android::CheckException(env); | |
1826 return ret; | |
1827 } | |
1828 | |
1829 static base::subtle::AtomicWord g_InputStream_readI = 0; | |
1830 static jint Java_InputStream_readI(JNIEnv* env, jobject obj) __attribute__ | |
1831 ((unused)); | |
1832 static jint Java_InputStream_readI(JNIEnv* env, jobject obj) { | |
1833 /* Must call RegisterNativesImpl() */ | |
1834 DCHECK(g_InputStream_clazz); | |
1835 jmethodID method_id = | |
1836 base::android::MethodID::LazyGet< | |
1837 base::android::MethodID::TYPE_INSTANCE>( | |
1838 env, g_InputStream_clazz, | |
1839 "read", | |
1840 "()I", | |
1841 &g_InputStream_readI); | |
1842 | |
1843 jint ret = | |
1844 env->CallIntMethod(obj, | |
1845 method_id); | |
1846 base::android::CheckException(env); | |
1847 return ret; | |
1848 } | |
1849 | |
1850 static base::subtle::AtomicWord g_InputStream_readI_AB = 0; | |
1851 static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) | |
1852 __attribute__ ((unused)); | |
1853 static jint Java_InputStream_readI_AB(JNIEnv* env, jobject obj, jbyteArray p0) { | |
1854 /* Must call RegisterNativesImpl() */ | |
1855 DCHECK(g_InputStream_clazz); | |
1856 jmethodID method_id = | |
1857 base::android::MethodID::LazyGet< | |
1858 base::android::MethodID::TYPE_INSTANCE>( | |
1859 env, g_InputStream_clazz, | |
1860 "read", | |
1861 "([B)I", | |
1862 &g_InputStream_readI_AB); | |
1863 | |
1864 jint ret = | |
1865 env->CallIntMethod(obj, | |
1866 method_id, p0); | |
1867 base::android::CheckException(env); | |
1868 return ret; | |
1869 } | |
1870 | |
1871 static base::subtle::AtomicWord g_InputStream_readI_AB_I_I = 0; | |
1872 static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray | |
1873 p0, | |
1874 jint p1, | |
1875 jint p2) __attribute__ ((unused)); | |
1876 static jint Java_InputStream_readI_AB_I_I(JNIEnv* env, jobject obj, jbyteArray | |
1877 p0, | |
1878 jint p1, | |
1879 jint p2) { | |
1880 /* Must call RegisterNativesImpl() */ | |
1881 DCHECK(g_InputStream_clazz); | |
1882 jmethodID method_id = | |
1883 base::android::MethodID::LazyGet< | |
1884 base::android::MethodID::TYPE_INSTANCE>( | |
1885 env, g_InputStream_clazz, | |
1886 "read", | |
1887 "([BII)I", | |
1888 &g_InputStream_readI_AB_I_I); | |
1889 | |
1890 jint ret = | |
1891 env->CallIntMethod(obj, | |
1892 method_id, p0, p1, p2); | |
1893 base::android::CheckException(env); | |
1894 return ret; | |
1895 } | |
1896 | |
1897 static base::subtle::AtomicWord g_InputStream_reset = 0; | |
1898 static void Java_InputStream_reset(JNIEnv* env, jobject obj) __attribute__ | |
1899 ((unused)); | |
1900 static void Java_InputStream_reset(JNIEnv* env, jobject obj) { | |
1901 /* Must call RegisterNativesImpl() */ | |
1902 DCHECK(g_InputStream_clazz); | |
1903 jmethodID method_id = | |
1904 base::android::MethodID::LazyGet< | |
1905 base::android::MethodID::TYPE_INSTANCE>( | |
1906 env, g_InputStream_clazz, | |
1907 "reset", | |
1908 "()V", | |
1909 &g_InputStream_reset); | |
1910 | |
1911 env->CallVoidMethod(obj, | |
1912 method_id); | |
1913 base::android::CheckException(env); | |
1914 | |
1915 } | |
1916 | |
1917 static base::subtle::AtomicWord g_InputStream_skip = 0; | |
1918 static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) | |
1919 __attribute__ ((unused)); | |
1920 static jlong Java_InputStream_skip(JNIEnv* env, jobject obj, jlong p0) { | |
1921 /* Must call RegisterNativesImpl() */ | |
1922 DCHECK(g_InputStream_clazz); | |
1923 jmethodID method_id = | |
1924 base::android::MethodID::LazyGet< | |
1925 base::android::MethodID::TYPE_INSTANCE>( | |
1926 env, g_InputStream_clazz, | |
1927 "skip", | |
1928 "(J)J", | |
1929 &g_InputStream_skip); | |
1930 | |
1931 jlong ret = | |
1932 env->CallLongMethod(obj, | |
1933 method_id, p0); | |
1934 base::android::CheckException(env); | |
1935 return ret; | |
1936 } | |
1937 | |
1938 static base::subtle::AtomicWord g_InputStream_Constructor = 0; | |
1939 static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env) | |
1940 __attribute__ ((unused)); | |
1941 static ScopedJavaLocalRef<jobject> Java_InputStream_Constructor(JNIEnv* env) { | |
1942 /* Must call RegisterNativesImpl() */ | |
1943 DCHECK(g_InputStream_clazz); | |
1944 jmethodID method_id = | |
1945 base::android::MethodID::LazyGet< | |
1946 base::android::MethodID::TYPE_INSTANCE>( | |
1947 env, g_InputStream_clazz, | |
1948 "<init>", | |
1949 "()V", | |
1950 &g_InputStream_Constructor); | |
1951 | |
1952 jobject ret = | |
1953 env->NewObject(g_InputStream_clazz, | |
1954 method_id); | |
1955 base::android::CheckException(env); | |
1956 return ScopedJavaLocalRef<jobject>(env, ret); | |
1957 } | |
1958 | |
1959 // Step 3: RegisterNatives. | |
1960 | |
1961 static bool RegisterNativesImpl(JNIEnv* env) { | |
1962 | |
1963 g_InputStream_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
1964 base::android::GetClass(env, kInputStreamClassPath).obj())); | |
1965 return true; | |
1966 } | |
1967 } // namespace JNI_InputStream | |
1968 | |
1969 #endif // java_io_InputStream_JNI | |
1970 """ | |
1971 self.assertTextEquals(golden_content, jni_from_javap.GetContent()) | |
1972 | 747 |
1973 def testREForNatives(self): | 748 def testREForNatives(self): |
1974 # We should not match "native SyncSetupFlow" inside the comment. | 749 # We should not match "native SyncSetupFlow" inside the comment. |
1975 test_data = """ | 750 test_data = """ |
1976 /** | 751 /** |
1977 * Invoked when the setup process is complete so we can disconnect from the | 752 * Invoked when the setup process is complete so we can disconnect from the |
1978 * native-side SyncSetupFlowHandler. | 753 * native-side SyncSetupFlowHandler. |
1979 */ | 754 */ |
1980 public void destroy() { | 755 public void destroy() { |
1981 Log.v(TAG, "Destroying native SyncSetupFlow"); | 756 Log.v(TAG, "Destroying native SyncSetupFlow"); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2040 class Example { | 815 class Example { |
2041 private static native void nativeTest(Test t); | 816 private static native void nativeTest(Test t); |
2042 } | 817 } |
2043 """ | 818 """ |
2044 jni_generator.JniParams.SetJarJarMappings( | 819 jni_generator.JniParams.SetJarJarMappings( |
2045 """rule org.chromium.example.** com.test.@1 | 820 """rule org.chromium.example.** com.test.@1 |
2046 rule org.chromium.example2.** org.test2.@0""") | 821 rule org.chromium.example2.** org.test2.@0""") |
2047 jni_from_java = jni_generator.JNIFromJavaSource( | 822 jni_from_java = jni_generator.JNIFromJavaSource( |
2048 test_data, 'org/chromium/example/jni_generator/Example', TestOptions()) | 823 test_data, 'org/chromium/example/jni_generator/Example', TestOptions()) |
2049 jni_generator.JniParams.SetJarJarMappings('') | 824 jni_generator.JniParams.SetJarJarMappings('') |
2050 golden_content = """\ | 825 self.assertGoldenTextEquals(jni_from_java.GetContent()) |
2051 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2052 // Use of this source code is governed by a BSD-style license that can be | |
2053 // found in the LICENSE file. | |
2054 | |
2055 // This file is autogenerated by | |
2056 // base/android/jni_generator/jni_generator.py | |
2057 // For | |
2058 // org/chromium/example/jni_generator/Example | |
2059 | |
2060 #ifndef org_chromium_example_jni_generator_Example_JNI | |
2061 #define org_chromium_example_jni_generator_Example_JNI | |
2062 | |
2063 #include <jni.h> | |
2064 | |
2065 #include "base/android/jni_android.h" | |
2066 #include "base/android/scoped_java_ref.h" | |
2067 #include "base/basictypes.h" | |
2068 #include "base/logging.h" | |
2069 | |
2070 using base::android::ScopedJavaLocalRef; | |
2071 | |
2072 // Step 1: forward declarations. | |
2073 namespace { | |
2074 const char kExampleClassPath[] = "com/test/jni_generator/Example"; | |
2075 // Leaking this jclass as we cannot use LazyInstance from some threads. | |
2076 jclass g_Example_clazz = NULL; | |
2077 } // namespace | |
2078 | |
2079 static void Test(JNIEnv* env, jclass clazz, | |
2080 jobject t); | |
2081 | |
2082 // Step 2: method stubs. | |
2083 | |
2084 // Step 3: RegisterNatives. | |
2085 | |
2086 static bool RegisterNativesImpl(JNIEnv* env) { | |
2087 | |
2088 g_Example_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
2089 base::android::GetClass(env, kExampleClassPath).obj())); | |
2090 static const JNINativeMethod kMethodsExample[] = { | |
2091 { "nativeTest", | |
2092 "(" | |
2093 "Lorg/test2/org/chromium/example2/Test;" | |
2094 ")" | |
2095 "V", reinterpret_cast<void*>(Test) }, | |
2096 }; | |
2097 const int kMethodsExampleSize = arraysize(kMethodsExample); | |
2098 | |
2099 if (env->RegisterNatives(g_Example_clazz, | |
2100 kMethodsExample, | |
2101 kMethodsExampleSize) < 0) { | |
2102 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | |
2103 return false; | |
2104 } | |
2105 | |
2106 return true; | |
2107 } | |
2108 | |
2109 #endif // org_chromium_example_jni_generator_Example_JNI | |
2110 """ | |
2111 self.assertTextEquals(golden_content, jni_from_java.GetContent()) | |
2112 | 826 |
2113 def testImports(self): | 827 def testImports(self): |
2114 import_header = """ | 828 import_header = """ |
2115 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 829 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2116 // Use of this source code is governed by a BSD-style license that can be | 830 // Use of this source code is governed by a BSD-style license that can be |
2117 // found in the LICENSE file. | 831 // found in the LICENSE file. |
2118 | 832 |
2119 package org.chromium.content.app; | 833 package org.chromium.content.app; |
2120 | 834 |
2121 import android.app.Service; | 835 import android.app.Service; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2186 params=[Param(datatype='long', | 900 params=[Param(datatype='long', |
2187 name='nativeChromeBrowserProvider')], | 901 name='nativeChromeBrowserProvider')], |
2188 java_class_name=None, | 902 java_class_name=None, |
2189 type='method', | 903 type='method', |
2190 p0_type='ChromeBrowserProvider', | 904 p0_type='ChromeBrowserProvider', |
2191 ptr_type=test_options.ptr_type), | 905 ptr_type=test_options.ptr_type), |
2192 ] | 906 ] |
2193 self.assertListEquals(golden_natives, natives) | 907 self.assertListEquals(golden_natives, natives) |
2194 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', | 908 h = jni_generator.InlHeaderFileGenerator('', 'org/chromium/TestJni', |
2195 natives, [], test_options) | 909 natives, [], test_options) |
2196 golden_content = """\ | 910 self.assertGoldenTextEquals(h.GetContent()) |
2197 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2198 // Use of this source code is governed by a BSD-style license that can be | |
2199 // found in the LICENSE file. | |
2200 | |
2201 // This file is autogenerated by | |
2202 // base/android/jni_generator/jni_generator.py | |
2203 // For | |
2204 // org/chromium/TestJni | |
2205 | |
2206 #ifndef org_chromium_TestJni_JNI | |
2207 #define org_chromium_TestJni_JNI | |
2208 | |
2209 #include <jni.h> | |
2210 | |
2211 #include "base/android/jni_android.h" | |
2212 #include "base/android/scoped_java_ref.h" | |
2213 #include "base/basictypes.h" | |
2214 #include "base/logging.h" | |
2215 | |
2216 using base::android::ScopedJavaLocalRef; | |
2217 | |
2218 // Step 1: forward declarations. | |
2219 namespace { | |
2220 const char kTestJniClassPath[] = "org/chromium/TestJni"; | |
2221 // Leaking this jclass as we cannot use LazyInstance from some threads. | |
2222 jclass g_TestJni_clazz = NULL; | |
2223 } // namespace | |
2224 | |
2225 // Step 2: method stubs. | |
2226 static void Destroy(JNIEnv* env, jobject obj, | |
2227 jlong nativeChromeBrowserProvider) { | |
2228 DCHECK(nativeChromeBrowserProvider) << "Destroy"; | |
2229 ChromeBrowserProvider* native = | |
2230 reinterpret_cast<ChromeBrowserProvider*>(nativeChromeBrowserProvider); | |
2231 return native->Destroy(env, obj); | |
2232 } | |
2233 | |
2234 // Step 3: RegisterNatives. | |
2235 | |
2236 static bool RegisterNativesImpl(JNIEnv* env) { | |
2237 | |
2238 g_TestJni_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
2239 base::android::GetClass(env, kTestJniClassPath).obj())); | |
2240 static const JNINativeMethod kMethodsTestJni[] = { | |
2241 { "nativeDestroy", | |
2242 "(" | |
2243 "J" | |
2244 ")" | |
2245 "V", reinterpret_cast<void*>(Destroy) }, | |
2246 }; | |
2247 const int kMethodsTestJniSize = arraysize(kMethodsTestJni); | |
2248 | |
2249 if (env->RegisterNatives(g_TestJni_clazz, | |
2250 kMethodsTestJni, | |
2251 kMethodsTestJniSize) < 0) { | |
2252 LOG(ERROR) << "RegisterNatives failed in " << __FILE__; | |
2253 return false; | |
2254 } | |
2255 | |
2256 return true; | |
2257 } | |
2258 | |
2259 #endif // org_chromium_TestJni_JNI | |
2260 """ | |
2261 self.assertTextEquals(golden_content, h.GetContent()) | |
2262 | 911 |
2263 | 912 |
2264 if __name__ == '__main__': | 913 if __name__ == '__main__': |
2265 unittest.main() | 914 unittest.main() |
OLD | NEW |