diff options
author | Dan Glastonbury <[email protected]> | 2017-05-23 14:20:11 +1000 |
---|---|---|
committer | Dan Glastonbury <[email protected]> | 2017-05-25 14:24:02 +1000 |
commit | 4efb2e695630d289c01bcb4bbd5c4505d37f4e0e (patch) | |
tree | c6d214564f35c6cdcf2865cfeeaacf1890dc40f0 /test | |
parent | c9641ca143e3263779137f08c58ef43ab0a7c75d (diff) | |
download | cubeb-4efb2e695630d289c01bcb4bbd5c4505d37f4e0e.tar.gz cubeb-4efb2e695630d289c01bcb4bbd5c4505d37f4e0e.zip |
Rework device collection (#309)
Rust compatiblity change to cubeb_device_collection.
Replace the C dynamic allocation with magic header into a structure
that hold pointer + count of entries. This is the same memory layout
that rust uses for fat pointers for &[T], Box<[T]>, etc.
Diffstat (limited to 'test')
-rw-r--r-- | test/common.h | 12 | ||||
-rw-r--r-- | test/test_devices.cpp | 16 |
2 files changed, 14 insertions, 14 deletions
diff --git a/test/common.h b/test/common.h index 6643b7c..9e5a002 100644 --- a/test/common.h +++ b/test/common.h @@ -70,7 +70,7 @@ layout_info const layout_infos[CUBEB_LAYOUT_MAX] = { int has_available_input_device(cubeb * ctx) { - cubeb_device_collection * devices; + cubeb_device_collection devices; int input_device_available = 0; int r; /* Bail out early if the host does not have input devices. */ @@ -80,14 +80,14 @@ int has_available_input_device(cubeb * ctx) return 0; } - if (devices->count == 0) { + if (devices.count == 0) { fprintf(stderr, "no input device available, skipping test.\n"); - cubeb_device_collection_destroy(ctx, devices); + cubeb_device_collection_destroy(ctx, &devices); return 0; } - for (uint32_t i = 0; i < devices->count; i++) { - input_device_available |= (devices->device[i]->state == + for (uint32_t i = 0; i < devices.count; i++) { + input_device_available |= (devices.device[i].state == CUBEB_DEVICE_STATE_ENABLED); } @@ -96,7 +96,7 @@ int has_available_input_device(cubeb * ctx) "available, skipping\n"); } - cubeb_device_collection_destroy(ctx, devices); + cubeb_device_collection_destroy(ctx, &devices); return !!input_device_available; } diff --git a/test/test_devices.cpp b/test/test_devices.cpp index d0a524d..8bc9190 100644 --- a/test/test_devices.cpp +++ b/test/test_devices.cpp @@ -102,14 +102,14 @@ print_device_collection(cubeb_device_collection * collection, FILE * f) uint32_t i; for (i = 0; i < collection->count; i++) - print_device_info(collection->device[i], f); + print_device_info(&collection->device[i], f); } TEST(cubeb, enumerate_devices) { int r; cubeb * ctx = NULL; - cubeb_device_collection * collection = NULL; + cubeb_device_collection collection; r = common_init(&ctx, "Cubeb audio test"); ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library"; @@ -128,9 +128,9 @@ TEST(cubeb, enumerate_devices) } ASSERT_EQ(r, CUBEB_OK) << "Error enumerating devices " << r; - fprintf(stdout, "Found %u input devices\n", collection->count); - print_device_collection(collection, stdout); - cubeb_device_collection_destroy(ctx, collection); + fprintf(stdout, "Found %zu input devices\n", collection.count); + print_device_collection(&collection, stdout); + cubeb_device_collection_destroy(ctx, &collection); fprintf(stdout, "Enumerating output devices for backend %s\n", cubeb_get_backend_id(ctx)); @@ -138,7 +138,7 @@ TEST(cubeb, enumerate_devices) r = cubeb_enumerate_devices(ctx, CUBEB_DEVICE_TYPE_OUTPUT, &collection); ASSERT_EQ(r, CUBEB_OK) << "Error enumerating devices " << r; - fprintf(stdout, "Found %u output devices\n", collection->count); - print_device_collection(collection, stdout); - cubeb_device_collection_destroy(ctx, collection); + fprintf(stdout, "Found %zu output devices\n", collection.count); + print_device_collection(&collection, stdout); + cubeb_device_collection_destroy(ctx, &collection); } |