diff options
Diffstat (limited to 'test/common.h')
-rw-r--r-- | test/common.h | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/test/common.h b/test/common.h index 47cc28c..051f3c4 100644 --- a/test/common.h +++ b/test/common.h @@ -17,10 +17,10 @@ void delay(unsigned int ms) { #if defined(_WIN32) - Sleep(ms); + Sleep(ms); #else - sleep(ms / 1000); - usleep(ms % 1000 * 1000); + sleep(ms / 1000); + usleep(ms % 1000 * 1000); #endif } @@ -28,3 +28,34 @@ void delay(unsigned int ms) #define M_PI 3.14159265358979323846 #endif +int has_available_input_device(cubeb * ctx) +{ + cubeb_device_collection * devices; + int input_device_available = 0; + int r; + /* Bail out early if the host does not have input devices. */ + r = cubeb_enumerate_devices(ctx, CUBEB_DEVICE_TYPE_INPUT, &devices); + if (r != CUBEB_OK) { + fprintf(stderr, "error enumerating devices."); + return 0; + } + + if (devices->count == 0) { + fprintf(stderr, "no input device available, skipping test.\n"); + return 0; + } + + for (uint32_t i = 0; i < devices->count; i++) { + 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"); + return 0; + } + + return 1; +} + |