aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPaul Adenot <[email protected]>2023-04-25 14:42:06 +0200
committerPaul Adenot <[email protected]>2023-04-26 14:28:46 +0200
commit2e0fe891062b6437ad26a75dd010d0b0247561f0 (patch)
tree5555cd37bc410408717920bcb24f07282c775426
parent9517d4e837a6bc9f50c35bd7df57153fc002e5e0 (diff)
downloadcubeb-2e0fe891062b6437ad26a75dd010d0b0247561f0.tar.gz
cubeb-2e0fe891062b6437ad26a75dd010d0b0247561f0.zip
Prevent running test that make use of audio input streams on backends that don't implement it
-rw-r--r--test/common.h40
-rw-r--r--test/test_callback_ret.cpp4
-rw-r--r--test/test_device_changed_callback.cpp5
-rw-r--r--test/test_devices.cpp9
-rw-r--r--test/test_duplex.cpp2
-rw-r--r--test/test_loopback.cpp4
-rw-r--r--test/test_record.cpp2
7 files changed, 59 insertions, 7 deletions
diff --git a/test/common.h b/test/common.h
index 98e9f90..76d318c 100644
--- a/test/common.h
+++ b/test/common.h
@@ -48,7 +48,34 @@ typedef struct {
uint32_t const layout;
} layout_info;
-inline int has_available_input_device(cubeb * ctx)
+struct backend_caps {
+ 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
+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},
+};
+
+inline int can_run_audio_input_test(cubeb * ctx)
{
cubeb_device_collection devices;
int input_device_available = 0;
@@ -77,7 +104,16 @@ inline int has_available_input_device(cubeb * ctx)
}
cubeb_device_collection_destroy(ctx, &devices);
- return !!input_device_available;
+
+ 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++) {
+ if (strcmp(backend_capabilities[i].id, backend_id) == 0) {
+ backend_has_input_capabilities = backend_capabilities[i].input_capabilities;
+ }
+ }
+
+ return !!input_device_available && !!backend_has_input_capabilities;
}
inline void print_log(const char * msg, ...)
diff --git a/test/test_callback_ret.cpp b/test/test_callback_ret.cpp
index 7ce33d0..49676f7 100644
--- a/test/test_callback_ret.cpp
+++ b/test/test_callback_ret.cpp
@@ -158,9 +158,9 @@ void run_test_callback(test_direction direction,
cleanup_cubeb_at_exit(ctx, cubeb_destroy);
if ((direction == INPUT_ONLY || direction == DUPLEX) &&
- !has_available_input_device(ctx)) {
+ !can_run_audio_input_test(ctx)) {
/* This test needs an available input device, skip it if this host does not
- * have one. */
+ * have one or if the backend doesn't implement input. */
return;
}
diff --git a/test/test_device_changed_callback.cpp b/test/test_device_changed_callback.cpp
index d1e60a8..890ebd9 100644
--- a/test/test_device_changed_callback.cpp
+++ b/test/test_device_changed_callback.cpp
@@ -75,9 +75,14 @@ TEST(cubeb, device_changed_callbacks)
int r = CUBEB_OK;
uint32_t latency_frames = 0;
+
r = common_init(&ctx, "Cubeb duplex example with device change");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
+ if (!can_run_audio_input_test(ctx)) {
+ return;
+ }
+
std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
cleanup_cubeb_at_exit(ctx, cubeb_destroy);
diff --git a/test/test_devices.cpp b/test/test_devices.cpp
index e9b34b3..76e9615 100644
--- a/test/test_devices.cpp
+++ b/test/test_devices.cpp
@@ -185,6 +185,9 @@ TEST(cubeb, enumerate_devices)
count_before_creating_duplex_stream = collection.count;
cubeb_device_collection_destroy(ctx, &collection);
+ if (!can_run_audio_input_test(ctx)) {
+ return;
+ }
cubeb_stream * stream;
cubeb_stream_params input_params;
cubeb_stream_params output_params;
@@ -221,6 +224,10 @@ TEST(cubeb, stream_get_current_device)
fprintf(stdout, "Getting current devices for backend %s\n",
cubeb_get_backend_id(ctx));
+ if (!can_run_audio_input_test(ctx)) {
+ return;
+ }
+
cubeb_stream * stream = NULL;
cubeb_stream_params input_params;
cubeb_stream_params output_params;
@@ -252,4 +259,4 @@ TEST(cubeb, stream_get_current_device)
r = cubeb_stream_device_destroy(stream, device);
ASSERT_EQ(r, CUBEB_OK) << "Error destroying current devices";
-} \ No newline at end of file
+}
diff --git a/test/test_duplex.cpp b/test/test_duplex.cpp
index 8cc93c3..5eda95f 100644
--- a/test/test_duplex.cpp
+++ b/test/test_duplex.cpp
@@ -96,7 +96,7 @@ TEST(cubeb, duplex)
/* This test needs an available input device, skip it if this host does not
* have one. */
- if (!has_available_input_device(ctx)) {
+ if (!can_run_audio_input_test(ctx)) {
return;
}
diff --git a/test/test_loopback.cpp b/test/test_loopback.cpp
index 9977f6f..ce29d6e 100644
--- a/test/test_loopback.cpp
+++ b/test/test_loopback.cpp
@@ -483,6 +483,10 @@ void run_loopback_device_selection_test(bool is_float)
r = common_init(&ctx, "Cubeb loopback example: device selection, separate streams");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
+ if (!can_run_audio_input_test(ctx)) {
+ return;
+ }
+
std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
cleanup_cubeb_at_exit(ctx, cubeb_destroy);
diff --git a/test/test_record.cpp b/test/test_record.cpp
index eeebd29..ba0c758 100644
--- a/test/test_record.cpp
+++ b/test/test_record.cpp
@@ -86,7 +86,7 @@ TEST(cubeb, record)
/* This test needs an available input device, skip it if this host does not
* have one. */
- if (!has_available_input_device(ctx)) {
+ if (!can_run_audio_input_test(ctx)) {
return;
}