This commit is contained in:
Nathan Rashleigh committed 2026-05-23 10:17:35 +10:00
1 parent f804c327de
commit 6a32066069
21 files changed
+2028 -1

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
from maple.pdb.strings import EMPTY, encode_devicesql
def test_empty():
assert encode_devicesql("") == EMPTY
def test_short_ascii():
out = encode_devicesql("ON")
# length=3 -> length_and_kind = (3<<1)|1 = 7
assert out == bytes([7]) + b"ON"
def test_longer_ascii():
s = "Hello, World!"
out = encode_devicesql(s)
length = len(s) + 1
assert out[0] == ((length << 1) | 1)
assert out[1:] == s.encode("ascii")
def test_utf16():
s = "ЛаBа"
out = encode_devicesql(s)
assert out[0] == 0x90
# Total length stored = payload_len + 4
payload = s.encode("utf-16-le")
assert out[1:3] == (len(payload) + 4).to_bytes(2, "little")
assert out[3] == 0
assert out[4:] == payload
+29
View File
@@ -0,0 +1,29 @@
from pathlib import Path
from maple.model import Album, Artist, Database, PlaylistEntry, PlaylistNode, Track
from maple.pdb.writer import write_pdb
def test_smoke(tmp_path: Path):
db = Database()
db.artists.append(Artist(id=1, name="AceMo"))
db.albums.append(Album(id=1, name="All My Life", artist_id=1))
db.tracks.append(Track(
id=1, title="Where They At", artist_id=1, album_id=1,
filename="ace.mp3", file_path="/Contents/AceMo/All My Life/ace.mp3",
file_size=14547692, sample_rate=44100, sample_depth=16, bitrate=320,
duration=436, track_number=7, year=2019, date_added="2025-01-04",
))
db.playlist_nodes.append(PlaylistNode(id=1, parent_id=0, sort_order=1, name="MyList"))
db.playlist_entries.append(PlaylistEntry(playlist_id=1, track_id=1, entry_index=1))
out = tmp_path / "export.pdb"
write_pdb(db, out)
assert out.exists()
data = out.read_bytes()
assert len(data) % 4096 == 0
assert data[:4] == b"\x00\x00\x00\x00"
# page_size at offset 4
assert int.from_bytes(data[4:8], "little") == 4096
# num_tables at offset 8
assert int.from_bytes(data[8:12], "little") == 5