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 import optparse | 12 import optparse |
13 import os | 13 import os |
14 import sys | 14 import sys |
15 import unittest | 15 import unittest |
16 | 16 |
17 from java_cpp_enum import EnumDefinition, GenerateOutput, HeaderParser | 17 from java_cpp_enum import EnumDefinition, GenerateOutput, GetScriptName |
18 from java_cpp_enum import HeaderParser | |
18 | 19 |
19 sys.path.append(os.path.join(os.path.dirname(__file__), "gyp")) | 20 sys.path.append(os.path.join(os.path.dirname(__file__), "gyp")) |
20 from util import build_utils | 21 from util import build_utils |
21 | 22 |
22 class TestPreprocess(unittest.TestCase): | 23 class TestPreprocess(unittest.TestCase): |
23 def testOutput(self): | 24 def testOutput(self): |
24 definition = EnumDefinition(original_enum_name='ClassName', | 25 definition = EnumDefinition(original_enum_name='ClassName', |
25 enum_package='some.package', | 26 enum_package='some.package', |
26 entries=[('E1', 1), ('E2', '2 << 2')]) | 27 entries=[('E1', 1), ('E2', '2 << 2')]) |
27 output = GenerateOutput('path/to/file', definition) | 28 output = GenerateOutput('path/to/file', definition) |
28 expected = """ | 29 expected = """ |
29 // Copyright 2014 The Chromium Authors. All rights reserved. | 30 // Copyright 2014 The Chromium Authors. All rights reserved. |
30 // Use of this source code is governed by a BSD-style license that can be | 31 // Use of this source code is governed by a BSD-style license that can be |
31 // found in the LICENSE file. | 32 // found in the LICENSE file. |
32 | 33 |
33 // This file is autogenerated by | 34 // This file is autogenerated by |
34 // build/android/gyp/java_cpp_enum_tests.py | 35 // %s |
35 // From | 36 // From |
36 // path/to/file | 37 // path/to/file |
37 | 38 |
38 package some.package; | 39 package some.package; |
39 | 40 |
40 public class ClassName { | 41 public class ClassName { |
41 public static final int E1 = 1; | 42 public static final int E1 = 1; |
42 public static final int E2 = 2 << 2; | 43 public static final int E2 = 2 << 2; |
43 } | 44 } |
44 """ | 45 """ |
45 self.assertEqual(expected, output) | 46 self.assertEqual(expected % GetScriptName(), output) |
jbudorick
2014/11/12 17:50:29
Is GetScriptName working as intended? It looks lik
| |
46 | 47 |
47 def testParseSimpleEnum(self): | 48 def testParseSimpleEnum(self): |
48 test_data = """ | 49 test_data = """ |
49 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace | 50 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace |
50 enum EnumName { | 51 enum EnumName { |
51 VALUE_ZERO, | 52 VALUE_ZERO, |
52 VALUE_ONE, | 53 VALUE_ONE, |
53 }; | 54 }; |
54 """.split('\n') | 55 """.split('\n') |
55 definitions = HeaderParser(test_data).ParseDefinitions() | 56 definitions = HeaderParser(test_data).ParseDefinitions() |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 options, _ = parser.parse_args(argv) | 333 options, _ = parser.parse_args(argv) |
333 | 334 |
334 suite = unittest.TestLoader().loadTestsFromTestCase(TestPreprocess) | 335 suite = unittest.TestLoader().loadTestsFromTestCase(TestPreprocess) |
335 unittest.TextTestRunner(verbosity=0).run(suite) | 336 unittest.TextTestRunner(verbosity=0).run(suite) |
336 | 337 |
337 if options.stamp: | 338 if options.stamp: |
338 build_utils.Touch(options.stamp) | 339 build_utils.Touch(options.stamp) |
339 | 340 |
340 if __name__ == '__main__': | 341 if __name__ == '__main__': |
341 main(sys.argv[1:]) | 342 main(sys.argv[1:]) |
OLD | NEW |