def testGetByteSize(self): """Tests the GetByteSize function.""" data_type_definition = data_types.StructureDefinition( u'my_struct_type', aliases=[u'MY_STRUCT_TYPE'], description=u'my structure type') byte_size = data_type_definition.GetByteSize() self.assertIsNone(byte_size) definitions_file = self._GetTestFilePath([u'structure.yaml']) definitions_registry = self._CreateDefinitionRegistryFromFile( definitions_file) member_definition = definitions_registry.GetDefinitionByName(u'int32') structure_member_definition = data_types.StructureMemberDefinition( u'my_struct_member', member_definition, aliases=[u'MY_STRUCT_MEMBER'], data_type=u'int32', description=u'my structure member') data_type_definition.AddMemberDefinition(structure_member_definition) byte_size = data_type_definition.GetByteSize() self.assertEqual(byte_size, 4)
def testGetAttributeNames(self): """Tests the GetAttributeNames function.""" data_type_definition = data_types.StructureDefinition( u'my_struct_type', aliases=[u'MY_STRUCT_TYPE'], description=u'my structure type') attribute_names = data_type_definition.GetAttributeNames() self.assertEqual(attribute_names, []) definitions_file = self._GetTestFilePath([u'structure.yaml']) definitions_registry = self._CreateDefinitionRegistryFromFile( definitions_file) member_definition = definitions_registry.GetDefinitionByName(u'int32') structure_member_definition = data_types.StructureMemberDefinition( u'my_struct_member', member_definition, aliases=[u'MY_STRUCT_MEMBER'], data_type=u'int32', description=u'my structure member') data_type_definition.AddMemberDefinition(structure_member_definition) attribute_names = data_type_definition.GetAttributeNames() self.assertEqual(attribute_names, [u'my_struct_member'])
def testGetStructFormatString(self): """Tests the GetStructFormatString function.""" data_type_definition = data_types.StructureDefinition( u'my_struct_type', aliases=[u'MY_STRUCT_TYPE'], description=u'my structure type') struct_format_string = data_type_definition.GetStructFormatString() self.assertIsNone(struct_format_string) definitions_file = self._GetTestFilePath([u'structure.yaml']) definitions_registry = self._CreateDefinitionRegistryFromFile( definitions_file) member_definition = definitions_registry.GetDefinitionByName(u'int32') structure_member_definition = data_types.StructureMemberDefinition( u'my_struct_member', member_definition, aliases=[u'MY_STRUCT_MEMBER'], data_type=u'int32', description=u'my structure member') data_type_definition.AddMemberDefinition(structure_member_definition) struct_format_string = data_type_definition.GetStructFormatString() self.assertEqual(struct_format_string, u'i') # Test with member without a struct format string. data_type_definition = data_types.StructureDefinition( u'my_struct_type', aliases=[u'MY_STRUCT_TYPE'], description=u'my structure type') member_definition = TestDataTypeDefinition(u'test') structure_member_definition = data_types.StructureMemberDefinition( u'my_struct_member', member_definition, aliases=[u'MY_STRUCT_MEMBER'], data_type=u'test', description=u'my structure member') data_type_definition.AddMemberDefinition(structure_member_definition) struct_format_string = data_type_definition.GetStructFormatString() self.assertIsNone(struct_format_string)
def testIsComposite(self): """Tests the IsComposite function.""" data_type_definition = data_types.StructureDefinition( 'my_struct_type', aliases=['MY_STRUCT_TYPE'], description='my structure type') result = data_type_definition.IsComposite() self.assertTrue(result)
def testReadStructureDataTypeDefinitionMember(self): """Tests the _ReadStructureDataTypeDefinitionMember function.""" definition_values = {u'name': u'x', u'data_type': u'int32'} definition_object = data_types.StructureDefinition(u'point3d') definitions_file = self._GetTestFilePath( [u'definitions', u'integers.yaml']) definitions_registry = self._CreateDefinitionRegistryFromFile( definitions_file) definitions_reader = reader.DataTypeDefinitionsFileReader() definitions_reader._ReadStructureDataTypeDefinitionMember( definitions_registry, definition_values, u'point3d') # TODO: implement. _ = definition_object
def _ReadStructureDataTypeDefinition(self, definitions_registry, definition_values, definition_name): """Reads a structure data type definition. Args: definitions_registry (DataTypeDefinitionsRegistry): data type definitions registry. definition_values (dict[str, object]): definition values. definition_name (str): name of the definition. Returns: StructureDefinition: structure data type definition. Raises: DefinitionReaderError: if the definitions values are missing or if the format is incorrect. """ members = definition_values.get(u'members', None) if not members: error_message = u'missing members' raise errors.DefinitionReaderError(definition_name, error_message) aliases = definition_values.get(u'aliases', None) description = definition_values.get(u'description', None) urls = definition_values.get(u'urls', None) definition_object = data_types.StructureDefinition( definition_name, aliases=aliases, description=description, urls=urls) self._ReadStructureDataTypeDefinitionMembers(definitions_registry, members, definition_object) return definition_object