Combine tests (#65)

* combine tests

* Delete runtests_local.jl

* More robust defaults, add SampledSignals

* get rid of flush

* get rid of flush, update printing

* Create runtests_local.jl

* Rename test/test/runtests_local.jl to test/runtests_local.jl
This commit is contained in:
bramtayl 2021-05-13 11:42:09 -04:00 committed by GitHub
parent 435e968b5a
commit 06a1a0f243
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 2 deletions

View file

@ -4,7 +4,7 @@ using libportaudio_jll, SampledSignals
import Base: eltype, show
import Base: close, isopen
import Base: read, read!, write, flush
import Base: read, read!, write
import LinearAlgebra
import LinearAlgebra: transpose!
@ -241,7 +241,6 @@ read(stream::PortAudioStream, args...) = read(stream.source, args...)
read!(stream::PortAudioStream, args...) = read!(stream.source, args...)
write(stream::PortAudioStream, args...) = write(stream.sink, args...)
write(sink::PortAudioStream, source::PortAudioStream, args...) = write(sink.sink, source.source, args...)
flush(stream::PortAudioStream) = flush(stream.sink)
function show(io::IO, stream::PortAudioStream)
println(io, typeof(stream))

View file

@ -1,7 +1,9 @@
#!/usr/bin/env julia
using PortAudio
using PortAudio: Pa_GetDefaultInputDevice, Pa_GetDefaultOutputDevice, Pa_GetDeviceInfo, PortAudioDevice
using Test
using SampledSignals
@testset "PortAudio Tests" begin
@testset "Reports version" begin
@ -16,3 +18,74 @@ using Test
PortAudio.devices()
end
end
if !isempty(PortAudio.devices())
# these default values are specific to my machines
inidx = Pa_GetDefaultInputDevice()
default_indev = PortAudioDevice(Pa_GetDeviceInfo(inidx), inidx).name
outidx = Pa_GetDefaultOutputDevice()
default_outdev = PortAudioDevice(Pa_GetDeviceInfo(outidx), outidx).name
@testset "Local Tests" begin
@testset "Open Default Device" begin
println("Recording...")
stream = PortAudioStream(2, 0)
buf = read(stream, 5s)
close(stream)
@test size(buf) == (round(Int, 5 * samplerate(stream)), nchannels(stream.source))
println("Playing back recording...")
stream = PortAudioStream(0, 2)
write(stream, buf)
close(stream)
println("Testing pass-through")
stream = PortAudioStream(2, 2)
write(stream, stream, 5s)
close(stream)
println("done")
end
@testset "Samplerate-converting writing" begin
stream = PortAudioStream(0, 2)
write(stream, SinSource(eltype(stream), samplerate(stream)*0.8, [220, 330]), 3s)
write(stream, SinSource(eltype(stream), samplerate(stream)*1.2, [220, 330]), 3s)
close(stream)
end
@testset "Open Device by name" begin
stream = PortAudioStream(default_indev, default_outdev)
buf = read(stream, 0.001s)
@test size(buf) == (round(Int, 0.001 * samplerate(stream)), nchannels(stream.source))
write(stream, buf)
io = IOBuffer()
show(io, stream)
@test occursin("""
PortAudioStream{Float32}
Samplerate: 44100.0Hz
2 channel sink: "$default_outdev"
2 channel source: "$default_indev\"""", String(take!(io)))
close(stream)
end
@testset "Error on wrong name" begin
@test_throws ErrorException PortAudioStream("foobarbaz")
end
# no way to check that the right data is actually getting read or written here,
# but at least it's not crashing.
@testset "Queued Writing" begin
stream = PortAudioStream(0, 2)
buf = SampleBuf(rand(eltype(stream), 48000, nchannels(stream.sink))*0.1, samplerate(stream))
t1 = @async write(stream, buf)
t2 = @async write(stream, buf)
@test fetch(t1) == 48000
@test fetch(t2) == 48000
close(stream)
end
@testset "Queued Reading" begin
stream = PortAudioStream(2, 0)
buf = SampleBuf(rand(eltype(stream), 48000, nchannels(stream.source))*0.1, samplerate(stream))
t1 = @async read!(stream, buf)
t2 = @async read!(stream, buf)
@test fetch(t1) == 48000
@test fetch(t2) == 48000
close(stream)
end
end
end