1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# deck-it - tests for games
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
import unittest
import deckit.modules.games as games
def lp(s: str) -> bytes:
"""A gamelist.cache string: little-endian u32 length, then the bytes."""
b = s.encode()
return len(b).to_bytes(4, "little") + b
def cache(*entries) -> bytes:
"""A gamelist.cache with (path, serial, title) entries and junk between."""
return b'GLCE"\0\0\0' + b"".join(lp(p) + lp(s) + lp(t) + b"\x01\x02\0\0\x9f" for p, s, t in entries)
class Parsers(unittest.TestCase):
def test_vdf_nested(self):
d = games.vdf('"A"\n{\n\t"name"\t\t"Game \\"X\\""\n\t"apps"\n\t{\n\t\t"10"\t"1"\n\t}\n}\n')
self.assertEqual(d, {"A": {"name": 'Game \\"X\\"', "apps": {"10": "1"}}})
def test_get_ignores_case(self):
self.assertEqual(games._get({"Software": {"valve": {"x": "1"}}}, "software", "Valve", "x"), "1")
self.assertIsNone(games._get({"a": "1"}, "a", "b"))
def test_cache_serials(self):
data = cache(("/g/A (Europe).cue", "SCES-01615", "A (Europe)"),
("/g/B.iso", "SLES-53559", "B - Most Wanted"))
self.assertEqual(games.cache_serials(data),
{"A (Europe)": "SCES-01615", "B - Most Wanted": "SLES-53559"})
def test_cache_serials_garbage(self):
self.assertEqual(games.cache_serials(b"\xff" * 64), {})
if __name__ == "__main__":
unittest.main()
|