diff options
author | Chun-Min Chang <[email protected]> | 2017-03-29 12:06:26 +0800 |
---|---|---|
committer | Matthew Gregan <[email protected]> | 2017-04-06 20:14:00 +1200 |
commit | 2612c2075b38e94756bea0c8c9941b834c08f26c (patch) | |
tree | 044fbca0824dd6dfcca1fbefe8a9f23944fc3dd4 | |
parent | 04826edb13c23a2b53732d63b09b24e05ca83d87 (diff) | |
download | cubeb-2612c2075b38e94756bea0c8c9941b834c08f26c.tar.gz cubeb-2612c2075b38e94756bea0c8c9941b834c08f26c.zip |
Using RAII helpers for cubeb context and stream but leaving test_sanity for explicit flow control
-rw-r--r-- | test/common.h | 14 | ||||
-rw-r--r-- | test/test_audio.cpp | 22 | ||||
-rw-r--r-- | test/test_devices.cpp | 22 | ||||
-rw-r--r-- | test/test_duplex.cpp | 7 | ||||
-rw-r--r-- | test/test_latency.cpp | 5 | ||||
-rw-r--r-- | test/test_overload_callback.cpp | 7 | ||||
-rw-r--r-- | test/test_record.cpp | 7 | ||||
-rw-r--r-- | test/test_tone.cpp | 7 |
8 files changed, 50 insertions, 41 deletions
diff --git a/test/common.h b/test/common.h index ef53963..d57ad59 100644 --- a/test/common.h +++ b/test/common.h @@ -107,4 +107,18 @@ void print_log(const char * msg, ...) va_end(args); } +struct cubeb_cleaner +{ + cubeb_cleaner(cubeb * context) : ctx(context) {} + ~cubeb_cleaner() { cubeb_destroy(ctx); } + cubeb * ctx; +}; + +struct cubeb_stream_cleaner +{ + cubeb_stream_cleaner(cubeb_stream * stream) : stm(stream) {} + ~cubeb_stream_cleaner() { cubeb_stream_destroy(stm); } + cubeb_stream * stm; +}; + #endif /* TEST_COMMON */ diff --git a/test/test_audio.cpp b/test/test_audio.cpp index d8eb26d..6031d78 100644 --- a/test/test_audio.cpp +++ b/test/test_audio.cpp @@ -75,20 +75,6 @@ long data_cb(cubeb_stream * /*stream*/, void * user, const void * /*inputbuffer* return nframes; } -struct CubebCleaner -{ - CubebCleaner(cubeb* ctx_) : ctx(ctx_) {} - ~CubebCleaner() { cubeb_destroy(ctx); } - cubeb* ctx; -}; - -struct CubebStreamCleaner -{ - CubebStreamCleaner(cubeb_stream* ctx_) : ctx(ctx_) {} - ~CubebStreamCleaner() { cubeb_stream_destroy(ctx); } - cubeb_stream* ctx; -}; - void state_cb_audio(cubeb_stream * /*stream*/, void * /*user*/, cubeb_state /*state*/) { } @@ -124,7 +110,7 @@ int run_test(int num_channels, layout_info layout, int sampling_rate, int is_flo fprintf(stderr, "Error initializing cubeb library\n"); return r; } - CubebCleaner cleanup_cubeb_at_exit(ctx); + cubeb_cleaner cleanup_cubeb_at_exit(ctx); const char * backend_id = cubeb_get_backend_id(ctx); @@ -153,7 +139,7 @@ int run_test(int num_channels, layout_info layout, int sampling_rate, int is_flo return r; } - CubebStreamCleaner cleanup_stream_at_exit(stream); + cubeb_stream_cleaner cleanup_stream_at_exit(stream); cubeb_stream_start(stream); delay(200); @@ -174,7 +160,7 @@ int run_panning_volume_test(int is_float) return r; } - CubebCleaner cleanup_cubeb_at_exit(ctx); + cubeb_cleaner cleanup_cubeb_at_exit(ctx); const char * backend_id = cubeb_get_backend_id(ctx); @@ -201,7 +187,7 @@ int run_panning_volume_test(int is_float) return r; } - CubebStreamCleaner cleanup_stream_at_exit(stream); + cubeb_stream_cleaner cleanup_stream_at_exit(stream); fprintf(stderr, "Testing: volume\n"); for(int i=0;i <= 4; ++i) diff --git a/test/test_devices.cpp b/test/test_devices.cpp index ee062f4..22a09f6 100644 --- a/test/test_devices.cpp +++ b/test/test_devices.cpp @@ -11,6 +11,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include "common.h" #include "cubeb/cubeb.h" static void @@ -103,7 +104,7 @@ print_device_collection(cubeb_device_collection * collection, FILE * f) print_device_info(collection->device[i], f); } -TEST(cubeb, enumerate_devices) +int run_enumerating_devices_test() { int r; cubeb * ctx = NULL; @@ -112,9 +113,11 @@ TEST(cubeb, enumerate_devices) r = cubeb_init(&ctx, "Cubeb audio test", NULL); if (r != CUBEB_OK) { fprintf(stderr, "Error initializing cubeb library\n"); - ASSERT_EQ(r, CUBEB_OK); + return r; } + cubeb_cleaner cleanup_cubeb_at_exit(ctx); + fprintf(stdout, "Enumerating input devices for backend %s\n", cubeb_get_backend_id(ctx)); @@ -122,12 +125,11 @@ TEST(cubeb, enumerate_devices) if (r == CUBEB_ERROR_NOT_SUPPORTED) { fprintf(stderr, "Device enumeration not supported" " for this backend, skipping this test.\n"); - r = CUBEB_OK; - goto cleanup; + return CUBEB_OK; } if (r != CUBEB_OK) { fprintf(stderr, "Error enumerating devices %d\n", r); - goto cleanup; + return r; } fprintf(stdout, "Found %u input devices\n", collection->count); @@ -140,15 +142,17 @@ TEST(cubeb, enumerate_devices) r = cubeb_enumerate_devices(ctx, CUBEB_DEVICE_TYPE_OUTPUT, &collection); if (r != CUBEB_OK) { fprintf(stderr, "Error enumerating devices %d\n", r); - goto cleanup; + return r; } fprintf(stdout, "Found %u output devices\n", collection->count); print_device_collection(collection, stdout); cubeb_device_collection_destroy(collection); -cleanup: - cubeb_destroy(ctx); - ASSERT_EQ(r, CUBEB_OK); + return r; } +TEST(cubeb, enumerate_devices) +{ + ASSERT_EQ(run_enumerating_devices_test(), CUBEB_OK); +} diff --git a/test/test_duplex.cpp b/test/test_duplex.cpp index 9620a1e..a4a938b 100644 --- a/test/test_duplex.cpp +++ b/test/test_duplex.cpp @@ -88,6 +88,8 @@ TEST(cubeb, duplex) ASSERT_EQ(r, CUBEB_OK); } + cubeb_cleaner cleanup_cubeb_at_exit(ctx); + /* This test needs an available input device, skip it if this host does not * have one. */ if (!has_available_input_device(ctx)) { @@ -119,12 +121,11 @@ TEST(cubeb, duplex) ASSERT_EQ(r, CUBEB_OK); } + cubeb_stream_cleaner cleanup_stream_at_exit(stream); + cubeb_stream_start(stream); delay(500); cubeb_stream_stop(stream); - cubeb_stream_destroy(stream); - cubeb_destroy(ctx); - ASSERT_TRUE(stream_state.seen_audio); } diff --git a/test/test_latency.cpp b/test/test_latency.cpp index 77a9908..654c31a 100644 --- a/test/test_latency.cpp +++ b/test/test_latency.cpp @@ -1,5 +1,6 @@ #include "gtest/gtest.h" #include <stdlib.h> +#include "common.h" #include "cubeb/cubeb.h" TEST(cubeb, latency) @@ -14,6 +15,8 @@ TEST(cubeb, latency) r = cubeb_init(&ctx, "Cubeb audio test", NULL); ASSERT_EQ(r, CUBEB_OK); + cubeb_cleaner cleanup_cubeb_at_exit(ctx); + r = cubeb_get_max_channel_count(ctx, &max_channels); ASSERT_TRUE(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED); if (r == CUBEB_OK) { @@ -44,6 +47,4 @@ TEST(cubeb, latency) if (r == CUBEB_OK) { ASSERT_GT(latency_frames, 0u); } - - cubeb_destroy(ctx); } diff --git a/test/test_overload_callback.cpp b/test/test_overload_callback.cpp index fa23222..5a4d511 100644 --- a/test/test_overload_callback.cpp +++ b/test/test_overload_callback.cpp @@ -64,6 +64,8 @@ TEST(cubeb, overload_callback) r = cubeb_init(&ctx, "Cubeb callback overload", NULL); ASSERT_EQ(r, CUBEB_OK); + cubeb_cleaner cleanup_cubeb_at_exit(ctx); + output_params.format = STREAM_FORMAT; output_params.rate = 48000; output_params.channels = 2; @@ -77,13 +79,12 @@ TEST(cubeb, overload_callback) latency_frames, data_cb, state_cb, NULL); ASSERT_EQ(r, CUBEB_OK); + cubeb_stream_cleaner cleanup_stream_at_exit(stream); + cubeb_stream_start(stream); delay(500); // This causes the callback to sleep for a large number of seconds. load_callback = true; delay(500); cubeb_stream_stop(stream); - - cubeb_stream_destroy(stream); - cubeb_destroy(ctx); } diff --git a/test/test_record.cpp b/test/test_record.cpp index 79ca5b6..eb6dfb4 100644 --- a/test/test_record.cpp +++ b/test/test_record.cpp @@ -82,6 +82,8 @@ TEST(cubeb, record) ASSERT_EQ(r, CUBEB_OK); } + cubeb_cleaner cleanup_cubeb_at_exit(ctx); + /* This test needs an available input device, skip it if this host does not * have one. */ if (!has_available_input_device(ctx)) { @@ -100,13 +102,12 @@ TEST(cubeb, record) ASSERT_EQ(r, CUBEB_OK); } + cubeb_stream_cleaner cleanup_stream_at_exit(stream); + cubeb_stream_start(stream); delay(500); cubeb_stream_stop(stream); - cubeb_stream_destroy(stream); - cubeb_destroy(ctx); - #ifdef __linux__ // user callback does not arrive in Linux, silence the error printf("Check is disabled in Linux\n"); diff --git a/test/test_tone.cpp b/test/test_tone.cpp index 2881c09..22c5be2 100644 --- a/test/test_tone.cpp +++ b/test/test_tone.cpp @@ -107,6 +107,8 @@ TEST(cubeb, tone) ASSERT_EQ(r, CUBEB_OK); } + cubeb_cleaner cleanup_cubeb_at_exit(ctx); + params.format = STREAM_FORMAT; params.rate = SAMPLE_FREQUENCY; params.channels = 1; @@ -126,13 +128,12 @@ TEST(cubeb, tone) ASSERT_EQ(r, CUBEB_OK); } + cubeb_stream_cleaner cleanup_stream_at_exit(stream); + cubeb_stream_start(stream); delay(500); cubeb_stream_stop(stream); - cubeb_stream_destroy(stream); - cubeb_destroy(ctx); - ASSERT_TRUE(user_data->position); free(user_data); |