Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(752)

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/generate/mojom_translator_unittest.py

Issue 1824263002: Mojom backend: Stop re-computing version info and field packing data. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import unittest 5 import unittest
6 import module 6 import module
7 7
8 try: 8 try:
9 import mojom_translator 9 import mojom_translator
10 from generated import mojom_files_mojom 10 from generated import mojom_files_mojom
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 graph.resolved_types['interface_key'] = mojom_types_mojom.UserDefinedType( 79 graph.resolved_types['interface_key'] = mojom_types_mojom.UserDefinedType(
80 interface_type=mojom_interface) 80 interface_type=mojom_interface)
81 81
82 mojom_struct = mojom_types_mojom.MojomStruct( 82 mojom_struct = mojom_types_mojom.MojomStruct(
83 fields=[], 83 fields=[],
84 decl_data=mojom_types_mojom.DeclarationData( 84 decl_data=mojom_types_mojom.DeclarationData(
85 short_name='AStruct', 85 short_name='AStruct',
86 full_identifier='foo.AStruct', 86 full_identifier='foo.AStruct',
87 source_file_info=mojom_types_mojom.SourceFileInfo( 87 source_file_info=mojom_types_mojom.SourceFileInfo(
88 file_name=file_name))) 88 file_name=file_name)))
89 add_version_info(mojom_struct, 0)
89 graph.resolved_types['struct_key'] = mojom_types_mojom.UserDefinedType( 90 graph.resolved_types['struct_key'] = mojom_types_mojom.UserDefinedType(
90 struct_type=mojom_struct) 91 struct_type=mojom_struct)
91 92
92 mojom_union = mojom_types_mojom.MojomUnion( 93 mojom_union = mojom_types_mojom.MojomUnion(
93 fields=[], 94 fields=[],
94 decl_data=mojom_types_mojom.DeclarationData( 95 decl_data=mojom_types_mojom.DeclarationData(
95 short_name='AUnion', 96 short_name='AUnion',
96 source_file_info=mojom_types_mojom.SourceFileInfo( 97 source_file_info=mojom_types_mojom.SourceFileInfo(
97 file_name=file_name))) 98 file_name=file_name)))
98 graph.resolved_types['union_key'] = mojom_types_mojom.UserDefinedType( 99 graph.resolved_types['union_key'] = mojom_types_mojom.UserDefinedType(
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 graph.files = {mojom_file.file_name: mojom_file} 242 graph.files = {mojom_file.file_name: mojom_file}
242 243
243 mojom_struct = mojom_types_mojom.MojomStruct( 244 mojom_struct = mojom_types_mojom.MojomStruct(
244 decl_data=mojom_types_mojom.DeclarationData(short_name='FirstStruct')) 245 decl_data=mojom_types_mojom.DeclarationData(short_name='FirstStruct'))
245 mojom_struct.fields = [ 246 mojom_struct.fields = [
246 mojom_types_mojom.StructField( 247 mojom_types_mojom.StructField(
247 decl_data=mojom_types_mojom.DeclarationData( 248 decl_data=mojom_types_mojom.DeclarationData(
248 short_name='field03', 249 short_name='field03',
249 declaration_order=2), 250 declaration_order=2),
250 type=mojom_types_mojom.Type( 251 type=mojom_types_mojom.Type(
251 simple_type=mojom_types_mojom.SimpleType.BOOL)), 252 simple_type=mojom_types_mojom.SimpleType.BOOL),
253 offset=21,
254 bit=6,
255 min_version=11),
252 mojom_types_mojom.StructField( 256 mojom_types_mojom.StructField(
253 decl_data=mojom_types_mojom.DeclarationData( 257 decl_data=mojom_types_mojom.DeclarationData(
254 short_name='field01', 258 short_name='field01',
255 declared_ordinal=1, 259 declared_ordinal=1,
256 declaration_order=0), 260 declaration_order=0),
257 type=mojom_types_mojom.Type( 261 type=mojom_types_mojom.Type(
258 simple_type=mojom_types_mojom.SimpleType.BOOL)), 262 simple_type=mojom_types_mojom.SimpleType.BOOL),
263 offset=17,
264 bit=1,
265 min_version=4),
259 mojom_types_mojom.StructField( 266 mojom_types_mojom.StructField(
260 decl_data=mojom_types_mojom.DeclarationData( 267 decl_data=mojom_types_mojom.DeclarationData(
261 short_name='field02', 268 short_name='field02',
262 declaration_order=1), 269 declaration_order=1),
263 type=mojom_types_mojom.Type( 270 type=mojom_types_mojom.Type(
264 simple_type=mojom_types_mojom.SimpleType.DOUBLE), 271 simple_type=mojom_types_mojom.SimpleType.DOUBLE),
272 offset=0,
273 bit=0,
274 min_version=0,
265 default_value=mojom_types_mojom.DefaultFieldValue( 275 default_value=mojom_types_mojom.DefaultFieldValue(
266 value=mojom_types_mojom.Value( 276 value=mojom_types_mojom.Value(
267 literal_value=mojom_types_mojom.LiteralValue(double_value=15)))), 277 literal_value=mojom_types_mojom.LiteralValue(double_value=15)))),
268 ] 278 ]
279 mojom_struct.version_info=[
280 mojom_types_mojom.StructVersion(
281 version_number=0, num_bytes=67, num_fields=1),
282 mojom_types_mojom.StructVersion(
283 version_number=1, num_bytes=76, num_fields=3),
284 ]
269 # mojom_fields_declaration_order lists, in declaration order, the indices 285 # mojom_fields_declaration_order lists, in declaration order, the indices
270 # of the fields in mojom_types_mojom.StructField. 286 # of the fields in mojom_types_mojom.StructField.
271 mojom_fields_declaration_order = [1, 2, 0] 287 mojom_fields_declaration_order = [1, 2, 0]
272 mojom_struct.decl_data.source_file_info = mojom_types_mojom.SourceFileInfo( 288 mojom_struct.decl_data.source_file_info = mojom_types_mojom.SourceFileInfo(
273 file_name=mojom_file.file_name) 289 file_name=mojom_file.file_name)
274 290
275 struct = module.Struct() 291 struct = module.Struct()
276 translator = mojom_translator.FileTranslator(graph, file_name) 292 translator = mojom_translator.FileTranslator(graph, file_name)
277 translator.StructFromMojom( 293 translator.StructFromMojom(
278 struct, mojom_types_mojom.UserDefinedType(struct_type=mojom_struct)) 294 struct, mojom_types_mojom.UserDefinedType(struct_type=mojom_struct))
279 295
280 self.assertEquals('FirstStruct', struct.name) 296 self.assertEquals('FirstStruct', struct.name)
281 self.assertEquals(translator._module, struct.module) 297 self.assertEquals(translator._module, struct.module)
282 298
283 self.assertEquals(len(mojom_struct.fields), len(struct.fields)) 299 self.assertEquals(len(mojom_struct.fields), len(struct.fields))
284 for index, gold_index in enumerate(mojom_fields_declaration_order): 300 for index, gold_index in enumerate(mojom_fields_declaration_order):
285 gold = mojom_struct.fields[gold_index] 301 gold = mojom_struct.fields[gold_index]
286 f = struct.fields[index] 302 f = struct.fields[index]
287 self.assertEquals(f.name, gold.decl_data.short_name) 303 self.assertEquals(f.name, gold.decl_data.short_name)
288 if gold.decl_data.declared_ordinal >= 0: 304 if gold.decl_data.declared_ordinal >= 0:
289 self.assertEquals(gold.decl_data.declared_ordinal, f.ordinal) 305 self.assertEquals(gold.decl_data.declared_ordinal, f.ordinal)
290 else: 306 else:
291 self.assertEquals(None, f.ordinal) 307 self.assertEquals(None, f.ordinal)
292 self.assertEquals(gold_index, f.computed_ordinal) 308 self.assertEquals(gold_index, f.computed_ordinal)
309 self.assertEquals(gold.offset, f.computed_offset)
310 self.assertEquals(gold.bit, f.computed_bit)
311 self.assertEquals(gold.min_version, f.computed_min_version)
312 self.assertEquals(struct.fields_in_ordinal_order[index].name,
313 mojom_struct.fields[index].decl_data.short_name)
314
315 self.assertEquals(2, len(struct.versions))
316 for i in xrange(0, 2):
317 self.assertEquals(mojom_struct.version_info[i].version_number,
318 struct.versions[i].version)
319 self.assertEquals(mojom_struct.version_info[i].num_bytes,
320 struct.versions[i].num_bytes)
321 self.assertEquals(mojom_struct.version_info[i].num_fields,
322 struct.versions[i].num_fields)
293 323
294 self.assertEquals(module.BOOL, struct.fields[0].kind) 324 self.assertEquals(module.BOOL, struct.fields[0].kind)
295 self.assertEquals(module.DOUBLE, struct.fields[1].kind) 325 self.assertEquals(module.DOUBLE, struct.fields[1].kind)
296 326
297 self.assertEquals('15.0', struct.fields[1].default) 327 self.assertEquals('15.0', struct.fields[1].default)
298 328
299 def test_constant(self): 329 def test_constant(self):
300 file_name = 'a.mojom' 330 file_name = 'a.mojom'
301 graph = mojom_files_mojom.MojomFileGraph() 331 graph = mojom_files_mojom.MojomFileGraph()
302 332
303 mojom_const = mojom_types_mojom.DeclaredConstant() 333 mojom_const = mojom_types_mojom.DeclaredConstant()
304 mojom_const.decl_data = mojom_types_mojom.DeclarationData( 334 mojom_const.decl_data = mojom_types_mojom.DeclarationData(
305 short_name='foo', container_type_key='struct_key') 335 short_name='foo', container_type_key='struct_key')
306 mojom_const.type = mojom_types_mojom.Type( 336 mojom_const.type = mojom_types_mojom.Type(
307 simple_type=mojom_types_mojom.SimpleType.INT64) 337 simple_type=mojom_types_mojom.SimpleType.INT64)
308 mojom_const.value = mojom_types_mojom.Value() 338 mojom_const.value = mojom_types_mojom.Value()
309 mojom_const.value.literal_value = mojom_types_mojom.LiteralValue( 339 mojom_const.value.literal_value = mojom_types_mojom.LiteralValue(
310 int64_value=20) 340 int64_value=20)
311 341
312 mojom_struct = mojom_types_mojom.MojomStruct( 342 mojom_struct = mojom_types_mojom.MojomStruct(
313 fields=[], 343 fields=[],
314 decl_data=mojom_types_mojom.DeclarationData( 344 decl_data=mojom_types_mojom.DeclarationData(
315 short_name='AStruct', 345 short_name='AStruct',
316 source_file_info =mojom_types_mojom.SourceFileInfo( 346 source_file_info =mojom_types_mojom.SourceFileInfo(
317 file_name=file_name))) 347 file_name=file_name)))
348 add_version_info(mojom_struct, 0)
318 graph.resolved_types = {'struct_key': mojom_types_mojom.UserDefinedType( 349 graph.resolved_types = {'struct_key': mojom_types_mojom.UserDefinedType(
319 struct_type=mojom_struct)} 350 struct_type=mojom_struct)}
320 351
321 const = module.Constant() 352 const = module.Constant()
322 translator = mojom_translator.FileTranslator(graph, file_name) 353 translator = mojom_translator.FileTranslator(graph, file_name)
323 translator.ConstantFromMojom(const, mojom_const) 354 translator.ConstantFromMojom(const, mojom_const)
324 355
325 self.assertEquals(mojom_const.decl_data.short_name, const.name) 356 self.assertEquals(mojom_const.decl_data.short_name, const.name)
326 self.assertEquals(module.INT64, const.kind) 357 self.assertEquals(module.INT64, const.kind)
327 self.assertEquals('20', const.value) 358 self.assertEquals('20', const.value)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 container_type_key='struct_key') 408 container_type_key='struct_key')
378 mojom_enum.values = [] 409 mojom_enum.values = []
379 410
380 graph = mojom_files_mojom.MojomFileGraph() 411 graph = mojom_files_mojom.MojomFileGraph()
381 mojom_struct = mojom_types_mojom.MojomStruct( 412 mojom_struct = mojom_types_mojom.MojomStruct(
382 fields=[], 413 fields=[],
383 decl_data=mojom_types_mojom.DeclarationData( 414 decl_data=mojom_types_mojom.DeclarationData(
384 short_name='AStruct', 415 short_name='AStruct',
385 source_file_info =mojom_types_mojom.SourceFileInfo( 416 source_file_info =mojom_types_mojom.SourceFileInfo(
386 file_name=file_name))) 417 file_name=file_name)))
418 add_version_info(mojom_struct, 0)
387 graph.resolved_types = {'struct_key': mojom_types_mojom.UserDefinedType( 419 graph.resolved_types = {'struct_key': mojom_types_mojom.UserDefinedType(
388 struct_type=mojom_struct)} 420 struct_type=mojom_struct)}
389 421
390 enum = module.Enum() 422 enum = module.Enum()
391 translator = mojom_translator.FileTranslator(graph, file_name) 423 translator = mojom_translator.FileTranslator(graph, file_name)
392 translator.EnumFromMojom( 424 translator.EnumFromMojom(
393 enum, mojom_types_mojom.UserDefinedType(enum_type=mojom_enum)) 425 enum, mojom_types_mojom.UserDefinedType(enum_type=mojom_enum))
394 426
395 self.assertEquals(mojom_enum.decl_data.short_name, enum.name) 427 self.assertEquals(mojom_enum.decl_data.short_name, enum.name)
396 self.assertEquals(len(mojom_enum.values), len(enum.fields)) 428 self.assertEquals(len(mojom_enum.values), len(enum.fields))
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 module_namespace='otherns', 547 module_namespace='otherns',
516 imports=[]), 548 imports=[]),
517 } 549 }
518 550
519 mojom_struct = mojom_types_mojom.MojomStruct() 551 mojom_struct = mojom_types_mojom.MojomStruct()
520 mojom_struct.decl_data = mojom_types_mojom.DeclarationData( 552 mojom_struct.decl_data = mojom_types_mojom.DeclarationData(
521 short_name='AStruct', 553 short_name='AStruct',
522 source_file_info=mojom_types_mojom.SourceFileInfo( 554 source_file_info=mojom_types_mojom.SourceFileInfo(
523 file_name='root/c.mojom')) 555 file_name='root/c.mojom'))
524 mojom_struct.fields = [] 556 mojom_struct.fields = []
557 add_version_info(mojom_struct, 0)
525 558
526 type_key = 'some_type_key' 559 type_key = 'some_type_key'
527 graph.resolved_types = { 560 graph.resolved_types = {
528 type_key: mojom_types_mojom.UserDefinedType(struct_type=mojom_struct)} 561 type_key: mojom_types_mojom.UserDefinedType(struct_type=mojom_struct)}
529 struct = module.Struct() 562 struct = module.Struct()
530 563
531 # Translate should create the imports. 564 # Translate should create the imports.
532 translator = mojom_translator.FileTranslator(graph, 'a.mojom') 565 translator = mojom_translator.FileTranslator(graph, 'a.mojom')
533 translator.Translate() 566 translator.Translate()
534 567
(...skipping 24 matching lines...) Expand all
559 key='ServiceName', value=mojom_types_mojom.LiteralValue( 592 key='ServiceName', value=mojom_types_mojom.LiteralValue(
560 string_value='test::TheInterface'))] 593 string_value='test::TheInterface'))]
561 else: 594 else:
562 mojom_interface.service_name = None 595 mojom_interface.service_name = None
563 mojom_method10 = mojom_types_mojom.MojomMethod( 596 mojom_method10 = mojom_types_mojom.MojomMethod(
564 ordinal=10, 597 ordinal=10,
565 decl_data=mojom_types_mojom.DeclarationData( 598 decl_data=mojom_types_mojom.DeclarationData(
566 short_name='AMethod10', 599 short_name='AMethod10',
567 source_file_info=mojom_types_mojom.SourceFileInfo( 600 source_file_info=mojom_types_mojom.SourceFileInfo(
568 file_name=file_name)), 601 file_name=file_name)),
569 parameters=mojom_types_mojom.MojomStruct(fields=[])) 602 parameters=mojom_types_mojom.MojomStruct(fields=[],
603 version_info=build_version_info(0),
604 decl_data=build_decl_data('AMethod10_Request')))
570 mojom_method0 = mojom_types_mojom.MojomMethod( 605 mojom_method0 = mojom_types_mojom.MojomMethod(
571 ordinal=0, 606 ordinal=0,
572 decl_data=mojom_types_mojom.DeclarationData( 607 decl_data=mojom_types_mojom.DeclarationData(
573 short_name='AMethod0', 608 short_name='AMethod0',
574 source_file_info=mojom_types_mojom.SourceFileInfo( 609 source_file_info=mojom_types_mojom.SourceFileInfo(
575 file_name=file_name)), 610 file_name=file_name)),
576 parameters=mojom_types_mojom.MojomStruct(fields=[])) 611 parameters=mojom_types_mojom.MojomStruct(fields=[],
612 version_info=build_version_info(0),
613 decl_data=build_decl_data('AMethod0_Request')))
577 mojom_method7 = mojom_types_mojom.MojomMethod( 614 mojom_method7 = mojom_types_mojom.MojomMethod(
578 ordinal=7, 615 ordinal=7,
579 decl_data=mojom_types_mojom.DeclarationData( 616 decl_data=mojom_types_mojom.DeclarationData(
580 short_name='AMethod10', 617 short_name='AMethod7',
581 source_file_info=mojom_types_mojom.SourceFileInfo( 618 source_file_info=mojom_types_mojom.SourceFileInfo(
582 file_name=file_name)), 619 file_name=file_name)),
583 parameters=mojom_types_mojom.MojomStruct(fields=[])) 620 parameters=mojom_types_mojom.MojomStruct(fields=[],
621 version_info=build_version_info(0),
622 decl_data=build_decl_data('AMethod7_Request')))
584 mojom_interface.methods = {10: mojom_method10, 0: mojom_method0, 623 mojom_interface.methods = {10: mojom_method10, 0: mojom_method0,
585 7: mojom_method7} 624 7: mojom_method7}
586 625
587 interface = module.Interface() 626 interface = module.Interface()
588 graph = mojom_files_mojom.MojomFileGraph() 627 graph = mojom_files_mojom.MojomFileGraph()
589 translator = mojom_translator.FileTranslator(graph, file_name) 628 translator = mojom_translator.FileTranslator(graph, file_name)
590 translator.InterfaceFromMojom(interface, mojom_types_mojom.UserDefinedType( 629 translator.InterfaceFromMojom(interface, mojom_types_mojom.UserDefinedType(
591 interface_type=mojom_interface)) 630 interface_type=mojom_interface))
592 631
593 self.assertEquals(translator._module, interface.module) 632 self.assertEquals(translator._module, interface.module)
(...skipping 13 matching lines...) Expand all
607 mojom_method = mojom_types_mojom.MojomMethod( 646 mojom_method = mojom_types_mojom.MojomMethod(
608 ordinal=10, 647 ordinal=10,
609 decl_data=mojom_types_mojom.DeclarationData( 648 decl_data=mojom_types_mojom.DeclarationData(
610 short_name='AMethod', 649 short_name='AMethod',
611 source_file_info=mojom_types_mojom.SourceFileInfo( 650 source_file_info=mojom_types_mojom.SourceFileInfo(
612 file_name=file_name))) 651 file_name=file_name)))
613 652
614 param1 = mojom_types_mojom.StructField( 653 param1 = mojom_types_mojom.StructField(
615 decl_data=mojom_types_mojom.DeclarationData(short_name='a_param'), 654 decl_data=mojom_types_mojom.DeclarationData(short_name='a_param'),
616 type=mojom_types_mojom.Type( 655 type=mojom_types_mojom.Type(
617 simple_type=mojom_types_mojom.SimpleType.UINT32)) 656 simple_type=mojom_types_mojom.SimpleType.UINT32),
657 offset=21,
658 bit=6,
659 min_version=11)
618 param2 = mojom_types_mojom.StructField( 660 param2 = mojom_types_mojom.StructField(
619 decl_data=mojom_types_mojom.DeclarationData(short_name='b_param'), 661 decl_data=mojom_types_mojom.DeclarationData(short_name='b_param'),
620 type=mojom_types_mojom.Type( 662 type=mojom_types_mojom.Type(
621 simple_type=mojom_types_mojom.SimpleType.UINT64)) 663 simple_type=mojom_types_mojom.SimpleType.UINT64),
664 offset=22,
665 bit=7,
666 min_version=12)
622 mojom_method.parameters = mojom_types_mojom.MojomStruct( 667 mojom_method.parameters = mojom_types_mojom.MojomStruct(
623 fields=[param1, param2]) 668 fields=[param1, param2],
669 version_info=build_version_info(2),
670 decl_data=build_decl_data('Not used'))
624 671
625 interface = module.Interface() 672 interface = module.Interface('MyInterface')
626 graph = mojom_files_mojom.MojomFileGraph() 673 graph = mojom_files_mojom.MojomFileGraph()
627 translator = mojom_translator.FileTranslator(graph, file_name) 674 translator = mojom_translator.FileTranslator(graph, file_name)
628 method = translator.MethodFromMojom(mojom_method, interface) 675 method = translator.MethodFromMojom(mojom_method, interface)
629 676
630 self.assertEquals(mojom_method.decl_data.short_name, method.name) 677 self.assertEquals(mojom_method.decl_data.short_name, method.name)
631 self.assertEquals(interface, method.interface) 678 self.assertEquals(interface, method.interface)
632 self.assertEquals(mojom_method.ordinal, method.ordinal) 679 self.assertEquals(mojom_method.ordinal, method.ordinal)
633 self.assertIsNone(method.response_parameters) 680 self.assertIsNone(method.response_parameters)
634 self.assertEquals( 681 self.assertEquals(
635 len(mojom_method.parameters.fields), len(method.parameters)) 682 len(mojom_method.parameters.fields), len(method.parameters))
636 self.assertEquals(param1.decl_data.short_name, method.parameters[0].name) 683 self.assertEquals(param1.decl_data.short_name, method.parameters[0].name)
637 self.assertEquals(param2.decl_data.short_name, method.parameters[1].name) 684 self.assertEquals(param2.decl_data.short_name, method.parameters[1].name)
685 self.assertEquals('MyInterface_AMethod_Params', method.param_struct.name)
686 self.assertEquals(len(mojom_method.parameters.fields),
687 len(method.param_struct.fields))
688 for i in xrange(0, len(mojom_method.parameters.fields)):
689 gold = mojom_method.parameters.fields[i]
690 f = method.param_struct.fields_in_ordinal_order[i]
691 self.assertEquals(gold.decl_data.short_name, f.name)
692 self.assertEquals(gold.offset, f.computed_offset)
693 self.assertEquals(gold.bit, f.computed_bit)
694 self.assertEquals(gold.min_version, f.computed_min_version)
638 695
639 # Add empty return params. 696 # Add empty return params.
640 mojom_method.response_params = mojom_types_mojom.MojomStruct(fields=[]) 697 mojom_method.response_params = mojom_types_mojom.MojomStruct(fields=[])
698 add_version_info(mojom_method.response_params, 0)
699 add_decl_data(mojom_method.response_params, 'AMethod_Response')
641 method = translator.MethodFromMojom(mojom_method, interface) 700 method = translator.MethodFromMojom(mojom_method, interface)
642 self.assertEquals([], method.response_parameters) 701 self.assertEquals([], method.response_parameters)
643 702
644 # Add non-empty return params. 703 # Add non-empty return params.
645 mojom_method.response_params.fields = [param1] 704 mojom_method.response_params.fields = [param1]
646 method = translator.MethodFromMojom(mojom_method, interface) 705 method = translator.MethodFromMojom(mojom_method, interface)
647 self.assertEquals( 706 self.assertEquals(
648 param1.decl_data.short_name, method.response_parameters[0].name) 707 param1.decl_data.short_name, method.response_parameters[0].name)
649 708
650 def test_parameter(self): 709 def test_parameter(self):
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 mojom_struct = mojom_types_mojom.MojomStruct( 1019 mojom_struct = mojom_types_mojom.MojomStruct(
961 decl_data=mojom_types_mojom.DeclarationData(short_name='FirstStruct')) 1020 decl_data=mojom_types_mojom.DeclarationData(short_name='FirstStruct'))
962 type_key = 'some opaque string' 1021 type_key = 'some opaque string'
963 mojom_struct.fields = [ 1022 mojom_struct.fields = [
964 # Make sure recursive structs are correctly handled. 1023 # Make sure recursive structs are correctly handled.
965 mojom_types_mojom.StructField( 1024 mojom_types_mojom.StructField(
966 decl_data=mojom_types_mojom.DeclarationData(short_name='field00'), 1025 decl_data=mojom_types_mojom.DeclarationData(short_name='field00'),
967 type=mojom_types_mojom.Type( 1026 type=mojom_types_mojom.Type(
968 type_reference=mojom_types_mojom.TypeReference(type_key=type_key))) 1027 type_reference=mojom_types_mojom.TypeReference(type_key=type_key)))
969 ] 1028 ]
1029 add_version_info(mojom_struct, 1)
970 graph.resolved_types = { 1030 graph.resolved_types = {
971 type_key: mojom_types_mojom.UserDefinedType(struct_type=mojom_struct)} 1031 type_key: mojom_types_mojom.UserDefinedType(struct_type=mojom_struct)}
972 1032
973 mojom_type = mojom_types_mojom.Type() 1033 mojom_type = mojom_types_mojom.Type()
974 mojom_type.type_reference = mojom_types_mojom.TypeReference( 1034 mojom_type.type_reference = mojom_types_mojom.TypeReference(
975 type_key=type_key) 1035 type_key=type_key)
976 1036
977 t = mojom_translator.FileTranslator(graph, None) 1037 t = mojom_translator.FileTranslator(graph, None)
978 result = t.KindFromMojom(mojom_type) 1038 result = t.KindFromMojom(mojom_type)
979 self.assertTrue(module.IsStructKind(result)) 1039 self.assertTrue(module.IsStructKind(result))
980 self.assertEquals(mojom_struct.decl_data.short_name, result.name) 1040 self.assertEquals(mojom_struct.decl_data.short_name, result.name)
981 self.assertEquals(result, result.fields[0].kind) 1041 self.assertEquals(result, result.fields[0].kind)
982 self.assertEquals(type_key, result.type_key) 1042 self.assertEquals(type_key, result.type_key)
983 1043
984 # Make sure we create only one module object per type. 1044 # Make sure we create only one module object per type.
985 result2 = t.KindFromMojom(mojom_type) 1045 result2 = t.KindFromMojom(mojom_type)
986 self.assertIs(result, result2) 1046 self.assertIs(result, result2)
987 1047
988 # Nullable type reference 1048 # Nullable type reference
989 mojom_type.type_reference.nullable = True 1049 mojom_type.type_reference.nullable = True
990 nullable_result = t.KindFromMojom(mojom_type) 1050 nullable_result = t.KindFromMojom(mojom_type)
991 self.assertTrue(module.IsNullableKind(nullable_result)) 1051 self.assertTrue(module.IsNullableKind(nullable_result))
992 1052
993 if __name__ == '__main__': 1053 if __name__ == '__main__':
994 unittest.main() 1054 unittest.main()
1055
1056 def build_decl_data(short_name):
1057 """Builds and returns a DeclarationData with the given short_name.
1058
1059 Args:
1060 short_name: {str} short_name to use
1061
1062 Returns:
1063 {mojom_types_mojom.DeclarationData} With the given short_name
1064 """
1065 return mojom_types_mojom.DeclarationData(short_name=short_name)
1066
1067 def add_decl_data(element, short_name):
1068 """Builds a DeclarationData with the given short_name and adds it
1069 as the |decl_data| attribute of |element|.
1070
1071 Args:
1072 element: {any} The Python object to which a |decl_data| attribute will be
1073 added.
1074 short_name: {str} short_name to use
1075 """
1076 element.decl_data=build_decl_data(short_name)
1077
1078 def build_version_info(num_fields):
1079 """Builds and returns a list containing a single StructVersion with
1080 version_number=0, num_bytes=0, and the given value for num_fields.
1081
1082 Args:
1083 num_fields: {int} The value of num_fields to use.
1084 Returns:
1085 {[mojom_types_mojom.StructVersion]} Containing a single element with
1086 the given value for num_fields.
1087 """
1088 return [mojom_types_mojom.StructVersion(
1089 version_number=0, num_bytes=0,num_fields=num_fields)]
1090
1091 def add_version_info(mojom_struct, num_fields):
1092 """Builds a list containing a single StructVersion with
1093 version_number=0, num_bytes=0, and the given value for num_fields. Adds this
1094 as the |version_info| attribute of |mojom_struct|.
1095
1096 Args:
1097 mojom_struct: {any} The Python object to which a |version_info| attribute
1098 will be added.
1099 num_fields: {int} The value of num_fields to use.
1100 """
1101 mojom_struct.version_info=build_version_info(num_fields)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698