Пример #1
0
    def test_map_type(self):
        map_types = [
            (False, False),
            (True, False),
            (False, True),
            (True, True),
        ]
        g = mojom_files_mojom.MojomFileGraph()
        t = mojom_translator.FileTranslator(g, None)

        for map_nullable, value_nullable in map_types:
            m = mojom_types_mojom.Type()
            m.map_type = mojom_types_mojom.MapType(nullable=map_nullable)
            m.map_type.key_type = mojom_types_mojom.Type(
                string_type=mojom_types_mojom.StringType())
            m.map_type.value_type = mojom_types_mojom.Type(
                handle_type=mojom_types_mojom.HandleType(
                    kind=mojom_types_mojom.HandleType.Kind.SHARED_BUFFER,
                    nullable=value_nullable))

            result = t.KindFromMojom(m)
            self.assertTrue(module.IsMapKind(result))
            self.assertTrue(module.IsStringKind(result.key_kind))
            self.assertTrue(module.IsSharedBufferKind(result.value_kind))
            self.assertEquals(map_nullable, module.IsNullableKind(result))
            self.assertEquals(value_nullable,
                              module.IsNullableKind(result.value_kind))
Пример #2
0
    def test_map_type(self):
        map_types = [
            (False, False),
            (True, False),
            (False, True),
            (True, True),
        ]
        g = fidl_files_fidl.FidlFileGraph()
        t = mojom_translator.FileTranslator(g, None)

        for map_nullable, value_nullable in map_types:
            m = fidl_types_fidl.Type()
            m.map_type = fidl_types_fidl.MapType(nullable=map_nullable)
            m.map_type.key_type = fidl_types_fidl.Type(
                string_type=fidl_types_fidl.StringType())
            m.map_type.value_type = fidl_types_fidl.Type(
                handle_type=fidl_types_fidl.HandleType(
                    kind=fidl_types_fidl.HandleType.Kind.VMO,
                    nullable=value_nullable))

            result = t.KindFromMojom(m)
            self.assertTrue(module.IsMapKind(result))
            self.assertTrue(module.IsStringKind(result.key_kind))
            self.assertTrue(module.IsVMOKind(result.value_kind))
            self.assertEquals(map_nullable, module.IsNullableKind(result))
            self.assertEquals(value_nullable,
                              module.IsNullableKind(result.value_kind))
Пример #3
0
 def extract_referenced_user_kinds(kind):
     if mojom.IsArrayKind(kind):
         return extract_referenced_user_kinds(kind.kind)
     if mojom.IsMapKind(kind):
         return (extract_referenced_user_kinds(kind.key_kind) +
                 extract_referenced_user_kinds(kind.value_kind))
     if mojom.IsInterfaceRequestKind(kind) or mojom.IsAssociatedKind(kind):
         return [kind.kind]
     if mojom.IsStructKind(kind):
         return [kind]
     if (mojom.IsInterfaceKind(kind) or mojom.IsEnumKind(kind)
             or mojom.IsUnionKind(kind)):
         return [kind]
     return []
Пример #4
0
    def AddImport(element):
      """AddImport is a utility function that adds the import of the provided
      element to the used dictionary defined above.
      """
      # Only named values or kinds could be imported.
      if (not isinstance(element, mojom.Kind) and
          not isinstance(element, mojom.NamedValue)):
        return

      if mojom.IsArrayKind(element) or mojom.IsInterfaceRequestKind(element):
        AddImport(element.kind)
        return
      if mojom.IsMapKind(element):
        AddImport(element.key_kind)
        AddImport(element.value_kind)
        return
      if not hasattr(element, 'imported_from') or not element.imported_from:
        return

      imported_from = element.imported_from
      used[imported_from['module'].path] = imported_from