| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 enum_preprocess.py. | 6 """Tests for enum_preprocess.py. |
| 7 | 7 |
| 8 This test suite containss various tests for the C++ -> Java enum generator. | 8 This test suite containss various tests for the C++ -> Java enum generator. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import collections | 11 import collections |
| 12 from datetime import date | 12 from datetime import date |
| 13 import optparse | 13 import optparse |
| 14 import os | 14 import os |
| 15 import sys | 15 import sys |
| 16 import unittest | 16 import unittest |
| 17 | 17 |
| 18 import java_cpp_enum | 18 import java_cpp_enum |
| 19 from java_cpp_enum import EnumDefinition, GenerateOutput, GetScriptName | 19 from java_cpp_enum import EnumDefinition, GenerateOutput, GetScriptName |
| 20 from java_cpp_enum import HeaderParser | 20 from java_cpp_enum import HeaderParser |
| 21 | 21 |
| 22 sys.path.append(os.path.join(os.path.dirname(__file__), "gyp")) | 22 sys.path.append(os.path.join(os.path.dirname(__file__), "gyp")) |
| 23 from util import build_utils | 23 from util import build_utils |
| 24 | 24 |
| 25 class TestPreprocess(unittest.TestCase): | 25 class TestPreprocess(unittest.TestCase): |
| 26 def testOutput(self): | 26 def testOutput(self): |
| 27 definition = EnumDefinition(original_enum_name='ClassName', | 27 definition = EnumDefinition(original_enum_name='ClassName', |
| 28 enum_package='some.package', | 28 enum_package='some.package', |
| 29 class_comment='comment', |
| 29 entries=[('E1', 1), ('E2', '2 << 2')], | 30 entries=[('E1', 1), ('E2', '2 << 2')], |
| 30 comments=[('E2', 'This is a comment.'), | 31 comments=[('E2', 'This is a comment.'), |
| 31 ('E1', 'This is a multiple line ' | 32 ('E1', 'This is a multiple line ' |
| 32 'comment that is really long. ' | 33 'comment that is really long. ' |
| 33 'This is a multiple line ' | 34 'This is a multiple line ' |
| 34 'comment that is really ' | 35 'comment that is really ' |
| 35 'really long.')]) | 36 'really long.')]) |
| 36 output = GenerateOutput('path/to/file', definition) | 37 output = GenerateOutput('path/to/file', definition) |
| 37 expected = """ | 38 expected = """ |
| 38 // Copyright %d The Chromium Authors. All rights reserved. | 39 // Copyright %d The Chromium Authors. All rights reserved. |
| 39 // Use of this source code is governed by a BSD-style license that can be | 40 // Use of this source code is governed by a BSD-style license that can be |
| 40 // found in the LICENSE file. | 41 // found in the LICENSE file. |
| 41 | 42 |
| 42 // This file is autogenerated by | 43 // This file is autogenerated by |
| 43 // %s | 44 // %s |
| 44 // From | 45 // From |
| 45 // path/to/file | 46 // path/to/file |
| 46 | 47 |
| 47 package some.package; | 48 package some.package; |
| 48 | 49 |
| 49 import android.support.annotation.IntDef; | 50 import android.support.annotation.IntDef; |
| 50 | 51 |
| 51 import java.lang.annotation.Retention; | 52 import java.lang.annotation.Retention; |
| 52 import java.lang.annotation.RetentionPolicy; | 53 import java.lang.annotation.RetentionPolicy; |
| 53 | 54 |
| 55 /** comment */ |
| 54 public class ClassName { | 56 public class ClassName { |
| 57 /** @hide */ |
| 55 @IntDef({ | 58 @IntDef({ |
| 56 E1, E2 | 59 E1, E2 |
| 57 }) | 60 }) |
| 58 @Retention(RetentionPolicy.SOURCE) | 61 @Retention(RetentionPolicy.SOURCE) |
| 59 public @interface ClassNameEnum {} | 62 public @interface ClassNameEnum {} |
| 60 /** | 63 /** |
| 61 * %s | 64 * %s |
| 62 * really really long. | 65 * really really long. |
| 63 */ | 66 */ |
| 64 public static final int E1 = 1; | 67 public static final int E1 = 1; |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 options, _ = parser.parse_args(argv) | 464 options, _ = parser.parse_args(argv) |
| 462 | 465 |
| 463 suite = unittest.TestLoader().loadTestsFromTestCase(TestPreprocess) | 466 suite = unittest.TestLoader().loadTestsFromTestCase(TestPreprocess) |
| 464 unittest.TextTestRunner(verbosity=0).run(suite) | 467 unittest.TextTestRunner(verbosity=0).run(suite) |
| 465 | 468 |
| 466 if options.stamp: | 469 if options.stamp: |
| 467 build_utils.Touch(options.stamp) | 470 build_utils.Touch(options.stamp) |
| 468 | 471 |
| 469 if __name__ == '__main__': | 472 if __name__ == '__main__': |
| 470 main(sys.argv[1:]) | 473 main(sys.argv[1:]) |
| OLD | NEW |