diff options
Diffstat (limited to 'test/test_devices.cpp')
-rw-r--r-- | test/test_devices.cpp | 156 |
1 files changed, 78 insertions, 78 deletions
diff --git a/test/test_devices.cpp b/test/test_devices.cpp index a194663..d0eab2d 100644 --- a/test/test_devices.cpp +++ b/test/test_devices.cpp @@ -7,19 +7,20 @@ /* libcubeb enumerate device test/example. * Prints out a list of devices enumerated. */ +#include "cubeb/cubeb.h" #include "gtest/gtest.h" +#include <memory> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <memory> -#include "cubeb/cubeb.h" -//#define ENABLE_NORMAL_LOG -//#define ENABLE_VERBOSE_LOG +// #define ENABLE_NORMAL_LOG +// #define ENABLE_VERBOSE_LOG #include "common.h" static long -data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes) +data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer, + void * outputbuffer, long nframes) { // noop, unused return 0; @@ -35,52 +36,52 @@ static void print_device_info(cubeb_device_info * info, FILE * f) { char devfmts[64] = ""; - const char * devtype, * devstate, * devdeffmt; + const char *devtype, *devstate, *devdeffmt; switch (info->type) { - case CUBEB_DEVICE_TYPE_INPUT: - devtype = "input"; - break; - case CUBEB_DEVICE_TYPE_OUTPUT: - devtype = "output"; - break; - case CUBEB_DEVICE_TYPE_UNKNOWN: - default: - devtype = "unknown?"; - break; + case CUBEB_DEVICE_TYPE_INPUT: + devtype = "input"; + break; + case CUBEB_DEVICE_TYPE_OUTPUT: + devtype = "output"; + break; + case CUBEB_DEVICE_TYPE_UNKNOWN: + default: + devtype = "unknown?"; + break; }; switch (info->state) { - case CUBEB_DEVICE_STATE_DISABLED: - devstate = "disabled"; - break; - case CUBEB_DEVICE_STATE_UNPLUGGED: - devstate = "unplugged"; - break; - case CUBEB_DEVICE_STATE_ENABLED: - devstate = "enabled"; - break; - default: - devstate = "unknown?"; - break; + case CUBEB_DEVICE_STATE_DISABLED: + devstate = "disabled"; + break; + case CUBEB_DEVICE_STATE_UNPLUGGED: + devstate = "unplugged"; + break; + case CUBEB_DEVICE_STATE_ENABLED: + devstate = "enabled"; + break; + default: + devstate = "unknown?"; + break; }; switch (info->default_format) { - case CUBEB_DEVICE_FMT_S16LE: - devdeffmt = "S16LE"; - break; - case CUBEB_DEVICE_FMT_S16BE: - devdeffmt = "S16BE"; - break; - case CUBEB_DEVICE_FMT_F32LE: - devdeffmt = "F32LE"; - break; - case CUBEB_DEVICE_FMT_F32BE: - devdeffmt = "F32BE"; - break; - default: - devdeffmt = "unknown?"; - break; + case CUBEB_DEVICE_FMT_S16LE: + devdeffmt = "S16LE"; + break; + case CUBEB_DEVICE_FMT_S16BE: + devdeffmt = "S16BE"; + break; + case CUBEB_DEVICE_FMT_F32LE: + devdeffmt = "F32LE"; + break; + case CUBEB_DEVICE_FMT_F32BE: + devdeffmt = "F32BE"; + break; + default: + devdeffmt = "unknown?"; + break; }; if (info->format & CUBEB_DEVICE_FMT_S16LE) @@ -93,23 +94,22 @@ print_device_info(cubeb_device_info * info, FILE * f) strcat(devfmts, " F32BE"); fprintf(f, - "dev: \"%s\"%s\n" - "\tName: \"%s\"\n" - "\tGroup: \"%s\"\n" - "\tVendor: \"%s\"\n" - "\tType: %s\n" - "\tState: %s\n" - "\tCh: %u\n" - "\tFormat: %s (0x%x) (default: %s)\n" - "\tRate: %u - %u (default: %u)\n" - "\tLatency: lo %u frames, hi %u frames\n", - info->device_id, info->preferred ? " (PREFERRED)" : "", - info->friendly_name, info->group_id, info->vendor_name, - devtype, devstate, info->max_channels, - (devfmts[0] == '\0') ? devfmts : devfmts + 1, - (unsigned int)info->format, devdeffmt, - info->min_rate, info->max_rate, info->default_rate, - info->latency_lo, info->latency_hi); + "dev: \"%s\"%s\n" + "\tName: \"%s\"\n" + "\tGroup: \"%s\"\n" + "\tVendor: \"%s\"\n" + "\tType: %s\n" + "\tState: %s\n" + "\tCh: %u\n" + "\tFormat: %s (0x%x) (default: %s)\n" + "\tRate: %u - %u (default: %u)\n" + "\tLatency: lo %u frames, hi %u frames\n", + info->device_id, info->preferred ? " (PREFERRED)" : "", + info->friendly_name, info->group_id, info->vendor_name, devtype, + devstate, info->max_channels, + (devfmts[0] == '\0') ? devfmts : devfmts + 1, + (unsigned int)info->format, devdeffmt, info->min_rate, info->max_rate, + info->default_rate, info->latency_lo, info->latency_hi); } static void @@ -125,22 +125,22 @@ TEST(cubeb, destroy_default_collection) { int r; cubeb * ctx = NULL; - cubeb_device_collection collection{ nullptr, 0 }; + cubeb_device_collection collection{nullptr, 0}; r = common_init(&ctx, "Cubeb audio test"); ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library"; - std::unique_ptr<cubeb, decltype(&cubeb_destroy)> - cleanup_cubeb_at_exit(ctx, cubeb_destroy); + std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit( + ctx, cubeb_destroy); ASSERT_EQ(collection.device, nullptr); - ASSERT_EQ(collection.count, (size_t) 0); + ASSERT_EQ(collection.count, (size_t)0); r = cubeb_device_collection_destroy(ctx, &collection); if (r != CUBEB_ERROR_NOT_SUPPORTED) { ASSERT_EQ(r, CUBEB_OK); ASSERT_EQ(collection.device, nullptr); - ASSERT_EQ(collection.count, (size_t) 0); + ASSERT_EQ(collection.count, (size_t)0); } } @@ -153,11 +153,11 @@ TEST(cubeb, enumerate_devices) r = common_init(&ctx, "Cubeb audio test"); ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library"; - std::unique_ptr<cubeb, decltype(&cubeb_destroy)> - cleanup_cubeb_at_exit(ctx, cubeb_destroy); + std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit( + ctx, cubeb_destroy); fprintf(stdout, "Enumerating input devices for backend %s\n", - cubeb_get_backend_id(ctx)); + cubeb_get_backend_id(ctx)); r = cubeb_enumerate_devices(ctx, CUBEB_DEVICE_TYPE_INPUT, &collection); if (r == CUBEB_ERROR_NOT_SUPPORTED) { @@ -200,9 +200,9 @@ TEST(cubeb, enumerate_devices) input_params.layout = output_params.layout = CUBEB_LAYOUT_MONO; input_params.prefs = output_params.prefs = CUBEB_STREAM_PREF_NONE; - r = cubeb_stream_init(ctx, &stream, "Cubeb duplex", - NULL, &input_params, NULL, &output_params, - 1024, data_cb_duplex, state_cb_duplex, nullptr); + r = cubeb_stream_init(ctx, &stream, "Cubeb duplex", NULL, &input_params, NULL, + &output_params, 1024, data_cb_duplex, state_cb_duplex, + nullptr); ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream"; @@ -220,11 +220,11 @@ TEST(cubeb, stream_get_current_device) int r = common_init(&ctx, "Cubeb audio test"); ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library"; - std::unique_ptr<cubeb, decltype(&cubeb_destroy)> - cleanup_cubeb_at_exit(ctx, cubeb_destroy); + std::unique_ptr<cubeb, decltype(&cubeb_destroy)> cleanup_cubeb_at_exit( + ctx, cubeb_destroy); fprintf(stdout, "Getting current devices for backend %s\n", - cubeb_get_backend_id(ctx)); + cubeb_get_backend_id(ctx)); if (!can_run_audio_input_test(ctx)) { return; @@ -240,12 +240,12 @@ TEST(cubeb, stream_get_current_device) input_params.layout = output_params.layout = CUBEB_LAYOUT_MONO; input_params.prefs = output_params.prefs = CUBEB_STREAM_PREF_NONE; - r = cubeb_stream_init(ctx, &stream, "Cubeb duplex", - NULL, &input_params, NULL, &output_params, - 1024, data_cb_duplex, state_cb_duplex, nullptr); + r = cubeb_stream_init(ctx, &stream, "Cubeb duplex", NULL, &input_params, NULL, + &output_params, 1024, data_cb_duplex, state_cb_duplex, + nullptr); ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream"; std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)> - cleanup_stream_at_exit(stream, cubeb_stream_destroy); + cleanup_stream_at_exit(stream, cubeb_stream_destroy); cubeb_device * device; r = cubeb_stream_get_current_device(stream, &device); |