diff options
Diffstat (limited to 'tests/test_script_qtable.py')
| -rw-r--r-- | tests/test_script_qtable.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/test_script_qtable.py b/tests/test_script_qtable.py index a9176d889..c405620c7 100644 --- a/tests/test_script_qtable.py +++ b/tests/test_script_qtable.py | |||
| @@ -333,6 +333,51 @@ class ScriptQtableTests(unittest.TestCase): | |||
| 333 | self.assertFalse(rep["valid"]) | 333 | self.assertFalse(rep["valid"]) |
| 334 | self.assertEqual(rep["cross_tree_edges"], n - 1) | 334 | self.assertEqual(rep["cross_tree_edges"], n - 1) |
| 335 | 335 | ||
| 336 | def test_bin_folder_sorts_hex_offsets_numerically_and_skips_bin_subdirs(self): | ||
| 337 | # Build a 2-chunk qtable (> 64 KiB) split across unpadded hex names 90000.bin and 100000.bin. | ||
| 338 | # Lexicographic sort puts 100000.bin before 90000.bin, and a subdir ending in .bin used to crash. | ||
| 339 | table_end = 40 + 2 * 8 | ||
| 340 | first_off = (table_end + 15) & ~15 | ||
| 341 | off0 = first_off | ||
| 342 | off1 = 65536 + 16 # second record starts in chunk 2 so chunk 1 alone is incomplete | ||
| 343 | root_rec = struct.pack("<4I2Q", 0x11111111, 0, 0xAAAA0001, 0, Q_PTR_HIGH | (off1 + 8), 0) + bytes(off1 - off0 - 32) | ||
| 344 | child_rec = struct.pack("<4I", 0, 0, 0xAAAA0002, 0) + bytes(16) | ||
| 345 | blob = ( | ||
| 346 | struct.pack("<10I", 0, 0, 0, 0, 0, 2, 0, 0, 0, 0) | ||
| 347 | + struct.pack("<2Q", off0, off1) | ||
| 348 | + bytes(first_off - table_end) | ||
| 349 | + root_rec | ||
| 350 | + child_rec | ||
| 351 | ) | ||
| 352 | self.assertGreater(len(blob), 65536) | ||
| 353 | with tempfile.TemporaryDirectory() as d: | ||
| 354 | os.mkdir(os.path.join(d, "000000.bin")) | ||
| 355 | with open(os.path.join(d, "90000.bin"), "wb") as f: | ||
| 356 | f.write(blob[:65536]) | ||
| 357 | with open(os.path.join(d, "100000.bin"), "wb") as f: | ||
| 358 | f.write(blob[65536:]) | ||
| 359 | loaded, meta = script_qtable.load_qtable_payload(d) | ||
| 360 | self.assertEqual(loaded, blob) | ||
| 361 | self.assertEqual((meta["offset"], meta["chunks"]), (0x90000, 2)) | ||
| 362 | |||
| 363 | def test_type_query_sorts_histograms_numerically(self): | ||
| 364 | # Two structs sharing the same type hash with sizes 32 and 112: "32" must come before "112". | ||
| 365 | table_end = 40 + 2 * 8 | ||
| 366 | first_off = (table_end + 15) & ~15 | ||
| 367 | off0 = first_off | ||
| 368 | off1 = off0 + 32 | ||
| 369 | r0 = struct.pack("<4I2Q", 0x22222222, 0, 0xBBBB0001, 0, Q_PTR_HIGH | (off1 + 8), 0) | ||
| 370 | r1 = struct.pack("<4I", 0, 0, 0xBBBB0001, 0) + bytes(112 - 16) | ||
| 371 | blob = ( | ||
| 372 | struct.pack("<10I", 0, 0, 0, 0, 0, 2, 0, 0, 0, 0) | ||
| 373 | + struct.pack("<2Q", off0, off1) | ||
| 374 | + bytes(first_off - table_end) | ||
| 375 | + r0 | ||
| 376 | + r1 | ||
| 377 | ) | ||
| 378 | rep = script_qtable.parse_qtable(blob, type_hash=0xBBBB0001) | ||
| 379 | self.assertEqual(list(rep["type_query"]["struct_sizes"].keys()), ["32", "112"]) | ||
| 380 | |||
| 336 | 381 | ||
| 337 | if __name__ == "__main__": | 382 | if __name__ == "__main__": |
| 338 | unittest.main() | 383 | unittest.main() |