Chromium Code Reviews| 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 1548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1559 datatype='int'), | 1559 datatype='int'), |
| 1560 Param(name='p3', | 1560 Param(name='p3', |
| 1561 datatype='int'),], | 1561 datatype='int'),], |
| 1562 'int')) | 1562 'int')) |
| 1563 self.assertEquals('openJIIS_JLS', | 1563 self.assertEquals('openJIIS_JLS', |
| 1564 jni_generator.GetMangledMethodName('open', | 1564 jni_generator.GetMangledMethodName('open', |
| 1565 [Param(name='p1', | 1565 [Param(name='p1', |
| 1566 datatype='java/lang/String'),], | 1566 datatype='java/lang/String'),], |
| 1567 'java/io/InputStream')) | 1567 'java/io/InputStream')) |
| 1568 | 1568 |
| 1569 def testFromJavaPGenerics(self): | |
| 1570 contents = """ | |
| 1571 public abstract class java.util.HashSet<T> extends java.util.AbstractSet<E> impl ements java.util.Set<E>, java.lang.Cloneable, java.io.Serializable { | |
|
joth
2013/08/31 02:43:38
nit: I think we'd like this wrapped like the Input
| |
| 1572 public void dummy(); | |
| 1573 } | |
| 1574 """ | |
| 1575 jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), None) | |
| 1576 self.assertEquals(1, len(jni_from_javap.called_by_natives)) | |
| 1577 golden_content = """\ | |
| 1578 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 1579 // Use of this source code is governed by a BSD-style license that can be | |
| 1580 // found in the LICENSE file. | |
| 1581 | |
| 1582 // This file is autogenerated by | |
| 1583 // base/android/jni_generator/jni_generator_tests.py | |
| 1584 // For | |
| 1585 // java/util/HashSet | |
| 1586 | |
| 1587 #ifndef java_util_HashSet_JNI | |
| 1588 #define java_util_HashSet_JNI | |
| 1589 | |
| 1590 #include <jni.h> | |
| 1591 | |
| 1592 #include "base/android/jni_android.h" | |
| 1593 #include "base/android/scoped_java_ref.h" | |
| 1594 #include "base/basictypes.h" | |
| 1595 #include "base/logging.h" | |
| 1596 | |
| 1597 using base::android::ScopedJavaLocalRef; | |
| 1598 | |
| 1599 // Step 1: forward declarations. | |
| 1600 namespace { | |
| 1601 const char kHashSetClassPath[] = "java/util/HashSet"; | |
| 1602 // Leaking this jclass as we cannot use LazyInstance from some threads. | |
| 1603 jclass g_HashSet_clazz = NULL; | |
| 1604 } // namespace | |
| 1605 | |
| 1606 namespace JNI_HashSet { | |
| 1607 | |
| 1608 // Step 2: method stubs. | |
| 1609 | |
| 1610 static base::subtle::AtomicWord g_HashSet_dummy = 0; | |
| 1611 static void Java_HashSet_dummy(JNIEnv* env, jobject obj) __attribute__ | |
| 1612 ((unused)); | |
| 1613 static void Java_HashSet_dummy(JNIEnv* env, jobject obj) { | |
| 1614 /* Must call RegisterNativesImpl() */ | |
| 1615 DCHECK(g_HashSet_clazz); | |
| 1616 jmethodID method_id = | |
| 1617 base::android::MethodID::LazyGet< | |
| 1618 base::android::MethodID::TYPE_INSTANCE>( | |
| 1619 env, g_HashSet_clazz, | |
| 1620 "dummy", | |
| 1621 | |
| 1622 "(" | |
| 1623 ")" | |
| 1624 "V", | |
| 1625 &g_HashSet_dummy); | |
| 1626 | |
| 1627 env->CallVoidMethod(obj, | |
| 1628 method_id); | |
| 1629 base::android::CheckException(env); | |
| 1630 | |
| 1631 } | |
| 1632 | |
| 1633 // Step 3: RegisterNatives. | |
| 1634 | |
| 1635 static bool RegisterNativesImpl(JNIEnv* env) { | |
| 1636 | |
| 1637 g_HashSet_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | |
| 1638 base::android::GetClass(env, kHashSetClassPath).obj())); | |
| 1639 return true; | |
| 1640 } | |
| 1641 } // namespace JNI_HashSet | |
| 1642 | |
| 1643 #endif // java_util_HashSet_JNI | |
| 1644 """ | |
| 1645 self.assertTextEquals(golden_content, jni_from_javap.GetContent()) | |
| 1646 | |
| 1569 def testFromJavaP(self): | 1647 def testFromJavaP(self): |
| 1570 contents = """ | 1648 contents = """ |
| 1571 public abstract class java.io.InputStream extends java.lang.Object | 1649 public abstract class java.io.InputStream extends java.lang.Object |
| 1572 implements java.io.Closeable{ | 1650 implements java.io.Closeable{ |
| 1573 public java.io.InputStream(); | 1651 public java.io.InputStream(); |
| 1574 public int available() throws java.io.IOException; | 1652 public int available() throws java.io.IOException; |
| 1575 public void close() throws java.io.IOException; | 1653 public void close() throws java.io.IOException; |
| 1576 public void mark(int); | 1654 public void mark(int); |
| 1577 public boolean markSupported(); | 1655 public boolean markSupported(); |
| 1578 public abstract int read() throws java.io.IOException; | 1656 public abstract int read() throws java.io.IOException; |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2075 | 2153 |
| 2076 def testJniParamsJavaToJni(self): | 2154 def testJniParamsJavaToJni(self): |
| 2077 self.assertTextEquals('I', JniParams.JavaToJni('int')) | 2155 self.assertTextEquals('I', JniParams.JavaToJni('int')) |
| 2078 self.assertTextEquals('[B', JniParams.JavaToJni('byte[]')) | 2156 self.assertTextEquals('[B', JniParams.JavaToJni('byte[]')) |
| 2079 self.assertTextEquals( | 2157 self.assertTextEquals( |
| 2080 '[Ljava/nio/ByteBuffer;', JniParams.JavaToJni('java/nio/ByteBuffer[]')) | 2158 '[Ljava/nio/ByteBuffer;', JniParams.JavaToJni('java/nio/ByteBuffer[]')) |
| 2081 | 2159 |
| 2082 | 2160 |
| 2083 if __name__ == '__main__': | 2161 if __name__ == '__main__': |
| 2084 unittest.main() | 2162 unittest.main() |
| OLD | NEW |