コード例 #1
0
ファイル: reader.py プロジェクト: pombredanne/dtfabric
    def testReadUUIDDataTypeDefinition(self):
        """Tests the _ReadUUIDDataTypeDefinition function."""
        definition_values = {
            u'aliases': [u'guid', u'GUID', u'UUID'],
            u'attributes': {
                u'byte_order': u'little-endian',
            },
            u'description':
            (u'Globally or Universal unique identifier (GUID or UUID) type'),
        }

        definitions_registry = registry.DataTypeDefinitionsRegistry()
        definitions_reader = reader.DataTypeDefinitionsFileReader()

        data_type_definition = definitions_reader._ReadUUIDDataTypeDefinition(
            definitions_registry, definition_values, u'uuid')
        self.assertIsNotNone(data_type_definition)
        self.assertIsInstance(data_type_definition, data_types.UUIDDefinition)

        # Test with unsupported size.
        definition_values[u'attributes'][u'size'] = 32

        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader._ReadUUIDDataTypeDefinition(
                definitions_registry, definition_values, u'uuid')
コード例 #2
0
ファイル: reader.py プロジェクト: pombredanne/dtfabric
    def testReadDefinitionFromDict(self):
        """Tests the ReadDefinitionFromDict function."""
        definition_values = {
            u'aliases': [u'LONG', u'LONG32'],
            u'attributes': {
                u'format': u'signed',
                u'size': 4,
            },
            u'description': u'signed 32-bit integer type',
            u'name': u'int32',
            u'type': u'integer',
        }

        definitions_registry = registry.DataTypeDefinitionsRegistry()
        definitions_reader = reader.DataTypeDefinitionsFileReader()

        data_type_definition = definitions_reader.ReadDefinitionFromDict(
            definitions_registry, definition_values)
        self.assertIsNotNone(data_type_definition)
        self.assertIsInstance(data_type_definition,
                              data_types.IntegerDefinition)

        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader.ReadDefinitionFromDict(definitions_registry,
                                                      None)

        definition_values[u'type'] = u'bogus'
        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader.ReadDefinitionFromDict(definitions_registry,
                                                      definition_values)
コード例 #3
0
ファイル: reader.py プロジェクト: pombredanne/dtfabric
    def testReadIntegerDataTypeDefinition(self):
        """Tests the _ReadIntegerDataTypeDefinition function."""
        definition_values = {
            u'aliases': [u'LONG', u'LONG32'],
            u'attributes': {
                u'format': u'signed',
                u'size': 4,
            },
            u'description': u'signed 32-bit integer type',
        }

        definitions_registry = registry.DataTypeDefinitionsRegistry()
        definitions_reader = reader.DataTypeDefinitionsFileReader()

        data_type_definition = definitions_reader._ReadIntegerDataTypeDefinition(
            definitions_registry, definition_values, u'int32')
        self.assertIsNotNone(data_type_definition)
        self.assertIsInstance(data_type_definition,
                              data_types.IntegerDefinition)

        # Test with unsupported format attribute.
        definition_values[u'attributes'][u'format'] = u'bogus'

        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader._ReadIntegerDataTypeDefinition(
                definitions_registry, definition_values, u'int32')
コード例 #4
0
ファイル: reader.py プロジェクト: pombredanne/dtfabric
    def testReadConstantDataTypeDefinition(self):
        """Tests the _ReadConstantDataTypeDefinition function."""
        definition_values = {
            u'aliases': [u'AVRF_MAX_TRACES'],
            u'description':
            (u'Application verifier resource enumeration maximum number of '
             u'back traces'),
            u'value':
            32,
        }

        definitions_registry = registry.DataTypeDefinitionsRegistry()
        definitions_reader = reader.DataTypeDefinitionsFileReader()

        data_type_definition = (
            definitions_reader._ReadConstantDataTypeDefinition(
                definitions_registry, definition_values, u'const'))
        self.assertIsNotNone(data_type_definition)
        self.assertIsInstance(data_type_definition,
                              data_types.ConstantDefinition)

        # Test with missing value definition.
        del definition_values[u'value']

        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader._ReadConstantDataTypeDefinition(
                definitions_registry, definition_values, u'const')
コード例 #5
0
ファイル: reader.py プロジェクト: pombredanne/dtfabric
    def testReadFile(self):
        """Tests the ReadFile function."""
        definitions_file = self._GetTestFilePath(
            [u'definitions', u'integers.yaml'])

        definitions_registry = registry.DataTypeDefinitionsRegistry()
        definitions_reader = reader.DataTypeDefinitionsFileReader()

        definitions_reader.ReadFile(definitions_registry, definitions_file)
コード例 #6
0
ファイル: reader.py プロジェクト: pombredanne/dtfabric
    def testReadSequenceDataTypeDefinition(self):
        """Tests the _ReadSequenceDataTypeDefinition function."""
        definition_values = {
            u'description': u'vector with 4 elements',
            u'element_data_type': u'int32',
            u'number_of_elements': 4,
        }

        definitions_file = self._GetTestFilePath(
            [u'definitions', u'integers.yaml'])
        definitions_registry = self._CreateDefinitionRegistryFromFile(
            definitions_file)
        definitions_reader = reader.DataTypeDefinitionsFileReader()

        data_type_definition = (
            definitions_reader._ReadSequenceDataTypeDefinition(
                definitions_registry, definition_values, u'vector4'))
        self.assertIsNotNone(data_type_definition)
        self.assertIsInstance(data_type_definition,
                              data_types.SequenceDefinition)

        # Test with undefined element data type.
        definition_values[u'element_data_type'] = u'bogus'

        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader._ReadSequenceDataTypeDefinition(
                definitions_registry, definition_values, u'vector4')

        definition_values[u'element_data_type'] = u'int32'

        # Test with missing element data type definition.
        del definition_values[u'element_data_type']

        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader._ReadSequenceDataTypeDefinition(
                definitions_registry, definition_values, u'vector4')

        definition_values[u'element_data_type'] = u'int32'

        # Test with missing number of elements definition.
        del definition_values[u'number_of_elements']

        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader._ReadSequenceDataTypeDefinition(
                definitions_registry, definition_values, u'vector4')

        definition_values[u'number_of_elements'] = 4

        # Test with unusuported attributes definition.
        definition_values[u'attributes'] = {u'byte_order': u'little-endian'}

        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader._ReadSequenceDataTypeDefinition(
                definitions_registry, definition_values, u'vector4')

        del definition_values[u'attributes']
コード例 #7
0
ファイル: reader.py プロジェクト: pombredanne/dtfabric
    def testReadDirectory(self):
        """Tests the ReadDirectory function."""
        definitions_directory = self._GetTestFilePath([u'definitions'])

        definitions_registry = registry.DataTypeDefinitionsRegistry()
        definitions_reader = reader.DataTypeDefinitionsFileReader()

        definitions_reader.ReadDirectory(definitions_registry,
                                         definitions_directory)

        definitions_reader.ReadDirectory(definitions_registry,
                                         definitions_directory,
                                         extension=u'yaml')
コード例 #8
0
ファイル: reader.py プロジェクト: pombredanne/dtfabric
    def testReadStructureDataTypeDefinition(self):
        """Tests the _ReadStructureDataTypeDefinition function."""
        definition_values = {
            u'aliases': [u'POINT'],
            u'attributes': {
                u'byte_order': u'little-endian',
            },
            u'description':
            u'Point in 3 dimensional space.',
            u'members': [{
                u'name': u'x',
                u'data_type': u'int32'
            }, {
                u'name': u'y',
                u'data_type': u'int32'
            }, {
                u'name': u'z',
                u'data_type': u'int32'
            }],
        }

        definitions_file = self._GetTestFilePath(
            [u'definitions', u'integers.yaml'])
        definitions_registry = self._CreateDefinitionRegistryFromFile(
            definitions_file)
        definitions_reader = reader.DataTypeDefinitionsFileReader()

        data_type_definition = (
            definitions_reader._ReadStructureDataTypeDefinition(
                definitions_registry, definition_values, u'point3d'))
        self.assertIsNotNone(data_type_definition)
        self.assertIsInstance(data_type_definition,
                              data_types.StructureDefinition)

        # Test with undefined data type.
        definition_values[u'members'][1][u'data_type'] = u'bogus'

        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader._ReadStructureDataTypeDefinition(
                definitions_registry, definition_values, u'point3d')

        # Test with missing member definitions.
        del definition_values[u'members']

        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader._ReadStructureDataTypeDefinition(
                definitions_registry, definition_values, u'point3d')
コード例 #9
0
ファイル: reader.py プロジェクト: pombredanne/dtfabric
    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
コード例 #10
0
ファイル: reader.py プロジェクト: pombredanne/dtfabric
    def testReadCharacterDataTypeDefinition(self):
        """Tests the _ReadCharacterDataTypeDefinition function."""
        definition_values = {
            u'aliases': [u'CHAR'],
            u'attributes': {
                u'size': 1,
            },
            u'description': u'8-bit character type',
        }

        definitions_registry = registry.DataTypeDefinitionsRegistry()
        definitions_reader = reader.DataTypeDefinitionsFileReader()

        data_type_definition = definitions_reader._ReadCharacterDataTypeDefinition(
            definitions_registry, definition_values, u'char')
        self.assertIsNotNone(data_type_definition)
        self.assertIsInstance(data_type_definition,
                              data_types.CharacterDefinition)
コード例 #11
0
ファイル: reader.py プロジェクト: pombredanne/dtfabric
    def testReadBooleanDataTypeDefinition(self):
        """Tests the _ReadBooleanDataTypeDefinition function."""
        definition_values = {
            u'aliases': [u'BOOL'],
            u'attributes': {
                u'size': 4,
            },
            u'description': u'32-bit boolean type',
        }

        definitions_registry = registry.DataTypeDefinitionsRegistry()
        definitions_reader = reader.DataTypeDefinitionsFileReader()

        data_type_definition = definitions_reader._ReadBooleanDataTypeDefinition(
            definitions_registry, definition_values, u'bool')
        self.assertIsNotNone(data_type_definition)
        self.assertIsInstance(data_type_definition,
                              data_types.BooleanDefinition)
コード例 #12
0
ファイル: reader.py プロジェクト: pombredanne/dtfabric
    def testReadFormatDefinition(self):
        """Tests the _ReadFormatDefinition function."""
        definition_values = {
            u'description': u'Windows Shortcut (LNK) file format',
            u'type': u'format',
        }

        definitions_registry = registry.DataTypeDefinitionsRegistry()
        definitions_reader = reader.DataTypeDefinitionsFileReader()

        # TODO: implement.
        _ = definitions_registry

        data_type_definition = definitions_reader._ReadFormatDefinition(
            definition_values, u'lnk')
        self.assertIsNotNone(data_type_definition)
        self.assertIsInstance(data_type_definition,
                              data_types.FormatDefinition)
コード例 #13
0
ファイル: reader.py プロジェクト: pombredanne/dtfabric
    def testReadFixedSizeDataTypeDefinition(self):
        """Tests the _ReadFixedSizeDataTypeDefinition function."""
        definition_values = {
            u'aliases': [u'LONG', u'LONG32'],
            u'attributes': {
                u'byte_order': u'little-endian',
                u'size': 4,
            },
            u'description': u'signed 32-bit integer type',
        }

        definitions_registry = registry.DataTypeDefinitionsRegistry()
        definitions_reader = reader.DataTypeDefinitionsFileReader()

        data_type_definition = definitions_reader._ReadFixedSizeDataTypeDefinition(
            definitions_registry, definition_values,
            data_types.IntegerDefinition, u'int32')
        self.assertIsNotNone(data_type_definition)
        self.assertIsInstance(data_type_definition,
                              data_types.IntegerDefinition)
        self.assertEqual(data_type_definition.byte_order,
                         definitions.BYTE_ORDER_LITTLE_ENDIAN)
        self.assertEqual(data_type_definition.size, 4)

        # Test with incorrect byte-order.
        definition_values[u'attributes'][u'byte_order'] = u'bogus'

        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader._ReadFixedSizeDataTypeDefinition(
                definitions_registry, definition_values,
                data_types.IntegerDefinition, u'int32')

        definition_values[u'attributes'][u'byte_order'] = u'little-endian'

        # Test with incorrect size.
        definition_values[u'attributes'][u'size'] = u'bogus'

        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader._ReadFixedSizeDataTypeDefinition(
                definitions_registry, definition_values,
                data_types.IntegerDefinition, u'int32')

        definition_values[u'attributes'][u'size'] = 4
コード例 #14
0
ファイル: reader.py プロジェクト: pombredanne/dtfabric
    def testReadFloatingPointDataTypeDefinition(self):
        """Tests the _ReadFloatingPointDataTypeDefinition function."""
        definition_values = {
            u'aliases': [u'float', u'FLOAT'],
            u'attributes': {
                u'size': 4,
            },
            u'description': u'32-bit floating-point type',
        }

        definitions_registry = registry.DataTypeDefinitionsRegistry()
        definitions_reader = reader.DataTypeDefinitionsFileReader()

        data_type_definition = (
            definitions_reader._ReadFloatingPointDataTypeDefinition(
                definitions_registry, definition_values, u'float32'))
        self.assertIsNotNone(data_type_definition)
        self.assertIsInstance(data_type_definition,
                              data_types.FloatingPointDefinition)
コード例 #15
0
ファイル: reader.py プロジェクト: pombredanne/dtfabric
    def testReadEnumerationDataTypeDefinition(self):
        """Tests the _ReadEnumerationDataTypeDefinition function."""
        definition_values = {
            u'description':
            u'Minidump object information type',
            u'values': [
                {
                    u'description':
                    u'No object-specific information available',
                    u'name': u'MiniHandleObjectInformationNone',
                    u'value': 0
                },
                {
                    u'description': u'Thread object information',
                    u'name': u'MiniThreadInformation1',
                    u'value': 1
                },
            ],
        }

        definitions_registry = registry.DataTypeDefinitionsRegistry()
        definitions_reader = reader.DataTypeDefinitionsFileReader()

        data_type_definition = (
            definitions_reader._ReadEnumerationDataTypeDefinition(
                definitions_registry, definition_values, u'enum'))
        self.assertIsNotNone(data_type_definition)
        self.assertIsInstance(data_type_definition,
                              data_types.EnumerationDefinition)

        # Test with missing name in enumeration value definition.
        del definition_values[u'values'][-1][u'name']

        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader._ReadEnumerationDataTypeDefinition(
                definitions_registry, definition_values, u'enum')

        definition_values[u'values'][-1][u'name'] = u'MiniThreadInformation1'

        # Test with missing value in enumeration value definition.
        del definition_values[u'values'][-1][u'value']

        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader._ReadEnumerationDataTypeDefinition(
                definitions_registry, definition_values, u'enum')

        definition_values[u'values'][-1][u'value'] = 1

        # Test with duplicate enumeration value definition.
        definition_values[u'values'].append({
            u'description': u'Thread object information',
            u'name': u'MiniThreadInformation1',
            u'value': 1
        })

        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader._ReadEnumerationDataTypeDefinition(
                definitions_registry, definition_values, u'enum')

        del definition_values[u'values'][-1]

        # Test with missing enumeration value definitions.
        del definition_values[u'values']

        with self.assertRaises(errors.DefinitionReaderError):
            definitions_reader._ReadEnumerationDataTypeDefinition(
                definitions_registry, definition_values, u'enum')