| 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 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 implements java.util.Set<E>, java.lang.Cloneable, java.io.Serializable { | 715 implements java.util.Set<E>, java.lang.Cloneable, java.io.Serializable { |
| 716 public void dummy(); | 716 public void dummy(); |
| 717 Signature: ()V | 717 Signature: ()V |
| 718 } | 718 } |
| 719 """ | 719 """ |
| 720 jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), | 720 jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), |
| 721 TestOptions()) | 721 TestOptions()) |
| 722 self.assertEquals(1, len(jni_from_javap.called_by_natives)) | 722 self.assertEquals(1, len(jni_from_javap.called_by_natives)) |
| 723 self.assertGoldenTextEquals(jni_from_javap.GetContent()) | 723 self.assertGoldenTextEquals(jni_from_javap.GetContent()) |
| 724 | 724 |
| 725 def testSnippnetJavap6_7(self): | 725 def testSnippnetJavap6_7_8(self): |
| 726 content_javap6 = """ | 726 content_javap6 = """ |
| 727 public class java.util.HashSet { | 727 public class java.util.HashSet { |
| 728 public boolean add(java.lang.Object); | 728 public boolean add(java.lang.Object); |
| 729 Signature: (Ljava/lang/Object;)Z | 729 Signature: (Ljava/lang/Object;)Z |
| 730 } | 730 } |
| 731 """ | 731 """ |
| 732 | 732 |
| 733 content_javap7 = """ | 733 content_javap7 = """ |
| 734 public class java.util.HashSet { | 734 public class java.util.HashSet { |
| 735 public boolean add(E); | 735 public boolean add(E); |
| 736 Signature: (Ljava/lang/Object;)Z | 736 Signature: (Ljava/lang/Object;)Z |
| 737 } | 737 } |
| 738 """ | 738 """ |
| 739 |
| 740 content_javap8 = """ |
| 741 public class java.util.HashSet { |
| 742 public boolean add(E); |
| 743 descriptor: (Ljava/lang/Object;)Z |
| 744 } |
| 745 """ |
| 746 |
| 739 jni_from_javap6 = jni_generator.JNIFromJavaP(content_javap6.split('\n'), | 747 jni_from_javap6 = jni_generator.JNIFromJavaP(content_javap6.split('\n'), |
| 740 TestOptions()) | 748 TestOptions()) |
| 741 jni_from_javap7 = jni_generator.JNIFromJavaP(content_javap7.split('\n'), | 749 jni_from_javap7 = jni_generator.JNIFromJavaP(content_javap7.split('\n'), |
| 742 TestOptions()) | 750 TestOptions()) |
| 751 jni_from_javap8 = jni_generator.JNIFromJavaP(content_javap8.split('\n'), |
| 752 TestOptions()) |
| 743 self.assertTrue(jni_from_javap6.GetContent()) | 753 self.assertTrue(jni_from_javap6.GetContent()) |
| 744 self.assertTrue(jni_from_javap7.GetContent()) | 754 self.assertTrue(jni_from_javap7.GetContent()) |
| 755 self.assertTrue(jni_from_javap8.GetContent()) |
| 745 # Ensure the javap7 is correctly parsed and uses the Signature field rather | 756 # Ensure the javap7 is correctly parsed and uses the Signature field rather |
| 746 # than the "E" parameter. | 757 # than the "E" parameter. |
| 747 self.assertTextEquals(jni_from_javap6.GetContent(), | 758 self.assertTextEquals(jni_from_javap6.GetContent(), |
| 748 jni_from_javap7.GetContent()) | 759 jni_from_javap7.GetContent()) |
| 760 # Ensure the javap8 is correctly parsed and uses the descriptor field. |
| 761 self.assertTextEquals(jni_from_javap7.GetContent(), |
| 762 jni_from_javap8.GetContent()) |
| 749 | 763 |
| 750 def testFromJavaP(self): | 764 def testFromJavaP(self): |
| 751 contents = self._ReadGoldenFile(os.path.join(os.path.dirname(sys.argv[0]), | 765 contents = self._ReadGoldenFile(os.path.join(os.path.dirname(sys.argv[0]), |
| 752 'testInputStream.javap')) | 766 'testInputStream.javap')) |
| 753 jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), | 767 jni_from_javap = jni_generator.JNIFromJavaP(contents.split('\n'), |
| 754 TestOptions()) | 768 TestOptions()) |
| 755 self.assertEquals(10, len(jni_from_javap.called_by_natives)) | 769 self.assertEquals(10, len(jni_from_javap.called_by_natives)) |
| 756 self.assertGoldenTextEquals(jni_from_javap.GetContent()) | 770 self.assertGoldenTextEquals(jni_from_javap.GetContent()) |
| 757 | 771 |
| 758 def testConstantsFromJavaP(self): | 772 def testConstantsFromJavaP(self): |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 } | 1133 } |
| 1120 """ | 1134 """ |
| 1121 jni_from_java = jni_generator.JNIFromJavaSource(test_data, | 1135 jni_from_java = jni_generator.JNIFromJavaSource(test_data, |
| 1122 'org/chromium/foo/Foo', | 1136 'org/chromium/foo/Foo', |
| 1123 TestOptions()) | 1137 TestOptions()) |
| 1124 self.assertGoldenTextEquals(jni_from_java.GetContent()) | 1138 self.assertGoldenTextEquals(jni_from_java.GetContent()) |
| 1125 | 1139 |
| 1126 | 1140 |
| 1127 if __name__ == '__main__': | 1141 if __name__ == '__main__': |
| 1128 unittest.main() | 1142 unittest.main() |
| OLD | NEW |