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