From f215e02bf85f68d3a6106c2a1f4f7f063f819064 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 11 Apr 2024 10:17:27 +0200 Subject: Adding upstream version 7.0.14-dfsg. Signed-off-by: Daniel Baumann --- .../Source/Python/tests/Split/test_split.py | 115 +++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/tests/Split/test_split.py (limited to 'src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/tests/Split/test_split.py') diff --git a/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/tests/Split/test_split.py b/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/tests/Split/test_split.py new file mode 100644 index 00000000..4e19e636 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/tests/Split/test_split.py @@ -0,0 +1,115 @@ +# @file +# Split a file into two pieces at the request offset. +# +# Copyright (c) 2021, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +# Import Modules +import unittest +import tempfile +import os +import shutil +import Split.Split as sp +import struct as st + + +class TestSplit(unittest.TestCase): + def setUp(self): + self.tmpdir = tempfile.mkdtemp() + self.binary_file = os.path.join(self.tmpdir, "Binary.bin") + self.create_inputfile() + + def tearDown(self): + if os.path.exists(self.tmpdir): + shutil.rmtree(self.tmpdir) + + def test_splitFile_position(self): + position = [-1, 0, 256, 512, 700, 1024, 2048] + result = [(0, 1024), (0, 1024), (256, 768), + (512, 512), (700, 324), (1024, 0), (1024, 0)] + outputfolder = self.tmpdir + for index, po in enumerate(position): + try: + sp.splitFile(self.binary_file, po) + except Exception as e: + self.assertTrue(False, msg="splitFile function error") + + output1 = os.path.join(outputfolder, "Binary.bin1") + output2 = os.path.join(outputfolder, "Binary.bin2") + with open(output1, "rb") as f1: + size1 = len(f1.read()) + with open(output2, "rb") as f2: + size2 = len(f2.read()) + + ex_result = result[index] + self.assertEqual(size1, ex_result[0]) + self.assertEqual(size2, ex_result[1]) + + def create_inputfile(self): + with open(self.binary_file, "wb") as fout: + for i in range(512): + fout.write(st.pack("