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 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 def testParseUnknownFixedTypeRaises(self): | 216 def testParseUnknownFixedTypeRaises(self): |
217 test_data = """ | 217 test_data = """ |
218 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace | 218 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace |
219 enum class Foo: foo_type { | 219 enum class Foo: foo_type { |
220 FOO_A, | 220 FOO_A, |
221 }; | 221 }; |
222 """.split('\n') | 222 """.split('\n') |
223 with self.assertRaises(Exception): | 223 with self.assertRaises(Exception): |
224 HeaderParser(test_data).ParseDefinitions() | 224 HeaderParser(test_data).ParseDefinitions() |
225 | 225 |
| 226 def testParseSimpleMultiLineDirective(self): |
| 227 test_data = """ |
| 228 // GENERATED_JAVA_ENUM_PACKAGE: ( |
| 229 // test.namespace) |
| 230 // GENERATED_JAVA_CLASS_NAME_OVERRIDE: Bar |
| 231 enum Foo { |
| 232 FOO_A, |
| 233 }; |
| 234 """.split('\n') |
| 235 definitions = HeaderParser(test_data).ParseDefinitions() |
| 236 self.assertEqual('test.namespace', definitions[0].enum_package) |
| 237 self.assertEqual('Bar', definitions[0].class_name) |
| 238 |
| 239 def testParseMultiLineDirective(self): |
| 240 test_data = """ |
| 241 // GENERATED_JAVA_ENUM_PACKAGE: (te |
| 242 // st.name |
| 243 // space) |
| 244 enum Foo { |
| 245 FOO_A, |
| 246 }; |
| 247 """.split('\n') |
| 248 definitions = HeaderParser(test_data).ParseDefinitions() |
| 249 self.assertEqual('test.namespace', definitions[0].enum_package) |
| 250 |
| 251 def testParseMultiLineDirectiveWithOtherDirective(self): |
| 252 test_data = """ |
| 253 // GENERATED_JAVA_ENUM_PACKAGE: ( |
| 254 // test.namespace) |
| 255 // GENERATED_JAVA_CLASS_NAME_OVERRIDE: ( |
| 256 // Ba |
| 257 // r |
| 258 // ) |
| 259 enum Foo { |
| 260 FOO_A, |
| 261 }; |
| 262 """.split('\n') |
| 263 definitions = HeaderParser(test_data).ParseDefinitions() |
| 264 self.assertEqual('test.namespace', definitions[0].enum_package) |
| 265 self.assertEqual('Bar', definitions[0].class_name) |
| 266 |
| 267 def testParseMalformedMultiLineDirectiveWithOtherDirective(self): |
| 268 test_data = """ |
| 269 // GENERATED_JAVA_ENUM_PACKAGE: ( |
| 270 // test.name |
| 271 // space |
| 272 // GENERATED_JAVA_CLASS_NAME_OVERRIDE: Bar |
| 273 enum Foo { |
| 274 FOO_A, |
| 275 }; |
| 276 """.split('\n') |
| 277 with self.assertRaises(Exception): |
| 278 HeaderParser(test_data).ParseDefinitions() |
| 279 |
| 280 def testParseMalformedMultiLineDirective(self): |
| 281 test_data = """ |
| 282 // GENERATED_JAVA_ENUM_PACKAGE: ( |
| 283 // test.name |
| 284 // space |
| 285 enum Foo { |
| 286 FOO_A, |
| 287 }; |
| 288 """.split('\n') |
| 289 with self.assertRaises(Exception): |
| 290 HeaderParser(test_data).ParseDefinitions() |
| 291 |
| 292 def testParseMalformedMultiLineDirectiveShort(self): |
| 293 test_data = """ |
| 294 // GENERATED_JAVA_ENUM_PACKAGE: ( |
| 295 enum Foo { |
| 296 FOO_A, |
| 297 }; |
| 298 """.split('\n') |
| 299 with self.assertRaises(Exception): |
| 300 HeaderParser(test_data).ParseDefinitions() |
| 301 |
226 def testEnumValueAssignmentNoneDefined(self): | 302 def testEnumValueAssignmentNoneDefined(self): |
227 definition = EnumDefinition(original_enum_name='c', enum_package='p') | 303 definition = EnumDefinition(original_enum_name='c', enum_package='p') |
228 definition.AppendEntry('A', None) | 304 definition.AppendEntry('A', None) |
229 definition.AppendEntry('B', None) | 305 definition.AppendEntry('B', None) |
230 definition.AppendEntry('C', None) | 306 definition.AppendEntry('C', None) |
231 definition.Finalize() | 307 definition.Finalize() |
232 self.assertEqual(collections.OrderedDict([('A', 0), | 308 self.assertEqual(collections.OrderedDict([('A', 0), |
233 ('B', 1), | 309 ('B', 1), |
234 ('C', 2)]), | 310 ('C', 2)]), |
235 definition.entries) | 311 definition.entries) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 options, _ = parser.parse_args(argv) | 409 options, _ = parser.parse_args(argv) |
334 | 410 |
335 suite = unittest.TestLoader().loadTestsFromTestCase(TestPreprocess) | 411 suite = unittest.TestLoader().loadTestsFromTestCase(TestPreprocess) |
336 unittest.TextTestRunner(verbosity=0).run(suite) | 412 unittest.TextTestRunner(verbosity=0).run(suite) |
337 | 413 |
338 if options.stamp: | 414 if options.stamp: |
339 build_utils.Touch(options.stamp) | 415 build_utils.Touch(options.stamp) |
340 | 416 |
341 if __name__ == '__main__': | 417 if __name__ == '__main__': |
342 main(sys.argv[1:]) | 418 main(sys.argv[1:]) |
OLD | NEW |