diff options
Diffstat (limited to 'test/common.h')
-rw-r--r-- | test/common.h | 70 |
1 files changed, 33 insertions, 37 deletions
diff --git a/test/common.h b/test/common.h index 76d318c..ad464a4 100644 --- a/test/common.h +++ b/test/common.h @@ -7,7 +7,7 @@ #if !defined(TEST_COMMON) #define TEST_COMMON -#if defined( _WIN32) +#if defined(_WIN32) #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif @@ -17,18 +17,19 @@ #include <unistd.h> #endif -#include <cstdarg> #include "cubeb/cubeb.h" #include "cubeb_mixer.h" +#include <cstdarg> -template<typename T, size_t N> +template <typename T, size_t N> constexpr size_t -ARRAY_LENGTH(T(&)[N]) +ARRAY_LENGTH(T (&)[N]) { return N; } -inline void delay(unsigned int ms) +inline void +delay(unsigned int ms) { #if defined(_WIN32) Sleep(ms); @@ -49,33 +50,24 @@ typedef struct { } layout_info; struct backend_caps { - const char* id; + const char * id; const int input_capabilities; }; - // This static table allows knowing if a backend has audio input capabilities. // We don't rely on opening a stream and checking if it works, because this // would make the test skip the tests that make use of audio input, if a // particular backend has a bug that causes a failure during audio input stream -// creation +// creation static backend_caps backend_capabilities[] = { - {"sun", 1}, - {"wasapi", 1}, - {"kai", 1}, - {"audiounit", 1}, - {"audiotrack", 0}, - {"opensl", 1}, - {"aaudio", 1}, - {"jack", 1}, - {"pulse", 1}, - {"sndio", 1}, - {"oss", 1}, - {"winmm", 0}, - {"alsa", 1}, + {"sun", 1}, {"wasapi", 1}, {"kai", 1}, {"audiounit", 1}, + {"audiotrack", 0}, {"opensl", 1}, {"aaudio", 1}, {"jack", 1}, + {"pulse", 1}, {"sndio", 1}, {"oss", 1}, {"winmm", 0}, + {"alsa", 1}, }; -inline int can_run_audio_input_test(cubeb * ctx) +inline int +can_run_audio_input_test(cubeb * ctx) { cubeb_device_collection devices; int input_device_available = 0; @@ -94,29 +86,32 @@ inline int can_run_audio_input_test(cubeb * ctx) } for (uint32_t i = 0; i < devices.count; i++) { - input_device_available |= (devices.device[i].state == - CUBEB_DEVICE_STATE_ENABLED); + input_device_available |= + (devices.device[i].state == CUBEB_DEVICE_STATE_ENABLED); } if (!input_device_available) { fprintf(stderr, "there are input devices, but they are not " - "available, skipping\n"); + "available, skipping\n"); } cubeb_device_collection_destroy(ctx, &devices); int backend_has_input_capabilities; const char * backend_id = cubeb_get_backend_id(ctx); - for (uint32_t i = 0; i < sizeof(backend_capabilities) / sizeof(backend_caps); i++) { + for (uint32_t i = 0; i < sizeof(backend_capabilities) / sizeof(backend_caps); + i++) { if (strcmp(backend_capabilities[i].id, backend_id) == 0) { - backend_has_input_capabilities = backend_capabilities[i].input_capabilities; + backend_has_input_capabilities = + backend_capabilities[i].input_capabilities; } } return !!input_device_available && !!backend_has_input_capabilities; } -inline void print_log(const char * msg, ...) +inline void +print_log(const char * msg, ...) { va_list args; va_start(args, msg); @@ -127,7 +122,8 @@ inline void print_log(const char * msg, ...) /** Initialize cubeb with backend override. * Create call cubeb_init passing value for CUBEB_BACKEND env var as * override. */ -inline int common_init(cubeb ** ctx, char const * ctx_name) +inline int +common_init(cubeb ** ctx, char const * ctx_name) { #ifdef ENABLE_NORMAL_LOG if (cubeb_set_log_callback(CUBEB_LOG_NORMAL, print_log) != CUBEB_OK) { @@ -150,22 +146,21 @@ inline int common_init(cubeb ** ctx, char const * ctx_name) if (r == CUBEB_OK && backend) { ctx_backend = cubeb_get_backend_id(*ctx); if (strcmp(backend, ctx_backend) != 0) { - fprintf(stderr, "Requested backend `%s', got `%s'\n", - backend, ctx_backend); + fprintf(stderr, "Requested backend `%s', got `%s'\n", backend, + ctx_backend); } } return r; } -#if defined( _WIN32) +#if defined(_WIN32) class TestEnvironment : public ::testing::Environment { public: - void SetUp() override { - hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); - } + void SetUp() override { hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); } - void TearDown() override { + void TearDown() override + { if (SUCCEEDED(hr)) { CoUninitialize(); } @@ -175,7 +170,8 @@ private: HRESULT hr; }; -::testing::Environment* const foo_env = ::testing::AddGlobalTestEnvironment(new TestEnvironment); +::testing::Environment * const foo_env = + ::testing::AddGlobalTestEnvironment(new TestEnvironment); #endif #endif /* TEST_COMMON */ |