Esempio n. 1
0
    def testReadData(self):
        """Tests the _ReadData function."""
        parser = dtfabric_plugin.DtFabricBaseOLECFPlugin()

        file_object = io.BytesIO(
            b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00')

        parser._ReadData(file_object, 0, self._POINT3D_SIZE)

        # Test with missing file-like object.
        with self.assertRaises(ValueError):
            parser._ReadData(None, 0, self._POINT3D_SIZE)

        # Test with file-like object with insufficient data.
        file_object = io.BytesIO(
            b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00')

        with self.assertRaises(errors.ParseError):
            parser._ReadData(file_object, 0, self._POINT3D_SIZE)

        # Test with file-like object that raises an IOError.
        file_object = ErrorBytesIO(
            b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00')

        with self.assertRaises(errors.ParseError):
            parser._ReadData(file_object, 0, self._POINT3D_SIZE)
Esempio n. 2
0
    def testReadStructureFromFileObject(self):
        """Tests the _ReadStructureFromFileObject function."""
        parser = dtfabric_plugin.DtFabricBaseOLECFPlugin()

        file_object = io.BytesIO(
            b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00')

        parser._ReadStructureFromFileObject(file_object, 0, self._POINT3D)

        file_object = io.BytesIO(
            b'\x03\x00\x00\x00'
            b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00'
            b'\x04\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00'
            b'\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00')

        parser._ReadStructureFromFileObject(file_object, 0, self._SHAPE3D)
Esempio n. 3
0
    def testReadStructureFromByteStream(self):
        """Tests the _ReadStructureFromByteStream function."""
        parser = dtfabric_plugin.DtFabricBaseOLECFPlugin()

        parser._ReadStructureFromByteStream(
            b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00', 0,
            self._POINT3D)

        # Test with missing byte stream.
        with self.assertRaises(ValueError):
            parser._ReadStructureFromByteStream(None, 0, self._POINT3D)

        # Test with missing data map type.
        with self.assertRaises(ValueError):
            parser._ReadStructureFromByteStream(
                b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00', 0, None)

        # Test with data type map that raises an dtfabric.MappingError.
        data_type_map = ErrorDataTypeMap(None)

        with self.assertRaises(errors.ParseError):
            parser._ReadStructureFromByteStream(
                b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00', 0,
                data_type_map)