diff --git a/src/tests/roc_sndio/target_sndfile/test_sndfile_sink.cpp b/src/tests/roc_sndio/target_sndfile/test_sndfile_sink.cpp deleted file mode 100644 index 30073b619..000000000 --- a/src/tests/roc_sndio/target_sndfile/test_sndfile_sink.cpp +++ /dev/null @@ -1,76 +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 "roc_core/heap_arena.h" -#include "roc_core/temp_file.h" -#include "roc_sndio/sndfile_sink.h" - -namespace roc { -namespace sndio { - -namespace { - -enum { FrameSize = 500, SampleRate = 44100, ChMask = 0x3 }; - -core::HeapArena arena; - -} // namespace - -TEST_GROUP(sndfile_sink) { - Config sink_config; - - void setup() { - sink_config.sample_spec = audio::SampleSpec( - SampleRate, audio::Sample_RawFormat, audio::ChanLayout_Surround, audio::ChanOrder_Smpte, ChMask); - - sink_config.frame_length = FrameSize * core::Second - / core::nanoseconds_t(sink_config.sample_spec.sample_rate() - * sink_config.sample_spec.num_channels()); - } -}; - -TEST(sndfile_sink, noop) { - SndfileSink sndfile_sink(arena, sink_config); -} - -TEST(sndfile_sink, error) { - SndfileSink sndfile_sink(arena, sink_config); - - CHECK(!sndfile_sink.open(NULL, "/bad/file")); -} - -TEST(sndfile_sink, has_clock) { - SndfileSink sndfile_sink(arena, sink_config); - - core::TempFile file("test.wav"); - CHECK(sndfile_sink.open(NULL, file.path())); - CHECK(!sndfile_sink.has_clock()); -} - -TEST(sndfile_sink, sample_rate_auto) { - sink_config.sample_spec.set_sample_rate(0); - SndfileSink sndfile_sink(arena, sink_config); - - core::TempFile file("test.wav"); - CHECK(sndfile_sink.open(NULL, file.path())); - CHECK(sndfile_sink.sample_spec().sample_rate() != 0); -} - -TEST(sndfile_sink, sample_rate_force) { - sink_config.sample_spec.set_sample_rate(SampleRate); - SndfileSink sndfile_sink(arena, sink_config); - - core::TempFile file("test.wav"); - CHECK(sndfile_sink.open(NULL, file.path())); - CHECK(sndfile_sink.sample_spec().sample_rate() == SampleRate); -} - -} // namespace sndio -} // namespace roc diff --git a/src/tests/roc_sndio/target_sox/test_sox_sink.cpp b/src/tests/roc_sndio/target_sox/test_sox_sink.cpp deleted file mode 100644 index db03ec349..000000000 --- a/src/tests/roc_sndio/target_sox/test_sox_sink.cpp +++ /dev/null @@ -1,77 +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 "roc_core/heap_arena.h" -#include "roc_core/temp_file.h" -#include "roc_sndio/sox_sink.h" - -namespace roc { -namespace sndio { - -namespace { - -enum { FrameSize = 500, SampleRate = 44100, ChMask = 0x3 }; - -core::HeapArena arena; - -} // namespace - -TEST_GROUP(sox_sink) { - Config sink_config; - - void setup() { - sink_config.sample_spec = - audio::SampleSpec(SampleRate, audio::Sample_RawFormat, - audio::ChanLayout_Surround, audio::ChanOrder_Smpte, ChMask); - - sink_config.frame_length = FrameSize * core::Second - / core::nanoseconds_t(sink_config.sample_spec.sample_rate() - * sink_config.sample_spec.num_channels()); - } -}; - -TEST(sox_sink, noop) { - SoxSink sox_sink(arena, sink_config); -} - -TEST(sox_sink, error) { - SoxSink sox_sink(arena, sink_config); - - CHECK(!sox_sink.open(NULL, "/bad/file")); -} - -TEST(sox_sink, has_clock) { - SoxSink sox_sink(arena, sink_config); - - core::TempFile file("test.wav"); - CHECK(sox_sink.open(NULL, file.path())); - CHECK(!sox_sink.has_clock()); -} - -TEST(sox_sink, sample_rate_auto) { - sink_config.sample_spec.set_sample_rate(0); - SoxSink sox_sink(arena, sink_config); - - core::TempFile file("test.wav"); - CHECK(sox_sink.open(NULL, file.path())); - CHECK(sox_sink.sample_spec().sample_rate() != 0); -} - -TEST(sox_sink, sample_rate_force) { - sink_config.sample_spec.set_sample_rate(SampleRate); - SoxSink sox_sink(arena, sink_config); - - core::TempFile file("test.wav"); - CHECK(sox_sink.open(NULL, file.path())); - CHECK(sox_sink.sample_spec().sample_rate() == SampleRate); -} - -} // namespace sndio -} // namespace roc diff --git a/src/tests/roc_sndio/test_backend_sink.cpp b/src/tests/roc_sndio/test_backend_sink.cpp new file mode 100644 index 000000000..9c61a914c --- /dev/null +++ b/src/tests/roc_sndio/test_backend_sink.cpp @@ -0,0 +1,127 @@ +/* + * 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 "roc_core/scoped_ptr.h" +#include "roc_sndio/backend_map.h" +#include "roc_core/heap_arena.h" +#include "roc_core/temp_file.h" +//#ifdef ROC_TARGERT_SNDFILE +#include "roc_sndio/sndfile_sink.h" +//#endif // ROC_TARGET_SNDFILE +//#ifdef ROC_TARGET_SOX +#include "roc_sndio/sox_sink.h" +//#endif // ROC_TARGET_SOX + +namespace roc { +namespace sndio { + +namespace { + +enum { FrameSize = 500, SampleRate = 44100, ChMask = 0x3 }; + +core::HeapArena arena; + +} // namespace + +TEST_GROUP(backend_sink) { + Config sink_config; + + void setup() { + sink_config.sample_spec = + audio::SampleSpec(SampleRate, audio::Sample_RawFormat, + audio::ChanLayout_Surround, audio::ChanOrder_Smpte, ChMask); + + sink_config.frame_length = FrameSize * core::Second + / core::nanoseconds_t(sink_config.sample_spec.sample_rate() + * sink_config.sample_spec.num_channels()); + } + + bool supports_wav(IBackend &backend){ + bool supports = false; + core::Array driver_list; + backend.discover_drivers(driver_list); + for (size_t n = 0; n < driver_list.size(); n++) { + if (strcmp(driver_list[n].name, "wav") == 0) { + supports = true; + break; + } + } + + return supports; + } +}; + +TEST(backend_sink, noop) { + SndfileSink sndfile_sink(arena, sink_config); + SoxSink sox_sink(arena, sink_config); +} + +TEST(backend_sink, error) { + for (size_t n_backend = 0; n_backend < BackendMap::instance().num_backends(); n_backend++) { + IBackend &backend = BackendMap::instance().nth_backend(n_backend); + if(!supports_wav(backend)){ + continue; + } + IDevice *backend_device = backend.open_device(DeviceType_Sink, DriverType_File, NULL, "/bad/file", sink_config, arena); + CHECK(backend_device == NULL); + } +} + +TEST(backend_sink, has_clock) { + 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; + } + IDevice* backend_device = backend.open_device(DeviceType_Sink, DriverType_File, NULL, file.path(), sink_config, arena); + CHECK(backend_device != NULL); + core::ScopedPtr backend_sink(backend_device->to_sink(), arena); + CHECK(backend_sink != NULL); + CHECK(!backend_sink->has_clock()); + } +} + +TEST(backend_sink, sample_rate_auto) { + sink_config.sample_spec.set_sample_rate(0); + 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; + } + IDevice* backend_device = backend.open_device(DeviceType_Sink, DriverType_File, NULL, file.path(), sink_config, arena); + CHECK(backend_device != NULL); + core::ScopedPtr backend_sink(backend_device->to_sink(), arena); + CHECK(backend_sink != NULL); + + CHECK(backend_sink->sample_spec().sample_rate() != 0); + } +} + +TEST(backend_sink, sample_rate_force) { + sink_config.sample_spec.set_sample_rate(SampleRate); + 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; + } + IDevice* backend_device = backend.open_device(DeviceType_Sink, DriverType_File, NULL, file.path(), sink_config, arena); + CHECK(backend_device != NULL); + core::ScopedPtr backend_sink(backend_device->to_sink(), arena); + CHECK(backend_sink != NULL); + + CHECK(backend_sink->sample_spec().sample_rate() == SampleRate); + } +} + +} +} \ No newline at end of file diff --git a/src/tests/roc_sndio/test_backend_source.cpp b/src/tests/roc_sndio/test_backend_source.cpp index a5dfdc47e..efb960a61 100644 --- a/src/tests/roc_sndio/test_backend_source.cpp +++ b/src/tests/roc_sndio/test_backend_source.cpp @@ -17,10 +17,14 @@ #include "roc_core/stddefs.h" #include "roc_core/temp_file.h" #include "roc_sndio/pump.h" +//#ifdef ROC_TARGET_SNDFILE #include "roc_sndio/sndfile_sink.h" #include "roc_sndio/sndfile_source.h" +//#endif // ROC_TARGET_SNDFILE +//#ifdef ROC_TARGET_SOX #include "roc_sndio/sox_sink.h" #include "roc_sndio/sox_source.h" +//#endif // ROC_TARGET_SOX namespace roc { namespace sndio { @@ -82,7 +86,10 @@ TEST(backend_source, noop) { TEST(backend_source, error) { for (size_t n_backend = 0; n_backend < BackendMap::instance().num_backends(); n_backend++) { IBackend &backend = BackendMap::instance().nth_backend(n_backend); - IDevice *backend_device = backend.open_device(DeviceType_Source, DriverType_File, NULL, "/bad/file", sink_config, arena); + if(!supports_wav(backend)){ + continue; + } + IDevice *backend_device = backend.open_device(DeviceType_Source, DriverType_File, NULL, "/bad/file", source_config, arena); CHECK(backend_device == NULL); } } @@ -92,16 +99,7 @@ TEST(backend_source, has_clock) { core::TempFile file("test.wav"); IBackend& backend = BackendMap::instance().nth_backend(n_backend); - bool supports_wav = false; - core::Array driver_list; - backend.discover_drivers(driver_list); - for (size_t n = 0; n < driver_list.size(); n++) { - if (strcmp(driver_list[n].name, "wav") == 0) { - supports_wav = true; - break; - } - } - if(!supports_wav){ + if(!supports_wav(backend)){ continue; } @@ -373,7 +371,7 @@ TEST(backend_source, eof_restart) { CHECK(backend_source->read(frame)); CHECK(backend_source->read(frame)); CHECK(!backend_source->read(frame)); - + CHECK(backend_source->restart()); } } diff --git a/src/tests/roc_sndio/test_pump.cpp b/src/tests/roc_sndio/test_pump.cpp index c0504aa53..16d48d6cb 100644 --- a/src/tests/roc_sndio/test_pump.cpp +++ b/src/tests/roc_sndio/test_pump.cpp @@ -19,14 +19,14 @@ #include "roc_sndio/config.h" #include "roc_sndio/pump.h" #include "roc_sndio/backend_map.h" -#ifdef ROC_TARGET_SOX -#include "roc_sndio/sox_sink.h" -#include "roc_sndio/sox_source.h" -#endif // ROC_TARGET_SOX #ifdef ROC_TARGET_SNDFILE #include "roc_sndio/sndfile_sink.h" #include "roc_sndio/sndfile_source.h" #endif // ROC_TARGET_SNDFILE +#ifdef ROC_TARGET_SOX +#include "roc_sndio/sox_sink.h" +#include "roc_sndio/sox_source.h" +#endif // ROC_TARGET_SOX namespace roc { namespace sndio { @@ -88,14 +88,9 @@ TEST(pump, write_read) { continue; } - printf("Currently on: %s\n", backend.name()); - fflush(stdout); - { IDevice *backend_device = backend.open_device(DeviceType_Sink, DriverType_File, "wav", file.path(), sink_config, arena); CHECK(backend_device != NULL); - printf("Passing sink test: %s\n", backend.name()); - fflush(stdout); core::ScopedPtr backend_sink(backend_device->to_sink(), arena); CHECK(backend_sink != NULL); Pump pump(buffer_factory, mock_source, NULL, *backend_sink, BufDuration, SampleSpecs, @@ -106,13 +101,8 @@ TEST(pump, write_read) { CHECK(mock_source.num_returned() >= NumSamples - BufSize); } - printf("File path: %s\n", file.path()); - fflush(stdout); - IDevice *backend_device = backend.open_device(DeviceType_Source, DriverType_File, "wav", file.path(), source_config, arena); CHECK(backend_device != NULL); - - printf("Passing source test: %s\n\n", backend.name()); core::ScopedPtr backend_source(backend_device->to_source(), arena); CHECK(backend_source != NULL);