diff --git a/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_source.cpp b/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_source.cpp index 3aaace12e..ee9a04825 100644 --- a/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_source.cpp +++ b/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_source.cpp @@ -370,7 +370,7 @@ bool SoxSource::open_() { is_file_ = !(input_->handler.flags & SOX_FILE_DEVICE); - if(is_file_ && in_signal_.rate != input_->signal.rate && in_signal_.rate != 0){ + if(is_file_ && sample_spec_.sample_rate() != input_->signal.rate && sample_spec_.sample_rate() != 0){ roc_log(LogInfo, "sndfile source: can't set rate: samplerate in argument is different from file samplerate"); return false; } diff --git a/src/tests/roc_sndio/target_sndfile/test_sndfile_source.cpp b/src/tests/roc_sndio/target_sndfile/test_sndfile_source.cpp deleted file mode 100644 index ef322f8b8..000000000 --- a/src/tests/roc_sndio/target_sndfile/test_sndfile_source.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (c) 2023 Roc Streaming authors - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#include - -#include "test_helpers/mock_source.h" - -#include "roc_core/buffer_factory.h" -#include "roc_core/heap_arena.h" -#include "roc_core/stddefs.h" -#include "roc_core/temp_file.h" -#include "roc_sndio/pump.h" -#include "roc_sndio/sndfile_sink.h" -#include "roc_sndio/sndfile_source.h" - -namespace roc { -namespace sndio { - -namespace { - -enum { - MaxBufSize = 8192, - FrameSize = 500, - SampleRate = 44100, - ChMask = 0x3, - NumChans = 2 -}; - -const audio::SampleSpec - SampleSpecs(SampleRate, audio::Sample_RawFormat, audio::ChanLayout_Surround, audio::ChanOrder_Smpte, ChMask); - -const core::nanoseconds_t FrameDuration = FrameSize * core::Second - / core::nanoseconds_t(SampleSpecs.sample_rate() * SampleSpecs.num_channels()); - -core::HeapArena arena; -core::BufferFactory buffer_factory(arena, MaxBufSize); - -} // namespace - -TEST_GROUP(sndfile_source) { - Config sink_config; - Config source_config; - - void setup() { - sink_config.sample_spec = audio::SampleSpec( - SampleRate, audio::Sample_RawFormat, audio::ChanLayout_Surround, audio::ChanOrder_Smpte, ChMask); - sink_config.frame_length = FrameDuration; - - source_config.sample_spec = audio::SampleSpec( - SampleRate, audio::Sample_RawFormat, audio::ChanLayout_Surround, audio::ChanOrder_Smpte, ChMask); - source_config.frame_length = FrameDuration; - } -}; - -TEST(sndfile_source, noop) { - SndfileSource sndfile_source(arena, source_config); -} - -TEST(sndfile_source, error) { - SndfileSource sndfile_source(arena, source_config); - - CHECK(!sndfile_source.open(NULL, "/bad/file")); -} - -TEST(sndfile_source, has_clock) { - core::TempFile file("test.wav"); - - { - test::MockSource mock_source; - mock_source.add(MaxBufSize * 10); - - SndfileSink sndfile_sink(arena, sink_config); - CHECK(sndfile_sink.open(NULL, file.path())); - - Pump pump(buffer_factory, mock_source, NULL, sndfile_sink, FrameDuration, - SampleSpecs, Pump::ModeOneshot); - CHECK(pump.is_valid()); - CHECK(pump.run()); - } - - SndfileSource sndfile_source(arena, source_config); - - CHECK(sndfile_source.open(NULL, file.path())); - CHECK(!sndfile_source.has_clock()); -} - - -TEST(sndfile_source, sample_rate_auto) { - core::TempFile file("test.wav"); - - { - test::MockSource mock_source; - mock_source.add(MaxBufSize * 10); - - SndfileSink sndfile_sink(arena, sink_config); - CHECK(sndfile_sink.open(NULL, file.path())); - - Pump pump(buffer_factory, mock_source, NULL, sndfile_sink, FrameDuration, - SampleSpecs, Pump::ModeOneshot); - CHECK(pump.is_valid()); - CHECK(pump.run()); - } - - source_config.sample_spec.set_sample_rate(0); - source_config.frame_length = FrameDuration; - SndfileSource sndfile_source(arena, source_config); - - CHECK(sndfile_source.open(NULL, file.path())); - CHECK(sndfile_source.sample_spec().sample_rate() == SampleRate); -} - -TEST(sndfile_source, sample_rate_mismatch) { - core::TempFile file("test.wav"); - - { - test::MockSource mock_source; - mock_source.add(MaxBufSize * 10); - - SndfileSink sndfile_sink(arena, sink_config); - CHECK(sndfile_sink.open(NULL, file.path())); - - Pump pump(buffer_factory, mock_source, NULL, sndfile_sink, FrameDuration, - SampleSpecs, Pump::ModeOneshot); - CHECK(pump.is_valid()); - CHECK(pump.run()); - } - - source_config.sample_spec.set_sample_rate(SampleRate * 2); - SndfileSource sndfile_source(arena, source_config); - - CHECK(!sndfile_source.open(NULL, file.path())); -} - -TEST(sndfile_source, pause_resume) { - core::TempFile file("test.wav"); - - { - test::MockSource mock_source; - mock_source.add(FrameSize * NumChans * 2); - - SndfileSink sndfile_sink(arena, sink_config); - CHECK(sndfile_sink.open(NULL, file.path())); - - Pump pump(buffer_factory, mock_source, NULL, sndfile_sink, FrameDuration, SampleSpecs, - Pump::ModeOneshot); - CHECK(pump.is_valid()); - CHECK(pump.run()); - } - - SndfileSource sndfile_source(arena, source_config); - - CHECK(sndfile_source.open(NULL, file.path())); - - audio::sample_t frame_data1[FrameSize * NumChans] = {}; - audio::Frame frame1(frame_data1, FrameSize * NumChans); - - CHECK(sndfile_source.state() == DeviceState_Active); - CHECK(sndfile_source.read(frame1)); - - sndfile_source.pause(); - CHECK(sndfile_source.state() == DeviceState_Active); - - audio::sample_t frame_data2[FrameSize * NumChans] = {}; - audio::Frame frame2(frame_data2, FrameSize * NumChans); - - CHECK(sndfile_source.read(frame2)); - - CHECK(sndfile_source.resume()); - CHECK(sndfile_source.state() == DeviceState_Active); - - CHECK(!sndfile_source.read(frame2)); - - if (memcmp(frame_data1, frame_data2, sizeof(frame_data1)) == 0) { - FAIL("frames should not be equal"); - } -} - -TEST(sndfile_source, pause_restart) { - core::TempFile file("test.wav"); - - { - test::MockSource mock_source; - mock_source.add(FrameSize * NumChans * 2); - - SndfileSink sndfile_sink(arena, sink_config); - CHECK(sndfile_sink.open(NULL, file.path())); - - Pump pump(buffer_factory, mock_source, NULL, sndfile_sink, FrameDuration, SampleSpecs, - Pump::ModeOneshot); - CHECK(pump.is_valid()); - CHECK(pump.run()); - } - - SndfileSource sndfile_source(arena, source_config); - - CHECK(sndfile_source.open(NULL, file.path())); - - audio::sample_t frame_data1[FrameSize * NumChans] = {}; - audio::Frame frame1(frame_data1, FrameSize * NumChans); - - CHECK(sndfile_source.state() == DeviceState_Active); - CHECK(sndfile_source.read(frame1)); - - sndfile_source.pause(); - CHECK(sndfile_source.state() == DeviceState_Active); - - audio::sample_t frame_data2[FrameSize * NumChans] = {}; - audio::Frame frame2(frame_data2, FrameSize * NumChans); - - CHECK(sndfile_source.read(frame2)); - - CHECK(sndfile_source.restart()); - CHECK(sndfile_source.state() == DeviceState_Active); - - CHECK(sndfile_source.read(frame2)); - - if (memcmp(frame_data1, frame_data2, sizeof(frame_data1)) != 0) { - FAIL("frames should be equal"); - } -} - -TEST(sndfile_source, eof_restart) { - core::TempFile file("test.wav"); - - { - test::MockSource mock_source; - mock_source.add(FrameSize * NumChans * 2); - - SndfileSink sndfile_sink(arena, sink_config); - CHECK(sndfile_sink.open(NULL, file.path())); - - Pump pump(buffer_factory, mock_source, NULL, sndfile_sink, FrameDuration, - SampleSpecs, Pump::ModeOneshot); - CHECK(pump.is_valid()); - CHECK(pump.run()); - } - - SndfileSource sndfile_source(arena, source_config); - - CHECK(sndfile_source.open(NULL, file.path())); - - audio::sample_t frame_data[FrameSize * NumChans] = {}; - audio::Frame frame(frame_data, FrameSize * NumChans); - - for (int i = 0; i < 3; i++) { - CHECK(sndfile_source.read(frame)); - CHECK(sndfile_source.read(frame)); - CHECK(!sndfile_source.read(frame)); //This line fails - - CHECK(sndfile_source.restart()); - } -} - -} // namespace sndio -} // namespace roc diff --git a/src/tests/roc_sndio/target_sox/test_sox_source.cpp b/src/tests/roc_sndio/target_sox/test_sox_source.cpp deleted file mode 100644 index 9248ce138..000000000 --- a/src/tests/roc_sndio/target_sox/test_sox_source.cpp +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Copyright (c) 2015 Roc Streaming authors - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#include - -#include "test_helpers/mock_source.h" - -#include "roc_core/buffer_factory.h" -#include "roc_core/heap_arena.h" -#include "roc_core/stddefs.h" -#include "roc_core/temp_file.h" -#include "roc_sndio/pump.h" -#include "roc_sndio/sox_sink.h" -#include "roc_sndio/sox_source.h" - -namespace roc { -namespace sndio { - -namespace { - -enum { - MaxBufSize = 8192, - FrameSize = 500, - SampleRate = 44100, - ChMask = 0x3, - NumChans = 2 -}; - -const audio::SampleSpec SampleSpecs(SampleRate, - audio::Sample_RawFormat, - audio::ChanLayout_Surround, - audio::ChanOrder_Smpte, - ChMask); - -const core::nanoseconds_t FrameDuration = FrameSize * core::Second - / core::nanoseconds_t(SampleSpecs.sample_rate() * SampleSpecs.num_channels()); - -core::HeapArena arena; -core::BufferFactory buffer_factory(arena, MaxBufSize); - -} // namespace - -TEST_GROUP(sox_source) { - Config sink_config; - Config source_config; - - void setup() { - sink_config.sample_spec = - audio::SampleSpec(SampleRate, audio::Sample_RawFormat, - audio::ChanLayout_Surround, audio::ChanOrder_Smpte, ChMask); - sink_config.frame_length = FrameDuration; - - source_config.sample_spec = - audio::SampleSpec(SampleRate, audio::Sample_RawFormat, - audio::ChanLayout_Surround, audio::ChanOrder_Smpte, ChMask); - source_config.frame_length = FrameDuration; - } -}; - -TEST(sox_source, noop) { - SoxSource sox_source(arena, source_config); -} - -TEST(sox_source, error) { - SoxSource sox_source(arena, source_config); - - CHECK(!sox_source.open(NULL, "/bad/file")); -} - -TEST(sox_source, has_clock) { - core::TempFile file("test.wav"); - - { - test::MockSource mock_source; - mock_source.add(MaxBufSize * 10); - - SoxSink sox_sink(arena, sink_config); - CHECK(sox_sink.open(NULL, file.path())); - - Pump pump(buffer_factory, mock_source, NULL, sox_sink, FrameDuration, SampleSpecs, - Pump::ModeOneshot); - CHECK(pump.is_valid()); - CHECK(pump.run()); - } - - SoxSource sox_source(arena, source_config); - - CHECK(sox_source.open(NULL, file.path())); - CHECK(!sox_source.has_clock()); -} - -TEST(sox_source, sample_rate_auto) { - core::TempFile file("test.wav"); - - { - test::MockSource mock_source; - mock_source.add(MaxBufSize * 10); - - SoxSink sox_sink(arena, sink_config); - CHECK(sox_sink.open(NULL, file.path())); - - Pump pump(buffer_factory, mock_source, NULL, sox_sink, FrameDuration, SampleSpecs, - Pump::ModeOneshot); - CHECK(pump.is_valid()); - CHECK(pump.run()); - } - - source_config.sample_spec.set_sample_rate(0); - source_config.frame_length = FrameDuration; - SoxSource sox_source(arena, source_config); - - CHECK(sox_source.open(NULL, file.path())); - CHECK(sox_source.sample_spec().sample_rate() == SampleRate); -} - -TEST(sox_source, sample_rate_mismatch) { - core::TempFile file("test.wav"); - - { - test::MockSource mock_source; - mock_source.add(MaxBufSize * 10); - - SoxSink sox_sink(arena, sink_config); - CHECK(sox_sink.open(NULL, file.path())); - - Pump pump(buffer_factory, mock_source, NULL, sox_sink, FrameDuration, SampleSpecs, - Pump::ModeOneshot); - CHECK(pump.is_valid()); - CHECK(pump.run()); - } - - source_config.sample_spec.set_sample_rate(SampleRate * 2); - SoxSource sox_source(arena, source_config); - - CHECK(sox_source.open(NULL, file.path())); - CHECK(sox_source.sample_spec().sample_rate() == SampleRate * 2); -} - -TEST(sox_source, pause_resume) { - core::TempFile file("test.wav"); - - { - test::MockSource mock_source; - mock_source.add(FrameSize * NumChans * 2); - - SoxSink sox_sink(arena, sink_config); - CHECK(sox_sink.open(NULL, file.path())); - - Pump pump(buffer_factory, mock_source, NULL, sox_sink, FrameDuration, SampleSpecs, - Pump::ModeOneshot); - CHECK(pump.is_valid()); - CHECK(pump.run()); - } - - SoxSource sox_source(arena, source_config); - - CHECK(sox_source.open(NULL, file.path())); - - audio::sample_t frame_data1[FrameSize * NumChans] = {}; - audio::Frame frame1(frame_data1, FrameSize * NumChans); - - CHECK(sox_source.state() == DeviceState_Active); - CHECK(sox_source.read(frame1)); - - sox_source.pause(); - CHECK(sox_source.state() == DeviceState_Paused); - - audio::sample_t frame_data2[FrameSize * NumChans] = {}; - audio::Frame frame2(frame_data2, FrameSize * NumChans); - - CHECK(!sox_source.read(frame2)); - - CHECK(sox_source.resume()); - CHECK(sox_source.state() == DeviceState_Active); - - CHECK(sox_source.read(frame2)); - - if (memcmp(frame_data1, frame_data2, sizeof(frame_data1)) == 0) { - FAIL("frames should not be equal"); - } -} - -TEST(sox_source, pause_restart) { - core::TempFile file("test.wav"); - - { - test::MockSource mock_source; - mock_source.add(FrameSize * NumChans * 2); - - SoxSink sox_sink(arena, sink_config); - CHECK(sox_sink.open(NULL, file.path())); - - Pump pump(buffer_factory, mock_source, NULL, sox_sink, FrameDuration, SampleSpecs, - Pump::ModeOneshot); - CHECK(pump.is_valid()); - CHECK(pump.run()); - } - - SoxSource sox_source(arena, source_config); - - CHECK(sox_source.open(NULL, file.path())); - - audio::sample_t frame_data1[FrameSize * NumChans] = {}; - audio::Frame frame1(frame_data1, FrameSize * NumChans); - - CHECK(sox_source.state() == DeviceState_Active); - CHECK(sox_source.read(frame1)); - - sox_source.pause(); - CHECK(sox_source.state() == DeviceState_Paused); - - audio::sample_t frame_data2[FrameSize * NumChans] = {}; - audio::Frame frame2(frame_data2, FrameSize * NumChans); - - CHECK(!sox_source.read(frame2)); - - CHECK(sox_source.restart()); - CHECK(sox_source.state() == DeviceState_Active); - - CHECK(sox_source.read(frame2)); - - if (memcmp(frame_data1, frame_data2, sizeof(frame_data1)) != 0) { - FAIL("frames should be equal"); - } -} - -TEST(sox_source, eof_restart) { - core::TempFile file("test.wav"); - - { - test::MockSource mock_source; - mock_source.add(FrameSize * NumChans * 2); - - SoxSink sox_sink(arena, sink_config); - CHECK(sox_sink.open(NULL, file.path())); - - Pump pump(buffer_factory, mock_source, NULL, sox_sink, FrameDuration, SampleSpecs, - Pump::ModeOneshot); - CHECK(pump.is_valid()); - CHECK(pump.run()); - } - - SoxSource sox_source(arena, source_config); - - CHECK(sox_source.open(NULL, file.path())); - - audio::sample_t frame_data[FrameSize * NumChans] = {}; - audio::Frame frame(frame_data, FrameSize * NumChans); - - for (int i = 0; i < 3; i++) { - CHECK(sox_source.read(frame)); - CHECK(sox_source.read(frame)); - CHECK(!sox_source.read(frame)); - - CHECK(sox_source.restart()); - } -} - -} // namespace sndio -} // namespace roc diff --git a/src/tests/roc_sndio/test_backend_source.cpp b/src/tests/roc_sndio/test_backend_source.cpp index 2958afb62..a5dfdc47e 100644 --- a/src/tests/roc_sndio/test_backend_source.cpp +++ b/src/tests/roc_sndio/test_backend_source.cpp @@ -88,9 +88,8 @@ TEST(backend_source, error) { } TEST(backend_source, has_clock) { - core::TempFile file("test.wav"); - for (size_t n_backend = 0; n_backend < BackendMap::instance().num_backends(); n_backend++) { + core::TempFile file("test.wav"); IBackend& backend = BackendMap::instance().nth_backend(n_backend); bool supports_wav = false; @@ -130,9 +129,8 @@ TEST(backend_source, has_clock) { } TEST(backend_source, sample_rate_auto) { - core::TempFile file("test.wav"); - for (size_t n_backend = 0; n_backend < BackendMap::instance().num_backends(); n_backend++) { + core::TempFile file("test.wav"); IBackend& backend = BackendMap::instance().nth_backend(n_backend); if (!supports_wav(backend)) { @@ -165,9 +163,8 @@ TEST(backend_source, sample_rate_auto) { } TEST(backend_source, sample_rate_mismatch) { - core::TempFile file("test.wav"); - for (size_t n_backend = 0; n_backend < BackendMap::instance().num_backends(); n_backend++) { + core::TempFile file("test.wav"); IBackend& backend = BackendMap::instance().nth_backend(n_backend); if (!supports_wav(backend)) { @@ -191,17 +188,193 @@ TEST(backend_source, sample_rate_mismatch) { source_config.sample_spec.set_sample_rate(SampleRate * 2); IDevice * backend_device = backend.open_device(DeviceType_Source, DriverType_File, "wav", file.path(), source_config, arena); + + if(strcmp(backend.name(), "wav") == 0){ + CHECK(backend_device != NULL); + core::ScopedPtr backend_source(backend_device->to_source(), arena); + CHECK(backend_source != NULL); + } + else + { + CHECK(backend_device == NULL); + } + } +} + +TEST(backend_source, pause_resume) { + for (size_t n_backend = 0; n_backend < BackendMap::instance().num_backends(); n_backend++) { + core::TempFile file("test.wav"); + IBackend& backend = BackendMap::instance().nth_backend(n_backend); + + if (!supports_wav(backend)) { + continue; + } + + { + test::MockSource mock_source; + mock_source.add(FrameSize * NumChans * 2); + + IDevice* backend_device = backend.open_device(DeviceType_Sink, DriverType_File, "wav", file.path(), sink_config, arena); + CHECK(backend_device != NULL); + core::ScopedPtr backend_sink(backend_device->to_sink(), arena); + CHECK(backend_sink != NULL); + + Pump pump(buffer_factory, mock_source, NULL, *backend_sink, FrameDuration, SampleSpecs, + Pump::ModeOneshot); + CHECK(pump.is_valid()); + CHECK(pump.run()); + } + + IDevice *backend_device = backend.open_device(DeviceType_Source, DriverType_File, "wav", file.path(), source_config, arena); + CHECK(backend_device != NULL); + core::ScopedPtr backend_source(backend_device->to_source(), arena); + CHECK(backend_source != NULL); + + audio::sample_t frame_data1[FrameSize * NumChans] = {}; + audio::Frame frame1(frame_data1, FrameSize * NumChans); + + CHECK(backend_source->state() == DeviceState_Active); + CHECK(backend_source->read(frame1)); + + audio::sample_t frame_data2[FrameSize * NumChans] = {}; + audio::Frame frame2(frame_data2, FrameSize * NumChans); + + backend_source->pause(); + if(strcmp(backend.name(), "SoX") == 0){ + CHECK(backend_source->state() == DeviceState_Paused); + + CHECK(!backend_source->read(frame2)); + + CHECK(backend_source->resume()); + CHECK(backend_source->state() == DeviceState_Active); + + CHECK(backend_source->read(frame2)); + } + else{ + CHECK(backend_source->state() == DeviceState_Active); + + CHECK(backend_source->read(frame2)); + + CHECK(backend_source->resume()); + CHECK(backend_source->state() == DeviceState_Active); + + CHECK(!backend_source->read(frame2)); + } + + if (memcmp(frame_data1, frame_data2, sizeof(frame_data1)) == 0) { + FAIL("frames should not be equal"); + } + } +} + +TEST(backend_source, pause_restart) { + for (size_t n_backend = 0; n_backend < BackendMap::instance().num_backends(); n_backend++) { + core::TempFile file("test.wav"); + IBackend& backend = BackendMap::instance().nth_backend(n_backend); + + if (!supports_wav(backend)) { + continue; + } + + { + test::MockSource mock_source; + mock_source.add(FrameSize * NumChans * 2); + + IDevice* backend_device = backend.open_device(DeviceType_Sink, DriverType_File, "wav", file.path(), sink_config, arena); + CHECK(backend_device != NULL); + core::ScopedPtr backend_sink(backend_device->to_sink(), arena); + CHECK(backend_sink != NULL); + + Pump pump(buffer_factory, mock_source, NULL, *backend_sink, FrameDuration, SampleSpecs, + Pump::ModeOneshot); + CHECK(pump.is_valid()); + CHECK(pump.run()); + } + + IDevice *backend_device = backend.open_device(DeviceType_Source, DriverType_File, "wav", file.path(), source_config, arena); + CHECK(backend_device != NULL); + core::ScopedPtr backend_source(backend_device->to_source(), arena); + CHECK(backend_source != NULL); + + audio::sample_t frame_data1[FrameSize * NumChans] = {}; + audio::Frame frame1(frame_data1, FrameSize * NumChans); + + CHECK(backend_source->state() == DeviceState_Active); + CHECK(backend_source->read(frame1)); + + backend_source->pause(); + + audio::sample_t frame_data2[FrameSize * NumChans] = {}; + audio::Frame frame2(frame_data2, FrameSize * NumChans); + + if(strcmp(backend.name(), "SoX") == 0){ + CHECK(backend_source->state() == DeviceState_Paused); + + CHECK(!backend_source->read(frame2)); + + CHECK(backend_source->restart()); + CHECK(backend_source->state() == DeviceState_Active); + + CHECK(backend_source->read(frame2)); + } + else{ + CHECK(backend_source->state() == DeviceState_Active); + + CHECK(backend_source->read(frame2)); + + CHECK(backend_source->restart()); + CHECK(backend_source->state() == DeviceState_Active); + + CHECK(backend_source->read(frame2)); + } + + if (memcmp(frame_data1, frame_data2, sizeof(frame_data1)) != 0) { + FAIL("frames should be equal"); + } + } +} + +TEST(backend_source, eof_restart) { + for (size_t n_backend = 0; n_backend < BackendMap::instance().num_backends(); n_backend++) { + core::TempFile file("test.wav"); + IBackend& backend = BackendMap::instance().nth_backend(n_backend); + printf("backend: %s\n", backend.name()); fflush(stdout); - if(strcmp(backend.name(), "wav") != 0){ - - - CHECK(backend_device == NULL); - core::ScopedPtr backend_source(backend_device->to_source(), arena); - CHECK(backend_source == NULL); - }else + + if (!supports_wav(backend)) { + continue; + } + { + test::MockSource mock_source; + mock_source.add(FrameSize * NumChans * 2); + + IDevice* backend_device = backend.open_device(DeviceType_Sink, DriverType_File, "wav", file.path(), sink_config, arena); + CHECK(backend_device != NULL); + core::ScopedPtr backend_sink(backend_device->to_sink(), arena); + CHECK(backend_sink != NULL); + + Pump pump(buffer_factory, mock_source, NULL, *backend_sink, FrameDuration, SampleSpecs, + Pump::ModeOneshot); + CHECK(pump.is_valid()); + CHECK(pump.run()); + } + + IDevice *backend_device = backend.open_device(DeviceType_Source, DriverType_File, "wav", file.path(), source_config, arena); + CHECK(backend_device != NULL); + core::ScopedPtr backend_source(backend_device->to_source(), arena); + CHECK(backend_source != NULL); + + audio::sample_t frame_data[FrameSize * NumChans] = {}; + audio::Frame frame(frame_data, FrameSize * NumChans); + + for (int i = 0; i < 3; i++) { + CHECK(backend_source->read(frame)); + CHECK(backend_source->read(frame)); + CHECK(!backend_source->read(frame)); + CHECK(backend_source->restart()); } } }