| 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 os | 15 import os |
| 16 import sys | 16 import sys |
| 17 import unittest | 17 import unittest |
| 18 import jni_generator | 18 import jni_generator |
| 19 from jni_generator import CalledByNative, NativeMethod, Param | 19 from jni_generator import CalledByNative, JniParams, NativeMethod, Param |
| 20 | 20 |
| 21 | 21 |
| 22 class TestGenerator(unittest.TestCase): | 22 class TestGenerator(unittest.TestCase): |
| 23 def assertObjEquals(self, first, second): | 23 def assertObjEquals(self, first, second): |
| 24 dict_first = first.__dict__ | 24 dict_first = first.__dict__ |
| 25 dict_second = second.__dict__ | 25 dict_second = second.__dict__ |
| 26 self.assertEquals(dict_first.keys(), dict_second.keys()) | 26 self.assertEquals(dict_first.keys(), dict_second.keys()) |
| 27 for key, value in dict_first.iteritems(): | 27 for key, value in dict_first.iteritems(): |
| 28 if (type(value) is list and len(value) and | 28 if (type(value) is list and len(value) and |
| 29 isinstance(type(value[0]), object)): | 29 isinstance(type(value[0]), object)): |
| (...skipping 1881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1911 self.assertTrue('Lorg/chromium/content/app/Foo$BookmarkNode' in | 1911 self.assertTrue('Lorg/chromium/content/app/Foo$BookmarkNode' in |
| 1912 jni_generator.JniParams._inner_classes) | 1912 jni_generator.JniParams._inner_classes) |
| 1913 self.assertTrue('Lorg/chromium/content/app/Foo$PasswordListObserver' in | 1913 self.assertTrue('Lorg/chromium/content/app/Foo$PasswordListObserver' in |
| 1914 jni_generator.JniParams._inner_classes) | 1914 jni_generator.JniParams._inner_classes) |
| 1915 self.assertEquals('Lorg/chromium/content/app/ContentMain$Inner;', | 1915 self.assertEquals('Lorg/chromium/content/app/ContentMain$Inner;', |
| 1916 jni_generator.JniParams.JavaToJni('ContentMain.Inner')) | 1916 jni_generator.JniParams.JavaToJni('ContentMain.Inner')) |
| 1917 self.assertRaises(SyntaxError, | 1917 self.assertRaises(SyntaxError, |
| 1918 jni_generator.JniParams.JavaToJni, | 1918 jni_generator.JniParams.JavaToJni, |
| 1919 'AnException') | 1919 'AnException') |
| 1920 | 1920 |
| 1921 def testJniParamsJavaToJni(self): |
| 1922 self.assertTextEquals('I', JniParams.JavaToJni('int')) |
| 1923 self.assertTextEquals('[B', JniParams.JavaToJni('byte[]')) |
| 1924 self.assertTextEquals( |
| 1925 '[Ljava/nio/ByteBuffer;', JniParams.JavaToJni('java/nio/ByteBuffer[]')) |
| 1926 |
| 1921 | 1927 |
| 1922 if __name__ == '__main__': | 1928 if __name__ == '__main__': |
| 1923 unittest.main() | 1929 unittest.main() |
| OLD | NEW |