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

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

Issue 1677343002: mojom_types.mojom: Changes the name |interface_name| to |service_name| in struct MojomInterface. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Responds to code review. Created 4 years, 10 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 module_namespace='somens') 66 module_namespace='somens')
67 graph.files = { 67 graph.files = {
68 file_name: mojom_file, 68 file_name: mojom_file,
69 imported_file_name: imported_file, 69 imported_file_name: imported_file,
70 second_level_imported_file_name: second_level_imported_file 70 second_level_imported_file_name: second_level_imported_file
71 } 71 }
72 72
73 mojom_interface = mojom_types_mojom.MojomInterface( 73 mojom_interface = mojom_types_mojom.MojomInterface(
74 methods={}, 74 methods={},
75 decl_data=mojom_types_mojom.DeclarationData( 75 decl_data=mojom_types_mojom.DeclarationData(
76 short_name='AnInterface',
76 source_file_info=mojom_types_mojom.SourceFileInfo( 77 source_file_info=mojom_types_mojom.SourceFileInfo(
77 file_name=file_name)), 78 file_name=file_name)))
78 interface_name='AnInterface')
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)))
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 self.assertEquals(imported_file.module_namespace, 138 self.assertEquals(imported_file.module_namespace,
139 mod.imports[0]['namespace']) 139 mod.imports[0]['namespace'])
140 self.assertEquals(imported_file.file_name, mod.imports[0]['module'].path) 140 self.assertEquals(imported_file.file_name, mod.imports[0]['module'].path)
141 141
142 self.assertEquals(2, len(mod.transitive_imports)) 142 self.assertEquals(2, len(mod.transitive_imports))
143 transitive_imports_paths = [imp['module'].path 143 transitive_imports_paths = [imp['module'].path
144 for imp in mod.transitive_imports] 144 for imp in mod.transitive_imports]
145 self.assertIn(imported_file_name, transitive_imports_paths) 145 self.assertIn(imported_file_name, transitive_imports_paths)
146 self.assertIn(second_level_imported_file_name, transitive_imports_paths) 146 self.assertIn(second_level_imported_file_name, transitive_imports_paths)
147 147
148 self.assertEquals(mojom_interface.interface_name, mod.interfaces[0].name) 148 self.assertEquals('AnInterface', mod.interfaces[0].name)
149 # Interfaces should be assigned their name as their spec. 149 # Interfaces should be assigned their name as their spec.
150 self.assertEquals('AnInterface', mod.interfaces[0].spec) 150 self.assertEquals('AnInterface', mod.interfaces[0].spec)
151 self.assertEquals(mojom_struct.decl_data.short_name, mod.structs[0].name) 151 self.assertEquals(mojom_struct.decl_data.short_name, mod.structs[0].name)
152 # The struct was given a full_identifier so its spec should be that. 152 # The struct was given a full_identifier so its spec should be that.
153 self.assertEquals(mojom_struct.decl_data.full_identifier, 153 self.assertEquals(mojom_struct.decl_data.full_identifier,
154 mod.structs[0].spec) 154 mod.structs[0].spec)
155 self.assertEquals(mojom_union.decl_data.short_name, mod.unions[0].name) 155 self.assertEquals(mojom_union.decl_data.short_name, mod.unions[0].name)
156 # The union was given a short name but not a full_identifier so its spec 156 # The union was given a short name but not a full_identifier so its spec
157 # should be the short name. 157 # should be the short name.
158 self.assertEquals(mojom_union.decl_data.short_name, 158 self.assertEquals(mojom_union.decl_data.short_name,
(...skipping 21 matching lines...) Expand all
180 self.assertEquals([], mod.imports) 180 self.assertEquals([], mod.imports)
181 181
182 @unittest.skipUnless(bindings_imported, 'Could not import python bindings.') 182 @unittest.skipUnless(bindings_imported, 'Could not import python bindings.')
183 class TestUserDefinedFromTypeRef(unittest.TestCase): 183 class TestUserDefinedFromTypeRef(unittest.TestCase):
184 184
185 def do_interface_test(self, nullable, interface_request): 185 def do_interface_test(self, nullable, interface_request):
186 # Build a MojomInterface 186 # Build a MojomInterface
187 file_name = 'a.mojom' 187 file_name = 'a.mojom'
188 mojom_interface = mojom_types_mojom.MojomInterface( 188 mojom_interface = mojom_types_mojom.MojomInterface(
189 decl_data=mojom_types_mojom.DeclarationData( 189 decl_data=mojom_types_mojom.DeclarationData(
190 short_name='AnInterface',
190 source_file_info=mojom_types_mojom.SourceFileInfo( 191 source_file_info=mojom_types_mojom.SourceFileInfo(
191 file_name=file_name)), 192 file_name=file_name)))
192 interface_name='AnInterface')
193 mojom_interface.methods={} 193 mojom_interface.methods={}
194 194
195 # Register the MojomInterface in a MojomFileGraph 195 # Register the MojomInterface in a MojomFileGraph
196 graph = mojom_files_mojom.MojomFileGraph() 196 graph = mojom_files_mojom.MojomFileGraph()
197 type_key = 'some_type_key' 197 type_key = 'some_type_key'
198 graph.resolved_types = { 198 graph.resolved_types = {
199 type_key: mojom_types_mojom.UserDefinedType( 199 type_key: mojom_types_mojom.UserDefinedType(
200 interface_type=mojom_interface)} 200 interface_type=mojom_interface)}
201 201
202 # Build a reference to the interface. 202 # Build a reference to the interface.
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 mojom_types_mojom.Type( 499 mojom_types_mojom.Type(
500 type_reference=mojom_types_mojom.TypeReference( 500 type_reference=mojom_types_mojom.TypeReference(
501 type_key=type_key))) 501 type_key=type_key)))
502 502
503 self.assertEquals( 503 self.assertEquals(
504 translator._transitive_imports['root/c.mojom']['module'], struct.module) 504 translator._transitive_imports['root/c.mojom']['module'], struct.module)
505 self.assertEquals( 505 self.assertEquals(
506 translator._transitive_imports['root/c.mojom'], struct.imported_from) 506 translator._transitive_imports['root/c.mojom'], struct.imported_from)
507 507
508 def test_interface(self): 508 def test_interface(self):
509 self.do_interface_test(True)
510 self.do_interface_test(False)
511
512 def do_interface_test(self, specify_service_name):
509 file_name = 'a.mojom' 513 file_name = 'a.mojom'
510 mojom_interface = mojom_types_mojom.MojomInterface( 514 mojom_interface = mojom_types_mojom.MojomInterface(
511 decl_data=mojom_types_mojom.DeclarationData( 515 decl_data=mojom_types_mojom.DeclarationData(
516 short_name='AnInterface',
512 source_file_info=mojom_types_mojom.SourceFileInfo( 517 source_file_info=mojom_types_mojom.SourceFileInfo(
513 file_name=file_name)), 518 file_name=file_name)))
514 interface_name='AnInterface') 519 if specify_service_name:
520 mojom_interface.service_name = 'test::TheInterface'
521 mojom_interface.decl_data.attributes = [mojom_types_mojom.Attribute(
522 key='ServiceName', value=mojom_types_mojom.LiteralValue(
523 string_value='test::TheInterface'))]
524 else:
525 mojom_interface.service_name = None
515 mojom_method10 = mojom_types_mojom.MojomMethod( 526 mojom_method10 = mojom_types_mojom.MojomMethod(
516 ordinal=10, 527 ordinal=10,
517 decl_data=mojom_types_mojom.DeclarationData( 528 decl_data=mojom_types_mojom.DeclarationData(
518 short_name='AMethod10', 529 short_name='AMethod10',
519 source_file_info=mojom_types_mojom.SourceFileInfo( 530 source_file_info=mojom_types_mojom.SourceFileInfo(
520 file_name=file_name)), 531 file_name=file_name)),
521 parameters=mojom_types_mojom.MojomStruct(fields=[])) 532 parameters=mojom_types_mojom.MojomStruct(fields=[]))
522 mojom_method0 = mojom_types_mojom.MojomMethod( 533 mojom_method0 = mojom_types_mojom.MojomMethod(
523 ordinal=0, 534 ordinal=0,
524 decl_data=mojom_types_mojom.DeclarationData( 535 decl_data=mojom_types_mojom.DeclarationData(
(...skipping 11 matching lines...) Expand all
536 mojom_interface.methods = {10: mojom_method10, 0: mojom_method0, 547 mojom_interface.methods = {10: mojom_method10, 0: mojom_method0,
537 7: mojom_method7} 548 7: mojom_method7}
538 549
539 interface = module.Interface() 550 interface = module.Interface()
540 graph = mojom_files_mojom.MojomFileGraph() 551 graph = mojom_files_mojom.MojomFileGraph()
541 translator = mojom_translator.FileTranslator(graph, file_name) 552 translator = mojom_translator.FileTranslator(graph, file_name)
542 translator.InterfaceFromMojom(interface, mojom_types_mojom.UserDefinedType( 553 translator.InterfaceFromMojom(interface, mojom_types_mojom.UserDefinedType(
543 interface_type=mojom_interface)) 554 interface_type=mojom_interface))
544 555
545 self.assertEquals(translator._module, interface.module) 556 self.assertEquals(translator._module, interface.module)
546 self.assertEquals(mojom_interface.interface_name, interface.name) 557 self.assertEquals('AnInterface', interface.name)
547 self.assertEquals(0, interface.methods[0].ordinal) 558 self.assertEquals(0, interface.methods[0].ordinal)
548 self.assertEquals(7, interface.methods[1].ordinal) 559 self.assertEquals(7, interface.methods[1].ordinal)
549 self.assertEquals(10, interface.methods[2].ordinal) 560 self.assertEquals(10, interface.methods[2].ordinal)
561 if specify_service_name:
562 self.assertEquals('test::TheInterface', interface.service_name)
563 else:
564 self.assertEquals(None, interface.service_name)
565
550 # TODO(azani): Add the contained declarations. 566 # TODO(azani): Add the contained declarations.
551 567
552 def test_method(self): 568 def test_method(self):
553 file_name = 'a.mojom' 569 file_name = 'a.mojom'
554 mojom_method = mojom_types_mojom.MojomMethod( 570 mojom_method = mojom_types_mojom.MojomMethod(
555 ordinal=10, 571 ordinal=10,
556 decl_data=mojom_types_mojom.DeclarationData( 572 decl_data=mojom_types_mojom.DeclarationData(
557 short_name='AMethod', 573 short_name='AMethod',
558 source_file_info=mojom_types_mojom.SourceFileInfo( 574 source_file_info=mojom_types_mojom.SourceFileInfo(
559 file_name=file_name))) 575 file_name=file_name)))
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 result2 = t.KindFromMojom(mojom_type) 947 result2 = t.KindFromMojom(mojom_type)
932 self.assertIs(result, result2) 948 self.assertIs(result, result2)
933 949
934 # Nullable type reference 950 # Nullable type reference
935 mojom_type.type_reference.nullable = True 951 mojom_type.type_reference.nullable = True
936 nullable_result = t.KindFromMojom(mojom_type) 952 nullable_result = t.KindFromMojom(mojom_type)
937 self.assertTrue(module.IsNullableKind(nullable_result)) 953 self.assertTrue(module.IsNullableKind(nullable_result))
938 954
939 if __name__ == '__main__': 955 if __name__ == '__main__':
940 unittest.main() 956 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698