Skip to content

Commit

Permalink
test_backend_sink.cpp fully implemented and passing all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrick87 committed Feb 25, 2024
1 parent 0695127 commit a5a4e81
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 179 deletions.
76 changes: 0 additions & 76 deletions src/tests/roc_sndio/target_sndfile/test_sndfile_sink.cpp

This file was deleted.

77 changes: 0 additions & 77 deletions src/tests/roc_sndio/target_sox/test_sox_sink.cpp

This file was deleted.

127 changes: 127 additions & 0 deletions src/tests/roc_sndio/test_backend_sink.cpp
Original file line number Diff line number Diff line change
@@ -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 <CppUTest/TestHarness.h>

#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<DriverInfo, MaxDrivers> 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<ISink> 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<ISink> 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<ISink> backend_sink(backend_device->to_sink(), arena);
CHECK(backend_sink != NULL);

CHECK(backend_sink->sample_spec().sample_rate() == SampleRate);
}
}

}
}
22 changes: 10 additions & 12 deletions src/tests/roc_sndio/test_backend_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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<DriverInfo, MaxDrivers> 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;
}

Expand Down Expand Up @@ -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());
}
}
Expand Down
18 changes: 4 additions & 14 deletions src/tests/roc_sndio/test_pump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<ISink> backend_sink(backend_device->to_sink(), arena);
CHECK(backend_sink != NULL);
Pump pump(buffer_factory, mock_source, NULL, *backend_sink, BufDuration, SampleSpecs,
Expand All @@ -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<ISource> backend_source(backend_device->to_source(), arena);
CHECK(backend_source != NULL);
Expand Down

0 comments on commit a5a4e81

Please sign in to comment.