Skip to content

Commit

Permalink
Add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Jun 22, 2023
1 parent 99574c3 commit 677a1ea
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 2 deletions.
22 changes: 22 additions & 0 deletions tests/streams/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,28 @@
(:run_test ../run_test.exe))
(action (run %{run_test} harbor_metadata.liq liquidsoap %{test_liq} harbor_metadata.liq)))

(rule
(alias citest)
(package liquidsoap)
(deps
hls_id3v2.liq
./file1.mp3
./file2.mp3
./file3.mp3
./jingle1.mp3
./jingle2.mp3
./jingle3.mp3
./file1.png
./file2.png
./jingles
./playlist
./huge_playlist
../../src/bin/liquidsoap.exe
(package liquidsoap)
(:test_liq ../test.liq)
(:run_test ../run_test.exe))
(action (run %{run_test} hls_id3v2.liq liquidsoap %{test_liq} hls_id3v2.liq)))

(rule
(alias citest)
(package liquidsoap)
Expand Down
80 changes: 80 additions & 0 deletions tests/streams/hls_id3v2.liq
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
s = sine()

s = insert_metadata(s)

def f() =
s.insert_metadata([("title", "test title"), ("album","foolol")])
end

thread.run(every=2., f)

s = mksafe(s)

tmp_dir = file.temp_dir("tmp")
on_shutdown({file.rmdir(tmp_dir)})

output.file.hls(
tmp_dir,
[
("aac", %ffmpeg(format="adts",%audio(codec="aac")).{id3_version = 3}),
("ts_with_meta", %ffmpeg(format="mpegts",%audio(codec="aac")).{id3 = true, id3_version = 4}),
("ts", %ffmpeg(format="mpegts",%audio(codec="aac")))
],
s
)

to_check = ref({
aac = null(),
ts_with_meta = null(),
ts = null()
})

def check_done() =
let { aac, ts_with_meta, ts } = to_check()

if null.defined(ts) then test.fail("ts shouldn't have metadata!") end

if null.defined(aac) and null.defined(ts_with_meta) then
aac = null.get(aac)
ts_with_meta = null.get(ts_with_meta)
if aac["title"] == "test title" and ts_with_meta["title"] == "test title" and
aac["album"] == "foolol" and ts_with_meta["album"] == "foolol" then
test.pass()
end
end
end

aac = input.hls("#{tmp_dir}/aac.m3u8")

aac = source.on_metadata(aac, fun (m) -> begin
if m["title"] != "" then
to_check := to_check().{ aac = m }
end
check_done()
end)

output.dummy(fallible=true, aac)

ts_with_meta = input.hls("#{tmp_dir}/ts_with_meta.m3u8")

ts_with_meta = source.on_metadata(ts_with_meta, fun (m) -> begin
if m["title"] != "" then
to_check := to_check().{ ts_with_meta = m }
end
check_done()
end)

output.dummy(fallible=true, ts_with_meta)

ts = input.hls("#{tmp_dir}/ts.m3u8")

ts = source.on_metadata(ts, fun (m) -> begin
if m["title"] != "" then
to_check := to_check().{ ts = m }
end
check_done()
end)

output.dummy(fallible=true, ts)

clock.assign_new(sync="none",[s, aac, ts_with_meta, ts])
5 changes: 3 additions & 2 deletions tests/test.liq
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ def test.pass()
end

# End test with a failure.
def test.fail()
print("Test failed!")
def test.fail(reason = null())
reason = if null.defined(reason) then ": #{null.get(reason)}" else "!" end
print("Test failed#{reason}")
exit(1)
end

Expand Down

0 comments on commit 677a1ea

Please sign in to comment.