Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/SoundPathTableTests.py

Source at documentation-generation time. See Test catalog for fixture associations.

1"""Check that static audio paths stay aligned with their sound IDs."""
2from pathlib import Path
3import ast
4import re
5import unittest
6
7
8def read_sound_table():
9 source = (Path(__file__).resolve().parents[1] / "Sound.h").read_text(encoding="cp1252")
10 source = re.sub(r"//[^\n]*", "", source)
11 enumeration = source.split("enum SOUNDS", 1)[1].split("{", 1)[1].split("};", 1)[0]
12 values = {}
13 value = -1
14 for entry in enumeration.split(","):
15 entry = entry.strip()
16 if not entry:
17 continue
18 if "=" in entry:
19 name, expression = map(str.strip, entry.split("=", 1))
20 if re.fullmatch(r"-?\d+", expression):
21 value = int(expression)
22 else:
23 match = re.fullmatch(r"(\w+)\s*\+\s*(\d+)", expression)
24 if not match:
25 raise ValueError(f"Unsupported sound ID expression: {expression}")
26 value = values[match[1]] + int(match[2])
27 else:
28 name = entry
29 value += 1
30 values[name] = value
31 initializer = source.split("std::vector<std::string> sound_path = {", 1)[1].split("};", 1)[0]
32 paths = [ast.literal_eval(token) for token in re.findall(r'"(?:\\.|[^"\\])*"', initializer)]
33 return values, paths
34
35
36class SoundPathTableTests(unittest.TestCase):
37 def test_every_sound_id_has_a_path_slot(self):
38 ids, paths = read_sound_table()
39 self.assertEqual(len(paths), ids["SOUND_ENUMERATION"])
40 for name, value in ids.items():
41 if name not in ("SOUND_NONE", "SOUND_ENUMERATION"):
42 with self.subTest(sound=name):
43 self.assertGreaterEqual(value, 0)
44 self.assertLess(value, len(paths))
45
46 def test_lazy_cockpit_paths_and_static_sound_mappings(self):
47 ids, paths = read_sound_table()
48 self.assertTrue(all(path == "" for path in paths[:ids["SOUND_THUNDER_NEAR"]]))
49 expected = {
50 "SOUND_THUNDER_NEAR": r"Sounds\Weather\near1.wav",
51 "SOUND_TEST": r"Sounds\GUI\test.wav",
52 "SOUND_HOLIDAY": "",
53 "SOUND_APTRIMCLACKER": r"Sounds\Instruments\coupleraltitude.wav",
54 "SOUND_BACKUP": r"Sounds\steerhead_reverse.wav",
55 "SOUND_RADIOCARRIER11": r"Sounds\Radio\carrier11.mp3",
56 "SOUND_EARPOP3": r"Sounds\People\earpop3.wav",
57 "SOUND_HORNCAR_START": r"Sounds\Horns\car-start.wav",
58 "SOUND_ECTO1_END": r"Sounds\Horns\ecto-end.wav",
59 }
60 for name, path in expected.items():
61 with self.subTest(sound=name):
62 self.assertEqual(paths[ids[name]], path)
63
64
65if __name__ == "__main__":
66 unittest.main()
SCRIPT_CONTROL SCRIPT_STATE const void int