def testImportFromDataNoExtraneousImports(self): """Tests that arrays, maps and interface requests are not imported.""" module = mojom.Module('test_module', 'test_namespace') imported_module = mojom.Module('import_module', 'import_namespace') #TODO(azani): Init values in module.py. imported_module.values = {} imported_data = {'module': imported_module} array = mojom.Array(mojom.INT16, length=20) imported_module.kinds[array.spec] = array map_kind = mojom.Map(mojom.INT16, mojom.INT16) imported_module.kinds[map_kind.spec] = map_kind interface = mojom.Interface('TestInterface', module=module) imported_module.kinds[interface.spec] = interface interface_req = mojom.InterfaceRequest(interface) imported_module.kinds[interface_req.spec] = interface_req data.ImportFromData(module, imported_data) self.assertNotIn(array.spec, module.kinds) self.assertNotIn(map_kind.spec, module.kinds) self.assertNotIn(interface_req.spec, module.kinds)
def _Interface(module, parsed_iface): """ Args: module: {mojom.Module} Module currently being constructed. parsed_iface: {ast.Interface} Parsed interface. Returns: {mojom.Interface} AST interface. """ interface = mojom.Interface(module=module) interface.mojom_name = parsed_iface.mojom_name interface.spec = 'x:' + module.mojom_namespace + '.' + interface.mojom_name module.kinds[interface.spec] = interface interface.enums = list( map(lambda enum: _Enum(module, enum, interface), _ElemsOfType(parsed_iface.body, ast.Enum, parsed_iface.mojom_name))) interface.constants = list( map( lambda constant: _Constant(module, constant, interface), _ElemsOfType(parsed_iface.body, ast.Const, parsed_iface.mojom_name))) # Stash methods parsed_iface here temporarily. interface.methods_data = _ElemsOfType(parsed_iface.body, ast.Method, parsed_iface.mojom_name) interface.attributes = _AttributeListToDict(parsed_iface.attribute_list) return interface
def _Interface(module, parsed_iface): """ Args: module: {mojom.Module} Module currently being constructed. parsed_iface: {ast.Interface} Parsed interface. Returns: {mojom.Interface} AST interface. """ interface = mojom.Interface(module=module) interface.mojom_name = parsed_iface.mojom_name interface.spec = 'x:' + module.GetNamespacePrefix() + interface.mojom_name module.kinds[interface.spec] = interface interface.attributes = _AttributeListToDict(parsed_iface.attribute_list) interface.enums = [] interface.constants = [] interface.methods_data = [] _ProcessElements( parsed_iface.mojom_name, parsed_iface.body, { ast.Enum: lambda enum: interface.enums.append(_Enum(module, enum, interface) ), ast.Const: lambda const: interface.constants.append( _Constant(module, const, interface)), ast.Method: interface.methods_data.append, }) return interface
def testInterfaceAlignment(self): """Tests that interfaces are aligned on 4-byte boundaries, although the size of an interface is 8 bytes. """ kinds = (mojom.INT32, mojom.Interface('test_interface')) fields = (1, 2) offsets = (0, 4) self._CheckPackSequence(kinds, fields, offsets)
def testNullableTypes(self): kinds = (mojom.STRING.MakeNullableKind(), mojom.HANDLE.MakeNullableKind(), mojom.Struct('test_struct').MakeNullableKind(), mojom.DCPIPE.MakeNullableKind(), mojom.Array().MakeNullableKind(), mojom.DPPIPE.MakeNullableKind(), mojom.Array(length=5).MakeNullableKind(), mojom.MSGPIPE.MakeNullableKind(), mojom.Interface('test_interface').MakeNullableKind(), mojom.SHAREDBUFFER.MakeNullableKind(), mojom.InterfaceRequest().MakeNullableKind()) fields = (1, 2, 4, 3, 5, 6, 8, 7, 9, 10, 11) offsets = (0, 8, 12, 16, 24, 32, 36, 40, 48, 56, 60) return self._CheckPackSequence(kinds, fields, offsets)
def testNonInterfaceAsInterfaceRequest(self): """Tests that a non-interface cannot be used for interface requests.""" module = mojom.Module('test_module', 'test_namespace') interface = mojom.Interface('TestInterface', module=module) method_dict = { 'name': 'Foo', 'parameters': [{ 'name': 'foo', 'kind': 'r:i32' }], } with self.assertRaises(Exception) as e: data.MethodFromData(module, method_dict, interface) self.assertEquals( e.exception.__str__(), 'Interface request requires \'i32\' to be an interface.')
def testImportFromDataNoMissingImports(self): """Tests that unions, structs, interfaces and enums are imported.""" module = mojom.Module('test_module', 'test_namespace') imported_module = mojom.Module('import_module', 'import_namespace') #TODO(azani): Init values in module.py. #TODO(azani): Test that values are imported. imported_module.values = {} imported_data = {'module' : imported_module} struct = mojom.Struct('TestStruct', module=module) imported_module.kinds[struct.spec] = struct union = mojom.Union('TestUnion', module=module) imported_module.kinds[union.spec] = union interface = mojom.Interface('TestInterface', module=module) imported_module.kinds[interface.spec] = interface enum = mojom.Enum('TestEnum', module=module) imported_module.kinds[enum.spec] = enum data.ImportFromData(module, imported_data) # Test that the kind was imported. self.assertIn(struct.spec, module.kinds) self.assertEquals(struct.name, module.kinds[struct.spec].name) self.assertIn(union.spec, module.kinds) self.assertEquals(union.name, module.kinds[union.spec].name) self.assertIn(interface.spec, module.kinds) self.assertEquals(interface.name, module.kinds[interface.spec].name) self.assertIn(enum.spec, module.kinds) self.assertEquals(enum.name, module.kinds[enum.spec].name) # Test that the imported kind is a copy and not the original. self.assertIsNot(struct, module.kinds[struct.spec]) self.assertIsNot(union, module.kinds[union.spec]) self.assertIsNot(interface, module.kinds[interface.spec]) self.assertIsNot(enum, module.kinds[enum.spec])