Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
  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])