aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_games.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_games.py')
-rw-r--r--tests/test_games.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/test_games.py b/tests/test_games.py
new file mode 100644
index 0000000..4c41367
--- /dev/null
+++ b/tests/test_games.py
@@ -0,0 +1,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()