Esempio n. 1
0
    def testReadStructureFromByteStream(self):
        """Tests the _ReadStructureFromByteStream function."""
        output_writer = test_lib.TestOutputWriter()
        test_format = data_format.BinaryDataFormat(debug=True,
                                                   output_writer=output_writer)

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

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

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

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

        with self.assertRaises(errors.ParseError):
            test_format._ReadStructureFromByteStream(
                b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00', 0,
                data_type_map, 'point3d')
Esempio n. 2
0
    def testDebugPrintValue(self):
        """Tests the _DebugPrintValue function."""
        output_writer = test_lib.TestOutputWriter()
        test_format = data_format.BinaryDataFormat(output_writer=output_writer)

        test_format._DebugPrintValue('Description', 'Value')

        expected_output = ['Description\t\t\t\t\t\t\t\t: Value\n']
        self.assertEqual(output_writer.output, expected_output)
Esempio n. 3
0
    def testDebugPrintText(self):
        """Tests the _DebugPrintText function."""
        output_writer = test_lib.TestOutputWriter()
        test_format = data_format.BinaryDataFormat(output_writer=output_writer)

        test_format._DebugPrintText('Text')

        expected_output = ['Text']
        self.assertEqual(output_writer.output, expected_output)
Esempio n. 4
0
    def testDebugPrintData(self):
        """Tests the _DebugPrintData function."""
        output_writer = test_lib.TestOutputWriter()
        test_format = data_format.BinaryDataFormat(output_writer=output_writer)

        data = b'\x00\x01\x02\x03\x04\x05\x06'
        test_format._DebugPrintData('Description', data)

        expected_output = [
            'Description:\n',
            ('0x00000000  00 01 02 03 04 05 06                              '
             '.......\n\n')
        ]
        self.assertEqual(output_writer.output, expected_output)
Esempio n. 5
0
    def testFormatDataInHexadecimal(self):
        """Tests the _FormatDataInHexadecimal function."""
        test_format = data_format.BinaryDataFormat()

        data = b'\x00\x01\x02\x03\x04\x05\x06'
        expected_formatted_data = (
            '0x00000000  00 01 02 03 04 05 06                              '
            '.......\n'
            '\n')
        formatted_data = test_format._FormatDataInHexadecimal(data)
        self.assertEqual(formatted_data, expected_formatted_data)

        data = b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09'
        expected_formatted_data = (
            '0x00000000  00 01 02 03 04 05 06 07  08 09                    '
            '..........\n'
            '\n')
        formatted_data = test_format._FormatDataInHexadecimal(data)
        self.assertEqual(formatted_data, expected_formatted_data)

        data = b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'
        expected_formatted_data = (
            '0x00000000  00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  '
            '................\n'
            '\n')
        formatted_data = test_format._FormatDataInHexadecimal(data)
        self.assertEqual(formatted_data, expected_formatted_data)

        data = (
            b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'
            b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'
            b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'
        )
        expected_formatted_data = (
            '0x00000000  00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  '
            '................\n'
            '...\n'
            '0x00000020  00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  '
            '................\n'
            '\n')
        formatted_data = test_format._FormatDataInHexadecimal(data)
        self.assertEqual(formatted_data, expected_formatted_data)