зеркало из https://github.com/mozilla/cubeb.git
Convert tests to gtests.
This commit is contained in:
Родитель
0d45a294ee
Коммит
55ed801cfd
|
@ -166,7 +166,7 @@ target_include_directories(test_record PRIVATE ${gtest_SOURCE_DIR}/include)
|
|||
target_link_libraries(test_record PRIVATE cubeb gtest_main)
|
||||
add_test(record test_record)
|
||||
|
||||
add_executable(test_devices test/test_devices.c)
|
||||
add_executable(test_devices test/test_devices.cpp)
|
||||
target_include_directories(test_devices PRIVATE ${gtest_SOURCE_DIR}/include)
|
||||
target_link_libraries(test_devices PRIVATE cubeb gtest_main)
|
||||
add_test(devices test_devices)
|
||||
|
|
|
@ -7,16 +7,12 @@
|
|||
|
||||
/* libcubeb api/function exhaustive test. Plays a series of tones in different
|
||||
* conditions. */
|
||||
#ifdef NDEBUG
|
||||
#undef NDEBUG
|
||||
#endif
|
||||
#define _XOPEN_SOURCE 600
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "cubeb/cubeb.h"
|
||||
#include "common.h"
|
||||
|
||||
|
@ -268,20 +264,18 @@ void run_channel_rate_test()
|
|||
|
||||
for(int j = 0; j < NELEMS(channel_values); ++j) {
|
||||
for(int i = 0; i < NELEMS(freq_values); ++i) {
|
||||
assert(channel_values[j] < MAX_NUM_CHANNELS);
|
||||
ASSERT_TRUE(channel_values[j] < MAX_NUM_CHANNELS);
|
||||
fprintf(stderr, "--------------------------\n");
|
||||
assert(run_test(channel_values[j], freq_values[i], 0) == CUBEB_OK);
|
||||
assert(run_test(channel_values[j], freq_values[i], 1) == CUBEB_OK);
|
||||
ASSERT_TRUE(run_test(channel_values[j], freq_values[i], 0) == CUBEB_OK);
|
||||
ASSERT_TRUE(run_test(channel_values[j], freq_values[i], 1) == CUBEB_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int /*argc*/, char * /*argv*/[])
|
||||
TEST(audio, main)
|
||||
{
|
||||
assert(run_panning_volume_test(0) == CUBEB_OK);
|
||||
assert(run_panning_volume_test(1) == CUBEB_OK);
|
||||
ASSERT_TRUE(run_panning_volume_test(0) == CUBEB_OK);
|
||||
ASSERT_TRUE(run_panning_volume_test(1) == CUBEB_OK);
|
||||
run_channel_rate_test();
|
||||
|
||||
return CUBEB_OK;
|
||||
}
|
||||
|
|
|
@ -7,17 +7,12 @@
|
|||
|
||||
/* libcubeb enumerate device test/example.
|
||||
* Prints out a list of devices enumerated. */
|
||||
#ifdef NDEBUG
|
||||
#undef NDEBUG
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "cubeb/cubeb.h"
|
||||
|
||||
|
||||
static void
|
||||
print_device_info(cubeb_device_info * info, FILE * f)
|
||||
{
|
||||
|
@ -158,13 +153,11 @@ cleanup:
|
|||
return r;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
TEST(devices, main)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
int ret;
|
||||
|
||||
ret = run_enumerate_devices();
|
||||
|
||||
return ret;
|
||||
ASSERT_EQ(ret, 0);
|
||||
}
|
|
@ -7,15 +7,11 @@
|
|||
|
||||
/* libcubeb api/function test. Loops input back to output and check audio
|
||||
* is flowing. */
|
||||
#ifdef NDEBUG
|
||||
#undef NDEBUG
|
||||
#endif
|
||||
#define _XOPEN_SOURCE 600
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "cubeb/cubeb.h"
|
||||
#include "common.h"
|
||||
|
||||
|
@ -86,7 +82,7 @@ void state_cb(cubeb_stream * stream, void * /*user*/, cubeb_state state)
|
|||
return;
|
||||
}
|
||||
|
||||
int main(int /*argc*/, char * /*argv*/[])
|
||||
TEST(duplex, main)
|
||||
{
|
||||
cubeb *ctx;
|
||||
cubeb_stream *stream;
|
||||
|
@ -99,13 +95,13 @@ int main(int /*argc*/, char * /*argv*/[])
|
|||
r = cubeb_init(&ctx, "Cubeb duplex example");
|
||||
if (r != CUBEB_OK) {
|
||||
fprintf(stderr, "Error initializing cubeb library\n");
|
||||
return r;
|
||||
ASSERT_EQ(r, CUBEB_OK);
|
||||
}
|
||||
|
||||
/* This test needs an available input device, skip it if this host does not
|
||||
* have one. */
|
||||
if (!has_available_input_device(ctx)) {
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* typical user-case: mono input, stereo output, low latency. */
|
||||
|
@ -120,7 +116,7 @@ int main(int /*argc*/, char * /*argv*/[])
|
|||
|
||||
if (r != CUBEB_OK) {
|
||||
fprintf(stderr, "Could not get minimal latency\n");
|
||||
return r;
|
||||
ASSERT_EQ(r, CUBEB_OK);
|
||||
}
|
||||
|
||||
r = cubeb_stream_init(ctx, &stream, "Cubeb duplex",
|
||||
|
@ -128,7 +124,7 @@ int main(int /*argc*/, char * /*argv*/[])
|
|||
latency_frames, data_cb, state_cb, &stream_state);
|
||||
if (r != CUBEB_OK) {
|
||||
fprintf(stderr, "Error initializing cubeb stream\n");
|
||||
return r;
|
||||
ASSERT_EQ(r, CUBEB_OK);
|
||||
}
|
||||
|
||||
cubeb_stream_start(stream);
|
||||
|
@ -138,7 +134,5 @@ int main(int /*argc*/, char * /*argv*/[])
|
|||
cubeb_stream_destroy(stream);
|
||||
cubeb_destroy(ctx);
|
||||
|
||||
assert(stream_state.seen_noise);
|
||||
|
||||
return CUBEB_OK;
|
||||
ASSERT_TRUE(stream_state.seen_noise);
|
||||
}
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
#ifdef NDEBUG
|
||||
#undef NDEBUG
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include "cubeb/cubeb.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "gtest/gtest.h"
|
||||
#include "cubeb/cubeb.h"
|
||||
|
||||
#define LOG(msg) fprintf(stderr, "%s\n", msg);
|
||||
|
||||
int main(int /*argc*/, char * /*argv*/[])
|
||||
TEST(latency, main)
|
||||
{
|
||||
cubeb * ctx = NULL;
|
||||
int r;
|
||||
|
@ -18,20 +15,20 @@ int main(int /*argc*/, char * /*argv*/[])
|
|||
|
||||
LOG("latency_test start");
|
||||
r = cubeb_init(&ctx, "Cubeb audio test");
|
||||
assert(r == CUBEB_OK && "Cubeb init failed.");
|
||||
ASSERT_TRUE(r == CUBEB_OK && "Cubeb init failed.");
|
||||
LOG("cubeb_init ok");
|
||||
|
||||
r = cubeb_get_max_channel_count(ctx, &max_channels);
|
||||
assert(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
|
||||
ASSERT_TRUE(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
|
||||
if (r == CUBEB_OK) {
|
||||
assert(max_channels > 0 && "Invalid max channel count.");
|
||||
ASSERT_TRUE(max_channels > 0 && "Invalid max channel count.");
|
||||
LOG("cubeb_get_max_channel_count ok");
|
||||
}
|
||||
|
||||
r = cubeb_get_preferred_sample_rate(ctx, &preferred_rate);
|
||||
assert(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
|
||||
ASSERT_TRUE(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
|
||||
if (r == CUBEB_OK) {
|
||||
assert(preferred_rate > 0 && "Invalid preferred sample rate.");
|
||||
ASSERT_TRUE(preferred_rate > 0 && "Invalid preferred sample rate.");
|
||||
LOG("cubeb_get_preferred_sample_rate ok");
|
||||
}
|
||||
|
||||
|
@ -41,13 +38,12 @@ int main(int /*argc*/, char * /*argv*/[])
|
|||
max_channels
|
||||
};
|
||||
r = cubeb_get_min_latency(ctx, params, &latency_frames);
|
||||
assert(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
|
||||
ASSERT_TRUE(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
|
||||
if (r == CUBEB_OK) {
|
||||
assert(latency_frames > 0 && "Invalid minimal latency.");
|
||||
ASSERT_TRUE(latency_frames > 0 && "Invalid minimal latency.");
|
||||
LOG("cubeb_get_min_latency ok");
|
||||
}
|
||||
|
||||
cubeb_destroy(ctx);
|
||||
LOG("cubeb_destroy ok");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -6,15 +6,11 @@
|
|||
*/
|
||||
|
||||
/* libcubeb api/function test. Record the mic and check there is sound. */
|
||||
#ifdef NDEBUG
|
||||
#undef NDEBUG
|
||||
#endif
|
||||
#define _XOPEN_SOURCE 600
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "cubeb/cubeb.h"
|
||||
#include "common.h"
|
||||
|
||||
|
@ -74,7 +70,7 @@ void state_cb(cubeb_stream * stream, void * /*user*/, cubeb_state state)
|
|||
return;
|
||||
}
|
||||
|
||||
int main(int /*argc*/, char * /*argv*/[])
|
||||
TEST(record, main)
|
||||
{
|
||||
cubeb *ctx;
|
||||
cubeb_stream *stream;
|
||||
|
@ -85,13 +81,13 @@ int main(int /*argc*/, char * /*argv*/[])
|
|||
r = cubeb_init(&ctx, "Cubeb record example");
|
||||
if (r != CUBEB_OK) {
|
||||
fprintf(stderr, "Error initializing cubeb library\n");
|
||||
return r;
|
||||
ASSERT_EQ(r, CUBEB_OK);
|
||||
}
|
||||
|
||||
/* This test needs an available input device, skip it if this host does not
|
||||
* have one. */
|
||||
if (!has_available_input_device(ctx)) {
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
params.format = STREAM_FORMAT;
|
||||
|
@ -102,7 +98,7 @@ int main(int /*argc*/, char * /*argv*/[])
|
|||
4096, data_cb, state_cb, &stream_state);
|
||||
if (r != CUBEB_OK) {
|
||||
fprintf(stderr, "Error initializing cubeb stream\n");
|
||||
return r;
|
||||
ASSERT_EQ(r, CUBEB_OK);
|
||||
}
|
||||
|
||||
cubeb_stream_start(stream);
|
||||
|
@ -112,7 +108,5 @@ int main(int /*argc*/, char * /*argv*/[])
|
|||
cubeb_stream_destroy(stream);
|
||||
cubeb_destroy(ctx);
|
||||
|
||||
assert(stream_state.seen_noise);
|
||||
|
||||
return CUBEB_OK;
|
||||
ASSERT_TRUE(stream_state.seen_noise);
|
||||
}
|
||||
|
|
|
@ -7,15 +7,11 @@
|
|||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif // NOMINMAX
|
||||
|
||||
#ifdef NDEBUG
|
||||
#undef NDEBUG
|
||||
#endif
|
||||
#include "cubeb_resampler_internal.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
/* Windows cmath USE_MATH_DEFINE thing... */
|
||||
const float PI = 3.14159265359f;
|
||||
|
@ -154,7 +150,7 @@ void test_delay_lines(uint32_t delay_frames, uint32_t channels, uint32_t chunk_m
|
|||
|
||||
// Check the diracs have been shifted by `delay_frames` frames.
|
||||
for (uint32_t i = 0; i < output.length() - delay_frames * channels + 1; i+=100) {
|
||||
assert(output.data()[i + channel + delay_frames * channels] == 0.5);
|
||||
ASSERT_TRUE(output.data()[i + channel + delay_frames * channels] == 0.5);
|
||||
channel = (channel + 1) % channels;
|
||||
}
|
||||
|
||||
|
@ -232,7 +228,7 @@ void test_resampler_one_way(uint32_t channels, uint32_t source_rate, uint32_t ta
|
|||
fuzzy_equal = false;
|
||||
}
|
||||
}
|
||||
assert(fuzzy_equal);
|
||||
ASSERT_TRUE(fuzzy_equal);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -397,8 +393,8 @@ void test_resampler_duplex(uint32_t input_channels, uint32_t output_channels,
|
|||
dump("input.raw", state.input.data(), state.input.length());
|
||||
dump("output.raw", state.output.data(), state.output.length());
|
||||
|
||||
assert(array_fuzzy_equal(state.input, expected_resampled_input, epsilon<T>(input_rate/target_rate)));
|
||||
assert(array_fuzzy_equal(state.output, expected_resampled_output, epsilon<T>(output_rate/target_rate)));
|
||||
ASSERT_TRUE(array_fuzzy_equal(state.input, expected_resampled_input, epsilon<T>(input_rate/target_rate)));
|
||||
ASSERT_TRUE(array_fuzzy_equal(state.output, expected_resampled_output, epsilon<T>(output_rate/target_rate)));
|
||||
|
||||
cubeb_resampler_destroy(resampler);
|
||||
}
|
||||
|
@ -468,8 +464,8 @@ long test_output_only_noop_data_cb(cubeb_stream * /*stm*/, void * /*user_ptr*/,
|
|||
const void * input_buffer,
|
||||
void * output_buffer, long frame_count)
|
||||
{
|
||||
assert(output_buffer);
|
||||
assert(!input_buffer);
|
||||
EXPECT_TRUE(output_buffer);
|
||||
EXPECT_TRUE(!input_buffer);
|
||||
return frame_count;
|
||||
}
|
||||
|
||||
|
@ -495,7 +491,7 @@ void test_output_only_noop()
|
|||
got = cubeb_resampler_fill(resampler, nullptr, nullptr,
|
||||
out_buffer, out_frames);
|
||||
|
||||
assert(got == out_frames);
|
||||
ASSERT_TRUE(got == out_frames);
|
||||
|
||||
cubeb_resampler_destroy(resampler);
|
||||
}
|
||||
|
@ -504,8 +500,8 @@ long test_drain_data_cb(cubeb_stream * /*stm*/, void * /*user_ptr*/,
|
|||
const void * input_buffer,
|
||||
void * output_buffer, long frame_count)
|
||||
{
|
||||
assert(output_buffer);
|
||||
assert(!input_buffer);
|
||||
EXPECT_TRUE(output_buffer);
|
||||
EXPECT_TRUE(!input_buffer);
|
||||
return frame_count - 10;
|
||||
}
|
||||
|
||||
|
@ -535,12 +531,12 @@ void test_resampler_drain()
|
|||
|
||||
/* If the above is not an infinite loop, the drain was a success, just mark
|
||||
* this test as such. */
|
||||
assert(true);
|
||||
ASSERT_TRUE(true);
|
||||
|
||||
cubeb_resampler_destroy(resampler);
|
||||
}
|
||||
|
||||
int main()
|
||||
TEST(resampler, main)
|
||||
{
|
||||
test_resamplers_one_way();
|
||||
test_delay_line();
|
||||
|
@ -549,6 +545,4 @@ int main()
|
|||
// test_resamplers_duplex();
|
||||
test_output_only_noop();
|
||||
test_resampler_drain();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,19 +1,17 @@
|
|||
#include "gtest/gtest.h"
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include <CoreAudio/CoreAudioTypes.h>
|
||||
|
||||
#include "cubeb/cubeb.h"
|
||||
#include "cubeb_ring_array.h"
|
||||
|
||||
int test_ring_array()
|
||||
void test_ring_array()
|
||||
{
|
||||
ring_array ra;
|
||||
|
||||
assert(ring_array_init(&ra, 0, 0, 1, 1) == CUBEB_ERROR_INVALID_PARAMETER);
|
||||
assert(ring_array_init(&ra, 1, 0, 0, 1) == CUBEB_ERROR_INVALID_PARAMETER);
|
||||
ASSERT_TRUE(ring_array_init(&ra, 0, 0, 1, 1) == CUBEB_ERROR_INVALID_PARAMETER);
|
||||
ASSERT_TRUE(ring_array_init(&ra, 1, 0, 0, 1) == CUBEB_ERROR_INVALID_PARAMETER);
|
||||
|
||||
unsigned int capacity = 8;
|
||||
ring_array_init(&ra, capacity, sizeof(int), 1, 1);
|
||||
|
@ -23,64 +21,56 @@ int test_ring_array()
|
|||
for (unsigned int i = 0; i < capacity; ++i) {
|
||||
verify_data[i] = i; // in case capacity change value
|
||||
*(int*)ra.buffer_array[i].mData = i;
|
||||
assert(ra.buffer_array[i].mDataByteSize == 1 * sizeof(int));
|
||||
assert(ra.buffer_array[i].mNumberChannels == 1);
|
||||
ASSERT_TRUE(ra.buffer_array[i].mDataByteSize == 1 * sizeof(int));
|
||||
ASSERT_TRUE(ra.buffer_array[i].mNumberChannels == 1);
|
||||
}
|
||||
|
||||
/* Get store buffers*/
|
||||
for (unsigned int i = 0; i < capacity; ++i) {
|
||||
p_data = ring_array_get_free_buffer(&ra);
|
||||
assert(p_data && *(int*)p_data->mData == verify_data[i]);
|
||||
ASSERT_TRUE(p_data && *(int*)p_data->mData == verify_data[i]);
|
||||
}
|
||||
/*Now array is full extra store should give NULL*/
|
||||
assert(NULL == ring_array_get_free_buffer(&ra));
|
||||
ASSERT_TRUE(NULL == ring_array_get_free_buffer(&ra));
|
||||
/* Get fetch buffers*/
|
||||
for (unsigned int i = 0; i < capacity; ++i) {
|
||||
p_data = ring_array_get_data_buffer(&ra);
|
||||
assert(p_data && *(int*)p_data->mData == verify_data[i]);
|
||||
ASSERT_TRUE(p_data && *(int*)p_data->mData == verify_data[i]);
|
||||
}
|
||||
/*Now array is empty extra fetch should give NULL*/
|
||||
assert(NULL == ring_array_get_data_buffer(&ra));
|
||||
ASSERT_TRUE(NULL == ring_array_get_data_buffer(&ra));
|
||||
|
||||
p_data = NULL;
|
||||
/* Repeated store fetch should can go for ever*/
|
||||
for (unsigned int i = 0; i < 2*capacity; ++i) {
|
||||
p_data = ring_array_get_free_buffer(&ra);
|
||||
assert(p_data);
|
||||
assert(ring_array_get_data_buffer(&ra) == p_data);
|
||||
ASSERT_TRUE(p_data);
|
||||
ASSERT_TRUE(ring_array_get_data_buffer(&ra) == p_data);
|
||||
}
|
||||
|
||||
p_data = NULL;
|
||||
/* Verify/modify buffer data*/
|
||||
for (unsigned int i = 0; i < capacity; ++i) {
|
||||
p_data = ring_array_get_free_buffer(&ra);
|
||||
assert(p_data);
|
||||
assert(*((int*)p_data->mData) == verify_data[i]);
|
||||
ASSERT_TRUE(p_data);
|
||||
ASSERT_TRUE(*((int*)p_data->mData) == verify_data[i]);
|
||||
(*((int*)p_data->mData))++; // Modify data
|
||||
}
|
||||
for (unsigned int i = 0; i < capacity; ++i) {
|
||||
p_data = ring_array_get_data_buffer(&ra);
|
||||
assert(p_data);
|
||||
assert(*((int*)p_data->mData) == verify_data[i]+1); // Verify modified data
|
||||
ASSERT_TRUE(p_data);
|
||||
ASSERT_TRUE(*((int*)p_data->mData) == verify_data[i]+1); // Verify modified data
|
||||
}
|
||||
|
||||
ring_array_destroy(&ra);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
TEST(ring_array, main)
|
||||
{
|
||||
test_ring_array();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
TEST(ring_array, main)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,16 +4,13 @@
|
|||
* This program is made available under an ISC-style license. See the
|
||||
* accompanying file LICENSE for details.
|
||||
*/
|
||||
#ifdef NDEBUG
|
||||
#undef NDEBUG
|
||||
#endif
|
||||
#define _XOPEN_SOURCE 600
|
||||
#include "cubeb/cubeb.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "common.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#define BEGIN_TEST fprintf(stderr, "START %s\n", __func__)
|
||||
#define END_TEST fprintf(stderr, "END %s\n", __func__)
|
||||
|
@ -41,7 +38,7 @@ static int delay_callback;
|
|||
static long
|
||||
test_data_callback(cubeb_stream * stm, void * user_ptr, const void * /*inputbuffer*/, void * outputbuffer, long nframes)
|
||||
{
|
||||
assert(stm && user_ptr == &dummy && outputbuffer && nframes > 0);
|
||||
EXPECT_TRUE(stm && user_ptr == &dummy && outputbuffer && nframes > 0);
|
||||
#if (defined(_WIN32) || defined(__WIN32__))
|
||||
memset(outputbuffer, 0, nframes * sizeof(float));
|
||||
#else
|
||||
|
@ -70,11 +67,11 @@ test_init_destroy_context(void)
|
|||
BEGIN_TEST;
|
||||
|
||||
r = cubeb_init(&ctx, "test_sanity");
|
||||
assert(r == 0 && ctx);
|
||||
ASSERT_TRUE(r == 0 && ctx);
|
||||
|
||||
|
||||
backend_id = cubeb_get_backend_id(ctx);
|
||||
assert(backend_id);
|
||||
ASSERT_TRUE(backend_id);
|
||||
|
||||
fprintf(stderr, "Backend: %s\n", backend_id);
|
||||
|
||||
|
@ -90,13 +87,13 @@ test_init_destroy_multiple_contexts(void)
|
|||
int r;
|
||||
cubeb * ctx[4];
|
||||
int order[4] = {2, 0, 3, 1};
|
||||
assert(ARRAY_LENGTH(ctx) == ARRAY_LENGTH(order));
|
||||
ASSERT_TRUE(ARRAY_LENGTH(ctx) == ARRAY_LENGTH(order));
|
||||
|
||||
BEGIN_TEST;
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(ctx); ++i) {
|
||||
r = cubeb_init(&ctx[i], NULL);
|
||||
assert(r == 0 && ctx[i]);
|
||||
ASSERT_TRUE(r == 0 && ctx[i]);
|
||||
}
|
||||
|
||||
/* destroy in a different order */
|
||||
|
@ -118,7 +115,7 @@ test_context_variables(void)
|
|||
BEGIN_TEST;
|
||||
|
||||
r = cubeb_init(&ctx, "test_context_variables");
|
||||
assert(r == 0 && ctx);
|
||||
ASSERT_TRUE(r == 0 && ctx);
|
||||
|
||||
params.channels = STREAM_CHANNELS;
|
||||
params.format = STREAM_FORMAT;
|
||||
|
@ -127,15 +124,15 @@ test_context_variables(void)
|
|||
params.stream_type = CUBEB_STREAM_TYPE_MUSIC;
|
||||
#endif
|
||||
r = cubeb_get_min_latency(ctx, params, &value);
|
||||
assert(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
|
||||
ASSERT_TRUE(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
|
||||
if (r == CUBEB_OK) {
|
||||
assert(value > 0);
|
||||
ASSERT_TRUE(value > 0);
|
||||
}
|
||||
|
||||
r = cubeb_get_preferred_sample_rate(ctx, &value);
|
||||
assert(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
|
||||
ASSERT_TRUE(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
|
||||
if (r == CUBEB_OK) {
|
||||
assert(value > 0);
|
||||
ASSERT_TRUE(value > 0);
|
||||
}
|
||||
|
||||
cubeb_destroy(ctx);
|
||||
|
@ -154,7 +151,7 @@ test_init_destroy_stream(void)
|
|||
BEGIN_TEST;
|
||||
|
||||
r = cubeb_init(&ctx, "test_sanity");
|
||||
assert(r == 0 && ctx);
|
||||
ASSERT_TRUE(r == 0 && ctx);
|
||||
|
||||
params.format = STREAM_FORMAT;
|
||||
params.rate = STREAM_RATE;
|
||||
|
@ -165,7 +162,7 @@ test_init_destroy_stream(void)
|
|||
|
||||
r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, ¶ms, STREAM_LATENCY,
|
||||
test_data_callback, test_state_callback, &dummy);
|
||||
assert(r == 0 && stream);
|
||||
ASSERT_TRUE(r == 0 && stream);
|
||||
|
||||
cubeb_stream_destroy(stream);
|
||||
cubeb_destroy(ctx);
|
||||
|
@ -185,7 +182,7 @@ test_init_destroy_multiple_streams(void)
|
|||
BEGIN_TEST;
|
||||
|
||||
r = cubeb_init(&ctx, "test_sanity");
|
||||
assert(r == 0 && ctx);
|
||||
ASSERT_TRUE(r == 0 && ctx);
|
||||
|
||||
params.format = STREAM_FORMAT;
|
||||
params.rate = STREAM_RATE;
|
||||
|
@ -197,8 +194,8 @@ test_init_destroy_multiple_streams(void)
|
|||
for (i = 0; i < ARRAY_LENGTH(stream); ++i) {
|
||||
r = cubeb_stream_init(ctx, &stream[i], "test", NULL, NULL, NULL, ¶ms, STREAM_LATENCY,
|
||||
test_data_callback, test_state_callback, &dummy);
|
||||
assert(r == 0);
|
||||
assert(stream[i]);
|
||||
ASSERT_TRUE(r == 0);
|
||||
ASSERT_TRUE(stream[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(stream); ++i) {
|
||||
|
@ -221,7 +218,7 @@ test_configure_stream(void)
|
|||
BEGIN_TEST;
|
||||
|
||||
r = cubeb_init(&ctx, "test_sanity");
|
||||
assert(r == 0 && ctx);
|
||||
ASSERT_TRUE(r == 0 && ctx);
|
||||
|
||||
params.format = STREAM_FORMAT;
|
||||
params.rate = STREAM_RATE;
|
||||
|
@ -232,13 +229,13 @@ test_configure_stream(void)
|
|||
|
||||
r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, ¶ms, STREAM_LATENCY,
|
||||
test_data_callback, test_state_callback, &dummy);
|
||||
assert(r == 0 && stream);
|
||||
ASSERT_TRUE(r == 0 && stream);
|
||||
|
||||
r = cubeb_stream_set_volume(stream, 1.0f);
|
||||
assert(r == 0 || r == CUBEB_ERROR_NOT_SUPPORTED);
|
||||
ASSERT_TRUE(r == 0 || r == CUBEB_ERROR_NOT_SUPPORTED);
|
||||
|
||||
r = cubeb_stream_set_panning(stream, 0.0f);
|
||||
assert(r == 0 || r == CUBEB_ERROR_NOT_SUPPORTED);
|
||||
ASSERT_TRUE(r == 0 || r == CUBEB_ERROR_NOT_SUPPORTED);
|
||||
|
||||
cubeb_stream_destroy(stream);
|
||||
cubeb_destroy(ctx);
|
||||
|
@ -257,7 +254,7 @@ test_init_start_stop_destroy_multiple_streams(int early, int delay_ms)
|
|||
BEGIN_TEST;
|
||||
|
||||
r = cubeb_init(&ctx, "test_sanity");
|
||||
assert(r == 0 && ctx);
|
||||
ASSERT_TRUE(r == 0 && ctx);
|
||||
|
||||
params.format = STREAM_FORMAT;
|
||||
params.rate = STREAM_RATE;
|
||||
|
@ -269,11 +266,11 @@ test_init_start_stop_destroy_multiple_streams(int early, int delay_ms)
|
|||
for (i = 0; i < ARRAY_LENGTH(stream); ++i) {
|
||||
r = cubeb_stream_init(ctx, &stream[i], "test", NULL, NULL, NULL, ¶ms, STREAM_LATENCY,
|
||||
test_data_callback, test_state_callback, &dummy);
|
||||
assert(r == 0);
|
||||
assert(stream[i]);
|
||||
ASSERT_TRUE(r == 0);
|
||||
ASSERT_TRUE(stream[i]);
|
||||
if (early) {
|
||||
r = cubeb_stream_start(stream[i]);
|
||||
assert(r == 0);
|
||||
ASSERT_TRUE(r == 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -281,7 +278,7 @@ test_init_start_stop_destroy_multiple_streams(int early, int delay_ms)
|
|||
if (!early) {
|
||||
for (i = 0; i < ARRAY_LENGTH(stream); ++i) {
|
||||
r = cubeb_stream_start(stream[i]);
|
||||
assert(r == 0);
|
||||
ASSERT_TRUE(r == 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -292,14 +289,14 @@ test_init_start_stop_destroy_multiple_streams(int early, int delay_ms)
|
|||
if (!early) {
|
||||
for (i = 0; i < ARRAY_LENGTH(stream); ++i) {
|
||||
r = cubeb_stream_stop(stream[i]);
|
||||
assert(r == 0);
|
||||
ASSERT_TRUE(r == 0);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(stream); ++i) {
|
||||
if (early) {
|
||||
r = cubeb_stream_stop(stream[i]);
|
||||
assert(r == 0);
|
||||
ASSERT_TRUE(r == 0);
|
||||
}
|
||||
cubeb_stream_destroy(stream[i]);
|
||||
}
|
||||
|
@ -318,7 +315,7 @@ test_init_destroy_multiple_contexts_and_streams(void)
|
|||
cubeb_stream * stream[8];
|
||||
cubeb_stream_params params;
|
||||
size_t streams_per_ctx = ARRAY_LENGTH(stream) / ARRAY_LENGTH(ctx);
|
||||
assert(ARRAY_LENGTH(ctx) * streams_per_ctx == ARRAY_LENGTH(stream));
|
||||
ASSERT_TRUE(ARRAY_LENGTH(ctx) * streams_per_ctx == ARRAY_LENGTH(stream));
|
||||
|
||||
BEGIN_TEST;
|
||||
|
||||
|
@ -331,13 +328,13 @@ test_init_destroy_multiple_contexts_and_streams(void)
|
|||
|
||||
for (i = 0; i < ARRAY_LENGTH(ctx); ++i) {
|
||||
r = cubeb_init(&ctx[i], "test_sanity");
|
||||
assert(r == 0 && ctx[i]);
|
||||
ASSERT_TRUE(r == 0 && ctx[i]);
|
||||
|
||||
for (j = 0; j < streams_per_ctx; ++j) {
|
||||
r = cubeb_stream_init(ctx[i], &stream[i * streams_per_ctx + j], "test", NULL, NULL, NULL, ¶ms, STREAM_LATENCY,
|
||||
test_data_callback, test_state_callback, &dummy);
|
||||
assert(r == 0);
|
||||
assert(stream[i * streams_per_ctx + j]);
|
||||
ASSERT_TRUE(r == 0);
|
||||
ASSERT_TRUE(stream[i * streams_per_ctx + j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -363,7 +360,7 @@ test_basic_stream_operations(void)
|
|||
BEGIN_TEST;
|
||||
|
||||
r = cubeb_init(&ctx, "test_sanity");
|
||||
assert(r == 0 && ctx);
|
||||
ASSERT_TRUE(r == 0 && ctx);
|
||||
|
||||
params.format = STREAM_FORMAT;
|
||||
params.rate = STREAM_RATE;
|
||||
|
@ -374,25 +371,25 @@ test_basic_stream_operations(void)
|
|||
|
||||
r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, ¶ms, STREAM_LATENCY,
|
||||
test_data_callback, test_state_callback, &dummy);
|
||||
assert(r == 0 && stream);
|
||||
ASSERT_TRUE(r == 0 && stream);
|
||||
|
||||
/* position and volume before stream has started */
|
||||
r = cubeb_stream_get_position(stream, &position);
|
||||
assert(r == 0 && position == 0);
|
||||
ASSERT_TRUE(r == 0 && position == 0);
|
||||
|
||||
r = cubeb_stream_start(stream);
|
||||
assert(r == 0);
|
||||
ASSERT_TRUE(r == 0);
|
||||
|
||||
/* position and volume after while stream running */
|
||||
r = cubeb_stream_get_position(stream, &position);
|
||||
assert(r == 0);
|
||||
ASSERT_TRUE(r == 0);
|
||||
|
||||
r = cubeb_stream_stop(stream);
|
||||
assert(r == 0);
|
||||
ASSERT_TRUE(r == 0);
|
||||
|
||||
/* position and volume after stream has stopped */
|
||||
r = cubeb_stream_get_position(stream, &position);
|
||||
assert(r == 0);
|
||||
ASSERT_TRUE(r == 0);
|
||||
|
||||
cubeb_stream_destroy(stream);
|
||||
cubeb_destroy(ctx);
|
||||
|
@ -415,7 +412,7 @@ test_stream_position(void)
|
|||
total_frames_written = 0;
|
||||
|
||||
r = cubeb_init(&ctx, "test_sanity");
|
||||
assert(r == 0 && ctx);
|
||||
ASSERT_TRUE(r == 0 && ctx);
|
||||
|
||||
params.format = STREAM_FORMAT;
|
||||
params.rate = STREAM_RATE;
|
||||
|
@ -426,44 +423,44 @@ test_stream_position(void)
|
|||
|
||||
r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, ¶ms, STREAM_LATENCY,
|
||||
test_data_callback, test_state_callback, &dummy);
|
||||
assert(r == 0 && stream);
|
||||
ASSERT_TRUE(r == 0 && stream);
|
||||
|
||||
/* stream position should not advance before starting playback */
|
||||
r = cubeb_stream_get_position(stream, &position);
|
||||
assert(r == 0 && position == 0);
|
||||
ASSERT_TRUE(r == 0 && position == 0);
|
||||
|
||||
delay(500);
|
||||
|
||||
r = cubeb_stream_get_position(stream, &position);
|
||||
assert(r == 0 && position == 0);
|
||||
ASSERT_TRUE(r == 0 && position == 0);
|
||||
|
||||
/* stream position should advance during playback */
|
||||
r = cubeb_stream_start(stream);
|
||||
assert(r == 0);
|
||||
ASSERT_TRUE(r == 0);
|
||||
|
||||
/* XXX let start happen */
|
||||
delay(500);
|
||||
|
||||
/* stream should have prefilled */
|
||||
assert(total_frames_written > 0);
|
||||
ASSERT_TRUE(total_frames_written > 0);
|
||||
|
||||
r = cubeb_stream_get_position(stream, &position);
|
||||
assert(r == 0);
|
||||
ASSERT_TRUE(r == 0);
|
||||
last_position = position;
|
||||
|
||||
delay(500);
|
||||
|
||||
r = cubeb_stream_get_position(stream, &position);
|
||||
assert(r == 0);
|
||||
assert(position >= last_position);
|
||||
ASSERT_TRUE(r == 0);
|
||||
ASSERT_TRUE(position >= last_position);
|
||||
last_position = position;
|
||||
|
||||
/* stream position should not exceed total frames written */
|
||||
for (i = 0; i < 5; ++i) {
|
||||
r = cubeb_stream_get_position(stream, &position);
|
||||
assert(r == 0);
|
||||
assert(position >= last_position);
|
||||
assert(position <= total_frames_written);
|
||||
ASSERT_TRUE(r == 0);
|
||||
ASSERT_TRUE(position >= last_position);
|
||||
ASSERT_TRUE(position <= total_frames_written);
|
||||
last_position = position;
|
||||
delay(500);
|
||||
}
|
||||
|
@ -472,35 +469,35 @@ test_stream_position(void)
|
|||
* stopping the stream. */
|
||||
for (i = 0; i < 5; ++i) {
|
||||
r = cubeb_stream_stop(stream);
|
||||
assert(r == 0);
|
||||
ASSERT_TRUE(r == 0);
|
||||
r = cubeb_stream_get_position(stream, &position);
|
||||
assert(r == 0);
|
||||
assert(last_position < position);
|
||||
ASSERT_TRUE(r == 0);
|
||||
ASSERT_TRUE(last_position < position);
|
||||
last_position = position;
|
||||
delay(500);
|
||||
r = cubeb_stream_start(stream);
|
||||
assert(r == 0);
|
||||
ASSERT_TRUE(r == 0);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
assert(last_position != 0);
|
||||
ASSERT_TRUE(last_position != 0);
|
||||
|
||||
/* stream position should not advance after stopping playback */
|
||||
r = cubeb_stream_stop(stream);
|
||||
assert(r == 0);
|
||||
ASSERT_TRUE(r == 0);
|
||||
|
||||
/* XXX allow stream to settle */
|
||||
delay(500);
|
||||
|
||||
r = cubeb_stream_get_position(stream, &position);
|
||||
assert(r == 0);
|
||||
ASSERT_TRUE(r == 0);
|
||||
last_position = position;
|
||||
|
||||
delay(500);
|
||||
|
||||
r = cubeb_stream_get_position(stream, &position);
|
||||
assert(r == 0);
|
||||
assert(position == last_position);
|
||||
ASSERT_TRUE(r == 0);
|
||||
ASSERT_TRUE(position == last_position);
|
||||
|
||||
cubeb_stream_destroy(stream);
|
||||
cubeb_destroy(ctx);
|
||||
|
@ -514,13 +511,13 @@ static int got_drain;
|
|||
static long
|
||||
test_drain_data_callback(cubeb_stream * stm, void * user_ptr, const void * /*inputbuffer*/, void * outputbuffer, long nframes)
|
||||
{
|
||||
assert(stm && user_ptr == &dummy && outputbuffer && nframes > 0);
|
||||
EXPECT_TRUE(stm && user_ptr == &dummy && outputbuffer && nframes > 0);
|
||||
if (do_drain == 1) {
|
||||
do_drain = 2;
|
||||
return 0;
|
||||
}
|
||||
/* once drain has started, callback must never be called again */
|
||||
assert(do_drain != 2);
|
||||
EXPECT_TRUE(do_drain != 2);
|
||||
#if (defined(_WIN32) || defined(__WIN32__))
|
||||
memset(outputbuffer, 0, nframes * sizeof(float));
|
||||
#else
|
||||
|
@ -534,7 +531,7 @@ void
|
|||
test_drain_state_callback(cubeb_stream * /*stm*/, void * /*user_ptr*/, cubeb_state state)
|
||||
{
|
||||
if (state == CUBEB_STATE_DRAINED) {
|
||||
assert(!got_drain);
|
||||
ASSERT_TRUE(!got_drain);
|
||||
got_drain = 1;
|
||||
}
|
||||
}
|
||||
|
@ -553,7 +550,7 @@ test_drain(void)
|
|||
total_frames_written = 0;
|
||||
|
||||
r = cubeb_init(&ctx, "test_sanity");
|
||||
assert(r == 0 && ctx);
|
||||
ASSERT_TRUE(r == 0 && ctx);
|
||||
|
||||
params.format = STREAM_FORMAT;
|
||||
params.rate = STREAM_RATE;
|
||||
|
@ -564,10 +561,10 @@ test_drain(void)
|
|||
|
||||
r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, ¶ms, STREAM_LATENCY,
|
||||
test_drain_data_callback, test_drain_state_callback, &dummy);
|
||||
assert(r == 0 && stream);
|
||||
ASSERT_TRUE(r == 0 && stream);
|
||||
|
||||
r = cubeb_stream_start(stream);
|
||||
assert(r == 0);
|
||||
ASSERT_TRUE(r == 0);
|
||||
|
||||
delay(500);
|
||||
|
||||
|
@ -575,22 +572,22 @@ test_drain(void)
|
|||
|
||||
for (;;) {
|
||||
r = cubeb_stream_get_position(stream, &position);
|
||||
assert(r == 0);
|
||||
ASSERT_TRUE(r == 0);
|
||||
if (got_drain) {
|
||||
break;
|
||||
} else {
|
||||
assert(position <= total_frames_written);
|
||||
ASSERT_TRUE(position <= total_frames_written);
|
||||
}
|
||||
delay(500);
|
||||
}
|
||||
|
||||
r = cubeb_stream_get_position(stream, &position);
|
||||
assert(r == 0);
|
||||
assert(got_drain);
|
||||
ASSERT_TRUE(r == 0);
|
||||
ASSERT_TRUE(got_drain);
|
||||
|
||||
// Really, we should be able to rely on position reaching our final written frame, but
|
||||
// for now let's make sure it doesn't continue beyond that point.
|
||||
//assert(position <= total_frames_written);
|
||||
//ASSERT_TRUE(position <= total_frames_written);
|
||||
|
||||
cubeb_stream_destroy(stream);
|
||||
cubeb_destroy(ctx);
|
||||
|
@ -625,8 +622,7 @@ int is_windows_7()
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int /*argc*/, char * /*argv*/[])
|
||||
TEST(sanity, main)
|
||||
{
|
||||
test_init_destroy_context();
|
||||
test_init_destroy_multiple_contexts();
|
||||
|
@ -664,6 +660,4 @@ main(int /*argc*/, char * /*argv*/[])
|
|||
test_stream_destroy_pending_drain();
|
||||
*/
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -6,16 +6,12 @@
|
|||
*/
|
||||
|
||||
/* libcubeb api/function test. Plays a simple tone. */
|
||||
#ifdef NDEBUG
|
||||
#undef NDEBUG
|
||||
#endif
|
||||
#define _XOPEN_SOURCE 600
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "cubeb/cubeb.h"
|
||||
#include "common.h"
|
||||
|
||||
|
@ -95,7 +91,7 @@ void state_cb(cubeb_stream *stream, void *user, cubeb_state state)
|
|||
return;
|
||||
}
|
||||
|
||||
int main(int /*argc*/, char * /*argv*/[])
|
||||
TEST(tone, main)
|
||||
{
|
||||
cubeb *ctx;
|
||||
cubeb_stream *stream;
|
||||
|
@ -106,7 +102,7 @@ int main(int /*argc*/, char * /*argv*/[])
|
|||
r = cubeb_init(&ctx, "Cubeb tone example");
|
||||
if (r != CUBEB_OK) {
|
||||
fprintf(stderr, "Error initializing cubeb library\n");
|
||||
return r;
|
||||
ASSERT_EQ(r, CUBEB_OK);
|
||||
}
|
||||
|
||||
params.format = STREAM_FORMAT;
|
||||
|
@ -116,7 +112,7 @@ int main(int /*argc*/, char * /*argv*/[])
|
|||
user_data = (struct cb_user_data *) malloc(sizeof(*user_data));
|
||||
if (user_data == NULL) {
|
||||
fprintf(stderr, "Error allocating user data\n");
|
||||
return CUBEB_ERROR;
|
||||
ASSERT_EQ(r, CUBEB_OK);
|
||||
}
|
||||
user_data->position = 0;
|
||||
|
||||
|
@ -124,7 +120,7 @@ int main(int /*argc*/, char * /*argv*/[])
|
|||
4096, data_cb, state_cb, user_data);
|
||||
if (r != CUBEB_OK) {
|
||||
fprintf(stderr, "Error initializing cubeb stream\n");
|
||||
return r;
|
||||
ASSERT_EQ(r, CUBEB_OK);
|
||||
}
|
||||
|
||||
cubeb_stream_start(stream);
|
||||
|
@ -134,9 +130,7 @@ int main(int /*argc*/, char * /*argv*/[])
|
|||
cubeb_stream_destroy(stream);
|
||||
cubeb_destroy(ctx);
|
||||
|
||||
assert(user_data->position);
|
||||
ASSERT_TRUE(user_data->position);
|
||||
|
||||
free(user_data);
|
||||
|
||||
return CUBEB_OK;
|
||||
}
|
||||
|
|
|
@ -1,80 +1,76 @@
|
|||
#include <cassert>
|
||||
#include "gtest/gtest.h"
|
||||
#include "cubeb_utils.h"
|
||||
|
||||
int test_auto_array()
|
||||
void test_auto_array()
|
||||
{
|
||||
auto_array<uint32_t> array;
|
||||
auto_array<uint32_t> array2(10);
|
||||
uint32_t a[10];
|
||||
|
||||
assert(array2.length() == 0);
|
||||
assert(array2.capacity() == 10);
|
||||
ASSERT_TRUE(array2.length() == 0);
|
||||
ASSERT_TRUE(array2.capacity() == 10);
|
||||
|
||||
|
||||
for (uint32_t i = 0; i < 10; i++) {
|
||||
a[i] = i;
|
||||
}
|
||||
|
||||
assert(array.capacity() == 0);
|
||||
assert(array.length() == 0);
|
||||
ASSERT_TRUE(array.capacity() == 0);
|
||||
ASSERT_TRUE(array.length() == 0);
|
||||
|
||||
array.push(a, 10);
|
||||
|
||||
assert(!array.reserve(9));
|
||||
ASSERT_TRUE(!array.reserve(9));
|
||||
|
||||
for (uint32_t i = 0; i < 10; i++) {
|
||||
assert(array.data()[i] == i);
|
||||
ASSERT_TRUE(array.data()[i] == i);
|
||||
}
|
||||
|
||||
assert(array.capacity() == 10);
|
||||
assert(array.length() == 10);
|
||||
ASSERT_TRUE(array.capacity() == 10);
|
||||
ASSERT_TRUE(array.length() == 10);
|
||||
|
||||
uint32_t b[10];
|
||||
|
||||
array.pop(b, 5);
|
||||
|
||||
assert(array.capacity() == 10);
|
||||
assert(array.length() == 5);
|
||||
ASSERT_TRUE(array.capacity() == 10);
|
||||
ASSERT_TRUE(array.length() == 5);
|
||||
for (uint32_t i = 0; i < 5; i++) {
|
||||
assert(b[i] == i);
|
||||
assert(array.data()[i] == 5 + i);
|
||||
ASSERT_TRUE(b[i] == i);
|
||||
ASSERT_TRUE(array.data()[i] == 5 + i);
|
||||
}
|
||||
uint32_t* bb = b + 5;
|
||||
array.pop(bb, 5);
|
||||
|
||||
assert(array.capacity() == 10);
|
||||
assert(array.length() == 0);
|
||||
ASSERT_TRUE(array.capacity() == 10);
|
||||
ASSERT_TRUE(array.length() == 0);
|
||||
for (uint32_t i = 0; i < 5; i++) {
|
||||
assert(bb[i] == 5 + i);
|
||||
ASSERT_TRUE(bb[i] == 5 + i);
|
||||
}
|
||||
|
||||
assert(!array.pop(nullptr, 1));
|
||||
ASSERT_TRUE(!array.pop(nullptr, 1));
|
||||
|
||||
array.push(a, 10);
|
||||
array.push(a, 10);
|
||||
|
||||
for (uint32_t j = 0; j < 2; j++) {
|
||||
for (uint32_t i = 0; i < 10; i++) {
|
||||
assert(array.data()[10 * j + i] == i);
|
||||
ASSERT_TRUE(array.data()[10 * j + i] == i);
|
||||
}
|
||||
}
|
||||
assert(array.length() == 20);
|
||||
assert(array.capacity() == 20);
|
||||
ASSERT_TRUE(array.length() == 20);
|
||||
ASSERT_TRUE(array.capacity() == 20);
|
||||
array.pop(nullptr, 5);
|
||||
|
||||
for (uint32_t i = 0; i < 5; i++) {
|
||||
assert(array.data()[i] == 5 + i);
|
||||
ASSERT_TRUE(array.data()[i] == 5 + i);
|
||||
}
|
||||
|
||||
assert(array.length() == 15);
|
||||
assert(array.capacity() == 20);
|
||||
|
||||
return 0;
|
||||
ASSERT_TRUE(array.length() == 15);
|
||||
ASSERT_TRUE(array.capacity() == 20);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
TEST(utils, main)
|
||||
{
|
||||
test_auto_array();
|
||||
return 0;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче